For my RC boat, I am using an Uno as my transmitter and ESP32 as my receiver. The idea is to have different modes of operation for the boat. On the transmitter side, I have 3 buttons, each connected to an LED to indicate what mode is active. I am using nRF24L01 for RF comms between the two. I'm struggling with the programming part. When the first button is pressed, I want to activate manual mode where joystick commands (x and y) are transmitted over to the receiver to influence a motor and a servo connected to the rudder. For the second mode, I'd like to have something like a heading hold mode where I can send a heading value through the serial monitor. I haven't yet decided what I want to do with the 3rd button but once I have an idea of how to successfully transmit and code this correctly, I'd like to have a 3rd functionality. The overall idea is that each LED will stay on as long as another button for a different mode is not selected. As of now, I can make the LEDs stay on but I am unable to command an output on the receiver's side. For the RF part, I have been going through tutorials and have been reading about sending data wirelessly using a struct format but I am relatively new to this so any guidance on that front would also be much appreciated. Thank you!
Thanks for your response, @gcjr, I really appreciate it.
I haven't had a chance to test out your code yet, hoping to do that tomorrow or day after after which I will provide an update. As for the sending data part, I'm simply wanting to send either joystick info or a number through the serial port.
Hi @Paul_KD7HB, thanks for that. That's what I'm doing. I was trying out sending data as a structure but I think I'll send it as an array since I've managed to do that in the past.
From what I've read online, a structure will take all data types whereas an array will take only one type - would that be correct? And since I'm wanting to send joystick values along with numbers sent through the serial monitor, I'm now thinking a structure might be better suited?
No need. nRF24L01 Transmission is packetized by the hardware with Header, Addressing, Payload, CRC, etc. All the packet overhead is stripped off at the RX end and the payload (32 bytes max) is presented to the host processor via SPI, in proper byte order. Also, with such a small available payload size, you usually can't afford to mess around sending ASCII strings.
You need to be careful. ESP32 (32-bit processor) and UNO (8-bit processor) will build the struct differently in memory because of differences in packing. Since the payload is sent as bytes over nRF24L01, what you have may not allow correct transfer of the struct between TX and RX. You can get around this by using a Packed struct:
Thanks @gfvalvo, that's what I was missing! My transmitter and receiver are now communicating! I still have some issues in my loop but I'll start another thread for that. Appreciate the assistance!
Thanks again for this, @gcjr, appreciate your inputs very much! I understand your code but being a newbie, I'm taking it one step at a time with functions. Tried out your code and it works (I'm trying to modify it so that pressing another button turns off the one that's on) just fine, just writing stuff out for now and gaining experience with C/C++ before moving on to functions. I also need to study the data types a little better. Appreciate your time as always!