Hi
Ok those are the final code and they works.
Transmitter
The nano takes what's coming on his RX pin and send it.
#include <nRF24L01.h>
#include <printf.h>
#include <RF24.h>
#include <RF24_config.h>
String serialdata; //Holds data coming in
char msg[32]; //Char array to send data out with
RF24 transmit (9,10); //create RF24 object called transmit
byte address [6] = "00001"; //set address to 00001
void setup() {
Serial.begin(9600);
Serial.println ("Serial Port Open");
transmit.begin();
transmit.openWritingPipe(address); //open writing pipe to address 00001
transmit.setPALevel(RF24_PA_MAX); //set RF power output to maximum
transmit.setDataRate(RF24_250KBPS); //set datarate to 250kbps
transmit.setChannel(20); //set frequency to channel 20
transmit.stopListening();
}
void loop() {
if (Serial.available()){
delay (200);
Serial.println ("I found Serial Data");// If you are having issues, these will help you find where your code doesnt work.
serialdata=Serial.readString();//put text from serial in serialdata string¸
}
else {
serialdata.toCharArray(msg, 32);//convert serialdat the the msg char array
Serial.println ("I converted it to a CHAR ARRAY");
Serial.println("Text to be Sent-");//debugging
Serial.println("");//debugging
Serial.print(msg);//debugging
Serial.println("");//debugging
}
transmit.write(msg, 32);
}
This is the receiver code
it receive numbers between comma and displays it on an OLED display.
#include <Wire.h> //IIC Library
#include <Adafruit_SSD1306.h>
#define OLED_RESET 4
Adafruit_SSD1306 display(OLED_RESET);
#include <nRF24L01.h>
#include <printf.h>
#include <RF24.h>
#include <RF24_config.h>
RF24 receive (9,10); //create object called receive
byte address [5] = "00001"; //creat an array with 5 elements, where each element is 1 byte;
String text = " ";//String to hold the text
void setup()
{
display.begin(SSD1306_SWITCHCAPVCC, 0x3C);
display.clearDisplay();
display.setTextColor(WHITE);
display.setCursor(25,0);
display.setTextSize(1);
display.print(F("Scuba Receiver"));
display.display();
delay (1500);//set this to the interval
Serial.begin(9600);
Serial.print("Starting Receiver \n");
receive.begin();
receive.openReadingPipe(0,address); //open reading pipe 0 at address 00001
receive.setPALevel(RF24_PA_MAX); //Set RF output to maximum
receive.setDataRate(RF24_250KBPS); //set datarate to 250kbps
receive.setChannel(20); //set frequency to channel 20
receive.startListening();
}
void loop(){
if (receive.available()) //check when received data available
{
char buf[32];
receive.read(&buf, sizeof(buf));
text = (char*)buf;
Serial.println(text);
display.clearDisplay();
}
if (text.startsWith(",")) {
int sepLocation[5];
int index = text.indexOf(",");
int i = 0;
String extractedValues[4];
while (index >= 0) {
sepLocation[i] = index;
i++ ;
index = text.indexOf(",", index + 1);
}
for (int o = 0; o < 4; o++) {
extractedValues[o] = text.substring((sepLocation[o] + 1), sepLocation[(o + 1)]);
}
display.setCursor(0, 0);
display.setTextColor(WHITE, BLACK);
display.setTextSize(1);
display.print("PSI = " + extractedValues[0]);
display.display();
display.setCursor(0, 12);
display.setTextColor(WHITE, BLACK);
display.setTextSize(1);
display.print("Oxygen = " + extractedValues[1] + "%");
display.display();
display.setCursor(0, 25);
display.setTextColor(WHITE, BLACK);
display.setTextSize(1);
display.print("Temp = " + extractedValues[2] + "C");
display.display();
display.setCursor(80, 25);
display.setTextColor(WHITE, BLACK);
display.setTextSize(1);
display.print("CO = " + extractedValues[3] + "");
display.display();
}
delay (500);
}
For now it's working and I will not change it except if it's only minor changes.
With time I will learn better and I will come back to it when I'm ready. Like I did
in my other project but for now I need to install this so I can use it.
I found examples of code to remotely control LED with the NRF24L01 and
I will try tomorrow to includ them in this code. I will certainly have some
bugs and if so, I will post it under a new topic.
Many many thanks for all the help.