Arduino Precious Metals Display With Live Prices and Two Tested TFT Versions

by vandenbrande in Circuits > Arduino

52 Views, 0 Favorites, 0 Comments

Arduino Precious Metals Display With Live Prices and Two Tested TFT Versions

Dashboard.jpg
Arduino Live Precious Metals Display | Gold, Silver, Platinum & Palladium

Hello world! Today i made a live precious-metals display with an Arduino Mega 2560, a 3.2-inch 480x320 TFT shield and a Windows companion application. It shows Gold, Silver, Platinum and Palladium in EUR per Troy ounce and EUR per gram.


The Windows computer retrieves online prices and sends them over USB. The Arduino loads the BlueCore Tech artwork from microSD and draws the latest values on top. Keep the computer connected and the application running for online updates; the Mega does not connect to the internet by itself.


A particularly useful discovery came from testing two nearly identical TFT shields. My older board displayed the RAW graphics normally, while the board marked V2.0 showed inverted, washed-out colours. Byte swapping did not fix it. An LCD inversion command after initialization did. This guide includes separate sketches for the two boards I physically tested.


I also made a separate BlueCore TFT Layout Designer to help create new 480x320 dashboards. You can load artwork, position text and export coordinates and RAW backgrounds. The aim is to get the original project working first, then make it easy to customize.


Created by Danny van den Brande — BlueCore Tech.

Supplies

• Arduino Mega 2560 or compatible ATmega2560 board.

• Compatible 3.2-inch 480x320 TFT Mega shield. See the screen-identification step: this guide does not claim that every similar shield works.

• microSD card formatted FAT32, in the TFT shield’s own slot.

• USB data cable.

• Windows PC with internet access, Python 3 and Arduino IDE.

• Supplied SPLASH.RAW and METALS.RAW graphics.

• BlueCore Precious Metals Live v2.1 Windows application.


Optional: enclosure or stand; BlueCore TFT Layout Designer v2.0 for custom artwork and text positions.


No GPS shield is used in this project. Power and display connections are made through the Mega shield headers, and price data arrives over USB.

Identify Your TFT: the Two-Screen Discovery

Two-Screen-Versions.jpg

Look at the back of your shield before choosing a sketch. In my comparison photo, the top board has no visible V2.0 marking; the bottom board is marked V2.0. Both are HUGA 3.2-inch 480x320 Mega2560 shields.


OLDER / NON-V2.0 BOARD: use BlueCore_Precious_Metals_V1_OLD_SCREEN. It initializes normally and does not send command 0x21.


TESTED V2.0 BOARD: use BlueCore_Precious_Metals_V2_SCREEN. It sends command 0x21 immediately after LCD initialization.


Both tested sketches use ILI9481 in UTFT and RAW_SWAP 0. On my V2.0 board, RAW_SWAP 1 made the colours worse. The successful fix was LCD inversion, not byte swapping.


The version label is a useful clue for these two boards, not a guarantee about every seller’s hardware. Other visually similar shields and HX8357 variants have not been confirmed for this project. Do not randomly change drivers to imitate this result.

Assemble the Mega and TFT Shield

Disconnect power. Align the TFT shield’s headers with the Mega and seat the board evenly, making sure no pin is offset by one position. Insert the microSD card into the TFT shield’s slot after preparing it in the next steps.


The tested display declaration is:

UTFT myGLCD(ILI9481, 38, 39, 40, 41);


The control arguments are RS=38, WR=39, CS=40 and RESET=41. The shield provides its parallel data connections through the headers. This is a stacked-shield build, not a loose-panel wiring guide.


SD chip select is 53. USB connects the Mega to the Windows PC and supplies the serial link at 115200 baud. No additional signal wires are needed for the tested shields.

Install the Arduino Libraries

Install the base UTFT library, UTFT_SdRaw and a compatible SdFat library. SPI comes with the Arduino AVR board package. UTFT_SdRaw is an add-on; it does not replace UTFT itself.


The sketches include:

#include <UTFT.h>

#include <UTFT_SdRaw.h>

#include <SdFat.h>

#include <SPI.h>


UTFT_SdRaw draws the full-screen RGB565 images from the card. The supplied sketches compile with the local working libraries, including UTFT_SdRaw 1.2.4 and SdFat 2.3.0.


Library sources:

UTFT: http://www.rinkydinkelectronics.com/library.php?id=51

UTFT_SdRaw: https://github.com/ghlawrence2000/UTFT_SdRaw

SdFat: https://github.com/greiman/SdFat


Select Arduino Mega or Mega 2560 / ATmega2560 in Arduino IDE.

Prepare the SD Card

Back up any files you need before formatting. Use FAT32 and copy these two files directly into the root of the card:


SPLASH.RAW

METALS.RAW


Each supplied file is 480 × 320 pixels, RGB565, with two bytes per pixel and no BMP header. Each must be exactly 307,200 bytes. These are binary RAW graphics, not renamed PNG, JPG or BMP files.


Keep RAW_SWAP set to 0 in both sketches. Insert the card into the TFT shield’s microSD slot. The sketch uses sd.begin(SD_CS, SPI_HALF_SPEED), with SD_CS set to 53.


Download both attachments below. If the website saves a generated filename or .unknown extension, rename the correct downloaded file back to SPLASH.RAW or METALS.RAW using its attachment label. Show filename extensions in Windows so you do not accidentally create SPLASH.RAW.txt. Do not place them inside a folder on the card.

Upload the Sketch Matching Your Screen

Download the .ino matching your TFT. Restore its original filename if Instructables renames it. Put BlueCore_Precious_Metals_V1_OLD_SCREEN.ino in a folder named BlueCore_Precious_Metals_V1_OLD_SCREEN, or BlueCore_Precious_Metals_V2_SCREEN.ino in a folder named BlueCore_Precious_Metals_V2_SCREEN. Keep the versions separate. Open the .ino in Arduino IDE. Select your Mega and its assigned COM port, then Verify and Upload.


V1 initialization:

myGLCD.InitLCD(LANDSCAPE);

myGLCD.clrScr();


V2 initialization includes this tested sequence:

myGLCD.InitLCD(LANDSCAPE);

digitalWrite(40, LOW);

myGLCD.LCD_Write_COM(0x21);

digitalWrite(40, HIGH);

myGLCD.clrScr();


Pin 40 is the display chip-select pin in this constructor. In the V2 sketch the command is wrapped in applyV2ColorFix(). The V1 sketch does not apply it.


These are two separate, physically tested versions. Do not overwrite the older-board sketch with the V2 initialization.

Check the First Boot

Expected startup:

1. TFT and SD initialization.

2. Check for both graphics files.

3. SPLASH.RAW appears for three seconds.

4. METALS.RAW appears.

5. WAITING FOR LIVE PRICES... is shown.


SD ERROR means card initialization failed. SPLASH MISSING or METALS MISSING identifies a missing file. Check the card, exact filenames, root directory and contacts before changing display settings.


At this stage the display has no online prices yet. It needs the Windows application.

Install BlueCore Precious Metals Live V2.1

bluecore_logo.png
Live-App.png

Download BlueCore_Precious_Metals_Live_v2_1.py and Live-requirements.txt from this step into a new Windows_Live_App folder. Also download the original bluecore_logo.png image and keep that exact filename in the same folder. Instructables may rename downloads: restore these filenames if necessary. The Python source is the unchanged working main.py, given a descriptive download name.


Install Python 3 for Windows with Tkinter and the Python launcher. Open a terminal in that folder and run:

py -m pip install -r Live-requirements.txt

py BlueCore_Precious_Metals_Live_v2_1.py


The app creates settings.json when you save settings. Select your own COM port; COM8 is only the port used in this build.


Live v2.1 requires requests and pyserial. It uses native Tkinter for the logo and gradient and does not require Pillow. The separate layout designer does require Pillow.


Close Arduino Serial Monitor and Serial Plotter before connecting from the app. Only one program can normally hold the COM port at a time. Keep the terminal open if diagnosing startup errors.


For a launch without a console, use pyw BlueCore_Precious_Metals_Live_v2_1.py after confirming the normal command works. The original batch launchers are not attached because the site did not accept them; the commands above run the same unchanged application directly. The optional settings.json.txt attachment can be renamed to settings.json. Select your own COM port.

Select the Port and Test the USB Link

Select the port assigned to your Mega. COM8 is my development setting, not a universal port number. Use Refresh Ports if necessary. Set the baud rate to 115200 and leave the initial refresh interval at 60 seconds. Save Settings.


Send Test Packet sends demonstration values without contacting the price APIs. For example, Gold is 3720.50 EUR/OZ and 119.62 EUR/GRAM. These are test values, not current market quotes.


Seeing the test numbers verifies the path through USB, parsing and display drawing. If the port has just opened, the Mega may reset and show its splash again. If the first test packet is missed during startup, start live updates and allow the next refresh to arrive.


Do not repeatedly change TFT drivers when the screen already displays correctly but is waiting for serial data.

Start Live Prices and Understand the Values

Press START LIVE PRICES. The app fetches a USD-to-EUR rate and the four metal prices, sends a packet to the Mega and waits the configured interval before the next cycle. Network time adds to the cycle, so it is not an exact once-per-minute clock.


The application requests prices from api.gold-api.com/price/XAU, XAG, XPT and XPD, and the exchange rate from https://api.frankfurter.dev/v2/rate/usd/eur.


Its conversion is:

EUR per Troy ounce = USD per Troy ounce × USD-to-EUR rate

EUR per gram = EUR per Troy ounce ÷ 31.1034768


The last-update time sent to the TFT is the Windows PC’s local HH:MM. It records the application’s update, not the provider’s market timestamp. External prices and exchange rates can have different update schedules; refreshing the app does not guarantee a new quote each time.


If a request or serial operation fails, the app logs the error and retries. The TFT retains its last displayed values, so check the timestamp and the PC status rather than assuming old numbers are fresh.


These are reference market values, not a jewellery appraisal or a shop’s buying/selling price. Purity, premiums, taxes and dealer margins are not included. API formats and availability may change.


Provider documentation: https://gold-api.com/docs and https://frankfurter.dev/

How the Serial Packet and Screen Refresh Work

The PC sends an ASCII line beginning PM, followed by eight prices and an HH:MM timestamp:


PM,GOLD_OZ,GOLD_G,SILVER_OZ,SILVER_G,PLATINUM_OZ,PLATINUM_G,PALLADIUM_OZ,PALLADIUM_G,HH:MM


Each packet ends with a newline. The sketch ignores carriage returns and splits the comma-separated fields with strtok(). Keep the format unchanged if you write your own sender.


On each complete expected packet, drawDashboard() reloads METALS.RAW and draws all current values. Reloading clears old digits when a new number is shorter. It is intentionally a full background refresh, not a claim of partial or flicker-free drawing.


Prices use BigFont, white transparent text and two decimal places. The update line uses SmallFont.

Keep the Tested Layout or Make Your Own

The supplied Arduino sketches retain the coordinates calibrated for the original METALS.RAW:


Gold: OZ (110,87), gram (126,123)

Silver: OZ (360,87), gram (377,123)

Platinum: OZ (110,190), gram (142,226)

Palladium: OZ (348,190), gram (380,226)

Last update: CENTER,294


Increasing X moves a field right; increasing Y moves it down. First get the original artwork and sketch working together before changing these settings.


The accompanying designer screenshot is an alternative layout with different artwork and coordinates. Do not copy its positions into the supplied sketch while keeping the original METALS.RAW.

Optional: BlueCore TFT Layout Designer V2.0

Designer-Example.png
Background1.png
Background2.png
Background3.png

Download BlueCore_TFT_Layout_Designer_v2_0.py and Designer-requirements.txt into a separate folder. Copy bluecore_logo.png from Step 7 into this folder too, preserving its filename. Open a terminal in this folder and run:

py -m pip install -r Designer-requirements.txt

py BlueCore_TFT_Layout_Designer_v2_0.py


The separate designer is useful for other TFT dashboards too. Load your background; the canvas is 480 × 320. This application uses Pillow.


Add named text fields, enter preview values, choose SmallFont or BigFont, then drag or fine-adjust X/Y. Save the project as JSON so you can reopen it. Export Arduino Defines produces X/Y definitions and comments describing font, colour and alignment. Export Background RAW RGB565 exports only the background artwork, not the preview text.


Important: the export is not a complete Arduino sketch. Match the exported names to your drawing code and apply the intended font, colour and alignment there. In this designer LEFT places text left of the anchor, RIGHT places it right, and CENTER centres it on the anchor. Numeric UTFT print positions do not automatically apply that designer alignment.


A 480x320 RAW export should be 307,200 bytes. Use it with the byte order expected by your display code; the supplied workflow uses RAW_SWAP 0.


The included example backgrounds and projects are customization examples. They do not replace the tested main dashboard unless you also adjust its drawing code.


Optional examples are attached individually. Rename BlueCore_TFT_Layout.json.txt to BlueCore_TFT_Layout.json before using Load Project. Its original background path is specific to my PC: after loading the project, use Load 480x320 Background to select your downloaded Background1.png, then save the project again. BACKGROUNDRAW1.RAW and the defines header are examples for this alternative layout, not replacements for the main dashboard files.

Read the complete BlueCore TFT Layout Designer tutorial and download the software here.

Troubleshooting and Finished Project

Negative or washed-out V2 colours: confirm you are using the V2 sketch containing the tested 0x21 command. Keep RAW_SWAP 0. The older board uses the V1 sketch without that command.


Colours became worse after byte swapping: restore RAW_SWAP 0 and check the screen version and original graphics.


SD ERROR: check FAT32, card contacts, the TFT slot and SD CS 53.


Missing splash/dashboard: check filenames and file location; both RAW files should be 307,200 bytes.


WAITING FOR LIVE PRICES: check the PC app, port and baud rate. Allow startup and the next update to finish.


COM port busy: close Serial Monitor, Serial Plotter and other serial tools.


Test packet works but live data does not: check the activity log, internet connection and the external services.


Python GUI does not open: install that application’s requirements and run py followed by the downloaded application’s .py filename in a terminal to see the error. Live v2.1 and Designer v2.0 have different dependencies.


Text overlaps: use the original artwork with its original coordinates, or adjust both together.


The key result is the two-board comparison: similar-looking shields needed different LCD initialization, and we verified the fix on the hardware. That does not establish support for untested controller variants.


Enjoy building your own dashboard! — Danny van den Brande, BlueCore Tech.