found and tested a library for communication with the bme280
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
cmake_minimum_required(VERSION 3.13)
|
||||
set(PICO_BOARD pico_w)
|
||||
|
||||
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
|
||||
set(PICO_SDK_PATH ${CMAKE_SOURCE_DIR}/../pico-sdk)
|
||||
@@ -6,7 +7,6 @@ set(PICO_SDK_PATH ${CMAKE_SOURCE_DIR}/../pico-sdk)
|
||||
# Pico SDK einbinden – MUSS vor project() stehen
|
||||
include(${PICO_SDK_PATH}/external/pico_sdk_import.cmake)
|
||||
|
||||
set(PICO_BOARD pico_w)
|
||||
|
||||
project(mein_projekt C CXX ASM)
|
||||
set(CMAKE_C_STANDARD 11)
|
||||
@@ -14,6 +14,8 @@ set(CMAKE_CXX_STANDARD 17)
|
||||
|
||||
pico_sdk_init()
|
||||
|
||||
add_subdirectory(../lib/bme280 bme280_build)
|
||||
|
||||
add_executable(mein_projekt
|
||||
main.cpp
|
||||
)
|
||||
@@ -26,7 +28,7 @@ pico_enable_stdio_uart(mein_projekt 0)
|
||||
target_link_libraries(mein_projekt
|
||||
pico_stdlib
|
||||
pico_cyw43_arch_none
|
||||
hardware_i2c
|
||||
bme280
|
||||
)
|
||||
|
||||
# Erzeugt .uf2 Datei zum Flashen
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user