I am trying to use the basic I2C detect script to detect a smart battery SMBus address. If I run the scanner with nothing connected, it returns that no devices were found. However, when I connect the SMBus clock and data lines to SDA and SCL on my Uno, it hangs in the serial monitor. I am pretty sure the board already has pull up resistors (Uno SMD)? I was wondering if I could get some guidance here, as I am no expert. I2C detection code is posted below.
// I2C address scanner program
#include <Wire.h>
void setup()
{
Wire.begin();
Serial.begin(9600);
Serial.println("I2C Scanner");
}
void loop()
{
byte error, address;
int nDevices;
Serial.println("Scanning...");
nDevices = 0;
for(address = 1; address < 127; address++ )
{
Wire.beginTransmission(address);
error = Wire.endTransmission();
if (error == 0)
{
Serial.print("I2C device found at address 0x");
if (address < 16)
Serial.print("0");
Serial.print(address,HEX);
Serial.println(" !");
nDevices++;
}
else if (error==4)
{
Serial.print("Unknown error at address 0x");
if (address < 16)
Serial.print("0");
Serial.println(address,HEX);
}
}
if (nDevices == 0)
Serial.println("No I2C devices found");
else
Serial.println("done");
delay(5000); // wait 5 seconds for next scan
}
I don't really have a schematic for a two wire set up, but I'll try to draw a mental picture.
SMBus clock pin to SCL on Uno
SMBus data pin to SDA on Uno
shared ground
Do I need more than this? (Also I've checked it both ways, same hanging output no matter which wire is on which pin). I'm not sure if I need external pull-ups or maybe it's something else?
Actual picture is most helpful.
The Uno has the ability to set pull ups, but they are weak. Depending on your exact setup (photo, diagram) you may still run into trouble.
The best information I can find on this battery is that it complies with all of the SMBus v1.1 standards. According to the SMBus v1.1 manual, the bus is "designed to operate over a range of voltages between 3 and 5 Volts +/- 10%." That makes me think the Uno's I2C Bus should be ok, no?
The battery is fully charged (according to the little LCD display on top of it).
I have not tested the Uno with any other I2C devices, unfortunately. I may be able to drum something up just to test it. I'll get back to you on that.
Ok, I hooked everything up to a dinosaur oscilloscope to determine what the clock and data lines were seeing. Turns out the Uno only pulls down the clock signal to around 1.5-2V. The SMBus requires a CLK Low of at least 0.8V or lower. This makes the Uno technically see the device, but never obtain a returning data signal (this is why it hangs...the SCL signal out just stays low because it never gets anything). So, now I'm hunting an IC I can integrate to handle the signals and send them to the SMBus at the appropriate levels.