4L x 20C Slave LCD using nRF24L01 modules

The following code for nRF24L01 Transmitter + Receiver can be used for updating a 4L x 20C LCD connected to the Receiver. Works OK with no glitches… The delay() used between successive transmissions may not be finally required - now it serves to know the LCD is updating.

A very basic implementation. Originally wanted to implement a handshake after each line was transmitted using AckPayLoad process. But going by the results it was not required.

Any suggestions for improvement welcome !!

Transmitter module :

#include <SPI.h>
#include <RF24.h>

/****************** User Config ***************************/
/* Hardware configuration: Set up nRF24L01 radio on SPI bus plus pins 7,8 */
RF24 radio(7, 8); // For RRDUINO pcb. But use the UNO pin numbers
/**********************************************************/

byte slaveAddress2[6] = "RxBBB";                               // Radio pipe addresses for Slave no 2.

struct dataStruct {                                            // Configure your transmission data into this structure
  byte lcdMessage[20];
  byte cursorRow;
} txDataStream  ;

bool firstLine, secondLine, thirdLine, fourthLine;
byte ackPayLoad1, ackPayLoad2, ackPayLoad3, ackPayLoad4;

byte Ch1_OKLed = 5;
byte Ch2_OKLed = 6;
byte pinSS     = 10;

void setup() {

  Serial.begin(9600);
  Serial.println(F("*** STARTING TRANSMITTER *** "));

  // Setup and configure radio
  radio.begin();
  radio.setChannel(108);                                       // Above most Wifi Channels
  radio.setDataRate( RF24_250KBPS );
  radio.enableAckPayload();                                    // Allow optional ack payloads
  radio.enableDynamicPayloads();                               // Ack payloads are dynamic payloads
  radio.setRetries(5, 10);                                     // Delay, count
  //radio.printDetails();

  pinMode( Ch1_OKLed, OUTPUT );
  pinMode( Ch2_OKLed, OUTPUT );
  pinMode( pinSS, OUTPUT );

  digitalWrite(Ch1_OKLed, LOW);
  digitalWrite(Ch2_OKLed, LOW);
}

//$$$$$$$$$$$$$$$$$$$$$$$$$$$$
void loop(void)
{
  send_Ch2();
}
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

void send_Ch2()
{
  radio.openWritingPipe(slaveAddress2);                               // Open the writing pipe to Slave 2

  strcpy(txDataStream.lcdMessage, "");                                // Update the payload
  txDataStream.cursorRow  = 4;
  (radio.write(&txDataStream, sizeof(txDataStream)));
  delay(5);
  strcpy(txDataStream.lcdMessage, "THIS IS LINE ONE ! ");            // Update the payload
  txDataStream.cursorRow  = 0;
  firstLine = (radio.write(&txDataStream, sizeof(txDataStream)));    // Send First Line of LCD..
  delay(5);                                                          // Wait for roundtrip delay...
  strcpy(txDataStream.lcdMessage, "THIS IS LINE TWO ! ");            // Update the payload
  txDataStream.cursorRow  = 1;
  firstLine = (radio.write(&txDataStream, sizeof(txDataStream)));    // Send First Line of LCD..
  delay(5);                                                          // Wait for roundtrip delay..
  strcpy(txDataStream.lcdMessage, "THIS IS LINE THR ! ");            // Update the payload
  txDataStream.cursorRow  = 2;
  firstLine = (radio.write(&txDataStream, sizeof(txDataStream)));    // Send First Line of LCD..
  delay(5);                                                          // Wait for roundtrip delay..
  strcpy(txDataStream.lcdMessage, "THIS IS LINE FOUR! ");            // Update the payload
  txDataStream.cursorRow  = 3;
  firstLine = (radio.write(&txDataStream, sizeof(txDataStream)));     // Send First Line of LCD..
  delay(500);                                                         // Update display delay..

}

Receiver Module :

#include <SPI.h>
#include <RF24.h>
#include <LCD.h>
#include <LiquidCrystal_I2C.h>
#include "Wire.h"

/****************** User Config ***************************/
/* Hardware configuration: Set up nRF24L01 radio on SPI bus plus pins 7,8 */
RF24 radio(7, 8);
/**********************************************************/

byte myAddress[6] = "RxBBB";                                   // Radio pipe addresses of this receiver - must match with one in Tx code Slave1.

unsigned long timeOut;
char startMsg[21] = "Starting Receiver..";

struct dataStruct {                                            // Configure your reception data into this structure
  byte recdMsg[20];
  byte cursorRow;
} rxDataStream;

char lcdMessage[21];
byte ackPayLoad[4] = {11,22,33,44};
byte pinSS = 10;

// DEFINE LCD PINS AND INSTANTIATE
LiquidCrystal_I2C  lcd(0x27, 2, 1, 0, 4, 5, 6, 7);

void setup()
{
  Serial.begin(9600);
  Serial.println(F("*** STARTING RECIEVER *** "));

  Wire.begin();
  lcd.begin(20, 4);
  lcd.setBacklightPin(3, POSITIVE);
  lcd.setBacklight(HIGH);
  lcd.clear();

  sprintf(lcdMessage, "%s", startMsg);
  lcd.print(lcdMessage);

  pinMode( pinSS, OUTPUT);
  // Setup and configure radio
  radio.begin();
  radio.setChannel(108);                                       // Above most Wifi Channels
  radio.setDataRate( RF24_250KBPS );
  radio.enableDynamicPayloads();                               // Ack payloads are dynamic payloads
  radio.openReadingPipe(1, myAddress);
  radio.enableAckPayload();
  radio.writeAckPayload(1, &ackPayLoad[0], sizeof(ackPayLoad[0])); // pre-load data for first acknowledgement

  radio.startListening();
}

//****************************************************
void loop(void)
{
  if ( radio.available())                                              // Is payload available from Tx ?
  {  
      radio.read( &rxDataStream, sizeof(rxDataStream));                // Get the Payload from Tx
      //Serial.println( rxDataStream.cursorRow);
     // if ( rxDataStream.cursorRow == 4) lcd.clear();                 // If uncommented introduces LCD flicker...
      lcd.setCursor(0, rxDataStream.cursorRow);                        // Send the first line to LCD
      sprintf(lcdMessage, "%s", rxDataStream.recdMsg);
      lcd.print(lcdMessage);
      radio.writeAckPayload(1, &ackPayLoad[0], sizeof(ackPayLoad[0])); // Send Ack Payload to Tx ( Not used in this code version ) 
  }
}