![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
EEPROMTEST
Fork of Test_nucleo_MCUUU by
main.cpp@8:2875bb7a4e67, 2018-05-09 (annotated)
- Committer:
- MockyBirdTwo
- Date:
- Wed May 09 11:13:21 2018 +0000
- Revision:
- 8:2875bb7a4e67
- Parent:
- 7:65325c237ac5
- Child:
- 9:cc559f905411
afdfs
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
xorjoep | 0:952479e15354 | 1 | #include "mbed.h" // Include files and define parameters. |
xorjoep | 0:952479e15354 | 2 | #include "Adafruit_ADS1015.h" |
MockyBirdTwo | 7:65325c237ac5 | 3 | #include <vector> |
xorjoep | 0:952479e15354 | 4 | |
xorjoep | 0:952479e15354 | 5 | I2C i2c_sensorplate_adc(PB_9, PB_8); // I2C for sensorplate. |
xorjoep | 0:952479e15354 | 6 | Adafruit_ADS1115 piezo_resistive_adc1(&i2c_sensorplate_adc, 0x48); // i2c pins, i2c address. |
xorjoep | 0:952479e15354 | 7 | Adafruit_ADS1115 piezo_resistive_adc2(&i2c_sensorplate_adc, 0x49); // i2c pins, i2c address. |
xorjoep | 0:952479e15354 | 8 | Adafruit_ADS1115 piezo_electric_adc(&i2c_sensorplate_adc, 0x4B); // i2c pins, i2c address. |
xorjoep | 0:952479e15354 | 9 | Serial usb_serial(SERIAL_TX, SERIAL_RX); // tx, rx |
xorjoep | 0:952479e15354 | 10 | |
xorjoep | 0:952479e15354 | 11 | int i2c__frequency = 100000; // I2C Frequency. |
xorjoep | 0:952479e15354 | 12 | int baud_rate = 115200; // Baud rate. |
xorjoep | 0:952479e15354 | 13 | |
xorjoep | 4:fd10d8609295 | 14 | Timer timer; |
xorjoep | 4:fd10d8609295 | 15 | |
MockyBirdTwo | 7:65325c237ac5 | 16 | // array to save sensor data |
MockyBirdTwo | 3:efb3a5b4bc9e | 17 | |
xorjoep | 0:952479e15354 | 18 | DigitalOut myled(LED1); |
MockyBirdTwo | 3:efb3a5b4bc9e | 19 | |
MockyBirdTwo | 8:2875bb7a4e67 | 20 | //Check whether any sensor values are zero |
MockyBirdTwo | 8:2875bb7a4e67 | 21 | void checkzero (std::vector<int>& sendat, int size){ |
MockyBirdTwo | 7:65325c237ac5 | 22 | for(int i=0;i<size;++i){ |
MockyBirdTwo | 8:2875bb7a4e67 | 23 | if(sendat[i]!= 0) |
MockyBirdTwo | 7:65325c237ac5 | 24 | usb_serial.printf("Sensor %d is not zero\n", i); |
MockyBirdTwo | 8:2875bb7a4e67 | 25 | else |
MockyBirdTwo | 8:2875bb7a4e67 | 26 | usb_serial.printf("Sensor %d is zero\n", i); |
MockyBirdTwo | 7:65325c237ac5 | 27 | } |
MockyBirdTwo | 7:65325c237ac5 | 28 | } |
MockyBirdTwo | 8:2875bb7a4e67 | 29 | |
MockyBirdTwo | 8:2875bb7a4e67 | 30 | //-------------FLASH FLASH----------------- |
MockyBirdTwo | 8:2875bb7a4e67 | 31 | //Only 16 bits data may be written. |
MockyBirdTwo | 8:2875bb7a4e67 | 32 | |
xorjoep | 0:952479e15354 | 33 | int main(){ |
MockyBirdTwo | 7:65325c237ac5 | 34 | std::vector<int> S_data(8); |
xorjoep | 0:952479e15354 | 35 | |
xorjoep | 0:952479e15354 | 36 | i2c_sensorplate_adc.frequency(i2c__frequency); // Set frequency for i2c connection to sensorplate (variable is declared in config part). |
xorjoep | 0:952479e15354 | 37 | usb_serial.baud(baud_rate); // Set serial USB connection baud rate (variable is declared in config part). |
xorjoep | 0:952479e15354 | 38 | |
MockyBirdTwo | 3:efb3a5b4bc9e | 39 | usb_serial.printf("MCUs rule the World !\n"); |
xorjoep | 1:8c5bcf47869e | 40 | |
xorjoep | 0:952479e15354 | 41 | piezo_resistive_adc1.setGain(GAIN_TWOTHIRDS); // Set ranges of ADC to +/-6.144V (end is marked with #): |
xorjoep | 0:952479e15354 | 42 | piezo_resistive_adc2.setGain(GAIN_TWOTHIRDS); |
xorjoep | 0:952479e15354 | 43 | |
xorjoep | 4:fd10d8609295 | 44 | usb_serial.printf("Gains set.\n"); |
xorjoep | 1:8c5bcf47869e | 45 | |
xorjoep | 4:fd10d8609295 | 46 | timer.start(); |
xorjoep | 0:952479e15354 | 47 | while(1){ |
xorjoep | 4:fd10d8609295 | 48 | while(timer.read_us() < 2000){}; timer.reset(); //Set readout frequency |
xorjoep | 0:952479e15354 | 49 | |
xorjoep | 0:952479e15354 | 50 | myled = !myled; |
xorjoep | 0:952479e15354 | 51 | //usb_serial.printf("Piezo electric 0_1 dif %d \n", piezo_electric_adc.readADC_Differential_0_1()); // First PE readout. |
xorjoep | 0:952479e15354 | 52 | // usb_serial.printf("Piezo electric 2_3 dif %d \n", piezo_electric_adc.readADC_Differential_2_3()); |
MockyBirdTwo | 6:7859d19b781a | 53 | |
MockyBirdTwo | 7:65325c237ac5 | 54 | for (uint8_t t=0; t<4; ++t){ //Save sensor data into array |
MockyBirdTwo | 7:65325c237ac5 | 55 | S_data[t] = (int16_t) piezo_resistive_adc1.readADC_SingleEnded(t); //Put first 4 PR sensor data into first 4 S_data array |
MockyBirdTwo | 7:65325c237ac5 | 56 | S_data[t+4]= (int16_t) piezo_resistive_adc2.readADC_SingleEnded(t); //Put next 4 PR sensor data into first 4 S_data array |
MockyBirdTwo | 6:7859d19b781a | 57 | } |
MockyBirdTwo | 7:65325c237ac5 | 58 | |
MockyBirdTwo | 8:2875bb7a4e67 | 59 | //checkzero(S_data,S_data.size()); |
xorjoep | 0:952479e15354 | 60 | for (uint8_t k = 0; k < 4; ++k) { |
MockyBirdTwo | 6:7859d19b781a | 61 | usb_serial.printf("R %d Ar %d: %d\n", k, 1, S_data[k]); // First 4 PR readout. |
MockyBirdTwo | 8:2875bb7a4e67 | 62 | usb_serial.printf("R %d Ar %d: %d\n", k, 2, S_data[k+4]); // Next 4 PR readout. |
xorjoep | 0:952479e15354 | 63 | } |
MockyBirdTwo | 8:2875bb7a4e67 | 64 | |
MockyBirdTwo | 7:65325c237ac5 | 65 | |
xorjoep | 0:952479e15354 | 66 | } |
xorjoep | 0:952479e15354 | 67 | } |