Library and demo program for MS4525DO differential pressure sensor based pitot tube, using I2C interface
Temperature values are correct. But I dont trust the PSI and airspeed (especially airspeed).
Code blended and ported from a combination of the following sources:
- https://forum.arduino.cc/index.php?topic=309653.0
- https://github.com/PX4/Firmware/blob/master/src/modules/commander/airspeed_calibration.cpp
- https://github.com/PX4/Firmware/tree/master/src/drivers/differential_pressure/ms4525
main.cpp@0:5965bf423184, 2019-09-13 (annotated)
- Committer:
- epremeaux
- Date:
- Fri Sep 13 08:41:37 2019 +0000
- Revision:
- 0:5965bf423184
initial commit. I dont trust the output values yet
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| epremeaux | 0:5965bf423184 | 1 | #include "mbed.h" |
| epremeaux | 0:5965bf423184 | 2 | #include "F303_logger.h" |
| epremeaux | 0:5965bf423184 | 3 | #include "MS4525DO.h" |
| epremeaux | 0:5965bf423184 | 4 | |
| epremeaux | 0:5965bf423184 | 5 | Serial terminal(USBTX, USBRX); |
| epremeaux | 0:5965bf423184 | 6 | I2C i2c(I2CSDA, I2CSCL); |
| epremeaux | 0:5965bf423184 | 7 | |
| epremeaux | 0:5965bf423184 | 8 | MS4525DO Pitot(i2c); |
| epremeaux | 0:5965bf423184 | 9 | |
| epremeaux | 0:5965bf423184 | 10 | DigitalOut myled(LED1); |
| epremeaux | 0:5965bf423184 | 11 | |
| epremeaux | 0:5965bf423184 | 12 | |
| epremeaux | 0:5965bf423184 | 13 | int main() { |
| epremeaux | 0:5965bf423184 | 14 | terminal.baud(115200); |
| epremeaux | 0:5965bf423184 | 15 | terminal.printf("MS4525DO library test\n"); |
| epremeaux | 0:5965bf423184 | 16 | |
| epremeaux | 0:5965bf423184 | 17 | while(1) { |
| epremeaux | 0:5965bf423184 | 18 | char PitotStatus; // A two bit field indicating the status of the I2C read |
| epremeaux | 0:5965bf423184 | 19 | PitotStatus = Pitot.measure(); |
| epremeaux | 0:5965bf423184 | 20 | |
| epremeaux | 0:5965bf423184 | 21 | switch (PitotStatus) |
| epremeaux | 0:5965bf423184 | 22 | { |
| epremeaux | 0:5965bf423184 | 23 | case 0: |
| epremeaux | 0:5965bf423184 | 24 | //Serial.println("Ok "); |
| epremeaux | 0:5965bf423184 | 25 | terminal.printf("PSI: %f\n", Pitot.getPSI()); |
| epremeaux | 0:5965bf423184 | 26 | terminal.printf("Temperature: %f\n", Pitot.getTemperature()); |
| epremeaux | 0:5965bf423184 | 27 | terminal.printf("Airspeed: %f\n", Pitot.getAirSpeed()); |
| epremeaux | 0:5965bf423184 | 28 | terminal.printf("\n"); |
| epremeaux | 0:5965bf423184 | 29 | break; |
| epremeaux | 0:5965bf423184 | 30 | |
| epremeaux | 0:5965bf423184 | 31 | case 1: |
| epremeaux | 0:5965bf423184 | 32 | terminal.printf("Busy\n"); |
| epremeaux | 0:5965bf423184 | 33 | break; |
| epremeaux | 0:5965bf423184 | 34 | |
| epremeaux | 0:5965bf423184 | 35 | case 2: |
| epremeaux | 0:5965bf423184 | 36 | terminal.printf("Stale\n"); |
| epremeaux | 0:5965bf423184 | 37 | break; |
| epremeaux | 0:5965bf423184 | 38 | |
| epremeaux | 0:5965bf423184 | 39 | default: |
| epremeaux | 0:5965bf423184 | 40 | terminal.printf("Error\n"); |
| epremeaux | 0:5965bf423184 | 41 | break; |
| epremeaux | 0:5965bf423184 | 42 | } |
| epremeaux | 0:5965bf423184 | 43 | myled = !myled; |
| epremeaux | 0:5965bf423184 | 44 | wait_ms(200); |
| epremeaux | 0:5965bf423184 | 45 | } |
| epremeaux | 0:5965bf423184 | 46 | } |
Emery Premeaux