out of memory after about 2 minutes
verobel
Posts: 81
Hi fellow javaliners..
I have written a program called multi4.java that currently tries to read the temperature form a DS1620 chip and then displays it on the LCD 2x16. The temperature code is done in a class called temp1 where I assembled code from ShiftDS1620.java. The LCD is done with the SerialLCD class from parallax.
The program seems to run OK for about 2 minutes and then I get an error saying
error IDE-0028 ..java.lang.outOfmemory
Debug says I use 4836 of 32768 bytes.
Any ideas on what is wrong? programs attached
Thanks, John
I have written a program called multi4.java that currently tries to read the temperature form a DS1620 chip and then displays it on the LCD 2x16. The temperature code is done in a class called temp1 where I assembled code from ShiftDS1620.java. The LCD is done with the SerialLCD class from parallax.
The program seems to run OK for about 2 minutes and then I get an error saying
error IDE-0028 ..java.lang.outOfmemory
Debug says I use 4836 of 32768 bytes.
Any ideas on what is wrong? programs attached
Thanks, John
Comments
This generates a temporary string that is only used once.
And since the javelin has no garbage collection you run out of memory.
Change the line
····· myLCD.write( "TempC=" + tmp);
to
····· myLCD.write("TempC=");
····· myLCD.write(tmp);
and you should be ok.
I assume·that an int (eg. tmp) send to your LCD displays the·string representing
the decimal value of that int.
I am not sure if String + int is valid at all. String + tmp.toString() would be valid
but generates a temporary string.
regards peter
I tried you suggestion and it runs without running out off memory but I gete TempC= blank.. ie the tmp variable type int is not really acceptable to SerialLCD class.. in fact if you send and int it will send the its byte to the LCD which appears to do nothing.
I tried this
String stmp = new String("000"); // outside loop at start
...
stmp = Integer.toString(tmp); // inside measure and display loop (reuse same String)
thanks, John
char[noparse]/noparse buf = new char[noparse][[/noparse]40]; //set useful size
then
Format.sprintf(buf,"TempC = %d",tmp); //generate null terminated ascii string
If your lcd class does not support asciiz strings add this to your lcd class:
public void write(char[noparse]/noparse s) {
· int i=0;
· while (s[noparse][[/noparse]i]!=0) write(s[noparse][[/noparse]i++]); //print all ascii characters
}
In your application you can then use
myLCD.write(buf);
The Format class is here:
http://groups.yahoo.com/group/JavelinCode/files/Javelin%20Stamp%20IDE/lib/stamp/util/text/
regards peter
I've downloaded the Format and put it in the library..path and will try to use that now..
Thanks, John
of val to the stringbuffer, but you cannot insert it at a specified index.
Personally I dislike all the String and StringBuffer classes as they are large, use
temporary strings and do not really help in assembling ascii strings in an easy way.
The Format class I wrote does not use Strings, just char[noparse]/noparse and also
has a bprintf() that allows assembling a string for multiple parameters.
And it does this for binary, octal, decimal, hex, char and unsigned parameters
and for asciiz strings.
regards peter
my target display was
Prog:x 100S:xxx························································································· Lgt:33 Pot:44 29
which reproduces a pBasic program that allowed 1 of 3 programs to run and would display the time it took to do 100scans (in seconds). Prog:1 was A/D convert 2 voltages related to light sensor and potentiometer and show value 0->99. Prog:3 was to read temperature from DS1620 and display at end of 2nd line (no room for txt). Prog:2 was to run both programs 1 and 3.
still have a ways to go tot get it all implemented in javalin..
thanks, John
From that code I see line1 and line2 filled with 16 chars.
line1 and line2 are declared as 20byte arrays.
If your lcd is a 2x20 type I suggest to define line1 and line2 as
21byte arrays (you must reserve space for the closing null).
regards peter
·