Other Parts Discussed in Thread: BQSTUDIO, BQ34110
Hello everyone, I am using the bq34110EVM-796 module without using the bqstudio software. I want to retrieve the real-time voltage() of my battery. The battery I'm using is a 6s LiPo, so I'm using the jumper on the 36V setting. My goal was to communicate via I2C with an Arduino board and check if I could retrieve the voltage across my battery terminals. For this, I used the "slua790comI2C" datasheet to write my code.
Here's my code:
#include <Wire.h>
#define DEVICE_ADDRESS 0x55 // Address of the bq34110 module
void setup() {
Wire.begin(); // Initialize the Wire library
Serial.begin(9600); // Initialize serial communication to display results
int voltage = readVoltage(); // Call the function to read the voltage
Serial.print("Voltage: ");
Serial.print(voltage);
Serial.println(" mV");
delay(1000); // Wait for a second before reading the voltage again
}
int readVoltage() {
int voltage = 0;
Wire.beginTransmission(DEVICE_ADDRESS);
Wire.write(0x55); // address writing
delay(250);
Wire.write(0x08); // cmd voltage
delay(250);
Wire.write(0x56); // address reading
delay(250);
Wire.requestFrom(DEVICE_ADDRESS, 2); // Read 2 bytes (the 2 voltage bits)
// Wait for data to be available
if (Wire.available() >= 2) { // Both bytes are available
byte lowByte = Wire.read();
byte highByte = Wire.read();
Serial.println(highByte);
Serial.println(lowByte); // Calculate the voltage from the received bytes (assuming millivolt representation)
voltage = (highByte << 8) | lowByte;
}
int error1 = Wire.endTransmission(); Serial.println(error1);
return voltage;
}
void loop() { Serial.println("Finished");
delay(1000000);
}
After running this code, I get 0 mV as the result, which is very strange because the I2C communication seems to be working fine. Additionally, if I execute the 3 Wire.write commands in separate communications, I get 22016 mV regardless of the battery voltage. Can you help me solve these issues? Thank you in advance for your time.