Skip to content

Instantly share code, notes, and snippets.

@Addidis
Created October 24, 2011 23:54
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save Addidis/1310811 to your computer and use it in GitHub Desktop.
Save Addidis/1310811 to your computer and use it in GitHub Desktop.
I am in the process of updating the Tautic accelerometer board demo code.
// MMA7660FC Basic demo by Addidis
// Released under the Creative Commons Attribution-ShareAlike License (3.0)
// http://creativecommons.org/licenses/by-sa/3.0/us/
// 10/24/11
// HW : Tautic accelerometer board +4.7k pull ups on sda scl , uno32, led +330 resistor
// SCL -->A5
// SDA -->A4
// INT -->D7
// gnd -->gnd
// vdd -->3.3v NOTE 3.3v!
// LED short pin to 330 resistor to gnd
// led long pin to D6
// Short jp6 and jp8 on the left side (towards analog pins) (chipkit specific)
// Open the serial monitor after running , set to 38400
// It will fire an interrupt and light the led briefly when it detects a change in orientation
// The values of the variables that are displayed are in the datasheet with what they mean.
// See http://www.freescale.com/files/sensors/doc/data_sheet/MMA7660FC.pdf
// See Also http://store.tautic.com/mma7660fc-3-axis-1-5g-accelerometer-breakout-board.html
// See also http://i280.photobucket.com/albums/kk184/xsavior38/acceldemo.jpg
//** Includes *************************************************************************
#include <Wire.h>
//** Variables ************************************************************************
int accelintpin = 7;
int ledpin = 6;
volatile int state = 0;
volatile int led = 0;
void setup()
{
pinMode(ledpin, OUTPUT);
digitalWrite(ledpin, LOW);
pinMode(accelintpin, INPUT);
attachInterrupt(2,accelISR, FALLING);
Serial.begin(38400); // start serial for output
delay(10);
Wire.begin();
}
void accelISR(void)
{
digitalWrite(ledpin, HIGH);
state=1;
}
void loop()
{
Wire.beginTransmission(0x4C); //Set MMA7660FCR1 to active mode
Wire.send(0x06); //write to register 6
Wire.send(0x03); //turn on orientation interupt
Wire.send(0x01); //set to active mode
Wire.send(0x00); //clear register 8
Wire.endTransmission();
delay(100);
volatile signed char xneg,yneg,zneg, x,xout, y,yout, z,zout, pola,bafro,t,tilt, srst, spcnt, intsu, mode, sr, pdet, pd, shake, tilterror, tap, face;
while(1)
{
xneg=' '; //clear bit
yneg=' '; //clear bit
zneg=' '; //clear bit
if (state ==1) //This if loop services the led. If you enable interrupts it will turn on the led
{ //this will turn it off after X delay.
delay(500);
digitalWrite(ledpin, LOW);
state=0;
}
//
Wire.beginTransmission(0x4C);
Wire.send(0x00); // register to read
Wire.endTransmission();
Wire.requestFrom(0x4C, 11); // read a string of bytes
while(!Wire.available()) { } // wait for data
xout = Wire.receive();
yout = Wire.receive();
zout = Wire.receive();
tilt = Wire.receive();
srst = Wire.receive();
spcnt = Wire.receive();
intsu = Wire.receive();
mode = Wire.receive();
sr = Wire.receive();
pdet = Wire.receive();
pd = Wire.receive();
//Data is not proccesed , we will parse out the stuff so it matches the data sheet for reference.
if(xout<=63)
{
xneg=(xout&0b00100000)+13; //it just so happens that 32 in ASCII is the first typable character.
x= xout&0b00011111; //so we can just add 13 to that and procure a minus sign when it is negative
} //and a non typable character when it is not.
if(yout<=63)
{
yneg=(yout&0b00100000)+13;
y= yout&0b00011111; //Here we are just stripping the empty bit 7 and error bit and and sign bit to get our actual number.
}
if(zout<=63)
{
zneg=(zout&0b00100000)+13;
z= zout&0b00011111;
}
bafro=tilt&0b00000011; //some more playing with bits to extract usefull information from the byte.
pola=(tilt&0b00011100)>>2;
tap=(tilt&0b00100000)>>5;
tilterror=(tilt&0b01000000)>>6;
shake=(tilt&0b10000000)>>7;
Serial.print("X=");
Serial.print(xneg, BYTE);
Serial.print(x, DEC);
Serial.print(", Y=");
Serial.print(yneg, BYTE);
Serial.print(y, DEC);
Serial.print(", Z=");
Serial.print(zneg, BYTE);
Serial.print(z, DEC);
Serial.print(", bafro=");
Serial.print(bafro,BIN);
Serial.print(", pola=");
Serial.print(pola,BIN);
Serial.print(", tap=");
Serial.print(tap,DEC);
Serial.print(", shake=");
Serial.print(shake,DEC);
Serial.print(", sample rate=");
Serial.print(srst,DEC);
Serial.print(", interrupt=");
Serial.print(intsu,BIN);
//todo add tap and tap debounce read out.
Serial.println(".");
delay(100);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment