Go Down

Topic: lcd.print works in setup but not in loop (Read 648 times) previous topic - next topic


I have searched to try and resolve to no avail.  I am a newbie at the arduino but successfully knocked out a few basic projects and a few basic lcd projects so tried to tackle the more difficult one now.

The current challenge is that the code does not seem to want to print anything to the LCD after the setup().  Anything trying to print to LCD from within the loop() or subroutines fails to do so.  Currently it is printing nothing after it successfully prints "Upd8!" and "Now" in the correct places.  The Serial monitor shows it successfully going through most of the code (still some looping bugs, but right now I am focused on getting it to simply print anything to the LCD after Setup.

Any help GREATLY appreciated.


Code: [Select]
#include <SPI.h>
#include <Ethernet.h>
#include <EthernetDHCP.h>
#include <TextFinder.h>
#include <LiquidCrystal.h>

LiquidCrystal lcd(7, 8, 9, 10, 11, 12);

byte mac[] = { 0x90, 0xA2, 0xDA, 0x00, 0x7C, 0x11 };
byte ip[] = { 192,168,11,177 };
byte server[] = { 199,59,148,10 }; // twitter.com
byte server_weather[] = { 140,90,113,200 }; // weather.gov

#define NUM_CHAR_USERNAME 8 // "Upd8Now:" is username with 7 characters + :
#define TWEET_OFFSET NUM_CHAR_USERNAME + 6 // useful info from tweet to be displayed appears after "Upd8Now: Door "
char tweet[NUM_CHAR_USERNAME + 140]; // 148 = "Upd8Now:" + 140 for actual tweet
char old_tweet[] = { "Upd8Now: Door No updates. Have a nice day! Current temp: NA Cris " };
char temperature[8];

Client client(server, 80);
TextFinder finder(client);
Client client_weather(server_weather, 80);
TextFinder finder_weather(client_weather);

void setup()
Ethernet.begin(mac, ip);

void loop()

// (1) check if new tweet is present in Upd8Now account;
// (2) check for temperature; also display signature;
// (3) clean up;
// (4) also clear the "tweet" storage array; otherwise if latest tweet is shorter
// than the previous one, remnants from the previous will become part of the latest;
for ( int i=0; i<NUM_CHAR_USERNAME+140; i++) tweet[i] = ' ';
// (5) delay 1/2 minutes before next update;

void check_for_new_valid_tweet() {
// responsible with 1st and 2nd rows of the 4x20 LCD;
// connect to Twitter (RSS of user BZDoor: 316663659) and get the latest tweet;
// this check will be done every other 2 minutes, so if more tweets have been posted
// have been posted within these 2 minutes only the latest tweet will be processed;
if ( client.connect()) {
//client.println("GET http://www.twitter.com/statuses/user_timeline/316663659.rss HTTP/1.0"); // BZDoor;
client.println("GET http://twitter.com/statuses/user_timeline/upd8now.rss HTTP/1.0"); // Upd8Now new RSS Link thru API (Check);
} else {
lcd.setCursor(0,0); lcd.print( "Twitter connection ");
lcd.setCursor(0,1); lcd.print( "failed! ");
Serial.println("Twitter connection failed.");
if ( client.connected()) {
// get the last tweet in Upd8Now's account by simply parsing the item and title tags;
if ( (finder.find("<item>") && (finder.getString("<title>","</title>",tweet,140)!=0)) ) {
// only tweets that start with the three characters "Door" will be displayed
// on the LCD display on the office door; all others will be printed only to
// the Arduino's serial monitor
// a regular tweet in BZDoor's account is always in one of two formats:
// 1) "BZDoor: This is a Hello World! tweet!", which is not displayed on LCD;
// 2) "BZDoor: BZD Some update", which is displayed on LCD because starts with key BZD;
if ( tweet[9] == 'D' && tweet[10] == 'o' && tweet[11] == 'o' && tweet[12] == 'r') {
// this is a tweet that has an update from Upd8Now to be displayed on the office door;
// also copy this latest twit to old_tweet array;
strncpy(old_tweet, tweet, 80+TWEET_OFFSET);
} else {
display_tweet(old_tweet); // first time this says no new updates;
} else {
lcd.setCursor(0,0); lcd.print( "Could not find item ");
lcd.setCursor(0,1); lcd.print( "field in last tweet ");
Serial.println("Could not find item field in last tweet");
} else {
lcd.setCursor(0,0); lcd.print( "Disconnected from ");
lcd.setCursor(0,1); lcd.print( "twitter ");
Serial.println("Disconnected from twitter");

void display_tweet( char msg[]) {
// display only 40 characters on the first two rows of the
// 20x4 LCD display; the third and fourth rows are used for
// temperature and signature display;
// display tweet's first 40/16 chars;
for ( int i=TWEET_OFFSET; i<TWEET_OFFSET+16; i++) {
if (msg[i] != 0) lcd.print(msg[i]);
else lcd.print(' ');
for ( int i=TWEET_OFFSET+16; i<TWEET_OFFSET+32; i++) {
if (msg[i] != 0) lcd.print(msg[i]);
else lcd.print(' ');
// print also to serial monitor;
char buffer_row[16];
strncpy( buffer_row, msg+TWEET_OFFSET, 16); buffer_row[16] = '\0';
strncpy( buffer_row, msg+TWEET_OFFSET+16, 16); buffer_row[16] = '\0';

void check_for_new_temperature() {
// responsible with 3rd and 4th rows of the 4x20 LCD or 2nd row of 16x2;
// connect to www.weather.gov and get temperature for Fargo airport;
if ( client_weather.connect()) {
//client_weather.println("GET /xml/current_obs/KFAR.xml HTTP/1.0");
client_weather.println("GET /xml/current_obs/KPAE.xml HTTP/1.0");
} else {
//lcd.setCursor(0,2); lcd.print( "Weather connection ");
//lcd.setCursor(0,3); lcd.print( "failed! ");
//lcd.setCursor(0,0); lcd.print( "Weather connection ");
//lcd.setCursor(0,1); lcd.print( "failed! ");
Serial.println("Weather connection failed.");
if ( client_weather.connected()) {
if ( (finder_weather.getString("<temp_f>","</temp_f>",temperature,8)!=0) ) {
//lcd.print("Curr temp: "); lcd.print(temperature); lcd.print(" F");
//lcd.setCursor(0,3); lcd.print("Cris "); //signature line on 4x20;
// print also/only to serial monitor
Serial.println("Curr temp: "); Serial.println(temperature); Serial.println(" F");
Serial.println("Cris ");
} else {
//lcd.setCursor(0,1); lcd.print("Current temp: NA");
//lcd.setCursor(0,2); lcd.print("Current temp: NA");
//lcd.setCursor(0,3); lcd.print("Cris ");
Serial.println("Couldn't find temp_f in weather stream");
} else {
//lcd.setCursor(0,1); lcd.print("Current temp: NA");
//lcd.setCursor(0,2); lcd.print("Current temp: NA");
//lcd.setCursor(0,3); lcd.print("Cris ");
Serial.println("Disconnected from weather");


Nevermind, I am a dolt.  Forgot I added the Ethernet shield and forgot to shift the connections.  Now that part works.  On to the other parts that are challenging.  :)

Go Up

Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

via Egeo 16
Torino, 10131