![](/media/cache/group/default_image.jpg.50x50_q85.jpg)
PmodNAV test
Dependencies: mbed LPS25HB_I2C LSM9DS1 UsaPack
main.cpp@1:e5d5afc20fe2, 2021-10-20 (annotated)
- Committer:
- osaka
- Date:
- Wed Oct 20 04:24:26 2021 +0000
- Revision:
- 1:e5d5afc20fe2
- Parent:
- 0:c99eaed54c50
- Child:
- 4:1f382a93d438
test
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
osaka | 0:c99eaed54c50 | 1 | #include "mbed.h" |
osaka | 0:c99eaed54c50 | 2 | #include "LSM9DS1.h" |
osaka | 0:c99eaed54c50 | 3 | #include "LPS.h" |
osaka | 0:c99eaed54c50 | 4 | |
osaka | 1:e5d5afc20fe2 | 5 | Serial pc(USBTX, USBRX); |
osaka | 1:e5d5afc20fe2 | 6 | Serial twelite(PE_8, PE_7); |
osaka | 1:e5d5afc20fe2 | 7 | |
osaka | 1:e5d5afc20fe2 | 8 | I2C i2c(PB_9, PB_8); |
osaka | 0:c99eaed54c50 | 9 | LSM9DS1 lsm(i2c); |
osaka | 0:c99eaed54c50 | 10 | LPS lps(i2c); |
osaka | 0:c99eaed54c50 | 11 | |
osaka | 0:c99eaed54c50 | 12 | |
osaka | 0:c99eaed54c50 | 13 | int main() |
osaka | 0:c99eaed54c50 | 14 | { |
osaka | 1:e5d5afc20fe2 | 15 | pc.baud(38400); |
osaka | 1:e5d5afc20fe2 | 16 | //enum gyro_scale gs; |
osaka | 1:e5d5afc20fe2 | 17 | //gs245 = G_SCALE_245DPS; |
osaka | 1:e5d5afc20fe2 | 18 | uint16_t reg = lsm.begin(lsm.G_SCALE_245DPS, lsm.A_SCALE_8G); |
osaka | 0:c99eaed54c50 | 19 | //printf("%x\n", reg); |
osaka | 0:c99eaed54c50 | 20 | if (!lps.init()){ |
osaka | 1:e5d5afc20fe2 | 21 | while (1) |
osaka | 1:e5d5afc20fe2 | 22 | { |
osaka | 1:e5d5afc20fe2 | 23 | pc.printf("Failed to autodetect pressure sensor!\r\n"); |
osaka | 1:e5d5afc20fe2 | 24 | wait(2); |
osaka | 1:e5d5afc20fe2 | 25 | }; |
osaka | 0:c99eaed54c50 | 26 | } |
osaka | 0:c99eaed54c50 | 27 | lps.enableDefault(); |
osaka | 0:c99eaed54c50 | 28 | wait_ms(100); |
osaka | 0:c99eaed54c50 | 29 | while(true) |
osaka | 0:c99eaed54c50 | 30 | { |
osaka | 0:c99eaed54c50 | 31 | lsm.readAccel(); |
osaka | 0:c99eaed54c50 | 32 | lsm.readMag(); |
osaka | 0:c99eaed54c50 | 33 | lsm.readGyro(); |
osaka | 0:c99eaed54c50 | 34 | //printf("%f %f %f %f %f %f %f %f %f\n", lsm.ax, lsm.ay, lsm.az, lsm.gx, lsm.gy, lsm.gz, lsm.mx, lsm.my, lsm.mz); |
osaka | 0:c99eaed54c50 | 35 | //printf("%f %f %f\n", lsm.gx, lsm.gy, lsm.gz); |
osaka | 0:c99eaed54c50 | 36 | //printf("%f %f %f\n", lsm.mx, lsm.my, lsm.mz); |
osaka | 0:c99eaed54c50 | 37 | float pressure = lps.readPressureMillibars(); |
osaka | 0:c99eaed54c50 | 38 | float altitude = lps.pressureToAltitudeMeters(pressure); |
osaka | 0:c99eaed54c50 | 39 | float temperature = lps.readTemperatureC(); |
osaka | 0:c99eaed54c50 | 40 | //printf("p:%.2f\t mbar\ta:%.2f m\tt:%.2f deg C\r\n",pressure,altitude,temperature); |
osaka | 1:e5d5afc20fe2 | 41 | pc.printf("%f %f %f %f %f %f %f %f %f %f\r\n", lsm.ax, lsm.ay, lsm.az, lsm.gx, lsm.gy, lsm.gz, lsm.mx, lsm.my, lsm.mz, pressure); |
osaka | 0:c99eaed54c50 | 42 | wait(0.1); |
osaka | 0:c99eaed54c50 | 43 | } |
osaka | 0:c99eaed54c50 | 44 | } |