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
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.
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())
tft.print((char)Serial1.read());
}
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>
//Adafruit_TFTLCD tft(LCD_CS, LCD_CD, LCD_WR, LCD_RD, LCD_RESET);
// 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) {
Serial1.begin(38400);
uint16_t ID = tft.readID(); //
if (ID == 0xD3D3) ID = 0x9481; // write-only shield
tft.begin(ID);
tft.setRotation(1);
tft.setTextSize(2);
}
void loop() {
// send data only when you receive data:
if (Serial1.available())
tft.print((char)Serial1.read());
}
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.
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.