Plot a processed signal coming from Arduino COM port in real time is a useful practice when working with sensors. Also this makes a great feature to present or show your proyect to others. Arduino code-debugging is another reason: Many of us only use single delays and Serial.println to figure out what is happening on the board. Here I am going to explain one simple solution without the need of writing a custom script, which could be the smarter solution to work with sensors.
To overcome this, the problem is split into two parts: first, we need to write the incoming data from the COM port into a CSV file (comma separated value file). Later we plot the data stored in this file on the real time plotter kst.
Get FREE Credit for your next AirBnb Reservation by opening a new account (even if you already have one!)
Write the data from COM port into a CSV File
1. To write the data coming from the COM port into a CSV you will need to install a software like RealTerm. There are more other programs that allow you to do this, but I used this one. A better and more advanced solution should be to write a script to do it directly, but here I will show how to do it without programming an special script. This program is an alternative to Putty, this serial terminal which came with windows.
Note that you can not have two serial connections opened at the same time. For example, if you are using the Arduino IDE Serial monitor, you are not allowed to open Putty or Realterm and vice-versa. Only one client can be connected at one time. Therefore, if you want to load an Arduino program into the board, you have to deactivate the connection with Realterm and vice-versa.
2. Open Realterm and configure the COM port that you are using with the Arduino. This can be seen at Tools>> Serial Boards. In RealTerm on the tab of “Echo Port”. We can manage and change the serial port.
Remember that to start reading the data and writing into the selected file, you have to check the box “Monitor” on the “Echo Port” tab. After the change don’t forget to push the button”Change” to save.
3. On the tab “Capture” of RealTerm, now select or create a new file to write the data and check the “Direct capture” box.
4. To start the writing, once your Arduino is already streaming data to the serial port, go to the tab “Capture” and push “Start : “Overwrite” or “append”, depending if you want to overwrite or append the new data.
To print your data “cleanly” print the data without text, for example:
While Realterm is writing to the file, the GUI should appear in red colour.
Plot the data from a CSV file
1.Download the free and open source kst program (available to all the platforms: Windows, Mac and linux). Follow the instructions to complete the instalation .
2. Execute the program. If you are using linux, you have to call the following command to open the GUI:
Also is possible to call kst from a python script. For that use:
subprocess.Popen[("kst2")] #open the real time plotter
If you want to open a saved kst configuration file, which have to be in the root folder:
subprocess.Popen[("kst2", "myKSTfile.kst")] #open the real time plotter
3. Open the data wizard and go thorugh as it is explained on the pictures.
5. ASCII configuration. Here you have to say to the program how to interpret the file. This configuration depend on your file. The most important parameters are selected with red.
6. Select your which data you want to plot. If your file has a header on the first row with the field names and you have selected “Read field names from line” on the previous step, now you should see the names. If not, you will see “column 1″, Column 2”, etc… Kst always generates an automatic column called INDEX, which is the numbers 0, 1, 2, 3… useful to use on the x-axis.
Select all the columns you want to plot on the correct order and press next.
7. Data range. Usualy, you want to plot real time data, so you want to show the last X samples available in your file. For this you have to choose “count from end” and put range between 200 and 500 depending on the speed you read the data. This can be changed later.
Put on the X-axis the INDEX column.
8. Layout configuration. Leave this as default and later you can change what you like. Here I like to remove the legends of each plot to have a better view. This only makes sense if you plot more than one curve per graph.
The final plot look like:
Another view of kst with more plots:
After changing your visualisation, parameters, etc you can save the configuration as a *.kst file. You will save many time for the next time.