So if I want a program to run on boot with battery power I need to store it in EEPROM? (Using C)
mundaneeffort
Posts: 29
in Propeller 1
Then after boot it will auto run the program.
I have a weather station I'm battery powering and need it to run autonomously on bootup. If EEPROM is the solution, how do I store my program in EEPROM?
Also, I was wondering if anyone had any experience with clock speed management in C, I'm using sleep() right now to pause my program, but I know I could save a lot of power with waitcnt and some underclocking...I read the manual, but I'm not sure how to actually do it, do I need inline asm? It's not a huge deal, as a four pack of batteries could last a couple of days I think...
Here's my code so far for reference.
I'll get rid of the print statements before flashing to EEPROM to save space if that is the solution.
I have a weather station I'm battery powering and need it to run autonomously on bootup. If EEPROM is the solution, how do I store my program in EEPROM?
Also, I was wondering if anyone had any experience with clock speed management in C, I'm using sleep() right now to pause my program, but I know I could save a lot of power with waitcnt and some underclocking...I read the manual, but I'm not sure how to actually do it, do I need inline asm? It's not a huge deal, as a four pack of batteries could last a couple of days I think...
Here's my code so far for reference.
#include "simpletools.h" #include "dht22.h" int DO = 22, CLK = 23, DI = 24, CS = 25; // SD card pins on Propeller BOE int Count = 0; int DatCount = 0; // ------ Main Program ------ int main() { int n, status; int array1[3]; int array2[3]; int i; float AveT, AveH; sd_mount(DO, CLK, DI, CS); // Mount SD card while(1) { while(Count < 3) { int n = dht22_read(5); array1[Count] = ((float) dht22_getTemp(FAHRENHEIT)); //store temps values array2[Count] = ((float) dht22_getHumidity()); //store humidity values print("%s%03.2f%s\r", "The temperature is ", ((float) dht22_getTemp(FAHRENHEIT)) / 10.0, " degrees F"); print("%s%03.2f%s\r", "Humidity is ", ((float) dht22_getHumidity()) / 10.0, "%"); pause(2000); Count = Count + 1; } AveT = (array1[0]+array1[1]+array1[2])/30.00; AveH = (array2[0]+array2[1]+array2[2])/30.00; print("\nThe average value over three samples is %.2f degress F.\n",AveT); print("\nThe average humidty over three samples is %.2f%\n",AveH); FILE* fp = fopen("THData.txt", "a"); fprintf(fp, "%.2f %.2f \n", AveT, AveH); fflush(fp); fclose(fp); print("\nHi\n\n"); sleep(); Count = 0; DatCount = DatCount + 1; if(DatCount == 3) { break; } } }
I'll get rid of the print statements before flashing to EEPROM to save space if that is the solution.
Comments
If you are using simpleIDE you would use Load EEPROM and run or press F11.
Mike
I have a library function for that unit and it does more than just temperature.
Mike
> This topic would probably go better in the Propeller1 sub-forum rather than Propeller2, since the original poster appears to be using SimpleIDE on Prop1.
It is a prop 2, I am using simple IDE though.
> @iseries said:
> If I was building a data logger for temperature I would use the BME280 unit found here: BME280.
>
> I have a library function for that unit and it does more than just temperature.
>
> Mike
I am already using the CM2303 sensor or temp/humidity. That's awesome that pause uses waitcnt already so hopefully that helps the power consumption go way down. I'll use that instead of sleep then.
> @iseries said:
> The propeller C code uses pause and not sleep and yes the pause command does use waintcnt so no need to write assembly code.
>
> If you are using simpleIDE you would use Load EEPROM and run or press F11.
>
> Mike
All I have to do is load it to EEPROM and the program will launch on boot up, say in a box outside my door not connected to anything?
OK, now I'm intrigued. How are you using simple IDE? Did you modify it to work with p2gcc or some other C compiler for the P2? The original SimpleIDE compiler only produces P1 code. Also, how are you getting it to download to the P2?
Just curious, it sounds like you're breaking some new ground here!
> mundaneeffort wrote: »
>
> > @ersmith said:
> > This topic would probably go better in the Propeller1 sub-forum rather than Propeller2, since the original poster appears to be using SimpleIDE on Prop1.
>
> It is a prop 2, I am using simple IDE though.
>
>
>
>
> OK, now I'm intrigued. How are you using simple IDE? Did you modify it to work with p2gcc or some other C compiler for the P2? The original SimpleIDE compiler only produces P1 code. Also, how are you getting it to download to the P2?
>
> Just curious, it sounds like you're breaking some new ground here!
Uhhhhh....
Maybe I'm wrong lol
Neither propeller has nonvolatile storage because that would have required more fab layers, driving up the cost and complexity of the chip. P1 can auto-load a program from I2C eeprom. P2 can auto-load from a flash memory chip. Neither chip requires this memory if there is some other method of starting it, such as another computer ready to load a program through the serial programming interface. P2 can also boot to a built-in Forth interpreter, which is really cool for doing quick tests.
https://www.parallax.com/product/32912
First off, I don't know why I thought I had a Prop 2, that's really my bad.
Load and running to EEPROM seems to do the trick. Flipping the on switch runs the program three times, stores the data, and terminates the program.
Sorry for the confusion, this has been quite the mundane effort.
Thanks for the replies, you guys are great though. I'll try and upload screens and pictures of the completed project when it is done, I think I have all the hardware problems figured out now.