Understanding TotalCross for Linux ARM

TotalCross now supports embedded systems!


See at this guide:

  • Discover plugin for VS Code;

  • Getting your Hello World App cooler;

  • How to deploy;

  • After basics;


Complete the Getting Started:

pageGetting Started

The following electronic components are also required:

  • Raspberry Pi 3;

  • 7x jumpers male-female;

  • Protoboard;

  • LED RGB module (or common 4 pins LED RGB);

  • Push-button module (or common push-button).

In order to execute Gpiod methods at your embedded device, you will also need to have the libgpiod-dev package installed in your board. You can do that by entering the following command at the device's terminal:

$ sudo apt-get install libgpiod-dev


Discover VS Code plugin

A quick way to start using TotalCross is installing the TotalCross extension for VS Code.

Step 1: open VS Code console (CTRL + Shift + P) and type TotalC… autocomplete should help!

Step 2: select TotalCross: Create new Project;

Step 3: create a folder called HelloWorld and select it;

Step 4: GroupId will be com.totalcross;

Step 5: ArtifactId will be HelloWorld;

Step 6: select the latest version of TotalCross SDK and -linux-arm platform;

Step 7: openRunHelloWorldApplication.java and click Run (IDE). The result should be:

Step 8: watch the integrated simulator!

Getting your Hello World App even more Cooler 🥶 😅

The following project deals with the control of an RGB LED with user interface buttons and a pin reset button!

Step 1: follow the schematic:

Step 2: to work with pin logic after public class HelloWorld extends MainWindow { add:

// Integers to store pin numbers
private int    R = 4, G = 17, B = 27, pushButton = 18;
// Integers to store state of each LED pin, 0 (LOW) and 1 (HIGH)
private int    sttR, sttG, sttB;
// Buttons to control colors 
private Button btnR, btnG, btnB;

If you need to work with different pinouts check the manufacturer manual!

Step 3: at HelloWorld.java in initUI() code add:

// Label helloWorld made on project creation
Label helloWorld = new Label("Hello World!");
// Change the position of label on the Y axis, with TOP (beginning of Y) + a fill of 20
add(helloWorld, CENTER, TOP + 20);

Step 4: then, board setup:

// Board Setup
GpiodChip gpioChip = GpiodChip.open(0);
GpiodLine pinR = gpioChip.line(R);
GpiodLine pinG = gpioChip.line(G);
GpiodLine pinB = gpioChip.line(B);
GpiodLine pinPushButton = gpioChip.line(pushButton);

Step 5: pins setup:

// Set LED pins as outputs and default value sttX
// Set Reset pin as input

Step 6: the red button:

// The TotalCross button:
btnR = new Button("R");                                       // Button instantiation
                                                              // without text
btnR.setBackColor(Color.RED);                                 // Set background color (red)
btnR.addPressListener(new PressListener() {                   // Press event listener
    public void controlPressed(ControlEvent controlEvent) {
        sttR = 1 - sttR;                                      // Invert pin state 
        pinR.setValue(sttR);                                  // Set value (HIGH or LOW)
add(btnR, CENTER - 70, AFTER + 40);                           // To make horizontally aligned 
                                                              // buttons in the 'RGB' sequence,
                                                              // take the center reference and 
                                                              // decrease 70 to place the 
                                                              // leftmost R. In the Y axis just
                                                              // take the reference of the
                                                              // previous component and add 40

Step 7: and the other buttons:

btnG = new Button("G");
btnG.addPressListener(new PressListener() {
    public void controlPressed(ControlEvent controlEvent) {
        sttG = 1 - sttG;                                      // Pay attention to change pin!!!
add(btnG, CENTER, SAME);                                      // The green button will be 
                                                              // placed at the center and in 
                                                              // the same line of previous 
                                                              // button

btnB = new Button("B");
btnB.addPressListener(new PressListener() {
    public void controlPressed(ControlEvent controlEvent) {
        sttB = 1 - sttB;                                       // Pay attention to change pin!!!
add(btnB, CENTER + 70, SAME);                                  // The last button will be placed 
                                                               // to the right of the center.

Step 8: finally we use a thread to check the state of the reset button:

// A thread will be used to check every 20 ms, if the reset button has been pressed: if yes then 
// the pin state goes to LOW
new Thread() {
    public void run() {
            if(pinPushButton.getValue() == 1) {
                sttG = 1 - sttG;
                sttR = 1 - sttR;
                sttB = 1 - sttB;

Step 9: run RunHelloWorldApplication.java again and watch the results!

View fully code here

How to deploy

Step 1: open VS Code console (CTRL + Shift + P) and select TotalCross: Deploy

Step 2: a second dialog box will appear and just fill in the board's information:

Step 3: see the results in screen or VNC

After basics

This was the beginning of application development for TotalCross embedded systems, how about taking a look at TCSample and seeing all that can be done? See dashboard made especially for Web Summit 2019:

See more

Are you interested in development with embedded systems? Contact us via Telegram!


Last updated