Nucleo-transfer

Dependencies:   ADS1015 MPU6050 PixelArray-Nucleo mbed

Fork of Momo_Pilot_1 by Momo Medical

ADS1115-hello_world/main.cpp

Committer:
DEldering
Date:
2017-08-28
Revision:
0:c0e44c46c573
Child:
1:a8e61f3910ad

File content as of revision 0:c0e44c46c573:

#include "mbed.h"
#include "Adafruit_ADS1015.h"
#include "USBSerial.h"
#include "MPU6050.h"
#define SERIAL_BAUD_RATE    115200

MPU6050 ark(p9,p10);
I2C i2c(p28, p27);
Adafruit_ADS1115 ads0(&i2c, 0x48);
Adafruit_ADS1115 ads1(&i2c, 0x49);
//Adafruit_ADS1115 ads2(&i2c, 0x4A);
Serial pc(USBTX, USBRX); // tx, rx
Ticker sample;
short read[8];
int done;
int j;
int k;
float acce[3];

void read_adc()
{
    for (k = 0; k < 4; k = k + 1) {
    read[k]=    ads0.readADC_SingleEnded(k);
    read[k+4]=  ads1.readADC_SingleEnded(k);
    }
    ark.getAccelero(acce);
    j = acce[0]*10;
    pc.printf(",%d,%d,%d,%d,%d,%d,%d,%d,%d,\r\n", read[1], read[0], read[4], read[7], read[5], read[6], read[2], read[3],j); // print 'read' array to serial port
    //pi.printf(",%d,%d,%d,%d,%d,%d,%d,%d,\r\n", read[1], read[0], read[4], read[7], read[5], read[6], read[2], read[3]); // print 'read' array to serial port
}

int main()
{
    i2c.frequency(400000);
    pc.baud(115200);
    //pi.baud(115200);
    ads0.setGain(GAIN_ONE); // set range to +/-4.096V
    ads1.setGain(GAIN_ONE); // set range to +/-4.096V
    sample.attach_us(&read_adc, 100000);
    while (1) {
        wait_ms(101); // wait indefinitely because the ticker restarts every 50 ms
    }
}