EEPROMTEST

Dependencies:   ADS1015 mbed

Fork of Test_nucleo_MCUUU by BAP TUDelft

Committer:
xorjoep
Date:
Mon May 07 09:31:14 2018 +0000
Revision:
4:fd10d8609295
Parent:
2:78e48758fa6b
Child:
5:ff21a388985c
Added timer

Who changed what in which revision?

UserRevisionLine numberNew contents of line
xorjoep 0:952479e15354 1 #include "mbed.h" // Include files and define parameters.
xorjoep 0:952479e15354 2 #include "Adafruit_ADS1015.h"
xorjoep 0:952479e15354 3
xorjoep 0:952479e15354 4 I2C i2c_sensorplate_adc(PB_9, PB_8); // I2C for sensorplate.
xorjoep 0:952479e15354 5 Adafruit_ADS1115 piezo_resistive_adc1(&i2c_sensorplate_adc, 0x48); // i2c pins, i2c address.
xorjoep 0:952479e15354 6 Adafruit_ADS1115 piezo_resistive_adc2(&i2c_sensorplate_adc, 0x49); // i2c pins, i2c address.
xorjoep 0:952479e15354 7 Adafruit_ADS1115 piezo_electric_adc(&i2c_sensorplate_adc, 0x4B); // i2c pins, i2c address.
xorjoep 0:952479e15354 8 Serial usb_serial(SERIAL_TX, SERIAL_RX); // tx, rx
xorjoep 0:952479e15354 9
xorjoep 0:952479e15354 10 int i2c__frequency = 100000; // I2C Frequency.
xorjoep 0:952479e15354 11 int baud_rate = 115200; // Baud rate.
xorjoep 0:952479e15354 12
xorjoep 4:fd10d8609295 13 Timer timer;
xorjoep 4:fd10d8609295 14
xorjoep 0:952479e15354 15 DigitalOut myled(LED1);
MockyBirdTwo 2:78e48758fa6b 16 //Test 1 2 3 test test
xorjoep 0:952479e15354 17 int main(){
xorjoep 0:952479e15354 18
xorjoep 0:952479e15354 19
xorjoep 0:952479e15354 20 i2c_sensorplate_adc.frequency(i2c__frequency); // Set frequency for i2c connection to sensorplate (variable is declared in config part).
xorjoep 0:952479e15354 21 usb_serial.baud(baud_rate); // Set serial USB connection baud rate (variable is declared in config part).
xorjoep 0:952479e15354 22
xorjoep 1:8c5bcf47869e 23 usb_serial.printf("Hello World !\n");
xorjoep 1:8c5bcf47869e 24
xorjoep 0:952479e15354 25 piezo_resistive_adc1.setGain(GAIN_TWOTHIRDS); // Set ranges of ADC to +/-6.144V (end is marked with #):
xorjoep 0:952479e15354 26 piezo_resistive_adc2.setGain(GAIN_TWOTHIRDS);
xorjoep 0:952479e15354 27
xorjoep 4:fd10d8609295 28 usb_serial.printf("Gains set.\n");
xorjoep 1:8c5bcf47869e 29
xorjoep 4:fd10d8609295 30 timer.start();
xorjoep 0:952479e15354 31 while(1){
xorjoep 4:fd10d8609295 32 while(timer.read_us() < 2000){}; timer.reset(); //Set readout frequency
xorjoep 0:952479e15354 33
xorjoep 0:952479e15354 34 myled = !myled;
xorjoep 0:952479e15354 35 //usb_serial.printf("Piezo electric 0_1 dif %d \n", piezo_electric_adc.readADC_Differential_0_1()); // First PE readout.
xorjoep 0:952479e15354 36 // usb_serial.printf("Piezo electric 2_3 dif %d \n", piezo_electric_adc.readADC_Differential_2_3());
xorjoep 0:952479e15354 37
xorjoep 0:952479e15354 38 for (uint8_t k = 0; k < 4; ++k) {
xorjoep 4:fd10d8609295 39 usb_serial.printf("R %d Ar %d: %d\n", k, 1, (int16_t) piezo_resistive_adc1.readADC_SingleEnded(k)); // First 4 PR readout.
xorjoep 4:fd10d8609295 40 usb_serial.printf("R %d Ar %d: %d\n", k, 2, (int16_t) piezo_resistive_adc2.readADC_SingleEnded(k)); // First 4 PR readout.
xorjoep 0:952479e15354 41 }
xorjoep 0:952479e15354 42 }
xorjoep 0:952479e15354 43 }