Search…
Understanding TotalCross for Linux ARM
TotalCross now supports embedded systems!

Introduction

See at this guide:
  • Discover plugin for VS Code;
  • Getting your Hello World App cooler;
  • How to deploy;
  • After basics;

Requirements

Complete the Getting 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:
1
$ sudo apt-get install libgpiod-dev
Copied!

Guide

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;
Click to expand
Step 7: openRunHelloWorldApplication.java and click Run (IDE). The result should be:
Click to expand
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:
1
// Integers to store pin numbers
2
private int R = 4, G = 17, B = 27, pushButton = 18;
3
// Integers to store state of each LED pin, 0 (LOW) and 1 (HIGH)
4
private int sttR, sttG, sttB;
5
// Buttons to control colors
6
private Button btnR, btnG, btnB;
Copied!
If you need to work with different pinouts check the manufacturer manual!
Step 3: at HelloWorld.java in initUI() code add:
1
// Label helloWorld made on project creation
2
Label helloWorld = new Label("Hello World!");
3
// Change the position of label on the Y axis, with TOP (beginning of Y) + a fill of 20
4
add(helloWorld, CENTER, TOP + 20);
Copied!
Step 4: then, board setup:
1
// Board Setup
2
GpiodChip gpioChip = GpiodChip.open(0);
3
GpiodLine pinR = gpioChip.line(R);
4
GpiodLine pinG = gpioChip.line(G);
5
GpiodLine pinB = gpioChip.line(B);
6
GpiodLine pinPushButton = gpioChip.line(pushButton);
Copied!
Step 5: pins setup:
1
// Set LED pins as outputs and default value sttX
2
pinR.requestOutput("CONSUMER",sttR);
3
pinG.requestOutput("CONSUMER",sttG);
4
pinB.requestOutput("CONSUMER",sttB);
5
// Set Reset pin as input
6
pinPushButton.requestInput("CONSUMER");
Copied!
Step 6: the red button:
1
// The TotalCross button:
2
btnR = new Button("R"); // Button instantiation
3
// without text
4
btnR.setBackColor(Color.RED); // Set background color (red)
5
btnR.addPressListener(new PressListener() { // Press event listener
6
@Override
7
public void controlPressed(ControlEvent controlEvent) {
8
sttR = 1 - sttR; // Invert pin state
9
pinR.setValue(sttR); // Set value (HIGH or LOW)
10
}
11
});
12
add(btnR, CENTER - 70, AFTER + 40); // To make horizontally aligned
13
// buttons in the 'RGB' sequence,
14
// take the center reference and
15
// decrease 70 to place the
16
// leftmost R. In the Y axis just
17
// take the reference of the
18
// previous component and add 40
Copied!
Step 7: and the other buttons:
1
btnG = new Button("G");
2
btnG.setBackColor(Color.GREEN);
3
btnG.addPressListener(new PressListener() {
4
@Override
5
public void controlPressed(ControlEvent controlEvent) {
6
sttG = 1 - sttG; // Pay attention to change pin!!!
7
pinG.setValue(sttG);
8
}
9
});
10
add(btnG, CENTER, SAME); // The green button will be
11
// placed at the center and in
12
// the same line of previous
13
// button
14
15
btnB = new Button("B");
16
btnB.setBackColor(Color.BLUE);
17
btnB.addPressListener(new PressListener() {
18
@Override
19
public void controlPressed(ControlEvent controlEvent) {
20
sttB = 1 - sttB; // Pay attention to change pin!!!
21
pinB.setValue(sttB);
22
}
23
});
24
add(btnB, CENTER + 70, SAME); // The last button will be placed
25
// to the right of the center.
Copied!
Step 8: finally we use a thread to check the state of the reset button:
1
// A thread will be used to check every 20 ms, if the reset button has been pressed: if yes then
2
// the pin state goes to LOW
3
new Thread() {
4
@Override
5
public void run() {
6
while(true){
7
if(pinPushButton.getValue() == 1) {
8
sttG = 1 - sttG;
9
sttR = 1 - sttR;
10
sttB = 1 - sttB;
11
pinR.setValue(sttR);
12
pinG.setValue(sttG);
13
pinB.setValue(sttB);
14
}
15
Vm.sleep(100);
16
}
17
}
18
}.start();
Copied!
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!
Bruno Muniz, Lucas Galvanini e Pedro Lyra no WebSummit

References