by Floris Wouterlood – September 1, 2023

**Summary**

With a robust Arduino Nano – 1.28” circular display bench assembled after a prototype described in a previous post (*) one can concentrate on developing attractive visual sensor value presentations. Think of thermometers, dials, gauges that show temperatures, revolutions per minute, speed, power generated, humidity, time, etcetera. Six such applications are discussed here.

figure 1. Voltage meter (left) and humidity display (right) on the Nano bench with circular display with GC9A01 controller.

**Bench**

First the bench. The essence of the Nano bench is illustrated in the previous post (*****) and repeated at the end of this post (figure 5): an Arduino Nano wired to an 1.28” circular TFT display with GC9A01 controller. These displays offer an amazing 24*240 pixels. They are used in smart watches and the like, often combined with sophisticated graphical interfaces. Reason to construct a bench around a Nano platform is that compiling time for the Nano is so much shorter compared with that for the more powerful microcontrollers that it saves much time developing essential for sketches on a Nano bench. And it is rewarding to write sketches that produce nice displays while at the same time fitting in the Nano’s severely limited memory space (32kB). While the display is a 3.3V device the Nano delivers control signals at 5V. This voltage is reduced to approximately 3V by the 220 Ω resistors in series in the SPI control wires. Crude but effective! For the sake of completeness follows here the spherical TFT’s SPI pin connectivity table.

**Pin connectivity table**

GC9A01 display |
Arduino Nano pin |

RST | — |

CS | 10 |

DC | 9 |

SDA | 11 |

SCL | 13 |

GND | GND |

VCC | 3V3 |

**Library**

The library used here is the Adafruit_GC9A01.h library. Instructions available in this library follow Adafruit convention. Three of the examples discussed in this post contain functions adapted from original examples that form part of Bodmer’s TFT_eSPI library. The latter library contains a treasure of snippets and functions. Many can be transferred to the Nano. Thanks, Bodmer!

**Juggling with arcs and triangles**

One limitation of the Adafruit_GC9A01.h library is that there is no function available to draw polygons. Lines, rectangles, circles, triangles – open or filled, that is the entire menu. However, creating polygons is very well possible by putting a few triangles together. Even a rainbow can be simulated with a series of triangles arranged in an arc shape. Another way is to define a series of points and draw lines between them to complete the polygon.

figure 2. Simple mathematics govern circles, arcs and scales.

How to create an arc? An arc is no more than a circle segment. However, the Adafruit_GC9A01 library does not provide a circle segment function. A workaround is to create one’s own circle segment. A complete circle consists of a series of pixels neatly arranged, at a fixed distance called the radius, around a circle center. The radius makes a 360 degrees turn to complete a circle. The total length of the circle circumference is 2 * pi * radius. Here the magic number pi (3.1415926535) comes into the picture. If one draws only part of the circle, say half of it, an arc is created with a length of pi * radius.

Essential elements of an arc are the x and y coordinates of the circle center, the length of the radius and the rotation angle of the radius versus the horizontal. The x and y coordinates of the pixels at the far end of the radius determine the arc. Let that pixel glow, start rotating and the arc magically starts to grow.

Note that there are two factors that cause confusion in the programming. First the rotation angle, whose start is the horizontal, say West. By contrast, magnetic compass scales start counting the rotation angle beginning with North. The second confusion factor is that the Arduino compiler works with angles expressed in radians instead of degrees. The rotation angle one complete circle is 2*pi radians. It is common to define in an Arduino sketch a conversion factor that translates degrees into radians: #define DEG2RAD 0.0174532925. Convenient, since does not have to type in the numbers all the time. An alternative is to divide the angle in degrees by 2*pi.

We do have now the x and y coordinates of the circle center, a radius and a rotation angle. The x and y coordinates of the pixel at the end of the radius are determined by the radius multiplied by the cosine and sine of the rotation angle, respectively.

figure 3: Bodmer’s rainbow spiral (adapted from his TFT_eSPI library example to the current.

figure 4: Pie chart data presentation with continuous expansion and shrinking of the ‘pie’ in mono (left) and in rainbow colors (right).

**Segmented arcs fabricated with triangles**

If one creates two concentric arcs: an outer and an inner arc, and creates on both arcs points by intersecting with a particular radius, as spokes in a wheel, then series of outer points and inner points are created. Outer points can be triangulated with points on the inner arc, as shown in figure 2. If each triangle is supplied with its own rainbow color a segmented rainbow is created.

**Rainbow lookup table**

As colors are indicated in the Arduino world with hexadecimal numbers in the RGB565 color scheme, e.g. 0x000 (white) or 0xFFFF (black) one can figure out which colors match those of the rainbow, going starting with blue, through green and yellow and ending in the red. I have created a 256-color rainbow lookup table in one of my Arduino infrared camera projects (******).

**Downloadable sketches**

(all the sketches need the Adafruit_GC9A01.h library for compilation)

All these sketches are based on the circle segment mathematics discussed above. As shown already by Bodmer with his rainbow scale meter, creativity is the key to the realization of colorful visualization of sensor data. The rainbow pie segment sketch, although inspired by Bodmer’s use of color in his ‘spiral’, uses the 256-color lookup table instead of Bodmer’s complex rainbow color generator.

The downloadable zip file contains sketches for:

• voltmeter

• humidity_meter

• pie_chart_mono

• pie_chart_rainbow

• Bodmer’s spiral

• tachometer

They are packed in GC9A01_Nano_gauges_meters.zip

auges_meters.zip

All sketches have been tested with ESP8266 and ESP32 platforms as well and they run fine with these microcontrollers, with some adaptations in the sketch specific to these platforms

**References**

**(***) **Arduino Nano and the circular GCA901 240*240 pixel TFT display** – TheSolarUniverse – August 1, 2023

**(******) 8*8 pixel AMG8833 thermal sensor, ESP8266 microcontroller board and a SSD1283 driven TFT display**. TheSolarUniverse – May 2, 2022

figure 5. Wiring diagram: Arduino Nano, 1.28” circular 240*240 SPI CG9A01 TFT display.