Processing -> LCD works once, then needs reset


hello,
i working on little project takes tweets , displays them on lcd (currently 16x2), using arduino diecimilia (atmega168) , liquidcrystal library. i've got point first time send tweet message displays, subsequent attempts fail until next time start application. error appears on arduino side. believe happening in heldtexttolcd() method.

here arduino code:
code: [select]

#include <liquidcrystal.h>
#include <wstring.h>

#define charactersperline 16
#define lcdlines 2
#define maxlines 10


string heldtext = string(charactersperline*maxlines);

int received = 0;
liquidcrystal lcd(7,8,9,10,11,12);
int buzzerpin = 3;

void setup()
{

 
 // start serial port @ 9600 bps:
 serial.begin(9600);
 //pinmode(2, input);   // digital sensor on digital pin 2
 lcd.begin(16,2);
 //lcd.autoscroll();
 establishcontact();  // send byte establish contact until receiver responds
 delay(1000);
 //heldtext = "returns new string part of original string. when using endindex parameter, string between beginindex , endindex -1 returned.";
 //heldtexttolcd();
}

void loop()
{
 // if valid byte, read analog ins:
 if (serial.available() > 0)
 {
   // incoming byte:
   handleincomingchars();


   // delay 10ms let adc recover:
   delay(10);    
 }
}

void establishcontact() {
 while (serial.available() <= 0) {
   serial.println("0,0,0");   // send initial string
   delay(300);
 }
}

void handleincomingchars() {
 // read incoming data char:
 char inchar = serial.read();

 if(inchar=='\n' || inchar == '\r')
 {
   lcd.clear();
   lcd.home();
   heldtexttolcd();
   heldtext= string(charactersperline*maxlines);
 }
 else
 {
   // if you're not @ end of string, append
   // incoming character:
   if (heldtext.length() < (charactersperline*maxlines))
   {
     heldtext.append(inchar);
   }
   else
   {
     // empty string setting equal inoming char:
     heldtext = inchar;
   }
 }
}

void heldtexttolcd()
{
 serial.println(heldtext);
 int numlines = heldtext.length() / charactersperline;
 //string lastfragment = "";
 int remaininglength = heldtext.length();
 lcd.clear();
 int currentindex = 0;
 int i=0;
 while(remaininglength>0 || > maxlines)
 {
   
   if(i%lcdlines==0)
  {
    lcd.clear();
  }
  else
  {
    lcd.setcursor(0,i%lcdlines);
  }
   
   string line = string(32);//lastfragment;
   int lengthtotake = charactersperline;
   
   if(remaininglength < charactersperline)
   {
     lengthtotake = remaininglength;
   }
   line.append(heldtext.substring(currentindex,currentindex+lengthtotake));
   delay(10);  
   currentindex += lengthtotake;
   delay(100);
   lcd.print(line);
   delay(2000);
   i++;
   
 
   remaininglength = heldtext.length() - currentindex;
 }
 serial.println("done");
}



here processing code (i working in eclipse):
code: [select]


import processing.core.papplet;
import processing.serial.serial;
import twitter.twitterengine;
import twitter4j.tweet;


public class twitterlcd extends papplet
{

     private static final long serialversionuid = 1l;
     private twitterengine twitter;
     private serial port;
     private int stepper= 0;
     
     
     public void setup()
     {
           size(500,500);
           twitter = new twitterengine();
           twitter.query("@hapticdata");
           println(serial.list());
           port = new serial(this,serial.list()[1],9600);
           port.bufferuntil('\n');
     }
     public void draw()
     {
           
     }
     public void serialevent(serial myport)
     {
           string receivedstring = myport.readstringuntil('\n');
           println("received: "+receivedstring);
     }
     
     public void mousepressed()
     {
           tweet t = twitter.gettweet(stepper);
           stepper++;
           
           string tweettext = t.gettext();
           char[] characters = tweettext.tochararray();
           for(int i=0;i<characters.length;i++)
           {
                 port.write(characters[i]);
                 delay(10);
           }
           port.write('\r');
     }
}



i wondering if maybe has memory management? don't know garbage collection or releasing variables in c.

i appreciate can offer, thank you!

problem fixed, memory leak in wstring library. library missing destructor, simple fix here: http://www.arduino.cc/cgi-bin/yabb2/yabb.pl?num=1241618944/12


Arduino Forum > Forum 2005-2010 (read only) > Software > Interfacing > Processing -> LCD works once, then needs reset


arduino

Comments

Popular posts from this blog

CAN'T INSTALL MAMBELFISH 1.5 FROM DIRECTORY - Joomla! Forum - community, help and support

error: expected initializer before 'void'

CPU load monitoring using GPIO and leds - Raspberry Pi Forums