Shop OBEX P1 Docs P2 Docs Learn Events
So if I want a program to run on boot with battery power I need to store it in EEPROM? (Using C) — Parallax Forums

So if I want a program to run on boot with battery power I need to store it in EEPROM? (Using C)

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.
#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 FlexGUI, just tick the appropriate menu item and it will be sent to non-vol memory. Configure the dip switch as “boot from flash” and you’re good to go.
  • 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
  • ersmithersmith Posts: 6,052
    edited 2020-01-06 22:11
    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.
  • 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
  • mundaneeffortmundaneeffort Posts: 29
    edited 2020-01-06 22:29
    > @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.

    > @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?
  • > @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!
  • > @ersmith said:
    > 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
  • Mundaneeffort, what board are you using? The P2-Eval and P2D2 are so far the only commercial products available with a P2 on board. If you are programming it with SimpleIDE it seems far more likely that you have one of the dozens of P1 powered boards which are available, and maybe you've just mistakenly assumed you're working with a P2. The development tools for P2 are actually pretty experimental and incomplete at this point, while there are a number of very mature development paths for P1.

    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.
  • mundaneeffortmundaneeffort Posts: 29
    edited 2020-01-07 01:19
    localroger wrote: »
    Mundaneeffort, what board are you using? The P2-Eval and P2D2 are so far the only commercial products available with a P2 on board. If you are programming it with SimpleIDE it seems far more likely that you have one of the dozens of P1 powered boards which are available, and maybe you've just mistakenly assumed you're working with a P2. The development tools for P2 are actually pretty experimental and incomplete at this point, while there are a number of very mature development paths for P1.

    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.
    It is the propeller activity board, my bad. I'm not sure why I thought it was the prop 2.

    https://www.parallax.com/product/32912
  • Okay, update.

    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.
Sign In or Register to comment.