Tisham Dhar / Hexi_GPSIMU_Hotshoe

Use hexiwear as a GPSIMU-AHRS for Nikon DSLR cameras

Dependencies:   FXOS8700CQ FXAS21000 MBed_Adafruit-GPS-Library Hexi_OLED_SSD1351 Hexi_KW40Z Madgwick

Fork of Hexi_Blinky_Example by Hexiwear

/media/uploads/whatnick/hexiwear_docking_station_numbers.jpg

Committer:
whatnick
Date:
Wed Mar 08 02:44:15 2017 +0000
Revision:
27:8c84611a4ca5
Parent:
25:6e43bbe76aec
Updated standard OLED and FXOS

Who changed what in which revision?

UserRevisionLine numberNew contents of line
dan0:7dec7e9ac085 1#include "mbed.h"
whatnick26:e35dd673fd13 2#include "FXOS8700CQ.h"
whatnick15:b5a3e22d706b 3#include "FXAS21000.h"
whatnick15:b5a3e22d706b 4#include "MBed_Adafruit_GPS.h"
whatnick21:b165e847c5ba 5#include "Hexi_OLED_SSD1351.h"
whatnick26:e35dd673fd13 6#include "MadgwickAHRS.h"
whatnick23:f170a1d72a84 7#include "images.h"
whatnick24:cbdf0f7d33bd 8
whatnick23:f170a1d72a84 9#include "rtos.h"
dan0:7dec7e9ac085 10
whatnick24:cbdf0f7d33bd 11
whatnick16:2e42284011d9 12DigitalOut myled(LED1);
whatnick16:2e42284011d9 13
whatnick14:9885c8536437 14Serial gps(PTD3,PTD2);
whatnick25:6e43bbe76aec 15Serial camera(PTC17,PTC16);
whatnick25:6e43bbe76aec 16
whatnick23:f170a1d72a84 17Adafruit_GPS myGPS(&gps);
whatnick23:f170a1d72a84 18char c; //when read via Adafruit_GPS::read(), the class returns single character stored here
whatnick22:e69bc54ca4c0 19
whatnick23:f170a1d72a84 20#define DEBUG
whatnick22:e69bc54ca4c0 21
whatnick22:e69bc54ca4c0 22#ifdef DEBUG
whatnick14:9885c8536437 23Serial pc(USBTX, USBRX);
whatnick22:e69bc54ca4c0 24#define LOG(args...) pc.printf(args)
whatnick22:e69bc54ca4c0 25#else
whatnick22:e69bc54ca4c0 26#define LOG(args...)
whatnick22:e69bc54ca4c0 27#endif
whatnick14:9885c8536437 28
whatnick21:b165e847c5ba 29/* Instantiate the SSD1351 OLED Driver */
whatnick21:b165e847c5ba 30SSD1351 oled(PTB22,PTB21,PTC13,PTB20,PTE6, PTD15); /* (MOSI,SCLK,POWER,CS,RST,DC) */
whatnick16:2e42284011d9 31
whatnick16:2e42284011d9 32//#define BLACK 0x000000
whatnick16:2e42284011d9 33//#define WHITE 0xFFFFFF
whatnick16:2e42284011d9 34#define GREEN 0x00FF00
whatnick16:2e42284011d9 35#define RED 0xFF0000
whatnick16:2e42284011d9 36#define BLUE 0x0000FF
whatnick15:b5a3e22d706b 37
whatnick26:e35dd673fd13 38FXOS8700CQ combo( PTC11, PTC10); // Proper Ports and I2C Address for Hexiwear
dan0:7dec7e9ac085 39
whatnick15:b5a3e22d706b 40FXAS21000 gyro( PTC11, PTC10); // Proper Ports for Hexiwear
whatnick15:b5a3e22d706b 41
whatnick26:e35dd673fd13 42Data combo_data;
whatnick23:f170a1d72a84 43float gyro_data[3];
whatnick23:f170a1d72a84 44
whatnick21:b165e847c5ba 45Timer t;
whatnick15:b5a3e22d706b 46
whatnick25:6e43bbe76aec 47//Worker threads
whatnick25:6e43bbe76aec 48Thread gps_t,imu_t;
whatnick25:6e43bbe76aec 49
whatnick25:6e43bbe76aec 50
whatnick25:6e43bbe76aec 51//GPS Reader worker task
whatnick25:6e43bbe76aec 52void gps_thread(void)
whatnick23:f170a1d72a84 53{
whatnick23:f170a1d72a84 54 while (true) {
whatnick23:f170a1d72a84 55 c = myGPS.read(); //queries the GPS
whatnick24:cbdf0f7d33bd 56
whatnick23:f170a1d72a84 57 //check if we recieved a new message from GPS, if so, attempt to parse it,
whatnick23:f170a1d72a84 58 if ( myGPS.newNMEAreceived() ) {
whatnick23:f170a1d72a84 59 if ( !myGPS.parse(myGPS.lastNMEA()) ) {
whatnick24:cbdf0f7d33bd 60 LOG(myGPS.lastNMEA());
whatnick23:f170a1d72a84 61 continue;
whatnick23:f170a1d72a84 62 }
whatnick23:f170a1d72a84 63 }
whatnick23:f170a1d72a84 64 Thread::wait(1);
whatnick23:f170a1d72a84 65 }
whatnick23:f170a1d72a84 66}
whatnick23:f170a1d72a84 67
whatnick25:6e43bbe76aec 68//IMU reader and sensor fusion worker task
whatnick25:6e43bbe76aec 69void imu_thread(void)
whatnick23:f170a1d72a84 70{
whatnick23:f170a1d72a84 71 while(true) {
whatnick23:f170a1d72a84 72 gyro.ReadXYZ(gyro_data);
whatnick26:e35dd673fd13 73 combo_data = combo.get_values();
whatnick25:6e43bbe76aec 74 Thread::wait(10);
whatnick23:f170a1d72a84 75 }
whatnick23:f170a1d72a84 76}
whatnick23:f170a1d72a84 77
whatnick21:b165e847c5ba 78int main()
whatnick21:b165e847c5ba 79{
whatnick22:e69bc54ca4c0 80 char text[30]; /* Text Buffer */
whatnick21:b165e847c5ba 81
whatnick21:b165e847c5ba 82//Start timer
whatnick21:b165e847c5ba 83 t.start();
whatnick21:b165e847c5ba 84
whatnick21:b165e847c5ba 85 myGPS.begin(9600);
whatnick15:b5a3e22d706b 86//Turn off all sentences except GGA and RMC
whatnick15:b5a3e22d706b 87//For MTK GPS
whatnick21:b165e847c5ba 88 myGPS.sendCommand(PMTK_SET_NMEA_OUTPUT_RMCGGA);
whatnick15:b5a3e22d706b 89
whatnick15:b5a3e22d706b 90//FOR UBLOX GPS
whatnick21:b165e847c5ba 91 myGPS.sendCommand(UBX_DISABLE_ZDA);
whatnick21:b165e847c5ba 92 myGPS.sendCommand(UBX_DISABLE_GLL);
whatnick21:b165e847c5ba 93 myGPS.sendCommand(UBX_DISABLE_VTG);
whatnick21:b165e847c5ba 94 myGPS.sendCommand(UBX_DISABLE_GSV);
whatnick21:b165e847c5ba 95 myGPS.sendCommand(UBX_DISABLE_GSA);
whatnick15:b5a3e22d706b 96
whatnick15:b5a3e22d706b 97
whatnick22:e69bc54ca4c0 98#ifdef DEBUG
whatnick21:b165e847c5ba 99 pc.baud(115200);
whatnick22:e69bc54ca4c0 100#endif
whatnick15:b5a3e22d706b 101
whatnick25:6e43bbe76aec 102//Connect to Nikon D800 UART at 4800baud
whatnick25:6e43bbe76aec 103 camera.baud(4800);
whatnick25:6e43bbe76aec 104
whatnick26:e35dd673fd13 105//Initialise gyro
whatnick26:e35dd673fd13 106 char whoami = gyro.getWhoAmI();
whatnick26:e35dd673fd13 107//Initialise combo (acc&mag)
whatnick26:e35dd673fd13 108 combo.init();
whatnick15:b5a3e22d706b 109
whatnick21:b165e847c5ba 110 /* Get OLED Class Default Text Properties */
whatnick21:b165e847c5ba 111 oled_text_properties_t textProperties = {0};
whatnick21:b165e847c5ba 112 oled.GetTextProperties(&textProperties);
whatnick16:2e42284011d9 113
whatnick21:b165e847c5ba 114 /* Turn on the backlight of the OLED Display */
whatnick21:b165e847c5ba 115 oled.DimScreenON();
whatnick20:5a4e47822d79 116
whatnick21:b165e847c5ba 117 /* Fills the screen with solid black */
whatnick21:b165e847c5ba 118 oled.FillScreen(COLOR_BLACK);
whatnick16:2e42284011d9 119
whatnick23:f170a1d72a84 120 /* Adding full screen splash */
whatnick23:f170a1d72a84 121 const uint8_t *image = NXP_whole_bmp;
whatnick23:f170a1d72a84 122 /* Draws the image on the Screen starting at (x=0,y=0) */
whatnick23:f170a1d72a84 123 oled.DrawImage(image,0,0);
whatnick23:f170a1d72a84 124
whatnick23:f170a1d72a84 125 Thread::wait(1000);
whatnick23:f170a1d72a84 126
whatnick23:f170a1d72a84 127 /* Fills the screen with solid black */
whatnick23:f170a1d72a84 128 oled.FillScreen(COLOR_BLACK);
whatnick23:f170a1d72a84 129
whatnick21:b165e847c5ba 130 /* Display Text at (x=7,y=0) */
whatnick21:b165e847c5ba 131 strcpy((char *) text,"AERO GPS-AHRS");
whatnick21:b165e847c5ba 132 oled.Label((uint8_t *)text,7,0);
whatnick16:2e42284011d9 133
whatnick21:b165e847c5ba 134 /* Change font color to blue */
whatnick21:b165e847c5ba 135 textProperties.fontColor = COLOR_BLUE;
whatnick21:b165e847c5ba 136 oled.SetTextProperties(&textProperties);
whatnick22:e69bc54ca4c0 137
whatnick22:e69bc54ca4c0 138
whatnick22:e69bc54ca4c0 139 /* Display text at (x=1,y=15) MAG label*/
whatnick21:b165e847c5ba 140 strcpy(text,"M:");
whatnick22:e69bc54ca4c0 141 oled.Label((uint8_t *)text,1,15);
whatnick22:e69bc54ca4c0 142
whatnick22:e69bc54ca4c0 143 /* Display text at (x=1,y=30) ACC label*/
whatnick21:b165e847c5ba 144 strcpy(text,"A:");
whatnick22:e69bc54ca4c0 145 oled.Label((uint8_t *)text,1,30);
whatnick22:e69bc54ca4c0 146
whatnick22:e69bc54ca4c0 147 /* Display text at (x=1,y=45) GYRO label*/
whatnick21:b165e847c5ba 148 strcpy(text,"G:");
whatnick22:e69bc54ca4c0 149 oled.Label((uint8_t *)text,1,45);
whatnick21:b165e847c5ba 150
whatnick22:e69bc54ca4c0 151 /* Display text at (x=1,y=60) Time label*/
whatnick21:b165e847c5ba 152 strcpy(text,"Timer(s):");
whatnick22:e69bc54ca4c0 153 oled.Label((uint8_t *)text,1,60);
whatnick22:e69bc54ca4c0 154
whatnick22:e69bc54ca4c0 155 /* Display text at (x=1,y=75) Position label*/
whatnick21:b165e847c5ba 156 strcpy(text,"P:");
whatnick22:e69bc54ca4c0 157 oled.Label((uint8_t *)text,1,75);
whatnick21:b165e847c5ba 158
whatnick21:b165e847c5ba 159 /* Set text properties to white and right aligned for the dynamic text */
whatnick21:b165e847c5ba 160 textProperties.fontColor = COLOR_WHITE;
whatnick21:b165e847c5ba 161 textProperties.alignParam = OLED_TEXT_ALIGN_RIGHT;
whatnick21:b165e847c5ba 162 oled.SetTextProperties(&textProperties);
whatnick21:b165e847c5ba 163
whatnick24:cbdf0f7d33bd 164 //Start read and update threads
whatnick25:6e43bbe76aec 165 gps_t.start(gps_thread);
whatnick25:6e43bbe76aec 166 imu_t.start(imu_thread);
whatnick15:b5a3e22d706b 167
whatnick23:f170a1d72a84 168 while (true) {
whatnick23:f170a1d72a84 169 /* Format the GYRO reading */
whatnick23:f170a1d72a84 170 sprintf(text,"%.2f %.2f %.2f",gyro_data[0],gyro_data[1],gyro_data[2]);
whatnick23:f170a1d72a84 171 /* Display gyro to 2 decimal */
whatnick23:f170a1d72a84 172 oled.TextBox((uint8_t *)text,15,45,80,15); /*Expand textbox for more digits*/
whatnick23:f170a1d72a84 173
whatnick23:f170a1d72a84 174
whatnick23:f170a1d72a84 175 /* Format the time reading */
whatnick23:f170a1d72a84 176 sprintf(text,"%.2f",t.read());
whatnick23:f170a1d72a84 177
whatnick23:f170a1d72a84 178 /* Display time reading */
whatnick23:f170a1d72a84 179 oled.TextBox((uint8_t *)text,55,60,35,15); /*Expand textbox for more digits*/
whatnick23:f170a1d72a84 180
whatnick23:f170a1d72a84 181 if(myGPS.fix) {
whatnick23:f170a1d72a84 182 LOG(myGPS.lastNMEA());
whatnick23:f170a1d72a84 183 sprintf(text,"%.2f%c %.2f%c",myGPS.longitude/100.0f,myGPS.lat,myGPS.latitude/100.0f,myGPS.lon);
whatnick23:f170a1d72a84 184 } else {
whatnick23:f170a1d72a84 185 sprintf(text,"No GPS");
whatnick15:b5a3e22d706b 186 }
whatnick21:b165e847c5ba 187
whatnick23:f170a1d72a84 188 /* Display GPS location or lock status */
whatnick23:f170a1d72a84 189 oled.TextBox((uint8_t *)text,15,75,80,15); /*Expand textbox for more digits*/
whatnick23:f170a1d72a84 190 Thread::wait(1000);
stevep4:81cea7a352b0 191 }
dan0:7dec7e9ac085 192}