TinyZero with Accelerometer & Wake from Sleep

SteveDorr

  • Newbie
  • *
    • Posts: 1
    • View Profile
Hi,
I just purchased a Tiny Zero with the built-in accelerometer.  I would like to build a small app that goes into low-power mode and wakes up via an interrupt from the accelerometer if it detects significant movement.

I have the accelerometer working, but I'm looking for some sample code which puts it to sleep and codes the accelerometer to generate the interrupt appropriately.  From what I read people were soldering connections to make INT1 work on the proto board, but I'm wondering about the TinyZero which has it all integrated on the same board.

Thanks for your help.
Steve


HunterHykes

  • Administrator
  • Full Member
  • *****
    • Posts: 20
    • View Profile
Hi Steve,

As can be seen in the TinyZero schematic and board files, the INT1 pin of the BMA250 accelerometer is only broken out to a solder pad on the bottom side of the board. This is the small copper circle labeled "INT1" next to the "BOOT" button.

Because of this, a wire would have to be soldered to this pad and then input to the processor via a Proto Board TinyShield. According to the official Arduino documentation for interrupts, any digital pin except for digital pin 4 is usable for interrupt input to the TinyZero processor.

If this is something you'd still like to pursue, I can look into getting some sample code for this.

Hope this helps.
- Hunter


greg.brougham

  • Full Member
  • ***
    • Posts: 10
    • View Profile
Hi, I'm also interested in this functionality and wondered if there is any sample code available?

btw I have this working via the following code

the setup() code for the interrupt - note the use of FALLING is so the rtc.standbyMode() triggers

  pinMode(1, INPUT_PULLDOWN); //BMA raises pin high on interrupt
  attachInterrupt(digitalPinToInterrupt(1), BMAInterrupt, FALLING); // try RISING?

The interrupt routine itself - bare bones

void BMAInterrupt()
{
  motionInterrupt = true; // flag motion
}

And the code for initialising interrupt for 'any motion' which is added to the begin() routine

   // set the interrupt mode - this is temporary 500 usec
   // note we don't not latched the interrupt
   Wire.beginTransmission(I2Caddress);
   Wire.write(0x21); // interrupt mode - see page 23 of the spec
   Wire.write(0x09);
   Wire.endTransmission();
   // enable slope interrupts - used for 'any motion' detection
   Wire.beginTransmission(I2Caddress);
   Wire.write(0x16);
   Wire.write(0x07);
   Wire.endTransmission();
   // Map slope interrupt to pin 1
   Wire.beginTransmission(I2Caddress);
   Wire.write(0x19);
   Wire.write(0x04);
   Wire.endTransmission();
   // Use 4 samples for the slope interrupt - threshold duration
   Wire.beginTransmission(I2Caddress);
   Wire.write(0x27);
   Wire.write(0x02); // reduce to 3 from 4
   Wire.endTransmission();
   // And set slope threshold
   Wire.beginTransmission(I2Caddress);
   Wire.write(0x28); // slope threshold
   Wire.write(0x14); // note this is the default value - see page 47 of the spec
   Wire.endTransmission();
« Last Edit: December 27, 2021, 10:45:44 AM by greg.brougham »


 

SMF spam blocked by CleanTalk