Test with EzSbc2 LPC1347 board and Adafruit 0,96" display, connected to i2c
Dependencies: Adafruit_GFX I2CDevLib MPU9150 SmallGUI USBDevice WeeESP8266 mbed nRF24L01P
Diff: main.txt
- Revision:
- 2:2eb3f38f9141
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.txt Mon Apr 24 16:24:46 2017 +0000 @@ -0,0 +1,183 @@ +#include "mbed.h" +#include "Adafruit_SSD1306.h" +#include "MPU9150.h" +#include "USBSerial.h" +#include "Controls.h" +#include "ArduinoAPI.h" +#include "ESP8266.h" + + +//#define USE_USBSERIAL + +// modified für EzSBC2 + +DigitalOut ledRed(P1_16); +DigitalOut ledGreen(P1_15); + +float sum = 0; +uint32_t sumCount = 0; +char buffer[14]; + +Timer t; +#ifdef USE_USBSERIAL +USBSerial pc; +#endif + +// an SPI sub-class that provides a constructed default +class SPI2 : public SPI +{ +public: + SPI2(PinName mosi, PinName miso, PinName clk) : SPI(mosi,miso,clk) { + format(8,3); + frequency(2000000); + }; +}; + +// an I2C sub-class that provides a constructed default +class I2C2 : public I2C +{ +public: + I2C2(PinName sda, PinName scl) : I2C(sda, scl) { + frequency(400000); + start(); + }; +}; + + +I2C2 gI2C(P0_5, P0_4); +Adafruit_SSD1306_I2c gOled2(gI2C, NC, 0x78, 64, 128); +I2Cdev i2Cdev; +MPU9150 mpu(i2Cdev); + +ArduinoSerial esp_uart(P1_13, P1_14); +ESP8266 wifi(esp_uart, 115200); + +int main() +{ + uint16_t x=0; + + //while(1) + { + ledRed = 1; + ledGreen = 0; + wait(0.5); + + ledRed = 0; + ledGreen = 1; + wait(0.5); + } + + int16_t y = 12; + int16_t ySize = 4; + int16_t yGap = 2; + + Canvas canvasBG(gOled2); + barGraph bgAx(barGraph::bgHorizontal, 0, y, 127, y+ySize); + canvasBG.addControl(bgAx); + bgAx.setScale(-16383.0f, 16384.0f); + y = y + ySize + yGap; + + barGraph bgAy(barGraph::bgHorizontal, 0, y, 127, y+ySize); + canvasBG.addControl(bgAy); + bgAy.setScale(-16383.0f, 16384.0f); + y = y + ySize + yGap; + + barGraph bgAz(barGraph::bgHorizontal, 0, y, 127, y+ySize); + canvasBG.addControl(bgAz); + bgAz.setScale(-16383.0f, 16384.0f); + y = y + ySize + yGap; + + barGraph bgGx(barGraph::bgHorizontal, 0, y, 127, y+ySize); + canvasBG.addControl(bgGx); + bgGx.setScale(-16383.0f, 16384.0f); + y = y + ySize + yGap; + + barGraph bgGy(barGraph::bgHorizontal, 0, y, 127, y+ySize); + canvasBG.addControl(bgGy); + bgGy.setScale(-16383.0f, 16384.0f); + y = y + ySize + yGap; + + barGraph bgGz(barGraph::bgHorizontal, 0, y, 127, y+ySize); + canvasBG.addControl(bgGz); + bgGz.setScale(-16383.0f, 16384.0f); + + gOled2.clearDisplay(); + gOled2.display(); + + //gOled2.setTextCursor(1, 0); + gOled2.printf("%ux%u OLED Display\r\n", gOled2.width(), gOled2.height()); + +#ifdef USE_USBSERIAL + pc.printf("MPU6050 test\n\n"); + pc.printf("MPU6050 initialize \n"); +#endif + + int16_t ax, ay, az; + int16_t gx, gy, gz; + + mpu.initialize(); + +#ifdef USE_USBSERIAL + pc.printf("MPU6050 testConnection \n"); +#endif + + bool mpu6050TestResult = mpu.testConnection(); + +#ifdef USE_USBSERIAL + if(mpu6050TestResult) { + pc.printf("MPU6050 test passed \n"); + } else { + pc.printf("MPU6050 test failed \n"); + } +#endif + + bool wifiOk = false; + // wifi connect + { + wifiOk = wifi.setOprToStationSoftAP(); + + if (wifiOk) + wifiOk = wifi.joinAP("JojosWLan2", "1883057324535716"); + + if (wifiOk) + wifiOk = wifi.disableMUX(); + //wifiOk = wifi.enableMUX(); + + if (wifiOk) + wifiOk = wifi.registerUDP("192.168.100.74", 8090); + + } + + char buffer[32]; + while(1) { + ledRed = !ledRed; + gOled2.clearDisplay(); + + mpu.getMotion6(&ax, &ay, &az, &gx, &gy, &gz); + //writing current accelerometer and gyro position + //pc.printf("%d;%d;%d;%d;%d;%d\n",ax,ay,az,gx,gy,gz); + + if (wifiOk) { + sprintf(buffer, "%i %i %i", ax, ay, az); + wifi.send((const uint8_t*)buffer, strlen(buffer)); + } + + gOled2.setTextCursor(0, 0); + gOled2.printf("wifi ok: %u\r", wifiOk); + + bgAx.setValue(ax); + bgAy.setValue(ay); + bgAz.setValue(az); + + bgGx.setValue(gx); + bgGy.setValue(gy); + bgGz.setValue(gz); + + canvasBG.draw(); + + gOled2.display(); + + x++; + //wait(0.1); + } +}