Hi. all my data is gone. I remember that it is possible to create a code that allows you to be IDENTICAL on both devices allows you to communicate with each other, but I do not remember how it should work. (I did it a long time ago) I want the code to be IDENTICAL and both sets of Arduino Uno + nrf24l01 were listening and when I send a message through the terminal from one set - the second set read the message and vice versa. How can it be done so that the codes on both different devices are the same?
Seems to run, I had only one instance, so the chat test is missing, I see only failed sends.
Edit: there was a missing line added radio.openWritingPipe(pipe);
#include <WhandallSerial.h> // https://github.com/whandall/WhandallSerial
#include <RF24.h>
void procLine(const char*);
SSerial cmds(Serial, procLine);
RF24 radio(9, 10);
const uint8_t pipe[5] = { '*', 'c', 'h', 'a', 't' };
uint8_t buffer[33];
void setup() {
Serial.begin(115200);
cmds.begin(32);
radio.begin();
radio.openReadingPipe(1, pipe);
radio.openWritingPipe(pipe);
radio.startListening();
}
void loop() {
cmds.loop();
if (radio.available()) {
radio.read(buffer, 32);
Serial.write('<');
Serial.println((char*)buffer);
}
}
void procLine(const char* line) {
radio.stopListening();
Serial.write('>');
Serial.write(radio.write(line, strlen(line) + 1) ? '+' : '-');
Serial.println(line);
radio.startListening();
}
Thanks you, i will try it later, but have found a other code:
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
#define CE_PIN 9
#define CSN_PIN 10
const byte Address[5] = {'N','e','s','s','y'};
RF24 radio(CE_PIN, CSN_PIN);
String username = "";
String dataInput;
char dataToSend[32];
char dataReceived[32];
void setup() {
Serial.begin(115200);
Serial.println("Enter username...");
radio.begin();
radio.setPALevel(RF24_PA_MAX);
radio.setDataRate(RF24_1MBPS);
radio.setRetries(3, 5);
radio.openWritingPipe(Address);
radio.openReadingPipe(1, Address);
}
void loop() {
// set username
while (username == "") {
if ( Serial.available() ) {
username = Serial.readStringUntil('\n');
Serial.print("Welcome ");
Serial.println(username);
}
}
// listen for radio data
radio.startListening();
if ( radio.available() ) {
// read data from radio
radio.read( &dataReceived, sizeof(dataReceived) );
Serial.println(dataReceived);
}
if( Serial.available() ) {
// stop listening on radio
radio.stopListening();
// get serial input
dataInput = "[" + username + "] " + Serial.readStringUntil('\n');
Serial.println(dataInput);
dataInput.toCharArray(dataToSend, 32);
// send data
radio.write( &dataToSend, sizeof(dataToSend) );
}
}
Did you try that code?
I don't like Strings, or blocking,
and I think the duration of listening is not enough to receive packet reliably
yes, I tried this code, I found it on my phone (I think I wrote it down once just in case) the code works but using the "Serial USB Terminal" application (on android) it adds two strange characters at the end (maybe a newline character?)
if you enter the nick: Wojtek, it is displayed like this, and when you send message: message
15:53:47,984 message
15:53:47.988 [Wojtek^M] message^M
To
^M
The sketch has no problems in sending, but in receiving,
and it does not handle messages that are longer than 32, it just cuts them off,
and (if that happens) could display strange output on the receiving side.
I know it's annoying to install my serial library, but it's worth it.
It's quite flexible and also supports communication with Nextion TFTs.
For your simple request,
I did not want to program a solid, non-blocking serial line gathering from scratch.
I don't fully understand (I'm not a programmer, I don't know what nextion tft is), but when I get back (I have to do something) I'll try to change something in the code myself and post it here. I have a few more questions, but I'll let you know what I'm talking about.
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.