diff options
| author | Nathan Perry <np@npry.dev> | 2024-10-24 01:13:31 -0400 |
|---|---|---|
| committer | Nathan Perry <np@npry.dev> | 2024-10-24 01:13:31 -0400 |
| commit | 96e8a6363d481171315ab81b3f72bfa381d64f02 (patch) | |
| tree | fb3e962ecf7b8939b632870267cf0556c521f959 | |
| parent | 5077fec0348e717fa93bd1879548fed03fcae52e (diff) | |
read lsm
| -rw-r--r-- | test_fw/include/lsm6dsm.h | 16 | ||||
| -rw-r--r-- | test_fw/platformio.ini | 6 | ||||
| -rw-r--r-- | test_fw/src/main.cpp | 102 |
3 files changed, 112 insertions, 12 deletions
diff --git a/test_fw/include/lsm6dsm.h b/test_fw/include/lsm6dsm.h new file mode 100644 index 0000000..17c80f5 --- /dev/null +++ b/test_fw/include/lsm6dsm.h @@ -0,0 +1,16 @@ +#pragma once + +#include <Adafruit_SPIDevice.h> +#include <Adafruit_BusIO_Register.h> + +namespace ocularium::lsm6dsm { + typedef Adafruit_BusIO_Register Reg; + + struct LSM6DSM { + LSM6DSM(Adafruit_SPIDevice& device) : spi_device(device) {}; + + Adafruit_SPIDevice& spi_device; + + Reg ctrl1 = Reg(&spi_device, ); + }; +} diff --git a/test_fw/platformio.ini b/test_fw/platformio.ini index d041309..df71bc1 100644 --- a/test_fw/platformio.ini +++ b/test_fw/platformio.ini @@ -10,7 +10,6 @@ [env:pico] platform = https://github.com/maxgerhardt/platform-raspberrypi.git -;platform = raspberrypi board = pico board_build.core = earlephilhower board_build.filesystem_size = 0m @@ -18,14 +17,15 @@ board_build.arduino.earlephilhower.usb_manufacturer = Nathan Perry board_build.arduino.earlephilhower.usb_product = ocularium (v0.2.0) board_build.arduino.earlephilhower.usb_vid = 0x8888 board_build.arduino.earlephilhower.usb_pid = 0x2008 - framework = arduino lib_deps = adafruit/Adafruit BME680 Library@^2.0.5 etlcpp/Embedded Template Library@^20.39.4 arduino-libraries/SD@^1.3.0 + adafruit/Adafruit LSM6DS@^4.7.3 build_flags = -std=c++2a -DPIO_FRAMEWORK_ARDUINO_ENABLE_EXCEPTIONS - -DDEBUG_RP2040_WIRE -DDEBUG_RP2040_SPI -DDEBUG_RP2040_CORE -DDEBUG_RP2040_PORT=Serial + -DDEBUG_RP2040_CORE + -DDEBUG_RP2040_PORT=Serial -fstack-protector diff --git a/test_fw/src/main.cpp b/test_fw/src/main.cpp index 5f8e1d4..5206c16 100644 --- a/test_fw/src/main.cpp +++ b/test_fw/src/main.cpp @@ -1,9 +1,10 @@ #include <Arduino.h> #include <Wire.h> #include <SPI.h> -#include <SD.h> #include <Adafruit_BME680.h> +#include <Adafruit_LSM6DS.h> +#include <Adafruit_LSM6DSL.h> #include <hardware/pio.h> @@ -14,13 +15,14 @@ using namespace ocularium; - static Adafruit_BME680 bme(&Wire1); static VEML lux(Wire1); +static Adafruit_LSM6DSL lsm; #define SCAN_I2C 0 #define SDCARD_SPI SD_SPI +#include <SD.h> static SDClass sd; static bringup::init_check STARTUP_CHECKS[] = { @@ -35,6 +37,24 @@ static bringup::init_check STARTUP_CHECKS[] = { .gain = veml::AmbientLightGain::Quarter, }); }, .succeeded = false, + }, + { + .name = String("lsm6dsm"), + .f = [] + { + if (lsm.begin_SPI(LSM_CS, &LSM_SPI)) + { + lsm.reset(); + + lsm.setAccelDataRate(LSM6DS_RATE_52_HZ); + lsm.setGyroDataRate(LSM6DS_RATE_52_HZ); + + return true; + }; + + return false; + }, + .succeeded = false, } }; @@ -72,13 +92,77 @@ void loop() { bme_target_millis = bme.beginReading(); } + + static sensors_vec_t accel, gyro; + + while (lsm.gyroscopeAvailable()) + { + lsm.readGyroscope(gyro.x, gyro.y, gyro.z); + } + + while (lsm.accelerationAvailable()) + { + lsm.readAcceleration(accel.x, accel.y, accel.z); + } + + struct + { + const char* name; + float value; + } readings[] = { + { + .name = "lux", + .value = lux.lux(), + }, + + { + .name = "temp", + .value = bme.temperature, + }, + { + .name = "hum", + .value = bme.humidity, + }, + { + .name = "pres", + .value = static_cast<float>(bme.pressure), + }, + { + .name = "gas", + .value = bme.humidity, + }, + + { + .name = "ax", + .value = accel.x, + }, + { + .name = "ay", + .value = accel.y, + }, + { + .name = "az", + .value = accel.z, + }, + + { + .name = "gx", + .value = gyro.x, + }, + { + .name = "gy", + .value = gyro.y, + }, + { + .name = "gz", + .value = gyro.z, + }, + }; + + for (const auto &[name, value] : readings) + { + Serial.printf("%s:%f,", name, value); + } - Serial.print("lux: " + String(lux.lux())); - Serial.print(", temp: " + String(bme.temperature)); - Serial.print(", hum: " + String(bme.humidity)); - Serial.print(", pres: " + String(bme.pressure)); - Serial.print(", gas: " + String(bme.gas_resistance)); Serial.println(); - - delay(100); }
\ No newline at end of file |
