Hey all,
Has anyone interfaced with this before? I found a post with alot of helpful info, like the wiring schematic, but I don't understand the code. Does any one have a simplified code or can dumb it down for me?
Thanks
Hey all,
Has anyone interfaced with this before? I found a post with alot of helpful info, like the wiring schematic, but I don't understand the code. Does any one have a simplified code or can dumb it down for me?
Thanks
Not really but I guess basic accelerometers are all the same, either analog with ratiometric output (I've got two) or digital on some sort of interface (I have two wii remote and Nunchucks but I never messed with them).
Where's the link to the codes and spec sheet?
Here is the code I found from a previous post...
#include <Wire.h>
#define address 0x40
void setup()
{
Wire.begin();
Serial.begin(9600);
initBMA180();
delay(2000);
}
void loop()
{
readAccel();
delay(10);
}
It makes a note that this code is tabbed in the IDE...
int x;
void readAccel()
{
int temp, result;
temp = 0;
while(temp != 1)
{
Wire.beginTransmission(address);
Wire.send(0x03);
Wire.requestFrom(address, 1);
while(Wire.available())
{
temp = Wire.receive() & 0x01;
}
}
Wire.beginTransmission(address);
Wire.send(0x02);
Wire.requestFrom(address, 1);
while(Wire.available())
{
temp |= Wire.receive();
temp = temp >> 2;
}
Serial.print("X = ");
Serial.println(temp);
result = Wire.endTransmission();
}
void initBMA180()
{
int temp, result, error;
Wire.beginTransmission(address);
Wire.send(0x00);
Wire.requestFrom(address, 1);
while(Wire.available())
{
temp = Wire.receive();
}
Serial.print("Id = ");
Serial.println(temp);
result = Wire.endTransmission();
checkResult(result);
if(result > 0)
{
error = 1;
}
delay(10);
if(temp == 3)
{
// Connect to the ctrl_reg1 register and set the ee_w bit to enable writing.
Wire.beginTransmission(address);
Wire.send(0x0D);
Wire.send(B0001);
result = Wire.endTransmission();
checkResult(result);
if(result > 0)
{
error = 1;
}
delay(10);
// Connect to the bw_tcs register and set the filtering level to 10hz.
Wire.beginTransmission(address);
Wire.send(0x20);
Wire.send(B00001000);
result = Wire.endTransmission();
checkResult(result);
if(result > 0)
{
error = 1;
}
delay(10);
// Connect to the offset_lsb1 register and set the range to +- 2.
Wire.beginTransmission(address);
Wire.send(0x35);
Wire.send(B0100);
result = Wire.endTransmission();
checkResult(result);
if(result > 0)
{
error = 1;
}
delay(10);
}
if(error == 0)
{
Serial.print("BMA180 Init Successful");
}
}
void checkResult(int result)
{
if(result >= 1)
{
Serial.print("PROBLEM..... Result code is ");
Serial.println(result);
}
else
{
Serial.println("Read/Write success");
}
}
void readId()
{
int temp, result;
Wire.beginTransmission(address);
Wire.send(0x00);
Wire.requestFrom(address, 1);
while(Wire.available())
{
temp = Wire.receive();
}
Serial.print("Id = ");
Serial.println(temp);
result = Wire.endTransmission();
checkResult(result);
delay(10);
}
Seems like a lot and apparently it reads only the X axis....
My lib works pretty well http://www.schwietering.com/jayduino/bma180.zip. Bear in mind that you need 5 to 3.3V conversion if you use a 5V arduino.
I have the line logic converter and the schematic for the circuit. I will check out your lib after work. Does the accelerometer output 3 values? or does it triangulate the values into a resultant? Not sure of thats a dumb question.
you get 3 distinct outputs (x, y, and z-axis).
z-axis will (at rest and horizontal) have 1G (or -1G if upside down), well yes, earth pulls .
The library will enable you to set different settings (sensitivity, filters, using interrupts).
And the scjurgen library works very well indeed!
Use it -- save yourself a lot of trouble.
I2C hookup through level changer
Pin 1 +3.3 V (From Arduino if available)
Pin 2 GND
Pin 3 Interrupt line I attach this directly to pin 3 On My Arduino to use the INTERRUPT Function
Pin 4 to +3.3V through a resistor -- to keep it high (1K?)
Pin 5 SCL (I2C Pin SCL Connects to Low V side of TXD Level Changer)
Pin 6 Grounded
Pin 7 SDA (I2C Pin SDA Connects to Low V Side of TXD Level Changer)
Pin 8 to +3.3V through a resistor -- to keep it high (1K?)
See the Sparkfun Schematic...
... code above... for other things
#include <Wire.h>
#include <bma180.h>
#include <Time.h>
#include <DS1307RTC.h> // a basic DS1307 library that returns time as a time_t
// Begin BMA Variables and Special Functions...
//#define DEBUGON
BMA180 bma180;
volatile byte newData=0;
volatile unsigned int countISR=0;
unsigned int served=0;
// int xval;
/* Interrupt service
Kept simple as it really should only call the work routines...
*/
void BMAISR(void)
//+++++++++++++++
{
countISR++;
//bma180.readAccel();
newData=1;
}
... more code ...
The below is from setup...
// Best seetings F15HZ0 and Mode 3
// Also F300HZ and Mode 2
/* Filter settings
F10HZ=0,F20HZ=1,F75HZ,F15HZ0,F300HZ,F600HZ,F1200HZ,HPPLUS1,BP300}FILTER;
*/
bma180.setFilter(bma180.F300HZ);
/* G Sensitivity
G1=0,1.G15=1,G2,G3,G4,G8,G16 ... enumerated type, 1, 1.5,2,3,4,8,16 g settings
*/
bma180.setGSensitivity(bma180.G15); // lets put 1.5 G maximum, not doing tests in a space shuttle
//setRegValue(int regAdr, int val, int maskPreserve)
/* MODE -- for 1, 1.5 and 2g
0x00=LowNoise, BW=1200 Noise 150 ug/rt
0x01 Ultra Low Noise BW=472 Noise 150 ug/rt
0x02 Low Noise Low Power BW= 236 Samp/Sec =1200 Noise 200 ug/rt
0X03 Low Power BW=600 Noise 200 ug/rt
Must see Page 28 section 7.7.3 for full info
*/
bma180.setRegValue(0x30,0x03,0xFC);
// digital pin 3= ISR1 --- ISR 0 = Dig Pin 2 ISR0 gave problems????
attachInterrupt(1, BMAISR, RISING);
// +++++++++++++++++++++++++++++++ -- note this
// sample skipping reduces noise sonsiderably... not sure of count...
bma180.setSMPSkip(); // allow sample skipping to reduce load...
bma180.setISRMode(); // allow interrupt on (connect to Dig. Pin 3)
bma180.disableWrite(); //parametrs are set so disallow further changes
delay(2000); //just a wait till thinggs settle and readings stabilize...
// End BMA180 Setup +++++++++++++++++++
Just see the example Jurgen provides.
It seems the only data coming across the serial monitor is the line " Id = -1 v .FFFFCA00"
I then get nothing else...
Some old (working) wiring I did with an Arduino novemila used as a POC.
complete wiring with a VFD Futaba display showing values http://www.schwietering.com/jayduino/documentation/CIMG0906.JPG
and the removed BMA180 to see the wiring better http://www.schwietering.com/jayduino/documentation/CIMG0902.JPG (never mind the 3.3K resistor there, it's not connected to anything meaningful). I mounted the pins on the other side, so that in the final version the BMA180 IC would be protected against rough usage (using it in a glove).
After this worked correctly I attached the BMA180 directly to an Arduino Fio (which runs on 3.3V, so no level converter needed).
Hmm, I wored it exactly as shown but I still get that one line. I checked all the lines for shorts and it all looks ok
-1 looks like a problem in the wire library. Did you initialize? Maybe post the source code (using the [code ] tags).
Source code is from your zip files...no change
judging from your circuit diagram: you did not connect CS of the BMA180. As far as I know, the BMA180 will not do anything if that input is not connected to Logical HIGH - which should not exceed VIO, i.e. maximal 3.3V.
cpixip
oops, seems that you are also missing the connection to VIO? Connect it to your 3.3V rail, as well as CS... .
cpixip
As shown? Which one? The real world jpgs from one of my posts are different from the hand painted wiring scheme you posted before. So I would recheck them one by one.
you might try to use the prg found under I2CScanner: Arduino as I2C bus scanner – todbot blog, i2cscanner.pde, to check whether you get any response from the chip at all. This scanner should find the appropriate I2C-address active. If you do not see any "found"-indicator, either your setup is wrong or your chip is defective.
cpixip
I wired the setup exactly as your real world jpgs showed. I will try the i2c scanner after work. Is there nay explanation as to why I would get that one line from the serial monitor and then nothing else? Also I tried switching the #4 and #5 pins on the arduino and still nothing. Where are those supposed to be wired?
Which Arduino are you using? I presume that you are using the dedicated I2C (TWI) Lines...
If you can post a picture of your hookup and draw and scan a schematic of what you did that would be the most helpful.
Even if you have to draw thew schematic and take a photo... Just use bold markers to do the drawing.