TinyCircuits Forum

TinyCircuits Products => TinyDuino Processors & TinyShields => Topic started by: SteveDorr on December 17, 2020, 01:14:24 PM

Title: TinyZero with Accelerometer & Wake from Sleep
Post by: SteveDorr on December 17, 2020, 01:14:24 PM
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
Title: Re: TinyZero with Accelerometer & Wake from Sleep
Post by: HunterHykes on December 18, 2020, 03:05:33 PM
Hi Steve,

As can be seen in the TinyZero schematic (https://github.com/TinyCircuits/TinyCircuits-TinyZero-ASM2021/blob/master/design_files/TinyZero_Schematic_Rev5.pdf) 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 (https://github.com/TinyCircuits/TinyCircuits-TinyZero-ASM2021/blob/master/images/TinyZero_back.jpg). 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 (https://tinycircuits.com/products/proto-board-tinyshield?variant=14984618887). According to the official Arduino documentation for interrupts (https://www.arduino.cc/reference/en/language/functions/external-interrupts/attachinterrupt/), 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
Title: Re: TinyZero with Accelerometer & Wake from Sleep
Post by: greg.brougham on December 23, 2021, 06:44:56 AM
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();