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
Sensorplate/main.cpp
- Committer:
- DEldering
- Date:
- 2017-09-14
- Revision:
- 3:cb38f2b1fd5a
- Parent:
- 2:c6497fc90768
- Child:
- 4:367af005956b
File content as of revision 3:cb38f2b1fd5a:
#include "mbed.h" #include "Adafruit_ADS1015.h" #include "USBSerial.h" #include "MPU6050.h" I2C i2c(p28, p27); // I2C MPU6050 agu(p28,p27); // Accelerometer/Gyroscope Unit Adafruit_ADS1115 pr1(&i2c, 0x48); // first PiëzoResistive ADC Adafruit_ADS1115 pr2(&i2c, 0x49); // second PiëzoResistive ADC Adafruit_ADS1115 pel(&i2c, 0x4B); // PiëzoElectric ADC Serial pc(USBTX, USBRX); // tx, rx // Serial USB connection Timer t; // Timer for equally time-spaced samples Ticker sample_cycle; // Polling cycle int cycle_time = 100000; // Cycle time in us int i2c_freq = 400000; // I2C Frequency int usb_baud = 115200; // USB Baud rate short res[8] = {0,0,0,0,0,0,0,0}; // 8 PR sensors 1 time per cycle short elec[5] = {0,0,0,0,0}; // 1 PE sensor 5 times per cycle int angle = 0; // Accelerometer Z-axis int k = 0; float acce[3]; // Raw accelerometer data float gyro[3]; // Raw gyroscope data void read_adc() { t.reset(); t.start(); elec[0] = pel.readADC_SingleEnded(0); for (k = 0; k < 4; k = k + 1) { res[k] = pr1.readADC_SingleEnded(k); } while(t.read_us()<(1*(cycle_time/5))) {} elec[1] = pel.readADC_SingleEnded(0); for (k = 0; k < 4; k = k + 1) { res[k+4] = pr2.readADC_SingleEnded(k); } while(t.read_us()<(2*(cycle_time/5))) {} elec[2] = pel.readADC_SingleEnded(0); agu.getAccelero(acce); angle = acce[2]*10; while(t.read_us()<(3*(cycle_time/5))) {} elec[3] = pel.readADC_SingleEnded(0); agu.getGyro(gyro); while(t.read_us()<(4*(cycle_time/5))) {} elec[4] = pel.readADC_SingleEnded(0); while(t.read_us()<(4.5*(cycle_time/5))) {} pc.printf(",%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,\r\n", res[4], res[7], res[6], res[5], res[1], res[0], res[2], res[3], angle, elec[0], elec[1], elec[2], elec[3], elec[4], acce[0]*100, acce[1]*100, acce[2]*100, gyro[0]*100, gyro[1]*100, gyro[2]*100); // print all to serial port } int main() { i2c.frequency(i2c_freq); pc.baud(usb_baud); pr1.setGain(GAIN_TWOTHIRDS); // set range to +/-6.144V pr2.setGain(GAIN_TWOTHIRDS); // set range to +/-6.144V pel.setGain(GAIN_TWOTHIRDS); // set range to +/-6.144V sample_cycle.attach_us(&read_adc, cycle_time); while (1) { wait_us(cycle_time+1); // wait indefinitely because the ticker restarts every 50 ms } }