Datasheet: http://www.datasheetdir.com/BMA020+download
ELV put the chip onto a small board with a 2,5V power regulator and a set of MOS transistors as level shifters. The board is not compatible to Lego but this can be fixed easily: Just remove the four pull-up resitors and the level-shifter transistors for the two I2C bus wires. The internal 4k7 resistors in the NXT do proper level shifting already (verified with an oscilloscope).
If you plan to use the chip directly, the following hints might be helpful:
- Use a 2,5V regulator for both VDD and VDDIO. The power consumption is less than 1mA.
- Configure the I/O interface as I2C bus in the following way:
- Connect SDO to GND
- Connect CSB to VDD
- The INT line is not used
- Use two 82k Pull-up resistors for the I2C bus, which are the pins SDI and SCK
- SDI is bidirectional
- The I2C bus can be connected directly to the next without level shifters
The following example program displays the three numeric values and draws 3 bars on the display. It does not configure the chip because the defaults are already ok. The program uses only the most significant 8 bits, to keep it simple.
- Code: Select all
package de.butterfly;
import lejos.nxt.*;
import javax.microedition.lcdui.Graphics;
// Test program for an Acceleration Sensor Bosh BMA-020
public class Main {
// Buffer for I/O
static byte buffer[]=new byte[8];
// I2C bus address of the sensor
static int i2cAddress=0x70;
// Paints onto the display
static Graphics g=new Graphics();
public static void main(String[] args) throws InterruptedException {
SensorPort.S1.i2cEnable(I2CPort.STANDARD_MODE);
LCD.drawString("X=",0,0);
LCD.drawString("Y=",0,1);
LCD.drawString("Z=",0,2);
while (true) {
buffer[0]=0x00; // First register to read
int count=SensorPort.S1.i2cTransaction(i2cAddress,buffer,0,1,buffer,0,8);
if (count==8) {
int x=buffer[3];
int y=buffer[5];
int z=buffer[7];
LCD.drawInt(x,4,3,0);
LCD.drawInt(y,4,3,1);
LCD.drawInt(z,4,3,2);
// Clear bars
g.setColor(255,255,255);
g.fillRect(0,26,99,42);
g.setColor(0,0,0);
// Draw X-Bar
x/=2;
if (x<0)
g.fillRect(50+x,26,-x,4);
else
g.fillRect(50,26,x,4);
// Draw Y-Bar
y/=2;
if (y<0)
g.fillRect(50+y,32,-y,4);
else
g.fillRect(50,32,y,4);
// Draw Z-Bar
z/=2;
if (z<0)
g.fillRect(50+z,38,-z,4);
else
g.fillRect(50,38,z,4);
}
else {
LCD.drawString("----",3,0);
LCD.drawString("----",3,1);
LCD.drawString("----",3,2);
}
}
}
}

