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

Files at this revision

API Documentation at this revision

Comitter:
Overdrivr
Date:
Thu Feb 11 08:59:40 2016 +0000
Child:
1:b63db8e76533
Commit message:
demo of the telemetry library on NXP KL25Z that publishes the capacitive slider value and the accelerometer XYZ values

Changed in this revision

BufferedSerial.lib Show annotated file Show diff for this revision Revisions of this file
MMA8451Q.lib Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
telemetry.lib Show annotated file Show diff for this revision Revisions of this file
tsi_sensor.lib Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/BufferedSerial.lib	Thu Feb 11 08:59:40 2016 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/sam_grove/code/BufferedSerial/#779304f9c5d2
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/MMA8451Q.lib	Thu Feb 11 08:59:40 2016 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/quevedo/code/MMA8451Q/#7c9ab58f6af3
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Thu Feb 11 08:59:40 2016 +0000
@@ -0,0 +1,88 @@
+#include "mbed.h"
+#include "telemetry/driver.hpp"
+#include "tsi_sensor.h"
+#include "MMA8451Q.h"
+ 
+#define MMA8451_I2C_ADDRESS (0x1d<<1)
+
+DigitalOut led(LED1);
+
+struct TM_state {
+  float throttle;  
+};
+
+void process(TM_state* state, TM_msg* msg);
+
+int main()
+{   
+    // Instance the structure holding our application tuning parameters
+    TM_state state;
+    state.throttle = 0;
+    
+    // Instance Telemetry
+    Telemetry TM(&state);
+    // Connect our process function
+    TM.sub(process);
+    
+    // Some sensors to read
+    TSIAnalogSlider tsi(PTB16,PTB17,40);
+    MMA8451Q acc(PTE25, PTE24);
+    
+    led = 1;
+    
+    Timer tm_timer;
+    Timer print_timer;
+    Timer led_timer;
+    
+    tm_timer.start();
+    print_timer.start();
+    
+    for(;;)
+    {       
+        // update telemetry
+        if(tm_timer.read_ms() > 50)
+        {
+            tm_timer.reset();
+            TM.update();   
+        }
+        
+       
+        // publish accelerometer data
+        if(print_timer.read_ms() > 50)
+        {
+            print_timer.reset();
+            TM.pub_f32("touch",tsi.readPercentage());
+            
+            int16_t axis[3];
+            acc.getAccAllAxis(axis);
+            
+            TM.pub_i16("acc:x",axis[0]);
+            TM.pub_i16("acc:y",axis[1]);
+            TM.pub_i16("acc:z",axis[2]);
+            
+            TM.pub_f32("throttle",state.throttle);
+            
+        }
+        
+        if(led_timer.read_ms() > 500)
+        {
+            led_timer.reset();
+            led = (led == 0) ? 1 : 0;  
+        }
+    }
+}
+
+void process(TM_state* state, TM_msg* msg)
+{
+    float value = 0.f;
+    
+    // If the received frame topic matches "throttle"
+    if(strcmp(msg->topic,"throttle") == 0)
+    {
+        // If the payload type matches float32
+        if(emplace_f32(msg,&value))
+        {
+            state->throttle = value; 
+        }
+    }
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Thu Feb 11 08:59:40 2016 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/f141b2784e32
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/telemetry.lib	Thu Feb 11 08:59:40 2016 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/Overdrivr/code/telemetry/#b7a3ac7bcec8
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tsi_sensor.lib	Thu Feb 11 08:59:40 2016 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/Kojto/code/tsi_sensor/#976904559b5c