Wednesday, July 18, 2012

Putting Everything Together Part 7: Accelerometer

Just finished the code for the BMA180 accelerometer today. I rewrote Dr. Bunn's code for the accelerometer into a library. The program will initialize the BMA180 and then output the acceleration felt in the horizontal and vertical axes (AH, AV). Here's a sample of the code (with the accelerometer on the table monitoring natural vibrations):


Reset BMA180 and Init
BMA180 Chip Id = 3
BMA180 Version = 20
Register 0x37 contents (12 bits) = 1101000
Register 0x30 contents (mode config) = 10000000
Register 0x30 will be set to = 10000011
Register 0x30 contents after write = 131
Register 0x20 contents = 1001000
Register 0x20 (bandwidth) contents after write = 1001111
Register 0x35 contents = 11000100
Register 0x35 (range) contents after write = 11000000
BMA180 Init Successful
AH: 0.05  AV: 1.02
AH: 0.05  AV: 1.02
AH: 0.06  AV: 1.02
AH: 0.04  AV: 1.02
AH: 0.05  AV: 1.02
AH: 0.06  AV: 1.02
AH: 0.05  AV: 1.02
AH: 0.06  AV: 1.02
AH: 0.05  AV: 1.02
AH: 0.06  AV: 1.02
AH: 0.05  AV: 1.02
AH: 0.06  AV: 1.02
AH: 0.04  AV: 1.02
AH: 0.06  AV: 1.02
AH: 0.06  AV: 1.02
AH: 0.04  AV: 1.02
AH: 0.05  AV: 1.02
AH: 0.05  AV: 1.02
AH: 0.06  AV: 1.02

The picture of the accelerometer looks like this:




The Fritizing picture looks like this:
Since I didn't want to spend all the time making a custom part for the BMA180, I just used the generic "mystery part". From left to right, the pins on the custom generated BMA180 are: VDD, GND, INT, CS, SCK, SDO, SDI, VIO. These should match the order of the pins on the real model as well.


The blue wire connects to 3.3V pin on the Arduino Duemilanove, the black wires connect to the GND pin, the red wire connects to A4 (SDA) and the orange wire connects to A5 (SCL). Thus, on the Arduino Mega/ADK, we would connect the red wire to pin 20 and the orange wire to pin 21. 

No comments:

Post a Comment