Arduino Code

I've put screen shots here so it is easy to see what the console should be doing. The next section refers to loading the code into the Arduino.

 

The first screen shows the 'normal' screen with Menus across the top, voltage measurements on the LHS, voltage and current measurements on the RHS and digital pin status along the bottom, red for 'false/low', green for 'true/high'. Finally in the centre is the resistance measurement.

 

The second screen shows the digital inputs enabled in Large mode, each input clearly displayed.

 

The third screen shows the voltage inputs in Large mode.

This project is based around the Arduino Mega 2650 for the simple reason I wanted a lot of I/O ports dedicated to tasks in a simple format. The libraries for the TFT touchscreen default to supporting the Arduino Uno and have to be edited to support the Mega. Editing the libraries is supported by the original TFT code author, is simple and described in the next step.

 

Using a touchscreen display is the basis of this part of the project but as the display someone ends up using may be different to the one I used, the code only places hardware specific functions in separate routines so all modifications necessary can be identified.

 

A working version of the code is included here and will be updated but the most recent updates will be on github.

The main function of the code revolves round the display, each element on the display having an entry in a single array which holds the element type, where on the screen it displays, colour, and additional parameters such as input source. A screenshot of this array with comments is shown above. It also holds a field to control whether it is to be displayed on the screen or not. By editing this array, new features can be added, or features removed. The 'loop' routine of the code runs through this array on a continuous basis, processing each eligible element sequentially and then repeating. There are currently 6 different elements.

 

Menu elements - these do not display information but when touched execute an associated subroutine, identified in the element parameters

 

Digital elements - display as a box on the screen as either red or green depending on the status of the associated digital input pin. The example console is wired for 8 digital pins but this can be increased or decreased as desired.

 

Analogue elements - display an approximate voltage as measured on the associated analogue pin. Four are originally specified.

 

Precision elements - display input from an external precision volt/current meter module. There are only three of these but a second or third module could be added.

 

Resistance element - this is a single element displaying the input from the resistance meter.

 

Touch - this is the only routine that is always executed to detect if the screen has been touched and then make a decision based on what has been touched. ie if a menu item, what does that entail being displayed next.

 

The screen has three status modes, normal, large and full screen and all elements change their operation depending on the status. The three modes are selectable from the menu by touching an element and the associated menu option.

 

Normal mode - displays 8 digital inputs, four analogue voltage inputs, three precision elements, the resistance element and four menu elements. Selecting Normal from the menu puts the display into this mode.

 

Large mode - is selected by touching any of the elements on the screen followed by Large. When selected, that element type is the only type selected and the elements of that type are rearranged to fill the whole screen.

 

Full screen mode - is selected by touching any of the elements on the screen followed by Full Screen. When selected, that element is the only element displayed and is rearranged to fill the whole screen giving maximum visibility of that one item.

 

To add additional functionality, the following routines need to be added

 

'draw' routine which is called to get the information for that element, call the appropriate screen update routine and register the returned touch information

 

'logic' routine which accepts the information from the draw routine and uses the appropriate screen driver routines to put the information on the screen and return the correct touch information for the area of screen drawn

 

'setup' routine which is called as part of the Arduino setup

 

Other routines can be included but there should not be any interdependence between element code, if an element hasn't been enabled then the it's code shouldn't get executed and the simple multifunctional structure retains it's integrity.

 

 

Editing the Arduino libraries

The display I used works very well with the Arduino Uno and the base libraries written for it but performs slowly when directly transferred to the Arduino Mega. To correctly drive the display, a different set of data pins have to be used and this change of use has to be setup in the libraries. This is a simple change and was intended by the author, David Prentice. The pictures highlight the changes made.

 

The two files are stored in the MCUFRIEND_kbv\utility folder as mcufriend_shield.h and mcufriend_special.h. The changes required are first to the 'shield' header file to ensure the first line reads

 

#define USE_SPECIAL

 

to ensure that the 'special' header file is loaded.

 

The 'special' header file must also be updated to ensure that the line

 

#define USE_MEGA_8BIT_PROTOSHIELD

 

is uncommented.

 

These two changes mean that the display code for this display will operate using pins 20-29 on the Arduino Mega instead of the default 3-10 on the Uno.

 

 

Loading the Arduino code

The code is attached, but as mentioned earlier will be put up to github at some time and the location added here. The main source code file is Arduino_Workbench_v01.ino and the other routines are to provide the various features.

 

If the libraries have been modified ok and the Arduino Mega2650 has been set as the target platform in the Arduino IDE, then the code should compile first time.

 

The libraries that will need to be loaded are Adafruit GFX and Touchscreen libraries which should be available from the Arduino library manager, a copy of MCUFRIEND_kbv downloadable from github and for the INA3221, the SwitchDocLabs library SDL_Arduino_INA3221 also downloadable from github, both come up quickly on a google search.

 

I am working on publishing a consolidated INA3221 library which I needed for version 2 or the workbench and also for another project, the IoT Motorhome.