Getting Started Building SDR_887x SDR program - K7MDL2/KEITHSDR GitHub Wiki

Getting Started Building your first SDR_RA8875 Program

You do not need to know how to code in C or C++ to configure, build and use this program. The following step should get most folks a working build. The biggest challenges are gathering all the right libraries and knowing what you want to configure and where to do that. Over time more and more configuration controls have moved to RadioConfig.h. Some more complicated setting are still in SDR_Data.h. The defaults will probably work for most people, at least to start out with.

Determine your hardware

This program takes advantage of certain display controller features found on the RA8875 and RA8876 LCD display controllers that make it possible to perform high resolution spectrum drawing with minimal CPU impact.

A homebuilt multi touch "engine" was built for these displays since the built-in touch controllers did not work well. Only specific touch controllers are supported. The RA8875 uses the built-in library touch support (requires setting a config item in one of the library's config files). The RA8876 uses a separate FT5206 library. It is possible to order a display with the right display controller but the wrong touch controller. There is a Wiki page that details the hardware and specifically which display and features to order. Today only the 4.3" RA8875 and 7" RA8876 models are tested. The 10" RA8876 display is likely to work with no changes but has not been tested.

Several versions of PCB "Motherboards" were designed and distributed to make building one of these much easier and faster with less noise challenges form long I2C or SPI cables. Many jacks are on board for a wide choice of hardware options, you do not need to use or install all of them, choose wht you need. The version board needs to be properly defined in the RadioConfig.h file. YU cna build without a board, be sure to carefully go through teh section of the config file to assign the correct GPIO pins.

Collect all libraries:

The main header files SDR_RA8875.h and RadioConfig.h, and the main file SDR_RA8875.ino, contain most of the header file declarations. The comments for each usually include where to find them. Most will be placed in your %USERNAME%/Documents/Arduino/libraries folder. A Wiki page also lists most libraries used and where to find them. Get as many as you can find downloaded. When you start your build it will call out any missing libraries. More on that below.

USB Audio:

Analog audio is always present on the headphone jack output and the mic input. Line In and Line Out are dedicated to connection with the SDR RF hardware audio. USB Audio is enabled by default along with CAT radio control on a serial port. The ideal setup requires the USB cable be configured to have 2 serial ports and 1 audio interface. Looking at the IDE's Tools->USB Type menu selections this combination does not exist by default. Certain TeensyDuino library file changes are required provide 2 Serial + 1 Audio, and for 48KHz to work right. Each time you update the TeensyDuino library, the old library is normally overwritten removing any library customizations. A Wiki Page explains how to manually make the necessary changes. The new library file version can change over time so the changes must be manually applied. At times I post modified library files for particular TeensyDuino library versions so you can just copy them in.

Set CPU Speed and USB Type, USB port:

In the IDE you need to set the Teensy 4.1 board type. This involves a few steps.

  1. Under File->Preferences find Additional boards manager URLs: and copy https://www.pjrc.com/teensy/package_teensy_index.json into it.
  2. Under Tools->CPU Speed choose one of them. I usually choose 816MHz or 912MHz. I put a heat sink on the CPU chip for good measure. They are similar size to the Raspberry Pi heat sinks.
  3. Under Tools->USB Type choose Serial+MIDI+Audio. This configures 1 serial and 1 audio interface. With the mentioned USB/48KHz lib changes a dual Serial+Audio choice will become available. If you do not need both a CAT and Debug port, and do not plan to use USB Audio, you can set #define ALT_CAT_PORT to put both CAT and debug onto the same single serial port. To use that single port for CAT serial control you must disable Debug (#define DEBUG found in the top of SDR_RA8875.h). IF you are not using CAT then you can leave debug turned on.

Where to make configuration choices:

RadioConfig.h - most settings are in here. SDR_Data.h - some settings require editing structure tables. These are easy to modify but requires a good understanding of what changes you want to make to ensure they will work. For most people the settings in these next 2 files won't be touched, they are more for experimenters familiar with C coding. SDR_RA8875.h SDR_RA8875.ino

How to test just the Display and Motherboard (no RF or aux encoders):

If you would like to test the display with a new motherboard before you have the RF hardware (PLL, RX/TX modules) it is possible. Choosing certain settings will cause the system to ignore errors (or not look for them) and not to configure auxiliary hardware. Set the correct PCB version so the GPIO pins align. Then turn off GPIO and I2C encoders. The below lines should accomplish what we want. //#define GPIO_ENCODERS // Requires I2C_Encoders library //#define I2C_ENCODERS // Use I2C connected encoders #define V22_7_PCB // choose the matching PCB version. See file for more choices #define NO_RSHFIQ_BLOCKING //#define USE_CAT_SER // if not using RS-HFIQ, this should turn off any CAT message handling in or out. #define ALT_CAT_PORT // if CAT is turned on then this use a single serial port for CAT and Debug (if enabled) over the USB cable. Debug is always the first serial port.

Enabling GPIO Encoders:

The Main tuning VFO encoder is always enabled and not connecting one is OK, makes no impact. If there are no auxiliary encoders connected, then the configuration must ensure they are turned off. It is usually OK to have them connected but turned off if needed for debug or testing. GPIO encoders are enabled with both the GPIO and I2C decoder config lines enabled. GPIO depends on some i2c library functions. Further configuration in RadioConfig.h enables/disables each individual encoder. This is covered in another Wiki Page so please refer to that page for more. #define I2C_ENCODERS // Use I2C connected encoders #define GPIO_ENCODERS // Requires I2C_Encoders library

Enabling i2c encoders:

I2C encoders offer simpler wiring since they only use 5 wires and care daisy chained. GPIO take 3 wires for each encoder. Due to limited free IO pins the software today only supports 3 GPIO aux encoders. Electrically you can have over 200 i2c encoders. You can also get features like RGB LED shafts/knobs for feedback when pushing or turning a knob (on by default) and some aux IO ports on each encoder board (not used today). A table in SDR_Data.h works with settings in RadioConfig.h to enable each encoder setting values for GPIO and I2C type, address, and function (role). Encoders may have dual roles, switched by tapping the encoder push switch. Refer to the Configuring Encoders Wiki page for more details. #define I2C_ENCODERS // Use I2C connected encoders

Start your build:

Press the Verify or Upload button on the IDE. You will likely get some error messages, maybe a lot. look a the last lines for what might be the primary error, and then scroll far up to the first error occurrence. Usually, it is a missing or misplaced library. Consider this and iterative process of identifying what is missing, fetching that library and try again until you have them all. At the end of the compile you will get something like the below example where all the libraries found and used are listed. Review the list and make sure it is using the one you want. There can be old and new versions on your machine. The screen capture below is with Arduino IDE 2.0.4 and TeensyDuino 1.58.0.

Memory Usage on Teensy 4.1:
FLASH: code:221684, data:151504, headers:8760   free for files:7744516
RAM1: variables:231264, code:183784, padding:12824   free for local variables:96416
RAM2: variables:171232  free for malloc/new:353056
"C:\\Users\\k7mdl\\AppData\\Local\\Arduino15\\packages\\teensy\\tools\\teensy-tools\\1.58.0/stdout_redirect" 
"C:\\Users\\k7mdl\\AppData\\Local\\Temp\\arduino\\sketches\\2E710F00E8EF106852898E7045372F8C/SDR_RA8875.ino.lst"     
"C:\\Users\\k7mdl\\AppData\\Local\\Arduino15\\packages\\teensy\\tools\\teensy-compile\\11.3.1/arm/bin/arm-none-eabi-objdump" -d -S -C         
"C:\\Users\\k7mdl\\AppData\\Local\\Temp\\arduino\\sketches\\2E710F00E8EF106852898E7045372F8C/SDR_RA8875.ino.elf"
Multiple libraries were found for "SD.h"
  Used: C:\Users\k7mdl\AppData\Local\Arduino15\packages\teensy\hardware\avr\1.58.0\libraries\SD
  Not used: C:\Users\k7mdl\AppData\Local\Arduino15\libraries\SD
  Not used: C:\Users\k7mdl\OneDrive\Documents\Arduino\libraries\SD
Multiple libraries were found for "TimeLib.h"
  Used: C:\Users\k7mdl\OneDrive\Documents\Arduino\libraries\Time
  Not used: C:\Users\k7mdl\AppData\Local\Arduino15\packages\teensy\hardware\avr\1.58.0\libraries\Time
Multiple libraries were found for "ili9488_t3_font_Arial.h"
  Used: C:\Users\k7mdl\OneDrive\Documents\Arduino\libraries\ILI9488_t3
  Not used: C:\Users\k7mdl\AppData\Local\Arduino15\packages\teensy\hardware\avr\1.58.0\libraries\ILI9488_t3
Multiple libraries were found for "SVN1AFN_BandpassFilters.h"
  Used: C:\Users\k7mdl\OneDrive\Documents\Arduino\libraries\SVN1AFN_BandpassFilters
  Not used: C:\Users\k7mdl\OneDrive\Documents\Arduino\libraries\SV1AFN_BandpassFilters
Using library Audio at version 1.3 in folder: C:\Users\k7mdl\AppData\Local\Arduino15\packages\teensy\hardware\avr\1.58.0\libraries\Audio 
Using library SPI at version 1.0 in folder: C:\Users\k7mdl\AppData\Local\Arduino15\packages\teensy\hardware\avr\1.58.0\libraries\SPI 
Using library SD at version 2.0.0 in folder: C:\Users\k7mdl\AppData\Local\Arduino15\packages\teensy\hardware\avr\1.58.0\libraries\SD 
Using library SdFat at version 2.1.2 in folder: C:\Users\k7mdl\AppData\Local\Arduino15\packages\teensy\hardware\avr\1.58.0\libraries\SdFat 
Using library SerialFlash at version 0.5 in folder: C:\Users\k7mdl\AppData\Local\Arduino15\packages\teensy\hardware\avr\1.58.0\libraries\SerialFlash 
Using library OpenAudio_ArduinoLibrary in folder: C:\Users\k7mdl\OneDrive\Documents\Arduino\libraries\OpenAudio_ArduinoLibrary (legacy)
Using library Wire at version 1.0 in folder: C:\Users\k7mdl\AppData\Local\Arduino15\packages\teensy\hardware\avr\1.58.0\libraries\Wire 
Using library Time at version 1.6 in folder: C:\Users\k7mdl\OneDrive\Documents\Arduino\libraries\Time 
Using library Encoder at version 1.4.3 in folder: C:\Users\k7mdl\AppData\Local\Arduino15\packages\teensy\hardware\avr\1.58.0\libraries\Encoder 
Using library Metro in folder: C:\Users\k7mdl\AppData\Local\Arduino15\packages\teensy\hardware\avr\1.58.0\libraries\Metro (legacy)
Using library InternalTemperature at version 2.1.1 in folder: C:\Users\k7mdl\OneDrive\Documents\Arduino\libraries\InternalTemperature 
Using library Ra8876LiteTeensy at version 1.0.0 in folder: C:\Users\k7mdl\OneDrive\Documents\Arduino\libraries\Ra8876LiteTeensy 
Using library ILI9488_t3 at version 1.0 in folder: C:\Users\k7mdl\OneDrive\Documents\Arduino\libraries\ILI9488_t3 
Using library FT5206 in folder: C:\Users\k7mdl\OneDrive\Documents\Arduino\libraries\FT5206 (legacy)
Using library DuPPa Library at version 1.2.0 in folder: C:\Users\k7mdl\OneDrive\Documents\Arduino\libraries\i2cEncoderLibV2 
Using library SVN1AFN_BandpassFilters in folder: C:\Users\k7mdl\OneDrive\Documents\Arduino\libraries\SVN1AFN_BandpassFilters (legacy)
Using library Adafruit MCP23017 Arduino Library at version 2.3.0 in folder: C:\Users\k7mdl\OneDrive\Documents\Arduino\libraries\Adafruit_MCP23017 
Using library Adafruit BusIO at version 1.14.1 in folder: C:\Users\k7mdl\OneDrive\Documents\Arduino\libraries\Adafruit_BusIO 
Using library Etherkit Si5351 at version 2.1.4 in folder: C:\Users\k7mdl\OneDrive\Documents\Arduino\libraries\Si5351Arduino 
Using library USBHost_t36 at version 0.2 in folder: C:\Users\k7mdl\AppData\Local\Arduino15\packages\teensy\hardware\avr\1.58.0\libraries\USBHost_t36 
Using library EEPROM at version 2.0 in folder: C:\Users\k7mdl\AppData\Local\Arduino15\packages\teensy\hardware\avr\1.58.0\libraries\EEPROM 

If you have the Teensy 4.1 hooked up with the right USB Type and port selected it will upload and run. You will see a set of messages like below

Memory Usage on Teensy 4.1:
 FLASH: code:221684, data:151504, headers:8760   free for files:7744516
 RAM1: variables:231264, code:183784, padding:12824   free for local variables:96416
 RAM2: variables:171232  free for malloc/new:353056

Up until this writing on 4/9/2023, builds have been using Arduino IDE 2.0.3 with TeensyDuino 1.58.3 Beta (listed as 0.58.3 in the package manager). When the library is not beta, it will display as the proper 1.58.X. The leading 0 forces it to the end of the version list and want nag you to update to a Beta. As if 4/9/2023 I have started using IDE 2.0.4 and TeensyDuino 1.58.0 (released version). I have not yet modified the lib files for dual Serial+Audio and 48KHz so I am using the above techniques for single serial+ audio using USB Type Serial+MIDI+Audio. A modified library wil list Serial+Serial+Audio type as an option.

I use Visual Studio Code as a complete replacement environment for the IDE. It uses the CLI shipped with IDE or downloaded separately. The New Arduino IDE actually uses a customized version of the open-source Visual Studio Code editor. You will need to add the Arduino and C/C++ extension to VS Code. I have more detail on a Wiki Page and posted in the forums.