Introduction: Plotting Arduino (Microcontroller) Data
This instructable uses an Arduino UNO with a temperature sensor hooked up to the analog input pin. Every second it takes a reading and sends the data value over the serial channel where a software tool called MegunoLink plots the data.
Step 1: Set Up the Arduino Program
{TIMEPLOT:ChannelName|data|SeriesName|T|25.6}
{TIMEPLOT:ChannelName|data|SeriesName|2013/04/23 14:00|25.6}
I'll start by describing the top line, each packet needs to have a {} pair to indicate a special message. Following the first { is the keyword TIMEPLOT this tells MegunoLink that you want to plot using the Time Plot visualiser (time on the xaxis and data value on the yaxis). Following this is some text, in this case ChannelName. You would use this to separate out different plots. In this case if we are plotting a bunch of temperatures throughout a house you could call the channel "Temperatures". After the channel name there is a data key word, MegunoLink uses this to decode the message properly. Following this is some more text naming the series. This would be what room you are monitoring, for example "Kitchen". Then in this top example another key word T, this indicates to MegunoLink that you want to use the computer time as a timestamp. Alternatively if you have a real time clock you could send your own time. This is demonstrated in the bottom example (second line above).
So in Arduino world you could simply use this code:
Serial.println("{TIMEPLOT:Temperatures|data|Kitchen|T|25.6}");and it would plot 25.6 continuously using the computer time on the x-axis.
Generally you would want to do more than just send a single value so a simple function is the way to go. Below is a function that takes a float (25.6) and send it with the same format above.
void PlotKitchenTemperature(float data)<br>{ Serial.print("{TIMEPLOT:Temperatures|data|Kitchen|T|"); Serial.print(data); Serial.println("}"); }<br>
So putting all of this together here is an Arduino program which reads an analog channel connected to a temperature sensor and sends the temperature to MegunoLink.
const byte TempSensorPin = 0;<br>float CurrentTemperature = 0; unsigned long LastPlotTime = 0; void setup() { Serial.begin(9600); } void loop() { if((millis()-LastPlotTime)>1000) { LastPlotTime = millis(); //Save time for 1s logging //reads 0-1023V -> 0-40degC CurrentTemperature = analogRead(TempSensorPin)*(float)40/(float)1023; PlotKitchenTemperature(CurrentTemperature); } } void PlotKitchenTemperature(float data) { Serial.print("{TIMEPLOT:Temperatures|data|Kitchen|T|"); Serial.print(data); Serial.println("}"); }Now simply program your Arduino with this and we are ready to look at the MegunoLink side of things.
Step 2: Set Up MegunoLink Pro
MegunoLink Pro can be found at MegunoLink.com. There is a free trial to make sure it does what you want it to. Download and install the program on any Windows based machine (XP or higher, Windows 7 or higher for the Visual Studio Features).
Open up MegunoLink Pro and you will be greeted with the welcome screen shown above. On the right is the selection tool for all of the different visualisers. As well as plotting there is:
- Logging and monitoring tools
- A way to display tabular data
- A way to separate out messages for the general serial stream (debug stream for example)
- A way to program some Arduino devices
- A tool to plot points on a map from GPS coordinates
- A way to create user interfaces which send and receive serial commands
- And a tool to plot arbitrary x-y data
For this instructable we only want three visualisers. Click each one to open it up. First the Connection Manager, next the standard Monitor, and finally the Time Plot visualiser. They will open on top of each other however MegunoLink has a nifty docked interface. Just drag each tab to where you want it. The next step shows the layout I used.
Step 3: Plotting Data
The main things to consider here are the COM port and the baud rate. Set the COM port to match your Arduino and select the baud rate to match your program. If you have been following along the baud rate for this example is 9600. When that's done hit connect. (Currently it says disconnect in the screenshot because its already connected).
Next I draw your attention to the green boxes in the screenshot above. Here you need to select the connection you just set up. In the screenshot the connection was called "RS232 4" so this is selected on the Monitor and Time Plot visualisers. Data should start to arrive in the monitor from your Arduino formatted in say way we discussed earlier.
The final step is to select the plotting channel. On the Time Plot select the drop down (orange box in the screenshot) and select Temperatures. The plot should jump in to life and start plotting the temperature value as it comes in.
That wraps up this instructable. Hope its helpful!
Download MegunoLink Pro here.
Download the attached Arduino program and the MegunoLink save file to get started right away.