Thursday, June 4, 2020

Furlough 40 Goes Color - Arduino SSB TFT Display Module



I wanted to liven up the display module for my F40 - the 4x20 LCD display is certainly functional, but decidedly industrial in look.  I have gotten quite fond of the color display on my uBitx, so I decided to build a color display module for the F40.   I opted for a color TFT for the display since they are ubiquitous, inexpensive and there are many good Arduino libraries that make programming a snap.  Uber Elmer N6QW, Pete Juliano graciously shared with me the sketches he had written for various color TFT projects and I downloaded and also evaluated sketches from several other hams. Not quite finding what I wanted, I decided to write my own sketch.

I should let you know that I'm a relatively young ham (60 years young, but licensed only two years ago), but I am a very old software guy (still 60,  but have been a professional software engineer and executive for 40 years).  So, when I started looking at source code for Arduino sketches that were written by amazing hams with no formal software training I knew I had to dive in.

My design goals for the project were the following:
  • The code must follow sound software engineering principles throughout.
  • It must be modular and reusable.  To be easily reusable the code most not be dependent on any particular hardware design.  You should be able to drop it in to any Arduino based radio control program with minimal effort.
  • It must have a small memory foot print and not use up much of the Arduino's precious dynamic RAM.
  • It must be fast and not tax the Arduino microcontroller- we want to save its CPU cycles for control of the rig. 
  • It must use standard Arduino display libraries and be relatively hardware independent - easy to port to a different display or microcontroller.
  • It must be easily reconfigurable - you should not have to change code to make simple user interface changes like screen colors and font sizes.
  • It must provide the basic display functions for a dual VFO SSB rig - and that means dual VFO display, active VFO indicator and LSB/USB indicator.
  •  It must be easy to add new display elements - including an S meter and other similar displays.
  • And last, the code must be easy for a non-professional coder to understand and work on.  No tricks or fancy code footowork.
So, over the long memorial day weekend I wrote and tested the KK4DAS SSB TFT Display.

A quick note if you are interested in building this.  This is not a complete radio control sketch - it is only the display module. Over the coming weeks I will publish additional modules that will implement a complete SSB transceiver controller.  But for now, all you need is an Arduino and a color TFT, and possibly some level shifters.  The Arduino nano uses 5V logic but the TFT needs 3.5V logic so the level shifters are used to take care of that.  You'll also need to install the Arduino IDE and load the two required libraries.

Here are some of the details:

Features

  • Basic radio display panel for an SSB transsceiver
  • Designed for a 320x240 Color TFT (non touch)
  • Tested with an ILI9341 display

Requires the following libararies

  • Adafruit_GFX
  • Adafruit_ILI9341

Implements a basic SSB display console with the following features

 Dual VFO A/B
 Mode indicator  SSB/LSB
 Tx/Rx ndicator
 TuningStep Inidicator
 S Meter
 Banner including Call sign

 Fully customizable. Fast display makins use of minimal resources./
 Room is left on the screen for additional features
 There is room on the screen for another row of features
 
 Easily change colors, font sizes and layout

Default Screeen Layout

  ____________________________________
  |       A 7.200.000 LSB             | -- VFO A/B indicator, Active VFO Freq, LSB/USB inidicator
  |      Rx 7.048.000 100K            | -- Rx/Tx indicator, Alternate VFO Freq, Tuning Increment
  |                                   | 
  |      S |_|_|_|_|_|_|_|_|_|_|_|_|  | -- S Meter
  |         1   3   5   7   9         |
  |                                   |
  |        AGC   SPL   RIT            | -- (Planned) AGC on/of, Split On/Off,  RIT On/OFF
  |                                   |                                        
  |     Ver   Rig Name   Call         |
  |___________________________________|

This module provides the following radio console display functions:

  • displaySetup - initialize the display and displays the startup values - call once from your setup function
  • displayBanner - Displays a text banner across the bottom of the screen
  • displayActVFO - Displays the frequency of the Active VFO
  • displayAltVFO - Displays the frequency of the Alternate VFO
  • displayVFOAB - Displays the indicator which VFO is active (A or B)
  • displayTxRx - Displays whether the rig is in (Tx or Rx)
  • displayMode - Displays the which sideband is selected (LSB or USB)
  • displayIncr - Displays the tuning increment (10, 100, 1K 10K, 100K, 1M)
  • displaySMeter - Displays the S Meter (1-9 are gray, +10 +20 and +30 are red

This module also provides the following general purpose display functions:

  • displayClearScreen - fills the screen with the selected backgrond color
  • displayPrintat - prints text or nubmers on the screen at a specific location
  • displayDrawBoundingBox - draw a box on the screen and fills it with a background color
  • displayDrawTextBox - displays text inside a boundig box

Design notes and how to use the code

NOTE TO BUILDERS

This is not a complete radio control sketch. It is the Display software only. In the spirit of modular design it is stand-alone and not dependent on using an SI-5351 or any other specific hardware, or on my particular hardware selection of switches, buttons and knobs. The demonstration sketch shows how to update the display, but you need to provide the code to determine what the actual values should be. You will likely need other libraries like the Si5351 and a Rotary encoder library aside from the GFX and the ILI9341.

DESIGN PRINCIPLES

Good software design principles are to use as few hard-coded numbers as possible. Wherever possible I have used #defines for any number that will be used more than one place in the code. For example #define DSP_VFO_ACT_X 60 defines the X coordinate (how far from the left of the screen) of the Active VFO frequency display. You will see multiple references to DSP_VFO_ACT_X throughout the code, but I never use the hardcoded number 60 again. Change it once – and it is changed throughout.

Taking the S-Meter as an example:

To update the S-Meter display you make a call to displaySMeter(n); where n is an integer from 1 to 12 (representing S1-9, +10, +20 +30). Your sketch will need a way of monitoring signal strength (an analog input pin on the Arduino attached to an appropriate place on your rig) and converting it to the logarithmic S scale.

SCREEN COORDINATES

Coordinates work differently on displays than a typical graph where the origin 0,0 is in the middle abd positive and negative values move you away from the origin. For displays 0,0, the origin, is always upper left hand corner of the display and you only use positive numbers for the coordinates +X is pixels from the left edge, +Y is pixels down from the top. This particular example based on a 320x240 display but should be easily portable to other display sizes – but you have to keep in mind how the coordinate system works.

SCREEN LAYOUT

Here are a few notes about how the demonstration display is laid out. This should help you understand the design concept and allow you to begin to modify it.

The VFO display is setup for a dual VFO rig. The currently Active VFO is always on the top and the alternate VFO is just below it. Your code will need to keep track of whether VFO A or VFO B is currently selected and call the display routines to update the display. I’ll describe how the VFO displays are are defined and that will give you an idea how you might modify or enhance the display.

Active VFO - top center of the screen

#define DSP_VFO_ACT_X 60   // Active VFO begins 60 pixels from the left hand edge (I picked 60 by experimenting)
#define DSP_VFO_ACT_Y 30   // Active VFO box starts 30 pixels down from the top of the screen
                          // (Try changing it to 50 and see what happens)
#define DSP_VFO_ACT_COLOR ILI9341_GREEN   // This sets the text color for the Frequency display. Use whatever colors you like
#define DSP_VFO_ACT_BK ILI9341_BLACK      // This sets the background color for the Active VFO
#define DSP_VFO_ACT_SZ 3                  // This is text size from Arduino TFT, values 1-5 1 is small 5 is large (2 was too                                                 // small, 4 was too large, 3 was just right)

Alternate VFO – the second VFO is placed directly below the Active VFO on the screen.

There are a couple of things of interest here. For the X coordinate, instead of putting in a hard coded number I refer back to the #define that I used for the Active VFO (DSP_VFO_ACT). That way, if I want to move VFO section to a different part of the screen I only need to change one number DSP_VFO_ACT_X, and the alternate VFO will move as well. Figuring out the Y coordinate for the alternate VFO is a little more challenging. Some math is involved. Starting with the Y coordinate of the Active VFO I need to calculate where how far down the display I need to go to place the second VFO. To do that I need calculate how many pixels tall the text characters in the Active VFO are and use that as an offset. It turns out we have everything we need already defined. CH_W and CH_H are #defines that specify the height and width of a text character in pixels for TFT font size 1. Size 2 through 5 are even multiples of that – so font height for size 2 is

2*CH_H pixels and font width 

And for size 4 is

4*CH_W

pixels and so on. so we have everything we need to calculate how many pixels the Active VFO takes on the screen – we multiply the font size by the character height and add 16 pixels offset. The 16 was determined by experimentation for something that looked good. The code looks like this:

#define DSP_VFO_ALT_X DSP_VFO_ACT_X
#define DSP_VFO_ALT_Y DSP_VFO_ACT_Y + (DSP_VFO_ACT_SZ * CH_H) + 16 

Take a look the other sections of the display code and you will see similar references and calculations. The VFO A//B indicator and LSB/USB mode indicator, for example are similarly “pinned” to the Active VFO display, so if you move the Active VFO display to another screen location they will move also.

In summary - each object is on the display is defined by a set of constants that indicate the X,Y coordinates of the object on the screen and various other attributes like text size and color. The basic user interface display object is a bounded/filed text box. You can control the text size and color, and the box fill color. With this basic set of features you can implement a wide variety of user interface elements. The S-meter, for example, is a row of filled boxes.

HARDWARE NOTES

My test sketch uses an Arduino Nano. The display is an HiLetgo 2.2 Inch ILI9341 SPI TFT LCD Display 240x320, but any ILI9341 display should work. There are many sources. Please note that the Arduino has 5V logic levels, but the display requires 3.3V - so you need some sort of level shifter. I used the"HiLetgo 10pcs 4 Channels IIC I2C Logic Level Converter Bi-Directional 3.3V-5V Shifter Module for Arduino" I used hardware SPI and the pinouts are standard as follows:

        Arduino 
         Pin       TFT Pin
      -----------|---------    
          8      |  RST  - any free Arduino Pin (not used in this sketch)
          9      |  DC   - any free Arduino Pin
          10     |  CS   - any free Arduino Pin 
          11     |  MOSI - fixed
          12     |  MISO - fixed
          13     |  CLK  - fixed

That is all the wiring you need for the demonstration sketch.

You can download the sketch on the KK4DAS Github

BUILDING THE DEMONSTRATION SKETCH

Create a folder called SSB_TFT_Display_Demo

Copy all three files to that folder

  • SSB_TFT_Display_Demo.ino
  • SSB_TFT_Display.h
  • SSB_TFT_Display.cpp

Use the Arduino IDE library manager to install the following libraries

  • Adafruit_GFX
  • Adafruit_ILI9341

Compile and upload the sketch.

If you build it or modify it,  it take a picture or make short video - or just let me know about it in the comments.

73 from Great Falls,

Dean

KK4DAS

Monday, May 25, 2020

Furlogh 40 gets CAT Control





One of the pleasures of a homebrew rig is that if it doesn't have a feature that you want, you can always add it. So this past weekend I added functionality to the F40 to make it work with Ham Radio Deluxe and other PC programs.  With a properly configured rig, Ham Radio Deluxe makes working DX much easier. It has an integrated DX spot function that lets you see the DX spots on your bands of interest.  If you see a station you would like to work you simply click on the entry and radio tunes to that frequency.  To log a new QSO, its just a couple of clicks and HRD picks up the frequency and mode directly from the rig.  But to do this you need to have a rig that supports some version of the Computer Aided Transceiver (CAT) protocol.   Happily, virtually every modern (and most not-so-modern) commercial rig has CAT capability that let you control most or all of the rigs settings from a PC program like HRD or WSJTX.  But how do you implement CAT control in your homebrew rig?

Enter Pavel Milanes (CO7WT).  Building on earlier work by James Buck (VE3BUX), FT857D arduino Lib, Pavel created the FT857d- CAT Control for Arduino Library (FT857d)

Pavel's library is elegant and straight-forward to add to an existing Ardhino sketch.  It implements the rig control functions that emulates a Yaesu FT857D transceiver.  The library handles all of the communications and protocol handling allow you to connect the Arduino to a PC via USB.

For the technically curious, here is what I had to do to integrate the CAT library in the F40 Sketch:

After installing the library using the Arduino IDE's Sketch -> Add library command. I loaded up the exampl program that Pavel provides and was pleasantly suprised that he had done most of the work,  I had to make a couple of small changes to my main sketch and them modify functions that Pavel provided  function to handle connecting the library to the rig code for things like changing and displaying frequencies and modes,

From my main sketch's setup() rountine I made a call to setupCat() which registers a series of call back functions described below.  Then from the main loop I made a call to checkCat() where all the magic happens.

Following Pavel's example I created a seperate .ino file that connects our particular righ to the FT857d library. It has one function for each CAT command,  We have to supply the working bits to connect it to our rig’s software, for example:

  1. catGoToggleVFOs() is  called when the PC program directs changing VFOS,  This is where we put the code to switch between VFO A and B
  2. catSetFreq(long f) is called to change the active VFO frequency to whatever the PC program wants
  3. catGetFreq() – returns the current active VFO frequency to the PC program so it can display the frequency that the rig is tuned to.
  4. And so on. 

Taking two examples…  here is my code for catGetFreq()

long catGetFreq() {
    // this must return the freq as an unsigned long in Hz, you must prepare it before
    long freq;
    if (active_vfo == VFOA) {
      freq = vfoAfreq-bfo;
    } else {
      freq = vfoBfreq-bfo;
    }
    // pass it away
    return freq;
}

This function is invoked when the PC software wants to know what the current active frequency is – usually to display it in the UI or to use it for logging.

It references the control variable from my main sketch.

  1. active_vfo – is either VFOA or VFOB  (#defines in my main sketch)
  2. vfoAFreq and vfoBfereq are variables that contain the current value of the two VFO settings – with the bfo offset already applied
  3. bfo – is the bfo offset frequency

So all the code does is recover the operating frequency from whichever is the active VFO and return that the cat library.  Pavel’s library will send it back to the PC program for display or logging or whatever.

And here is my code for catSetFreq()

void catSetFreq(long f) {
   //
   // Change the frequency of the current active VFO
   // Clock frequency is the operatingfrequecy plus the BFO 
   // 
   if (active_vfo == VFOA) {
       vfoAfreq=f+bfo;
       setVFO(VFOA, vfoAfreq);
   } else {
       vfoBfreq=f+bfo;
       setVFO(VFOB, vfoBfreq);
   }
}

The CAT library calls this routine when the PC software has issued a command to tune to a new frequency.  All I do here is add the BFO offset to the requested operating frequency and call the setVFO() function in the main sketch which updates the SI5351 clocks and the F40 display.   

So far I have it tested it with Ham Radio Deluxe, WSJTX and FLDIGI, and FLRIG and the get and set frequency routines work fine.  Next step will be to implement software PTT.  

Thanks to James and Pavel for their contribution to the F40. This mod opens up a whole new world of possibilities.  Check this space for progress reports.

I am happy to provide the sketch to anyone interested, but I would like to keep track of who is using it.  Just send an email to KK4DAS@gmail.com.

73 from Great Falls,

Dean

KK4DAS

Wednesday, April 29, 2020

Getting Control of the Furlough 40 and First Week's Log

Adding Controls to the Furlough 40

When I got the Furlough 40 up and running a little over a week ago I was so excited just to make contacts that it didn't bother me that the controls were hanging by wires off the edge of the board, but that got quickly annoying. So it was time to build the control panel.  I decided to keep with the al-fresco look and go with something that more-or-less matched the open, modular construction style.  

The controls consist of:
  • Rotary digital encoder for tuning
  • VFO A/B select mini-toggle
  • USB/LSB mini-toggle
  • MOX mini-toggle put the rig in to transmit
  • Tone - momentary switch to trigger a 10 second tune tone
  • Power button (push on/off, not installed yet)
In keeping with the "Home Depot Homebrew Chic" esthetic, I went with 1/8" aluminum angle stock for the panel.  Having none in the shop and while out on my pre-planned weekly social-distancing grocery run, I stopped in at Home Depot to pick some up along with various screws and a carbide tipped saw blade for my miter saw to make it easy to cut the aluminum stock.

As an aside - this rig is so inexpensive to build that I spent more on the saw blade than all the parts of the rig combined.
Here is a hint - knobs, switches and an assortment of electronic parts can be purchased from Marlon P. Jones - MPJA.COM.  I purchased a pack of 5 knobs for $3 - the knobs are good quality with brass shaft screws - and they have flat rate shipping.

A couple of minutes with graph paper and pencil and I had the layout.  The new saw blade made short work of cutting the angle stock to size.  Carbide tipped drill bits in the drill press and ample WD-40 and I had the holes cut.  The labels are from my trusty Brother P-Touch - I need to get some clear label tape, but for now, the white will do. The whole effort - including trip to the store took about 3 hours. Still to do:
  • Mount the display using angle brackets
  • The right hand side - audio level knob, mic and speaker jacks
The rig is a pleasure to use now. The tune tone is a terrific feature added by N6QW, Pete Juliano, the designer of the rig. It puts an 988 Hz 1/2 duty cycle tone directly in to the microphone input. This is great, not only as a tune-up tone, but it replaces the need for an external signal generator to put a known signal into the rig for testing. I found out, as Pete advised, that I needed to unplug the mic first - other wise you are feeding the audio in to the mic which turns the mic into a speaker.  I am guessing that is not good for the mic element.  

***

Furlough 40 First Week Contacts

This is the first week's log - I don't have much time to work the rig in the morning and evening hours when 40 meters is wide open, but even so I am very happy with the results.  There are a few contacts with local club members but the rest are a result of me answering CQs - all good contacts with call signs and signal reports exchanged at a minimum. Responses varied from "Wow! Three watts? Amazing!" to "sound like 3 watts :(".   The distance ranges from 250 miles to nearly 800 miles on a maximum of 3 watts.  From my QTH in Great Falls, VA near Washington, DC I am doing well up and down the east coast and in to the mid-west.  Only DX so far are two Canadian stations.

I even made my first digital contact with my friend Don, KM4UDX on his uBitx.  Using FLDIGI - for receive, I hooked the speaker out directly in to the PC mic input and for transmit I held the mic up near the laptop.  To make this easier I'll need to add 3.5mm mic jack to the rig and decide how I want to enable PTT.  Pete has a simple USB hardware digital interface that I may build or I might go all-in and port the CAT control implementation from the uBitx firmware for full integration with digital and logging software. 

Furlough 40 - First Digital QSO

That's all for now - for the next post we will go back to the beginning and document the build board by board.  Please subscribe, like, follow, share and tell your friends.

73 from Great Falls,

Dean
KK4DAS



Friday, April 24, 2020

Furlough 40 Hears the World



I'm still working on tuning up the transmit side of the transceiver to see if I can get a little closer to designer N6QW, Pete Juliano's 5 watt specification, but in the meantime I decided to checkout the performance of the receiver.

I ran a weak signal propagation receive test overnight to see how well the receiver is working.  The image all the stations I heard over about 12 hours.  I'm located in Northern Virginia, just outside of Washington DC and I heard stations from Australia and New Zealand. This is a pretty sensitive receiver! Kudo's to Pete for the terrific design.

If you haven’t checked out WSPR,  it is one of the digital modes that I like.  It uses signal processing software from Nobel Prize winning Princeton physicist Joe Taylor.  It is a great way to analyze your station’s reach both in receive and transmit.

The software is available here - https://physics.princeton.edu/pulsar/K1JT/wsjtx.html 

The same software also supports FT8 and other weak signal digital modes. 

The only thing I needed to do to use the software on receive was plug the rig’s phone output into the mic input on the laptop and tune the rig to the 40 meter WSPR frequency on upper side band.  The software does all the work.  Its time based, so you PC’s clock needs to be sync’d pretty close to internet time. 

All stations that run WSPR have the option of uploading the signals they hear to WSPRnet.org, and the WSPRnet database is open and searchable.   The web site I used to produce the map is at http://wspr.vk7jj.com/.  If you use WSPR you should check it out - this is just one of many tools to allow to check your rig's performance,  test new antennas, and so on.  I let WSPR run in receive mode over night and looked at the results this morning.

In order to test how well I am getting out on transmit I need to get some sort of keying control built for the rig – either through integrating CAT control into my Arduino control program – or using serial port keying through a USB interface.  So, in addition to tuning up the transmit circuits, this will be one of my next projects.

73 from Great Falls
Dean
KK4DAS