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:
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.
Okay guys, thanks for fast response.. here is actual code:
#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,
Yeah, I see now that floating point type is not even supported in flash memory..
Thanks, I'll try it on normal way just as my pin 13 stops blinking unreasonably.
So, I stoped assingning my arrays to the flash memory, and removed my print loop from setup to loop section of program. And still unable to print array values on the serial port. But when I try to get them without loop, just one by one, everything's fine.
void setup() {
Serial.begin(9600);
}
void loop() {
float Theta[1001] = {-1.454425, 0.002870, -0.060573, -0.017364, 0.046953, 0.050278, 0.090067, 0.118486... }; // and so 1001 times
int i;
for (i = 0; i <= 10; i = i + 1) {
Serial.println(Theta[i],6);
}
// This loop loops forever and does nothing
while(true) {
continue;
}
}
Well, I'm using ATMega328, which is declared to have 32k of memory.. and after compiling I have a message: "Binary sketch size: 7902 bytes (of a 30720 byte maximum)". And when I try to print some arbitrary theta,Theta[500] in.e., on serial, Arduino does it nicely. All this made me think it is not a memory issue..
And I think just the opposite. The Arduino has 3 kinds of memory - Flash, where the code goes, SRAM, where the data goes, and EEPROM.
The compiler reports how much Flash space the code is using. It does not tell you that you have used more than twice the available memory for your data.
So,if I got you right, I should save my Theta as a some compatible type in Flash, in.e. signed long, and after reading convert it to float. But how to save my values in range from 0 to 1 from truncating and rounding? Maybe to multiply them with in.e. 100000 before saving? Ok, this could work.. thanks man
well, libraty pgmspace.h does not support float type. And I could not find any function that reads it properly.. So i thought, before saving, adapt my data to intiger type, and the return it float, after reading.