My old, fried 51yr old brain CANNOT figure this out.
I have a wireless link between a Mega 2560p and an Uno, using a pair of NRF24L01's.
Used the demo code and wiring on this page:
Didn't work as usual. Finally worked out that you need a 100uf across each NRF24L01. Why that isn't mentioned anywhere on the page is maddening. But hey ho.
The transmitter code is:
/*
* Arduino Wireless Communication Tutorial
* Example 1 - Transmitter Code
*
* by Dejan Nedelkovski, www.HowToMechatronics.com
*
* Library: TMRh20/RF24, https://github.com/tmrh20/RF24/
*/
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
RF24 radio(7, 8); // CE, CSN
const byte address[6] = "00001";
void setup() {
radio.begin();
radio.openWritingPipe(address);
radio.setPALevel(RF24_PA_MIN);
radio.stopListening();
}
void loop() {
const char text[] = "Hello World";
radio.write(&text, sizeof(text));
delay(1000);
}
And the receiver code is:
/*
* Arduino Wireless Communication Tutorial
* Example 1 - Receiver Code
*
* by Dejan Nedelkovski, www.HowToMechatronics.com
*
* Library: TMRh20/RF24, https://github.com/tmrh20/RF24/
*/
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
RF24 radio(7, 8); // CE, CSN
const byte address[6] = "00001";
void setup() {
Serial.begin(9600);
radio.begin();
radio.openReadingPipe(0, address);
radio.setPALevel(RF24_PA_MIN);
radio.startListening();
}
void loop() {
if (radio.available()) {
char text[32] = "";
radio.read(&text, sizeof(text));
Serial.println(text);
}
}
Now, it declares the 'Hello world' as: const char text[] = "Hello World";
How do I re-write this code, so that I can change the contents of the message 'text'?
No matter what I seem to try, it fails.
I did get some kind of horrific affair going using a string, but then everyone rolls their eyes at using those.
All I want to do is put line of varied line of text into the 'text' container whenever I need to and send it.
Why I can't get my head around it I don't know...