I'm trying to use the I2C Wire interface with the Boron but am stuck just trying to get it working. The thought was, prove that there are no I2C devices in use, then wire one up and show that it exists. The firmware I cobbled together from many helpful posts in the forum is:
int nDevices;
byte error;
byte address;
void setup() {
Serial.begin(9600);
delay(5000);
// Initialize the I2C bus if not already enabled
if (!Wire.isEnabled()) {
Serial.println("Wire begin");
Wire.begin();
}
delay(5000);
if (Wire.isEnabled()) {
Serial.println("Wire reset");
Wire.reset();
}
}
void loop() {
Serial.println("Scanning...");
nDevices = 0;
for(address = 1; address < 127; address++ )
{
Serial.println("Begin Transmission");
Wire.beginTransmission(address);
Serial.println("End Transmission");
error = Wire.endTransmission(true);
Serial.print("Error = 0x");
Serial.println(error,HEX);
if (error == 0)
{
Serial.print("I2C device found at address 0x");
if (address<16)
Serial.print("0");
Serial.println(address,HEX);
nDevices++;
}
else if (error==4)
{
Serial.print("Unknow 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");
Serial.println("Loop");
delay(10000);
}
The resulting serial output is:
particle serial monitor --follow
Polling for available serial device...
Opening serial monitor for com port: "COM21"
Serial monitor opened successfully:
Wire begin
Wire reset
Scanning...
Begin Transmission
End Transmission
(hangs)
Nothing is hooked up at this point other than the USB and the antenna. I've tried adding a device, there's no difference in the outcome. Called endTransmission with TRUE and FALSE, this does not change the outcome. What am I missing?