Hi, I've recently been using the portenta H7 lite with the portenta breakout for I2C for communication with a humidifier sensor, the SHT4x (address = 0x44)). I was only able to see and read data from the sensor connected to the I2C_1 port. No addresses were found on the I2C_0 and I2C_2.
To test if the sensor was detectable I was using the example scanning code from arduino project hub (https://create.arduino.cc/projecthub/abdularbi17/how-to-scan-i2c-address-in-arduino-eaadda), and changing which wire were activated (example: replacing Wire.begin() with Wire1.begin()).
If I have understood correctly this is equivalent: Wire = Breakout.I2C_0, Wire1 = Breakout.I2C_1 and Wire2=Breakout.I2C_2. In the scanning code, I therefore replaced which wire I wanted to test and also changed the wiring on the Portenta breakout to be on the correct I2C port.
So my question is what did I do wrong? or why don't I detect my sensor on I2C_0 and I2C_2? This is important for me as I would like to communicate in the future with several sensors for a project, and thus would like to use I2C_0 and I2C_2.
I couldn't find much literature so thought I'd ask here hopefully getting some answers and helping others with the same problem. Thanks!
This is the adapted scanning code for I2C_1. It runs and finds several addresses (internal components I think) but also my sensor (address 0x44). It also worked if I used Wire1 instead of Breakout.I2C_1.
//this code is adapted for the I2C_1 port of the portenta breakout
#include <Arduino_PortentaBreakout.h>
void setup() {
Breakout.I2C_1.begin();
Serial.begin(9600);
while (!Serial); // wait for serial monitor
Serial.println("\nI2C Scanner");
}
void loop() {
int nDevices = 0;
Serial.println("Scanning...");
for (byte address = 1; address < 127; ++address) {
// The i2c_scanner uses the return value of
// the Write.endTransmisstion to see if
// a device did acknowledge to the address.
Breakout.I2C_1.beginTransmission(address);
byte error = Breakout.I2C_1.endTransmission();
if (error == 0) {
Serial.print("I2C device found at address 0x"); //0 = success
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);
} else if (error == 1) {
Serial.println("1: data too long to fit in transmit buffer.");
} else if (error == 2) {
Serial.println("2: received NACK on transmit of address.");
} else if (error == 3) {
Serial.println("3: received NACK on transmit of data.");
} else if (error == 5) {
Serial.println("5: timeout");
}
}
if (nDevices == 0) {
Serial.println("No I2C devices found\n");
} else {
Serial.println("done\n");
}
delay(5000); // Wait 5 seconds for next scan
}
After changing to the wires to I2C_0.
The following code is used for the I2C_0 port. It runs but doesn't find any devices and returns "0 I2C devices found". The arduino only receives "NACK", which is the error message N°2 in the code below.
//this code is adapted for the I2C_0 port of the portenta breakout
#include <Arduino_PortentaBreakout.h>
void setup() {
Breakout.I2C_0.begin();
Serial.begin(9600);
while (!Serial); // wait for serial monitor
Serial.println("\nI2C Scanner");
}
void loop() {
int nDevices = 0;
Serial.println("Scanning...");
for (byte address = 1; address < 127; ++address) {
// The i2c_scanner uses the return value of
// the Write.endTransmisstion to see if
// a device did acknowledge to the address.
Breakout.I2C_0.beginTransmission(address);
byte error = Breakout.I2C_0.endTransmission();
if (error == 0) {
Serial.print("I2C device found at address 0x"); //0 = success
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);
} else if (error == 1) {
Serial.println("1: data too long to fit in transmit buffer.");
} else if (error == 2) {
Serial.println("2: received NACK on transmit of address.");
} else if (error == 3) {
Serial.println("3: received NACK on transmit of data.");
} else if (error == 5) {
Serial.println("5: timeout");
}
}
if (nDevices == 0) {
Serial.println("No I2C devices found\n");
} else {
Serial.println("done\n");
}
delay(5000); // Wait 5 seconds for next scan
}

