-
Notifications
You must be signed in to change notification settings - Fork 4
platypus
- Invensense MPU9250 IMU (3D accelerometer, 3D gyroscope, 3D magnetometer, Temperature)
- Bosch BME280 (Humidity, Temperature, Barometric pressure)
- AMS TSL2584TSV Ambient Visible/IR Light Sensor
- Maxim MAX17043 Battery Gauge
- Sharp LS013B7DH03 128x128 Low-Power Display (Datasheet)
- or the Sharp LS013B4DN04 96x96 display
Note: In order to use the interrupt functionalities of the sensors, you may have to solder connections at the interrupt jumpers (J_IMU, J_BAT, J_ALS).
Note: Since we have changed the platypus board schematics multiple times throughout development, some boards may use a different I2C bus than others. If the sensors on your board don't work, try bus 6 instead of bus 1!
There is a script that automatically tests all attached sensors that might help you to debug particular problems:
setup according to edison/package-control, then
opkg update
opkg install wsnlab
platypus-test
There are already C drivers for the display (LcdDriver), that use a minimal graphics library (grlib). An example program which initializes the display and draws some stuff could look like this (dsptest.c):
Note: If you have the smaller 96px version of the display, use the Sharp96x96.h/.c
driver.
#include "LcdDriver.h"
#include "Sharp128x128.h"
#include "grlib.h"
int main(int argc, const char* argv[]) {
HAL_LCD_initDisplay(); // init display
tContext g_sContext;
Graphics_initContext(&g_sContext, &g_sharp128x128LCD); // init display context
Graphics_setForegroundColor(&g_sContext, ClrWhite); // foreground color (text, drawings, etc.)
Graphics_setBackgroundColor(&g_sContext, ClrBlack); // background color
Graphics_setFont(&g_sContext, &g_sFontFixed6x8); // font (see grlib font folder)
Graphics_clearDisplay(&g_sContext); // clear the display
Graphics_flushBuffer(&g_sContext); // flush the changes (clear at this point)
Graphics_drawLine(&g_sContext,118,11,126,11); // example for a line
Graphics_drawCircle(&g_sContext, 50, 50, 20); // example for a circle
Graphics_drawString(&g_sContext, "hello world", 12, 40, 40, OPAQUE_TEXT); // example for some text
Graphics_flushBuffer(&g_sContext); // flush the changes (draws)
printf("Done\n");
return 0;
}
In a directory structure like this:
- [name]/
- GrLib/
- LcdDriver/
- include/
- lib/
[name].cpp
compile the program with:
g++ -IGrLib/grlib -ILcdDriver -Iinclude -Llib -lmraa -lGrLib -lLcdDriver -lplatypus -o [name] [name].cpp
Make yourself familiar with the IMU datasheet and especially the register map!
Note: Since we have changed the platypus board schematics multiple times throughout development, some boards may use a different I2C bus than others. If the sensors on your board don't work, try bus 6 instead of bus 1!
Some example C code that uses mraa to reset the IMU and read the current accelerometer values:
#include "mraa.h"
int main (int argc, const char* argv[]) {
// init i2c comms
mraa_i2c_context i2c = mraa_i2c_init(1); // i2c bus 1
mraa_i2c_address(i2c, 0x68);
uint8_t rx_tx_buf[2];
// reset
rx_tx_buf[0] = 0x6B; // power management 1
rx_tx_buf[1] = 0x80; // set reset bit
mraa_i2c_write(i2c, rx_tx_buf, 2);
usleep(200000); // wait for reset
// wakeup
rx_tx_buf[0] = 0x6B; // power management 1
rx_tx_buf[1] = 0x00; // unset sleep bit
mraa_i2c_write(i2c, rx_tx_buf, 2);
usleep(200000); // wait for new measurements
// read raw accelerometer values
uint8_t ax_rawH = mraa_i2c_read_byte_data(i2c, 0x3B);
uint8_t ax_rawL = mraa_i2c_read_byte_data(i2c, 0x3C);
uint8_t ay_rawH = mraa_i2c_read_byte_data(i2c, 0x3D);
uint8_t ay_rawL = mraa_i2c_read_byte_data(i2c, 0x3E);
uint8_t az_rawH = mraa_i2c_read_byte_data(i2c, 0x3F);
uint8_t az_rawL = mraa_i2c_read_byte_data(i2c, 0x40);
// convert high and low bytes to signed 16-bit integers
int16_t ax_raw = (int16_t) ((ax_rawH<<8) + ax_rawL);
int16_t ay_raw = (int16_t) ((ay_rawH<<8) + ay_rawL);
int16_t az_raw = (int16_t) ((az_rawH<<8) + az_rawL);
// convert to g
float ax = ax_raw / 16384.0;
float ay = ay_raw / 16384.0;
float az = az_raw / 16384.0;
printf("X: %f\n", ax);
printf("Y: %f\n", ay);
printf("Z: %f\n", az);
return 0;
}
Compile with gcc -lmraa imutest.c -o imutest
.
Code for the other sensors will work very similar to this, just look up the datasheets.