loading

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.

<p>I adapted your sketch for the stm32duino and an ILI9163C 1.44&quot; 128x128 TFT</p><p>See the results here....</p><p><a href="http://stm32duino.com/viewtopic.php?f=13&t=292&start=10#p19583" rel="nofollow">http://stm32duino.com/viewtopic.php?f=13&amp;t=292&amp;sta...</a><br>Many thanks. </p>
<p>ILI 9163 version code is here -&gt; </p><p>https://github.com/pingumacpenguin/STM32duino_TFT_ILI9163_Analog_Meter</p>
<p>Have you had any issues with screen burn-in or are you only using this for short bursts? Thanks.</p>
Hi,<br>I have only run TFT's fot 100's of hours and the screens change so I have not seen any problems.<br>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 &quot;washed away&quot; by cycling the colours.<br>https://en.wikipedia.org/wiki/Image_persistence<br><br>These displays are so cheap I have not been concerned about the problem myself.<br>
<p>This is exactly what I was looking for. Thanks a ton!</p>
<p>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?</p><p>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?</p><p>Thanks and congratulations</p>
Here you are, hope this is what you want...<br><br>The zip file contains a new library for the ILI9341 display and a sketch called &quot;TFT_Meter_linear_4_30&quot; which has been modified.<br><br>TTFN
<p>Hi, first of all I wanted to thank you for helping me !!!!</p><p>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 ?</p><p>Regards</p>
<p>Hi,</p><p>I have tested it again on my setup and it works fine. Can you post a picture so I can see these blue lines?</p><p>It looks like the display data going to the display is getting corrupted. Do you have any other electronics connected?</p><p>TTFN</p>
<p>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)</p><p>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 !!!</p>
<p>Try this version.</p><p>TTFN</p>
<p>Perfect, that is just what I needed, Bodmer!!!! Thanks a lot!!!!</p><p>Another question, you can display text at the bottom of the TFT, the party remains free under the indicator, which indicates eg &quot;RH METER ON&quot; when the A1 (Arduino analog input) is set to &quot;1 &quot;or high value?</p><p>THANKS A LOT BODMER!!!!!</p>
<p>Just add these lines after plotNeedle function on the loop():</p><p>tft.setTextColor(TFT_WHITE,TFT_BLACK); // Text colour<br>if(analogRead(A1)&gt;511) tft.drawCentreString(&quot; RH METER ON &quot;, 160, 210, 4);<br>else tft.drawCentreString(&quot; RH METER OFF &quot;, 160, 210, 4);</p>
<p>Thank you very much again, Bodmer. Thanks for sharing your knowledge and the time you spend with us</p>
<p>Hi</p><p>I've tried to modify the sketch to suit the 1.8&quot; ST7735 Display with no joy</p><p>is this something you could help with ?</p><p>many thanks</p><p>Sam</p>
OK, it is tricky to mod..<br><br>Here is a copy of the ST7735 library I use and I have added a meter sketch that works with this display.<br><br>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. <br><br>Let me know how you get on with it.

About This Instructable

16,552views

54favorites

License:

More by Bodmer:Arduino - TFT display of icons and images from FLASH memory Arduino - TFT display of bitmap images from an SD Card Arduino analogue 'ring' meter on colour TFT display 
Add instructable to: