Go Down

Topic: H3LIS331DL accelerometer and Arduino Micro  (Read 54 times) previous topic - next topic

Riyadhmoh

Hi,

My project is to have 3 modules connected to arduino micro. These modules are H3LIS331DL accelerometer, RTC, and an SD card.

All three components work fine together, and I was able to read and store accelerometer data to the SD card. My problem is that I need the Arduino Micro to go to sleep whenever the data read is below a certain threshold (G value), and wake up when there is a shock detected higher than 10G. However whenever the Go_to_Sleep(); function is called, my computer does not recognize the device and fails to upload.

Riyadhmoh

Code: [Select]
void setup()
{
 
  pinMode(ConstHighPin, INPUT);
  digitalWrite(ConstHighPin, HIGH);
  Serial.begin(9600);
  //============
  h3lis.init();
  h3lis.importPara(VAL_X_AXIS,VAL_Y_AXIS,VAL_Z_AXIS);
  Serial.println(h3lis.setFullScale(H3LIS331DL_FULLSCALE_2));
  Wire.begin();
  //============= REGISTER CONFIG =====================
  Wire.beginTransmission(Addr);// Configuring the accelerometer to operate in low power mode
  Wire.write(0x20); // Select control register 1
  Wire.write(0x37); // Enable X, Y, Z axis, power on mode, data output rate 50Hz
  // Stop I2C Transmission
  Wire.endTransmission();
  //===========
  Wire.beginTransmission(Addr);
  Wire.write(0x22);
  Wire.write(0x00);
  Wire.endTransmission();
  //===========
  Wire.beginTransmission(Addr);
  Wire.write(0x23);
  Wire.write(0x10);
  Wire.endTransmission();
  //===========
  Wire.beginTransmission(Addr);
  Wire.write(0x24);
  Wire.write(0x03);
  Wire.endTransmission();
  //--------------------------------------------
  Wire.beginTransmission(Addr);
  Wire.write(0x31);
  Wire.write(0x6A);
  Wire.endTransmission();
  //----------------------------------
  Wire.beginTransmission(Addr);
  Wire.write(0x32); //Interrupt threshold config
  Wire.write(0x04);
  Wire.endTransmission();
  //--------------------------------
 
 
   
  //RTC set up
   if (! rtc.begin()) {
    Serial.println("Couldn't find RTC");
    while (1); }
   
  if (! rtc.isrunning()) {
    Serial.println("RTC is NOT running!");
    // following line sets the RTC to the date & time this sketch was compiled
    rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
    // This line sets the RTC with an explicit date & time, for example to set
    // (Year, month, day, hours, minutes, seconds)
    rtc.adjust(DateTime(2019, 3, 4, 18, 30, 0));
    }
   
//attachInterrupt(digitalPinToInterrupt(7),wakeup, RISING);

delay(5000);
}


void Go_to_sleep(){
 
  sleep_enable();
  //arduino micro interrupt pins are 0,1,2,3,7
 attachInterrupt(digitalPinToInterrupt(7),wakeup, RISING);
  set_sleep_mode(SLEEP_MODE_PWR_DOWN); //Set the MC to go to sleep mode
  sleep_cpu(); //this command activates sleep mode
}


void wakeup(){
  if (start == LOW){
  sleep_disable(); // disable sleep mode
  detachInterrupt(1); //Removes the interrupt from pin 7 (check)
  start = HIGH;
 
  }
}

Go Up