diff options
| author | Dawsyn Schraiber <[email protected]> | 2024-06-13 14:30:58 -0400 |
|---|---|---|
| committer | GitHub <[email protected]> | 2024-06-13 14:30:58 -0400 |
| commit | 58b4bc754bbb9f5197119cd0c124e49c05acff46 (patch) | |
| tree | 8a65e23756374626e2c9cb997af9d8ed6f892390 /tools/alt_test.cpp | |
| parent | 8fbd08fe29bbc2246a78b481b219c241f62ff420 (diff) | |
| download | active-drag-system-58b4bc754bbb9f5197119cd0c124e49c05acff46.tar.gz active-drag-system-58b4bc754bbb9f5197119cd0c124e49c05acff46.tar.bz2 active-drag-system-58b4bc754bbb9f5197119cd0c124e49c05acff46.zip | |
Where to begin…. (#13)
+/- Reworked collection of altimeter related functions into altimeter class
+/- Reworked bno055 class to be imu class with minimal functionality
\- Removed external Kalman filter implementations in favor of own in house version
\- Removed any/unused files
\+ Added buffer logger for when sitting on pad for extended period of time in effort to prevent filling of flash chip
\+ Added heartbeat LED for alive status
Diffstat (limited to 'tools/alt_test.cpp')
| -rw-r--r-- | tools/alt_test.cpp | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/tools/alt_test.cpp b/tools/alt_test.cpp new file mode 100644 index 0000000..a5c8849 --- /dev/null +++ b/tools/alt_test.cpp @@ -0,0 +1,50 @@ +#include <stdio.h> + +#include "hardware/gpio.h" +#include "boards/pico_w.h" +#include "hardware/i2c.h" +#include "pico/stdio.h" +#include "pico/time.h" + +#define ALT_ADDR 0x60 +#define MAX_SCL 400000 +#define DATA_RATE_HZ 15 + +float altitude = 0.0f; +float get_altitude(); + +int main() { + stdio_init_all(); + + i2c_init(i2c_default, MAX_SCL); + 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 config[2] = {0}; + + // Select control register(0x26) + // Active mode, OSR = 16, altimeter mode(0xB8) + config[0] = 0x26; + config[1] = 0xB9; + i2c_write_blocking(i2c_default, ALT_ADDR, config, 2, true); + sleep_ms(1500); + + while (1) { + sleep_ms(1000); + altitude = get_altitude(); + printf("Altitude: %4.2f\n", altitude); + } +} + +float get_altitude() { + uint8_t reg = 0x01; + uint8_t data[5]; + i2c_write_blocking(i2c_default, ALT_ADDR, ®, 1, true); + i2c_read_blocking(i2c_default, ALT_ADDR, data, 5, false); + // Exactly how MPL3115A2 datasheet says to retrieve altitude + float altitude = (float) ((int16_t) ((data[0] << 8) | data[1])) + (float) (data[2] >> 4) * 0.0625; + return altitude; +} + |
