Arduino mini rev05 strange behavior

Hello

I've some problems with the Arduino Mini. I've a DS18S20 sensor connected to pin 6 of the arduino.

I uploaded the sketch below. After the upload when i opened the serial monitor all worked fine and the temperature number are printed like this :

1 86
24.37
1 85
24.31
1 86
24.37
1 86
24.37

So i unplugged the arduino from the power source (usb with arduino2serial adaptator) and wait about 5 minutes.

Then i plugged the power source and then nothing... The arduino seems to sleep. I open the serial monitor and nothing appear.

When i reload the sketch all work fine again until i unplug the power source.

I've tried with a brand new Arduino mini rev5 and it was the same.

What is the problem ? I'm blocked

I wanted to create a wireless sensor with an xbee series 2 API. I was thinking that the xbee causing some problems, so i write the same code without xbee management but i had the same problem...

(Sorry for my english, i'm french :smiley: )

Thank you

#include <SoftwareSerial.h>
#include <OneWire.h>
 
 long previousMillis = 0;        // will store last time LED was updated
 long interval = 2000;           // interval at which to blink (milliseconds)
 
 //Temperature chip i/o 
int DS18S20_Pin = 6; //DS18S20 Signal pin on digital 6
OneWire ds(DS18S20_Pin);  // on digital pin 6


int statusLed = 13;
int errorLed = 11;



void setup(void) {
  pinMode(statusLed, OUTPUT);
  pinMode(errorLed, OUTPUT);

  digitalWrite(statusLed, HIGH);
  digitalWrite(errorLed, HIGH);
  

  Serial.begin(9600);
  
}
 
void loop(void) {
  

 
 unsigned long currentMillis = millis();
 
  if(currentMillis - previousMillis > interval) {
    // save the last time you blinked the LED 
    previousMillis = currentMillis;   
    digitalWrite(statusLed, HIGH); 
    float temperature = getTemp();
    
    Serial.println(temperature);
    digitalWrite(statusLed, LOW); 
   
  }
  
   
}
 
 void flashLed(int pin, int times, int wait) {
   digitalWrite(pin, LOW);
  for (int i = 0; i < times; i++) {
    digitalWrite(pin, HIGH);
    delay(wait);
    digitalWrite(pin, LOW);

    if (i + 1 < times) {
      delay(wait);
    }
  }
   digitalWrite(pin, HIGH);
}

float getTemp(){
  //returns the temperature from one DS18S20 in DEG Celsius
 
  byte data[12];
  byte addr[8];
 
  if ( !ds.search(addr)) {
      //no more sensors on chain, reset search
      ds.reset_search();
      return -1000;
  }
 
  if ( OneWire::crc8( addr, 7) != addr[7]) {
      Serial.println("CRC is not valid!");
      return -1000;
  }
 
  if ( addr[0] != 0x10 && addr[0] != 0x28) {
      Serial.print("Device is not recognized");
      return -1000;
  }
 
  ds.reset();
  ds.select(addr);
  ds.write(0x44,1); // start conversion, with parasite power on at the end
 
  byte present = ds.reset();
  ds.select(addr);    
  ds.write(0xBE); // Read Scratchpad
 
   
  for (int i = 0; i < 9; i++) { // we need 9 bytes
    data[i] = ds.read();
  }
   
  ds.reset_search();
   
  byte MSB = data[1];
  byte LSB = data[0];
 
  float tempRead = ((MSB << 8) | LSB); //using two's compliment
  float TemperatureSum = tempRead / 16;
  
   
  Serial.print(MSB,HEX);
  Serial.print(" ");
  Serial.print(LSB,HEX);
  Serial.println();
  return TemperatureSum;
  
   
}

The code with the xbee attached :

#include <SoftwareSerial.h>
#include <XBee.h>
#include <OneWire.h>
 
 long previousMillis = 0;        // will store last time LED was updated
 long interval = 1000;           // interval at which to blink (milliseconds)
 long xbeeInterval=6000;
 //Temperature chip i/o 
int DS18S20_Pin = 6; //DS18S20 Signal pin on digital 6
OneWire ds(DS18S20_Pin);  // on digital pin 6

//SoftwareSerial xbeeSerial(4,5);
 
 // create the XBee object
XBee xbee = XBee();

uint8_t payload[] = { 0, 0 };
// SH + SL Address of receiving XBee
XBeeAddress64 addr64 = XBeeAddress64(0x0013a200, 0x40B14DE4);
ZBTxRequest zbTx = ZBTxRequest(addr64, payload, sizeof(payload));
ZBTxStatusResponse txStatus = ZBTxStatusResponse();

int statusLed = 13;
int errorLed = 11;


void setup(void) {
  pinMode(statusLed, OUTPUT);
  pinMode(errorLed, OUTPUT);

  digitalWrite(statusLed, HIGH);
  digitalWrite(errorLed, HIGH);
    
  Serial.begin(9600);
  delay(1000);
  Serial.println("Serial port ok !");
  xbeeSerial.begin(9600);
  Serial.println("Xbee Serial port initialized !");
  delay(1000); 
  xbee.setSerial(xbeeSerial);
  
}
 
void loop(void) {
  

 
 unsigned long currentMillis = millis();
 
  if(currentMillis - previousMillis > interval) {
    // save the last time you blinked the LED 
    previousMillis = currentMillis;   

  float temperature = getTemp();
  Serial.println(temperature);
  delay(2000); 
 }
  
   
}

void flashLed(int pin, int times, int wait) {
   digitalWrite(pin, LOW);
  for (int i = 0; i < times; i++) {
    digitalWrite(pin, HIGH);
    delay(wait);
    digitalWrite(pin, LOW);

    if (i + 1 < times) {
      delay(wait);
    }
  }
   digitalWrite(pin, HIGH);
} 
 
float getTemp(){
  //returns the temperature from one DS18S20 in DEG Celsius
 
  byte data[12];
  byte addr[8];
 
  if ( !ds.search(addr)) {
      //no more sensors on chain, reset search
      ds.reset_search();
      return -1000;
  }
 
  if ( OneWire::crc8( addr, 7) != addr[7]) {
      Serial.println("CRC is not valid!");
      return -1000;
  }
 
  if ( addr[0] != 0x10 && addr[0] != 0x28) {
      Serial.print("Device is not recognized");
      return -1000;
  }
 
  ds.reset();
  ds.select(addr);
  ds.write(0x44,1); // start conversion, with parasite power on at the end
 
  byte present = ds.reset();
  ds.select(addr);    
  ds.write(0xBE); // Read Scratchpad
 
   
  for (int i = 0; i < 9; i++) { // we need 9 bytes
    data[i] = ds.read();
  }
   
  ds.reset_search();
   
  byte MSB = data[1];
  byte LSB = data[0];
 
  float tempRead = ((MSB << 8) | LSB); //using two's compliment
  float TemperatureSum = tempRead / 16;
  
  //Send Temp byte to xBee
  sendData(MSB,LSB);  
  Serial.print(MSB,HEX);
  Serial.print(" ");
  Serial.print(LSB,HEX);
  Serial.println();
  return TemperatureSum;
  
   
}

void sendData(byte Msb, byte Lsb) {
  
   // break down 10-bit reading into two bytes and place in payload
  payload[0] = Lsb;
  payload[1] = Msb;
 

  xbee.send(zbTx);

  // flash TX indicator
  flashLed(statusLed, 1, 100);

  // after sending a tx request, we expect a status response
  // wait up to half second for the status response
  if (xbee.readPacket(5000)) {
    // got a response!

    // should be a znet tx status            	
    if (xbee.getResponse().getApiId() == ZB_TX_STATUS_RESPONSE) {
      xbee.getResponse().getZBTxStatusResponse(txStatus);

      // get the delivery status, the fifth byte
      if (txStatus.getDeliveryStatus() == SUCCESS) {
        // success.  time to celebrate
        flashLed(statusLed, 6, 150);
      
      } else {
        // the remote XBee did not receive our packet. is it powered on?
        flashLed(errorLed, 6, 150);
      }
    }
  } else if (xbee.getResponse().isError()) {
    //nss.print("Error reading packet.  Error code: ");  
    //nss.println(xbee.getResponse().getErrorCode());
  } else {
    // local XBee did not provide a timely TX Status Response -- should not happen
    flashLed(errorLed, 6, 150);
  }

  delay(xbeeInterval);
  
}