• Content count

  • Joined

  • Last visited

  1. I see I bungled the description, so here is a clarification. We have a new gas water heater that uses a thermopile(?) to keep the pilot light actuated. To indicate the pilot light is on, the water heater uses excess thermopile electic energy to blink a light on the control that it is running. Light blinks, pilot light on. Light off, pilot light off. In the rare instance that the pilot light goes off, and the light stops blinking, I want to be notified of this. (Otherwise we have cold water and have to wait an hour to give the kids baths) I want the msp to check that the light is on every few minutes. If light is on, go back to sleep. If light is off, sound the alarm. Fmilburn, I checked on the suspend/wakeup function but I don't think it will work. Based on the guide, suspend can only be canceled by an external input. If the light on the heater goes out, the msp will never see an external input. Correct me if I am not understanding this correctly. NurseBob, I would prefer not to mess with the sealing and function of the gas water heater by adding a thermocouple next to the pilot.
  2. Hello. This is my first Energia project and one of the first self written pieces of code for a micro controller. The code is a written for a battery powered water heater monitor that blinks a light every few seconds provided the pilot light is on. The process will be to turn on a light sensor, wait to see a light and if on the device will go to sleep until the next time. If no light after a test period, then the device will alarm via a piezo buzzer. The light sensing and piezo circuit are TBD at this point, until the code works. I am using a MSP430 Launchpad v1.5 board and programming an G2553 chip that came with the Launchpad. The latest version of Energia on a Windows 7 Starter netbook is used for coding. I The test code uses the green LED to indicate that the test period is on (mimics turning on the sense circuit). It then waits for SW2 to be pressed (mimics sensor seeing a light). If SW2 is pressed the micro turns off pins and goes to sleep. If no input is sensed an alarm is triggered by flashing the red LED (mimics the piezo buzzer). I use a SW2 ISR to toggle a flag and control the loop(). have several questions and I am open to optimizations suggestions. 1. I use a flag because sleep within the ISR does not work per Energia guide, and early experiments with the code. Is there a better way to put the chip to sleep from inside the ISR? Right now the ISR flag is set but the sensor stays on for the duration of the sense period. This works, but does not optimize the design for lowest possible power. The sense period will be set to capture an average of 2 light flashes with margin to ensure a light flash is seen. This could be reduced if the code would sleep() right after a detection. How can I do this? (trying to not go write in C as I still don't quite grasp the C language and intrinsic functions cause me trouble.) 2. What is a good way to trap the loop() in the alarm loop? Do I use a goto command? (these are frowned upon I hear..) 3. The PinsOn() function has to use a pinMode(pin, INPUT) function before switching to OUTPUT. I found that I have to do this to disconnect the pulldown resistor, else I get dim LED's. This is not entirely addressed in the Energia guide, and only pullup resistors are mentioned. Is this normal? Is there a better way to do it? 4. Any other optimization tricks that can be used? 5. I would like to run the finished sensor from 2x AA batteries without regulation. Is this possible? What other precautions do I need to take? Can you point me to a project that did just that? 6. Is there another good site that gives more examples of Energia? Other than this site? Books? Thank you for your time. Mark P. PS Mods please move if in the wrong forum. CODE============== // Timer Guard v2 // turns on green led and waits for button push // if pushed goes to sleep until next time // else sounds the alarm (red light blinking) // Sep 2016 // Mark P. int Flag; //Flag for determining if button was pressed const int ledR = RED_LED; // Red LED on LaunchPad const int ledG = GREEN_LED; // Green LED on LaunchPad const int button = PUSH2; // Green LED on LaunchPad unsigned long test_time = 5; //test time duration, enter in secons, converts to milis at startup volatile unsigned long sleep_time = 10; //sleep time duration, enter in secons, converts to milis at startup void setup() { // put your setup code here, to run once: //Pin Initialization //set all pins to low power first then change the led pins and switch for(uint8_t i;i<20;i++){ pinMode(i,INPUT_PULLDOWN); //minimize power loop, set all pins to input+pulldown } //Variable Setup test_time *= 1000; //convert from seconds to milis sleep_time *= 1000; //convert from seconds to milis //ISR attachInterrupt(button, Interval, FALLING); } void loop() // put your main code here, to run repeatedly: { Flag = 0; PinsOn(); //turn on sense and led pins digitalWrite(ledG, HIGH); // turn the LED on to indicate waiting for button press sleep(test_time); //pause for button press if (Flag == 0) //if no button press in allowed time, proceeds to alarm { digitalWrite(ledG, LOW); //Turn off green LED for (int i=0; i <= 5; i++){ digitalWrite(ledR, HIGH); // turn the LED on (HIGH is the voltage level) sleep(1000); // wait for a second digitalWrite(ledR, LOW); // turn the LED off by making the voltage LOW sleep(1000); // wait for a second } } else { // if button pressed take a long nap PinsOff(); //turn pins off to save power sleep(sleep_time); } } void Interval() //Sleep interval between sensing, activated by button push ISR { Flag = 1; } //Function for turning OFF sense pins void PinsOff() { pinMode(ledR, INPUT_PULLDOWN); //red led pinMode(ledG, INPUT_PULLDOWN); //green led pinMode(button, INPUT_PULLDOWN); //SW2 button } //Function for turning on sense pins void PinsOn(){ pinMode(ledR,INPUT); //disconnect pull down resistor pinMode(ledR,OUTPUT); //red led pinMode(ledG,INPUT); //disconnect pull down resistor pinMode(ledG,OUTPUT); //green led pinMode(button,INPUT_PULLUP); //SW2 button }