mDot with ADS1115

Fork of mbed-os-example-mbed5-blinky by mbed-os-examples

Files at this revision

API Documentation at this revision

Comitter:
jortronm
Date:
Mon Jul 31 13:37:07 2017 +0000
Parent:
39:bcfaadc319d3
Commit message:
mDot connected to a ADS1115

Changed in this revision

ADS1015.lib Show annotated file Show diff for this revision Revisions of this file
README.md Show diff for this revision Revisions of this file
img/uvision.png Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/ADS1015.lib	Mon Jul 31 13:37:07 2017 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/arve0/code/ADS1015/#aa277517f0ad
--- a/README.md	Thu Jun 22 09:00:02 2017 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,87 +0,0 @@
-# Getting started with Blinky on mbed OS
-
-This guide reviews the steps required to get Blinky working on an mbed OS platform.
-
-Please install [mbed CLI](https://github.com/ARMmbed/mbed-cli#installing-mbed-cli).
-
-## Import the example application
-
-From the command-line, import the example:
-
-```
-mbed import mbed-os-example-blinky
-cd mbed-os-example-blinky
-```
-
-### Now compile
-
-Invoke `mbed compile`, and specify the name of your platform and your favorite toolchain (`GCC_ARM`, `ARM`, `IAR`). For example, for the ARM Compiler 5:
-
-```
-mbed compile -m K64F -t ARM
-```
-
-Your PC may take a few minutes to compile your code. At the end, you see the following result:
-
-```
-[snip]
-+----------------------------+-------+-------+------+
-| Module                     | .text | .data | .bss |
-+----------------------------+-------+-------+------+
-| Misc                       | 13939 |    24 | 1372 |
-| core/hal                   | 16993 |    96 |  296 |
-| core/rtos                  |  7384 |    92 | 4204 |
-| features/FEATURE_IPV4      |    80 |     0 |  176 |
-| frameworks/greentea-client |  1830 |    60 |   44 |
-| frameworks/utest           |  2392 |   512 |  292 |
-| Subtotals                  | 42618 |   784 | 6384 |
-+----------------------------+-------+-------+------+
-Allocated Heap: unknown
-Allocated Stack: unknown
-Total Static RAM memory (data + bss): 7168 bytes
-Total RAM memory (data + bss + heap + stack): 7168 bytes
-Total Flash memory (text + data + misc): 43402 bytes
-Image: .\.build\K64F\ARM\mbed-os-example-blinky.bin
-```
-
-### Program your board
-
-1. Connect your mbed device to the computer over USB.
-1. Copy the binary file to the mbed device.
-1. Press the reset button to start the program.
-
-The LED on your platform turns on and off.
-
-## Export the project to Keil MDK, and debug your application
-
-From the command-line, run the following command:
-
-```
-mbed export -m K64F -i uvision
-```
-
-To debug the application:
-
-1. Start uVision.
-1. Import the uVision project generated earlier.
-1. Compile your application, and generate an `.axf` file.
-1. Make sure uVision is configured to debug over CMSIS-DAP (From the Project menu > Options for Target '...' > Debug tab > Use CMSIS-DAP Debugger).
-1. Set breakpoints, and start a debug session.
-
-![Image of uVision](img/uvision.png)
-
-## Troubleshooting
-
-1. Make sure `mbed-cli` is working correctly and its version is `>1.0.0`
-
- ```
- mbed --version
- ```
-
- If not, you can update it:
-
- ```
- pip install mbed-cli --upgrade
- ```
-
-2. If using Keil MDK, make sure you have a license installed. [MDK-Lite](http://www.keil.com/arm/mdk.asp) has a 32 KB restriction on code size.
\ No newline at end of file
Binary file img/uvision.png has changed
--- a/main.cpp	Thu Jun 22 09:00:02 2017 +0100
+++ b/main.cpp	Mon Jul 31 13:37:07 2017 +0000
@@ -1,12 +1,131 @@
-#include "mbed.h"
-
-DigitalOut led1(LED1);
-
-// main() runs in its own thread in the OS
-int main() {
-    while (true) {
-        led1 = !led1;
-        wait(0.5);
-    }
-}
-
+#include "mbed.h"
+#include "Adafruit_ADS1015.h"
+
+//Pin definition
+DigitalOut led1(PA_0); //External Red LED
+DigitalOut led2(PB_1); //Second LED (Green)
+DigitalOut reset(PA_7); //Pin to reset the ESP
+DigitalIn User_Button(PC_13); //User button
+DigitalOut Wire1(PA_4); //Sensor wire 1
+DigitalOut Wire2(PA_1); //Sensor wire 2
+DigitalOut Wire3(PC_1); //Sensor wire 3
+DigitalIn Sensor_Switch(PA_11); //Pin to switch the peripherals on/off
+DigitalOut SPI_cs(PB_0); // SPI chip select pin
+#define D_SDA PC_9 //I2C SDA pin
+#define D_SCL PA_8 //I2C SCL pin
+#define Serial2_tx PA_2 //Serial2 tx pin
+#define Serial2_rx PA_3 //Serial2 rx pin
+
+
+
+//Interfaces definition
+int BaudRate =115200;
+Serial pc(USBTX, USBRX,BaudRate); //tx, rx : PA_9,PA_10 : pc Serial
+Serial Serial2 (Serial2_tx,Serial2_rx,BaudRate); //tx, rx : Serial2 Serial
+I2C i2c(D_SDA, D_SCL);  //I2C interface, pins define in "Pin definition"
+SPI spi(NC, PA_6, PA_5); //PI interface : mosi, miso, sclk
+Adafruit_ADS1115 ads(&i2c);//ADS1115 library though I2C
+
+//Function definition
+void ADSReadinmg();
+void SerialPrintData();
+
+//Global variable definition
+int Reading_Number=0;
+int data[12]= {0,3,0,0,0,0,0,0,0,0,0,32}; //Reading_Number, V_bat, Wire1_1, Wire1_2, Wire1_3, Wire2_1, Wire2_2, Wire2_3, Wire3_1, Wire3_2, Wire3_3, Temp
+
+
+int main()
+{
+    wait(3);
+    ads.setGain(GAIN_SIXTEEN); // set range to +/-0.256V
+    pc.printf("\r\n"); //New carage return + new line
+    pc.printf("App Started \r\n"); //New carage return + new line
+    SerialPrintData();
+    while (1) {
+        Reading_Number++;
+        data[0]=Reading_Number;
+        ADSReadinmg();
+        SerialPrintData();
+        led1 = !led1;
+        wait(1);
+    }
+}
+
+
+void ADSReadinmg()
+{
+    Wire1=0;
+    Wire2=0;
+    Wire3=0;
+    wait(1);
+
+    Wire1=1;
+    wait(1);
+    for(int i=1; i<4; i++) {
+        pc.printf("Wire1_X: %d\r\n",ads.readADC_SingleEnded(i)); //Wire 1
+        data[i+1]=ads.readADC_SingleEnded(i);
+        wait(1);
+    }
+    Wire1=0;
+    wait(1);
+
+    Wire2=1;
+    wait(1);
+    for(int i=1; i<4; i++) {
+        pc.printf("Wire2_?: %d\r\n",ads.readADC_SingleEnded(i)); //Wire 1
+        data[i+4]=ads.readADC_SingleEnded(i);
+        wait(1);
+    }
+    Wire2=0;
+    wait(1);
+
+    Wire3=1;
+    wait(1);
+    for(int i=1; i<4; i++) {
+        pc.printf("Wire3_?: %d\r\n",ads.readADC_SingleEnded(i)); //Wire 1
+        data[i+7]=ads.readADC_SingleEnded(i);
+        wait(1);
+    }
+
+    pc.printf("\r\n"); //Wire 1
+    Wire3=0;
+    wait(1);
+
+
+    /*
+      for(int i=0; i<4; i++) {
+          data[i+1]=ads.readADC_SingleEnded(i);
+      }
+    */
+}
+
+
+void SerialPrintData()
+{
+    pc.printf("\r\n"); //New carage return + new line
+    pc.printf("Reading #: %d\r\n",data[0]); //Reading #
+    pc.printf("V_Bar: %d\r\n",data[1]); //Baterry voltage
+
+    pc.printf("Wire1_1: %d\r\n",data[2]); //Wire 1
+    pc.printf("Wire1_2: %d\r\n",data[3]); //Wire2
+    pc.printf("Wire1_3: %d\r\n",data[4]); //Wire3
+
+    pc.printf("Wire2_1: %d\r\n",data[5]); //Wire 1
+    pc.printf("Wire2_2: %d\r\n",data[6]); //Wire2
+    pc.printf("Wire2_3: %d\r\n",data[7]); //Wire3
+
+    pc.printf("Wire3_1: %d\r\n",data[8]); //Wire 1
+    pc.printf("Wire3_2: %d\r\n",data[9]); //Wire2
+    pc.printf("Wire3_3: %d\r\n",data[10]); //Wire3
+
+    pc.printf("Temp: %d\r\n",data[11]); //Temperature
+    pc.printf("\r\n"); //New carage return + new line
+
+    /*
+        int DataElements=sizeof(data)/sizeof(data[0]);
+        for(int i=0; i<DataElements; i++) {
+            pc.printf("Ch%d: %d\r\n",i,data[i+1]);
+        }
+    */
+}
\ No newline at end of file