voor Arne
Dependencies: ESP8266Interface FXAS21002 FXOS8700 Hexi_OLED_SSD1351
Fork of Hexi_Magneto-v2_Example by
main.cpp@2:3c1fe1657db9, 2016-12-05 (annotated)
- Committer:
- blownelco
- Date:
- Mon Dec 05 15:36:53 2016 +0000
- Revision:
- 2:3c1fe1657db9
- Parent:
- 1:31908216b9ac
- Child:
- 3:e259f976e1fc
wifi ok
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
GregC | 0:3fcdc27ab845 | 1 | #include "mbed.h" |
GregC | 0:3fcdc27ab845 | 2 | #include "FXOS8700.h" |
GregC | 0:3fcdc27ab845 | 3 | #include "Hexi_OLED_SSD1351.h" |
GregC | 0:3fcdc27ab845 | 4 | #include "images.h" |
GregC | 0:3fcdc27ab845 | 5 | #include "string.h" |
blownelco | 2:3c1fe1657db9 | 6 | #include "ESP8266Interface.h" |
GregC | 0:3fcdc27ab845 | 7 | |
GregC | 0:3fcdc27ab845 | 8 | // Pin connections |
GregC | 0:3fcdc27ab845 | 9 | DigitalOut led1(LED_GREEN); // RGB LED |
blownelco | 2:3c1fe1657db9 | 10 | DigitalOut led2(PTA12); // RGB LED |
blownelco | 2:3c1fe1657db9 | 11 | |
blownelco | 2:3c1fe1657db9 | 12 | |
blownelco | 1:31908216b9ac | 13 | DigitalOut PWD(PTB2); |
blownelco | 1:31908216b9ac | 14 | DigitalOut G15(PTB11); |
blownelco | 1:31908216b9ac | 15 | |
blownelco | 1:31908216b9ac | 16 | |
blownelco | 1:31908216b9ac | 17 | |
blownelco | 2:3c1fe1657db9 | 18 | //Serial pc(USBTX, USBRX); // Serial interface |
blownelco | 2:3c1fe1657db9 | 19 | //RawSerial wifi(PTD3, PTD2); |
GregC | 0:3fcdc27ab845 | 20 | FXOS8700 mag(PTC11, PTC10); |
GregC | 0:3fcdc27ab845 | 21 | SSD1351 oled(PTB22,PTB21,PTC13,PTB20,PTE6, PTD15); // SSD1351 OLED Driver (MOSI,SCLK,POWER,CS,RST,DC) |
GregC | 0:3fcdc27ab845 | 22 | |
GregC | 0:3fcdc27ab845 | 23 | // Variables |
GregC | 0:3fcdc27ab845 | 24 | float mag_data[3]; // Storage for the data from the sensor |
GregC | 0:3fcdc27ab845 | 25 | float mag_rms=0.0; // RMS value from the sensor |
GregC | 0:3fcdc27ab845 | 26 | float mx, my, mz; // Integer value from the sensor to be displayed |
GregC | 0:3fcdc27ab845 | 27 | const uint8_t *image1; // Pointer for the image to be displayed |
GregC | 0:3fcdc27ab845 | 28 | char text1[20]; // Text Buffer for dynamic value displayed |
GregC | 0:3fcdc27ab845 | 29 | char text2[20]; // Text Buffer for dynamic value displayed |
GregC | 0:3fcdc27ab845 | 30 | char text3[20]; // Text Buffer for dynamic value displayed |
GregC | 0:3fcdc27ab845 | 31 | |
blownelco | 2:3c1fe1657db9 | 32 | |
blownelco | 2:3c1fe1657db9 | 33 | //void Rx_interrupt(); |
blownelco | 2:3c1fe1657db9 | 34 | //void read_line(); |
blownelco | 2:3c1fe1657db9 | 35 | |
blownelco | 2:3c1fe1657db9 | 36 | |
blownelco | 2:3c1fe1657db9 | 37 | // Circular buffers for serial TX and RX data - used by interrupt routines |
blownelco | 2:3c1fe1657db9 | 38 | const int buffer_size = 255; |
blownelco | 2:3c1fe1657db9 | 39 | // might need to increase buffer size for high baud rates |
blownelco | 2:3c1fe1657db9 | 40 | char rx_buffer[buffer_size+1]; |
blownelco | 2:3c1fe1657db9 | 41 | // Circular buffer pointers |
blownelco | 2:3c1fe1657db9 | 42 | // volatile makes read-modify-write atomic |
blownelco | 2:3c1fe1657db9 | 43 | volatile int rx_in=0; |
blownelco | 2:3c1fe1657db9 | 44 | volatile int rx_out=0; |
blownelco | 2:3c1fe1657db9 | 45 | // Line buffers for sprintf and sscanf |
blownelco | 2:3c1fe1657db9 | 46 | char tx_line[80]; |
blownelco | 2:3c1fe1657db9 | 47 | char rx_line[80]; |
blownelco | 2:3c1fe1657db9 | 48 | |
blownelco | 2:3c1fe1657db9 | 49 | ESP8266Interface wifi(PTD3,PTD2,PTD11,"MINI","kplaetevoet",9600); // TX,RX,Reset,SSID,Password,Baud |
blownelco | 2:3c1fe1657db9 | 50 | |
GregC | 0:3fcdc27ab845 | 51 | int main() { |
blownelco | 1:31908216b9ac | 52 | |
blownelco | 2:3c1fe1657db9 | 53 | |
blownelco | 2:3c1fe1657db9 | 54 | /* wifi3 board reset etc */ |
blownelco | 1:31908216b9ac | 55 | PWD = 1; |
blownelco | 1:31908216b9ac | 56 | G15 = 0; |
blownelco | 1:31908216b9ac | 57 | /*Wifi initialisation commands */ |
blownelco | 1:31908216b9ac | 58 | |
blownelco | 2:3c1fe1657db9 | 59 | wifi.init(); //Reset |
blownelco | 2:3c1fe1657db9 | 60 | printf("init done"); |
blownelco | 2:3c1fe1657db9 | 61 | wifi.connect(); |
blownelco | 2:3c1fe1657db9 | 62 | wifi.getIPAddress(); |
blownelco | 1:31908216b9ac | 63 | |
blownelco | 2:3c1fe1657db9 | 64 | //ebsocket ws("ws://192.168.1.20:8888/ws"); |
blownelco | 1:31908216b9ac | 65 | |
blownelco | 2:3c1fe1657db9 | 66 | |
GregC | 0:3fcdc27ab845 | 67 | // Configure Accelerometer FXOS8700, Magnetometer FXOS8700 |
GregC | 0:3fcdc27ab845 | 68 | mag.mag_config(); |
GregC | 0:3fcdc27ab845 | 69 | |
GregC | 0:3fcdc27ab845 | 70 | /* Setting pointer location of the 96 by 96 pixel bitmap */ |
GregC | 0:3fcdc27ab845 | 71 | image1 = Magneto; |
GregC | 0:3fcdc27ab845 | 72 | |
GregC | 0:3fcdc27ab845 | 73 | /* Turn on the backlight of the OLED Display */ |
GregC | 0:3fcdc27ab845 | 74 | // oled.DimScreenON(); |
GregC | 0:3fcdc27ab845 | 75 | |
GregC | 0:3fcdc27ab845 | 76 | /* Fill 96px by 96px Screen with 96px by 96px NXP Image starting at x=0,y=0 */ |
GregC | 0:3fcdc27ab845 | 77 | oled.DrawImage(image1,0,0); |
GregC | 0:3fcdc27ab845 | 78 | |
GregC | 0:3fcdc27ab845 | 79 | |
GregC | 0:3fcdc27ab845 | 80 | while (true) |
GregC | 0:3fcdc27ab845 | 81 | { |
GregC | 0:3fcdc27ab845 | 82 | |
GregC | 0:3fcdc27ab845 | 83 | mag.acquire_mag_data_uT(mag_data); |
GregC | 0:3fcdc27ab845 | 84 | mag_rms = sqrt(((mag_data[0]*mag_data[0])+(mag_data[1]*mag_data[1])+(mag_data[2]*mag_data[2]))/3); |
GregC | 0:3fcdc27ab845 | 85 | printf("Magnetometer \tX-Axis %4.2f \tY-Axis %4.2f \tZ-Axis %4.2f \tRMS %4.2f\n\n\r",mag_data[0],mag_data[1],mag_data[2],mag_rms); |
GregC | 0:3fcdc27ab845 | 86 | wait(0.01); |
GregC | 0:3fcdc27ab845 | 87 | mx = mag_data[0]; |
GregC | 0:3fcdc27ab845 | 88 | my = mag_data[1]; |
GregC | 0:3fcdc27ab845 | 89 | mz = mag_data[2]; |
GregC | 0:3fcdc27ab845 | 90 | |
GregC | 0:3fcdc27ab845 | 91 | /* Get OLED Class Default Text Properties */ |
GregC | 0:3fcdc27ab845 | 92 | oled_text_properties_t textProperties = {0}; |
GregC | 0:3fcdc27ab845 | 93 | oled.GetTextProperties(&textProperties); |
GregC | 0:3fcdc27ab845 | 94 | |
GregC | 0:3fcdc27ab845 | 95 | /* Set text properties to white and right aligned for the dynamic text */ |
GregC | 0:3fcdc27ab845 | 96 | textProperties.fontColor = COLOR_BLUE; |
GregC | 0:3fcdc27ab845 | 97 | textProperties.alignParam = OLED_TEXT_ALIGN_LEFT; |
GregC | 0:3fcdc27ab845 | 98 | oled.SetTextProperties(&textProperties); |
GregC | 0:3fcdc27ab845 | 99 | |
GregC | 0:3fcdc27ab845 | 100 | /* Display Legends */ |
GregC | 0:3fcdc27ab845 | 101 | strcpy((char *) text1,"X-Axis (uT):"); |
GregC | 0:3fcdc27ab845 | 102 | oled.Label((uint8_t *)text1,3,45); |
GregC | 0:3fcdc27ab845 | 103 | |
GregC | 0:3fcdc27ab845 | 104 | /* Format the value */ |
GregC | 0:3fcdc27ab845 | 105 | sprintf(text1,"%4.2f",mx); |
GregC | 0:3fcdc27ab845 | 106 | /* Display time reading in 35px by 15px textbox at(x=55, y=40) */ |
GregC | 0:3fcdc27ab845 | 107 | oled.TextBox((uint8_t *)text1,70,45,20,15); //Increase textbox for more digits |
GregC | 0:3fcdc27ab845 | 108 | |
GregC | 0:3fcdc27ab845 | 109 | /* Set text properties to white and right aligned for the dynamic text */ |
GregC | 0:3fcdc27ab845 | 110 | textProperties.fontColor = COLOR_GREEN; |
GregC | 0:3fcdc27ab845 | 111 | textProperties.alignParam = OLED_TEXT_ALIGN_LEFT; |
GregC | 0:3fcdc27ab845 | 112 | oled.SetTextProperties(&textProperties); |
GregC | 0:3fcdc27ab845 | 113 | |
GregC | 0:3fcdc27ab845 | 114 | /* Display Legends */ |
GregC | 0:3fcdc27ab845 | 115 | strcpy((char *) text2,"Y-Axis (uT):"); |
GregC | 0:3fcdc27ab845 | 116 | oled.Label((uint8_t *)text2,3,62); |
GregC | 0:3fcdc27ab845 | 117 | |
GregC | 0:3fcdc27ab845 | 118 | /* Format the value */ |
GregC | 0:3fcdc27ab845 | 119 | sprintf(text2,"%4.2f",my); |
GregC | 0:3fcdc27ab845 | 120 | /* Display time reading in 35px by 15px textbox at(x=55, y=40) */ |
GregC | 0:3fcdc27ab845 | 121 | oled.TextBox((uint8_t *)text2,70,62,20,15); //Increase textbox for more digits |
GregC | 0:3fcdc27ab845 | 122 | |
GregC | 0:3fcdc27ab845 | 123 | /* Set text properties to white and right aligned for the dynamic text */ |
GregC | 0:3fcdc27ab845 | 124 | textProperties.fontColor = COLOR_RED; |
GregC | 0:3fcdc27ab845 | 125 | textProperties.alignParam = OLED_TEXT_ALIGN_LEFT; |
GregC | 0:3fcdc27ab845 | 126 | oled.SetTextProperties(&textProperties); |
GregC | 0:3fcdc27ab845 | 127 | |
GregC | 0:3fcdc27ab845 | 128 | /* Display Legends */ |
GregC | 0:3fcdc27ab845 | 129 | strcpy((char *) text3,"Z-Axis (uT):"); |
GregC | 0:3fcdc27ab845 | 130 | oled.Label((uint8_t *)text3,3,79); |
GregC | 0:3fcdc27ab845 | 131 | |
GregC | 0:3fcdc27ab845 | 132 | /* Format the value */ |
GregC | 0:3fcdc27ab845 | 133 | sprintf(text3,"%4.2f",mz); |
GregC | 0:3fcdc27ab845 | 134 | /* Display time reading in 35px by 15px textbox at(x=55, y=40) */ |
GregC | 0:3fcdc27ab845 | 135 | oled.TextBox((uint8_t *)text3,70,79,20,15); //Increase textbox for more digits |
GregC | 0:3fcdc27ab845 | 136 | |
GregC | 0:3fcdc27ab845 | 137 | led1 = !led1; |
GregC | 0:3fcdc27ab845 | 138 | Thread::wait(250); |
GregC | 0:3fcdc27ab845 | 139 | } |
blownelco | 2:3c1fe1657db9 | 140 | } |
blownelco | 2:3c1fe1657db9 | 141 | |
blownelco | 2:3c1fe1657db9 | 142 | |
blownelco | 2:3c1fe1657db9 | 143 | |
blownelco | 2:3c1fe1657db9 | 144 | |
blownelco | 2:3c1fe1657db9 | 145 | |
blownelco | 2:3c1fe1657db9 | 146 | |
blownelco | 2:3c1fe1657db9 | 147 |