-
Notifications
You must be signed in to change notification settings - Fork 27
Tutorial (Arduino)
This tutorial will guide you on how to use Telemetry
on your Arduino.
By the end of this tutorial, you will able to receive any kind of data from the Arduino, plot it in a graph, send data to the Arduino and update some variables in real-time.
If you don't know yet how to install Telemetry
on Arduino, see the previous tutorial.
In a first time, we will only send some data, for instance, the value of a variable, from the Arduino.
With Telemetry, sending data is called publishing
.
In your blank .ino file, import the library and instanciate it.
#include <Telemetry.h>
Telemetry TM;
Initialize it. By default, Telemetry
will configure the serial port (UART) a baudrate of 9600 bauds.
void setup() {
TM.begin(9600);
}
In the loop function, let's publish a string continously.
void loop() {
TM.pub("Hello","world");
delay(1000); // wait for a second
}
In this example, we have only published a string. This can be useful for sending error messages to the computer.
Note: By default, do not send strings that are longer than 128 characters, otherwise they will be truncated.
If you connect to the device with pytelemetrycli, you can run a few commands to observe the result desktop-side: todo : animated ttty gif
>: ls -s
# Will list all available ports. Take the one for Arduino
>: serial comXX
Connected to port comXX at [9600] bauds
>: ls
Hello
>: print Hello
World
Note: In writing
Example from the Telemetry-examples repository: At this point, you know how to send data from the device to the computer.
The other way around is just as simple.
telemetry
lets you attach any variable to a given topic.
Every time a new value under the given topic is received, the attached variable will be updated (if received type and variable type match). This is called subscribing a variable to a topic.
uint8_t myInc = 0;
Telemetry TM;
void setup() {
TM.begin(9600);
// Subscribe myInc variable to topic "foo"
TM.attach_u8_to("foo",&myInc);
}
void loop(){
TM.update();
}
In this code, the variable myInc is updated with any new value received under topic "foo" with a payload of type uint8. The update is performed during TM.update().
You can attach all standard integer types and float numbers to any topic using this method.
At this point, you are now able to exchange data with a computer in both ways, with minimal efforts.
You may want to check at this point more advanced features or the list of examples.
Back Wiki home
- Fast data visualization with the command line interface (todo)
- Fast prototyping remote program control with python (todo)
- Overview of the library
- Protocol description
- All the good stuff inside Telemetry
- List of supported platforms
- Good practices (Must-read !) in writing
- Frequently Asked Questions todo
- List of official examples
- List of projects using telemetry