Los Putacos / Mbed OS WearableDevice_Nucleo_New

Dependencies:   MPU9250_SPI

Fork of WearableDevice_Nucleo by Los Putacos

Committer:
Muglug
Date:
Tue Oct 17 12:04:41 2017 +0000
Revision:
17:f98597cd2efc
Parent:
13:837ea602def0
Child:
18:7f9c2b8541e1
Still the Best Arooound

Who changed what in which revision?

UserRevisionLine numberNew contents of line
gusteibolt 1:a6dc717fb060 1 /*
gusteibolt 1:a6dc717fb060 2 * Los Putacos
gusteibolt 1:a6dc717fb060 3 * Copyright (C) 2017, All rights reserved.
gusteibolt 1:a6dc717fb060 4 * ________________________________________
gusteibolt 1:a6dc717fb060 5 *
gusteibolt 1:a6dc717fb060 6 * Created by: Gustavo Campana, Michael Schmidt, Miguel Lopez
gusteibolt 1:a6dc717fb060 7 * Date: 11-Oct-2017
gusteibolt 1:a6dc717fb060 8 * Version: V0.1
gusteibolt 1:a6dc717fb060 9 */
gusteibolt 1:a6dc717fb060 10
gusteibolt 1:a6dc717fb060 11 //-----------------------------------------------------------------
gusteibolt 1:a6dc717fb060 12 // Board: NUCLEO - F401RE
gusteibolt 1:a6dc717fb060 13 // Version: MR1136 rev C
gusteibolt 1:a6dc717fb060 14 //-----------------------------------------------------------------
gusteibolt 1:a6dc717fb060 15
gusteibolt 1:a6dc717fb060 16 //-----------------------------------------------------------------
gusteibolt 1:a6dc717fb060 17 // Includes
gusteibolt 0:73cd0cb02330 18 #include "mbed.h"
gusteibolt 0:73cd0cb02330 19 #include "rtos.h"
gusteibolt 3:26aeff25f610 20 #include "mbed_events.h"
gusteibolt 3:26aeff25f610 21
gusteibolt 3:26aeff25f610 22 #include "configuration.h"
gusteibolt 10:577e1fc4453e 23 #include "event.h"
gusteibolt 7:ebaaff27840b 24 #include "pin.h"
gusteibolt 3:26aeff25f610 25 #include "MPU9250.h"
Muglug 17:f98597cd2efc 26
Muglug 17:f98597cd2efc 27 #include "XBeeLib.h"
gusteibolt 1:a6dc717fb060 28 //-----------------------------------------------------------------
gusteibolt 0:73cd0cb02330 29
gusteibolt 1:a6dc717fb060 30 //-----------------------------------------------------------------
gusteibolt 1:a6dc717fb060 31 // Declarations
gusteibolt 10:577e1fc4453e 32 Timer time_stamp; //Timer µS time-stamp
gusteibolt 3:26aeff25f610 33
gusteibolt 3:26aeff25f610 34 EventQueue queue(32 * EVENTS_EVENT_SIZE); //Event
gusteibolt 3:26aeff25f610 35
gusteibolt 3:26aeff25f610 36 Serial pc(USBTX, USBRX); // PC Serial (Debug)
Muglug 17:f98597cd2efc 37 // Serial xbee(PA_2, PA_3); // Xbee
gusteibolt 3:26aeff25f610 38
gusteibolt 10:577e1fc4453e 39 MPU9250 imu; // IMU MPU-9255 by Kris Winer
gusteibolt 1:a6dc717fb060 40 //-----------------------------------------------------------------
gusteibolt 1:a6dc717fb060 41
gusteibolt 1:a6dc717fb060 42 //-----------------------------------------------------------------
gusteibolt 1:a6dc717fb060 43 // Global Variables
gusteibolt 3:26aeff25f610 44 // Your code here!
gusteibolt 1:a6dc717fb060 45 //-----------------------------------------------------------------
gusteibolt 10:577e1fc4453e 46 /*
gusteibolt 1:a6dc717fb060 47 //-----------------------------------------------------------------
gusteibolt 8:ba93a973f967 48 void print_event(void const *argv, int i) {
gusteibolt 10:577e1fc4453e 49 pc.printf("%d ",i);
gusteibolt 8:ba93a973f967 50 pc.printf((const char*)argv);
gusteibolt 10:577e1fc4453e 51 pc.printf("\r\n");
gusteibolt 8:ba93a973f967 52 }
gusteibolt 8:ba93a973f967 53 //-----------------------------------------------------------------
gusteibolt 10:577e1fc4453e 54 */
gusteibolt 8:ba93a973f967 55 //-----------------------------------------------------------------
gusteibolt 8:ba93a973f967 56 void blink_event(DigitalOut pin){
gusteibolt 10:577e1fc4453e 57 pin = !pin;
gusteibolt 8:ba93a973f967 58 }
gusteibolt 8:ba93a973f967 59 //-----------------------------------------------------------------
gusteibolt 8:ba93a973f967 60
gusteibolt 8:ba93a973f967 61 //-----------------------------------------------------------------
gusteibolt 8:ba93a973f967 62 void println_event(){
gusteibolt 8:ba93a973f967 63 pc.printf("Arroz, feijao e batata\r\n");
gusteibolt 8:ba93a973f967 64 }
gusteibolt 8:ba93a973f967 65 //-----------------------------------------------------------------
gusteibolt 8:ba93a973f967 66
gusteibolt 8:ba93a973f967 67 //-----------------------------------------------------------------
gusteibolt 7:ebaaff27840b 68 void setup(){
gusteibolt 3:26aeff25f610 69
gusteibolt 3:26aeff25f610 70 // PC Serial (Debug) baudrate
gusteibolt 3:26aeff25f610 71 pc.baud(9600);
gusteibolt 3:26aeff25f610 72 pc.printf("CPU SystemCoreClock is %d Hz\r\n", SystemCoreClock);
gusteibolt 3:26aeff25f610 73
gusteibolt 3:26aeff25f610 74 // Task queue
gusteibolt 3:26aeff25f610 75 int task1_id = queue.call_every(1000, printf, "called every 1 seconds\n");
gusteibolt 3:26aeff25f610 76 int task2_id = queue.call_every(2500, printf, "called every 2.5 seconds\n");
gusteibolt 10:577e1fc4453e 77 //int task3_id = queue.call_every(3000, &print_event, (void *)"called every 3 seconds\n", (int) time_stamp.read());
gusteibolt 10:577e1fc4453e 78 //int task4_id = queue.call_every(50, blink_event, led1);
gusteibolt 8:ba93a973f967 79 int task5_id = queue.call_every(500, println_event);
gusteibolt 10:577e1fc4453e 80 int task6_id = queue.call_every(500, readIMU);
gusteibolt 12:c88478dfc622 81 int task7_id = queue.call_every(500, gayEvent);
gusteibolt 0:73cd0cb02330 82 }
gusteibolt 1:a6dc717fb060 83 //-----------------------------------------------------------------
gusteibolt 0:73cd0cb02330 84
gusteibolt 1:a6dc717fb060 85 //-----------------------------------------------------------------
Mister_Lopez 4:56e903769e94 86 void initMPU9250()
Mister_Lopez 4:56e903769e94 87 {
Mister_Lopez 4:56e903769e94 88 // Initialize MPU9250 device
Mister_Lopez 4:56e903769e94 89 // wake up device
gusteibolt 10:577e1fc4453e 90 imu.writeByte(MPU9250_ADDRESS, PWR_MGMT_1, 0x00); // Clear sleep mode bit (6), enable all sensors
Mister_Lopez 4:56e903769e94 91 }
Mister_Lopez 4:56e903769e94 92
Mister_Lopez 4:56e903769e94 93 //-----------------------------------------------------------------
Mister_Lopez 4:56e903769e94 94
Muglug 17:f98597cd2efc 95 using namespace XBeeLib;
Muglug 17:f98597cd2efc 96
Mister_Lopez 4:56e903769e94 97 //-----------------------------------------------------------------
gusteibolt 0:73cd0cb02330 98 int main()
gusteibolt 0:73cd0cb02330 99 {
gusteibolt 7:ebaaff27840b 100 setup(); // Initial setups
gusteibolt 3:26aeff25f610 101
Mister_Lopez 4:56e903769e94 102 //Reading the analog input (Microphone) array = micro.read_u16();
Mister_Lopez 4:56e903769e94 103
Muglug 17:f98597cd2efc 104 XBeeZB xbee = XBeeZB(RADIO_TX, RADIO_RX, RADIO_RESET);
Muglug 17:f98597cd2efc 105 xbee.init();
gusteibolt 10:577e1fc4453e 106 time_stamp.start(); // Start timer
Mister_Lopez 4:56e903769e94 107
gusteibolt 0:73cd0cb02330 108 while (true) {
gusteibolt 3:26aeff25f610 109 queue.dispatch();
Muglug 17:f98597cd2efc 110
Muglug 17:f98597cd2efc 111 const uint8_t data[] = "Hello, XBees!";
Muglug 17:f98597cd2efc 112 const uint16_t data_len = sizeof data / sizeof data[0] - 1;
Muglug 17:f98597cd2efc 113
Muglug 17:f98597cd2efc 114 TxStatus txStatus = xbee.send_data_to_coordinator(data, data_len);
Muglug 17:f98597cd2efc 115 if (txStatus != TxStatusSuccess) {
Muglug 17:f98597cd2efc 116 printf("send_data_broadcast() failed with error %d\n", (int)txStatus);
Muglug 17:f98597cd2efc 117 }
gusteibolt 0:73cd0cb02330 118 }
gusteibolt 0:73cd0cb02330 119 }
gusteibolt 1:a6dc717fb060 120 //-----------------------------------------------------------------