Serial data to zero with tft


I have been trying for a few days to try and figure out how to display the serial data being transmitted from a st32 micro and display it on a tft attached to a arduino zero.

At to moment the st32 uart is attached to a cp2102 uart to usb bridge which allows me to see the serial data using putty on the computer.

I would like to get away from having to use the computer all the time and have a stand alone system.

The st32 uart has a speed of 38400.

I can get the tft working using the mcufriend library.

I have found a few examples of peoples code for displaying serial data on a tft but i can’t get any of them to work.

Could anybody please help me figure out the code as this is the first time I’ve used a tft and am lost on how to write the code

Thank you for any help

Which TFT display have you got exactly ?
Link to it ?

Which library are you intending to use ?
Link to it ?
Has the library got any examples ?

Do you want to display coloured graphics or just monochrome text?

What STM32 board are you using?
You could connect the display directly to the STM32 board in the first place.


The link to the tft is

The tft library’s that work with the display are

The st32 micro is part of a test box i have and don’t have access to the code.

I don’t expect you to have the code for the STM32. But you can probably read the STM32 part number. And post a photo of the pcb.

You have not answered about graphics, colours, …

If it is a Black Box that sends UART text, you will just read the text on the Zero. Then write the text to the TFT. Not difficult.


This is the board with the st32.

The display will just be monochrome. Black background with white writing.

Ah-ha. You can’t stick a shield on that pcb !

The TFT Shield uses most of the pins on the Zero.
You should be able to connect digital#0, digital#1 to your external UART as Serial1. The Zero uses SERCOM5 for Serial over the EDBG USB cable.


This is the board i have. It doesn’t have the debug port.

Well, don’t call it a genuine “Arduino Zero”. It has “M0” pinout with probably a “Zero” bootloader.

It is still going to have Serial comms on SerialUSB i.e. “Native USB”
What appears in Tools->Port dropdown menu ?

It is still going to have UART comms on digital #0, #1


Ok so i used graphictest_kbv.ino to get the display to work on the zero impostor. But i don’t understand what is going on.

Which parts would i need to keep and/or change for what i require.

How would i read serial1 and write it to the display

The “testText()” function starting on line 349 shows you how to display text on your display. You use tft.print() and tft.println() just like you would use Serial.print() and Serial.println() to send text to Serial Monitor.

After ‘tft’ and ‘Serial1’ are set up it may be as simple as:

void loop()
  if (Serial1.available())

Is setting up serial1 the same as setting up serial on a uno

Probably, but I don’t have an Arduino Zero to test on. Give it a try.

I used parts of the graphictest_kbv and the code suggested to read the the serial and print in to the tft.

The code works and displays the txt as i see it on the serial console on the computer but how do I get it to scroll the text up when it gets to the bottom of the screen

#define LCD_CS A3 // Chip Select goes to Analog 3
#define LCD_CD A2 // Command/Data goes to Analog 2
#define LCD_WR A1 // LCD Write goes to Analog 1
#define LCD_RD A0 // LCD Read goes to Analog 0
#define LCD_RESET A4 // Can alternately just connect to Arduino's reset pin

#include <SPI.h>          // f.k. for Arduino-1.5.2
#include "Adafruit_GFX.h"// Hardware-specific library
#include <MCUFRIEND_kbv.h>
MCUFRIEND_kbv tft;
//#include <Adafruit_TFTLCD.h>

// Assign human-readable names to some common 16-bit color values:
#define  BLACK   0x0000
#define BLUE    0x001F
#define RED     0xF800
#define GREEN   0x07E0
#define CYAN    0x07FF
#define MAGENTA 0xF81F
#define YELLOW  0xFFE0
#define WHITE   0xFFFF

void setup(void) {
  uint16_t ID = tft.readID(); //
  if (ID == 0xD3D3) ID = 0x9481; // write-only shield

void loop() {
  // send data only when you receive data:
  if (Serial1.available())


You keep track of the cursor position i.e. when you get to the bootom:
Either clear the screen and “start a new page”
Or “hardware scroll” the screen. delete the bottom line. write on the bottom line. Keep track of logical cursor position relative to “scrolled” screen memory.

The “hardware scroll” arrangement requires careful design. Possibly beyond your skill level.


Most of this is beyond my skill level.

When the text is on the screen it gets to the bottom then doesn’t show the rest of the text.

I wouldn’t know how to implement any of the suggestions you have mentioned David.

Start simple, even if it not quite what you want, it will give you a start

Every time that you print a character increment a counter. When the counter reaches say 100 then clear the screen and reset the counter to zero

I think that the scroll_kbv.ino example might show some hints.

Your controller is capable of vertical scrolling a Band.

If you want help, write a version that captures to the Serial Terminal. Copy-Paste the sample text from the Terminal.

Post this sample text. Then I can show you how to do it on your TFT.


This is what is displayed on the serial terminal.

Speed signal is currently stopped.
Select an operating mode by pressing a numeric key 1 - 4
Mode 1 and 3 = 133Hz @60mph, Mode 2 & 4 = 800Hz @75mph
Enter menu option:-

Speed is 35 mph. Change = +/- = stop = auto mode

Automatic closed loop testing has started
There are no user adjustment options in this version.
The speed error is adjusted automatically.

To stop the test hit

State=0 Cruise=35mph Speed=35mph Pot=1944 Delta=0

That looks like about 14 lines of text.
You can get 60 lines of 53 letter text on a 320x480 screen.

Or in size2 Landscape it would be 20 lines of 40 letters.

I suspect that you would be better off with a clear screen and fresh start. Very simple. You can use nice fonts, bold emphasis, …

e.g. interpret a few embedded command like “clear screen” or “change font”