Introduction: Arduino Sketch for a Retro Analogue Meter Graphic on a Modern TFT Display

Another sketch from my collection that may be of interest...

Displaying small digital numbers of temperature and humidity etc on a tiny screen is not always the best way to show information. The old style analogue meters are better in some situations and are great for a quick visual check of a sensor reading from a distance, they are also a good way of showing trends. So here we have a retro looking analogue meter on a modern TFT display, complete with smoothly animated needle!

I've pulled together a couple of functions in a demo sketch here for digital and analogue meters. I have not got around to "parameterising" the functions, so at the moment it is not easy to draw the meters anywhere on the screen with defined size and scales, but if there is sufficient interest (and given time!) I will try to do this at some point, in which case this Instructable will be updated.

I used an UNO and 2.2" ILI9341 based 320 x 240 pixel TFT, these are available at low cost on the internet.

Step 1: Connecting Up and Libraries Needed

The UNO is connected to the TFT display as in my Instructable here.

The libraries needed are also in that Instructable too.

Step 2: The Meters

The analogue meter has a moving needle that sweeps slowly with configurable speed to show the new value of a variable. The value in this example is in the range 0 to 100 (I used it for showing humidity). Meter labels can be changed easily. The actual new digital reading is shown in the bottom left corner of the meter. Needle end stops are emulated for readings outside of the normal range! Coloured zones can be added to show comfortable ranges etc.

Tip: The needle flicker is minimal but removing the units display from the needle sweep zone will improve things (and also mean that Font 4 does not need to be loaded, saving FLASH space). Just two lines in the sketch (156 and 200) need to be commented out, use the new Arduino 1.6.0 IDE and switch on line numbering to help find them!

The digital meter uses a 7 segment font and shows a dim image of the unlit segments to try to emulate the look of a real 7 segment display! The colour could easily be changed, perhaps with the value as in my Instructable here.

Step 3: The Sketch

Here we are...

Normally I would make graphics functions like this easier to adapt, resize and relocate on the screen, but I did not need to elaborate the functions for my application. Come back for updates and any bug fixes at a future date!

Step 4: Video...

Here is a video of the analogue meter in operation (this includes some linear meters that are not part of this instructable). The needle flicker and jerky pauses in the video is due to my cheap webcam, the actual movement is much much smoother.

Comments

author
AndrewH356 made it! (author)2016-11-01

I adapted your sketch for the stm32duino and an ILI9163C 1.44" 128x128 TFT

See the results here....

http://stm32duino.com/viewtopic.php?f=13&t=292&sta...
Many thanks.

RIMG0963_small.JPG
author
AndrewH356 made it! (author)AndrewH3562016-11-02

ILI 9163 version code is here ->

https://github.com/pingumacpenguin/STM32duino_TFT_ILI9163_Analog_Meter

author
dcastor made it! (author)2016-05-16

Have you had any issues with screen burn-in or are you only using this for short bursts? Thanks.

author
Bodmer made it! (author)Bodmer2016-05-16

Hi,
I have only run TFT's fot 100's of hours and the screens change so I have not seen any problems.
TFT's don't suffer from permanent phosphor burns like CRT's did but it is possible to get image persistence in the LCD polarising medium which can sometimes be "washed away" by cycling the colours.
https://en.wikipedia.org/wiki/Image_persistence

These displays are so cheap I have not been concerned about the problem myself.

author
KD0CQ made it! (author)2016-05-06

This is exactly what I was looking for. Thanks a ton!

author
Mery YC made it! (author)2015-09-22

It would be too much to ask a skit where the orientation of the meter out 90 degrees to the right and to occupy 90% of TFT?

And it would be an example of how to modify the sketch paa have a full scale of 30 and a total of 100 increments for full scale deflection?

Thanks and congratulations

author
Bodmer made it! (author)Bodmer2015-09-25

Here you are, hope this is what you want...

The zip file contains a new library for the ILI9341 display and a sketch called "TFT_Meter_linear_4_30" which has been modified.

TTFN

Meter and library.zip
author
Mery YC made it! (author)Mery YC2015-10-02

Hi, first of all I wanted to thank you for helping me !!!!

It's perfect but I get a blue vertical parallel lines tested under needle.He ARDUINO fleet card and other new TFT and continue to show the blue vertical lines do not you get it done ?

Regards

author
Bodmer made it! (author)Bodmer2015-10-02

Hi,

I have tested it again on my setup and it works fine. Can you post a picture so I can see these blue lines?

It looks like the display data going to the display is getting corrupted. Do you have any other electronics connected?

TTFN

author
Mery YC made it! (author)Mery YC2015-10-03

Hi, thank you very much Bodmer. Already solved, the problem was that I was using an old IDE. I used the IDE 1.6.0 and it works perfect. You can center the meter in the center of the TFT? (Not in the top part)

And the indication at the lower left corner does not match the indication of the needle (needle) can be adjusted to match the indications of the needle and the digital display? Thank you and congratulations !!!

author
Bodmer made it! (author)Bodmer2015-10-04

Try this version.

TTFN

Centred_meter.zip
author
Mery YC made it! (author)Mery YC2015-10-11

Perfect, that is just what I needed, Bodmer!!!! Thanks a lot!!!!

Another question, you can display text at the bottom of the TFT, the party remains free under the indicator, which indicates eg "RH METER ON" when the A1 (Arduino analog input) is set to "1 "or high value?

THANKS A LOT BODMER!!!!!

author
Bodmer made it! (author)Bodmer2015-10-13

Just add these lines after plotNeedle function on the loop():

tft.setTextColor(TFT_WHITE,TFT_BLACK); // Text colour
if(analogRead(A1)>511) tft.drawCentreString(" RH METER ON ", 160, 210, 4);
else tft.drawCentreString(" RH METER OFF ", 160, 210, 4);

author
Mery YC made it! (author)Mery YC2015-10-14

Thank you very much again, Bodmer. Thanks for sharing your knowledge and the time you spend with us

author
Sam00Cleveland made it! (author)2015-10-01

Hi

I've tried to modify the sketch to suit the 1.8" ST7735 Display with no joy

is this something you could help with ?

many thanks

Sam

author
Bodmer made it! (author)Bodmer2015-10-02

OK, it is tricky to mod..

Here is a copy of the ST7735 library I use and I have added a meter sketch that works with this display.

You may have to change the initR parameter at line 40 to the one in 41 as some ST7735 displays use a different initialisation setup.

Let me know how you get on with it.

ST7735_Meter.zip