16x2 LCD and nRF24L01 issue?

I have two sketches that use the same piece of code and the LCD displays different things.

One is using the DallasTemperature library and reads a sensor directly, and uses lcd.print to print the int to the lcd. Code here:

void loop(){ 
  sensors.requestTemperatures(); 
  int sensorValue = sensors.getTempCByIndex(0);
  Serial.println(sensorValue); 
  lcd.setCursor(0, 1);
  lcd.print (sensorValue); //have also tried lcd.print(20) - it works
  delay(1000);
}

The other sketch uses the RF24 library to get the temperature data (from another arduino nano) and uses this data with lcd.print to print the int to the lcd. Code here:

void loop() {
  if (radio.available()){
    int val = 0;
    radio.read(&val, sizeof(val));
    Serial.println(val);
    lcd.setCursor (0, 1);
    lcd.print(val); //also tried lcd.print(20) - it does NOT work
  } 
}//loop

The serial monitor is printing the correct value, an int, but the LCD displays this weird character, and not in the place the cursor is set to! (Photo attached) I cannot figure out why these two sketches are behaving differently. The setup code that writes "Temp: " clearly works for both of them. I'll attach the full code of both sketches in case there is something else that I'm completely missing.

DS18B20LCD is the one that works.
testRFLCDreceiver is the one that doesn't work.

I've tried closing all my instances of Arduino and trying again. After I post this I'll try rebooting my computer.

DS18B20LCD.ino (1.09 KB)

testRFLCDreceiver.ino (1.05 KB)

Quick update:

Rebooting didn't work. I also tried getting rid of the conditional that is checking the radio, and used this code in the second program that wasn't working:

void loop() {
  lcd.setCursor(0, 1);
  lcd.print (20); //still doesn't work
  delay(1000);
}//loop

Which still doesn't work. This is copied and pasted from the other sketch. I have no idea what's wrong with it.

Please post the entire codes (in code tags, not attachments). Both sending and receiving programs. Snippets may well leave out some important information.

Ok.

Transmitter:

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

#define ONE_WIRE_BUS 4
#define CE_PIN 8  //chip enable
#define CSN_PIN 9 //chip select not

RF24 radio(CE_PIN, CSN_PIN);
const byte address[6] = "00001"; //radio channel

OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);

void setup() {
  Serial.begin(9600);
  sensors.begin();
  
  radio.begin();
  radio.openWritingPipe(address);
  radio.setPALevel(RF24_PA_MIN);
  radio.stopListening();
}

void loop() {
  sensors.requestTemperatures(); 
  int val = sensors.getTempCByIndex(0);
  String s_val = String(val);
  Serial.print("Celsius temperature: ");
  Serial.println(s_val); 
  delay(1000);
  
  radio.write (&val, sizeof(val));
}

Receiver:

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

#define CE_PIN 5  //chip enable
#define CSN_PIN 6 //chip select not

RF24 radio(CE_PIN, CSN_PIN);
const byte address[6] = "00001"; //radio channel
LiquidCrystal lcd (7, 8, 9, 10, 11, 12);
int lcdContrast = 110;  //110 tried and true

void setup() {
  Serial.begin(9600);

  pinMode (3, OUTPUT);
  analogWrite(3, lcdContrast);
  lcd.begin (16, 2);
  lcd.setCursor (0, 0);
  lcd.write("Temp: ");
  
  radio.begin();
  radio.openReadingPipe(0, address);
  radio.setPALevel(RF24_PA_MIN);
  radio.startListening();
}//setup

void loop() {
  if (radio.available()){
    int val = 0;
    radio.read(&val, sizeof(val));
    Serial.println(val);
    lcd.setCursor (0, 1);
    lcd.print(20); // doesn't work!?
  } //if radio
}//loop

It's the lcd.print in the loop method that doesn't work. I have tried lcd.print(val) or lcd.print(20) or lcd.print((int)20) and all of these show the weird character in the image I attached on the first post.

Following is the entire code where one nano reads the DS18B20 and writes it to the LCD directly with no radio, and it works.

/*********
  Rui Santos
  Complete project details at https://randomnerdtutorials.com  
  Based on the Dallas Temperature Library example
*********/

#include <OneWire.h>
#include <DallasTemperature.h>
#include <LiquidCrystal.h>

// Data wire is conntec to the Arduino digital pin 4
#define ONE_WIRE_BUS 4

// Setup a oneWire instance to communicate with any OneWire devices
OneWire oneWire(ONE_WIRE_BUS);

LiquidCrystal lcd (7, 8, 9, 10, 11, 12);
int lcdContrast = 110;

// Pass our oneWire reference to Dallas Temperature sensor 
DallasTemperature sensors(&oneWire);

void setup()
{
  // Start serial communication for debugging purposes
  Serial.begin(9600);
  // Start up the library
  sensors.begin();
  pinMode (3, OUTPUT);
  analogWrite(3, lcdContrast);
  lcd.begin (16, 2);
  lcd.setCursor (0, 0);
  lcd.write("Temp: ");
}

void loop(){ 
  sensors.requestTemperatures(); 
  int sensorValue = sensors.getTempCByIndex(0);
  Serial.println(sensorValue); 
  lcd.setCursor(0, 1);
  lcd.print (sensorValue); //have also tried lcd.print(20) - it works
  delay(1000);
}//loop
#include <SPI.h>
...
LiquidCrystal lcd (7, 8, 9, 10, 11, 12);

please check which pins are used for SPI and verify, that they do not interfere with your pins of the LCD

I am using the ICSP pins for the SPI, and the given digital pins for the LCD.

Does using the digital pins that have dual purpose as SPI pins (using them as digital pins) while using the ICSP pins for SPI cause problems?

check again where your "icsp" pins are connected to.

google for Arduino pinout

Pins 11 (MOSI) and/ 12 (MISO) are used by SPI (the radio). The analog input pins (A0-A5) are also digital pins. You can use the for the LCD.

noiasca:
check again where your "icsp" pins are connected to.

google for Arduino pinout

My transmitter and receiver are working perfectly fine when I print the value received to the serial monitor. There are no issues with the transmitter and receiver being able to exchange data.

The issue is that when I print the value (20 - whether using the value received from the radio, or just printing a native integer) to the LCD, the output is garbled (as per the image attached to the first post).

The fact that the transmitter and receiver are functioning properly tells me that the SPI connections on the ICSP pins are correct.

groundFungus:
Pins 11 (MOSI) and/ 12 (MISO) are used by SPI (the radio). The analog input pins (A0-A5) are also digital pins. You can use the for the LCD.

If I am using the ICSP pins for MOSI, MISO instead of pins 11 and 12, does this mean that pins 11 and 12 cannot function as digital pins?

if you are using SPI, why do you think that you can use the SAME PINS for something different?

what I am saying is that you cannot use pins 11 and 12 for both devices. The radio, absoutely, needs those pns so use unused analog inputs to replace 11 and 12 in the LCD costructor.

noiasca:
if you are using SPI, why do you think that you can use the SAME PINS for something different?

I think you aren't reading my posts completely. I am NOT using pins 11 and 12 for MOSI and MISO. I am using the ICSP pins for MOSI and MISO. Should I post a photo of my arduino wired up to clear this confusion?

There are two different pins on the arduinos for MISO, and two different pins for MOSI. I am using the ICSP pins for MOSI, according to this image that I already shared in a previous post. I am using pins 11 and 12 ONLY for the LCD.

I am wondering if there is some conflict that is causing my issue. There is no part of the code that tells the arduino to look at the ICSP pins for the MOSI and MISO connections - is it possible that the arduino is somehow corrupting the data sent to the LCD on pins 11 and 12 because it might be looking for SPI connections there? This doesn't make sense to me, since the connection to the NRF24 module is working, and I am getting the data I expect when I print it out to the Serial monitor.

But I cannot think of any other way thing that would change the data sent to the LCD just because there is now code running that uses SPI to communicate with the nRF24 module.

I am wondering if there is some conflict that is causing my issue.

Three days ago I suggested you to download an Arduino Pin Out.

I.e.


Find out which Arduino GPIOs are 11, 12, 13.
And now tell me, which GPIOs are used for MOSI, MISO an SCL.

let's do an example:
13 is connected to PB5.
SCL is connected to PB5.

Surprise: Its the same pin. Now it's your turn to find out were MOSI and MISO are connected to.

If you still don't understand my posting: Take a multimeter and check if you have connectivtiy on any pin between LCD and your SPI Modul. If you find more than GND and VCC than there is something wrong in your wiring.

So you're telling me that the ICSP pins that are explicitly labelled SCK2, MISO2, and MISO2 are wired to the same pins on the ATMEGA as SCK/D13, MISO/D12, MOSI/D11?

I would have been clearer if you had said "Check where the arduino maps the different pins to on the microchip" instead of "where the pins are connected to" because I am using an arduino nano, and I searched online for "arduino nano pinout" which led me to this site which doesn't state the wiring conflict.

Why are there multiple places to connect SPI devices if using any of them makes the other pins unusable? This is a strange 'feature' indeed.

Why are there multiple places to connect SPI devices if using any of them makes the other pins unusable?

the grouped 6 pin connector is planned to do ICSP.
In Circuit Serial Programming

So you're telling me that the ICSP pins that are explicitly labelled SCK2, MISO2, and MISO2 are

NO.
The pins SCK2/MISO2/MOSI2 on an Arduino UNO are connected to the atmega8u2/atmega16u2

on a Nano you have SCK/MISO/MOSI as ICSP

Your are Using a Nano.
So look for a datasheet for a Nano.

finally:

And now tell me, which GPIOs are used for MOSI, MISO an SCL.