Sunday, June 17, 2018

ESP32 'Test Gadget' starting on software

I got back from visiting with family at a wedding, and finally getting time to work on the software for the 'Test Gadget'
After getting the drivers for the TFT display and the Adafruit graphics library working along with the Joystick, I started porting some of my existing software over to the ESP32.  It has turned out to be nearly a direct drop-in from the code I have for the Nano and Pro-mini I have used before.

For some of the test functions a digital read out of values is OK, but when you are making adjustments I prefer some sort of a analog display.  In my early projects I used a bar-graph as a analog display, but recently I came up with a very small set of functions that simulate a analog meter.  With the speed of the processor and memory available, I could probably make one that is more accurate in appearance, but this simple one is adequate for what I want.

As a test I drew two meters on the screen, and have room for four if I would ever need them.  With this size, there is plenty of room on the screen to display multiple digital values, such as instantaneous reading, and peak readings.  I could also make one  large meter that would cover the entire display area.

Some of the other test instruments I plan on making with the 'Test Gadget' will have frequency scans shown as a wave-form.  I ported over my basic waveform screen with programmable grid sizes, and Y-axis scales.  They look very nice on this size display, and can redraw with very little flicker.

I have just a few more of these routines to port over in the next few days.
Then I have to decide if I want to incorporate a full menu management system, or just use the simple menus I have used in the past.
Thats all for now  check back for updates.

Thursday, May 31, 2018

ESP32 and the CWTD 'Test Gadget' Update 6/3/18

I have several projects in the early stages of development that I am working on.  Most of them require more program and sram memory then available in the Nano or Pro-Mini that I have been using for my projects.  This has led me to do some testing of a  several Arduino compatible boards.  I tried the Mega2560 and the Mega mini, but decided that the form factor would be hard to work with in my projects.  I also did some experimenting with the STM32 'Blue Pill' and was very satisfied with the results I found.  For around $2 it is a very powerful board.  Recently I saw some information on  ESP32 development boards that look really interesting.  Along with WiFi and Bluetooth capabilities they have an amazing amount of IO capabilities.  I found one from that appears to have just about any IO type you could need.
Here is a list of what is available on the module.  Of course many of the pins are multipurpose so all of these functions are not available at the same time.  The module can be programmed directly from the Arduino environment without pushing any buttons.  The upload speed is 921600 bps, which makes program upload very fast.
  • 240 MHz dual core Tensilica LX6 microcontroller with 600 DMIPS  
  • Integrated 802.11BGN HT40 Wi-Fi transceiver, baseband, stack and LWIP   
  • Integrated dual mode Bluetooth (classic and BLE) 
  • 4 MByte flash 
  • 3 x UARTs, including hardware flow control 
  • 3 x SPI
  • 2 x I2S
  • 12 x ADC input channels
  • 2 x DAC
  • 2 x I2C
  • PWM/timer input/output available on every GPIO pin
  • SDIO master/slave 50 MHz
  • SD-card interface support
What I liked about this version is that all the IO pins are brought out to single row headers on each side of the module, that is only slightly larger than a Nano.  That and the fact that they are under $10, made this something I wanted to try.

I ordered ordered one and after it arrived I configured my Arduino IDE environment to support the ESP32.   I first compiled an empty sketch to see just how much program and variable space is available.  I was a little surprised at first to see how large the core  was that it compiled. 
Sketch uses 159060 bytes (12%) of program storage space. Maximum is 1310720 bytes.
Global variables use 10756 bytes (3%) of dynamic memory, leaving 284156 bytes for local variables. Maximum is 294912 bytes.
But after checking around several sites, I found that this includes all the functions associated with Wifi and Bluetooth and most of the functions available in the ESP32 SDK.  It also includes FreeRTOS, a real time operating system that allows you to do multi-tasking and  use both cores at the same time.  So even though it takes nearly 160K program space and around 11K sram, there is still over 1.1 MB program space and  280K sram available for variables.  I think it will take a while before I can come up with a program to use all of that. 

Next I attached a 2.8"  320 x 240 TFT display to see how fast it was.  Using the Adafruit graphic library and drivers the speed for the standard graphics test using the SPI bus was about the same as using a 8 bit interface on a Nano.  Not going to be any problem with display speed that I can see.  

Looking around for information on the ESP32, I found a great series of YouTube videos by G6EJDThey range from basic Arduino IDE install and setup to advanced web servers.  There are many other great YouTube videos available from others that cover many advanced topics.

I have been following a series of podcasts from 'Chatting with the Designers'  CWTD.ORG that cover building simple Arduino based test equipment.  I decided that this would make a nice way to get into development with the ESP32.  The CWTD 'Test Gadget' is basically an Arduino Nano with a 2 line LCD display, and a breadboard area where small modules can be plugged in to make different types of instruments.  My version will use the ESP32 and the TFT display.  I am also replacing their rotary encoder with a joystick for the user interface device.  I am bringing all the pins from the ESP32 module out to two pairs of female headers, that should allow me to plug in two small modules at the same time.  I also added a couple extra pins to the headers to supply 12 V. to the modules and a couple pins that allow signals from one module to be connected to another with out having to run jumper wires.  The use of female headers will also allow me to connect to a wireless breadboard for initial testing of module prototypes.

I designed a simple board to provide two pairs of headers so I could plug in two  4x6 or 5x7 cm. modules at a time, or allow the use of a single 8x12 cm. module.  To keep the size down I have the ESP32 module mounted on the back of the board along with a 5 V regulator to bring the 12 V supply I plan on using down to  5 V to power the ESP32 board.  This allowed me to keep the board size down to the 10x10 cm. size that qualifies for the inexpensive rate from multiple Chinese board houses.

After the boards arrived, I quickly built one up.  I found that I had to make a small change and add a jumper to get the display to work properly, also needed to add a pull-up resistor for the switch on the joystick.  While I was waiting for the boards to arrive, I had designed and 3D printed a  small case to hold everything.  I had a bezel and mounting plate I had previously done for the TFT display and joystick, so designed the case to use that.  After it was assembled, I wrote a quick sketch to see what the unit will look like with the display active.  

Now I just need to wire up some simple modules and write some code to see how everything will work. If everything goes as I hope using the TFT display, I will think about enabling the WiFi .  This could possibly lead to having some simple Web based instrumentation.  As always I will keep you informed of my progress.

Update 6/3/18
Just a few notes on the 'Test Gadget' mother board for a couple of those who asked.  I have added a schematic of the mother board, and a couple things I had to do to get everything working the way I wanted it to.  
First problem I ran into was with the RESET on the TFT display.  I wanted save the use of a pin on the ESP32, so originally tied the RESET pin on the display to 5V.  I could not get the display to start up consistently.  I removed the pull-up I had on the board and ran a jumper to the LED pin.  It appears that RESET wants to be closer to 3.3 volts.  The only other problem I found was that I had to add a 10K pull-up from the joystick switch to 3.3 volts.  Some joystick modules have pads for this purpose, but I just added an external resistor across  the appropriate contacts on the mother board.
Power to the board is 12 volts that goes to a 1117-5 5 volt regulator.  The 5 volts goes to the VIN on the ESP32 board and to pins on the module connectors.  The 12 volts is also brought out to another pin on the module connectors for use by any analog circuitry that requires a larger voltage.
In most of my previous projects, I used a rotary encoder for the User Interface device.  For this I am going with a small Joystick with switch.  From some of the testing I have done with this, I find it to offer more versatility and speed of use than a Rotary Encoder. The ReadJoystick function stores the V, H and SW values in global variables, and if any changes occur a global status variable is set.  The V and H values are +- 1 or 2 depending on direction and degree of movement.  The SW values are either  1 for a short press or -1 for a long press of over .5 seconds.  
In the setup()  routine the center H and V values are read and used to set a 'deadband' area that determines the how far the Joystick must be moved to get a reading.  This value is also used set the amount of movement required for the two movement values.

void ReadJoyStick() {
  int jsVin;          // variables to hold raw input from joystick
  int jsHin;
  int jsSWin;
  jstick = false;     // clear all global variables
  jstickV = 0;
  jstickH = 0;
  jstickSW = 0;
  // look for input opn vertical axis
  jsVin = analogRead( jsVPin);
  if ( jsVin > jsVcenter + jsDeadBand) {              // maintain dead spot around center position
    jstickV = 1;
    if ( jsVin > jsVcenter + jsX2)                    // large movement so bigger value
      jstickV = 2;
    jstick = true;                                     // set joystick value changed flag
  else if ( jsVin < jsVcenter - jsDeadBand) {              // maintain dead spot around center position
    jstickV = -1;
    if ( jsVin < jsVcenter - jsX2)
      jstickV = -2;                                        // large movement so bigger value
    jstick = true;                                         // set joystick value changed flag
   delay(100);                                           // to prevent noise issues
  // do the same thing for Horizontal axis
  jsHin = analogRead( jsHPin);
  if ( jsHin > jsHcenter + jsDeadBand) {              // maintain dead spot around center position
    jstickH = 1;
    if ( jsHin > jsHcenter + jsX2)
      jstickH = 2;
    jstick = true;
  else if ( jsHin < jsHcenter - jsDeadBand) {              // maintain dead spot around center position
    jstickH = -2;
    if ( jsHin > jsHcenter - jsX2)
      jstickH = -1;
    jstick = true;
   delay(100);                                         // to prevent noise issues
  // check for switch pushed
  jsSWin = digitalRead(jsSWPin);              
  if ( jsSWin == LOW) {
    jstickSW = ShortPress;                              // 1 if short press
    jstick = true;
    delay(500);                               // delay half second to
    jsSWin = digitalRead( jsSWPin);           // see if it was a long press
    if ( jsSWin == LOW)
      jstickSW = LongPress;                  // -1 for a long press
 delay(100);                                         // to prevent noise issues
This function is called  repeatedly in the program any time a input is allowed.  After the input is processed the status variable needs to be cleared.  For now this routine is just called from the main program code as needed.  Later when I start playing around with the multitasking  and dual core functionality, I might change this to a background task that runs all the time.

Monday, April 2, 2018

Stand-alone Simulated Analog Meter updated 4/27/18

Now that I have the latest QQ article finished, I have a little more time for some of my other projects.  One of them is working on the graphic display for the uBITX, I came up with a simple simulated analog meter that worked quite well.  Only problem is with the Raduino, board there is only one available analog pin. Thinking about ways to get around this I looked at some of the inexpensive I2C ADC baords available on e-Bay.  That would do for the uBITX, but I also wanted something I could use with the BITX 40 and a couple of other projects I have been thinking about doing.  I started to wonder how hard it would be to build a stand alone simulated analog meter with several input channels and control lines to select what values are being read and displayed. I wanted it to be small, and simple to construct.  Looking around I found aYou-Tube video showing a Arduino Nano based VU meter using one of the small .96" OLED displays.  Since I had several of those displays' from another project I thought I would try something based on it.

 The video comments had links to the source code and instructions for building the meter.  I thought this would make the basis for a nice little meter that could be added to almost any transceiver.

Thinking about what values I would like to display, I came up with three basic items.  A S-meter when in receive, and a power output display when in transmit.  In transmit, I would also like to have the capability of measuring VSWR.  Thinking about the switching functions required for this I will need one control line that monitors  transmit/receive, this can come from the PTT or key line in the transceiver.  Then  I use a second control line to select either power or VSWR when the T/R line is in transmit.  Another control line can do the same for the S-meter or some other display when in receive.  Since this is based on a VU meter, I will use that for the secondary function in receive.  Now looking at the signal lines I need to measure, they are the AGC line for S-meter, audio signal for VU meter.  And in transmit, the forward and reverse power levels will take care of power and a computed VSWR reading.

I can easily get the 4 analog and digital lines I need from my favorite Arduino for embedding in systems, the Pro-mini.  I like it because of its smaller size since it does not have the USB interface built in like the Nano.  This also means that it takes a little less current than the Nano.  Looking at the physical layout of pins on the Pro-mini, I can get 4 digital, and 4 analog pins in a row that I can use for my control and input signals. 

 I have some pre-made 8 wire cables with a connector, and matching jack that fits the pin spacing on the Pro-mini.  And since I only need 4 wires for I2C OLED display, it was easy to solder a short cable directly from the Pro-mini to a 4 pin connector for the display.
I will be able to supply 5 volts to power everything through the programming pins at the end of the Pro-mini.  If needed I can build a small board with a 5 v regulator and possibly some filtering, so I can run everything off the 12 volts in the transceiver.

After everything was wired up, I loaded the VU-Meter sketch and was very happy with the response of the meter.  Since the display is basically monochrome, it only takes a 1 kilobyte image file to completely redraw the screen.  This allows for a very fast update, and a realistic looking needle movement. The OLED display I had has a two color effect, that is created by two different colors of plastic in its construction.  I have ordered several additional displays that have only the blue overlay. Following the procedure mentioned in the original article, I drew a set of the meter faces I would need for the basic functions of the meter.
 For the power meter function, I decided on a maximum reading of about 15 watts.  The uBITX is rated at about 10 watts on 12 volts, and a little bit more if a higher supply voltage is used on the final amplifier stage.
 Not sure what I plan on using for the S-meter, for now I will probably just rectify the audio output of the preamplifier stage and read that directly.  Later I will see about some sort of an AGC circuit that I can use for the S-meter reading.   The display function I wrote for all except the original VU reading, have provisions for using simple constants to set the full scale movement of the needle, and any DC offset in the circuit at the being measured.

The VSWR display goes up to about 1:3.8 which should be more than adequate for most use.  I think I can use the same directional coupler, without its amplifier that I have in my QRP power/SWR meter. Since I am measuring both forward and reverse power, I can compute the VSWR without having to worry about the power output. 

As far as the signal levels being measured, I can take anything up to 5 volts without having to add in a adjustment pot or voltage divider.  The software should be able to manage full scale and offset values with simple defined constants.

I still have one extra control signal I can use for selecting the display function.  Now what else can I do with this display? Possibly an audio frequency spectrum display, so I can join those on 40M with their SDR rigs that are quick to let everyone know exactly how too wide your signal is.  Lets see what I can come up with, stay tuned.

UPDATE  4/4/18
Finished up the software to select the desired display screen, and modified one of the Audio spectrum analyzer sketches I found on line to fit in the program space available.  It works, but after playing with it, I don't know how useful it would be.  With the memory available, it is only possible to do a FFT that will cover to about 5 KHz. , and I would probably have to add a preamp to get enough voltage for a usable display.  
But It works and feeding a fairly large tone in from a signal generator, I could get a reliable display of the spectrum of that tone.  Trying it on a normal SSB signal did not give anything I found to be usable.  I guess if you were doing CW and had a narrow audio filter in line, you could use the FFT display to see what other signals are around you.  Here is a photo of the response with a 1200Hz. signal from a signal generator. 

UPDATE  4/4/27
I spent a little time working on a directional coupler to measure forward and reflected power for the Power/SWR display functions.
I went with the same basic design I had used in my SWR meter, without the amplifier.  This should give decent sensitivity with normal output levels on the uBITX.  

I need to test it with one of my other transmitters to see what power range I have and if I need to do anything to scale the values before I feed them to the pro-mini ADC.  
Here is a link to the software so far if anyone is interested in playing with one of their own.

Monday, March 5, 2018

Sweeprino Jr revisited Update 3/16/18

Well after three weeks of feeling terrible and not having the ambition to do anything, I finally got over what ever version of the 'flu' I had.  This has put me quite a bit behind in working on the next article in the series of Arduino building blocks for QQ.  Over a year ago I had started on a version of Farhan's Sweeperino project. at  I knew this would make a great basis for the next article

Since this was  to be a stand alone instrument or connect to a PC to use Farhan's  'Specan.exe' software, I made some changes to my Arduino/display building block.  I changed from a pro-mini to a Arduino Nano.  This gave me the USB interface to a PC, brought out the I2C lines that do not have dedicated pins on the pro-mini.  The Nano also has a heavier duty voltage regulator on the 5 volt line.  This will allow me to run a Adafruit SI5351 board with out having to add additional voltage regulation. I also added a rotary encoder with push button to use as the interface to the software.

Doing the board layout for these changes was very easy.  Mainly because except for the form factor, it is very near to what I did to make the stand alone VFO/BFO board for Pete's Simpleceiver project.  Instead of making my own boards this time, I took advantage of a promotional offer by one of the Chinese board houses.  For a limited time they had offered 10 boards for a little over $5 and free shipping. 
 I couldn't even buy the raw pcb material for that price.  After they arrived and I built one up, I found a small error I had made in the board layout.  One end of a resistor was grounded that should not have been.  After discovering the error, about 30 seconds with a hobby knife took care of the problem.  Also modified the 3D printed case I had designed for earlier projects in the series to fit the new board

I pulled a copy of Farhans sketch, and made changes to use a tft display instead of the 2 line LCD he had in his original unit.  The first cut of the software worked with the PC interface, and a simulated two line  LCD display on the TFT display.  

After making sure everything was working I decided to use the graphic capabilities of the TFT display.  In previous projects, I had used simple bar graphs to give a analog representation of values, to make tuning easier than just a digital value.  I was real happy with the simulated analog meter I came up with for the uBITX, so I incorporated it in the new display screen for the manual operation mode.   I made a few changes to the basic code  so I could also display the actual value as a number along with the analog meter.    Still trying to decide if I want to add a sticky needle in a slightly different color to indicate the peak reading for the last few seconds.  Will only take a couple lines of code, but not sure if it will be necessary.  For the frequency setting display, I decided to show the digit that is changed by the rotary encoder in a different color than the rest of the value.  So a short push on the encoder button moves the active digit around in a circular manor.

Need to do a little more checking of the software so far. Then the only other thing I want to add is a graphic sweep waveform very similar to what I have on my SNA Jr.  Just going to be very basic, so everyone can add any additional functions they want.

Will keep you informed, but I also have to hurry up and write the article for QQ to have it ready for the next issue.  Maybe this time they can get the author correct.

Update 3/16/2018

Finally finished the QQ article on the Sweeperino Jr so far.  I decided to make this two articles instead of just one.  The first one will have the Sweeperino Jr with the same basic functionality as the original.  In the next article, I will add a graphical sweep function similar to the SNA Jr.  I have the latest Eagle file Gerber files , and Arduino sketch in a dropbox folder for any one interested in building one of these.

It works quite well, if you understand that there are going to be some issues with harmonics because of the square-wave output.  I am working on a method to get rid of that problem, and mostly finished with the preliminary design for the SNA Jr. version III.  Hope to get around to finishing that in the near future.

Saturday, January 27, 2018

SWR / Power Meter QQ article

I caught a case of the 'flu' and for the last week have been just sitting around without the energy to do anything.  About the only thing I accomplished was to open the envelope with the latest issue of QQ.  I saw that there has been a mix up and my second article on Arduino building blocks was credited to Glen Popiel KW5GP.  Since reading Glen's book on Arduino projects for the ham was one of my inspirations for learning the Arduino, I didn't  feel too bad.  And, if every one hates the article, Glen gets the blame not me.
As with the last article I have build notes for those interested in a dropbox folder along with the Eagle CAD files, Gerbers and Arduino sketch  at
Once I get to feeling a little bit better, I will update that folder.  For now it is time to take another batch of cold/flu medicine and pretend to be a vegetable for a little while longer.

Thursday, December 28, 2017

uBITX TFT display update 1/10/2018

I had a little time over Christmas weekend while everyone else was watching football to work on the TFT display for the uBITX.  I grabbed a 2.4" TFT display from another project and connected it to the Nano I am using as a test bed.  Just to be sure about the logic levels the display wanted I fed the control lines through a voltage divider made up of a 4K7 and 10K resistors.  This display gave me a much larger area to work with, and I could add some of the features that several other people suggested.  One of them was the display of the A: and B: VFO frequencies.   I decided to display the active VFO frequency in a larger font, with the alternate in a smaller font and a different color. 

 Another suggestion I uses was, when the RIT function was active, I displayed the offset from the transmit frequency.  I also changed the RIT tuning steps to 50 Hz. instead of 100.  I still have several other settings I need to display on the screen, but it is starting to take shape.

One other thing I wanted to do was add was an analog meter.  Mainly to use as a s-meter, but possibly as a power meter that will switch between modes on receive or transmit.  I looked at and tried the code from several versions I found, but they were fairly large in code size and required quite a bit of processing to compute the needle movement.  I decided I wanted top try something a little simpler.  Instead of using sin and cos functions to compute the angular position of the needle, I would treat  everything as a straight line value.  This lets me just draw a line from a pivot point for the needle to some point near the top of the meter face.  The line length would vary, but the effect would look close enough to an actual meter.  This resulted in two very simple functions, one to draw the meter itself and the other to plot the needle.  To move the needle, first it is drawn in the face color of the meter to erase the old value and then redrawn in the desired needle color.
The function to draw the meter is very simple 

void drawMeter(int x, int y, int w, int h, int face_c, int bar_c, char *txt) {
  tft.fillRoundRect(x, y, w, h, 5, face_c);
  tft.fillRoundRect(x + 1, y + 1, w - 2, h / 5, 3, bar_c);
  tft.drawRoundRect(x, y, w, h, 5, YELLOW);
  tft.setCursor(x + 2, (y + (h/5))-12);

Draw a  filled rectangle with rounded corners at the desired position and size, then draw another that will serve as the background color for the meter scale.  I also added another empty rectangle around the main one to highlight the meter.  Then position the cursor and print the meter scale.  I did not add auto sizing of the meter, so the actual size of the main rectangle, will have to be determined manually from the desired text on the meter scale.  To draw the basic meter without needle is to give it a position, size , colors needed, and scale text.

// define some values for the meter position and size
#define  MTR_X   160
#define  MTR_Y   108
#define  MTR_W   155

#define  MTR_H   100

drawMeter(MTR_X, MTR_Y, MTR_W, MTR_H, WHITE, RED,"0  2  4  6  9 +20 +40 +60");

Plotting the needle was simpler than I had expected.  Since I was treating the meter range as a straight line value.  I pass the function the same parameters for position and size as the drawMeter function, and add the value, max_value and color to draw the needle.  
void plotNeedle(int x, int y, int w, int h, int value,int max_value,int color)
  int tw;
  int w2 = w/2;
  tw = map(value, 0, max_value, 3, w-3 );
  tft.drawLine(x + w2 ,   y + h - 4,  x+tw ,    y + (h / 5)+4, color);
  tft.drawLine(x + w2+1,  y + h - 4,  x+tw+1  ,  y + (h / 5)+4, color);
  tft.drawLine(x + w2+2,  y + h - 4,  x+tw +2 , y + (h / 5)+4, color);
Then I used the Arduino map() function to return a value that represented the position along the meter scale based on the value read and the maximum value.  Then just plot a straight line from the pivot point for the needle to just below the meter scale, which I compute depending on scale size.  I draw this three times with a slight offset to make the needle more visible as it moves. 

Since the only available Analog pin is A7, wrote a little code to read that value and display the meter reading. 
  plotNeedle(MTR_X, MTR_Y, MTR_W, MTR_H,last_meter,1023,WHITE);
  plotNeedle(MTR_X, MTR_Y, MTR_W, 1MTR_H,meter_reading,1023,BLACK);

Next I will see about building something to get a signal from the uBITX to display.  I might start with a simple voltage doubler off the top of the volume control just to see how well it works.  Later I will probably tap into the IF chain to get an actual S-Meter .  Also thinking about adding a pickup off the antenna lead to measure power output, I can probably use the PTT signal to allow switching between meter readings from receive to transmit.

Update 1/10/2018

After playing around with several different versions of the display screen, I have come up with something I like.  Following a couple of suggestions from N6QW, I now show options available in Cyan and any active settings in Yellow.  On the screen you can see the second VFO frequency, and that RIT is optional.   

Below the frequency read out, I have an area to display the command prompts from the uBITX, such as band change, VFO selection, RIT on/off. 

When RIT is turned on the offset from transmit frequency is displayed. I did make a change to the original code to change in 50 Hz. steps instead of 100 Hz.  

Finally I added a transmit indicator, and also checked the CW keying line and changed the mode display while a keying is present.

I am happy with the way the display looks, now to put everything in a box and see how it works.  I think I will re-write the code I have for the BITX40 and use one of the VFO/BFO boards I designed.  With that I have more Analog input pins available and should be able to implement power and SWR readings on the screen.

UPDATE 1/29/18 

I have received several questions about the display I used on my uBIX.  The ones that I am most interested in are the ones that use a  ILI9340 or ILI9341 controller.   They are available in 2.4" or 2.8 " models.  I have found the response to be very fast using the standard SPI interface.  

The main issue with them is that they usually require 3.3 volt logic levels instead of the 5 volt from Arduino, I have found a simple voltage divider does well in this application.  I usually power the LED pin through a 100 ohm resistor to 5V.  If a PWM pin was available, I would add backlight intensity control instead.  Software changes in the main sketch  ubitx_20 were fairly simple, and then I replaced the ubitx_ui  file with a modified ubitx_tft_ui file.  Changes to the ubitx_20 file are made in the declarations 

Comment out the original display driver  and replace with the Adafruit drivers
#include <LiquidCrystal.h>
  LiquidCrystal lcd(8,9,10,11,12,13);


#include <Adafruit_GFX.h>
#include "Adafruit_ILI9340.h"
#define _sclk 13
#define _miso 12
#define _mosi 11
#define _cs 8
#define _dc 10
#define _rst 9

#define CALLSIGN  "KV4QB"

// Color definitions
#define BLACK   0x0000
#define BLUE    0x001F
#define GRAY    0x3333
#define RED     0xF800
#define GREEN   0x07E0
#define CYAN    0x07FF
#define MAGENTA 0xF81F
#define YELLOW  0xFFE0
#define WHITE   0xFFF6

Adafruit_ILI9340 tft = Adafruit_ILI9340(_cs, _dc, _rst);

and then in the setup code make these changes
  // lcd.begin(16, 2);   // using tft instead of lcd

  // setup the tft display and draw basic display screen
  //tft.initR(INITR_BLACKTAB);  //ST7735 depends on exact one used
  tft.setRotation(1); // landsacape versus portrait


  //we print this line so this shows up even if the raduino
  //crashes later in the code

  printLine1("uBITX v0.20");

  tft.setTextColor(YELLOW, BLUE);
  tft.setCursor(22, 20);
  tft.print("uBITX v0.20");
  tft.setCursor(22, 20);
  tft.print("           ");

With the updated ubitx_tft_ui code I tried to keep the code in the other files as unchanged as possible.  Except for the display, nothing else has been changed.

Here is a link to my modified uBITX sketch to support a TFT display instead of the normal 2 line LCD display.  Hardware change  is a small board with the voltage dividers that has a connector for the TFT display.  Only the first 8 pins are used.  Then there is a short cable that plugs in where the existing display plugs in on the Raduino board.

Sunday, December 17, 2017

Santa Came Early - uBITX update 12/20/17/.........

I had not realized that Santa traded in his Sleigh for a yellow cargo van, but he must have.  After seeing that the new uBitx was available for sale last Saturday, I thought about ordering it.  Then about 2 AM Sunday morning I couldn't resist much more and pushed the button at Paypal.  

Just sitting around Thursday afternoon when the door bell rang, and there disguised as a DHL deliver driver was Santa.  I couldn't wait to see what the new toy looked like.  So after letting Santa get on his way to his next delivery, I tore into the box.  Inside the sturdy cardboard box was a plastic box with a couple of bubble wrapped boards, and a bag of parts. The uBitx board and Raduino are each wrapped in bubble wrap, and I could not see any shipping damage on either one. 

 I plan on replacing the 2 x 16 LCD display with a small TFT display, so I took a look at the wiring diagram of the display connector.  I checked the pins and they contain all pins to use hardware SPI on the Arduino to drive a TFT display.  I wired up a 1.8" display I had from other projects, and could not get it working with the pin combination I choose.  Playing around with some other wiring combinations, I was able to get it working.  Still wondering about that, because I have always been able to map anything but 11 and 13 to anything I wanted to use.  I realized that pin 12 is also used by the hardware SPI, and after changing to pin 10 everything worked as expected.  First thing I had to do was disable the LCD driver software and include the Adafruit libraries for the ST7735 and the graphics routines.  After that I replaced the LCD display routines with ones written for TFT display.  Luckily the uBITX routines map everything related to the display to a couple of simple functions.  It took very little to change these over to the TFT display.  
The only problem I found was that with the 1.8" display I only had a x resolution of 160 pixels, and that limited me to using a small size font, without the text wrapping around to the next line.  But everything should work after I redesign a display screen layout to replace the default two line layout used in the stock uBitx.  The 1.8" display could be wired in directly, but for a 2.4" or 2.8" I will need to converted from 5 to 3.3 volts on the control lines.  I have found that simple voltage dividers work well for this, as the data flow is only one way.  At last something to keep me busy for the holidays

UPDATE 12/20/17
To make things a little easier to work with on converting the uBITX display to a TFT display, I wired up a Nano, display, encoder, and a couple other parts on a wireless breadboard.  This will allow me to take everything along when I go to spend the holidays with relatives.  So far it has been fairly easy to come up with a screen layout that fits well on the 1.8" display.  I am trying to limit any code changes to the ubitx_ui module, and mainly to the updateDisplay() function.  This should make it possible to easily switch back to the LCD by just loading in  a different version of  the ubitx_ui module, or possibly use  of #ifdef depending on how complicated the whole thing turns out.
With the limited size on the 1.8" display I am trying to keep everything as simple as possible.  It looks like I will probably have to switch toa separate screen display when I switch to setup mode.  When I move to a 2.4" or 2.8" with higher resolution, I will have room for information to be displayed at one time, and may be able to add a pop-up sub menu. 

As of now I have the FREQUENCY, VFO, and MODE display finished.  Just now trying to add the RIT status display to the empty red box on the right of the screen.  Also plan on having the command prompts from pushbutton work as a pop-up item. Don't know how much I will get done before I have to pack it up and go visit relatives, but will keep you informed.