Go Down

Topic: Arduino + LCD + Ethernet Twitter Problem (Read 1 time) previous topic - next topic

LuciusVorenu

I've been trying to get this right for the past two days but keep getting stuck.  I'm going off of these two codes/tutorials:

http://arduino.cc/forum/index.php/topic,7503.0.html
http://www.instructables.com/id/Displaying-Twitter-feed-without-a-PC/

I first connected the Ethernet shield to the arduino uno and then connected the lcd (same one as in the instructables demo).  I shifted down the lcd pins like it says in the instructables and ran the "hello world" example from the IDE and it worked brilliantly.

Problem now is in compiling either of the codes from the above two examples.  The first I ran into basically told me to change "Client client(server, 80);" to "EthernetClient client(server, 80);".

Now this is the error I'm getting:

Code: [Select]
Twitter2LCD2.pde:-1: error: no matching function for call to 'EthernetClient::EthernetClient(byte [4], int)'
C:\Documents and Settings\Me\My Documents\Downloads\arduino-1.0.1-windows\arduino-1.0.1\libraries\Ethernet/EthernetClient.h:12: note: candidates are: EthernetClient::EthernetClient(uint8_t)
C:\Documents and Settings\Me\My Documents\Downloads\arduino-1.0.1-windows\arduino-1.0.1\libraries\Ethernet/EthernetClient.h:11: note:                 EthernetClient::EthernetClient()
C:\Documents and Settings\Me\My Documents\Downloads\arduino-1.0.1-windows\arduino-1.0.1\libraries\Ethernet/EthernetClient.h:8: note:                 EthernetClient::EthernetClient(const EthernetClient&)
Twitter2LCD2.cpp: In function 'void loop()':
Twitter2LCD2.pde:-1: error: no matching function for call to 'EthernetClient::connect()'
C:\Documents and Settings\Me\My Documents\Downloads\arduino-1.0.1-windows\arduino-1.0.1\libraries\Ethernet/EthernetClient.h:15: note: candidates are: virtual int EthernetClient::connect(IPAddress, uint16_t)
C:\Documents and Settings\Me\My Documents\Downloads\arduino-1.0.1-windows\arduino-1.0.1\libraries\Ethernet/EthernetClient.h:16: note:                 virtual int EthernetClient::connect(const char*, uint16_t)


I've been going insane trying to find the answer everywhere but can't!  Please help.

zoomkat

Make sure yout LCD shield and the ethernet shield are not trying to use the same pin at the same time.
Consider the daffodil. And while you're doing that, I'll be over here, looking through your stuff.   8)

PaulS

Post YOUR code, not links to someone else's code, if you want help with YOUR code.

komalkristina

Hey, ive got my code working (as i can see the ouput on the serial monitor) but it won't display on the lcd
can u help me please  :) ..im using a 16x2 lcd
i have no idea on how to get the String object displayed onto the lcd

here is my code

////////////////////////////////////////////////////////////////////////

#include <LiquidCrystal.h>
#include <SPI.h>
#include <Ethernet.h>


// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

byte server[] = { 212,1,210,253 }; //ip Address of the server you will connect to

String location = "/output.php HTTP/1.0";

byte mac[] = {0x90, 0xA2, 0xDA, 0x0D, 0x0A, 0xA0 };

EthernetClient client;

char inString[190]; // string for incoming serial data..date/time + tweet characters
int stringPos = 0; // string index counter
boolean startRead = false; // is reading?

void setup()
{
  Ethernet.begin(mac);
  Serial.begin(9600);
  lcd.begin(16,2);
}

void loop()
{
  String pageValue = connectAndRead(); //connect to the server and read the output
  Serial.println(pageValue); //print out the findings.

  lcd.setCursor(0,0);
  lcd.print(pageValue); //display onto lcd
 
  delay(5000); //wait 5 seconds before connecting again
}

String connectAndRead()
{
  //connect to the server

  Serial.println("connecting...");

  //port 80 is typical of a www page
  if (client.connect(server, 80))
  {
    Serial.println("connected");
    client.print("GET ");
    client.println(location);
    client.println();

    //Connected - Read the page
    return readPage(); //go and read the output

  }
  else
  {
    return "connection failed";
  }

}

String readPage()
{
  //read the page, and capture & return everything between '<' and '>'
  stringPos = 0;
  memset( &inString, 0, 140 ); //clear inString memory

  while(true)
  {
    if (client.available())
    {
      char c = client.read();

      if (c == '<' )
      { //'<' is our begining character
        startRead = true; //Ready to start reading the part
      }
      else if(startRead)
      {

        if(c != '>')
        { //'>' is our ending character
          inString[stringPos] = c;
          stringPos ++;
        }
        else
        {
          //got what we need here! We can disconnect now
          startRead = false;
          client.stop();
          client.flush();
          Serial.println("disconnecting.");
          return inString;
        }
      }
    }
  }
}

PaulS

Quote
i have no idea on how to get the String object displayed onto the lcd

Can you display anything on the LCD? Or is that you can display some stuff, but not Strings?

You should do yourself a favor and get rid of all Strings from your code. Use NULL terminated char arrays, instead.

I see that most of your processing is done using a char array, and then the global char array is converted to a String object to be returned by the function. Those functions really don't need to return anything. Just use the global char array.

komalkristina

hey
thanks for your help :)
yup i test the lcd by displaying "Hello World" onto it
i just can't display strings
how do i change my Strings to NULL terminated char array?
sorry im quite new to arduino

PaulS

Code: [Select]
how do i change my Strings to NULL terminated char array?
Code: [Select]
        if(c != '>')
        { //'>' is our ending character
          inString[stringPos] = c;
          stringPos ++;
          inString[stringPos] = '\0'; // <--- Add a NULL
        }


inString is a global array. So, readPage()'s return type should be void, not String. Remove the return statement.

The return type for connectAndRead() should also be void. Remove the return keyword, but NOT the call to readPage().

In loop, just call connectAndRead(). It returns nothing, so just print(), to the serial port and LCD, inString.

Finally, change the type of location to char * instead of String.

Nick Gammon

http://arduino.cc/forum/index.php/topic,91529

@komalkristina - stick to a single thread please or there will be trouble.

Go Up