found and tested a library for communication with the bme280

This commit is contained in:
2026-03-23 19:45:00 +01:00
parent b12c61d7b8
commit 359c04bf16
2 changed files with 26 additions and 17 deletions

View File

@@ -1,25 +1,32 @@
#include "bme280.h"
#include "hardware/i2c.h"
#include "pico/cyw43_arch.h"
#include "pico/stdlib.h"
#include <cstdio>
void check_i2c() {
uint8_t buffer;
for (int addr{0x08}; addr < 0x78; addr++) {
if (i2c_read_blocking(i2c0, addr, &buffer, 1, false) > 0) {
printf("Adresse: %02X\n", addr);
}
}
}
constexpr int i2cAddress{0x76};
int main() {
sleep_ms(3000);
stdio_init_all();
i2c_init(i2c0, 400 * 1000);
gpio_set_function(0, GPIO_FUNC_I2C); // SDA
gpio_set_function(1, GPIO_FUNC_I2C); // SCL
gpio_pull_up(0);
gpio_pull_up(1);
sleep_ms(3000);
cyw43_arch_init();
bme280_handle_t handle;
int result{bme280_init(&handle, i2cAddress, INTERVAL_1000MS)};
printf("I2C scan...\n");
for (uint8_t addr = 0x08; addr < 0x78; addr++) {
uint8_t dummy;
int ret = i2c_read_blocking(i2c1, addr, &dummy, 1, false);
if (ret >= 0) {
printf("Gefunden: 0x%02X\n", addr);
}
}
while (true) {
check_i2c();
int result{bme280_init(&handle, i2cAddress, INTERVAL_1000MS)};
printf("Init result: %d\n", result);
bme280_read_data(handle);
printf("%s\n", bme280_get_json(handle));
sleep_ms(3000);
}
}