Getting Started 3 OwnPlot - owntech-foundation/Tutorials GitHub Wiki
Objective
The goal of this tutorial is to monitor a dummy variable via the serial port, using SerialPlot. We will start from the Serial Monitor Tutorial.
Required hardware
- O2
v_1_1_2
- STLinkV3
- PC 64-bits (windows or linux)
Required software
- Git
- Visual Studio Code with PlatformIO (see Blinky tutorial)
- Source control extension
We will use OwnPlot to monitor variables. Download OwnPlot by going to https://github.com/owntech-foundation/OwnPlot/releases. You will arrive at the page below.
Download and install the software according to your system.
In Windows, ...
In Linux, allow the appImage to be executed as a code.
Launch OwnPlot. Here is how it looks like when open.
Commit the changes in the project
-
In the side menu, click on the Source Control button, Which will open a new menu . You can see that the only changes on your code are located at the main.cpp file. We are going to commit these changes as to keep track of our progress.
-
Click on the
+
button on the right side of themain.cpp
file to "stage" the changes. You can add a comment to explain what these changes are useful for. It is good practice to describe your changes when you commit them in git. Click on the+ Commit
button. Your work has been committed, we can come back to it later if necessary.
Step-by-step implementation
- Define the variables
We will define a dummy variable that will be updated via the Serial.
In src/main.cpp
, in the section USER VARIABLE DECLARATIONS
, define the dummy variable counter
.
//--------------USER VARIABLES DECLARATIONS----------------------
static uint32_t counter = 0; //counter variable
- Configure the hardware peripherals
In src/main.cpp
, in the setup_hardware()
, do not modify anything.
- Configure the software scheduling
In src/main.cpp
, in the setup_software()
, do not modify anything.
- Loop communication task
In the communication task, you will create the possibility of increasing or decreasing the counter
dummy variable via the Serial Interface.
In src/main.cpp
, in the function loop_communication_task()
, add the following code.
void loop_communication_task()
{
received_serial_char = console_getchar();
switch (received_serial_char) {
case 'h':
//----------SERIAL INTERFACE MENU-----------------------
printk(" _____________________________________\n");
printk("| ------- MENU --------- |\n");
printk("| press i : idle mode |\n");
printk("| press s : serial mode |\n");
printk("| press u : counter UP |\n");
printk("| press d : counter DOWN |\n");
printk("|_____________________________________|\n\n");
//------------------------------------------------------
break;
case 'i':
printk("idle mode\n");
mode = IDLEMODE;
break;
case 's':
printk("serial mode\n");
mode = SERIALMODE;
break;
case 'u':
counter++;
break;
case 'd':
counter--;
break;
default:
break;
}
}
- Loop application task
The application task will print the value in the counter
dummy variable whenever the SERIALMODE
is ON.
In src/main.cpp
, in the function loop_application_task()
, add the following code.
void loop_application_task()
{
if(mode==IDLEMODE) {
hwConfig.setLedOff();
}else if(mode==SERIALMODE) {
hwConfig.setLedOn();
printk("%d\n", counter);
}
scheduling.suspendCurrentTaskMs(100);
}
- Loop control task
In src/main.cpp
, in the loop_control_task()
function, do not modify anything. This control task will remain empty for this tutorial.
- Connect hardware (see Blinky tutorial)
- Connect the USB power supply cable. The LED2 of the O2 should be ON.
- Connect the micro-JTAG connector of the O2 to the PC thanks to the STLinkV3.
-
Build and Upload (+ ).
-
In the bottom toolbar, click on the Serial Monitor icon . Select it and press the
h
key. Press thes
key: you should see the current value ofcounter
on the Serial Monitor.
Expected outputs
- Press the
i
key to switch to IDLEMODE: stop printingcounter
and turns the LED1 OFF. - Press the
s
key to switch to SERIALMODE: printscounter
and turns the LED1 ON. - Press the
u
key to increase thecounter
. - Press the
d
key to decrease thecounter
.
OwnPlot Visualization
-
We will now visualize the value of
counter
using OwnPlot, instead of the Serial Monitor. -
First kill the Serial Monitor by clicking on the trash button on the right hand side of the window as shown in the image below.
- Launch OwnPlot. In Port tab, choose the STLinkV3. Click on the
Closed
button to open the port.
:warning: The Port might have a different name depending on your operating system.
- In OwnPlot, Settings tab, set the
# of channels
to 1.
- In OwnPlot, in the Chart tab, change the same of
Dataset 1
toCounter
.
- In OwnPlot, in the Send tab, add the commands below by typing the command name and its associated character.
- In OwnPlot click on the
Serial
button corresponding to thes
command to switch to SERIALMODE and turn the LED1 ON. You should see the value ofCounter
on your OwnPlot window and its raw value on the terminal below. You can increase and decrease thecounter
, by clicking onUp
andDown
buttons. OwnPlot will automatically update the size of the window as you change the value of the variable.
- In OwnPlot, click on the
Idle
button corresponding to thei
command to switch to IDLEMODE and turn the LED1 OFF. OwnPlot stops displaying the value ofcounter
and the window will continue to scroll since the port is still open.
That’s it!
Contributors
- 2021.11.04: Romain Delpoux, Loïc Quéval, Adrien Prévost
- 2021.11.07: Luiz Villa, Antoine Boche
- 2022.01.24: Luiz Villa, Loïc Quéval
- 2022.02.01: Luiz Villa
- 2022.02.22: Luiz Villa
- 2022.03.13: Luiz Villa
- 2022.06.23: Loïc Quéval, Romain Delpoux
- 2022.01.16: Luiz Villa