I2C on Husarion to push Sensor Data and read in Python

I use the Bosch BME 680 sensor on my Leo (on the 2nd Raspberry). I have a library and a Flask web server. Everything works. However, I did think about whether it is possible to operate the sensor on the Husarion board. How can you simply read out the I2C data of the BME via the Husarion Board / RAspberry. So I would save the 2nd RAspberry. Unfortunately, the I2C pins on the LEO Raspberry are occupied.

To read the sensor data from Python code, you will have the provide the functionality in CORE2 firmware to ROS topics/services. Take a look at our Firmware Development guide to learn how to add new topics.

The CORE2 board provides hardware I2C on hSensor ports 1 & 2. If you want to use hSens1 for I2C, you would first initialize it like below:

hSens1.selectI2C();  // change hSensor mode to I2C
II2C& i2c = hSens1.getI2C();  // get the I2C interface
i2c.setDataRate(100000);  // set data rate to 100kHz

If both hSens ports are already occupied, you may try the Software implementation (although, I have not tested it yet) to use any other hSens port:

hSensor_softi2c& hSens_softi2c = hSens3.getSoftwareI2C();  // get the proxy object for accesing the software i2c
hSens_softi2c.selectI2C();  // change hSensor mode to I2C
II2C& i2c = hSens_softi2c.getI2C();  // get the I2C interface
i2c.setDataRate(10000);  // set data rate to 10kHz

After the initialization, you can, for example, read a register value like below:

uint8_t data;
bool success;
success = i2c.read(0x10, &data, 1);
if (!success) {
	// read failed
}
1 Like

This would be a hard way - but i will try. But a the Moment i can´t find my LEO

Haha, what are you doing there?

Network discovery :slight_smile: So I have a bit more modern devices :-). But somehow it fits my programming style.

So, I tried something to expand the firmware to get the BME680 up and running - unfortunately without success. It is also somehow not entirely clear to me how I am migrating the BME program part - and where. I think I won’t get very far without support. Here is the Lib. I´ve tried the hsense1 Port (I2C)

@Blazej_Sowa Can you help?

The Adafruit libraries can be difficult to port as they are very specific for the Arduino platform. I suggest using directly the Bosh drivers available here as they allow to specify a custom communication layer for the I2C protocol.

I developed a sample project for the CORE2 board that uses these libraries to read data from the BME sensor connected to the hSens1 port:

You should be able to compile it in VS Code with the Husarion extension. Once you flash it, open the serial console and check the output. I haven’t tested it because I don’t have this sensor.

1 Like

I will try and report

Bonjour, j’essaie d’utilisé les pins du leo en utilisant hsens mais à chaque fois j’ai des erreurs, pouvez vous m’aidez?