Pilot 1 working code (excluding new patient after calculation). %d changed in %f sensordata serial log.
Dependencies: ADS1015 MPU6050 PixelArray mbed
Fork of Momo_New by
ADS1115-hello_world/main.cpp@0:c0e44c46c573, 2017-08-28 (annotated)
- Committer:
- DEldering
- Date:
- Mon Aug 28 10:16:59 2017 +0000
- Revision:
- 0:c0e44c46c573
- Child:
- 1:a8e61f3910ad
Pre PE integration
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
DEldering | 0:c0e44c46c573 | 1 | #include "mbed.h" |
DEldering | 0:c0e44c46c573 | 2 | #include "Adafruit_ADS1015.h" |
DEldering | 0:c0e44c46c573 | 3 | #include "USBSerial.h" |
DEldering | 0:c0e44c46c573 | 4 | #include "MPU6050.h" |
DEldering | 0:c0e44c46c573 | 5 | #define SERIAL_BAUD_RATE 115200 |
DEldering | 0:c0e44c46c573 | 6 | |
DEldering | 0:c0e44c46c573 | 7 | MPU6050 ark(p9,p10); |
DEldering | 0:c0e44c46c573 | 8 | I2C i2c(p28, p27); |
DEldering | 0:c0e44c46c573 | 9 | Adafruit_ADS1115 ads0(&i2c, 0x48); |
DEldering | 0:c0e44c46c573 | 10 | Adafruit_ADS1115 ads1(&i2c, 0x49); |
DEldering | 0:c0e44c46c573 | 11 | //Adafruit_ADS1115 ads2(&i2c, 0x4A); |
DEldering | 0:c0e44c46c573 | 12 | Serial pc(USBTX, USBRX); // tx, rx |
DEldering | 0:c0e44c46c573 | 13 | Ticker sample; |
DEldering | 0:c0e44c46c573 | 14 | short read[8]; |
DEldering | 0:c0e44c46c573 | 15 | int done; |
DEldering | 0:c0e44c46c573 | 16 | int j; |
DEldering | 0:c0e44c46c573 | 17 | int k; |
DEldering | 0:c0e44c46c573 | 18 | float acce[3]; |
DEldering | 0:c0e44c46c573 | 19 | |
DEldering | 0:c0e44c46c573 | 20 | void read_adc() |
DEldering | 0:c0e44c46c573 | 21 | { |
DEldering | 0:c0e44c46c573 | 22 | for (k = 0; k < 4; k = k + 1) { |
DEldering | 0:c0e44c46c573 | 23 | read[k]= ads0.readADC_SingleEnded(k); |
DEldering | 0:c0e44c46c573 | 24 | read[k+4]= ads1.readADC_SingleEnded(k); |
DEldering | 0:c0e44c46c573 | 25 | } |
DEldering | 0:c0e44c46c573 | 26 | ark.getAccelero(acce); |
DEldering | 0:c0e44c46c573 | 27 | j = acce[0]*10; |
DEldering | 0:c0e44c46c573 | 28 | pc.printf(",%d,%d,%d,%d,%d,%d,%d,%d,%d,\r\n", read[1], read[0], read[4], read[7], read[5], read[6], read[2], read[3],j); // print 'read' array to serial port |
DEldering | 0:c0e44c46c573 | 29 | //pi.printf(",%d,%d,%d,%d,%d,%d,%d,%d,\r\n", read[1], read[0], read[4], read[7], read[5], read[6], read[2], read[3]); // print 'read' array to serial port |
DEldering | 0:c0e44c46c573 | 30 | } |
DEldering | 0:c0e44c46c573 | 31 | |
DEldering | 0:c0e44c46c573 | 32 | int main() |
DEldering | 0:c0e44c46c573 | 33 | { |
DEldering | 0:c0e44c46c573 | 34 | i2c.frequency(400000); |
DEldering | 0:c0e44c46c573 | 35 | pc.baud(115200); |
DEldering | 0:c0e44c46c573 | 36 | //pi.baud(115200); |
DEldering | 0:c0e44c46c573 | 37 | ads0.setGain(GAIN_ONE); // set range to +/-4.096V |
DEldering | 0:c0e44c46c573 | 38 | ads1.setGain(GAIN_ONE); // set range to +/-4.096V |
DEldering | 0:c0e44c46c573 | 39 | sample.attach_us(&read_adc, 100000); |
DEldering | 0:c0e44c46c573 | 40 | while (1) { |
DEldering | 0:c0e44c46c573 | 41 | wait_ms(101); // wait indefinitely because the ticker restarts every 50 ms |
DEldering | 0:c0e44c46c573 | 42 | } |
DEldering | 0:c0e44c46c573 | 43 | } |