LEO Software

Possible to implement 3 GPIO Buttons in comming Firmware ?

1 = ON/ OFF over Webbrowser
2 = ON/ OFF over Webbrowser
3 = Pulse ON /OFF 0,3s

Need for Lighting System.

We’re not planning to add such functionality at the moment, but you can implement new features by yourself. Let me know and I can guide you through it.

Thats nice. I have have no plan :slight_smile:

When you have time, you can write a litle guide. I will implement by self.

You will first need to prepare your environment:

  1. Install git and Visual Studio Code.
  2. Open Visual Studio Code and install Husarion extension ([Ctrl]+[Shift]+[X] and find "Husarion"). Restart Code
  3. Using git, clone leo_firmware repository and add it to your workspace in Code.
  4. Check if you can succesfully build the project. Open main.cpp file and type [Ctrl]+[Shift]+[B]. If everything is correct, leo_firmware.hex file should appear in your workspace.

Now you can start to modify the firmware to your needs.
Let’s start with the 3rd option. I’m assuming you want an output pin which changes the state (between high and low) every 0.3s

Put this function before hMain:

void GPIO3Loop()
	// Sets pin 2 on hExt port mode to output
	// pin 1 is already used for informative LED (you can change it in param.h file)

	// Gets system time
    uint32_t t = sys.getRefTime();

	// Specifies the pulse duration in ms
	long dt = 300; 	

	while(true) //infinite loop
		// waits for the next pulse cycle
		sys.delaySync(t, dt);

		// changes state on pin to opposite

In hMain, before while loop, type:


Build the project and flash it. You can flash it from raspberry pi like described here or using Husarion extension in VSC ([Ctrl]+[Shift]+[P] and select “Flash project to CORE2”)

Now you can connect your electric circuit. You can read more about the board’s pinout here

If this guide was helpful to you, I can write a second one (about the 1st option)

Thanks for the instructions

However, it’s just about a simple I / O control. Controllable via the HTML page. 2GPIO with ON / OFF button and the third Gpio only as Pulse. Quasi Button pressed = GPIO High —> Button Release = GPIO LOW. I’ve got that on my module relatively easy with Flask via Websocket. So without firmware … That’s the real problem. Nowhere is it clear how to do it. With Flask and Python no problem - but via Husarion ???.

When i “RUN BUILD TASKS” in VSC — Is the HEX File also automatic updated ?

When i “RUN BUILD TASKS” in VSC — Is the HEX File also automatic updated ?
However, it’s just about a simple I / O control. Controllable via the HTML page. 2GPIO with ON / OFF button and the third Gpio only as Pulse. Quasi Button pressed = GPIO High —> Button Release = GPIO LOW.
I get that you want to do WebUI <-> firmware communication (I just wanted to start with something simpler).

We use ROS to send messages components, so you need to write a ROS subscriber in your firmware.

First, we need to include the message type you want to use. The most logical would be to use a boolean value (true -> GPIO High, false -> GPIO Low). So add this line at the top of main.cpp file (after including ros.h):

#include "std_msgs/Bool.h"

Declare ROS subscriber that takes Bool messages:

ros::Subscriber<std_msgs::Bool> *gpio2_sub;

Add the following function before initROS:

void gpio2Callback(const std_msgs::Bool& msg)

The function will be called for every received message. msg.data is the boolean value.
Now, we need to initialize the subscriber. In initROS add:

gpio2_sub = new ros::Subscriber<std_msgs::Bool>("/gpio2", &gpio2Callback);	

We also need to set the pin to output mode. In hMain add this line:


Here’s a modified main.cpp: https://pastebin.com/2GChWacq
Build and flash the firmware.

Before adding the buttons to WebUI, let’s test if the new functionality works.
Log in to your Raspberry Pi and type:

rostopic list

You should see a list of available topics. The /gpio2 topic should appear in this list. You might need to restart ROS nodes (sudo systemctl restart leo).
To set GPIO to High state, type:

rostopic pub /gpio2 std_msgs/Bool -- True

For low state, change True to False

Now for the Webui, we use roslibjs to send ROS messages to RPi (I’m assuming you use leo_ui and not your custom UI).
You will need to edit leo.js file (should be located in /opt/leo_ui/js/).

To initialize ROS publisher, declare variable at the top of the file:

var gpio2Pub;

And in initROS add the following:

gpio2Pub = new ROSLIB.Topic({
    ros: ros,
    name: "/gpio2",
    messageType: `std_msgs/Bool`,
    queue_size: 1

And add somewhere these functions:

function gpio2High() {
    msg = new ROSLIB.Message({
        data: true

function gpio2Low() {
    msg = new ROSLIB.Message({
        data: false

Now, you can open the UI in your browser, open Developer Console ([Ctrl] + [Shift] + [J] in google chrome) and run these functions (gpio2High() and gpio2Low()).

Now, what’s left is to add buttons to the UI that run these functions.

I’m sorry for the lack of tutorials on our docs page. This should change in the near future

A big thank you. Now things are getting clearer. I’m already busy progging and it works. Is quite difficult … but feasible. I once created a flowchart to illustrate the way. Incidentally, I try to put a recording function via HTML5 (Stream Recording) on ​​the surface - but it does not quite want it. But it starts to be great fun. Unfortunately my laptop does not like Ubuntu properly (Nvidia driver) otherwise I would try out Rvitz and CO. But come time, come advice.

I have one more question. I use 2 Raspberry in my Leo rover. Thus, I have a 2nd camera steam and can independently experiment something. In my software, I would like to be able to move the Leo - almost an interface to the Leo software. I thought so with the existing joystick. How do I best do that? I would have to somehow link the Leo J.S - no idea how. The IP of the 2nd Raspberry is

Many thanks for your help