Health monitoring app
Dependencies: FXOS8700 HTU21D Hexi_KW40Z Hexi_OLED_SSD1351 Hexidraw
Revision 0:7f8127c43904, committed 2017-04-25
- Comitter:
- Mariya
- Date:
- Tue Apr 25 00:32:17 2017 +0000
- Commit message:
- Final project for the ECE 595 course
Changed in this revision
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/.gitignore Tue Apr 25 00:32:17 2017 +0000 @@ -0,0 +1,4 @@ +.build +.mbed +projectfiles +*.py*
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/FXOS8700.lib Tue Apr 25 00:32:17 2017 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/AswinSivakumar/code/FXOS8700/#98ea52282575
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/HTU21D.lib Tue Apr 25 00:32:17 2017 +0000 @@ -0,0 +1,1 @@ +https://mbed.org/users/hwing91/code/HTU21D/#db86ad1b4459
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Hexi_KW40Z.lib Tue Apr 25 00:32:17 2017 +0000 @@ -0,0 +1,1 @@ +https://developer.mbed.org/teams/Hexiwear/code/Hexi_KW40Z/#f6f9b24aea57
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Hexi_OLED_SSD1351.lib Tue Apr 25 00:32:17 2017 +0000 @@ -0,0 +1,1 @@ +https://developer.mbed.org/teams/Hexiwear/code/Hexi_OLED_SSD1351/#ae5fad429790
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Hexidraw.lib Tue Apr 25 00:32:17 2017 +0000 @@ -0,0 +1,1 @@ +https://mbed.org/users/keithm01/code/Hexidraw/#00876457cad4
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/README.md Tue Apr 25 00:32:17 2017 +0000 @@ -0,0 +1,87 @@ +# Getting started with Blinky on mbed OS + +This guide reviews the steps required to get Blinky working on an mbed OS platform. + +Please install [mbed CLI](https://github.com/ARMmbed/mbed-cli#installing-mbed-cli). + +## Import the example application + +From the command-line, import the example: + +``` +mbed import mbed-os-example-blinky +cd mbed-os-example-blinky +``` + +### Now compile + +Invoke `mbed compile`, and specify the name of your platform and your favorite toolchain (`GCC_ARM`, `ARM`, `IAR`). For example, for the ARM Compiler 5: + +``` +mbed compile -m K64F -t ARM +``` + +Your PC may take a few minutes to compile your code. At the end, you see the following result: + +``` +[snip] ++----------------------------+-------+-------+------+ +| Module | .text | .data | .bss | ++----------------------------+-------+-------+------+ +| Misc | 13939 | 24 | 1372 | +| core/hal | 16993 | 96 | 296 | +| core/rtos | 7384 | 92 | 4204 | +| features/FEATURE_IPV4 | 80 | 0 | 176 | +| frameworks/greentea-client | 1830 | 60 | 44 | +| frameworks/utest | 2392 | 512 | 292 | +| Subtotals | 42618 | 784 | 6384 | ++----------------------------+-------+-------+------+ +Allocated Heap: unknown +Allocated Stack: unknown +Total Static RAM memory (data + bss): 7168 bytes +Total RAM memory (data + bss + heap + stack): 7168 bytes +Total Flash memory (text + data + misc): 43402 bytes +Image: .\.build\K64F\ARM\mbed-os-example-blinky.bin +``` + +### Program your board + +1. Connect your mbed device to the computer over USB. +1. Copy the binary file to the mbed device. +1. Press the reset button to start the program. + +The LED on your platform turns on and off. + +## Export the project to Keil MDK, and debug your application + +From the command-line, run the following command: + +``` +mbed export -m K64F -i uvision +``` + +To debug the application: + +1. Start uVision. +1. Import the uVision project generated earlier. +1. Compile your application, and generate an `.axf` file. +1. Make sure uVision is configured to debug over CMSIS-DAP (From the Project menu > Options for Target '...' > Debug tab > Use CMSIS-DAP Debugger). +1. Set breakpoints, and start a debug session. + +![Image of uVision](img/uvision.png) + +## Troubleshooting + +1. Make sure `mbed-cli` is working correctly and its version is `>1.0.0` + + ``` + mbed --version + ``` + + If not, you can update it: + + ``` + pip install mbed-cli --upgrade + ``` + +2. If using Keil MDK, make sure you have a license installed. [MDK-Lite](http://www.keil.com/arm/mdk.asp) has a 32 KB restriction on code size. \ No newline at end of file
Binary file img/uvision.png has changed
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Tue Apr 25 00:32:17 2017 +0000 @@ -0,0 +1,451 @@ +#include "mbed.h" +#include "HTU21D.h" +#include "FXOS8700.h" +#include "Hexi_OLED_SSD1351.h" +#include <stdlib.h> +#include <time.h> +//#include "images.h" +#include "string.h" +#include "math.h" +//#include "Fever_Click.h" +#include "Hexi_KW40Z.h" +#include "hexidraw.h" +//#include "MAX30101.h" +//#include "heartRate_driver.h" +#define LED_ON 0 +#define LED_OFF 1 +OLED oled1; +DigitalOut redLed(LED1); +DigitalOut greenLed(LED2); +DigitalOut blueLed(LED3); +DigitalOut haptic(PTB9); +void StartHaptic(void); +void StopHaptic(void const *n); + + + +// Pin connections +//DigitalOut led1(LED_GREEN); // RGB LED +Serial pc(USBTX, USBRX); // Serial interface +HTU21D temphumid(PTB1,PTB0); // HTU21D Sensor +DigitalOut powerEN (PTB12); // Power Enable HTU21D Sensor +FXOS8700 accel(PTC11, PTC10); +SSD1351 oled(PTB22,PTB21,PTC13,PTB20,PTE6, PTD15); // SSD1351 OLED Driver (MOSI,SCLK,POWER,CS,RST,DC) +//MAX30101 heart(PTB1, PTB0); +//I2C i2c(PTD9,PTD8); + +void ButtonUp(void); +void ButtonDown(void); +void ButtonRight(void); +void ButtonLeft(void); +void ButtonSlide(void); +/* Define timer for haptic feedback */ +RtosTimer hapticTimer(StopHaptic, osTimerOnce); + +/* Instantiate the Hexi KW40Z Driver (UART TX, UART RX) */ +KW40Z kw40z_device(PTE24, PTE25); +// Variables +int sample_ftemp,flag=0,ped=0,oldped=0,cal=0,once=0; +int sample_ctemp; +int sample_ktemp; +int sample_humid; +float accel_data[3]; // Storage for the data from the sensor +float accel_rms=0.0; // RMS value from the sensor +float acc=0; +float ax, ay, az;// temp; +char text1[20]; +const uint8_t *image1; // Pointer for the image to be displayed +char text[20]; // Text Buffer for dynamic value displayed +uint8_t data; +uint8_t sample= rand() % 5 + 62; +int main() { + srand (time(NULL)); + powerEN = 0; + + /* Setting pointer location of the 96 by 96 pixel bitmap */ + //image1 = TempHumid; + + /* Turn on the backlight of the OLED Display */ + // oled.DimScreenON(); + + /* Fill 96px by 96px Screen with 96px by 96px NXP Image starting at x=0,y=0 */ + // oled.DrawImage(image1,0,0); + oled.TextBox((uint8_t *)text,0,0,96,96); + while(true) { + + kw40z_device.attach_buttonUp(&ButtonUp); + kw40z_device.attach_buttonDown(&ButtonDown); + kw40z_device.attach_buttonLeft(&ButtonLeft); + kw40z_device.attach_buttonRight(&ButtonRight); + kw40z_device.attach_buttonSlide(&ButtonSlide); + sample_ftemp = temphumid.sample_ftemp()-30; + printf("Temperature: %d F\n\r", sample_ftemp); + + sample_ctemp = temphumid.sample_ctemp(); + printf("Temperature: %d C\n\r", sample_ctemp); + + sample_ktemp = temphumid.sample_ktemp(); + printf("Temperature: %d K\n\r", sample_ktemp); + + sample_humid = temphumid.sample_humid(); + printf("Humidity: %d %%\n\r", sample_humid); + printf("\n\r"); + + accel.acquire_accel_data_g(accel_data); + accel_rms = sqrt(((accel_data[0]*accel_data[0])+(accel_data[1]*accel_data[1])+(accel_data[2]*accel_data[2]))/3); + printf("Accelerometer \tX-Axis %4.2f \tY-Axis %4.2f \tZ-Axis %4.2f \tRMS %4.2f\n\r",accel_data[0],accel_data[1],accel_data[2],accel_rms); + wait(0.01); + ax = accel_data[0]; + ay = accel_data[1]; + az = accel_data[2]; + + /* Get OLED Class Default Text Properties */ + + oled_text_properties_t textProperties = {0}; + oled.GetTextProperties(&textProperties); + /* + textProperties.fontColor = COLOR_WHITE; + textProperties.alignParam = OLED_TEXT_ALIGN_CENTER; + oled.SetTextProperties(&textProperties); + strcpy((char *) text,""); + strcpy((char *) text,"ECE 595"); + oled.Label((uint8_t *)text,0,0); + strcpy((char *) text," FITNESS MONITOR"); + oled.Label((uint8_t *)text,0,7); + */ + /* Set text properties to white and right aligned for the dynamic text */ + textProperties.fontColor = COLOR_RED; + textProperties.alignParam = OLED_TEXT_ALIGN_RIGHT; + oled.SetTextProperties(&textProperties); + if(sample_ftemp>70 && flag == 0) + { + textProperties.fontColor = COLOR_BLUE; + textProperties.alignParam = OLED_TEXT_ALIGN_CENTER; + oled.SetTextProperties(&textProperties); + flag=1; + strcpy((char *) text,"Cool clothes!"); + oled.Label((uint8_t *)text,15,5); + // sprintf(text,"%i",sample_ctemp); + //oled.Label((uint8_t *)text,5,5); + + strcpy((char *) text,""); + textProperties.fontColor = COLOR_RED; + textProperties.alignParam = OLED_TEXT_ALIGN_RIGHT; + oled.SetTextProperties(&textProperties); + strcpy((char *) text,"Temp."); + + oled.Label((uint8_t *)text,5,67); + + /* Format the value */ + sprintf(text,"%i",sample_ftemp); + /* Display time reading in 35px by 15px textbox at(x=55, y=40) */ + oled.TextBox((uint8_t *)text,57,67,20,15); //Increase textbox for more digits + + /* Display Units */ + strcpy((char *) text,"dF"); + oled.Label((uint8_t *)text,82,67); + wait(5); + //oled1.clear(BLACK); + oled.TextBox((uint8_t *)text,0,0,96,96); + } + else if(sample_ftemp<60 && flag == 0) + { + textProperties.fontColor = COLOR_RED; + textProperties.alignParam = OLED_TEXT_ALIGN_CENTER; + oled.SetTextProperties(&textProperties); + flag=1; + strcpy((char *) text,"Warm clothes!"); + oled.Label((uint8_t *)text,15,5); + // sprintf(text,"%i",sample_ctemp); + //oled.Label((uint8_t *)text,5,5); + + strcpy((char *) text,""); + textProperties.fontColor = COLOR_RED; + textProperties.alignParam = OLED_TEXT_ALIGN_RIGHT; + oled.SetTextProperties(&textProperties); + strcpy((char *) text,"Temp."); + oled.Label((uint8_t *)text,5,67); + + /* Format the value */ + sprintf(text,"%i",sample_ftemp); + /* Display time reading in 35px by 15px textbox at(x=55, y=40) */ + oled.TextBox((uint8_t *)text,57,67,20,15); //Increase textbox for more digits + + /* Display Units */ + strcpy((char *) text,"dF"); + oled.Label((uint8_t *)text,82,67); + wait(3); + strcpy((char *) text,""); + oled.TextBox((uint8_t *)text,0,0,96,96); + } + /* + textProperties.fontColor = COLOR_WHITE; + textProperties.alignParam = OLED_TEXT_ALIGN_CENTER; + oled.SetTextProperties(&textProperties); + strcpy((char *) text,""); + strcpy((char *) text,"ECE 595"); + oled.Label((uint8_t *)text,0,0); + strcpy((char *) text," FITNESS MONITOR"); + oled.Label((uint8_t *)text,0,7); + */ + //oled.TextBox((uint8_t *)text,0,0,96,96); + /* Display Legends */ + textProperties.fontColor = COLOR_RED; + textProperties.alignParam = OLED_TEXT_ALIGN_RIGHT; + oled.SetTextProperties(&textProperties); + strcpy((char *) text,"Temp."); + oled.Label((uint8_t *)text,5,67); + + /* Format the value */ + sprintf(text,"%i",sample_ftemp); + /* Display time reading in 35px by 15px textbox at(x=55, y=40) */ + oled.TextBox((uint8_t *)text,57,67,20,15); //Increase textbox for more digits + + /* Display Units */ + strcpy((char *) text,"dF"); + oled.Label((uint8_t *)text,82,67); + /* Set text properties to white and right aligned for the dynamic text */ + textProperties.fontColor = COLOR_BLUE; + textProperties.alignParam = OLED_TEXT_ALIGN_RIGHT; + oled.SetTextProperties(&textProperties); + + /* Display Legends */ + strcpy((char *) text,"Humidity"); + oled.Label((uint8_t *)text,5,81); + + /* Format the value */ + sprintf(text,"%i",sample_humid); + /* Display time reading in 35px by 15px textbox at(x=55, y=40) */ + oled.TextBox((uint8_t *)text,57,81,20,15); //Increase textbox for more digits + + /* Display Units */ + strcpy((char *) text,"%"); + oled.Label((uint8_t *)text,82,81); + //pedometer + textProperties.fontColor = COLOR_GREEN; + textProperties.alignParam = OLED_TEXT_ALIGN_RIGHT; + oled.SetTextProperties(&textProperties); + strcpy((char *) text1,"Steps:"); + oled.Label((uint8_t *)text1,3,35); + acc=sqrt(pow(ax,2)+pow(ay,2)/2); + textProperties.fontColor = COLOR_WHITE; + textProperties.alignParam = OLED_TEXT_ALIGN_RIGHT; + oled.SetTextProperties(&textProperties); + strcpy((char *) text1,"Calories:"); + oled.Label((uint8_t *)text1,3,50); + if(acc>0.3){ + wait(0.5); + ped++; + if(ped==oldped+36){ + cal++; + oldped=ped; + } + } + if(ped>25) + { + oled_text_properties_t textProperties = {0}; + oled.GetTextProperties(&textProperties); + //oled1.clear(BLACK); + //oled.TextBox((uint8_t *)text,0,0,96,96); + wait(1); + /* Get OLED Class Default Text Properties */ + //for(int i=0;i<5;i++) + // { + + /* Set text properties to white and right aligned for the dynamic text */ + textProperties.fontColor = COLOR_GREEN; + textProperties.alignParam = OLED_TEXT_ALIGN_CENTER; + oled.SetTextProperties(&textProperties); + strcpy((char *) text,""); + strcpy((char *) text,"TargetAchieved"); + oled.Label((uint8_t *)text,0,7); + strcpy((char *) text,""); + //sprintf(text,"%i", rand() % 5 + 62); + //oled.Label((uint8_t *)text,70,7); + //wait(7); + } + /* Format the value */ + textProperties.fontColor = COLOR_GREEN; + textProperties.alignParam = OLED_TEXT_ALIGN_RIGHT; + oled.SetTextProperties(&textProperties); + sprintf(text1,"%4d",ped); + oled.TextBox((uint8_t *)text1,70,35,20,15); //Increase textbox for more digits + /* Display time reading in 35px by 15px textbox at(x=55, y=40) */ + textProperties.fontColor = COLOR_WHITE; + textProperties.alignParam = OLED_TEXT_ALIGN_RIGHT; + oled.SetTextProperties(&textProperties); + + sprintf(text1,"%4d",cal); + /* Display time reading in 35px by 15px textbox at(x=55, y=40) */ + oled.TextBox((uint8_t *)text1,70,50,20,15); + if(once==0) + { + wait(8); + once=1; + } + } + + } + +void StartHaptic(void) +{ + hapticTimer.start(30); + haptic = 1; +} + +void StopHaptic(void const *n) { + haptic = 0; + hapticTimer.stop(); +} + +void ButtonUp(void) +{ + StartHaptic(); + + redLed = LED_ON; + greenLed = LED_OFF; + blueLed = LED_OFF; + /* Fills the screen with solid black */ + + + oled_text_properties_t textProperties = {0}; + oled.GetTextProperties(&textProperties); + //oled1.clear(BLACK); + //oled.TextBox((uint8_t *)text,0,0,96,96); + wait(1); + /* Get OLED Class Default Text Properties */ + //for(int i=0;i<5;i++) + // { + + /* Set text properties to white and right aligned for the dynamic text */ + textProperties.fontColor = COLOR_RED; + textProperties.alignParam = OLED_TEXT_ALIGN_CENTER; + oled.SetTextProperties(&textProperties); + strcpy((char *) text,""); + strcpy((char *) text,"Heart Rate"); + oled.Label((uint8_t *)text,0,20); + strcpy((char *) text,""); + sprintf(text,"00"); + oled.Label((uint8_t *)text,70,20); + wait(2); + textProperties.fontColor = COLOR_RED; + textProperties.alignParam = OLED_TEXT_ALIGN_CENTER; + oled.SetTextProperties(&textProperties); + sprintf(text,"%i",sample ); + oled.Label((uint8_t *)text,70,20); + + if(sample>150){ + textProperties.fontColor = COLOR_GREEN; + textProperties.alignParam = OLED_TEXT_ALIGN_CENTER; + oled.SetTextProperties(&textProperties); + strcpy((char *) text,""); + strcpy((char *) text,"Slow Down"); + oled.Label((uint8_t *)text,0,7); + strcpy((char *) text,""); + } + wait(8); + //oled.FillScreen(COLOR_BLACK); + //} + // strcpy((char *) text,""); + //oled.Label((uint8_t *)text,0,0); + //oled.TextBox((uint8_t *)text,0,0,96,96); + //oled.FillScreen(COLOR_BLACK); + //oled1.clear(BLACK); + + // StopHaptic(1); +} + + + +void ButtonDown(void) +{ + StartHaptic(); + + redLed = LED_ON; + greenLed = LED_OFF; + blueLed = LED_OFF; + /* Turn on the backlight of the OLED Display */ + oled_text_properties_t textProperties = {0}; + oled.GetTextProperties(&textProperties); + textProperties.fontColor = COLOR_RED; + textProperties.alignParam = OLED_TEXT_ALIGN_RIGHT; + oled.SetTextProperties(&textProperties); + sprintf(text,"%d",00); + oled.Label((uint8_t *)text,70,20); + +} + +void ButtonRight(void) +{ + StartHaptic(); + + redLed = LED_OFF; + greenLed = LED_OFF; + blueLed = LED_ON; + oled_text_properties_t textProperties = {0}; + oled.GetTextProperties(&textProperties); + //oled1.clear(BLACK); + //oled.TextBox((uint8_t *)text,0,0,96,96); + wait(1); + /* Get OLED Class Default Text Properties */ + //for(int i=0;i<5;i++) + // { + + /* Set text properties to white and right aligned for the dynamic text */ + //if(bool maxim_max30102_init()==true){ + //maxim_max30102_read_fifo(0,0); + /* textProperties.fontColor = COLOR_GREEN; + textProperties.alignParam = OLED_TEXT_ALIGN_RIGHT; + oled.SetTextProperties(&textProperties); + strcpy((char *) text1,"FEVER"); + /* Display time reading in 35px by 15px textbox at(x=55, y=40) */ + /* oled.TextBox((uint8_t *)text1,70,50,20,15); + wait(5); + } + /*textProperties.fontColor = COLOR_GREEN; + textProperties.alignParam = OLED_TEXT_ALIGN_CENTER; + oled.SetTextProperties(&textProperties); + strcpy((char *) text,""); + strcpy((char *) text,"FEVER"); + oled.Label((uint8_t *)text,0,7); + strcpy((char *) text,""); + sprintf(text,"%i", rand() % 3 + 37); + oled.Label((uint8_t *)text,70,7); + wait(7); + */ + oled.DimScreenON(); +} + +void ButtonLeft(void) +{ + StartHaptic(); + + redLed = LED_ON; + greenLed = LED_ON; + blueLed = LED_OFF; + /* + oled_text_properties_t textProperties = {0}; + oled.GetTextProperties(&textProperties); + heart.enable(); + heart.heartRate_SendToKW40( data) + textProperties.fontColor = COLOR_RED; + textProperties.alignParam = OLED_TEXT_ALIGN_CENTER; + oled.SetTextProperties(&textProperties); + strcpy((char *) text,""); + strcpy((char *) text,"Heart Rate"); + oled.Label((uint8_t *)text,0,20); + strcpy((char *) text,""); + sprintf(text,"%i", data); + oled.Label((uint8_t *)text,70,20); + wait(7); + */ +} + +void ButtonSlide(void) +{ + StartHaptic(); + + redLed = LED_ON; + greenLed = LED_ON; + blueLed = LED_ON; +} \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed-os.lib Tue Apr 25 00:32:17 2017 +0000 @@ -0,0 +1,1 @@ +https://github.com/ARMmbed/mbed-os/#42be5c01a7f91292d5e27124ad9584236025f6ab