1
TinyDuino Processors & TinyShields / Accelerometer Shield
« on: June 28, 2013, 11:46:36 AM »
Hi All,
Just got my starter kit yesterday from Kickstarter (waited for the accelerometer shield to be ready) set it up and so far so good!
I found this example sketch that might be helpful to others:
I found it here: http://dsscircuits.com/accelerometer-bma250.html but it was out of date, so I updated it.
Note that you need to change the serial monitor baud to match the Serial.begin(), so 115200 baud.
Hope this helps someone, it was quite a bit of searching to find it.
-ak
Just got my starter kit yesterday from Kickstarter (waited for the accelerometer shield to be ready) set it up and so far so good!
I found this example sketch that might be helpful to others:
Code: [Select]
/**********************************************************
* BMA250_I2C_Sketch.pde ----- Sample sketch for BMA250 Accelerometer using I2C
*
* A sample sketch that shows the basic functions of the BMA250 acclerometer.
*
*
* 2011, DSS Circuits, Inc. http://www.dsscircuits.com
*
**********************************************************/
#include <Wire.h>
#define BMA250 0x18
#define DELAY 64000
#define BW 0x08 //7.81Hz bandwith
#define GSEL 0x05 //0x03 - 2g, 0x05 - 4, 0x08 - 8g, 0x0C - 16g
uint8_t dataArray[16];
int x,y,z;
void setup()
{
Wire.begin();
Serial.begin(115200);
initializeBMA();
}
void loop()
{
read3AxisAcceleration();
delayMicroseconds(DELAY);
}
byte read3AxisAcceleration()
{
Wire.beginTransmission(BMA250);
Wire.write(0x02);
Wire.endTransmission();
Wire.requestFrom(BMA250,7);
for(int i = 0; i < 7;i++)
{
dataArray[i] = Wire.read();
}
if(!bitRead(dataArray[0],0)){return(0);}
int8_t temp = dataArray[6];
x = dataArray[1] << 8;
x |= dataArray[0];
x >>= 6;
y = dataArray[3] << 8;
y |= dataArray[2];
y >>= 6;
z = dataArray[5] << 8;
z |= dataArray[4];
z >>= 6;
Serial.print("X = ");
Serial.print(x);
Serial.print(" ");
Serial.print("Y = ");
Serial.print(y);
Serial.print(" ");
Serial.print("Z = ");
Serial.print(z);
Serial.print(" Temperature(C) = ");
Serial.println((temp*0.5)+24.0,1);
}
byte initializeBMA()
{
Wire.beginTransmission(BMA250);
Wire.write(0x0F); //set g
Wire.write(GSEL);
Wire.endTransmission();
Wire.beginTransmission(BMA250);
Wire.write(0x10); //set bandwith
Wire.write(BW);
Wire.endTransmission();
return(0);
}
I found it here: http://dsscircuits.com/accelerometer-bma250.html but it was out of date, so I updated it.
Note that you need to change the serial monitor baud to match the Serial.begin(), so 115200 baud.
Hope this helps someone, it was quite a bit of searching to find it.
-ak