If you only connect one IC2 device on the bus perhaps you can use the followig code to determine if it is working if you know its address.
Code:
#include <stdio.h>#include "pico/stdlib.h"#include "hardware/i2c.h"bool is_device_present(i2c_inst_t *i2c, uint8_t address) { uint8_t rxdata; return i2c_read_blocking(i2c, address, &rxdata, 1, false) >= 0;}int main() { stdio_init_all();#if !defined(i2c_default) || !defined(PICO_DEFAULT_I2C_SDA_PIN) || !defined(PICO_DEFAULT_I2C_SCL_PIN)#warning i2c/bus_scan example requires a board with I2C pins puts("Default I2C pins were not defined");#else i2c_init(i2c_default, 100 * 1000); gpio_set_function(PICO_DEFAULT_I2C_SDA_PIN, GPIO_FUNC_I2C); gpio_set_function(PICO_DEFAULT_I2C_SCL_PIN, GPIO_FUNC_I2C); gpio_pull_up(PICO_DEFAULT_I2C_SDA_PIN); gpio_pull_up(PICO_DEFAULT_I2C_SCL_PIN); uint8_t target_address = 0xC2; if (is_device_present(i2c_default, target_address)) { printf("Device found at 0x%02X\n", target_address); } else { printf("No device at 0x%02X\n", target_address); } return 0;#endif}Statistics: Posted by hoodhlab — Tue Mar 25, 2025 10:28 pm