Can I Send Readings from I2C via Bluetooth?

Hi all,

I have a BMA220 accelerometer sensor that I can read using I2C. I also have an HC-05 bluetooth that I can use to send data via serial to Android. The question is, can I combine them so I can transmit the sensor reading to an Android phone via bluetooth? Because I’ve tried it and it’s not sending anything. I can see stuffs printed on Arduino Serial Monitor, but I don’t see anything transmitted via Bluetooth. Not even the “START” message that I make.

Here’s my code, if it helps

#include <Wire.h>

// for accelerometer
byte Version[3];
int8_t x_data;

void setup() 
{ 
  Serial.begin(9600); 
  Wire.begin(); 
  Wire.beginTransmission(0x0A); // address of the accelerometer 
  // low pass filter, range settings 
  Wire.write(0x20); 
  Wire.write(0x05); 
  Wire.endTransmission();
  Serial.println("START");  
} 

void AccelerometerInit() 
{ 
  Wire.beginTransmission(0x0A); // address of the accelerometer 
  // reset the accelerometer 
  Wire.write(0x04); // Y data
  Wire.endTransmission(); 
  Wire.requestFrom(0x0A,1);    // request 6 bytes from slave device #2
  while(Wire.available())    // slave may send less than requested
  { 
    Version[0] = Wire.read(); // receive a byte as characte
  }  
  x_data=(int8_t)Version[0]>>2;

  Serial.print(x_data);         // print the character
} 

void loop() { 
  AccelerometerInit();
}

Cheers

If you can see the data you expect to see in the monitor, the code is kosher. Time to check the wiring. If you are sure that is OK, the problem is at the other end.

You might find the following background notes useful

http://homepages.ihug.com.au/~npyner/Arduino/GUIDE_2BT.pdf
http://homepages.ihug.com.au/~npyner/Arduino/BT_2_WAY.ino

Right, thanks for the suggestion Nick_Pyner (also, good reading material regarding the Bluetooth, first time using it and I'm amazed that it's that simple). I'm checking out the wiring now.

Also, I found out that the code is OK, I can use that to send something via Bluetoot. it's when I actually connect the Accelerometer that it stops sending stuffs.

I'm totally new to I2C, I connect the accelerometer to SCL and SDA pins in my Uno R3 and have the Bluetooth uses RX and TX. This should be okay right? If anyone can pointed out something, that would be gold.

You can use Serial only for one connection, either to USB or BT. You can add another serial device using e.g. SoftwareSerial. In such cases I prefer to use an Arduino Mega instead, with more serial ports in hardware.

Right, so I've double checked the wiring and I founded out that the main culprit is the I/O expansion shield that I used. For whatever reason, I think it stops the accelerometer from functioning properly. It's an old beaten shield, so maybe it's time to give it a rest.

It works now, so, thanks a lot guys.

I reckon that it's ok to use I2C and Serial (via RX/TX) at the same time.