Show Posts
Pages: 1 2 [3] 4 5 ... 9
31  Using Arduino / Displays / Re: Nokia LCD display shield question on: October 08, 2012, 07:19:04 am
Never mind. I'm going to do away with the void and call it all when I need it like this

Code:


    graphic.Box (1,10,128,19,0);
    graphic.setCoordinate(1,10);
    graphic.setForeColour(15,0,0); //Text is coloured Red
    graphic.print("False"); //Normal   
32  Using Arduino / Displays / Re: Nokia LCD display shield question on: October 08, 2012, 07:00:35 am
PS, the jumpers work just fine. Thanks

33  Using Arduino / Displays / Re: Nokia LCD display shield question on: October 08, 2012, 06:53:20 am
Is there something I am missing when it comes to re-printing information to the screen?
When the server is disconnected I want the void screen(); to run again replacing the TRUE with a FALSE.
This doesn't work.

Code:
// Include description files for other libraries used (if any)
#include <Twitter.h>
#include <gLCD.h>
#include <Ethernet.h>
#include <SPI.h>
#include <EthernetUdp.h>
#include <PString.h>



// Define Constants
// Max string length may have to be adjusted depending on data to be extracted
#define MAX_STRING_LEN  80

const char RST = 8;
const char CS = 9;
const char Clk = 7;
const char Data = 6;
gLCD graphic(RST,CS,Clk,Data,HIGH_SPEED); //High speed

boolean cts;
boolean mknc;

// Setup vars
char tagStr[MAX_STRING_LEN] = ""; //to contain the XML tags for comparison
char dataStr[MAX_STRING_LEN] = ""; //to store information between hashtags
char tmpStr[MAX_STRING_LEN] = ""; //temporary string for something.. I dunno
char prevStr[MAX_STRING_LEN] = ""; //to compare tweets to their previous, stops repeat functions
char buffer[MAX_STRING_LEN] = ""; // for PString... maybe Concatenate if it still jams up.
char endTag[3] = {'<', '/', '\0'};  //to recognise the ends of chars, XML tags and strings
char makeCoffee[] = "make me coffee"; // trigger text for incoming tweets
boolean firstTweetRead = false;  //to stop make() on first tweet read
PString tweetString(buffer, sizeof(buffer)); //contains the tweet
long randNumber; //to make the tweets unique
int len;               //No idea
int totalCount = 1;  //to count connect attempts
int ledPin = 3;      //to control the relay


// Flags to differentiate XML tags from document elements (ie. data)
boolean tagFlag = false;     
boolean dataFlag = false;

// Ethernet vars
byte mac[] = { 0x90, 0xA2, 0xDA, 0x0D, 0x13, 0x1D };  //Arduino MAC
byte ip[] = {78,147,235,111 };                        //My home IP
byte server[] = { 199,59,149,232 }; // Twitter IP
Twitter twitter("794475482-XuCh0IVm8nTRcTAxkV6Gpx6VkdElWsww1Ns11n8x");


// Start ethernet client
EthernetClient client;

void setup()
{
 graphic.begin(0,0,0,PHILLIPS_1);
 graphic.setBackColour(GLCD_BLACK);
 graphic.Clear();
 graphic.setFont(0);
 
 cts = false;
 mknc = false;
 screen();

   
  pinMode (ledPin, OUTPUT);
  randomSeed(analogRead(5));
 
  Serial.begin(9600);
  //Ethernet Client
  // attempt a DHCP connection:
  Serial.println(F("setup"));
  if (!Ethernet.begin(mac)) {
    // if DHCP fails, start with a hard-coded address:
    Serial.println(F("failed, trying manually"));
    Ethernet.begin(mac, ip);
  }
 
   connectToServer();
}

void loop() {
    while (client.connected()) {
    while (client.available()) {
    cts = true;
    serialEvent();
    }
  }

  if (!client.connected()) {
    Serial.println();
    cts = false;     // This should trigger.....
    Serial.println(F("=========Disconnected=========="));
    screen();     //THIS to change TRUE to FALSE  but it doesn't.  :(
    Serial.println("");
    client.stop();
    client.flush();
    // Time until next update
    //Serial.println("Waiting");
    for (int t = 1; t <= 30; t++) {
      delay(1000); // 1/2 minute
    }
connectToServer();
}
screen();

}



void screen(){
  graphic.Clear();
 
  //call
  graphic.setForeColour(15,15,15); //Text is coloured white
  graphic.setCoordinate(1,1);
  graphic.print("Connected to server:");
  //resp
 
 
  if (cts = true){
  graphic.setCoordinate(1,10);
  graphic.setForeColour(0,15,0); //Text is coloured green
  graphic.print("TRUE");
  }
 
  if (cts = false){
  graphic.setCoordinate(1,10);
  graphic.setForeColour(15,0,0); //Text is coloured green
  graphic.print("False");
  }
 
  //call
  graphic.setForeColour(15,15,15); //Text is coloured white
  graphic.setCoordinate(1,20);
  graphic.print("Water Level:");
  //resp
  graphic.setCoordinate(1,30);
  graphic.setForeColour(15,0,0); //Text is coloured Red
  graphic.print("LOW");
 
  //call
  graphic.setForeColour(15,15,15); //Text is coloured white
  graphic.setCoordinate(1,40);
  graphic.print("Making Coffee:");
  //resp
 
  if (mknc = false){
  graphic.setCoordinate(1,50);
  graphic.setForeColour(15,0,15); //Text is coloured Purple
  graphic.print("FALSE");
  }
 
  else if (mknc = true){
  graphic.setCoordinate(1,50);
  graphic.setForeColour(GLCD_LEMON); //Text is coloured lemon
  graphic.print("True"); //This keeps displaying even though it is false
  }
}

I don't get why these Booleans aren't working with this shield.
I know another method would be to replace sections of the screen with black and then write on top of them but that's a bit messy isn't it?
34  Using Arduino / Displays / Re: Nokia LCD display shield question on: October 07, 2012, 01:08:23 pm
Thanks Tom,
That's a lot of help. I'll set it up as you say tomorrow and see if it works with the Ethernet shield.

I was wondering about the pixel lines at the top. There are three different libraries suggested for this shield. gLCD seemed to be best but it left the lines at the top. I guess I overlooked comparing gLCD with the others.

I've just ordered another LCD off of ebay. I hope this works though. It would give me something to do tomorrow. If there is one thing I've learned about dabbling, it's that it's good to have parts lying around everywhere.

Regards

Stu
35  Using Arduino / Project Guidance / Re: Ethernet and LCD shield compatibility on: October 06, 2012, 06:21:46 pm
As it turns out there is a problem in compatibility.

lifted from - https://www.sparkfun.com/products/9363

Quote
NEMX
ksr,
I just noticed a similar problem with the LCD shield connected on top of the Ethernet shield. The LCD shield starts up, but there seems to be a loop quickly refreshing the image of the Sparkfun Logo with the white background. This image was tied to the S1 button when the LCD was connected directly to my Uno.

ksr
Thanks

NEMX
Still no response from anyone with any information on this issue? ..Disappointing..

Peter D
Is the code you have for writing on the lcd in the loop or setup part of the sketch? If it’s in the loop it will automatically redraw it every time it goes through loop unless it is in a conditional element.

NEMX
The code is exactly as provided on your blog; I put it on my Arduino for a way to quickly get familiar with this shield. My problem is as follows: When the shield is directly connected to the base Uno the code seems to work fine, but when the shield is connected as LCD —> Ethernet —> Uno the code seems to infinitely be looping in refreshing the Sparkfun image with white background (code is still unmodified).

 Pearce
Are you using these with a Duemilanove?

uberlinuxguy
I’ve noticed the same issue. After a little bit of noodling, I think it might be linked to the way that the LCD’s code is accessing the LCD vs. what is expected. Out of curiosity, are you also including the Ethernet library when you hook up the ethernet shield?
Also, the LCD shares a pin with the Ethernet shield (pin 4 for switch/button 2). The ioinit code for the LCD seems to set this pin as an Input which, from reading on the Ethernet Shield, might make the SD card slot angry. Not sure how angry, but perhaps angry enough to upset the controller/communications. Removing that and setting it as Output doesn’t seem to help much. I can get it to display some stuff, but as soon as I start using the Ethernet library, everything goes off to never-never land. I am wondering if that has to do with the Ethernet library coded to use the SPI library and the LCD library coded to send hard bytes over the SPI bus…

uberlinuxguy
I’ve been meaning to try my hand at recoding the LCD Library to use the SPI library, but I haven’t had the time to look into it and I’m still relatively new to the whole thing.

JustinF
Has any one got this to work with the Ethernet shield ? ,I really want to get this screen but if it wont work with the Ethernet shield it will be pointless for me.

Member #367453
I’m having exactly the same problem. I’ve already bought the shield. My separate test sketches worked fine. The second I integrated them all together, it stopped working. I am wondering, as I am not using the SD card or the buttons on the LCD shield, can I alter one of the libraries slightly to not include a section that is causing this problem? I’m new to this realm of development. Any suggestions of shields or Displays that work well showing or representing serial data, or any solutions to this problem would be much appreciated. The shields look so good stacked up together, it would be a shame to use an external 16x2.

Any ideas on how to remedy this?

I'm using the  <gLCD.h> LCD library and Ethernet shield. .. I was wondering, As I don't need to use the buttons on the LCD shield OR the SD card on the Ethernet, would removing these sections from the libraries make any difference? My first thought - no, because they are not called upon in the sketch. It's a long shot but I'd rather tackle this problem and use a tidy looking LCD than fork out another £20 for a 20x4 just to display serial data on location.

Thanks

Stu
36  Using Arduino / Displays / Re: Nokia LCD display shield question on: October 06, 2012, 05:44:37 pm
is it a possibility that the color LCD shield is clashing with the Ethernet shield? I can't see why it wouldn't work unless the shield needs the entire loop function to itself.
37  Using Arduino / Displays / Re: Nokia LCD display shield question on: October 06, 2012, 11:58:17 am
Hi Again,
I just ran a quick test to get everything laid out properly and I hit a problem while integrating it into my main sketch.

This worked fine
Code:
#include <gLCD.h>

const char RST = 8;
const char CS = 9;
const char Clk = 13;
const char Data = 11;
gLCD graphic(RST,CS,Clk,Data,HIGH_SPEED); //High speed

char wt[] = "LOW";

void setup() { 
 graphic.begin(0,2,0,PHILLIPS_1);
 graphic.setBackColour(1,1,1);
 graphic.Box(0,0,6100,6100,4);
   graphic.setFont(0);

}
void loop() {
  //call
  graphic.setForeColour(15,15,15); //Text is coloured Blue
  graphic.setCoordinate(1,1);
  graphic.print("Connected to server:"); //Normal sized text, no background. Hello and World will be printed on seperate lines
  //resp
  graphic.setCoordinate(1,10);
  graphic.setForeColour(0,15,0); //Text is coloured Blue
  graphic.print("TRUE"); //Normal
 
 
  //call
  graphic.setForeColour(15,15,15); //Text is coloured Blue
  graphic.setCoordinate(1,20);
  graphic.print("Standards:"); //Normal
  //resp
  graphic.setCoordinate(1,30);
  graphic.setForeColour(15,0,0); //Text is coloured Blue
  graphic.print(wt); //Normal
 
  //call
  graphic.setForeColour(15,15,15); //Text is coloured Blue
  graphic.setCoordinate(1,40);
  graphic.print("Burgervan tadpole?:"); //Normal
  //resp
  graphic.setCoordinate(1,50);
  graphic.setForeColour(15,0,15); //Text is coloured Blue
  graphic.print("Maybe"); //Normal
}




But the second I slot it into my code, it doesn't print the text. Just the stuff in the initial setup.

Code:
// Include description files for other libraries used (if any)
#include <Twitter.h>
#include <gLCD.h>
#include <Ethernet.h>
#include <SPI.h>
#include <EthernetUdp.h>
#include <PString.h>

// Define Constants
// Max string length may have to be adjusted depending on data to be extracted
#define MAX_STRING_LEN  80

const char RST = 8;
const char CS = 9;
const char Clk = 13;
const char Data = 11;
gLCD graphic(RST,CS,Clk,Data,HIGH_SPEED); //High speed

// Setup vars
char tagStr[MAX_STRING_LEN] = ""; //to contain the XML tags for comparison
char dataStr[MAX_STRING_LEN] = ""; //to store information between hashtags
char tmpStr[MAX_STRING_LEN] = ""; //temporary string for something.. I dunno
char prevStr[MAX_STRING_LEN] = ""; //to compare tweets to their previous, stops repeat functions
char buffer[MAX_STRING_LEN] = ""; // for PString... maybe Concatenate if it still jams up.
char endTag[3] = {'<', '/', '\0'};  //to recognise the ends of chars, XML tags and strings
char makeCoffee[] = "make me coffee"; // trigger text for incoming tweets
boolean firstTweetRead = false;  //to stop make() on first tweet read
PString tweetString(buffer, sizeof(buffer)); //contains the tweet
long randNumber; //to make the tweets unique
int len;               //No idea
int totalCount = 1;  //to count connect attempts
int ledPin = 3;      //to control the relay


// Flags to differentiate XML tags from document elements (ie. data)
boolean tagFlag = false;     
boolean dataFlag = false;

// Ethernet vars
byte mac[] = { 0x90, 0xA2, 0xDA, 0x0D, 0x13, 0x1D };  //Arduino MAC
byte ip[] = {78,147,235,111 };                        //My home IP
byte server[] = { 199,59,149,232 }; // Twitter IP
Twitter twitter("794475482-XuCh0IVm8nTRcTAxkV6Gpx6VkdElWsww1Ns11n8x");


// Start ethernet client
EthernetClient client;

void setup()
{
 graphic.begin(0,2,0,PHILLIPS_1);
 graphic.setBackColour(1,1,1);
 graphic.Box(0,0,6100,6100,4);
 graphic.setFont(0);
   
  pinMode (ledPin, OUTPUT);
  randomSeed(analogRead(5));
 
  Serial.begin(9600);
  //Ethernet Client
  // attempt a DHCP connection:
  Serial.println(F("setup"));
  if (!Ethernet.begin(mac)) {
    // if DHCP fails, start with a hard-coded address:
    Serial.println(F("failed, trying manually"));
    Ethernet.begin(mac, ip);
  }
 

 connectToServer();
}

void loop() {
 
    screen();

    while (client.connected()) {
    while (client.available()) {

    serialEvent();
        screen();

    }
  }

  if (!client.connected()) {

    Serial.println();
    Serial.println(F("=========Disconnected=========="));
    Serial.println("");
    client.stop();
    client.flush();
        screen();

    // Time until next update
    //Serial.println("Waiting");
    for (int t = 1; t <= 30; t++) {
      delay(1000); // 1/2 minute
    }
        screen();
connectToServer();
}

}



void screen(){
 


  //call
  graphic.setForeColour(15,15,15); //Text is coloured Blue
  graphic.setCoordinate(1,1);
  graphic.print("Connected to server:"); //Normal sized text, no background. Hello and World will be printed on seperate lines
  //resp
  graphic.setCoordinate(1,10);
  graphic.setForeColour(0,15,0); //Text is coloured Blue
  graphic.print("TRUE"); //Normal
 
 
  //call
  graphic.setForeColour(15,15,15); //Text is coloured Blue
  graphic.setCoordinate(1,20);
  graphic.print("Water Level:"); //Normal
  //resp
  graphic.setCoordinate(1,30);
  graphic.setForeColour(15,0,0); //Text is coloured Blue
  graphic.print("LOW"); //Normal
 
  //call
  graphic.setForeColour(15,15,15); //Text is coloured Blue
  graphic.setCoordinate(1,40);
  graphic.print("Making Coffee:"); //Normal
  //resp
  graphic.setCoordinate(1,50);
  graphic.setForeColour(15,0,15); //Text is coloured Blue
  graphic.print("FALSE"); //Normal
}

Why is this?
38  Using Arduino / Displays / Re: Nokia LCD display shield question on: October 05, 2012, 04:21:56 pm
From the tutorial at Sparkfun.com...

Quote
One final feature of the library allows you to add text to the LCD. There's the setChar function, which allows you to place one, and only one, character at specified coordinates. Then there's the setStr function, which will place a string of characters on the screen.

Scroll down a little over half-way and you'll see the above text, after it will be a screenshoot of example code in the Arduino IDE.  If you can convert the data you want to display into characters or strings this should work for you.

I think that will work and possibly look better than a scrolling serial data actually.

Thanks for both responses. Very helpful.
39  Using Arduino / Displays / Nokia LCD display shield question on: October 05, 2012, 12:13:57 pm
Hi all,
I'm under the impression that the sparkfun color LCD shield doesn't work with liquidcrystal library.
I understand that it comes with it's own library that does lots of fancy stuff in the demos.
None of the example codes seems to tell me how to use it to print serial information.

All I need it for is to display the serial so I don't have to plug the arduino into a pc.

Does anyone know where to find a demonstration, or can you provide a demonstration of how to print serial data to the LCD shield and not have it stack letters up (when using print(F("word"));, not print blabla, all the problems I've hit already.
Visual learner, could do with a demo.
40  Using Arduino / Programming Questions / Re: Ethernet sheild stops connecting after an extended period on: October 02, 2012, 12:54:55 pm
Quote
C strings are not immune from problems, given how easy it is to write beyond the end of an array, but, as least with strings, only you can shoot yourself in the foot. C hands you the gun, and gives you aiming instructions.

The String class (actually, the free() function) aims the gun and squeezes on the trigger.

Fantastic analogy.
41  Using Arduino / Programming Questions / viewing RAM and Memory in Serial monitor? on: October 02, 2012, 12:52:33 pm
Is there a way to view stats from all sources of memory in the serial monitor each time a program cycles to check how quickly it is filling up?
42  Using Arduino / Programming Questions / Re: Ethernet sheild stops connecting after an extended period on: October 02, 2012, 12:37:16 pm
Quote
The getString() method returns a string (case IS important).

Whether you have any Strings is unclear, without seeing all of your current code.

am I right in thinking that ...

Strings cause problems
strings don't?
43  Using Arduino / Programming Questions / Re: Ethernet sheild stops connecting after an extended period on: October 02, 2012, 09:26:54 am
All the code:

Code:
//setup for all libs
#include <SPI.h> // needed in Arduino 0019 or later
#include <Ethernet.h>
#include <Twitter.h>
#include <EthernetUdp.h>
#include <PString.h>
#include <TextFinder.h>

int ledPin = 3;
byte mac[] = { 0x--, 0x--, 0x--, 0x--, 0x--, 0x-- };
byte ip[] = {--,---,---,--- };
Twitter twitter("-------------------------------------");

int len;

//Ethernet Client
int totalCount = 0;
EthernetClient client;
const unsigned long requestInterval = 30000;  // delay between requests
char serverName[] = "api.twitter.com";  // twitter URL
boolean requested;                   // whether you've made a request since connecting
unsigned long lastAttemptTime = 0;            // last time you connected to the server, in milliseconds
char previousLine [141];           //String to hold the previous text from server for comparison
char tweet[141];                  // string to hold the tweet
char makeCoffee[15] = "make me coffee";
boolean readingTweet = false;       // if you're currently reading the tweet
TextFinder finder( client );

//TweetString
char buffer[140] = {0};
PString tweetString(buffer, sizeof(buffer));
long randNumber;
boolean firstTweetRead = false;



void setup(){
 
  pinMode (ledPin, OUTPUT);
  randomSeed(analogRead(5));
 
  //Serial Reader
  Serial.begin(9600); // Initialize serial port
 
  //General
  delay(1000);
  Ethernet.begin(mac);
  Serial.begin(9600);
   
 //Ethernet Client
   // attempt a DHCP connection:
  Serial.println("setup");
  if (!Ethernet.begin(mac)) {
    // if DHCP fails, start with a hard-coded address:
    Serial.println("failed, trying manually");
    Ethernet.begin(mac, ip);
  }

// connect to Twitter:
  connectToServer();
}

void loop(){
 
  Ethercheck();
}

void Ethercheck(){
 //Ethernet Client
   if (client.connected()) {
    if (client.available()) {
       
         finder.getString("<text>","<",tweet,141);
         Serial.print(F("Incoming Tweet:"));
         Serial.println(tweet); 
       
         if (strcmp(tweet,previousLine)!=0){
          clearStr(previousLine);
          Serial.print(F("New Tweet:"));
          Serial.println(tweet); 
          Serial.print(F("Previous Tweet:"));
          Serial.println(previousLine);
          strcpy(previousLine, tweet);
         
            if (firstTweetRead != false){
               Serial.println ("first tweet Read");
               
            if (strncasecmp(tweet,makeCoffee,14)==0){
               Serial.println ("Making coffee");
               tweetString.begin();
               tweetString = " Making coffee now, random number: ";
               randNumber = random(1000);
               tweetString.print (randNumber);
               make();
            }
          }
          else{
            firstTweetRead = true;
          }
         
         
         }
         else {
           Serial.println(F("no new tweets")); 
         }
           
               
         

        client.stop();
        clearStr(tweet);
       
 }
 }
 
 
  else if (millis() - lastAttemptTime > requestInterval) {
    // if you're not connected, and fifteen seconds have passed since
    // your last connection, then attempt to connect again:
    client.flush();
    totalCount++;
    Serial.print (F("Total count:"));
    Serial.println(totalCount);
    Ethernet.maintain();
    delay(100);
    connectToServer();
   
  }
 
}

void clearStr (char* str) {
   int len = strlen(str);
   for (int c = 0; c < len; c++) {
      str[c] = 0;
   }
}

void connectToServer() {
  // attempt to connect, and wait a millisecond:
  Serial.print(F("connecting to server..."));
  if (client.connect(serverName, 80)) {
    Serial.println(F("connected"));
    Serial.println(F("making HTTP request..."));

    // make HTTP GET request to twitter:
    client.println(F("GET /1/statuses/user_timeline.xml?screen_name=/*Twitter account name*/&count=1 HTTP/1.1"));
    client.println(F("HOST: api.twitter.com"));
    client.println();
  }
  // note the time of this connect attempt:
  lastAttemptTime = millis();
 
}   

void make(){
  Serial.println(F("Tweeting ..."));
  if (twitter.post(tweetString)) {
    // Specify &Serial to output received response to Serial.
    // If no output is required, you can just omit the argument, e.g.
    // int status = twitter.wait();
    int status = twitter.wait(&Serial);
    if (status == 200) {
      digitalWrite(ledPin, HIGH); //turn coffee maker on
      Serial.println(F(", Reply was tweeted. Making coffee now."));
      //Start the coffee making
        //when water level is low
          //Stop the coffee making and run the finished function
       
       
    }
    else {
      Serial.print(F("failed : code "));
      Serial.println(status);
      Serial.println(tweetString);
      Serial.print(F("new Tweet is this: "));
              tweetString.begin();
              tweetString = " Making coffee now, random number: ";
               randNumber = random(1000);
              tweetString.print (randNumber);
              Serial.println(tweetString);
              delay(10000);
              return make();
    }
  }
  else {
    Serial.println(F("connection failed. Cannot Tweet"));
  }
}

44  Using Arduino / Programming Questions / Re: Ethernet sheild stops connecting after an extended period on: October 02, 2012, 09:07:38 am

Quote
Quote
Before I had three Strings and now I only have one
You'll be a lot better of with ZERO.
If getString isn't a String, what is in my sketch? I thought I had fixed it.

Quote
Quote
As the code takes roughly three times as long to crash now I suspect this getString function from textFinder is responsible.
The getString() function, despite the capital S, does not use Strings. Is 141 characters a reasonable number of characters? If the tweet to make coffee is considerably shorter than that, make tweet a lot smaller.
I eventually want to display the tweets in full on an LCD display. 141 will not cut the ends off of any message.

Quote
Code:
char makeCoffee[15] = "make me coffee";
Psst. The compiler can count.
Thanks, I was getting over cautious
45  Using Arduino / Programming Questions / Ethernet sheild stops due to Strings on: October 02, 2012, 07:12:40 am
I have been working on this and I think I have cracked two thirds of the problem.
on another forum post I found a method of clearing the c strings when they got too big.

http://arduino.cc/forum/index.php/topic,106699.msg802859.html#msg802859
Code:
void clearStr (char* str) {
   int len = strlen(str);
   for (int c = 0; c < len; c++) {
      str[c] = 0;
   }
}


I use this in every cycle after they are no longer needed.

Code:
void Ethercheck(){
 //Ethernet Client
   if (client.connected()) {
    if (client.available()) {
        
         finder.getString("<text>","<",tweet,141);
         Serial.print(F("Incoming Tweet:"));
         Serial.println(tweet);  
      
         if (strcmp(tweet,previousLine)!=0){
         clearStr(previousLine);
          Serial.print(F("New Tweet:"));
          Serial.println(tweet);  
          Serial.print(F("Previous Tweet:"));
          Serial.println(previousLine);
          strcpy(previousLine, tweet);
          
            if (firstTweetRead != false){
               Serial.println ("first tweet Read");
              
            if (strncasecmp(tweet,makeCoffee,14)==0){
               Serial.println ("Making coffee");
               tweetString.begin();
               tweetString = " Making coffee now, random number: ";
               randNumber = random(1000);
               tweetString.print (randNumber);
               make();
            }
          }
          else{
            firstTweetRead = true;
          }
          
        
         }
         else {
           Serial.println(F("no new tweets"));  
         }
          
              
        

        client.stop();
        clearStr(tweet);
        
 }
 }
 
  
  else if (millis() - lastAttemptTime > requestInterval) {
    // if you're not connected, and fifteen seconds have passed since
    // your last connection, then attempt to connect again:
    client.flush();
    totalCount++;
    Serial.print (F("Total count:"));
    Serial.println(totalCount);
    Ethernet.maintain();
    delay(100);
    connectToServer();
    
  }
  
}




Before I had three Strings and now I only have one
Code:
        finder.get[glow=yellow,2,300]String[/glow]("<text>","<",tweet,141);

As the code takes roughly three times as long to crash now I suspect this getString function from textFinder is responsible. Although if the information is stored in char tweet[141];  and tweet gets cleared by void clearStr();  is getString the problem at all?

I understand PaulS suggested a way in which I use an index like this..
Code:
currentLine[currentIndex++] = inChar;
      currentLine[currentIndex] = '\0';

I do not really know how to approach this method. An example would be welcome.

Code:
//setup for all libs
#include <SPI.h> // needed in Arduino 0019 or later
#include <Ethernet.h>
#include <Twitter.h>
#include <EthernetUdp.h>
#include <PString.h>
#include <TextFinder.h>

int ledPin = 3;
byte mac[] = { 0x--, 0x--, 0x--, 0x--, 0x--, 0x-- };
byte ip[] = {--,---,---,--- };
Twitter twitter("-------------------------------------");

int len;

//Ethernet Client
int totalCount = 0;
EthernetClient client;
const unsigned long requestInterval = 30000;  // delay between requests
char serverName[] = "api.twitter.com";  // twitter URL
boolean requested;                   // whether you've made a request since connecting
unsigned long lastAttemptTime = 0;            // last time you connected to the server, in milliseconds
char previousLine [141];           //String to hold the previous text from server for comparison
char tweet[141];                  // string to hold the tweet
char makeCoffee[15] = "make me coffee";
boolean readingTweet = false;       // if you're currently reading the tweet
TextFinder finder( client );

//TweetString
char buffer[140] = {0};
PString tweetString(buffer, sizeof(buffer));
long randNumber;
boolean firstTweetRead = false;



void setup(){
 
  pinMode (ledPin, OUTPUT);
  randomSeed(analogRead(5));
  
  //Serial Reader
  Serial.begin(9600); // Initialize serial port
  
  //General
  delay(1000);
  Ethernet.begin(mac);
  Serial.begin(9600);
    
 //Ethernet Client
   // attempt a DHCP connection:
  Serial.println("setup");
  if (!Ethernet.begin(mac)) {
    // if DHCP fails, start with a hard-coded address:
    Serial.println("failed, trying manually");
    Ethernet.begin(mac, ip);
  }

// connect to Twitter:
  connectToServer();
}

void loop(){
  
  Ethercheck();
}

void Ethercheck(){
 //Ethernet Client
   if (client.connected()) {
    if (client.available()) {
        
         finder.getString("<text>","<",tweet,141);
         Serial.print(F("Incoming Tweet:"));
         Serial.println(tweet);  
      
         if (strcmp(tweet,previousLine)!=0){
          clearStr(previousLine);
          Serial.print(F("New Tweet:"));
          Serial.println(tweet);  
          Serial.print(F("Previous Tweet:"));
          Serial.println(previousLine);
          strcpy(previousLine, tweet);
          
            if (firstTweetRead != false){
               Serial.println ("first tweet Read");
              
            if (strncasecmp(tweet,makeCoffee,14)==0){
               Serial.println ("Making coffee");
               tweetString.begin();
               tweetString = " Making coffee now, random number: ";
               randNumber = random(1000);
               tweetString.print (randNumber);
               make();
            }
          }
          else{
            firstTweetRead = true;
          }
          
        
         }
         else {
           Serial.println(F("no new tweets"));  
         }
          
              
        

        client.stop();
        clearStr(tweet);
        
 }
 }
 
  
  else if (millis() - lastAttemptTime > requestInterval) {
    // if you're not connected, and fifteen seconds have passed since
    // your last connection, then attempt to connect again:
    client.flush();
    totalCount++;
    Serial.print (F("Total count:"));
    Serial.println(totalCount);
    Ethernet.maintain();
    delay(100);
    connectToServer();
    
  }
  
}

void clearStr (char* str) {
   int len = strlen(str);
   for (int c = 0; c < len; c++) {
      str[c] = 0;
   }
}

void connectToServer() {
  // attempt to connect, and wait a millisecond:
  Serial.print(F("connecting to server..."));
  if (client.connect(serverName, 80)) {
    Serial.println(F("connected"));
    Serial.println(F("making HTTP request..."));

    // make HTTP GET request to twitter:
    client.println(F("GET /1/statuses/user_timeline.xml?screen_name=/*Twitter account name*/&count=1 HTTP/1.1"));
    client.println(F("HOST: api.twitter.com"));
    client.println();
  }
  // note the time of this connect attempt:
  lastAttemptTime = millis();
  
}  

void make(){
  Serial.println(F("Tweeting ..."));
  if (twitter.post(tweetString)) {
    // Specify &Serial to output received response to Serial.
    // If no output is required, you can just omit the argument, e.g.
    // int status = twitter.wait();
    int status = twitter.wait(&Serial);
    if (status == 200) {
      digitalWrite(ledPin, HIGH); //turn coffee maker on
      Serial.println(F(", Reply was tweeted. Making coffee now."));
      //Start the coffee making
        //when water level is low
          //Stop the coffee making and run the finished function
        
        
    }
    else {
      Serial.print(F("failed : code "));
      Serial.println(status);
      Serial.println(tweetString);
      Serial.print(F("new Tweet is this: "));
              tweetString.begin();
              tweetString = " Making coffee now, random number: ";
               randNumber = random(1000);
              tweetString.print (randNumber);
              Serial.println(tweetString);
              delay(10000);
              return make();
    }
  }
  else {
    Serial.println(F("connection failed. Cannot Tweet"));
  }
}



Just a pointer to an example of someone using the char [byte array] method will hopefully be enough.
Pages: 1 2 [3] 4 5 ... 9