There are two firmwares involved with creating the CTR2 HMI. The first runs on the Teensy 4.1 development board on the HMI board and provides the core functionality of the HMI. The second runs on the Nextion display and provides the majority of the user interface. This post will explain how to set up your programming environments so you can examine, modify, and upload firmware to these devices.
HMI – TEENSY 4.1 FIRMWARE
CTR2’s HMI firmware is based on Arduino primarily because PJRC.com uses this environment for their development boards. They provide a software add-on package called Teensyduino v1.54 that includes all the libraries you need to develop code for the Teensy. This add-on also makes many other Arduino libraries compatible with the Teensy. The end result is a powerful, easy to use programming environment.
To create your programming environment for the HMI you’ll need to install at a minimum the Arduino IDE (Integrated Development Environment) and the Teensyduino v1.54 software add-on. Download and install the latest version of the Arduino IDE (v1.8.15 as of July 2021) then download and install the Teensyduino software. Instructions for both of these programs are found on their respective web sites.
If you have a favorite programming IDE such as Eclipse, PlatformIO, Microsoft Code, or Microsoft Visual Studio you can use those, but you’ll still need to have the Arduino IDE installed since all of these IDEs rely on the Arduino IDE for their core functions. My personal preference is Microsoft Visual Studio with the Visual Micro add-on.
I’ll describe how to setup the Arduino IDE for the Teensy 4.1. The other IDEs have similar methods to do this.
Start your IDE and open the CTR2.ino firmware file. The latest CTR2 HMI firmware files can be downloaded from the CTR2 Firmware Files blog post.
Once you have the CTR2.ino file open, select the Teensy 4.1 board. Click on the Tools menu in the IDE then select Boards. Under Boards click on the Teensyduino menu to open the list of Teensy boards. Click on the Teensy 4.1 board.
NOTE: The Teensy 4.1 board will only be available if you’ve installed the Teensyduino library.
Next, click on the Tools menu again, then click USB Type. On this menu select Serial + MIDI + Audio. This configures the USB port on the Teensy 4.1 to support these interfaces.
The CPU Speed should be left at the default, 600 MHz. You can select slower speeds but I recommend running the default speed.
Finally you’ll need to select the serial port assigned to your Teensy 4.1. Plug a micro-USB cable into the Teensy’s micro-USB connector then connect the other end to a USB-A jack on your PC. Your PC will find the Teensy and assign a virtual serial port to it. Click on the Tools menu again then click Port and locate the port labeled Comm# (Teensy). Remember the comm port #. This port will be used by 3rd party apps such as WSJT-X to communication with CTR2.
Finally, click the Sketch menu then Verify/Compile to compile the firmware. If all goes well you’ll see a memory usage report at the bottom and no compile errors.
Once you have verified the firmware, click the Sketch menu again and select Upload to upload the compiled program to your Teensy.
NEXTION DISPLAY FIRMWARE
Now you have your Teensy updated it’s time to download and install the Nextion IDE. Nextion provides a free IDE to program their displays. Click here to download the latest version. The Nextion IDE is only available for Windows and only required if you want to modify the display firmware (see the Note below).
Download the appropriate .hmi source code file for your display from the CTR Firmware Files blog post. CTR2 supports two display sizes, the 3.5″ and the 5″ Enhanced displays. The file named CTR2_3-5.hmi is used with the 3.5″ display and CTR2_5-0.hmi is for the 5″ display.
Warning! CTR2 is not compatible with the Nextion Basic or Intelligent displays. Only the 3.5″ and 5″ Enhanced displays are supported at this time.
Run the Nextion IDE and click the Open button in the upper left-hand corner to open the .hmi source file for your display. You can edit this file if you want to. When you’re ready to compile it for your display, select the Files menu then select TFT File Output. A window will pop up showing the location where the .tft file will be created. You can choose any folder. Just remember where you saved it as you’ll need to copy this file to an SD card to install it on your display.
Updating the firmware on the display is done by copying the .tft file to an SD card, inserting that card into the display’s SD card slot, then powering up the display. There can only be one .tft file on the SD card, and the file must match the display model or it won’t update. This is one reason why there are two versions of the display source code. The other reason is that the gSize global variable in the source code identifies the display size for the HMI firmware.
NOTE: If you don’t plan on modifying the Nextion firmware you can just download the appropriate .tft file from the CTR2 Firmware Files blog post. Just copy that file to an SD card as described above to update the program on your display.