OctoPrint for the Seeed Studio reTerminal – Live Blog – Day 11

This post is a series of posts in which I detail my journey to bring OctoPrint to the Seeed Studio reTerminal.

Day 11

In today’s post we’ll be digging in to how to use the reTerminal User Buttons with OctoPrint and the TouchUI Plugin.

Contents

The reTerminal User Buttons – 16-09-2022

As I pointed out yesterday, the first place to start is the GitHub repo for the Seed Studio reTerminal Python Library.

This repo is described as;

This is a Python library which enables you to use the onboard hardware on the reTerminal and reTerminal Bridge.

Currently the accelerometer, user LEDs, user buttons and buzzer can be accessed using this Python library on reTerminal, and the fan, RS232, RS485, CAN can be accessed by using this Python library on reTerminal Bridge.

Again, this is a Python Library, so that’s handy for us as OctoPrint is written in Python. However, we need to figure out primarily how we integrate this Python Library and OctoPrint from a BackEnd / FrontEnd perspective.

Of course, we do know that it’s possible to develop directly on a Raspberry Pi with OctoPrint installed. Further, the CM4 is a very capable devices, so it’s possible we’ll have a reasonable experience to be fair.

I think the first thing we should do though is to make sure the User Buttons work on our reTerminal…

The reTerminal App

We can actually see the buttons working already using the reTerminal App that comes preinstalled on the device;

reTerminal App

Interestingly, I’ve just noticed that this app has an uppercase R for ReTerminal rather than a lowercase one like I’ve been using the whole way through this blog post series.

Checking the official site for the Re/reTerminal;

Seeed Studio reTerminal

Phew… I was using the official styling… Interesting then that the app uses something different… Hey ho.

Firing up the ReTerminal app;

reTerminal App – Home Screen

The first thing we see is the Home Screen, showing the version information of our device etc…. Very handy.

The next tab gives us a wonderful looking graphical representation of the CPU Usage, RAM Usage, CPU Temperature and Storage Usage;

reTerminal App – Stats Tab

The next tab gives us access to the onboard sensors and buttons as well as an area showing us the Touch Panel details;

reTerminal App – Buttons and Sensors Tab

Pressing the F1 button;

reTerminal App – F1 Button Pressed

I can see this repeated for the other buttons, as well as a view of where the touchscreen has been pressed along with how many simultaneous touches are registered;

reTerminal App – Touch Screen Touches

Waving my hand in front of the reTerminal affects the Light Sensor graph;

reTerminal App – Light Sensor

While rotating or moving the device changes the 3-Axis Accelerometer graph;

reTerminal App – 3-Axis Accelerometer

The next tab down in the HMI Configuration tab;

reTerminal App – HMI Configuration

Here we can see some sort of Human Machine Interface example. As far as I can see, this tab doesn’t actually have any functionality, but I might be missing something?

The final tab is Settings, where we can control the various reTerminal and essentially Raspberry Pi interfaces;

reTerminal App – Settings

We’ve already got everything turned on here, which I think I did during the IoTeaLive stream.

Trying the reTerminal Python Library Samples

Now that we know our buttons are working correctly, let’s dial in to the reTerminal using SSH, create a folder for our samples, and start playing.

I guess we could actually clone the GitHub Repo, install the python package and use the samples that are included in the repo.

I do wonder then if we should be creating a virtual environment too though. I think for one library, we’ll be ok… I’m betting it’s already installed system wide by default anyway!

Using a Terminal Window we can SSH into our reTerminal using the hostname we have it during the IoTeaLive stream, along with the default user name of pi and password of raspberry;

reTerminal – SSH Session

Doing a quick dir;

reTerminal – Home Directory

We can see we have our OctoPrint directory as a result of installing that during IoTeaLive, but we also have a Seed_Python_ReTerminalQTExamples directory too.

Doing a search in the Seeed Studio GitHub Account;

Seeed Studio GitHub Repo – reTerminal

We can see there are three repos with some examples;

The Face Recognition demo looks really interesting;

reTerminal Face Recognition Demo

reTerminal CSI Camera Investigations

It does remind me that, I also need to figure out how to get the Raspberry Pi camera working with this setup too.

reTerminal Camera Cutout

There appears to be a cutout for the Raspberry Pi Camera on the rear of the device

The specs intimate that there’s support for the camera;

reTerminal Raspberry Pi Camera Support

Then looking at the actual board, we can see there is indeed a CSI Camera Port;

reTerminal CSI Camera Port

I’ll add that to the list of things to do!

reTerminal Python Samples

Returning to the reTerminal Python Samples, let’s clone the python repo on our reTerminal itself with;

git clone https://github.com/Seeed-Studio/Seeed_Python_ReTerminal.git
Cloned reTerminal Python Repo

Entering the new directory and doing a dir shows us what we’ve cloned;

reTerminal Python Samples Repo Directory

Let’s also install the latest compiled version using;

sudo pip3 install seeed-python-reterminal
reTerminal Installed Python Samples using pip

Let’s navigate into the samples folder and run the test_button.py file;

Run Test button Python File

Using just the python command doesn’t work here, we need to use python3.

Let’s try pressing the buttons now;

reTerminal Sample shows Button Presses

We can see we have two events per button, where it’s recording the press and release events, which is mega eh.

The code for this looks pretty simple too;

#!/usr/bin/env python3

import seeed_python_reterminal.core as rt
import seeed_python_reterminal.button as rt_btn


device = rt.get_button_device()
while True:
    for event in device.read_loop():
        buttonEvent = rt_btn.ButtonEvent(event)
        if buttonEvent.name != None:
            print(f"name={str(buttonEvent.name)} value={buttonEvent.value}")

Pretty easy to integrate from a code perspective… So how do we get this to work with OctoPrint.

Thoughts on using Buttons with OctoPrint

The first thing we need to figure out is what we want the buttons to actually do…

There are 4 buttons for us to make use of;

reTerminal User Buttons

Where we have F1, F2, F3 and a green button with a circle on it… I wonder what its name is?

We know the main TouchUI interface looks like this;

reTerminal – TouchUI Interface

So, as we have at least 6 tabs to navigate, we can’t just use a one-to-one button to tab relationship.

So, we’ll need a next tab, previous tab type idea I guess, which means we’ll have a couple of buttons left over too.

That’s it for today… Tomorrow we’ll create our new plugin, install the Seeed Python Package, see if we can read the buttons and show the values in the console… From there we can see if we can add some control to the UI with them.

Leave a Reply