Hi,
I’ve been trying to get a BMA180 (I’m on my second one already) to send a continuous stream of accel data via a serial port (eventually bluetooth but that’s a problem for a different day). I’ve looked at and tried to emulate numerous examples and consistently come across the problem of data coming in “fits and starts”. One packet, wait a second or two, a few more packets, etc etc. Usually this ends in the data stopping all together after 5, 10, 50 chunks.
My wiring is as show here : posting.php?mode=post&f=32 but I have VIO unconnected. When VIO is tied to 3.3V, my output is all 0’s.
This is my code, which is adapted from several other sources:
#include <Wire.h>
#define DEVICE ((byte)0x40)
#define DATA_X0 0x02
#define AXIS_SHIFT 2
#define DELAY_RATE 500
int counter = 0;
static void readFrom(byte address, byte num, byte *buff) {
Wire.beginTransmission(DEVICE);
Wire.write(address);
Wire.endTransmission();
Wire.requestFrom(DEVICE, num);
num = Wire.available();
while(num-- > 0) {
*(buff++) = Wire.read(); // receive a byte
}
}
void setup()
{
Wire.begin(); // join i2c bus (address optional for master)
Serial.begin(115200); // start serial for output
Serial.flush();
delay(15);
}
void loop()
{
digitalWrite(13, HIGH);
int axis[5] = {0x0101, 0, 0, 0, 0};
readFrom(DATA_X0, 6, (byte*)(axis+1));
axis[1] = axis[1] ;
axis[2] = axis[2] ;
axis[3] = axis[3] ;
axis[4] = axis[1] + axis[2] + axis[3];
Serial.println("");
Serial.println(axis[1]);
Serial.println(axis[2]);
Serial.println(axis[3]);
Serial.println(axis[4]);
counter++;
delay(100);
digitalWrite(13, LOW);
delay(100);
}
This is what I get coming into the serial monitor, in weird sporadic thrusts:
-879
321
17077
16519
-411
345
16761
16695
249
0
0
249
…etc…
I suspect the 249 /0 /0/ 249 chunk is the temperature because it will go up and down a little although the application of my desk lamp caused all data to cease.
I am baffled. The ‘L’ LED on the arduino blinks when the packets get pushed out so I think it’s not a serial port problem. I would really appreciate any ideas here.