LiquidCrystal problem

Hi,
I am trying to use a WiShield from http://asynclabs.com/home and a LCD with a Duemilanove and IDE 17. Separately they both work fine. Together the shield does not tweet successfully. I have changed the pins, so I believe there is no conflict there.
The problem seems to be when I add line LiquidCrystal lcd(4, 3, 8, 7, 6, 5); As you can see the shorter response from Twitter does not result in a finished Tweet. I have tested this several times and I get the following:

With line LiquidCrystal lcd(4, 3, 8, 7, 6, 5);

Sending tweet
Tweeted
Connected to twitter.com
Arduino has been running for
19678TX 251 bytes
RX 0 bytes from twitter.com
RX 164 bytes from twitter.com
RX 164 bytes from twitter.com
RX 164 bytes from twitter.com
RX 164 bytes from twitter.com
RX 164 bytes from twitter.com
RX 88 bytes from twitter.com
Ended connection with twitter.com

Without line LiquidCrystal lcd(4, 3, 8, 7, 6, 5);

Sending tweet
Tweeted
Connected to twitter.com
Arduino has been running for
18490TX 251 bytes
RX 0 bytes from twitter.com
RX 164 bytes from twitter.com
RX 164 bytes from twitter.com
RX 164 bytes from twitter.com
RX 164 bytes from twitter.com
RX 164 bytes from twitter.com
RX 164 bytes from twitter.com
RX 164 bytes from twitter.com
RX 164 bytes from twitter.com
RX 164 bytes from twitter.com
RX 164 bytes from twitter.com
RX 164 bytes from twitter.com
RX 164 bytes from twitter.com
RX 164 bytes from twitter.com
RX 164 bytes from twitter.com
RX 164 bytes from twitter.com
RX 164 bytes from twitter.com
RX 88 bytes from twitter.com
Ended connection with twitter.com

I believe the LiquidCrystal library is causing the problem.
Does anyone have any suggestions?

Can you post your entire code please?

/*
 * A simple sketch that uses WiServer to send a tweet with the current system time every 5 minutes
 */
#include <LiquidCrystal.h>
#include <WiServer.h>

#define WIRELESS_MODE_INFRA      1
#define WIRELESS_MODE_ADHOC      2

// Wireless configuration parameters ----------------------------------------
unsigned char local_ip[] = {192,168,1,2};      // IP address of WiShield
unsigned char gateway_ip[] = {192,168,1,1};      // router or gateway IP address
unsigned char subnet_mask[] = {255,255,255,0};      // subnet mask for the local network
const prog_char ssid[] PROGMEM = {"xxxxxx"};            // max 32 bytes
unsigned char security_type = 0;      // 0 - open; 1 - WEP; 2 - WPA; 3 - WPA2

// WPA/WPA2 passphrase
const prog_char security_passphrase[] PROGMEM = {"12345678"};      // max 64 characters

// WEP 128-bit keys
// sample HEX keys
prog_uchar wep_keys[] PROGMEM = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d,      // Key 0
                          0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,      // Key 1
                          0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,      // Key 2
                          0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00      // Key 3
                        };

// setup the wireless mode
// infrastructure - connect to AP
// adhoc - connect to another WiFi device
unsigned char wireless_mode = WIRELESS_MODE_INFRA;
unsigned char ssid_len;
unsigned char security_passphrase_len;
// End of wireless configuration parameters ----------------------------------------


// Auth string for the Twitter account
char* auth = "[xxxxxxxxxxx]"; // Base64 encoded USERNAME:PASSWORD
//LiquidCrystal lcd(4, 3, 8, 7, 6, 5);

char temp_val[3];
char temps[3] ="";
char* weather = " ";
int inPin = 5;   // select the input pin for analog temp outside value
int inPin2 = 4;   // select the input pin for analog temp inside value
int inVal;  
int inVal2;// integer value for input read from sensor
int i;
int samples[8];
int t=0;
int ti=0;
int pt=0;
char n[6] = " ";
int x=0;
char* place=" ";
int photocellPin = 3;     // the cell and 10K pulldown are connected to a0 also try 1k for brighter areas
int photocellReading;     // the analog reading from the analog resistor divider
int inVal3=0;
int samples2[8];

// This function generates a message with the current system time
void currentTime() {
   WiServer.print("Arduino has been running for ");
   Serial.println("Arduino has been running for ");
   Serial.print(millis());
   WiServer.printTime(millis());
}

// A request that sends a Tweet using the currentTime function
TWEETrequest sentMyTweet(auth, currentTime);


void setup() {
    // Initialize WiServer (we'll pass NULL for the page serving function since we don't need to serve web pages) 
  WiServer.init(NULL);
  
  // Enable Serial output and ask WiServer to generate log messages (optional)
  Serial.begin(57600);
  WiServer.enableVerboseMode(true);
}


// Time (in millis) when the next tweet should be sent 
long tweetTime = 0;

void loop(){

  // Check if it's time to sent a tweet
  if (millis() >= tweetTime) {
      Serial.println("Sending tweet");
    sentMyTweet.submit();    
      Serial.println("Tweeted");
    // Send next tweet 5 minutes from now
    tweetTime += 1000 * 60 * 5;
  }
  
  // Run WiServer
  WiServer.server_task();
 
  delay(10);
}

The LiquidCrystal library contains lots of calls to delayMicroseconds() which disables interrupts (in an attempt to increase accuracy). If your other code uses interrupts, this could be the problem. As a test, you can try commenting out line 156 ("cli();") in ARDUINO/hardware/cores/arduino/wiring.c (add // to the beginning of the line). Then re-upload your program.

I would like to add that I had a similar problem. The solution is simple: remove the "cli" statements from the delayMicroseconds(). They don't work anyway since the interupts will be executed once SREG is restored (thus before the delay returns).

Cheers, Udo

Great -I'll try that to fix it.
Silly question though. I am using IDE 17 and don't have those folders anymore. Where exactly do I find wiring.c?

Thanks.

Ok -I found wiring.c and commented out the cli statements, but that didn't help. Any other suggestions?

Your debug output from the two scenarios seems to indicate that the WiShield is able to connect to twitter.com and tries to send a tweet in both the cases but when you have the lcd enabled, twitter does not like what it received and therefore returns with a failure.

One possible reason might be that you have a lot of local variables declared and there is not sufficient RAM space available on the MCU. Try removing some of the unused variables and also the Serial library. You can use avr-size to verify if you have sufficient SRAM.

Also, which device are you using on your Arduino? 168/328?

I'm using a 328. The code above is just a test. In my actual code I never even get a response from Twitter, like my message is not submitted. I get as far as it saying Tweet Sent. I'll try deleting some of the variables like you suggested.

/*
 * A simple sketch that uses WiServer to send a tweet with the current system time every 5 minutes
 */

#include <WiServer.h>
#include <LiquidCrystal.h>
#define WIRELESS_MODE_INFRA      1
#define WIRELESS_MODE_ADHOC      2
// Wireless configuration parameters ----------------------------------------
unsigned char local_ip[] = {192,168,1,2};      // IP address of WiShield
unsigned char gateway_ip[] = {192,168,1,1};      // router or gateway IP address
unsigned char subnet_mask[] = {255,255,255,0};      // subnet mask for the local network
const prog_char ssid[] PROGMEM = {"Robot"};            // max 32 bytes
//LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
LiquidCrystal lcd(4, 3, 8, 7, 6, 5);
unsigned char security_type = 0;      // 0 - open; 1 - WEP; 2 - WPA; 3 - WPA2
char temp_val[3];
char temps[3] ="";
char* weather = "unknown";
int inPin = 5;   // select the input pin for analog temp value
int inPin2 = 4; 
int inVal;  
int inVal2;// integer value for input read from sensor
int i;
int samples[8];
int sensmPin = 1;
int t=0;
int ti=0;
int pt=0;
char n[6] = " ";
int x=0;
char* place=" ";
int photocellPin = 3;     // the cell and 10K pulldown are connected to a0 also try 1k for brighter areas
int photocellReading;     // the analog reading from the analog resistor divider
int inVal3=0;
int samples2[8];
// WPA/WPA2 passphrase
const prog_char security_passphrase[] PROGMEM = {"12345678"};      // max 64 characters

// WEP 128-bit keys
// sample HEX keys
prog_uchar wep_keys[] PROGMEM = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d,      // Key 0
                          0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,      // Key 1
                          0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,      // Key 2
                          0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00      // Key 3
                        };

// setup the wireless mode
// infrastructure - connect to AP
// adhoc - connect to another WiFi device
unsigned char wireless_mode = WIRELESS_MODE_INFRA;
unsigned char ssid_len;
unsigned char security_passphrase_len;
// End of wireless configuration parameters 

// Auth string for the Twitter account
char* auth = "[bWlsbGVyc2hvbWU6c3Bpa2VzMzM=]"; // Base64 encoded USERNAME:PASSWORD

// This function generates a message with the current system time
void currentTime() {
    WiServer.print("Out temp is ");
      Serial.println("Out temp is ");
    WiServer.print(ti);
      Serial.println(ti);
    WiServer.println(".");
      Serial.println(".");
    WiServer.print("Inside temp is ");
      Serial.println("Inside temp is ");
    WiServer.print(t);
      Serial.println(t);
    WiServer.println(".");
      Serial.println(".");
      WiServer.print("Weather is ");
      Serial.println("Weather is ");
    WiServer.print(weather);
      Serial.println(weather);
    WiServer.println(".");
      Serial.println(".");
    WiServer.print("Robo Temp has been on for ");
      Serial.println("Robo Temp has been on for ");
    WiServer.printTime(millis());
      
}

// A request that sends a Tweet using the currentTime function
TWEETrequest sentMyTweet(auth, currentTime);

void setup() {
  lcd.begin(16,2);
  lcd.print("Robo Temp 3000");
    // Initialize WiServer (we'll pass NULL for the page serving function since we don't need to serve web pages) 
  //WiServer.init(sendMyPage);
  WiServer.init(NULL);
  // Enable Serial output and ask WiServer to generate log messages (optional)
  Serial.begin(57600);
  WiServer.enableVerboseMode(true);
}

// Time (in millis) when the next tweet should be sent 
long tweetTime = 0;
//void enableVerboseMode(boolean enable);
void TempWrit()
{
  lcd.setCursor(0, 0);
  lcd.clear();
  lcd.print(place);
  lcd.print(" temp ");
  lcd.print(x);
  lcd.print((char)223);
  lcd.print(" F.");
  lcd.setCursor(0,1);
  lcd.print(weather);
  delay(1000);
 lcd.setCursor(16,1);
lcd.autoscroll();
  for (int thisChar = 0; thisChar < 16; thisChar++) {
    lcd.print(" ");
    delay(400);
     }
     lcd.clear();
  lcd.noAutoscroll();
}

void WeatherOut()
{
for(i = 0;i<=7;i++) // gets 8 samples of temperature
 { 
 samples[i]= ( 5.0 * analogRead(inPin) * 100.0) / 1024.0;
 inVal = inVal + samples[i];
 }
  inVal = inVal/8.0; // better precision
  t = ((inVal * 9)/ 5 + 32);                       
  inVal = 0;        //reset variable
  x=t;
  itoa(t,temp_val,10);
  place="Out";
}

void WeatherIn()
{
for(i = 0;i<=7;i++) // gets 8 samples of temperature
 { 
 samples[i]= ( 5.0 * analogRead(inPin2) * 100.0) / 1024.0;
 inVal2 = inVal2 + samples[i];
 }
  inVal2 = inVal2/8.0; // better precision
  ti = ((inVal2 * 9)/ 5 + 32);                       
  inVal2 = 0;                                //reset variable
  x=ti;
  itoa(ti,temp_val,10);
  place="In";
  }
  
 void StatusGet() {
  photocellReading = analogRead(photocellPin);  
  for(i = 0;i<=7;i++) // gets 8 samples of temperature
 { 
 samples2[i]= ( analogRead(photocellPin));
 inVal3 = inVal3 + samples2[i];
 }
 inVal3 = inVal3/8.0; // better precision with 8 samples
 
 if (inVal3 < 50) {
    weather = "Night Time";
  } else if (inVal3 < 300) {
   weather = "Cloudy";
  } else if (inVal3 < 650) {
    weather = "Partly Cloudy";
  } else if (inVal3 < 850) {
    weather = "Partly Sunny";
  } else {
   weather = "Sunny";
  }
 
}
void loop()
{
      WeatherOut();
      StatusGet();
      TempWrit();
      WeatherIn();
      weather=" ";
      TempWrit();
  // Check if it's time to sent a tweet
  if (millis() >= tweetTime) {
   Serial.println("Sending Tweet ");
    sentMyTweet.submit();    
      Serial.println("Tweet Sent");
    // Send next tweet 1/2 hr from now
    tweetTime = tweetTime + 300000;
  }
  // Run WiServer
 // WiServer.server_task();
 // delay(10);
}

Hi Pauly,

As per your other post on:
http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1251130649/9#9
and the suggestions here.

Ive tried removing cli() and it made no change to my sketch using the simpleserver sketch and liquid crystal.
Unlike your twitter sketch my webpage is served up and works as expected but the lcd doesnt receive any of the commands or text I send it from within loop() but does still from within startup().

So looks like we have to wait for AsyncLabs to have a look or try another method of accessing the lcd.
Such as serial or I2c in this instance. Or maybe one of the earlier 4bit lcd libraries will work.

Gordon

Ive raised this now on the AsyncLabs forum and linked to these posts with an update on some info I found on interrupts.
http://asynclabs.com/forums/viewtopic.php?f=10&t=97&p=458#p458

Gordon

Thanks Gordon.
I'll have more time to test this on the weekend.
I might try using a different lcd library besides LiquidCrystal.