A quick and dirty demo of the Xadow M0 acceleromoeter values displayed on the Xadow OLED 0.96" (using the SSD1308 128x64 OLED Driver with I2C interface library).
Dependencies: mbed SSD1308_128x64_I2C_opt XadowGPS BMP180 ADXL345_I2C MPU9250 USBDevice
main.cpp
- Committer:
- ruevs
- Date:
- 2016-01-05
- Revision:
- 2:7abdbccdf0c8
- Parent:
- 0:b017c907d53d
- Child:
- 5:50051611b5bd
File content as of revision 2:7abdbccdf0c8:
#define __STDC_LIMIT_MACROS 1 #include <stdint.h> #include "ADXL345_I2C.h" #include "SSD1308.h" //#define DEBUG #ifdef DEBUG #include "USBSerial.h" // To use USB virtual serial, a driver is needed, check http://mbed.org/handbook/USBSerial #define LOG(args...) pc.printf(args) USBSerial pc; #else #define LOG(args...) #endif #define MAX_ACC_AXIS 3 ADXL345_I2C accelerometer(P0_5, P0_4); // Xhadow - OLED 128x64 is connected with I2C I2C i2c(P0_5, P0_4); // SDA, SCL SSD1308 oled = SSD1308(i2c, SSD1308_SA0); AnalogIn AD00(P0_11); AnalogIn AD01(P0_12); AnalogIn ChargerStatus(P0_13); // ADC input from VCC through a 200K/200K divider with extara 100K pull down on !DONE and 49.9K on !CHRG DigitalOut blue_led(P0_20, 0); DigitalOut white_led(P0_23, 1); DigitalOut Bus3V3En(P0_14, 1); // Pin that controls the BUS-3V3 (3.3V) regulator output to the Xadow Bus InterruptIn test_int(P0_7); void test_pin_int(void) { white_led = !white_led; Bus3V3En = !Bus3V3En; } int main() { int readings[MAX_ACC_AXIS] = {0, 0, 0}; int MAXreadings[MAX_ACC_AXIS] = {INT16_MIN, INT16_MIN, INT16_MIN}; int MINreadings[MAX_ACC_AXIS] = {INT16_MAX, INT16_MAX, INT16_MAX}; char display_buf[17]; test_int.rise(test_pin_int); LOG("Starting ADXL345 test...\n"); LOG("Device ID is: 0x%02x\n", accelerometer.getDeviceID()); oled.writeString(0, 0, "Accelerometer:"); oled.writeString(1, 0, " Curr Min Max"); //Go into standby mode to configure the device. accelerometer.setPowerControl(0x00); //Full resolution, +/-16g, 4mg/LSB. accelerometer.setDataFormatControl(0x0B); //3.2kHz data rate. accelerometer.setDataRate(ADXL345_3200HZ); //Measurement mode. accelerometer.setPowerControl(0x08); while (1) { accelerometer.getOutput(readings); for (int i=0; i<MAX_ACC_AXIS; ++i) { if ((int16_t)readings[i] > (int16_t)MAXreadings[i]) { MAXreadings[i] = readings[i]; } if ((int16_t)readings[i] < (int16_t)MINreadings[i]) { MINreadings[i] = readings[i]; } snprintf(display_buf, sizeof(display_buf), "%c%5i%5i%5i", 'X'+i, (int16_t)readings[i], (int16_t)MINreadings[i], (int16_t)MAXreadings[i] ); oled.writeString(2+i, 0, display_buf); LOG("%c:%i|%i|%i\r\n", 'X'+i, (int16_t)readings[i], (int16_t)MINreadings[i], (int16_t)MAXreadings[i] ); } /* snprintf(display_buf, sizeof(display_buf), "Ch: %u", ChargerStatus.read_u16()); oled.writeString(2+MAX_ACC_AXIS, 0, display_buf); snprintf(display_buf, sizeof(display_buf), "Ch: %f", 3.3*(float)ChargerStatus.read_u16()/UINT16_MAX); oled.writeString(2+MAX_ACC_AXIS+1, 0, display_buf); */ snprintf(display_buf, sizeof(display_buf), "Bat:%.2fV", 3.3*ChargerStatus); oled.writeString(2+MAX_ACC_AXIS+2, 0, display_buf); LOG("Ch: %f\r\n", ChargerStatus.read()); LOG("Chu: %u\r\n", ChargerStatus.read_u16()); LOG("A0: %f\r\n", (float)AD00.read()); LOG("A1: %f\r\n", AD01.read()); blue_led = !blue_led; // white_led = !white_led; // toggled by pin P0_7 interrupt // deepsleep(); // Deep sleep until external interrupt // The wakeup pin on Xadow is on the sme buton at RESET - no good. wait(1); } }