summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--unologger/config.h27
-rw-r--r--unologger/datalogger.h7
-rw-r--r--unologger/images.h5
-rw-r--r--unologger/unologger.ino100
4 files changed, 52 insertions, 87 deletions
diff --git a/unologger/config.h b/unologger/config.h
index 0662878..76b4dbe 100644
--- a/unologger/config.h
+++ b/unologger/config.h
@@ -7,7 +7,7 @@
// OBD_MODEL_I2C for I2C version
// OBD_MODEL_UART for UART version
#define OBD_MODEL OBD_MODEL_UART
-#define OBD_PROTOCOL 0 /* 0 for auto */
+#define OBD_PROTOCOL PROTO_AUTO
/**************************************
* Data logging options
@@ -19,38 +19,19 @@
/**************************************
* Data streaming options
**************************************/
-// enable(1)/disable(0) data streaming
+// data streaming is not supported on Arduino UNO
#define ENABLE_DATA_OUT 0
-// uses software(1)/hardware(0) serial for data streaming
-#define USE_SOFTSERIAL 0
-
-// this defines the format of data streaming
-// FORMAT_BIN is required by Freematics OBD iOS App
-#define STREAM_FORMAT FORMAT_CSV
-
-/* Default streaming baudrates:
- 9600bps for BLE
- 38400bps for BT 2.1
-*/
-#define STREAM_BAUDRATE 9600
-
-// outputs debug information
-#define VERBOSE 0
-
/**************************************
* Accelerometer & Gyro
**************************************/
-#define USE_MPU6050 1
-#define ACC_DATA_RATIO 160
-#define GYRO_DATA_RATIO 256
+//#define USE_MPU6050 1
+//#define USE_MPU9150 1
/**************************************
* Timeout/interval options
**************************************/
#define OBD_MIN_INTERVAL 20 /* ms */
-#define ACC_DATA_INTERVAL 200 /* ms */
-#define GPS_DATA_TIMEOUT 2000 /* ms */
/**************************************
* LCD module (uncomment only one)
diff --git a/unologger/datalogger.h b/unologger/datalogger.h
index 920af4c..2a58bf3 100644
--- a/unologger/datalogger.h
+++ b/unologger/datalogger.h
@@ -30,6 +30,9 @@ typedef struct {
#define PID_ACC 0x20
#define PID_GYRO 0x21
+#define PID_COMPASS 0x22
+#define PID_MEMS_TEMP 0x23
+#define PID_BATTERY_VOLTAGE 0x24
#define FILE_NAME_FORMAT "/DAT%05d.CSV"
@@ -39,8 +42,6 @@ typedef struct {
#if defined(__AVR_ATmega2560__) || defined(__AVR_ATmega1280__)
SoftwareSerial SerialBLE(A8, A9); /* for BLE Shield on MEGA*/
-#elif defined(__AVR_ATmega644P__)
- SoftwareSerial SerialBLE(9, 10); /* for Microduino */
#else
SoftwareSerial SerialBLE(A2, A3); /* for BLE Shield on UNO/leonardo*/
#endif
@@ -151,7 +152,7 @@ public:
{
uint16_t fileIndex;
char filename[24] = "/FRMATICS";
-
+
dataSize = 0;
if (SD.exists(filename)) {
for (fileIndex = 1; fileIndex; fileIndex++) {
diff --git a/unologger/images.h b/unologger/images.h
deleted file mode 100644
index 0a0f0b6..0000000
--- a/unologger/images.h
+++ /dev/null
@@ -1,5 +0,0 @@
-const PROGMEM uint8_t tick[16 *16 / 8] =
-{0x00,0x80,0xC0,0xE0,0xC0,0x80,0x00,0x80,0xC0,0xE0,0xF0,0xF8,0xFC,0x78,0x30,0x00,0x00,0x01,0x03,0x07,0x0F,0x1F,0x1F,0x1F,0x0F,0x07,0x03,0x01,0x00,0x00,0x00,0x00};
-
-const PROGMEM uint8_t cross[16 *16 / 8] =
-{0x00,0x0C,0x1C,0x3C,0x78,0xF0,0xE0,0xC0,0xE0,0xF0,0x78,0x3C,0x1C,0x0C,0x00,0x00,0x00,0x30,0x38,0x3C,0x1E,0x0F,0x07,0x03,0x07,0x0F,0x1E,0x3C,0x38,0x30,0x00,0x00};
diff --git a/unologger/unologger.ino b/unologger/unologger.ino
index 48f48b9..ba7f0a7 100644
--- a/unologger/unologger.ino
+++ b/unologger/unologger.ino
@@ -10,18 +10,15 @@
#include <SPI.h>
#include <SD.h>
#include <Wire.h>
-#include <MPU6050.h>
+#include <I2Cdev.h>
+#include <MPU9150.h>
#include "MultiLCD.h"
-#include "images.h"
#include "config.h"
-#if USE_SOFTSERIAL
-#include <SoftwareSerial.h>
-#endif
#include "datalogger.h"
#define STATE_SD_READY 0x1
#define STATE_OBD_READY 0x2
-#define STATE_ACC_READY 0x10
+#define STATE_MEMS_READY 0x10
#define STATE_SLEEPING 0x20
#define OBD_MODEL_UART 0
@@ -36,6 +33,10 @@ static uint16_t elapsed = 0;
static uint8_t lastPid = 0;
static int lastValue = 0;
+#if USE_MPU6050 || USE_MPU9150
+MPU6050 accelgyro;
+#endif
+
static byte pidTier1[]= {PID_RPM, PID_SPEED, PID_ENGINE_LOAD, PID_THROTTLE, PID_INTAKE_MAP};
static byte pidTier2[] = {PID_COOLANT_TEMP, PID_INTAKE_TEMP, PID_AMBIENT_TEMP, PID_FUEL_LEVEL, PID_DISTANCE};
@@ -54,12 +55,10 @@ public:
{
showStates();
-#if USE_MPU6050
+#if USE_MPU6050 || USE_MPU9150
Wire.begin();
- if (MPU6050_init() == 0) {
- state |= STATE_ACC_READY;
- showStates();
- }
+ accelgyro.initialize();
+ if (accelgyro.testConnection()) state |= STATE_MEMS_READY;
#endif
do {
@@ -93,9 +92,6 @@ public:
}
#endif
- showECUCap();
- delay(3000);
-
initScreen();
}
void benchmark()
@@ -143,7 +139,7 @@ public:
}
#if USE_MPU6050
- if (state & STATE_ACC_READY) {
+ if (state & STATE_MEMS_READY) {
processAccelerometer();
}
#endif
@@ -191,8 +187,7 @@ public:
lcd.print((int)((volumesize + 511) / 1000));
lcd.print("GB");
} else {
- lcd.print("SD ");
- showTickCross(false);
+ lcd.print("SD: No");
digitalWrite(SD_CS_PIN, HIGH);
return false;
}
@@ -243,13 +238,30 @@ private:
#if USE_MPU6050
void processAccelerometer()
{
- accel_t_gyro_union data;
- MPU6050_readout(&data);
- dataTime = millis();
- // log x/y/z of accelerometer
- logData(PID_ACC, data.value.x_accel, data.value.y_accel, data.value.z_accel);
- // log x/y/z of gyro meter
- logData(PID_GYRO, data.value.x_gyro, data.value.y_gyro, data.value.z_gyro);
+#if USE_MPU6050 || USE_MPU9150
+ int16_t ax, ay, az;
+ int16_t gx, gy, gz;
+#if USE_MPU9150
+ int16_t mx, my, mz;
+#endif
+
+#if USE_MPU9150
+ accelgyro.getMotion9(&ax, &ay, &az, &gx, &gy, &gz, &mx, &my, &mz);
+#else
+ accelgyro.getMotion6(&ax, &ay, &az, &gx, &gy, &gz);
+#endif
+
+ dataTime = millis();
+
+ // log x/y/z of accelerometer
+ logData(PID_ACC, ax, ay, az);
+ // log x/y/z of gyro meter
+ logData(PID_GYRO, gx, gy, gz);
+#if USE_MPU9150
+ // log x/y/z of compass
+ logData(PID_COMPASS, mx, my, mz);
+#endif
+#endif
}
#endif
void logOBDData(byte pid)
@@ -270,24 +282,6 @@ private:
return;
}
}
- void showECUCap()
- {
- lcd.clear();
- lcd.setFontSize(FONT_SIZE_MEDIUM);
- byte pid = 0;
- uint16_t col;
- uint8_t row;
- for (byte i = 0; ; pid++) {
- if (pid % 0x20 == 0) continue;
- col = (i / 15) * 52;
- row = (i % 15) << 1;
- i++;
- if (col > 280) break;
- lcd.setCursor(col, row);
- lcd.print(0x100 | pid, HEX);
- showTickCross(isValidPID(pid));
- }
- }
void reconnect()
{
#if ENABLE_DATA_LOG
@@ -297,12 +291,12 @@ private:
lcd.setFontSize(FONT_SIZE_MEDIUM);
lcd.print("Reconnecting");
startTime = millis();
- state &= ~(STATE_OBD_READY | STATE_ACC_READY);
+ state &= ~(STATE_OBD_READY | STATE_MEMS_READY);
state |= STATE_SLEEPING;
//digitalWrite(SD_CS_PIN, LOW);
for (uint16_t i = 0; ; i++) {
if (i == 5) {
- lcd.backlight(false);
+ lcd.setBackLight(0);
lcd.clear();
}
if (init()) {
@@ -313,26 +307,20 @@ private:
}
state &= ~STATE_SLEEPING;
fileIndex++;
- lcd.backlight(true);
+ lcd.setBackLight(255);
setup();
}
- void showTickCross(bool yes)
- {
- lcd.setColor(yes ? RGB16_GREEN : RGB16_RED);
- lcd.draw(yes ? tick : cross, 16, 16);
- lcd.setColor(RGB16_WHITE);
- }
// screen layout related stuff
void showStates()
{
lcd.setFontSize(FONT_SIZE_MEDIUM);
lcd.setCursor(0, 6);
lcd.print("OBD ");
- showTickCross(state & STATE_OBD_READY);
-#if USE_MPU6050
+ if (state & STATE_OBD_READY) lcd.print("OK");
+#if USE_MPU6050 || USE_MPU9150
lcd.setCursor(0, 8);
- lcd.print("ACC ");
- showTickCross(state & STATE_ACC_READY);
+ lcd.print("MEMS ");
+ if (state & STATE_MEMS_READY) lcd.print("OK");
#endif
}
void showData(byte pid, int value)
@@ -392,7 +380,7 @@ private:
void initLoggerScreen()
{
lcd.clear();
- lcd.backlight(true);
+ lcd.setBackLight(255);
lcd.setFontSize(FONT_SIZE_SMALL);
lcd.setColor(RGB16_CYAN);
lcd.setCursor(4, 0);