BME280_SensorAPI
BME280_SensorAPI copied to clipboard
fixed example to work on a raspberry pi
the linux api to talk to i2c devices requires that the device id be specified by ioctl, otherwise how would it know which device to talk to?!
I tested this on a Raspberry Pi 4 (with latest Raspberry Pi OS) and can confirm that it works (after resolving conflicts). In contrast with the current version which does not.
Conflict resolution:
- use id struct (this is what marked as conflict)
- assign device address before use
final result:
[...]
/* Make sure to select BME280_I2C_ADDR_PRIM or BME280_I2C_ADDR_SEC as needed */
id.dev_addr = BME280_I2C_ADDR_PRIM;
if (ioctl(id.fd, I2C_SLAVE, id.dev_addr) < 0)
{
fprintf(stderr, "Failed to acquire bus access and/or talk to slave.\n");
exit(1);
}
dev.intf = BME280_I2C_INTF;
dev.read = user_i2c_read;
dev.write = user_i2c_write;
dev.delay_us = user_delay_us;
[...]