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

46K7927

Intro: 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.

19 Comments

how to speed it up? its painfully slow and I can't figure out how to define delay as 0
if (ms_delay == 0) old_analog = value; // Update immediately id delay is 0
Its works with Arduino nano + Shield TFT 2.4 FOR Arduino Uno
Hi Clauder, did you use Arduino Shield ? like I try to use ?
You have your code ?
Tnx
Hi Bodmer, this is sublime
But I use a ILI9341 Shield like from ALI, plugged on UNO
It uses different library
Some intstruction DrawCircleString do not exist..
Any solution ?
Tnx
Jempi

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

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.

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

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

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

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

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

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 !!!

Try this version.

TTFN

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!!!!!

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);

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

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

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.