atmega328 + LCD 16x2 - nothing shows in void loop

Hello.

I have been starting my adventure with LCD screen today. I wanted to add some lcd functions to my existing sketch and after that problem appered.

When i try to write something on LCD in void loop, program compile the sketch but nothing displays in LCD screen. When I was writing lcd.print(“something”) in void setup, everything is ok. LCD displays what I want. Problem is in void loop.

Here is the sketch:

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

int led_sensor = 8;
int led_error = 6;
int sensor[1];

RF24 radio(9,10);
const uint64_t pipe = 0xE8E8F0F0E1LL;

LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

void setup()
{
  Serial.begin(9600);
  
  lcd.begin(16, 2);
  lcd.noDisplay();
  
  radio.begin();
  
  radio.openReadingPipe(1,pipe);
  radio.startListening();
  
  pinMode(led_sensor, OUTPUT);
  pinMode(led_error, OUTPUT);
}
void loop()
{
  if (radio.available())
 {
   bool done = false;
   while (!done)
   {
     done = radio.read(sensor, sizeof(sensor));
     Serial.println(sensor[0]);
     delay(20);

     if (sensor[0] > 600)
       {
         digitalWrite(led_error, LOW);
         digitalWrite(led_sensor, LOW);
         lcd.noDisplay();
       }
       else
       {
         digitalWrite(led_error, LOW);
         digitalWrite(led_sensor, HIGH);
         lcd.display();
         lcd.print("Working...");
       }
   }
 }
 else
 {
   Serial.println("Radio off");
   digitalWrite(led_error, HIGH);
   digitalWrite(led_sensor, LOW);
   lcd.display();
   lcd.print("Radio off");
   delay(1000);
 }
}

If someone knows whats wrong, please help. I tried to find a solution in “Learning” bookmark but i didn’t find anything.

BTW. Sorry for my poor english.

When you post code on the forum, please make a habit of using the code tags “#” button.

click the MODIFY button in the upper right of the post window.
Highlight all you code.
click the “#” CODE TAGS button on the toolbar above just to the left of the QUOTE button.
click SAVE (at the bottom).

I think you need to learn how to use the lcd.SetCursor(0,0);
http://arduino.cc/en/Reference/LiquidCrystalSetCursor

I have never used, or seen anybody else use lcd.display() or lcd.nodisplay() before and I really don't understand why you are using it here.

That command seems to allow you to either display a specific message or not display that same message without the need to re-write it each time you want to display it.

In your case you are immediately writing a new message immediately after restoring the old one but, as was implied in the preceding answer, the new message is appended to the old one. So at least at some point you are going to be sending information to locations that are not visible on your 16x2 display.

Don

Ok, I changed some lines in my sketch and now it looks like this:

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

int led_sensor = 8;
int led_error = 6;
int sensor[1];

RF24 radio(9,10);

const uint64_t pipe = 0xE8E8F0F0E1LL;

LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

void setup()
{
  Serial.begin(9600);
  
  lcd.begin(16, 2);
  
  lcd.setCursor(0, 0);
  lcd.print("Ready");
  
  radio.begin();
  
  radio.openReadingPipe(1,pipe);
  radio.startListening();
  
  pinMode(led_sensor, OUTPUT);
  pinMode(led_error, OUTPUT);
}
void loop()
{
  if (radio.available())
 {
   bool done = false;
   
   while (!done)
   {
     done = radio.read(sensor, sizeof(sensor));
     
     Serial.println(sensor[0]);
     delay(20);

     if (sensor[0] > 600)
       {
         digitalWrite(led_error, LOW);
         digitalWrite(led_sensor, LOW);
         lcd.clear();
         lcd.setCursor(0, 1);
         lcd.print("Sleep");
       }
       else
       {
         digitalWrite(led_error, LOW);
         digitalWrite(led_sensor, HIGH);
         lcd.clear();
         lcd.setCursor(0, 1);
         lcd.print("Working");
       }
   }
 }
 else
 {
   lcd.clear();
   lcd.setCursor(0, 1);
   lcd.print("Radio off");
   Serial.println("Radio off");
   digitalWrite(led_error, HIGH);
   digitalWrite(led_sensor, LOW);
   delay(1000);
 }
}

Unfortunetly it doesn’t work. On the display is only word “ready”.

I tried to program the example “Hello world!” and it works, but my sketch not. Is still something wrong in my code?

It's not getting to any of the lcd.clear statements which means that it is probably hanging up in one of your radio routines.

You are going to have to do some troubleshooting to find out where. Some additional strategically placed serial.print statements may help.

Don

Thanks a lot. I'll try to find where is the problem.