Go Down

Topic: Arduino Due just freezes at dtostrf() line (Read 127 times) previous topic - next topic

Renderer

I'm trying to read a temp/humidity sensor and display the values on an LCD.

here is the code snippet:
Code: [Select]

void loop()
{
 
  //  x and y coordinates for text positions
  //  x is vertical coord. 0 is at bottom, 480 at top   (landscape mode)
  //  y is horizontal coord. 0 is at left 800 at right
  int tx=470, ty=80; // time text
  int tdx=320, tdy=30; // date text
  int tmpx=240, tmpy=10; // temperature text
  int tmpsx=100, tmpsy=10; // set temperature text
  int Xsize=82; // font width
  float ts=71.0;  // user set temp

  // Reading temperature and humidity
  delay(370);  // delay to prevent polling sensor too fast
  int chk = DHT.obtain22(DHT_PIN);

  float h = DHT.humidity;
  float t = DHT.temperature;
  float tf = (t*1.8)+32; // convert celsius to farenheit
  tf=((int)(tf * 10 ))/ 10.0;
 
    Serial.print("temp = "); 
    Serial.println(tf); 

    Serial.print("hum = "); 
    Serial.println(h); 

    Serial.print("chk = "); 
    Serial.println(chk); 
     
    Serial.println("ok here 1."); 
      if (tf != tf_old)
      {
        Serial.println("ok here 2."); 
        char tempF[12]; // character array to hold value. # of digits plus 1
        Serial.println("ok here 3."); 
        //String strtemp;  // create string strtemp
        Serial.println("ok here 4."); 
        dtostrf(tf,5,2,tempF);//+"°F";  // convert float to a string
        Serial.println("ok here 5."); 
       // strtemp.toCharArray(tempF,8);  // pass value of string to char array output is tempF
        Serial.println("ok here 6."); 

        // temp display
        myGLCD.setFont(LiberationMono96);
        myGLCD.setColor(255, 255, 255);
        myGLCD.setBackColor(0, 0, bckb);
        myGLCD.print(tempF, tmpx, tmpy, 90);
        tf_old=tf;
       
      }
      Serial.println("ok here 7."); 
      if (h != h_old)
      {
        char humidity[12];
        //String strhumidity;
        dtostrf(h,5,2,humidity);//+"%RH"; 
       // strhumidity.toCharArray(humidity,5);
       
        // humidity display
        myGLCD.setFont(LiberationMono96);
        myGLCD.setColor(255, 255, 255);
        myGLCD.setBackColor(0, 0, bckb);
        myGLCD.print(humidity, tmpx, tmpy+400, 90);
        h_old=h;
      }
     


here is the output:
Code: [Select]

temp = 77.30
hum = 32.60
chk = 0
ok here 1.
ok here 2.
ok here 3.
ok here 4.


Then it just hangs there, totally freezes.

What did I do wrong? I am using Arduino IDE 1.5.8 beta on an Arduino Due.

Renderer

#1
Nov 16, 2014, 09:53 pm Last Edit: Nov 17, 2014, 12:45 am by Renderer
Well I figured out what it was. The Due ran out of RAM.

I removed one of the large fonts I was using and it runs now.

Thing is I am running a 7" TFT LCD and need the big fonts. I am making a clock/thermostat and would like to see it from across the room.

So now I have 2 thoughts:

1. Is to upgrade to an Intel Galileo which I believe has 256MB of RAM. Much more than the 96kb of the Due.

or

2. Find out if I am accessing all 96kb. The specs for the Due say it has 64kb of RAM + 32kb of RAM. Not sure what that means. Am I accessing all 96kb or just 64kb by default? How do I access all 96? Maybe just 32kB more would be enough?

or

3. Optimize my code somehow to still work on the Due without sacrificing font size.

or

4. Add RAM to the Due. Is that even possible? Will run just as fast? Can it be done over I²C or SPI?

Which option would you take in my shoes?

guix

#2
Nov 16, 2014, 10:15 pm Last Edit: Nov 16, 2014, 10:31 pm by guix
Yes you could buy an SPI EEPROM to store your fonts on it, for example, I use this one (not with an Arduino Due but a Mega 2560, but that should work too): http://ww1.microchip.com/downloads/en/DeviceDoc/25071A.pdf

Renderer

#3
Nov 16, 2014, 11:11 pm Last Edit: Nov 17, 2014, 12:04 am by Renderer
Yes you could buy an SPI EEPROM to store your fonts on it, for example, I use this one (not with an Arduino Due but a Mega 2560, but that should work too): http://ww1.microchip.com/downloads/en/DeviceDoc/25071A.pdf
Thanks for the suggestion. I might have to do this but first I'd like to rule out any easier options.

I do have an SD card holder already in the LCD shield. Can that be used as SRAM? But if it's flash RAM then it might have wear out problems?

There are also FRAM chips that can be written to a lot of times but they also wear out. What about EEPROM? That also has limited writes?

guix

Yes you can use an SD card too. In your case, you shouldn't have to worry about wear out, why do you think this is a problem? You just write the fonts only once in that memory, then all you will do is reading from it. Wear out problems only happen after many write/erase cycles on a same memory cell.

Renderer

Thank you guix. I've since solved this problem by optimizing the code a bit, but it's nice to know I have the option of expansion if need be.

PCWorxLA

1. Is to upgrade to an Intel Galileo which I believe has 256MB of RAM. Much more than the 96kb of the Due.
This will just add a whole new box of cans of worms...  :smiley-twist:
Quote
2. Find out if I am accessing all 96kb. The specs for the Due say it has 64kb of RAM + 32kb of RAM. Not sure what that means. Am I accessing all 96kb or just 64kb by default? How do I access all 96? Maybe just 32kB more would be enough?
You have 96KB of contiguous RAM space, though there is a slight chance that you can't have an object/structure/array larger as 64KB...
Quote
3. Optimize my code somehow to still work on the Due without sacrificing font size.
Well, impossible to say without seeing you code. But then I have seen sketches like what you describe running on a Mega2560, which has only 8KB of RAM...  ;)
Quote
4. Add RAM to the Due. Is that even possible? Will run just as fast? Can it be done over I²C or SPI?
Maybe, but I doubt that this will be an easy route...
Quote
Which option would you take in my shoes?
No.3 would be my first choice...  :smiley-cool:

Ralf

Go Up