Advanced gyroscope program example for Hexiwear featuring OLED Display
Dependencies: FXAS21002 Hexi_OLED_SSD1351
Fork of Hexi_Gyro-v2_Example by
This project demonstrates the use of the FXAS21002CQ Gyroscope sensor embedded in Hexiwear
Compile the project and copy the binary "Hexi_Gyro-V2_Example_HEXIWEAR.bin" in the DAP-LINK drive from your computer file explorer Press the K64F-RESET button on the docking station to start the program on your board
The Roll, the Pitch and the Yaw values will be displayed in real-time on the OLED Display.
Diff: main.cpp
- Revision:
- 2:a041eec9ea8f
- Parent:
- 1:6bd53a378639
diff -r 6bd53a378639 -r a041eec9ea8f main.cpp
--- a/main.cpp Sat Sep 24 19:51:05 2016 +0000
+++ b/main.cpp Wed Oct 19 22:46:58 2016 +0000
@@ -12,40 +12,38 @@
// Variables
float gyro_data[3]; // Storage for the data from the sensor
-//float gyro_rms=0.0; // RMS value from the sensor
-int x, y, z; // Integer value from the sensor to be displayed
-const uint8_t *image1; // Pointer for the image to be displayed
-char text[20]; // Text Buffer for dynamic value displayed
-
-
-
+float gyro_rms=0.0; // RMS value from the sensor
+float gx, gy, gz; // Integer value from the sensor to be displayed
+const uint8_t *image1; // Pointer for the image1 to be displayed
+char text1[20]; // Text Buffer for dynamic value displayed
+char text2[20]; // Text Buffer for dynamic value displayed
+char text3[20]; // Text Buffer for dynamic value displayed
int main() {
-
+
+ // Configure Gyroscope FXAS21002
gyro.gyro_config();
/* Setting pointer location of the 96 by 96 pixel bitmap */
- image1 = Gyroscope;
+ image1 = Gyro;
- /* Turn on the backlight of the OLED Display */
+ // Dimm Down OLED backlight
// oled.DimScreenON();
/* Fill 96px by 96px Screen with 96px by 96px NXP Image starting at x=0,y=0 */
oled.DrawImage(image1,0,0);
-
-
-
- while (true) {
+ while (true)
+ {
gyro.acquire_gyro_data_dps(gyro_data);
- pc.printf("Roll (G) %4.2f,\t Pitch (G) %4.2f,\t Yaw (G) %4.2f\r\n",gyro_data[0],gyro_data[1],gyro_data[2]);
-// gyro_rms = sqrt(((gyro_data[0]*gyro_data[0])+(gyro_data[1]*gyro_data[1])+(gyro_data[2]*gyro_data[2]))/3);
-// pc.printf("Gyroscope RMS %f \r\n\n",gyro_rms);
- x = gyro_data[0];
- y = gyro_data[1];
- z = gyro_data[2];
+ gyro_rms = sqrt(((gyro_data[0]*gyro_data[0])+(gyro_data[1]*gyro_data[1])+(gyro_data[2]*gyro_data[2]))/3);
+ pc.printf("Gyroscope \tRoll (G) %4.2f \tPitch (G) %4.2f \tYaw (G) %4.2f \tRMS %4.2f\n\r",gyro_data[0],gyro_data[1],gyro_data[2],gyro_rms);
+ wait(0.01);
+ gx = gyro_data[0];
+ gy = gyro_data[1];
+ gz = gyro_data[2];
/* Get OLED Class Default Text Properties */
oled_text_properties_t textProperties = {0};
@@ -56,44 +54,44 @@
textProperties.alignParam = OLED_TEXT_ALIGN_LEFT;
oled.SetTextProperties(&textProperties);
- /* Display Legends */
- strcpy((char *) text,"Roll");
- oled.Label((uint8_t *)text,5,67);
+ /* Display Legends */
+ strcpy((char *) text1,"Roll (dps):");
+ oled.Label((uint8_t *)text1,3,45);
/* Format the value */
- sprintf(text,"%i",x);
+ sprintf(text1,"%4.2f",gx);
/* Display time reading in 35px by 15px textbox at(x=55, y=40) */
- oled.TextBox((uint8_t *)text,5,81,20,15); //Increase textbox for more digits
+ oled.TextBox((uint8_t *)text1,70,45,20,15); //Increase textbox for more digits
/* Set text properties to white and right aligned for the dynamic text */
textProperties.fontColor = COLOR_GREEN;
- textProperties.alignParam = OLED_TEXT_ALIGN_CENTER;
+ textProperties.alignParam = OLED_TEXT_ALIGN_LEFT;
oled.SetTextProperties(&textProperties);
- /* Display Legends */
- strcpy((char *) text,"Pitch");
- oled.Label((uint8_t *)text,37,67);
+ /* Display Legends */
+ strcpy((char *) text2,"Pitch (dps):");
+ oled.Label((uint8_t *)text2,3,62);
/* Format the value */
- sprintf(text,"%i",y);
+ sprintf(text2,"%4.2f",gy);
/* Display time reading in 35px by 15px textbox at(x=55, y=40) */
- oled.TextBox((uint8_t *)text,37,81,20,15); //Increase textbox for more digits
+ oled.TextBox((uint8_t *)text2,70,62,20,15); //Increase textbox for more digits
/* Set text properties to white and right aligned for the dynamic text */
textProperties.fontColor = COLOR_RED;
- textProperties.alignParam = OLED_TEXT_ALIGN_RIGHT;
+ textProperties.alignParam = OLED_TEXT_ALIGN_LEFT;
oled.SetTextProperties(&textProperties);
- /* Display Legends */
- strcpy((char *) text,"Yaw");
- oled.Label((uint8_t *)text,70,67);
+ /* Display Legends */
+ strcpy((char *) text3,"Yaw (dps):");
+ oled.Label((uint8_t *)text3,3,79);
/* Format the value */
- sprintf(text,"%i",z);
+ sprintf(text3,"%4.2f",gz);
/* Display time reading in 35px by 15px textbox at(x=55, y=40) */
- oled.TextBox((uint8_t *)text,70,81,20,15); //Increase textbox for more digits
+ oled.TextBox((uint8_t *)text3,70,79,20,15); //Increase textbox for more digits
led1 = !led1;
Thread::wait(250);
- }
+ }
}
\ No newline at end of file
