A demo on NXP KL25Z of the telemetry library to publish some sensor data that can be read/plotted on the computer using pytelemetrycli (https://github.com/Overdrivr/pytelemetrycli) Published data: "touch" -> capacitive slider output value "acc:x" -> x channel of the accelerometer "acc:y" -> y channel "acc:z" -> z channel
Dependencies: BufferedSerial MMA8451Q mbed telemetry tsi_sensor
main.cpp
00001 #include "mbed.h" 00002 #include "Telemetry.hpp" 00003 #include "tsi_sensor.h" 00004 #include "MMA8451Q.h" 00005 00006 #define MMA8451_I2C_ADDRESS (0x1d<<1) 00007 00008 /* 00009 Example of the 'Telemetry' library, a portable communication library for embedded devices. 00010 00011 This code fetches all the data from the KL25Z bord and publishes it on different topics : 00012 00013 The available data is the following : 00014 * Accelerometer X 00015 * Accelerometer Y 00016 * Accelerometer Z 00017 * Capacitive slider 00018 00019 You can use the Pytelemetry Command Line Interface to open plots, visualize the received data, 00020 and communicate with the car. 00021 See https://github.com/Overdrivr/pytelemetrycli 00022 */ 00023 00024 00025 DigitalOut led(LED1); 00026 00027 int main() 00028 { 00029 Telemetry TM(115200); 00030 00031 // Some sensors to read 00032 TSIAnalogSlider tsi(PTB16,PTB17,40); 00033 MMA8451Q acc(PTE25, PTE24); 00034 00035 led = 1; 00036 00037 // Some timers 00038 Timer tm_timer; 00039 Timer print_timer; 00040 Timer led_timer; 00041 00042 tm_timer.start(); 00043 print_timer.start(); 00044 led_timer.start(); 00045 00046 // To store accelerometer values 00047 int16_t axis[3]; 00048 00049 for(;;) 00050 { 00051 // update telemetry 00052 if(tm_timer.read_ms() > 50) 00053 { 00054 tm_timer.reset(); 00055 TM.update(); 00056 } 00057 00058 00059 // publish accelerometer data 00060 if(print_timer.read_ms() > 50) 00061 { 00062 print_timer.reset(); 00063 TM.pub_f32("touch",tsi.readPercentage()); 00064 00065 acc.getAccAllAxis(axis); 00066 00067 TM.pub_i16("acc/x",axis[0]); 00068 TM.pub_i16("acc/y",axis[1]); 00069 TM.pub_i16("acc/z",axis[2]); 00070 } 00071 00072 if(led_timer.read_ms() > 500) 00073 { 00074 led_timer.reset(); 00075 led = (led == 0) ? 1 : 0; 00076 } 00077 } 00078 }
Generated on Wed Jul 13 2022 17:03:31 by 1.7.2