Need help with LCD and nRF24L01+

Hello, recently I started a project in which I want to make 2 Arduinos communicate using nRF module and LCD. I hooked everything but I am bad at coding and I tried one but can't seem to make the receiving arduino display the message on the LCD. I am posting the code on both the transmitting and the receiving arduino. I am using a button on the transmitting end and I try to read the button state through text in which it sends. I haven't though of this code I used different codes I found online and snitched them together.


// Code 1 : Push Button and LCD (Transmitter)

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

RF24 radio(7, 8);  // CE, CSN
const byte address[10] = "ADDRESS01";

const int B1_Pin = 6;  // Pushbutton B1
char txt1[] = "B1", txt3[] = "00";

void setup() {
  Serial.begin(9600);
  pinMode(B1_Pin, INPUT);

  radio.begin();
  radio.openWritingPipe(address);
  radio.setPALevel(RF24_PA_MIN);
  radio.stopListening();
};

void loop() {
  int B1_State = digitalRead(B1_Pin);

  if (B1_State == HIGH) {
    radio.write(&txt1, sizeof(txt1));
    Serial.println(txt1);
  } else {
    radio.write(&txt3, sizeof(txt3));
    Serial.println(txt3);
  };
  delay(100);
};


// Code 2 : Push Button and LCD (Receiver)

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

RF24 radio(7, 8);  // CE, CSN
const byte address[10] = "ADDRESS01";

const int rs = 12, en = 11, d4 = 5, d5 = 4, d6 = 3, d7 = 2;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);

void setup() {
  Serial.begin(9600);
  lcd.begin(16, 2);
  lcd.setCursor(0, 0);

  radio.begin();
  radio.openReadingPipe(0, address);
  radio.setPALevel(RF24_PA_MIN);
  radio.startListening();
};

void loop() {
  if (radio.available()) {
    char txt[5] = "";
    radio.read(&txt, sizeof(txt));
    switch (txt[1]) {
      case '1': lcd.print("hello, world!"); break;
      default: lcd.clear(); break;
    };
    Serial.println(txt);
    delay(100);
  };
};


Screenshots of code are nearly worthless. We cannot copy the code to a text editor or to the IDE for examination or verification. Read the forum guidelines to see how to properly post code and some good information on making a good post. If I can copy the code I can try it out on hardware.

Use the IDE autoformat tool (ctrl-t or Tools, Auto format) before posting code in code tags.

Please go back and fix your original post

I suggest that you use the example code in Robin2's excellent simple rf24 tutorial to get the radios to work. Pay close attention to the part about getting sufficient current to the 3.3V power input.

Some other tips that I have come across.

Run the CheckConnection.ino (look in reply #30 in the tutorial) to verify the physical wiring between the radio module and its processor (Arduino). This is especially useful if all you see is “Data received” repeating much more quickly then there is a problem - most likely theArduino is not communicating properly with its nRF24.

Make sure the rf24 power supply can provide enough current. This is especially true for the high power (external antenna) modules. I use homemade adapters like these. They are powered by 5V and have a 3.3V regulator on the board. Robin2 also has suggested trying with a 2 AA cell battery pack.

If using the high powered radios make sure to separate them by a few meters. They may not work too close together. Try the lower power settings.

Reset the radios by cycling power to them after uploading new code. I have found that to help. They do not reset with the Arduino.

Sending too often can also cause a problem. Trying to send every time through a fast loop may not work. Slow down to 1 to 5 packets per second to test.

Please post a schematic. Hand drawn, photographed and posted is fine. Include all pin names/numbers, components, their part numbers and/or values and power supplies.

If you are using an UNO or similar, SPI pins 11, 12, and 13 may only be used for SPI,
not some LCD fiddling.

delay has no room in a receiver.

Sorry for the code. I realized that doesn't help one bit if I post it that way. The code should be updated already. I will be posting the schematics bellow the code. I am bad at designing schematics so it could be somewhat messy. Thanks for showing me how to post it properly.

As for the sending signals when I try to run the codes on both devices in the serial monitor on the receiver I get that I receive 00 and when i press the button I get B1. I don't know if that is of any help but I guess if I can make different signal when I press it I should be able to read it in a way that can make the LCD show a message. I am not really sure I am still new in these things so any help is appreciated.

The first two (rs and en) collide with SPI.

Will it work if I change them to not SPI pins?

I certainly will not work with the LCD using SPI pins.

Thanks for fixing the code. Now I can try it out.

I tried your send and receive codes on 2 Unos with rf24 radio modules. I had to change the rf24 CE and CSN pins since my setups are hard wired. And the LCD RS and EN pins had to move from the SPI pins. And I made a small change to the LCD code so the display would not be spammed with "hello world". The code works fine, receiver serial monitor shows "00" for no button press and "B1" when the button is pressed and the LCD is blank for no press and "hello world" with the button press.

One big difference in our setups is that my radio modules are powered by their own 3.3V supply using a LM1117 3.3 connected to the Uno 5V rail (home made, but similar to these adapters). The most common problem causing those radios to not work is lack of current to the radio.

So the code is OK. That suggests a hardware problem. Either power or wiring. Robin2's tutorial has some suggestions about how to supply sufficient power and a diagnostic sketch to verify the wiring between the radio module and its host processor (see post #30 of the tutorial linked in post #2).

I found my problem. My problem was that my nRF and LCD were on the same SPI pins. I moved the LCD 10 and 9 and works like a charm. I updated the code a bit as well so to not spam "hello world" non stop when I hold the button with delay and clear after each tick.

Now I want to make it bidirectional with LCD on each side. Thanks a lot for the help and if I need any help with the bidirectional I will post again.

By reading and understanding #3?

Yes thanks a lot. Sorry that I made it sound like I found it by myself. It wasn't my intention. Still thanks a lot.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.