2nd line of LCD flashing

I am having a problem with the 2nd line of info on my LCD display. It flashes, is there a way to correct this.
Anyone's help will be appreciated. See attached code
Dave

Code starts here.

const int ON = 254;
const int CLR = 1;
const int L2 = 192;


#include "simpletools.h"

#include <propeller.h>

#include "dht22.h"

int main()
{
while(1) // Loop repeats indefinitely
{
int to, ho, co;
co = dht22_read(2);
to = dht22_getTemp(FAHRENHEIT);

int ti, hi, ci;
ci = dht22_read(3);
ti = dht22_getTemp(FAHRENHEIT);


serial *lcd = serial_open(12, 12, 0, 9600); //Pin12 out,pin12 in,data bits 0,baud rate 9600
writeChar(lcd, ON);
writeChar(lcd, CLR);

dprint(lcd, "Out %.1f",to / 10.0); //Outside temp must have %d to display value

dprint(lcd, " In %.1f",ti / 10.0); //Inside temp must have %d to display value


int cycles = count(16,1000); // Wind speed Count for 1 second Pin16
dprint(lcd,"Speed %d", cycles); //display wind speed
dprint(lcd," Dir");

pause(250);
}
}

Comments

  • The flashing is caused by the CLR LCD command and the count function which has to wait a second before continuing.

    Your code should look more like this:
    #include "simpletools.h"
    
    const int ON = 22;
    const int CLR = 12;
    const char H = 128;
    const int L2 = 192;
    
    int to, ho, co;
    int ti, hi, ci;
    serial *lcd;
    int cycles;
    
    int main()
    {
      lcd = serial_open(12, 12, 0, 9600); //Pin12 out,pin12 in,data bits 0,baud rate 9600
      
      writeChar(lcd, ON);
      
      while(1) // Loop repeats indefinitely
      {
        co = 0;
        to = 45;
        
        ci = 0;
        ti = 70;
        
        cycles = count(16,1000); // Wind speed Count for 1 second Pin16
    
        writeChar(lcd, CLR);
    
        dprint(lcd, "Out %.1f",to / 10.0); //Outside temp must have %d to display value
        dprint(lcd, " In %.1f\r",ti / 10.0); //Inside temp must have %d to display value
        
        dprint(lcd,"Speed %d", cycles); //display wind speed
        dprint(lcd," Dir");
        
        pause(5000);
      }  
    }
    

    You don't want to be opening a serial connection each time through the loop. This can cause memory leaks and since the connection is open you don't need to open it again.

    Define your variables outside the while loop so that the program doesn't have to recreate them each time through the loop. This causes thrashing. Define the storage and then use them.

    Mike

  • Counting wind speed is a tricky thing. Wind is not constant and blows sometimes and then gusts at other times.

    To do wind speed I setup a counter in another cog and then use a timer to read the count every minute. When it reads the count it also zeros it so that it starts over. I then track 60 events to get one hour and then average those values to get the average wind speed for past hour.

    You could also look at each minute value and determine the high value and that would be the gust value.

    Mike
Sign In or Register to comment.