![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
Use ADS1115
main.cpp@2:00320fd347da, 2019-06-04 (annotated)
- Committer:
- LoloF
- Date:
- Tue Jun 04 12:08:23 2019 +0000
- Revision:
- 2:00320fd347da
- Parent:
- 1:02d947b2fdec
ADS1115
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
arve0 | 0:ea70612a3ee1 | 1 | #include "mbed.h" |
arve0 | 0:ea70612a3ee1 | 2 | #include "Adafruit_ADS1015.h" |
LoloF | 2:00320fd347da | 3 | |
arve0 | 0:ea70612a3ee1 | 4 | |
arve0 | 0:ea70612a3ee1 | 5 | #define SERIAL_BAUD_RATE 9600 |
arve0 | 0:ea70612a3ee1 | 6 | |
LoloF | 2:00320fd347da | 7 | I2C i2c(PB_11, PB_10); |
arve0 | 1:02d947b2fdec | 8 | Adafruit_ADS1115 ads(&i2c); |
LoloF | 2:00320fd347da | 9 | Serial pc(USBTX, USBRX); // lire sur le port serie du pc |
arve0 | 0:ea70612a3ee1 | 10 | |
arve0 | 1:02d947b2fdec | 11 | |
arve0 | 1:02d947b2fdec | 12 | int main(){ |
arve0 | 1:02d947b2fdec | 13 | ads.setGain(GAIN_SIXTEEN); // set range to +/-0.256V |
LoloF | 2:00320fd347da | 14 | int reading,reading1,reading2,reading3; |
arve0 | 0:ea70612a3ee1 | 15 | while (1) { |
arve0 | 0:ea70612a3ee1 | 16 | reading = ads.readADC_SingleEnded(0); // read channel 0 |
LoloF | 2:00320fd347da | 17 | pc.printf("Entree0: %d\r\n", reading); // print reading |
LoloF | 2:00320fd347da | 18 | reading2 = ads.readADC_SingleEnded(2); // read channel 2 |
LoloF | 2:00320fd347da | 19 | pc.printf("Entree2: %d\r\n", reading2); // print reading |
LoloF | 2:00320fd347da | 20 | reading1 = ads.readADC_SingleEnded(1); // read channel 1 |
LoloF | 2:00320fd347da | 21 | pc.printf("Entree1: %d\r\n", reading1); // print reading |
LoloF | 2:00320fd347da | 22 | reading3 = ads.readADC_SingleEnded(3); // read channel 3 |
LoloF | 2:00320fd347da | 23 | pc.printf("Entree3: %d\r\n", reading3); // print reading |
arve0 | 0:ea70612a3ee1 | 24 | wait(2); // loop 2 sek |
LoloF | 2:00320fd347da | 25 | //reading = ads.readADC_Differential_2_3(); // differential channel 2-3 |
LoloF | 2:00320fd347da | 26 | // pc.printf("diff a2, a3: %d\r\n", reading); // print diff |
arve0 | 0:ea70612a3ee1 | 27 | } |
arve0 | 0:ea70612a3ee1 | 28 | } |