text:
NodeMCU capable of key injection?
Short version: Is the NodeMCU capable of key injection in the same way that an Arduino Teensy can be programmed with Duckuino script to function as a HID?
Long version: Recently, my 7+ year old iMac suddenly stopped working and now I am unable to boot into the Mac which is a right pain. Even more of a pain is that due to the fact that the iMac has a wireless keyboard as opposed to a USB meaning that I am unable to boot into Single User mode, recovery mode, safe boot etc. This is a pain as I am currently stuck with an iMac in an unsuccessful boot loop. I understand that the best option would be to buy a USB keyboard and use this separately; however, it turns out that one of my friends has a spare NodeMCU and said he's willing to lend it to me as he is pretty sure that the Duckuino script will work on it meaning that I could use the NodeMCU as a sort of impromptu keyboard to hold down the shift key on boot, effectively removing the need for me to buy and wait for a new USB keyboard.
I had found this video here on YouTube which explains the process of turning an Arduino into a "USB Rubber Ducky" but there is no mention of this working with a NodeMCU. Assuming that I have the ESP8266 addon for the Arduino IDE and was able to put the Duckuino script onto the NodeMCU, would the NodeMCU function as intended with the Duckuino script or is the NodeMCU hardware such that this would be impossible?
Thank you for any assistance,
Kind regards,
John
P.s. This is what my NodeMCU looks like:

No, you can't. You need a USB capable MCU. The ESP8266 is not.

@Majenko Thank you for your response; so I would need something like the Teensy etc?

Yes, or an Arduino Micro, or other ATMega32U4 based Arduino. Or one of the direct-USB connected chipKIT boards, like a Fubarino Mini, etc.

lend an USB keyboard :-)

@Majenko Thank you for your help. For now I think I'll just have to settle with getting a USB keyboard but might look further into Duckuino etc. in the future. :)

if you live near a goodwill or salvation army, you can get a (used) usb kb for about $2...

A bit late, but yes you can. Though it seems to be a pain: https://hackaday.com/2016/09/03/software-usb-on-the-esp8266/

For those who are still looking for ESP8266 Software USB, have a look at this GH repo (cnlohr/espusb)

No, you can't use a NodeMCU for this.
To emulate a USB keyboard you have to have a device with a main MCU on it which is directly connected to USB. The ESP8266 on the NodeMCU is not a USB-capable MCU, and so it uses a USB to UART bridge chip to connect the ESP8266 to the USB of your computer.
You can't program that bridge chip, so you can't make it anything other than a serial port.
Common devices that are directly USB connected and can emulate a keyboard include:

Arduino Micro
Teensy 3.X
Fubarino Mini / SD
Arduino Leonardo
chipKIT Lenny

And there are many more.
For 8-bit Arduino boards you need to look at the MCU it uses. If it's an ATMega32U4 as the main MCU then you can program it to be a keyboard.

Addendum: There are ways of making non-USB boards work as a keyboard. For ATMega328P based Arduinos and similar that use an ATMega16U2 chip as the USB to UART bridge, that bridge chip can be reprogrammed to appear as a keyboard.  For other MCUs there may be software "bit-banged" USB implementations available (such as V-USB), though YMMV with those implementations, and they require building extra hardware to interface the chip to the USB port.

Thank you very much for your answer! It's a shame that the NodeMCU cannot be used for this purpose. I see that you have mentioned there are ways of making non-USB boards work as keyboards but I can't see any mention of the NodeMCU specifically; is this because it is impossible to do for this board? If not, would you be able to point me in the right direction of how to do this? Thank you once again!

yes, it's impossible to make the ch340 or cp2102 into a usb hid like you can the megaxUxs...


text:
Serial.begin(9600); in Arduino
I want to know what Serial.begin(9600); does and if it is necessary to write it in the code.

Have you done any research yourself? Like googling?

It enables the UART port and sets it to 9600 baud.  Without it you can't use Serial.print etc.

Will the bot work without this?

Does "the bot" use Serial.print, Serial.read, or Serial.anythingelseatall?

I'm making an obstacle avoiding bot. I'm not debugging it or using the serial monitor. So, can I exclude it from the code?

The probably. If you're not using Serial.print, Serial.println or Serial.write then it should be doing nothing.

source: Stack Exchange

license: Creative Commons - Attribution Share-Alike - https://creativecommons.org/licenses/by-sa/4.0/

sort: votes


text:
How do I inherit a class that requires &foo() in its constructor?
General
I have a library with a class constructor class Math(&foo1,&foo2);, which I would like to put into a library for class Algebra(), where foo1 and foo2 are defined in Algebra.cpp
My current constructor Algebra::Algebra():Math(&Algebra::foo1,&Algebra::foo2) is returning an error in the Arduino IDE to the effect of:
error: no matching function for call to 'Math::Math(void (Algebra::*)(long unsigned int, byte), byte (Algebra::*)(long unsigned int))':Math(&Algebra::foo1, &Algebra::foo2)
Meta Note: I believe this is on topic because I'm dealing specifically with developing code for the Arduino Mega using libraries and hardware components designed for Arduino. If I am in error, and there is a better exchange for this question please let me know

Specifically,
I'm writing a library to combine Adafruit's I2C FRAM with the Extended database library (I have validated that the libraries work when called into a sketch independently, but I'd like to combine them to be more easily inheritable in [Big_Machine_api.h] that I will be making later)
I'm testing my library with this sketch:
/*
 EDB_AT24C1024.pde
 Extended Database Library + Adafruit_FRAM_I2C EEPROM Test Sketch

 The Extended Database library project page is here:
 http://www.arduino.cc/playground/Code/ExtendedDatabaseLibrary

 The Adafruit_FRAM_I2C library project page is here:
 https://github.com/adafruit/Adafruit_FRAM_I2C

 */
#include "Arduino.h"
#include <Wire.h>
#include <Adafruit_FRAM_I2C_EDB.h>
#define TABLE_SIZE 131072

// Arbitrary record definition for this table.
// This should be modified to reflect your record needs.
struct LogEvent {
  int id;
  unsigned long Rotations;
}
logEvent;

// Create an EDB object with the appropriate write and read handlers
Adafruit_FRAM_I2C_EDB db;

// Run the demo
void setup() {
  Serial.begin(115200);
  Serial.println("DONE");
}

void loop() {
}

My ADAFRUIT_FRAM_I2C_EDB.h file:
#ifndef ADAFRUIT_FRAM_I2C_EDB_h
#define ADAFRUIT_FRAM_I2C_EDB_h

#include <Arduino.h>
#include <Adafruit_FRAM_I2C.h>
#include <EDB.h>

#define MB85RC_DEFAULT_ADDRESS        (0x50) /* 1010 + A2 + A1 + A0 = 0x50 default */

class Adafruit_FRAM_I2C_EDB : public EDB {
 public:
  Adafruit_FRAM_I2C_EDB(uint8_t addr = MB85RC_DEFAULT_ADDRESS);
  void getDeviceID(uint16_t *manufacturerID, uint16_t *productID);

 private:
  Adafruit_FRAM_I2C _fram;
  uint8_t _FRAMaddr;
  void writer(unsigned long address, byte data);
  byte reader(unsigned long address);

};
#endif

My ADAFRUIT_FRAM_I2C_EDB.cpp file:
#include "Arduino.h"
#include "Adafruit_FRAM_I2C.h"
#include "EDB.h"
#include "Adafruit_FRAM_I2C_EDB.h"
Adafruit_FRAM_I2C_EDB::Adafruit_FRAM_I2C_EDB(uint8_t addr)
:_FRAMaddr(addr),EDB(&Adafruit_FRAM_I2C_EDB::writer, &Adafruit_FRAM_I2C_EDB::reader) {
  _fram = Adafruit_FRAM_I2C();
  _fram.begin(_FRAMaddr);
}

void Adafruit_FRAM_I2C_EDB::getDeviceID(uint16_t *manufacturerID, uint16_t *productID) {
  _fram.getDeviceID(manufacturerID, productID);
}

void Adafruit_FRAM_I2C_EDB::writer(unsigned long address, byte data) {
  _fram.write8(address, data);
}

byte Adafruit_FRAM_I2C_EDB::reader(unsigned long address) {
  return _fram.read8(address);
}

Full Error List:
C:[...]\Arduino\libraries\Adafruit_FRAM_I2C_EDB\Adafruit_FRAM_I2C_EDB.cpp:16:84: note: candidates are:

In file included from C:[...]\Arduino\libraries\Adafruit_FRAM_I2C_EDB\Adafruit_FRAM_I2C_EDB.cpp:3:0:

C:[...]\Arduino\libraries\EDB-master/EDB.h:54:5: note: EDB::EDB(void (*)(long unsigned int, uint8_t), uint8_t (*)(long unsigned int))

     EDB(EDB_Write_Handler *, EDB_Read_Handler *);

     ^

C:[...]\Arduino\libraries\EDB-master/EDB.h:54:5: note:   no known conversion for argument 1 from 'void (Adafruit_FRAM_I2C_EDB::*)(long unsigned int, byte) {aka void (Adafruit_FRAM_I2C_EDB::*)(long unsigned int, unsigned char)}' to 'void (*)(long unsigned int, uint8_t) {aka void (*)(long unsigned int, unsigned char)}'

C:[...]\Arduino\libraries\EDB-master/EDB.h:50:7: note: constexpr EDB::EDB(const EDB&)

 class EDB {

       ^

C:[...]Arduino\libraries\EDB-master/EDB.h:50:7: note:   candidate expects 1 argument, 2 provided

C:[...]Arduino\libraries\EDB-master/EDB.h:50:7: note: constexpr EDB::EDB(EDB&&)

C:[...]\Arduino\libraries\EDB-master/EDB.h:50:7: note:   candidate expects 1 argument, 2 provided

exit status 1
Error compiling for board Arduino/Genuino Mega or Mega 2560.

You only use &foo when constructing if the constructor needs *foo.

Ok, my constructor  Algebra::Algebra():Math(Algebra::foo1,Algebra::foo2) results in error: invalid use of non-static member function:Math(Algebra::foo1, Algebra::foo2) Where would I go from here?

Algebra::Algebra(FooType &foo1, FooType &foo1):Math(foo1, foo2)?

You just pass the variables to the parent constructor in the initialization list of the child. No need for qualifications or anything like that.
Here's an example that compiles:
class Math {
    private:
        int _foo1;
        int _foo2;

    public:
        Math(int &foo1, int &foo2) : _foo1(foo1), _foo2(foo2) {}
};

class Algebra : public Math {
    private:
        int myFoo1 = 12;
        int myFoo2 = 34;

    public:
        Algebra() : Math(myFoo1, myFoo2) {}
};

Math's constructor takes two integers passed by reference.  The Algebra constructor's initialization list calls the parent Math constructor with two of its own member integers that are then automatically passed by reference, since that is what the constructor calls for.
However, that isn't what your actual problem is. You're asking about one thing, then showing an error that is for a completely different problem.
You have a constructor (actually any function will do the same) that expects a pair of pointers to two functions:

void (*)(long unsigned int, uint8_t)
uint8_t (*)(long unsigned int)

That is, you need two functions, such as:
void reader(unsigned long a, uint8_t b) {
}

and
uint8_t writer(unsigned long a) {
    return 3;
}

But instead you are attempting to pass member functions of a class.  The problem here is that although they look the same, because they are class members they aren't the same.
Any class member function has an additional implied parameter, which is a pointer to the containing class instance and is called this.  So your functions actually look more like:
void reader(Adafruit_FRAM_I2C_EDB *this, unsigned long a, uint8_t b) {
}

and
uint8_t writer(Adafruit_FRAM_I2C_EDB*this, unsigned long a) {
    return 3;
}

(Note: that's only an approximation - it's actually a lot more involved than that, but it serves to illustrate the problem).  As you can see that doesn't match what is expected, and so you can't pass those functions to the parent constructor - they're simply wrong.
This is a commonly occuring problem - often seen when trying to use a class member function with attachInterrupt(). You just can't do it.  Or not like that anyway.
The only way of passing a member function directly is for that member function to be static. That then acts like a normal function, and there is no this parameter. However, it can only act on other static variables and functions. So using it takes a little more care - plus of course static functions and variables are shared between all instances of a class.

Is there a way I can edit the constructor to accept void writer (Class *this, unsigned long a, uint8_t b) and uint8_t reader (Class *this, unsigned long a) ? I've been trying to make it work, but my FRAM library does not seem to want to work as a static function.

The parent class would need to know about the child class and explicitly include it in the prototype. Either that or you create a separate interface class that the parent uses in the prototype and the child inherits from. Personally I wouldn't take either route, but would have the parent define some pure virtual read/write function stubs and then create a child class that implements those stubs.

all_licenses: Creative Commons - Attribution Share-Alike - https://creativecommons.org/licenses/by-sa/4.0/


text:
Correct way of having loop end when required?
I'm brand new to Arduinos. I'm currently trying to modify a script from here which at the moment, simply turns an LED on or off depending on which HTTP GET request it receives. However, I want to modify this to have the LED modulate on/off when presented with the On HTTP GET request and then simply turn off all together when presented with the Off HTTP GET request. However, I have two conflicting methods that I have found about how to achieve this; the first is:
int value = LOW;
    if (request.indexOf("/LED=ON") != -1)  {
      value = HIGH;
      do
      {
      digitalWrite(ledPin, HIGH);
      delay(3000);
      digitalWrite(ledPin, LOW);
      delay(5000);
      value = HIGH;
      } while (value = HIGH);
    }
    if (request.indexOf("/LED=OFF") != -1)  {
      digitalWrite(ledPin, LOW);
      value = LOW;
    }

Wheareas the other is:
  int value = LOW;
    if (request.indexOf("/LED=ON") != -1)  {
      value = HIGH;
      void loop() {
      digitalWrite(ledPin, HIGH);
      delay(3000);
      digitalWrite(ledPin, LOW);
      delay(5000);
      value = HIGH;
      }
    }
    if (request.indexOf("/LED=OFF") != -1)  {
      digitalWrite(ledPin, LOW);
      value = LOW;
    }

As you can see, the first uses do...while and the second uses loop(). I have a feeling that the first of the two scripts would be more suitable as it should cut out as soon as value is set to LOW (i.e. when requested to turn off)
However, I would really appreciate it if someone could look through the two scripts and tell me which of the two is the correct way to achieve this sort of cut off when the HTTP GET Off is requested (if either for them even is the correct way to do this!).
Thank you in advance for your help,
Kind regards,
Tom

Unfortunately they're both completely wrong. Use a state machine instead.

@IgnacioVazquez-Abrams Thank you for your response; that's a shame, how would I do that?

how does the do...while loop exit in the first snippet?

I assumed that when the off get request is made, you can see from the script that"value" is set to LOW and when this condition is met, the loop should exit

examine the example codes that are part of the Arduino IDE .... pay attention to the use of setup() and loop()   ....... have a very close look at the flashWithoutDelay sketch ..... in your program, set a flag when you receive an HTTP request ..... then in the code that follows the HTTP check, flash LED if flag is set .... turn off LED if flag is not set

also have a look at how the original code is formatted ... the indentation and the positioning of braces {} ..... then look at your code .... your code is badly formatted, so it is harder to read (hard to follow the program flow)

With the do...while value never changes to LOW, since the code that changes it is outside of the do...while and isn’t being run while value is HIGH. try moving the int value... outside the loop function (i.e. global variable), and removing the do...while (only leave the code inside it). Not sure if checking http requests only every 8 seconds will work.

@jsotola Thanks for your response. That sounds like a great solution for this problem. I've had a look for that example sketch and couldn't find it. If it possible and if it is not too much to ask, would you please mind showing how I'd do this in an Answer format as I have very little programming experience with the Arduino IDE. Thank you

@Gerben Thank you for your comment. I understand the solution you are trying to suggest but I agree that I feel checking for a request every 8 seconds only will not work as the request itself would have to be made at exactly the right time. Any other solution you can think of?

The network stuff works in parallel to your code, so it might work.

@Gerben I'll give that a shot in a bit. Might it be better two have two separate loops going at the same time if that is even possible? I.e. one loop which is constantly ready for a new get request and another which can handle the do...while loop as the first loop is then free to change the "value" at any time which could stop the second loop if you see what I mean?

I don’t know if you can (simply) do multithreading on the ESP. a better solution is to do the blinking based on the millis value. That way you don’t need any delays. See the Arduino “blink without delay” page.

As pointed out by Ignacio Vazquez-Abrams and jsotola, you need to use a
state machine, like the one from the Blink Without Delay
Arduino tutorial. Yours would be slightly more complicated because you
need a way to turn it on and off, and because you use different on and
off periods. Here is an example code that abstract the blinking logic
into three functions:

update_led() takes care of the blinking, and it has to be called
quite often in order to achieve a smooth blinking
start_blinking() and stop_blinking(), as their names suggest, are
used to turn the blinking state machine on and off.

const uint32_t ON_TIME  = 3000;
const uint32_t OFF_TIME = 5000;

bool led_blinking;     // are we blinking the LED?
bool led_on;           // is the LED currently on?
uint32_t last_toggle;  // last time it toggled while blinking

void update_led() {
    if (!led_blinking) return;
    uint32_t now = millis();
    if (led_on && now - last_toggle >= ON_TIME) {
        digitalWrite(ledPin, LOW);
        led_on = false;
        last_toggle = now;
    }
    if (!led_on && now - last_toggle >= OFF_TIME) {
        digitalWrite(ledPin, HIGH);
        led_on = true;
        last_toggle = now;
    }
}

void start_blinking() {
    digitalWrite(ledPin, HIGH);
    led_blinking = true;
    led_on = true;
    last_toggle = millis();
}

void stop_blinking() {
    digitalWrite(ledPin, LOW);
    led_blinking = false;
    led_on = false;
}

You then have to call these functions from loop() as follows:
void loop() {
    // Keep the LED blinking if necessary.
    update_led();
    ...
    if (request.indexOf("/LED=ON") != -1)  {
        start_blinking();
    }
    if (request.indexOf("/LED=OFF") != -1)  {
        stop_blinking();
    }
    ...
}

Edit, in response to jsotola’s comments:
When answering the question, I was initially tempted to make a
BlinkingLed class, with the functions as its public interface and the
variables private. I resisted the temptation on the grounds that, given
the apparent OP’s level of C++ knowledge, that could end up being well
over his head. Instead, I used documentation as an informal way of
separating the public from the private: you are only supposed to use
what is documented, i.e. the functions. You don't “take a shortcut in
your program and clear led_blinking directly”.
You could, of course, make the led_blinking variable part of the
public interface. That could even be a nice simplification, as you don't
need the start/stop function anymore. But then you loose control over
the initial phase of the blinking pattern. That may not be an issue, but
if you want the LED to turn on as soon as you set led_blinking to
true, then you have to do something like
void update_led() {
    uint32_t now = millis();
    if (!led_blinking) {
        digitalWrite(ledPin, LOW);
        led_on = false;
        last_toggle = now - OFF_TIME;  // fix initial phase
        return;
    }
    ...
}

Note that the subtraction can overflow, but that's not as issue because
it follows the rules of modular arithmetics.
I actually kind of like this option, with all the logic in a single
function. This way the variables led_on and last_toggle can be made
static local to the function, which provides true encapsulation without
a class. However, from a pedagogic point of view, I think my initial
proposal is easier to understand.

Thank you so much for your answer! This is exactly what I was looking for! I appreciate all the help that people have supplied me with in the comments but I really appreciate the fact that you have been able to break down the problem into understandable chunks and provide a well structured answer. Thank you!

change this line if (!led_blinking) return;  so that it turns off the LED and then returns

@jsotola I'm confused as to what you mean. Are you saying that this line he has written is incorrect? If so, what should the line read?

no, i am not saying that it was written wrong ... the LED will certainly stop blinking when led_blinking==false ..... if led_blinking is cleared (set to false) by the stop_blinking() function, then the LED will be off ..... however, if you take a shortcut in your program and clear led_blinking directly without calling stop_blinking(), then the LED will stop blinking, but it may be on

@jsotala Ah, I see, that makes sense. How exactly would I adapt that code to have it that when led_blinking==false, the led will turn off completely even if currently on? Would you be able to post some code which may help fix this problem? Thank you very much :)

i do not understand why you are asking for code .... you already have the if (!led_blinking) line given to you by Edgar Bonet ... and you have previously written the turnoff code in what you posted .... look at the second if statement .... just insert the code for turning off the LED before the return command

@jsotola: I am responding to your comments in an edit to my answer.


text:
PIR motion wake ESP8266 from deepsleep
I'm trying, what I thought would be simple, to wake a sleeping ESP8266 via motion detected by a PIR.
There are a lot of schematics around and they all seem to go about it more or less the same way, and the simplest form seems to be this:

Where RST is the RST pin of the ESP8266 and Trigger is the PIR's trigger line.
The problem I'm finding is that this is not working.
The PIR is working fine, and throws out almost 3v for 2 seconds when triggered and 0 when no motion is detected.
My ESP is being woken up when the PIR trigger is OVER, not when it STARTS. So if the PIR senses motion for a long time, the ESP will only wake up when the motion STOPS.
The PIR is one of these.
The ESP is currently a NodeMCU on breadboard, but the final product will be a Wemos D1 Mini.
What am I doing wrong here?

you measured only 1/2 of your circuit .... The PIR is working fine, and throws out almost 3v for 2 seconds when triggered ... how about measuring the RST line

The RST line has 3.3v as expected. When the PIR fires, the voltage on RST drops to zero, which I expect to wake the ESP. However, the ESP only wakes when the PIR stops firing and the voltage to RST goes back up to 3.3v. I don't get it.

it is simple, the esp8266 stays in reset mode as long as RST is active (low) .... it leaves reset mode and starts executing its program when RST becomes inactive (rising edge on RST)

What you need is an edge detector. As long as the PIR output is hight, the ESP stays in reset mode.
You can use a capacitor to do the trick, as shown in the following schematic.
You'll probably want to get rid of the pull-down resistor R1 since you're using an open-collector output.

If the voltage at the collector is the blue curve, then the resulting voltage at the output of the circuit will be similar to the yellow curve. (Note that this simulation used an ideal square wave as input, produced by a push-pull output from a CMOS chip, for example. An open-collector output will have slightly different characteristics, the high peak won't be as high.)

At the instant when the collector voltage drops to (almost) zero, the voltage across C1 will be 0V, so the output is close to 0V as well. Then the capacitor immediately starts to charge through R2, so the voltage on the reset pin rises exponentially.
To prevent a high voltage peak when the PIR turns off, a diode is used to discharge the capacitor more quickly. If the resistor at the collector is large enough, this might not be an issue at all.
The same principle is used in the Arduino UNO, for example, to reset the ATmega when DTR goes low.

Thanks. That is very useful. Based on your schematic and a few others I found, I have re-worked my wiring to this: http://groovy.globi.ca/img/20180722-3404caebc3bdc7f233726e6afe54ffea.png
This is working very well. The ESP is woken quickly, and by setting D3 LOW, is prevented from re-booting while running.
The problem I'm now facing is that the PIR output pin is showing a negative voltage. I want to connected it as an INPUT to the ESP so it can check the status, but the ESP goes crazy when connecting it. Any ideas?

If D3 goes from low to high when trigger is low, trigger will get pulled negative. (Because there was a negative charge on C1). The output impedance of most PIRs is greater than 1kΩ, so the voltage will go negative. You need a resistor on your base. If you do the edge detection after the transistor, you shouldn't have to worry about this. You can still use the AND configuration you have right now.

Hmm. I put another NPN between V++ and the edge detect with trigger to the base, but I'm still getting a negative voltage on the trigger. Where exactly do you think the resistor should go, and what value? Is the 1M resistor maybe too high in this circuit?

Use your initial circuit, the one you used in your question. Then add the circuit of my answer (without R1). Connect your RST output to my DTR input. Then add the second transistor between the emiter of the first transistor and ground (collector 2 to emitter 1, emitter 2 to ground, base 2 through a resistor to the GPIO pin of the ESP).

I tried adding your edge detector to my original circuit at RST, and it looks like this: http://groovy.globi.ca/img/20180723-d02a55da8edcc7ec95a59ce5c8a93f5b.png
However, when I plug D3 into the ESP, it never boots - just throws gibberish to the serial console and dies. Did I mis-interpret your instructions?

You forgot your pull-up resistor at the collector, and the base resistor of the second transistor. D3 is the boot select pin for the ESP8266. You're pulling it low through the transistor, use a different pin. Avoid D3, D4, and D8, as they all have special functions at boot time.

I appreciate your patience and apologize if I'm being stupid, but by adding the pull-up to the collector, I'm now reading a consistent 3v3 at RST. This is the current circuit (except that Q5 base is going to D1 now and not D3 as suggested): http://groovy.globi.ca/img/20180723-6931232cc901e6c1d521acb48828cad0.png. When the PIR fires, no change happens and the ESP is not triggered.

You didn't pull up the base of the lower transistor.


text:
Can't display the two float values correctly from pyserial on Arduino's LCD
I transported two float values with pyserial to COM3 and Arduino accepted the values.
But it displayed the first value correctly on LCD, the second value can't be read and showed "nan" on LCD.
Python code:
import serial
import struct
ser =serial.Serial("COM3", 115200, timeout=2)

##======Get  Ready================
print("Connecting to Arduino.....")
for i in range (1,10):
    rv=ser.readline()
    print("Loading...")
    #Debug print (rv) # Read the newest output from the Arduino
    print (rv.decode("utf-8"))
    ser.flushInput()
    sleep(1) # Delay for one tenth of a secon
    Str=rv.decode("utf-8")
    #Debug print(Str[0:5])
    if Str[0:5]=="Ready":
          print("Get Arduino Ready !")
          break
##------------------------------------------------------
d = 77.25
a = 111.32
ser.write(struct.pack('>2f',d,a))

Arduino code:
#include <LiquidCrystal.h>
float x;
byte *xdata = (byte *) & x;
float y;
byte *ydata = (byte *) & y;
int num = 0;
char coor[2];

LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

void setup() {
  Serial.begin(115200); // set the baud rate
  Serial.println("Ready"); // print "Ready" once
  // set up the LCD's number of columns and rows:
  lcd.begin(16, 2);
  // Print a message to the LCD.
}

void loop(){
  while(Serial.available() > 0){
    for(int i = 0; i < 2; i++){
      coor[i] = Serial.read();
      }
    if(coor[0] == 'B' ){
      xdata[3] = coor[0];
      ydata[3] = coor[1];
      num = 1;
    } else if(num == 1){
      xdata[2] = coor[0];
      ydata[2] = coor[1];
      num++;
    } else if(num == 2){
      xdata[1] = coor[0];
      ydata[1] = coor[1];
      num++;
    } else if(num == 3){
      xdata[0] = coor[0];
      ydata[0] = coor[1];
      num = 0;
    // use the values
    Serial.write(xdata,4);
    Serial.write(ydata,4);
    lcd.print(x);
    lcd.setCursor(8,0);
    lcd.print(y);
      }
    }

The LCD monitor will show 77.25 and nan. It can't show 111.32 correctly.

you read two bytes if at least one is available. read the two bytes with Serial.readBytes(coor, 2). it will wait for the second byte

Or wait for there to be 2 bytes available before reading them...

sorry,i still can't unserstand the following code," Serial.readBytes(coor, 2) ",where to write.

I replaced "coor[i] = Serial.read();" with "Serial.readBytes(coor, 2)",but it still can't work.

and you removed the for loop? https://www.arduino.cc/reference/en/language/functions/communication/serial/readbytes/

No,I deleted the  "for(int i = 0; i < 2; i++){ coor[i] = Serial.read(); }" and write "Serial.readBytes(coor, 2);" in while funtion.

the LCD showed different,the 77.25 became 64.25 on LCD monitor,and the nan became -0.00

I don't understand why you read the bytes this way. Your original version was reading only the bytes of the first float into xdata and -1 into ydata. (read returns -1 if no data is available, it doesn't wait.) Now when two bytes are read with readBytes, first two bytes of the first float are written one into xdata[0] and second into ydata[0].
read first float with readBytes(xdata, 4) and the the second with readBytes(ydata, 4)


text:
Difference between these two NodeMCU boards?
I recently received a NodeMCU (identical to the one shown in the first picture below) and originally, I was unable to connect it to my computer which eventually turned out to be driver issues; however, during my initial panic, I found that there seems to be two variations of the NodeMCU board.
As you can see from the pictures below, at first glance there seems to be no difference to the boards, however, some of the more noticeable differences are that the first one has only one "orange" chip whereas the second one has two. Moreover, the first one has a large square chip towards the USB port wheareas the second seems to have a rectangular one.
First one:

Second one:

I would really appreciate if someone could enlighten me to what these small differences are between the two boards are and also what are the implications of these differences (if there are any).
Thank you in advance for any help,
Kind regards,
John

the one on top is better: narrower, better 5v (vin), faster serial, etc

Marcel Stör wrote an excellent comparison of the different NodeMCU development boards: https://frightanic.com/iot/comparison-of-esp8266-nodemcu-development-boards/

The top one is a real NodeMCU version 1 board (ESP-12E module).
The bottom one is a knock-off copy - looks like the same module on it.
The biggest difference is the USB interface. The real one uses a CP2102 USB to UART bridge. The copy uses a CH340G chip.  The CH340G is notoriously unstable and liable to die at a moments notice.  The CP2102 is far more reliable.  I recently accidentally nuked a Wemos D1 Mini pro which has the same CP2102 on it with 12V.  It took out the voltage regulator. It took out the ESP8266 chip.  I replaced both those, and the CP2102 was proved to still be working fine. More than could be said for a CH340G - glance at one of those wrong and they die.

Thank you for your answer! I wasn't aware that there were knock-off clones of the NodeMCU out there and I'm so glad that the one I have is not one of them! I'll be sure to look out for the differences in the future; other than that, my NodeMCU seems to be functioning perfectly. Quick point; I came across this article: frightanic.com/iot/comparison-of-esp8266-nodemcu-development-boards/ where the picture they use of the board does seem to have the  CP2102 chip but also seems to have an extra orange chip compared to the first picture above; why is this? Thanks once again :)

That's just a tantalum capacitor. They come in different colours from different manufacturers. Black and yellow are the most common colours.

Having China clone your device is a sign of success :)

Perfect, thank you so much for your help! Hahaha I guess that's true :)

@Majenko: Regarding the CH340G, have you had that happen to you? Under which circumstances?
Most of my 3D-printer control boards use the CH340, and they've always been reliable.

I have 5 Arduinos with CH340G, all flashed few hundreds times, and none died.

I was wondering thy they would use the CH340G if the CP2102 is so much better, but then I looked up unit prices and saw how super expensive the CP2102 is.
actually somewhat odd how little progress there is in the USB to serial market.
actually at this point it might even be a good option to program a microcontroller to emulate/simulate a USB to serial chip, since adding a extra microcontroller for that purpose would actually be cheaper than a CP2102 in general.
also allowing more protocols, would only need to be (pre) programmed with a external chip once and then it works.

I have several of the second version and they all have the CP2102 USB to UART bridge. So I wouldn't say it's a copy or a clone. These are now made by several manufacturers, mine came from DOITING not AI Thinker, so the components can vary and come in different colours ! AND, Chinese is Good !


text:
How do I reset my libraries back to original condition?
How do I reset my arduino installation back to its original state? i.e., no extra downloaded libraries, etc.  If I delete Documents/Arduino/libraries is there any other state that needs to be cleaned up?

What operating system are you using? Did you use the installer or the portable zip?

Delete the Documents -> Arduino -> Libraries to remove all your libraries.
Delete the User -> AppData -> Local -> Arduino15 folder to remove all the preferences.
Uninstall Arduino IDE.
Install a fresh one.

Directory to suppress for reset config.

C:\Users\YourName\.arduinoIDE
C:\Users\YourName\AppData\Local\Arduino15
C:\Users\YourName\AppData\Local\Programs\Arduino IDE
C:\Users\YourName\AppData\Local\arduino-ide-updater
C:\Users\YourName\Documents\Arduino
C:\Users\YourName\AppData\AppData\Roaming\Arduino IDE
C:\Users\YourName\AppData\AppData\Roaming\arduino-ide


text:
Detect a camera flash? Light sensor, photoresistor?
I'm looking to build an Arduino-based "camera flash logger" to detect when a camera flash goes off, and maintain a log of those events. My thinking is to use a photoresistor to measure light level, and watch for sudden changes using a loop. Something like:
const int ldrPin = A0;

// no idea what this number would end up being
// just putting something here to start with
const int threshold = 10;
int currentLevel, lastLevel = 0;

void setup() {
    Serial.begin(9600);
    pinMode(ldrPin, INPUT);
}

void loop() {
    lastLevel = currentLevel;
    currentLevel = analogRead( ldrPin );

    // look for a sudden change
    if( abs( lastLevel - currentLevel ) > threshold ) {

        // serial out here to simplify the example.
        // I'll be logging outputs (with timestamps) to an SD card.
        Serial.println( currentLevel );
    }
}

A couple of things I'm not sure of though:

will the response time of a photoresistor be fast enough to respond to the very short (sometimes less than 1ms) burst from a camera flash?
is a loop measuring level changes the best way to go about this, or would something like a state change interrupt be better? The ambient light level will vary depending on time of day, so it's an edge detection problem, as opposed to just reading a light level.

Apologies if this comes across as a "you haven't done your homework yet" question. I haven't started the project yet, so all I'm hoping for is a little direction on which way to proceed.

I would propose to use a phototransistor, reacts faster. And if you search for "Flash slave trigger schematics" you will find a lot of circuits (ex. http://www.learningelectronics.net/circuits/slave-flash-trigger.html) that could inspire you.

This ATtiny-based camera trigger uses a photodiode and an op-amp to detect lightings.

Thanks @MatsK. That circuit is more involved than, for example, the one shown in circuit 5 here. Is there a reason for that, or would the simpler circuit work for this purpose?

Thanks @EdgarBonet. Is there a reason to go that way (photodiode + op-amp) over a phototransistor or photoresistor?

Circuit 5 doesn't have a pulse filter, the circuit I refer to have C1 that will improve the detection of a pulse/fast changes of light and the darlington transistors for higher amplification. But you may need to modify the circuit to adopt it to your needs.

AFAIK, a phototransistor is kind of like a photodiode with built-in amplification. Not sure how it compares with with photodiode + an op-amp, you will have to read the datasheets of the individual parts to really know.

Interesting question. Do we really need to poll that quickly? For example every millisecond if the even lasts a millisecond.  Is there any way to use some electronic setup, such that a capacitor for example is loaded when the flash comes, so that a lower poll rate would be enough? (thus integrating over a period of time). Thanks.

A photo-resistor would not be recommended to detect a camera flash accurately.  For example, the Jameco Part #202403 (Part PDF) has a response time of 50 to 75 milliseconds.  Photo-resistors are more suitable for general light levels, for instance, like how bright it is in a room.  On the other hand, photo-transistors are suitable for very fast reaction times.  The Jameco Part #2129385 (Part PDF) has a response time of 15 microseconds, which is more than 1000 times faster.  A photo-resistor will be able to respond to the light change, but it will be nowhere as sensitive.As with any product, however, search for the product PDF before buying it.

I have used a photo-resistor to measure the light level of the surroundings during the solar eclipse of 2017, but that is better for general light levels.  You would use a photo-transistor for laser applications, or optoisolators

Thanks for the response. Would a phototransistor circuit (I've found an example in circuit 5 here work the same as a photoresistor? In other words, would the method I'm using (the script) work the same?

I believe that it should work, because it is adjusting the resistance, and that is the only thing the Arduino analog input cares about.  If it doesn't appear to work, add some delay timing to the loop.  You might want to record a test run with the code similar to below.

Here is a sketch that should work.  https://drive.google.com/open?id=1XTAKTFROCUzBeI-EQkweJ2aMK_MSvMJX


text:
Writing to serial LCD seems to interfere with servos
I have an OBD-based Arduino project (OBD adapter link below) which uses two servos and a serial LCD from Sparkfun (link below). My problem: writing to the LCD seems to interfere with the servos. Details:
1) When all LCD-related code is excluded, the servos work smoothly.
2) When LCD-related code is included, but the servos are not hooked up, the LCD displays everything OK.
3) When the LCD-related code is included, even if the LCD itself is NOT hooked up, the problem occurs. There's a brief noise from the servos every time I write to the LCD (the servos don't move much, they just make a brief noise).
Any idea what's causing this? Below are the relevant parts of the code (OBD, servo, LCD):
#include <Arduino.h>
#include <Wire.h>
#include <OBD.h>
#include "MPU6050.h"
#include <SoftwareSerial.h>
#include <Servo.h>

int servoPin1=13;
int servoPin2=12;

Servo servo1;
Servo servo2;

COBDI2C obd;
SoftwareSerial lcd(2,3);

void clearDisplay() {
  lcd.write(0xFE);
  lcd.write(0x01);
}

void setLCDCursor(byte cursor_position) {
  lcd.write(0xFE);
  lcd.write(0x80);
  lcd.write(cursor_position);
}

void Show() {
  setLCDCursor(0);
  lcd.print("Test");
}

void setup() {
  lcd.begin(9600);
  clearDisplay();
  setLCDCursor(0);
  lcd.print("OBD");

  pinMode(servoPin1,OUTPUT);
  pinMode(servoPin2,OUTPUT);
  servo1.attach(servoPin1);
  servo2.attach(servoPin2);
  servo1.write(0);
  delay(200);
  servo2.write(100);
  delay(200);

  obd.begin();
  conn=obd.init(PROTO_AUTO);
  lcd.print("Connected");

  Wire.begin();
}

void loop() {
  conn=obd.readPID(PID_RPM,rpm);
  if (condition) {
     servo2.write(50);
    delay(500);
    servo1.write(100);
    delay(500);
  }
  Show();
  delay(1000);
}

OBD adapter
Serial LCD

You are using SoftwareSerial which turns interrupts off when sending/receiving in order to precisely time gaps between bits. The Servo library may use hardware timers, but to work on pins 12 and 13 would require interrupts to "copy" the pulses to those pins. Thus the copies will be distorted when writing to, or reading from, SoftwareSerial.
I suggest using hardware serial (pins 0 and 1) for talking to the LCDs, which does not turn interrupts off. Alternatively, implement the servo positioning using the hardware timers yourself, which (once set up) won't change the pulse widths if interrupts are turned off.

Thanks. I tried connecting the LCD data wire (pink in the schematic above) to either Tx or Rx (0 or 1) on the UNO. I removed all refs to SoftwareSerial and replaced all calls to "lcd." with "Serial." in the above code, but I'm getting garbage on the LCD. I tried different baud rates 4800,9600,19200 = all garbage. Is this the proper way to use the hardware serial?

To write to the LCD you need to use pin 1 on the board (Tx). Don't thrash around trying different baud rates, if 9600 worked with SoftwareSerial then it will work with Hardware Serial. You may need to unplug the LCD from pin 1 whilst uploading new sketches.

The servo control PWM signal is generated in HW.  So should be stable if left alone with adequate power despite what the code is doing.  Servos are analog devices.  So any perturbation in the shape or length of the wave form may affect the servo.
Consider, once the servo has reached the desired position, turning off the PWM signal which, for most servos, simply leaves them motionless where they are.


text:
Arduino IDE and subfolders
I have a sketch with multiple source files and folders arranged like so. I've divided up the project like this to keep things clean.
|
\---project
    |   project.ino
    |   types.h
    |
    +---sub1
    |       gadget1.c
    |       gadget1.h
    |       gadget2.c
    |       gadget2.h
    |
    \---blarg
            foobar.c
            foobar.h

The sketch file includes the headers via quoted include directives (rather than the lib alternative with angled brackets). This seems to work for compilation.
However, when the IDE tries to link, all references to implementations (c source files) in the subfolders generate "undefined reference" errors. Almost as if the IDE is completely ignoring the C source files.
In trying to resolve this I've discovered that apparently the handling of subfolders by the IDE seems to be all over the place. Some versions only acknowledge headers in subfolders, others work if you put everything in a "src" folder (I've also seen mention of a "utility" folder), some people suggest modifying environment variables, etc. I've even tried manually adding source files via the "sketch/add file" option which makes the files visible in the IDE but does not solve the linking problems. All these methods seem to depend on IDE version, and I couldn't distill what was the correct way vs a hack or work-around.
So my question is what is the correct/current way of organizing the above project so that it can be compiled/linked using the IDE? I am using IDE version 1.8.5 which I believe is either the latest version, or close too it.

src and util are used in library folder structure, not for project folder. 1.8.5 is current release version

I find it humorous that the other two people responding are authors of alternative IDE projects and likely don't even use the Arduino IDE. So of course they are providing erroneous information.

sorry Per. I use Sloeber, but I am not the author :-). I knew that you will write the right answer. Majenko deleted his answer

From Arduino IDE 1.6.10 onward the Arduino IDE compiles all source files in the src subfolder of the sketch and recursively through all folders under the src folder.
Support for compilation of sketch subfolders was added one or two IDE versions before 1.6.10 and was originally not limited to the src folder but a lot of problems were reported by people who had stored separate programs in subfolders of their sketch that caused compilation errors so this feature was restricted to the src subfolder only.
So if you structure a sketch like this:
foo
|_foo.ino
|_src
   |_bar.cpp
   |_bar.h

And use this #include directive in your sketch:
#include "src/bar.h"

it will work fine.

Almost as if the IDE is completely ignoring the C source files.

Arduino sketches are converted to C++ before being compiled. They are not C. If you want to use C in C++ code you need to wrap it in extern "C" {}
extern "C" {
#include "src/sub1/gadget1.h"
}

what is the correct/current way of organizing the above project

project
|_project.ino
|_types.h
|_src
   |_sub1
   |  |_gadget1.c
   |  |_gadget1.h
   |  |_gadget2.c
   |  |_gadget2.h
   |_blarg
      |_foobar.c
      |_foobar.h

not working with 1.8.12. any constellation gives me: bash: line 0: [: too many arguments cp: target 'partitions.csv' is not a directory exit status 1


text:
RGB LED strip controlled through PySerial only somewhat functional
I am trying to set up an LED-strip of 30 RGB LEDs (model WS2801). The strip is connected to an Arduino Uno and an external power supply and the goal is to send colors to the arduino using PySerial which are then shown on the LED strip.
I have been trying to wrap my head around the communications, which I am having a hard time with, especially due to the loose typing of python.
I wrote some code that generates smooth color transitions and got the strip to actually show a fairly smooth color transition, unfortunately the colors are the wrong ones.
Now I am guessing something overflows somewhere, especially since colors such as 0xFF0000 (red) show as a yellow tone, which indicates that on top of red some green gets added as well.
The Python code using pySerial:
@classmethod
def set_lights(self: RGBHardware, colors: List[int]) -> None:
    for i in range(len(colors)):
        rgb = color_to_rgb(colors[i])
        self.arduino.write(chr(76).encode()) # 'L'
        self.arduino.write(chr(i).encode())
        self.arduino.write(chr(rgb[0]).encode())
        self.arduino.write(chr(rgb[1]).encode())
        self.arduino.write(chr(rgb[2]).encode())
    self.arduino.write(chr(90).encode()) # 'Z'

@classmethod
def turn_on(self) -> None:
    self.arduino = serial.Serial('/dev/ttyACM0', 115200)
    if self.arduino.isOpen:
        self.arduino.close()
    self.arduino.open()
    pass

The code running on the Arduino Uno:
void setup() {
#if defined(__AVR_ATtiny85__) && (F_CPU == 16000000L)
  clock_prescale_set(clock_div_1); // Enable 16 MHz on Trinket
#endif

  Serial.begin(115200);
  strip.begin();
  // Update LED contents, to start they are all 'off'
  strip.show();
}

void loop() {
   while (Serial.available()) {
        uint8_t serial = Serial.read();
        if (serial == 'Z') {
            strip.show();
        } else if (serial == 'L') {
            int i = getNextInput();
            int r = getNextInput();
            int g = getNextInput();
            int b = getNextInput();
            strip.setPixelColor(i, Color(r,g,b));
        }
   }
}

uint8_t getNextInput() {
  while(!Serial.available()); // wait for a character
  return Serial.read();
}

I am having the strong feeling I am just missing a miniscule detail and it is quite frustrating.
Any help would be greatly appreciated!
EDIT:
So I recorded some data and pasted the results below. I found that always not the whole LED-strip was updated and none of it with the correct color. Once even the character "Z" seemed to go missing (that causes the strip to fully refresh) so no color was showing at all.
What I also forgot to mention earlier was that I am using Celery in Python to do the light switching as a background task.
To record the results I used
print("i, R,G,B: " + str(i) + ", " + str(rgb[0]) + "," + str(rgb[1]) + "," + str(rgb[2])) to print the data in python and
Serial.println("i, R,G,B: " + String(i) + ", " + String(r) + "," + String(g) + "," + String(b)); to do the same on the Arduino.
Sending color red from Python:
[2018-07-23 16:13:57,121: WARNING/ForkPoolWorker-7] i, R,G,B: 0, 255,0,0
[2018-07-23 16:13:57,122: WARNING/ForkPoolWorker-7] i, R,G,B: 1, 255,0,0
[2018-07-23 16:13:57,123: WARNING/ForkPoolWorker-7] i, R,G,B: 2, 255,0,0
[2018-07-23 16:13:57,125: WARNING/ForkPoolWorker-7] i, R,G,B: 3, 255,0,0
[2018-07-23 16:13:57,126: WARNING/ForkPoolWorker-7] i, R,G,B: 4, 255,0,0
[2018-07-23 16:13:57,127: WARNING/ForkPoolWorker-7] i, R,G,B: 5, 255,0,0
[2018-07-23 16:13:57,127: WARNING/ForkPoolWorker-7] i, R,G,B: 6, 255,0,0
[2018-07-23 16:13:57,128: WARNING/ForkPoolWorker-7] i, R,G,B: 7, 255,0,0
[2018-07-23 16:13:57,129: WARNING/ForkPoolWorker-7] i, R,G,B: 8, 255,0,0
[2018-07-23 16:13:57,129: WARNING/ForkPoolWorker-7] i, R,G,B: 9, 255,0,0
[2018-07-23 16:13:57,131: WARNING/ForkPoolWorker-7] i, R,G,B: 10, 255,0,0
[2018-07-23 16:13:57,132: WARNING/ForkPoolWorker-7] i, R,G,B: 11, 255,0,0
[2018-07-23 16:13:57,132: WARNING/ForkPoolWorker-7] i, R,G,B: 12, 255,0,0
[2018-07-23 16:13:57,133: WARNING/ForkPoolWorker-7] i, R,G,B: 13, 255,0,0
[2018-07-23 16:13:57,134: WARNING/ForkPoolWorker-7] i, R,G,B: 14, 255,0,0
[2018-07-23 16:13:57,136: WARNING/ForkPoolWorker-7] i, R,G,B: 15, 255,0,0
[2018-07-23 16:13:57,137: WARNING/ForkPoolWorker-7] i, R,G,B: 16, 255,0,0
[2018-07-23 16:13:57,139: WARNING/ForkPoolWorker-7] i, R,G,B: 17, 255,0,0
[2018-07-23 16:13:57,140: WARNING/ForkPoolWorker-7] i, R,G,B: 18, 255,0,0
[2018-07-23 16:13:57,141: WARNING/ForkPoolWorker-7] i, R,G,B: 19, 255,0,0
[2018-07-23 16:13:57,142: WARNING/ForkPoolWorker-7] i, R,G,B: 20, 255,0,0
[2018-07-23 16:13:57,144: WARNING/ForkPoolWorker-7] i, R,G,B: 21, 255,0,0
[2018-07-23 16:13:57,145: WARNING/ForkPoolWorker-7] i, R,G,B: 22, 255,0,0
[2018-07-23 16:13:57,146: WARNING/ForkPoolWorker-7] i, R,G,B: 23, 255,0,0
[2018-07-23 16:13:57,147: WARNING/ForkPoolWorker-7] i, R,G,B: 24, 255,0,0
[2018-07-23 16:13:57,148: WARNING/ForkPoolWorker-7] i, R,G,B: 25, 255,0,0
[2018-07-23 16:13:57,149: WARNING/ForkPoolWorker-7] i, R,G,B: 26, 255,0,0
[2018-07-23 16:13:57,150: WARNING/ForkPoolWorker-7] i, R,G,B: 27, 255,0,0
[2018-07-23 16:13:57,151: WARNING/ForkPoolWorker-7] i, R,G,B: 28, 255,0,0
[2018-07-23 16:13:57,151: WARNING/ForkPoolWorker-7] i, R,G,B: 29, 255,0,0

Received color red on the arduino:
i, R,G,B: 0, 195,191,0
i, R,G,B: 1, 195,191,0
i, R,G,B: 2, 195,191,0
i, R,G,B: 3, 195,191,0
i, R,G,B: 4, 195,191,0
i, R,G,B: 5, 195,191,0
i, R,G,B: 6, 195,191,0
i, R,G,B: 7, 195,191,0
i, R,G,B: 8, 195,191,0
i, R,G,B: 9, 195,191,0
i, R,G,B: 10, 195,191,0
i, R,G,B: 11, 195,191,0
i, R,G,B: 12, 195,191,0
i, R,G,B: 13, 195,191,0
i, R,G,B: 14, 195,191,0
i, R,G,B: 15, 195,191,0
i, R,G,B: 16, 195,191,0
i, R,G,B: 17, 195,191,0
i, R,G,B: 18, 195,191,0
i, R,G,B: 19, 195,191,0
i, R,G,B: 20, 195,191,0
i, R,G,B: 21, 195,191,0
i, R,G,B: 22, 195,191,0
i, R,G,B: 23, 195,191,0
i, R,G,B: 24, 195,191,0
i, R,G,B: 25, 195,191,0
i, R,G,B: 26, 76,27,195

Sending color green from Python:
[2018-07-23 16:22:34,374: WARNING/ForkPoolWorker-8] i, R,G,B: 0, 0,255,0
[2018-07-23 16:22:34,376: WARNING/ForkPoolWorker-8] i, R,G,B: 1, 0,255,0
[2018-07-23 16:22:34,377: WARNING/ForkPoolWorker-8] i, R,G,B: 2, 0,255,0
[2018-07-23 16:22:34,378: WARNING/ForkPoolWorker-8] i, R,G,B: 3, 0,255,0
[2018-07-23 16:22:34,380: WARNING/ForkPoolWorker-8] i, R,G,B: 4, 0,255,0
[2018-07-23 16:22:34,381: WARNING/ForkPoolWorker-8] i, R,G,B: 5, 0,255,0
[2018-07-23 16:22:34,382: WARNING/ForkPoolWorker-8] i, R,G,B: 6, 0,255,0
[2018-07-23 16:22:34,383: WARNING/ForkPoolWorker-8] i, R,G,B: 7, 0,255,0
[2018-07-23 16:22:34,384: WARNING/ForkPoolWorker-8] i, R,G,B: 8, 0,255,0
[2018-07-23 16:22:34,385: WARNING/ForkPoolWorker-8] i, R,G,B: 9, 0,255,0
[2018-07-23 16:22:34,386: WARNING/ForkPoolWorker-8] i, R,G,B: 10, 0,255,0
[2018-07-23 16:22:34,387: WARNING/ForkPoolWorker-8] i, R,G,B: 11, 0,255,0
[2018-07-23 16:22:34,387: WARNING/ForkPoolWorker-8] i, R,G,B: 12, 0,255,0
[2018-07-23 16:22:34,388: WARNING/ForkPoolWorker-8] i, R,G,B: 13, 0,255,0
[2018-07-23 16:22:34,389: WARNING/ForkPoolWorker-8] i, R,G,B: 14, 0,255,0
[2018-07-23 16:22:34,389: WARNING/ForkPoolWorker-8] i, R,G,B: 15, 0,255,0
[2018-07-23 16:22:34,390: WARNING/ForkPoolWorker-8] i, R,G,B: 16, 0,255,0
[2018-07-23 16:22:34,390: WARNING/ForkPoolWorker-8] i, R,G,B: 17, 0,255,0
[2018-07-23 16:22:34,391: WARNING/ForkPoolWorker-8] i, R,G,B: 18, 0,255,0
[2018-07-23 16:22:34,392: WARNING/ForkPoolWorker-8] i, R,G,B: 19, 0,255,0
[2018-07-23 16:22:34,393: WARNING/ForkPoolWorker-8] i, R,G,B: 20, 0,255,0
[2018-07-23 16:22:34,393: WARNING/ForkPoolWorker-8] i, R,G,B: 21, 0,255,0
[2018-07-23 16:22:34,394: WARNING/ForkPoolWorker-8] i, R,G,B: 22, 0,255,0
[2018-07-23 16:22:34,395: WARNING/ForkPoolWorker-8] i, R,G,B: 23, 0,255,0
[2018-07-23 16:22:34,395: WARNING/ForkPoolWorker-8] i, R,G,B: 24, 0,255,0
[2018-07-23 16:22:34,396: WARNING/ForkPoolWorker-8] i, R,G,B: 25, 0,255,0
[2018-07-23 16:22:34,397: WARNING/ForkPoolWorker-8] i, R,G,B: 26, 0,255,0
[2018-07-23 16:22:34,398: WARNING/ForkPoolWorker-8] i, R,G,B: 27, 0,255,0
[2018-07-23 16:22:34,398: WARNING/ForkPoolWorker-8] i, R,G,B: 28, 0,255,0
[2018-07-23 16:22:34,399: WARNING/ForkPoolWorker-8] i, R,G,B: 29, 0,255,0

Received color green on the Arduino:
i, R,G,B: 0, 0,195,191
i, R,G,B: 1, 0,195,191
i, R,G,B: 2, 0,195,191
i, R,G,B: 3, 0,195,191
i, R,G,B: 4, 0,195,191
i, R,G,B: 5, 0,195,191
i, R,G,B: 6, 0,195,191
i, R,G,B: 7, 0,195,191
i, R,G,B: 8, 0,195,191
i, R,G,B: 9, 0,195,191
i, R,G,B: 10, 0,195,191
i, R,G,B: 11, 0,195,191
i, R,G,B: 12, 0,195,191
i, R,G,B: 13, 0,195,191
i, R,G,B: 14, 0,195,191
i, R,G,B: 15, 0,195,191
i, R,G,B: 16, 0,195,191
i, R,G,B: 17, 0,195,191
i, R,G,B: 18, 0,195,191
i, R,G,B: 19, 0,195,191
i, R,G,B: 20, 0,195,191
i, R,G,B: 21, 0,195,191
i, R,G,B: 22, 0,195,191
i, R,G,B: 23, 0,195,191
i, R,G,B: 24, 0,195,191
i, R,G,B: 25, 0,195,191
i, R,G,B: 26, 76,28,0

Sending color blue from Python:
[2018-07-23 16:26:52,416: WARNING/ForkPoolWorker-2] i, R,G,B: 0, 0,0,255
[2018-07-23 16:26:52,416: WARNING/ForkPoolWorker-2] i, R,G,B: 1, 0,0,255
[2018-07-23 16:26:52,417: WARNING/ForkPoolWorker-2] i, R,G,B: 2, 0,0,255
[2018-07-23 16:26:52,417: WARNING/ForkPoolWorker-2] i, R,G,B: 3, 0,0,255
[2018-07-23 16:26:52,418: WARNING/ForkPoolWorker-2] i, R,G,B: 4, 0,0,255
[2018-07-23 16:26:52,418: WARNING/ForkPoolWorker-2] i, R,G,B: 5, 0,0,255
[2018-07-23 16:26:52,419: WARNING/ForkPoolWorker-2] i, R,G,B: 6, 0,0,255
[2018-07-23 16:26:52,419: WARNING/ForkPoolWorker-2] i, R,G,B: 7, 0,0,255
[2018-07-23 16:26:52,420: WARNING/ForkPoolWorker-2] i, R,G,B: 8, 0,0,255
[2018-07-23 16:26:52,420: WARNING/ForkPoolWorker-2] i, R,G,B: 9, 0,0,255
[2018-07-23 16:26:52,421: WARNING/ForkPoolWorker-2] i, R,G,B: 10, 0,0,255
[2018-07-23 16:26:52,421: WARNING/ForkPoolWorker-2] i, R,G,B: 11, 0,0,255
[2018-07-23 16:26:52,422: WARNING/ForkPoolWorker-2] i, R,G,B: 12, 0,0,255
[2018-07-23 16:26:52,422: WARNING/ForkPoolWorker-2] i, R,G,B: 13, 0,0,255
[2018-07-23 16:26:52,423: WARNING/ForkPoolWorker-2] i, R,G,B: 14, 0,0,255
[2018-07-23 16:26:52,423: WARNING/ForkPoolWorker-2] i, R,G,B: 15, 0,0,255
[2018-07-23 16:26:52,424: WARNING/ForkPoolWorker-2] i, R,G,B: 16, 0,0,255
[2018-07-23 16:26:52,424: WARNING/ForkPoolWorker-2] i, R,G,B: 17, 0,0,255
[2018-07-23 16:26:52,425: WARNING/ForkPoolWorker-2] i, R,G,B: 18, 0,0,255
[2018-07-23 16:26:52,426: WARNING/ForkPoolWorker-2] i, R,G,B: 19, 0,0,255
[2018-07-23 16:26:52,427: WARNING/ForkPoolWorker-2] i, R,G,B: 20, 0,0,255
[2018-07-23 16:26:52,427: WARNING/ForkPoolWorker-2] i, R,G,B: 21, 0,0,255
[2018-07-23 16:26:52,428: WARNING/ForkPoolWorker-2] i, R,G,B: 22, 0,0,255
[2018-07-23 16:26:52,428: WARNING/ForkPoolWorker-2] i, R,G,B: 23, 0,0,255
[2018-07-23 16:26:52,429: WARNING/ForkPoolWorker-2] i, R,G,B: 24, 0,0,255
[2018-07-23 16:26:52,429: WARNING/ForkPoolWorker-2] i, R,G,B: 25, 0,0,255
[2018-07-23 16:26:52,430: WARNING/ForkPoolWorker-2] i, R,G,B: 26, 0,0,255
[2018-07-23 16:26:52,430: WARNING/ForkPoolWorker-2] i, R,G,B: 27, 0,0,255
[2018-07-23 16:26:52,431: WARNING/ForkPoolWorker-2] i, R,G,B: 28, 0,0,255
[2018-07-23 16:26:52,431: WARNING/ForkPoolWorker-2] i, R,G,B: 29, 0,0,255

Received color blue on the Arduino:
i, R,G,B: 0, 0,0,195
i, R,G,B: 1, 0,0,195
i, R,G,B: 2, 0,0,195
i, R,G,B: 3, 0,0,195
i, R,G,B: 4, 0,0,195
i, R,G,B: 5, 0,0,195
i, R,G,B: 6, 0,0,195
i, R,G,B: 7, 0,0,195
i, R,G,B: 8, 0,0,195
i, R,G,B: 9, 0,0,195
i, R,G,B: 10, 0,0,195
i, R,G,B: 11, 0,0,195
i, R,G,B: 12, 0,0,195
i, R,G,B: 13, 0,0,195
i, R,G,B: 14, 0,0,195
i, R,G,B: 15, 0,0,195
i, R,G,B: 16, 0,0,195
i, R,G,B: 17, 0,0,195
i, R,G,B: 18, 0,0,195
i, R,G,B: 20, 0,0,195
i, R,G,B: 23, 191,76,26

Sending color orange from Python:
[2018-07-23 16:29:20,725: WARNING/ForkPoolWorker-9] i, R,G,B: 0, 255,128,0
[2018-07-23 16:29:20,726: WARNING/ForkPoolWorker-9] i, R,G,B: 1, 255,128,0
[2018-07-23 16:29:20,727: WARNING/ForkPoolWorker-9] i, R,G,B: 2, 255,128,0
[2018-07-23 16:29:20,728: WARNING/ForkPoolWorker-9] i, R,G,B: 3, 255,128,0
[2018-07-23 16:29:20,729: WARNING/ForkPoolWorker-9] i, R,G,B: 4, 255,128,0
[2018-07-23 16:29:20,731: WARNING/ForkPoolWorker-9] i, R,G,B: 5, 255,128,0
[2018-07-23 16:29:20,732: WARNING/ForkPoolWorker-9] i, R,G,B: 6, 255,128,0
[2018-07-23 16:29:20,733: WARNING/ForkPoolWorker-9] i, R,G,B: 7, 255,128,0
[2018-07-23 16:29:20,734: WARNING/ForkPoolWorker-9] i, R,G,B: 8, 255,128,0
[2018-07-23 16:29:20,735: WARNING/ForkPoolWorker-9] i, R,G,B: 9, 255,128,0
[2018-07-23 16:29:20,736: WARNING/ForkPoolWorker-9] i, R,G,B: 10, 255,128,0
[2018-07-23 16:29:20,737: WARNING/ForkPoolWorker-9] i, R,G,B: 11, 255,128,0
[2018-07-23 16:29:20,738: WARNING/ForkPoolWorker-9] i, R,G,B: 12, 255,128,0
[2018-07-23 16:29:20,739: WARNING/ForkPoolWorker-9] i, R,G,B: 13, 255,128,0
[2018-07-23 16:29:20,740: WARNING/ForkPoolWorker-9] i, R,G,B: 14, 255,128,0
[2018-07-23 16:29:20,741: WARNING/ForkPoolWorker-9] i, R,G,B: 15, 255,128,0
[2018-07-23 16:29:20,742: WARNING/ForkPoolWorker-9] i, R,G,B: 16, 255,128,0
[2018-07-23 16:29:20,743: WARNING/ForkPoolWorker-9] i, R,G,B: 17, 255,128,0
[2018-07-23 16:29:20,744: WARNING/ForkPoolWorker-9] i, R,G,B: 18, 255,128,0
[2018-07-23 16:29:20,744: WARNING/ForkPoolWorker-9] i, R,G,B: 19, 255,128,0
[2018-07-23 16:29:20,745: WARNING/ForkPoolWorker-9] i, R,G,B: 20, 255,128,0
[2018-07-23 16:29:20,746: WARNING/ForkPoolWorker-9] i, R,G,B: 21, 255,128,0
[2018-07-23 16:29:20,747: WARNING/ForkPoolWorker-9] i, R,G,B: 22, 255,128,0
[2018-07-23 16:29:20,747: WARNING/ForkPoolWorker-9] i, R,G,B: 23, 255,128,0
[2018-07-23 16:29:20,749: WARNING/ForkPoolWorker-9] i, R,G,B: 24, 255,128,0
[2018-07-23 16:29:20,750: WARNING/ForkPoolWorker-9] i, R,G,B: 25, 255,128,0
[2018-07-23 16:29:20,750: WARNING/ForkPoolWorker-9] i, R,G,B: 26, 255,128,0
[2018-07-23 16:29:20,751: WARNING/ForkPoolWorker-9] i, R,G,B: 27, 255,128,0
[2018-07-23 16:29:20,752: WARNING/ForkPoolWorker-9] i, R,G,B: 28, 255,128,0
[2018-07-23 16:29:20,752: WARNING/ForkPoolWorker-9] i, R,G,B: 29, 255,128,0

Received color orange on the Arduino:
i, R,G,B: 0, 195,191,194
i, R,G,B: 1, 195,191,194
i, R,G,B: 2, 195,191,194
i, R,G,B: 3, 195,191,194
i, R,G,B: 4, 195,191,194
i, R,G,B: 5, 195,191,194
i, R,G,B: 6, 195,191,194
i, R,G,B: 7, 195,191,194
i, R,G,B: 8, 195,191,194
i, R,G,B: 9, 195,191,194
i, R,G,B: 10, 195,191,194
i, R,G,B: 11, 195,191,194
i, R,G,B: 12, 195,191,194
i, R,G,B: 13, 195,191,194
i, R,G,B: 14, 195,191,194
i, R,G,B: 15, 195,191,194
i, R,G,B: 16, 195,191,194
i, R,G,B: 17, 195,191,194
i, R,G,B: 18, 195,191,194
i, R,G,B: 19, 195,191,194
i, R,G,B: 76, 23,195,191
i, R,G,B: 194, 128,0,76

Received color orange on the Arduino (again):
i, R,G,B: 0, 195,191,194
i, R,G,B: 1, 195,191,194
i, R,G,B: 2, 195,191,194
i, R,G,B: 3, 195,191,194
i, R,G,B: 4, 195,191,194
i, R,G,B: 5, 195,191,194
i, R,G,B: 6, 195,191,194
i, R,G,B: 7, 195,191,194
i, R,G,B: 8, 195,191,194
i, R,G,B: 9, 195,191,194
i, R,G,B: 10, 195,191,194
i, R,G,B: 11, 195,191,194
i, R,G,B: 12, 195,191,194
i, R,G,B: 13, 195,191,194
i, R,G,B: 14, 195,191,194
i, R,G,B: 15, 195,191,194
i, R,G,B: 16, 195,191,194
i, R,G,B: 17, 195,191,194
i, R,G,B: 18, 195,191,194
i, R,G,B: 128, 0,76,24
i, R,G,B: 27, 195,191,194

Another Edit:
What is also interesting is that the main color (e.g. when I send red most of the LEDs are yellow) stays the same every time I tried.
But the amount of LEDs that gets passed differs with each try. The same goes for the last one or two LEDs the Arduino receives. Their colors and indexes are all over the place.

generates smooth color transitions .... do not send transitions ..... send discrete colors to the whole string  0xFF0000, 0x00FF00, 0x0000FF, 0xFFFF00 ... etc ...............document the resulting color ...... check color value on the web ....  http://html-color-codes.com/       ................ update your question with results

Red and green produce yellow. I think you are seeing cyan 0x00FFFF. It kind of looks like the bits are inverted.

@jsotola I added some sample data, maybe you could take a look again?

@Gerben That was a mistake on my end, red actually show up as yellow on the strip.

Try using a lower baudrate and see if the problem persists.

You don't seem to be using the bytes correctly

@Gerben Thank you, after reducing the baud rate to 57600 all lights look the same (still the same wrong color though). Unfortunately the weird behavior persists if I leave the color printing on, so apparently the Arduino Uno is a little too weak for doing both.

@esoterik Can you elaborate?

@smoelge chr(rgb[0]).encode() is a little bit obtuse; you are making an arbitrary chcaracer of an int, then encoding it, when you should just call .to_bytes on it. ex. rgb[0].to_bytes(1,'big') or simple convert all 3 at once with bytes(rgb)

@smoelge, you have to start at bottom and work your way up .... remove all code that has anything to do with the LEDs  .... send only single bytes and receive only single bytes, with a pause in between ..... if that has no errors, then send two bytes and test again .... reinsert the LED code only after the serial comm is reliable

This
...
  self.arduino.write(chr(76).encode()) # 'L'
  self.arduino.write(chr(i).encode())
  self.arduino.write(chr(rgb[0]).encode())
  self.arduino.write(chr(rgb[1]).encode())
  self.arduino.write(chr(rgb[2]).encode())
self.arduino.write(chr(90).encode()) # 'Z'
...

should be spelled:
  self.arduino.write(b'L')
  self.arduino.write(i.to_bytes(1,'big'))
  self.arduino.write(bytes(rgb))
self.arduino.write(b'Z')

It is much more readable this way; you could refactor even further:
  sout = b'L' + i.to_bytes(1,'big') + bytes(rgb)
  self.arduino.write(sout)
self.arduino.write(b'Z')

Your also wasting effort here:
Serial.println("i, R,G,B: " + String(i) + ", " + String(r) + "," + String(g) + "," + String(b));

This should be said more like this:
Serial.print(i);
Serial.print(", ");
Serial.print(r);
Serial.print(", ");
Serial.print(g);
Serial.print(", ");
Serial.println(b);

This eliminates three temporary String objects you were creating with String().
The rest of the code looks like it should work so you should try trouble shooting, you could:

Lower the baud rate till it works
Try 9600 baud and increase it until it stops working
Try the a serial sample program, make sure the serial portion is working correctly first
Write your own minimal test program, make sure the serial is working correctly at first.

Thank you very much, this worked perfectly.
And you are completely right about the String concatenation, I wasn't really paying attention to performance, due to those values just being printed for debugging.


text:
In the latest version of Arduino Desktop IDE, are there all features of Arduino Web Editor?
I would like to know if there are always the latest features in Arduino Desktop IDE if I update it every day.
I mean if there is a new feature in Arduino Web Editor, can I get it on Arduino Desktop IDE?

A new GUI feature, or a new feature of the language / API?

Is it possible to know for both?

How are you updating it? The Arduino IDE beta build is actually a little more closely aligned with the Arduino Web Editor because they both use arduino-preprocessor. The hourly build of the IDE does not currently use arduino-preprocessor (this will change as soon as some serious bugs in arduino-preprocessor are resolved). Arduino Web Editor users are actually unknowing beta testers for the unfinished arduino-preprocessor.

You will always get the same API features in both, because the API is separate to both of them - it's a plugin that's developed separately.
Would you get the same GUI facilities? No idea. Maybe - maybe not. It depends how useful they would be. You may get features added to the GUI that don't appear on the web. Or you may get the other way around. If they are essential to the operation of the system, though, you will get them added to both.


text:
Do I need an external power supply for the SG90 micro servo?
I have a Uno R3 and although I can add an external power supply for the SG90 micro servo it would make the project more complicated. Can I power the servo using the 5v pin of the Uno R3?
I measured the current and it does not seem to pass 160mA and in normal use, it uses only 60mA.

I'm not sure if the data sheet for every SG90 servo is the same, but if you look at this one, SG90 Specifications, you'll see the "stall current" can be between 570mA and 730mA. You may want to test your servo under this condition before deciding to power it with an Uno.

Does your servo have to push or pull anything? Or is this just to practice writing code for an unattached SG90 and see it move? If it's the former, the servo will draw more current than an Arduino can deliver so you'd need a separate power supply. If it's the latter, you can get away with it. The SG90 is about the least demanding (of current) servo available and you can drive an unloaded one directly off the Arduino. It's current-peaks should be short enough to limit thermal damage to the Arduino pin driver. Just make short test runs and don't leave it see-sawing for any length of time.


text:
What is the difference between Arduino board and Genuino Board?
I've got an Arduino UNO REV3 SMD EDITION.
In the Arduino Editor, I've selected Arduino/Genuino Uno.
In a tutorial, I saw Hardware required : Arduino or Genuino Board
What is the difference between Arduino board and Genuino Board?

The name Genuino grew out of the split between Massimo and Gianluca (aided in part by Microsoft of course, and a trademark wrangle that went wrong). Each side wanted to appear to be more "genuine" than the other. That lead to the "Genuino" name (a genuine Arduino), and a version number war with the IDE.
Both sides started making their own variants of boards, with some only available from the USA (Arduino) and others only outside the USA (Genuino).
Since they have patched up their differences now the two boards are one and the same. A Genuino Uno and an Arduino Uno are the exact same board. They always have been, there has just been arguments over the name.

At this moment I think people use term "Genuino" to describe the "original board" from official website, and "Arduino" as "any compatible board" including the 2$ Chinese clones.

Not so. I see Arduino as the originally made boards, and clone as anything else. Arduino's use Atmega16U2 (Uno & Mega) or FT232 (Nano) for USB/Serial, while $2 clones use CH340g for that purpose. I use FT232 or FT232 modules in my designs as the US distributors do not carry CH340g chips, and I won't design in parts I cannot source from reputable suppliers.


text:
Do I need to power off the Arduino board before doing something?
Is it safe to build a circuit while the Arduino board is powered?
Should I power the board only when I have to upload the program?

which switch are you talking about?

Don't be like me, but I keep my Arduino (made in china) connected via USB to my laptop when prototyping. Many times I short pins to ground accidentally, but fortunately my laptop has builtin overcurrent protection on USBs to 500mA. If it didn't the ports (or arduino pins) would be fried long time ago. To break the board all it takes is to connect arduino pin physically to ground, and then accidentally in code assign it as output (instead of input) and set to 5V.

@FilipFranik Even if Arduino boards are inexpensive (like the clone you mention sourced from China), it's no excuse for poor practice.

It is not safe, as you may accidentally connect some points, which should not be connected and destroy Arduino and/or any other part of circuit. typically legs of resistors/LEDs tends to touch other legs near them, when you are putting it in - and if it is powered, magical smoke can happened easily.
Even if you do not this kind of mistake, not everything can be put in random order without risc of damage.
So everytime you change something with circuit, disconnect power source/USB first. And if you have big capacitors anywhere, you better make sure, they are discharged too.
You switch on the board, when the building is done and you want to program it, or use the already present program.

It can be dangerous, not only to the Arduino, but to whatever you are connecting, if you do so with the power applied.
Current can end up flowing where it shouldn't, and components can become damaged.
However if it's something as simple as an LED then it really doesn't matter.


text:
How to properly link an Arduino and its sensors
To finalize a prototype, I would like to have a proper structure containing the arduino (uno here), its shields and its sensors. I would like the sensors to be soldered to the arduino+shields block, but the sensors were sold on a small separate PCB (example).
What is the recommended method to have a strong, clean link between the two ?

You could solder those modules to a prototype shield.  If you replace the header with a right-angle one (or even just bend the pins on the existing one) you could even mount it vertically to save space.

Prototype shield:

Right-angled headers:

This sounds right. I would be glad if you could illustrate with pictures so that it is perfectly clear, though. Thank you

I tried to find a picture online but couldn't. You may be the first to do it :)

A prototype shield has a matrix of holes like a breadboard - except you solder them. The breakout board has pins. The pins go in the holes, and you solder it. Then you solder wires between those soldered pins and the Arduino header pins. If you want more than one module and the pins are only on one side, then use right angled pins so the breakout board sticks up in the air.

In effect treat the breakout board like any other component. It's just a little larger than most.

You can create a pretty good quality DIY "prototype shield" (shields are expensive) like here https://startingelectronics.org/projects/arduino-projects/arduino-tiny-stripboard-shield/


text:
Reconstruct uint32_t from char array to RTC.set
I am currently experimenting with a Digistump ATTiny85. Since it has no Serial, I use the basic DigiUSB library for communication. The RTC library used is this one: https://github.com/JChristensen/DS3232RTC/. The DigiUSB library is from Digispark.
I attached a DS3232 via TWI to the Digistump, because I want to use this construct as a USB-Realtime-Clock.
Initially setting the time in the setup method works as follows
  RTC.set(1532341020);

But I am unable to transfer the time via the pseudo serial connection and set it remotely. What I've tried so far:

Using union with char and uint32_t. Althougt the char representation is correct (tried DigiUSB.println()), the uint32_t representation of this union is not what I need.
Tried to adapt to some shifting examples, but seriously got lost here. All examples where about 4 byte streams.
atoi and some other functions with no success.

Here is my current sketch
#include <DS3232RTC.h>
#include <DigiUSB.h>

//union ArrayToInteger {
//  char array[10];
//  uint32_t integer;
//};

unsigned char foo[10];
uint32_t num;

void setup() {
  RTC.begin();
  //RTC.set(1532341020);
  DigiUSB.begin();
}

void loop() {
  if (DigiUSB.available() >= 10) {
    for (int i=0; i<=10; i++) {
    foo[i] = DigiUSB.read();
  }
  RTC.set((uint32_t)foo);
  DigiUSB.delay(100);
  DigiUSB.refresh();
  //DigiUSB.println(_foo.array);
  DigiUSB.println(RTC.get());
} else {
  DigiUSB.refresh();
  DigiUSB.println(RTC.get());
  DigiUSB.refresh();
  DigiUSB.delay(1000);
  }
}

In the end I need the a char _foo 0123456789 represented as/converted to uint32_t num 0123456789
Kinda stuck here. Can anyone point me in the right direction ore provide an example?

add links to libraries. a number representation of time with RTC is 'Epoch' - seconds from 1.1.1970. what do you mean by "char representation"?

You may try atol(), but note that from Jan 19 2038 you will need to use strtoul() instead.

how do you send the epoch value?

@EdgarBonet atol errors invalid conversion from 'unsigned char*' to 'const char*'. Same with strtoul.

if (DigiUSB.available()) { time_t epoch = DigiUSB.parseInt(); RTC.set(epoch);}?

@Juraj DigiUSB does not support .parseInt.

Don't make foo unsigned.

@EdgarBonet Thanks. Already fixed that. But when I do RTC.set(atol(foo)) it does not set the time correctly.

Answering this question based on the help from above. It works with this code. Thank you all for the help. The clock does not reply the newly set time instantly, but after a few seconds.
#include <DS3232RTC.h>
#include <DigiUSB.h>
char foo[10];

void setup() {
  RTC.begin();
  DigiUSB.begin();
}

 void loop() {
   if (DigiUSB.available() >= 10) {
     for (int i=0; i<=10; i++) {
       foo[i] = DigiUSB.read();
   }
   RTC.set(atol(foo));
   DigiUSB.delay(100);
   DigiUSB.refresh();
   DigiUSB.println(RTC.get());
} else {
   DigiUSB.refresh();
   DigiUSB.println(RTC.get());
   DigiUSB.refresh();
   DigiUSB.delay(1000);
   }
}

There are several possible issues here:

can you send the number, as a string, from the PC to the ATtiny?
can you convert the string to an actual number?
can you give this number to the RTC?

The phrasing of your question sounds like your issue is with the
conversion. However that is easily handled with atol(). Here is a test
program I tried on my Uno:
void setup() {
    char time_string[] = "1532341020";
    uint32_t time_number = atol(time_string);

    Serial.begin(9600);
    Serial.print("string: \"");
    Serial.print(time_string);
    Serial.print("\", number = ");
    Serial.println(time_number);
}

The output is:
string: "1532341020", number = 1532341020

Indeed atol does the trick. For completeness, I answered by posting the working code. Thanks for input.


text:
Rc car controller using the RC-switch library

simulate this circuit – Schematic created using CircuitLab
(Newbie in arduino)
Hi so i have a project which involves creating an rc car which uses the 433Mhz rf module and an arduino nano with a servo motor and an ultrasonic parking sensor.
I'm having problems with the code both on the transmitter and receiver,
Here is the code for the transmitter.
 #include <RCSwitch.h>
RCSwitch mySwitch = RCSwitch();
// Assigning controller buttons to Digital Pins
 const int forward = 8;
 const int reverse = 9;
 const int rightTurn = 10;
 const int leftTurn = 11;

 int Fwd = 0
 int Bwd = 0
 int Lt  = 0
 int Rt  = 0

void setup () {
  pinMode (forward, INPUT);
  pinMode (reverse, INPUT);
  pinMode (rightTurn, INPUT);
  pinMode (leftTurn, INPUT);
  mySwitch.enableTransmit(7);
  Serial.begin (9600);         // Debugging only
  Serial.println ("Transmitting");
}

void loop () {
  Fwd = digitalRead(forward);
  Bwd = digitalRead(reverse);
  Rt  = digitalRead(rightTurn);
  Lt  = digitalRead(leftTurn);

  if (Fwd == HIGH) {
    mySwitch.send('1');
    Serial.println ("Forward");
    delay(100);
  }

  if (Bwd == HIGH) {
    mySwitch.send('2');
    Serial.println ("Reverse");
    delay(100);
  }

  if (Rt == HIGH) {
    mySwitch.send('3');
    Serial.println ("Left Turn");
    delay(100);
  }

  if (Lt == HIGH) {
    mySwitch.send('4');
    Serial.println ("Right Turn");
    delay(100);
  }
}

And here's the code for the receiver
#include <RCSwitch.h>
#include <Servo.h>

const int IN1 = 3;
const int IN2 = 4;
const int trigPin = 5;
const int echoPin = 6;
int distance = 0;

RCSwitch mySwitch = RCSwitch();
Servo myservo;

void setup () {
  mySwitch.enableReceive(2);
  myservo.attach(7);
  pinMode(IN1, OUTPUT);
  pinMode(IN2, OUTPUT);
  pinMode(trigPin, OUTPUT); // Sets the trigPin as an Output
  pinMode(echoPin, INPUT); // Sets the echoPin as an Input
  Serial.begin (9600);    // Debugging only
  Serial.println ("Receiver Ready");
}

void loop () {
 if (mySwitch.available()) {

    int value = mySwitch.getReceivedValue();

      if(value == '1') {
        forward ();
        Serial.println (" = forward");
      }

      if(value == '2'){
        backward ();
        Serial.println (" = backward");
      }

      if(value == '3') {
        left ();
        Serial.println (" = left");
      }

      if(value == '4') {
        right ();
        Serial.println (" = right");
      }
      Serial.print(" ");
    }

}

void forward () {
  digitalWrite (IN1, LOW);
  digitalWrite (IN2, HIGH);
}
long duration;
int value = mySwitch.getReceivedValue();
void backward () {
  if ((distance > 10)&& (value == '2'))
  {
  digitalWrite (IN1, LOW);
  digitalWrite (IN2, LOW);
  }
  else if ((distance < 10)&& (value == '2'))
  {
  digitalWrite (IN1, HIGH);
  digitalWrite (IN2, LOW);
  }
  delayMicroseconds(10);
  // Clears the trigPin
  digitalWrite(trigPin, LOW);
  delayMicroseconds(2);
  // Sets the trigPin on HIGH state for 10 micro seconds
  digitalWrite(trigPin, HIGH);
  delayMicroseconds(10);
  digitalWrite(trigPin, LOW);
  // Reads the echoPin, returns the sound wave travel time in microseconds
  duration = pulseIn(echoPin, HIGH);
  // Calculating the distance
  distance= duration*0.034/2;
  // Prints the distance on the Serial Monitor
  Serial.print("Distance: ");
  Serial.println(distance); //distance is the returned integer,
}

void right () {
  myservo.write(0);
  digitalWrite (IN1, LOW);
  digitalWrite (IN2, HIGH);
}

void left () {
  myservo.write(90);
  digitalWrite (IN1, LOW);
  digitalWrite (IN2, HIGH);
}

The problem is when i run the code the buttons start getting pressed even if I'm not pressing them and even when i disconnect them from the arduino. and also the receiver cant receive any data.
Please help

Sounds as if your button pins are floating. Do you use a pulldown resistor for each button in your setup? If not, this is the problem.

ohh, yeah im not using any i just connect them to the gnd and their respective pins ,what value should i use?

Hi i added the circuit of the button

As you wrote in your comment, you didn't use  pullup or pulldown resistors for connecting the buttons. In this case the pin is floating, whenever the corresponding button is not pressed. It will pick up random noise from the environment and change it's state randomly.
A pullup or pulldown resistor defines a specific value for the pin, if the button is not pressed (LOW or HIGH). The value of such is a resistor is not critical, as long, as it isn't a too big load. Pick some value in the kiloohms (for example 10kOhm).
But you don't need external resistors for this. The Atmega328, which is the heart of the Arduino Nano, already has buildin pullup resistors for each digital output pin. You can activate them by using
pinMode(pin_number, INPUT_PULLUP);

In this case you will have to change the if-statements to check for LOW instead of HIGH and connect the button to ground instead of 5V, because with a pullup resistor in idle state the pin will be pulled up to 5V and the button can then pull it down to ground.

so i'd add another line of code with pinMode(9, 10)?

No, you have to change the lines with pinMode (forward, INPUT); and it's siblings to pinMode(forward, INPUT_PULLUP). And then you have to connect one button pin with the corresponding pin on Arduino and the other button pin to GND.

Ohh ok, thanks, i think that might solve the problem since i already have the pins of my buttons to GND and the pin it's set to on the program.

Thanks it actually solved the problem the pinMode(forward, INPUT_PULLUP) fixed it

another question, is the code for the receiver correct?


text:
For Arduino, is there a meaningful difference between carriage returns?
Serial.write(0x0d); // hex
Serial.write(13);   // ASCII
Serial.write('\r');  // char
Is one more efficient? I read how it depends on the terminal program. So does that mean the IDE? (This is my first time working with serial comm.)

It’s \r not /r.

All of them are identical. But the last one is the most readable to us humans. So I’d prefer the last one.

it depends on the terminal program ... no it does not. .... the terminal program will receive ASCII CR for each of the lines

As mentioned before they are all the same. The thing you have to rememeber is that the compiler takes the human readable code you write and turns it into the instructions the processor can understand. If you want to explore ways the compiler does thing you can compile the program into the hex file and then compare. Or for even less detail, but much easier, look at the size of the file created when you compile in the IDE
using just the one line in question inside the setup function
write(0x0d)  ----> 1334 bytes
write(13)    ----> 1334 bytes
write('\r')  ----> 1334 bytes

For this simple example we can assume that all three of these are producing the exact same hex file.   There are many more complicated example of different ways to do the same task that may produce more or less efficient code, but in this case the compiler is going to produce the same instruction set to the processor.
As pointed out in the comments, I am not saying that because they are the same size they must be the same hex code. As any single byte being written would produce the same size code, but not the same result. But when comparing two methods that we know are the same functionality ( 0x0d and '\r') and they produce the same size binary, then we can assume the compiler reduced them to the same code.

write('\t') would result in same size

yes, as would any other single byte. and without having the ability to analyze the hex file, or other ways of getting a gaining a detailed idea of how efficient the code is, you could deduce that they were equally efficient. Although there are many cases this idea would not hold. It does give a new programmer an Idea of whats going on under the hood.

Is one more efficient?

after compilation it is same for all notations. the function and the value are the same for all 3 notations.

There is no difference between all the lines of code in your question. All representations stand for one value, containing one byte. There is only one implementation of Serial::write(), which has a uint8_t as parameter. So all the different representations result in a uint8_t anyway.


text:
Can't burn Bootloader on Atmega328P Using Arduino Uno
I'm trying to create an Arduino Uno following the circuit described in the diagram below which I'd based from here.
I'd tried this circuit on an Atmega328 PDIP version (with the correct connections since the PDIP has different pinouts from this TQFP) and I was successful in creating and using my own Arduino.
However, when I've used the TQFP version and had this circuit layout and printed on a pcb, I can't burn the bootloader using an Arduino UNO.
I've double checked the pinouts from the Atmega328P datasheet and they are correct. Using a tester, I've also verified that the connections are there.
By the way, I've used the following connections.
Arduino Digital Pin 13 to SCLK
Arduino Digital Pin 12 to MISO
Arduino Digital Pin 11 to MOSI
Arduino Digital Pin 10 to RESET
Arduino 5V to VCC
Arduino GND to GND

I've also burned the ArduinoISP program on th Arduino UNO, selected Arduino as ISP and chosen Arduino UNO as board.
When I press 'Burn Bootloader', I'm getting this error message.
avrdude: Device signature = 0x000000
avrdude: Yikes!  Invalid device signature.
     Double check connections and try again, or use -F to override
     this check.

I've looked at different forums and they are only saying to check the connections which I'd already checked that there is.

I have had this problem in the past and it has always been one of two solutions

The wires were misconfigured, and I only saw it after the Nth time
Wrong chip, I was trying to program a 328 when it expected a 328p

And the secret third option:

Some chip/wire/etc. was busted/burned/bad.

Unfortunately These were the only outcomes to ever come for me when I encountered that particular error.

I've checked the connections a lot of times today and they were correct. Also, I've wrongfully placed an Atmega328PB before. Upon making necessary software changes, I've successfully burned a bootloader. It is also a correct chip now that I'm having this issue. And I've used 3 chips by now and changed a lot of wires so I would want to rule that out?

here is a Link... https://www.arduino.cc/en/Tutorial/ArduinoToBreadboard
If bootloader is burned with arduino uno in atmega328 then code will be uploaded for once and run correctly but next time you tried to burn code in atmega328 then code will not burn in atmega328. I also tried this way but it just work one time for me then I bought usbasp(price 1.5$) to burn bootloader permanently. after burning bootloader with usbasp then its works perfect for me.
Just connect crystall with filtering capacitor thats enough to burn bootloader. above config is just in case you want to use it as MCU.

That's actually the link where I'd based my circuit. Also, I've just bought the chips so I think there are no bootloaders in them. I've tried reburnong the bootloader on the Atmega328p DIP that I've used before. It's working.

The design is missing 0.1uF caps on VCC, AVCC, and Aref.
Aref should not connect to 5V directly. It is connected internally thru a mux and only needs the 0.1uF to Gnd.  If Aref is direct connected and then the sketch selects the internal 1.1V reference, it can/will damage the chip.
Change the 220 ohm resistor on D13/SCK to 1K.  220 ohm puts quite a load on the SCK line for a Programmer. 1K will result in a plenty bright LED.
Do you have a 0.1uF between DTR of a Serial programmer and the Reset pin?  A Programmer needs direct control of the Reset line, a Serial programmer (such as an FTDI Basic module) needs to go thru a cap so a Reset pulse is created.

Actually, I have a cap between VCC, AVCC and GND that I haven't included in the screenshot. Now that you've mentioned it, I'm seeing a small arc (spark) on the AREF pin. What I've done is I'd lifted the pin out to disconnect it from AVCC and VCC, and soldered a 100nF cap to GND. What it did however is create a larger arc on the pin.

Also, before, I'd ordered Atmega328PB instead of Atmega328P. I'm getting an error on device signature then. I've done some modifications based on different forums and was successful on burning a bootloader and uploading a sketch. Now, I've got the correct Atmega328P, installed on the same layout and I'm having this problem.

By arc, you mean you are seeing sparks? That's not good at all. Is your 5v line ok?

Yes, I mean spark. And I can't understand why. The 5V line is ok. Seeing some spikes on oscilloscope whenever a spark forms on the AREF pin though.


text:
storage problem
I made a Arduino program to control my air conditioner(model:GREE Lomo) by PC.
I download IRremote library from here for that.
#include "IRremote.h"

IRsend irsend;
int irPin = 3; // pin IR led

int khz = 38; // 38kHz carrier frequency for the NEC protocol

const unsigned int irSignalOn[] = {8972, 4492, 644, 1664, 640, 564, 644, 564, 640, 1668, 636, 568, 640, 1664, 644, 560, 644,
                               560, 644, 564, 640, 564, 644, 560, 644, 1664, 640, 564, 644, 564, 640, 564, 640, 1668, 640, 1664, 640, 564, 644,
                               1664, 640, 564, 644, 564, 640, 1668, 640, 1664, 640, 564, 644, 564, 640, 564, 640, 564, 644, 564, 640, 1664, 644,
                               560, 644, 1664, 640, 564, 644, 564, 640, 1668, 640, 560, 644, 19980, 640, 564, 644, 1664, 640, 1668, 640, 564, 640,
                               564, 644, 1660, 644, 560, 644, 564, 644, 560, 644, 564, 640, 564, 644, 560, 644, 564, 640, 1664, 640, 564, 644, 564,
                               640, 564, 640, 564, 644, 564, 640, 564, 644, 560, 644, 564, 640, 564, 644, 564, 640, 564, 640, 564, 644, 560, 644, 564,
                               640, 564, 640, 564, 644, 1664, 640, 564, 644, 39972, 8976, 4496, 640, 1664, 644, 560, 644, 564, 640, 1668, 640, 564, 640,
                               1668, 640, 564, 640, 564, 644, 560, 644, 564, 640, 564, 644, 1664, 640, 564, 644, 564, 640, 564, 644, 1664, 640, 1668, 640,
                               564, 640, 1668, 640, 564, 640, 564, 644, 1668, 636, 1668, 640, 564, 640, 564, 640, 564, 644, 560, 644, 564, 644, 560, 644,
                               1668, 640, 1664, 640, 564, 644, 564, 640, 1668, 640, 564, 640, 19980, 640, 564, 644, 564, 640, 564, 644, 560, 644, 564, 640,
                               564, 644, 560, 644, 564, 640, 564, 640, 564, 644, 564, 640, 1668, 636, 568, 640, 1664, 640, 564, 640, 1672, 636, 1664, 640,
                               564, 644, 564, 640, 564, 640, 1668, 640, 564, 640, 564, 640, 568, 640, 1664, 640, 564, 640, 564, 644, 564, 640, 1692, 616,
                               1664, 640, 564, 640, 1664, 640, 39980, 8972, 4492, 644, 1664, 640, 568, 636, 564, 644, 1664, 640, 564, 640, 1668, 640, 564,
                               640, 564, 644, 564, 640, 564, 640, 564, 640, 1668, 640, 564, 640, 568, 640, 560, 644, 1664, 640, 1664, 644, 564, 640, 1668,
                               640, 564, 640, 564, 644, 1660, 644, 1664, 640, 564, 644, 560, 644, 564, 640, 564, 640, 564, 644, 1664, 640, 1664, 644, 1664,
                               644, 560, 644, 564, 640, 1668, 640, 560, 644, 19984, 640, 564, 644, 560, 644, 564, 640, 564, 640, 564, 640, 564, 644, 564, 640,
                               564, 644, 564, 640, 564, 640, 564, 640, 568, 640, 564, 644, 560, 644, 564, 640, 564, 644, 560, 644, 564, 640, 564, 644, 564,
                               640, 1664, 640, 1668, 640, 564, 640, 564, 640, 564, 644, 564, 640, 568, 640, 560, 644, 1668, 640, 1664, 640, 564, 640, 564, 644
                              };

const unsigned int irSignalOff[] = {8996, 4496, 640, 1688, 616, 568, 636, 568, 640, 568, 636, 568, 640, 1688, 616, 568, 640, 564, 640, 564, 640, 564, 644, 564,
                                640, 1688, 616, 1692, 616, 568, 640, 568, 636, 1668, 640, 1688, 616, 1692, 616, 568, 636, 568, 640, 564, 640, 1692, 616,
                                568, 636, 568, 636, 568, 640, 564, 640, 568, 636, 568, 640, 1688, 616, 564, 640, 1692, 616, 568, 636, 564, 640, 1672, 636,
                                564, 644, 19980, 640, 568, 636, 1692, 616, 1688, 616, 568, 636, 568, 640, 1688, 616, 572, 636, 564, 640, 568, 640, 564, 640,
                                568, 636, 568, 636, 568, 640, 1688, 616, 568, 640, 564, 640, 568, 636, 564, 640, 568, 640, 564, 640, 564, 640, 568, 640, 568,
                                636, 568, 636, 568, 640, 564, 640, 564, 640, 568, 636, 568, 640, 1688, 616, 568, 636, 1692, 616, 39980, 8972, 4496, 640, 1688,
                                616, 568, 636, 568, 640, 568, 636, 568, 636, 1692, 616, 564, 640, 568, 640, 564, 640, 564, 640, 568, 640, 1688, 616, 1692, 612,
                                568, 640, 564, 640, 1692, 612, 1692, 616, 1692, 616, 564, 640, 568, 640, 564, 640, 1692, 612, 568, 640, 568, 636, 568, 636, 568,
                                640, 564, 640, 564, 640, 568, 640, 1692, 612, 1692, 616, 568, 640, 564, 640, 1688, 616, 568, 636, 19984, 640, 564, 640, 568, 640,
                                564, 640, 568, 636, 568, 636, 568, 640, 564, 640, 568, 636, 568, 640, 564, 640, 564, 644, 1688, 616, 568, 640, 564, 640, 568, 636,
                                568, 640, 564, 640, 568, 636, 1672, 636, 1692, 612, 568, 640, 564, 640, 568, 636, 568, 640, 1692, 612, 568, 640, 568, 636, 568, 640,
                                564, 640, 1692, 616, 1668, 632, 568, 640, 39980, 8972, 4500, 640, 1688, 616, 568, 636, 568, 640, 564, 640, 568, 636, 1668, 640, 568,
                                636, 568, 640, 568, 636, 564, 640, 568, 636, 1692, 616, 1688, 616, 568, 636, 568, 640, 1668, 636, 1688, 620, 1692, 612, 568, 640, 564,
                                640, 564, 640, 1692, 612, 568, 640, 564, 644, 564, 640, 564, 640, 552, 652, 568, 640, 1688, 616, 1688, 616, 1692, 616, 564, 640, 568,
                                640, 1664, 640, 564, 640, 19988, 636, 568, 640, 564, 640, 568, 636, 568, 640, 564, 640, 568, 636, 568, 640, 564, 640, 564, 640, 568,
                                636, 568, 640, 568, 636, 568, 640, 568, 640, 564, 636, 568, 640, 568, 636, 568, 636, 568, 636, 568, 640, 1668, 636, 1692, 616, 568,
                                640, 564, 640, 564, 640, 568, 636, 568, 640, 564, 640, 1692, 616, 564, 640, 568, 636, 1692, 616
                               };

void setup() {
  pinMode(irPin, OUTPUT);
  Serial.begin(9600);
}

void loop() {

  if (Serial.available() > 0) {
    char letter = Serial.read();
    if (letter == '1') {
      irsend.sendRaw(irSignalOn, sizeof(irSignalOn) / sizeof(irSignalOn[0]), khz); //Note the approach used to automatically calculate the size of the array.
      Serial.println("ON");
    } else if (letter == '0') {
      irsend.sendRaw(irSignalOff, sizeof(irSignalOff) / sizeof(irSignalOff[0]), khz); //Note the approach used to automatically calculate the size of the array.
      Serial.println("OFF");
    }
  }
}

i got an error for arduino uno :
 Global variables use 2080 bytes (101%) of dynamic memory, leaving -32 bytes for local variables. Maximum is 2048 bytes.
how can i fix it?
EDIT 07/26:
I know with board like ATmega2560 problem will fix but I want use Arduino uno.
I tried to save my data at program memory but I don't know how to read that.

Search “PROGMEM”.

https://arduino.stackexchange.com/questions/54150/locally-declared-variable-takes-up-global-variable-space-in-dynamic-memory-sram

what make and model of air conditioner?

the signal data could be greatly reduced .... https://techdocs.altium.com/display/FPGA/NEC+Infrared+Transmission+Protocol

Re “I don't know how to read that”: 1. Search the Web for “Arduino PROGMEM”, or “AVR PROGMEM”. 2. Carefully read the resources you find, and try for yourself. 3. If you still can't after having given a genuine effort, then post here another question.

A solution is to move the tables into program memory (aka PROGMEM). Use the below:
const unsigned int irSignalOn[] PROGMEM = {
 ...
};

And modify the call to sendRaw() to sendRaw_P().
irsend.sendRaw_P(irSignalOn, sizeof(irSignalOn) / sizeof(irSignalOn[0]), khz);

For more information see the library documentation.
Cheers!

i used shirriff's IRremote library and compiler don't find sendRaw_P function ?

@MortezaMirzai Please update your question with all relevant information.

not an answer
please try this
let me know if it turns on the A/C when you press 1
#include "IRremote.h"

IRsend irsend;
int irPin = 3; // pin IR led

int khz = 38; // 38kHz carrier frequency for the NEC protocol

void setup() {
  pinMode(irPin, OUTPUT);
  Serial.begin(9600);
}

void loop() {

  if (Serial.available() > 0) {
    char letter = Serial.read();
    if (letter == '1') {
      irsend.sendNEC(0x4A08D3052, 35);
      irsend.sendNEC(0x64040002,  32);
      irsend.sendNEC(0x4A08D3032, 35);
      irsend.sendNEC(0x0015888D,  32);
      irsend.sendNEC(0x4A08D3072, 35);
      irsend.sendNEC(0x00000C0C,  32);

      Serial.println("ON");
    }
  }
}

I test that but it don't work. (maybe my fault) and compiler give a warning.

that's it? .... compiler give a warning  .... nothing about the warning? .... do you want help or not?

warning: large integer implicitly truncated to unsigned type [-Woverflow] irsend.sendNEC(0x4A08D3052, 35);

One can also jump to a Atmega1284P based board, with it's 16K of SRAM, 8x that of a '328P's 2K and 2x that of the Mega's 8K.  Dual hardware serial ports too if your project should need one.

or an esp8266 for cheaper and with 4X the ram and dozens of times the flash...

But limited to 3.3V operation, and I think much less current capability on the IO, if the project needs that.