Arduino micro looses program when power disconnected

I have two Arduino micros. One sends sensor data via Xbee to the other. When power is interrupted and restored to the receiver micro, it restarts as it should. When power is interrupted and restored to the sender micro, the program must be reloaded. Any ideas? It is a bit mysterious why one micro works and the other doesn't.

I don't know. I don't have the code, I don't have schematics.

But I can tell you I really doubt it. It's not easy to "loss a program". In order to loss the program the chip needs to be programmed again (with a blank program) which doesn't happen that easy. I really think it's just a bug in your code which makes you think it "lost it's code".

  • When power is removed from the Micro and then restored, the program will not run and must be reloaded.
  • Trouble shooting advice from the Arduino website offers the following:

Why doesn’t my sketch start when I power up or reset the Arduino board?

Most likely because you are sending serial data to the board when it firsts turns on. During the first few seconds, the bootloader (a program pre-burned onto the chip on the board) listens for the computer to send it a new sketch to be uploaded to the board. After a few seconds without communication, the bootloader will time out and start the sketch that’s already on the board. If you continue to send data to the bootloader, it will never time out and your sketch will never start. You’ll either need to find a way to stop serial data from arriving for the first few seconds when the board powers (e.g. by enabling the chip that sends the data from within your setup() function) or burn your sketch onto the board with an external programmer, replacing the bootloader.

  • There is a sensor chip involved which sends data via I2C on Micro pins 2 and 3.
  • According to a Micro pinout diagram pin 2 is SDA and pin 3 is SCL
  • If the clock line is active as soon as power is applied, will this not qualify as data that will prevent the bootloader from starting the program?
  • Removing power from the sensor so that both SCL and SDA are not sending data to the Micro does not result in the program automatically restarting.
  • This same diagram advises that there are no on board pull-ups for these pins.
  • A contributor to the SparkFun forum declares that ‘Pullups on the I2C lines are absolutely required.’
  • The sensor has reliably transmitted data for several days without pull-ups.
  • This morning when the system was powered up after having been unpowered for about 8 hours, the program started automatically.
  • About 30 minutes later after a power cycle, the program started automatically.
  • Four subsequent restarts resulted in the program not automatically starting and it was reloaded.
  • The “Hello World” program does not automatically restart after a power cycle.
  • The Arduino website also advises:

Why doesn’t my sketch start when I’m powering the board with an external power supply? (Arduino Diecimila or earlier)

Because the RX pin is unconnected, the bootloader on the board may be seeing garbage data coming in, meaning that it never times out and starts your sketch. Try tying the RX pin to ground with a 10K resistor (or connecting RX directly to the TX pin).

  • This advice was followed to no effect.
  • The program follows:

SKETCH_DAremoteDriver
READS BME280, CALCULATES DA, SENDS DATA TO COORD. XBEE****/

#include <SoftwareSerial.h>
#include <Wire.h>
#include <math.h>
#include <cactus_io_BME280_I2C.h>

const float c0 = 6.1078; //constants for satVapourPress
const float c1 = 7.5;
const float c2 = 237.3;
const float RdryAir = 286.9; // gas constant for dry air J/kg K
const float RwaterVapour = 461.5; // gas constant for water vapour J/kg K
const float dA1 = 44.3308; // constants for densityAlt
const float dA2 = 42.2665;
const float dA3 = 0.234969;
const float kmToFt = 3280.0; // converts km to feet
const float cToK = 273.15; // converts *C to *K
const float mbToPasc = 100; // converts millibars to pascals

const int Rx = 16; //the micro can’t use pin 2 for Rx
const int Tx = 5;

float satVapPress; // saturation vapour pressure mb
float parPressWatVap; // partial pressure of water vapour mb
float parPressDryAir; // partial pressure of dry air mb
float airDensity; // air density kg/m3
float densityAlt; // density altitude in feet
float tempVar1; // temporary variables for long equations
float tempVar2;
float temperature; // sensor temperature value
float rh; // sensor relative humidity value
float pressure; // sensor pressure value

int tempDA;

/SO THAT END POINT XBEE 2 BYTE DATA CAN BE SENT AND REASSEMBLED AT COORDINATOR XBEE/
int LSBtempDA;
int MSBtempDA;
int LSBpressure;
int MSBpressure;
int divisor = 256;
int rhInt;
int temperatureInt;
int pressureInt;

SoftwareSerial xbee(Rx, Tx);
BME280_I2C bme; // Create BME280 object I2C using address 0x77

void setup()
{
//delay(5000);
Serial.begin(9600);
while (!Serial); //because it takes a while to make the serial connection which is why println would not display
xbee.begin(9600);

Serial.println(“Bosch BME280 Pressure - Humidity - Temp Sensor | cactus.io”);

if (!bme.begin())
{
Serial.println(“Could not find a valid BME280 sensor, check wiring!”);
while (1);
//pins A4 (SCK) and A5 (SDA), used for I2C on the Uno are pins 2 (SDA) and 3 (SCL) on the micro
}

bme.setTempCal(-0.5); // Temp was very close so subtract 0 degree
Serial.println(“Pressure\tHumdity\t\tTemp\t\tsatVapPress\tparPressWatVap\tparPressDryAir\tairDensity\tdensityAlt”);
}

void loop()
{
bme.readSensor();
temperature = bme.getTemperature_C();
pressure = bme.getPressure_MB();
rh = bme.getHumidity();

satVapPress = c0 * pow(10, (c1 * temperature) / (c2 + temperature)); //calculate water vapour saturation pressure
parPressWatVap = satVapPress * rh / 100; //calculate water vapour partial pressure
parPressDryAir = pressure - parPressWatVap; //calculate dry air partial pressure

tempVar1 = parPressDryAir * mbToPasc / (RdryAir * (temperature + cToK)); //first term of airDensity
tempVar2 = parPressWatVap * mbToPasc / (RwaterVapour * (temperature + cToK)); //second term of airDensity
airDensity = tempVar1 + tempVar2; //calculate air density

int densityAlt = round((dA1 - dA2 * pow(airDensity, dA3)) * kmToFt); //calculate density altitude in feet

Serial.print(pressure); Serial.print(" mb\t");
Serial.print(rh); Serial.print(" %\t\t");
Serial.print(temperature); Serial.print(" *C\t");
Serial.print(satVapPress); Serial.print(" mb\t");
Serial.print(parPressWatVap); Serial.print(" mb\t\t");
Serial.print(parPressDryAir); Serial.print(" mb\t");
Serial.print(airDensity); Serial.print(" kg/m3\t");
Serial.print(densityAlt); Serial.println(" ft");

tempDA = abs(densityAlt);
//rhInt = round(rh);
//temperatureInt = round(temperature);
//pressureInt = round(pressure * 10);

//Serial.println(tempDA);

/*Each call sends 3 bytes to coordinator xbee packing its read buffer with 12 bytes./
DisassembleSendData(densityAlt);
DisassembleSendData(temperature);
DisassembleSendData(pressure);
DisassembleSendData(rh);

//Serial.println(LSBtempDA);
//Serial.println(MSBtempDA);
//Serial.println(rhInt);
//Serial.println(temperatureInt);

/****
if (densityAlt < 0) lc.setChar(0,placeHolder,’-’,false);
digit = 0; // determines the digit for the LED readout
placeHolder = 0;
****/

delay(4000); // Add a 10 second delay
}

void DisassembleSendData (float dataToDisassemble)
{
int tempVar;
//int fractionalPart;
int LSB;
int MSB;
int divisor = 256;

/Disassembles sensor data into 3 bytes/
tempVar = dataToDisassemble;
//fractionalPart = (tempVar % 10);
//tempVar = (tempVar - fractionalPart) / 10;;
LSB = tempVar % divisor;
MSB = (tempVar - LSB) / divisor;

/Sends 2 bytes to coordinator xbee read buffer/
//xbee.write(fractionalPart);
xbee.write(LSB);
xbee.write(MSB);
}

[/list]