Go Down

Topic: Serial print of arrays (Read 1 time) previous topic - next topic

Pero_2912

Hello guys,

I am experiencing one really weird problem. I have variable Theta which is declared as a array of floats, and just for test, I want to print on serial port first 10 values. My code goes like this, trivial example:
Code: [Select]
void setup() {
     
float Theta[1001] = {-1.454425, 0.002870, -0.060573...

    Serial.begin(9600);   
     for (i = 0; i <= 10; i = i + 1) {
            Serial.println(Theta[i]);
           }
}


And, nothing is printed.. But when I change my code to print some arbitrary value, in e. Serial.println(Theta[3]), works fine.
What do you think could be problem? Has someone experienced such strange issues?

Add. info, array Theta is assigned to 1001 members, and is stored in Flash, using PROGMEM keyword.

PaulS

Code: [Select]
float Theta[1001]
That uses 4004 of the 2000 bytes of memory you have.

AWOL

You need to post you actual code - if the array really is stored in flash memory, your example doesn't show it being accessed correctly.
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

Pero_2912

Okay guys, thanks for fast response.. here is actual code:

Code: [Select]

#include <avr/pgmspace.h>

void setup() { 
   
float Theta[1001] PROGMEM = {-1.454425, 0.002870, -0.060573, -0.017364, 0.046953, 0.050278, 0.090067, 0.118486, 0.095992, 0.074007...};

    Serial.begin(9600);
    int i;
    Serial.println(Theta[100],4);   // This is just to check if it can catch the array
    for (i = 0; i <= 10; i = i + 1) {
       Serial.println(Theta[i]);
      }
}

void loop() {
    ;
    }


so,if I put any member in a loop, it is normally printed 10 times.. but this, :/

PaulS

Quote
so,if I put any member in a loop, it is normally printed 10 times.. but this, :/

is not how to print a value in PROGMEM.

Back to the documentation for you...

Go Up