This tutorial will explain how you can develop a simple application with Apache NuttX RTOS and the LVGL graphics library. But first, let me show you the board we'll be using.,
The ESP322432S028 board is based on the ESP32 Wrover SoC, built from SunStore. This low-cost development board aims to create graphical applications such as stream desks, analyze charts, visualize data sensors, etc. Additionally, this board has a low-cost built-in RGB LED, SD card slot, GPIO connections, LDR, and speaker output.
Our application will demonstrate how to use a rotary encode to control the value of the gauge and show the current percent.
Before we start, follow these steps to set up your machine.
Hands-onFirst, let's understand what a quadrature encoder is (Figure 2) it's an encoder with two output channels, one of which is offset by 90 degrees electrical signal or a quarter cycle. The allowed out-of-phase signal identifies the direction in which the shaft is rotating (clockwise or counterclockwise).
Looking more closely you notice this model has five pins:
- +: positive voltage
- GND: negative voltage
- SW: switch output
- DT/CLK: signal output
Notice on the back of the board that you should find something similar to Figure 3. We will use the connector labeled CN1. The connection with the encode will be disposed of like this:
- + to 3.3V
- GND to GND
- DT to GPIO 22
- CLK to GPIO 27
It's important to inform you that, you may need a JST connector 4 vias.
The schematic should follow the connection below (Figure 3):
Download NuttX and Apps
$ mkdir nuttxspace
$ cd nuttxspace
$ cd git clone https://github.com/apache/nuttx
$ cd git clone https://github.com/apache/nuttx-apps apps
Download the App and create a copy into apps/examples
$ git clone git@github.com:halyssonJr/NuttX-Tutorial.git
$ ls
apps nuttx NuttX-Tutorial
$ cd NuttX-Tutorial/
$ cp -R lvgl_encoder ../apps/examples
Select the board configuration
$ cd nuttx
$ make distclean
$ ./tools/configure.sh esp32-2432S028:lvgl
$ make menuconfig
Enable the Quadrature Encoder Peripheral
System Type --->
ESP32 Peripheral Selection --->
[*] Pulse Counter (PCNT / QE) Module
- Exit and move down to "Pulse Counter (PCNT) Configuration" :
- Select "Enable PCNT Unit 0" and setup as below:
Enable the Generic Quadrature Encoder Driver
Device Drivers --->
[*] Sensors Driver Support --->
[*] Qencoder
Enable the Demo
Application Configuration --->
Examples --->
[*] LVGL Encoder demo
After setup, go back to the main menu and save the configuration.
Compile and Flash
$ make bootloader
$ make -j8
$ make download ESPTOOL_PORT=/dev/ttyUSB0 ESTOOL_BINDIR=.
Once this part is complete, let's interact with NSH to start the application, you can use picocom, minicom, or another software for your preference. Type ?
to access the help commands and built-in apps. You will see three applications available (nsh, sh, and lvencon). To run our application type: lvencon
$ picocom -b 115200 /dev/ttyUSB0
NuttShell (NSH) NuttX-12.4.0
nsh> ?
help usage: help [-v] [<cmd>]
. cp exit mkdir rmdir umount
[ cmp expr mkrd set unset
? dirname false mount sleep uptime
alias dd fdinfo mv source usleep
unalias df free pidof test xd
basename dmesg help printf time
break echo hexdump ps true
cat env kill pwd truncate
cd exec ls rm uname
Builtin Apps:
lvencon nsh sh
nsh> lvencon
Arc value = 0
Now, we can play with our application. Have fun!
Comments