The TFT screen I am using is the Elegoo UNO R3 2.8 Inches TFT Touch Screen. I can attached its user manual to a post. I believe its voltage is the 5V. As far as the library it came with the adafruit_gfx.h and the adafruit_tftlcd.h.
I didn't have documentation with the rfid, it was the MFRC-522 RC522 RFID Radiofrequency IC Card Inducing Sensor Reader for Arduino.
I found the MFRC522.h library for the rfid card.
I have code to try and do what I'd like to see done. Pretty much I would like the project to scan rfid tags I have strategically hidden around a room and on the lcd screen state that it was found or not. The "clock" program is just a visual timer, and should always be counting down from 60 minutes.
#include <Adafruit_GFX.h> // Core graphics library
#include <Adafruit_TFTLCD.h> // Hardware-specific library
#include <SPI.h>
#include <MFRC522.h>
#define RST_PIN 9 // Configurable, see typical pin layout above
#define SS_PIN 10 // Configurable, see typical pin layout above
MFRC522 mfrc522(SS_PIN, RST_PIN); // Create MFRC522 instance
#define LCD_CS A3 // Chip Select goes to Analog 3 A3
#define LCD_CD A2 // Command/Data goes to Analog 2 A2
#define LCD_WR A1 // LCD Write goes to Analog 1 A1
#define LCD_RD A0 // LCD Read goes to Analog 0 A0
#define LCD_RESET A4 // Can alternately just connect to Arduino's reset pin A4
#define BLACK 0x0000
#define RED 0xF800
#define YELLOW 0xFFE0
#define WHITE 0xFFFF
#define SAND 0xFFFB //this is one I created to try to get sand color
Adafruit_TFTLCD tft(LCD_CS, LCD_CD, LCD_WR, LCD_RD, LCD_RESET);
//These set up the parameters for the clock program
float sx = 0, sy = 1, mx = 1, my = 0, hx = -1, hy = 0; // Saved H, M, S x & y multipliers
float sdeg=0, mdeg=0, hdeg=0;
uint16_t osx=120, osy=120, omx=120, omy=120, ohx=120, ohy=120; // Saved H, M, S x & y coords
uint16_t x0=0, x1=0, y0=0, y1=0;
uint32_t targetTime = 0; // for next 1 second timeout
uint8_t hh=0, mm=0, ss=0; // Get H, M, S from compile time, set the start times for the countdown
boolean initial = 1;
void setup() {
Serial.begin(9600);
SPI.begin();
mfrc522.PCD_Init();
Serial.println(F("Read personal data on a MIFARE PICC:"));
uint16_t identifier = tft.readID();
identifier=0x9341;
tft.begin(identifier);
//Create a background fill
tft.fillScreen(BLACK);
// Draw clock face
tft.fillCircle(120, 120, 118, SAND);
tft.fillCircle(120, 120, 110, BLACK);
// Draw 12 lines
for(int i = 0; i<360; i+= 30) {
sx = cos((i-90)*0.0174532925);
sy = sin((i-90)*0.0174532925);
x0 = sx*114+120;
y0 = sy*114+120;
x1 = sx*100+120;
y1 = sy*100+120;
tft.drawLine(x0, y0, x1, y1, SAND);
}
// Draw 60 dots
for(int i = 0; i<360; i+= 6) {
sx = cos((i-90)*0.0174532925);
sy = sin((i-90)*0.0174532925);
x0 = sx*102+120;
y0 = sy*102+120;
// Draw minute markers
tft.drawPixel(x0, y0, WHITE);
// Draw main quadrant dots
if(i==0 || i==180) tft.fillCircle(x0, y0, 2, YELLOW);
if(i==90 || i==270) tft.fillCircle(x0, y0, 2, YELLOW);
//Draw start marker
tft.fillTriangle(114,0,124,0,119,25,RED);
}
tft.fillCircle(120, 121, 3, WHITE);
}
void loop() {
// this first loop will keep the clock counting down from 60 and move accordingly
if (targetTime < millis()) {
targetTime = millis()+1000;
ss++; // Advance second
if (ss==60) {
ss=0;
mm++; // Advance minute
if(mm>59) {
mm=0;
hh++; // Advance hour
if (hh>23) {
hh=0;
}
}
}
// Pre-compute hand degrees, x & y coords for a fast screen update
sdeg = ss*6; // 0-59 -> 0-354
mdeg = mm*6+sdeg*0.01666667; // 0-59 -> 0-360 - includes seconds
hdeg = hh*30+mdeg*0.0833333; // 0-11 -> 0-360 - includes minutes and seconds
hx = cos((hdeg-90)*0.0174532925);
hy = sin((hdeg-90)*0.0174532925);
mx = cos((mdeg-90)*0.0174532925);
my = sin((mdeg-90)*0.0174532925);
sx = cos((sdeg-90)*0.0174532925);
sy = sin((sdeg-90)*0.0174532925);
if (ss==0 || initial) {
initial = 0;
// Erase hour and minute hand positions every minute
tft.drawLine(omx, omy, 120, 121, BLACK);
omx = mx*84+120;
omy = my*84+121;
}
// Redraw new hand positions, hour and minute hands not erased here to avoid flicker
osx = sx*90+121;
osy = sy*90+121;
tft.drawLine(omx, omy, 120, 121, WHITE);
}
//This Loop Writes a string text to the arduino tft screen using the serial monitor
Serial.begin(9600);
String serialcommand;
serialcommand = Serial.readString();
tft.setCursor(0,250);
tft.setTextSize(3); //this size will only fill 13 characters across the screen
tft.setTextColor(SAND);
tft.print(serialcommand);
Serial.print(serialcommand);
//This is the "eraser", the character used to clear the tft screen using the serial monitor, one must enter this in to start a new text, without it overlapping itself.
if(serialcommand == "~") {
Serial.println(serialcommand);
tft.fillRect(0,250,300,100,BLACK);
}
MFRC522::MIFARE_Key key;
for (byte i = 0; i < 6; i++) key.keyByte[i] = 0xFF;
//some variables we need
byte block;
byte len;
MFRC522::StatusCode status;
//-------------------------------------------
// Look for new cards
if ( ! mfrc522.PICC_IsNewCardPresent()) {
return;
}
// Select one of the cards
if ( ! mfrc522.PICC_ReadCardSerial()) {
return;
}
Serial.println(F("**Card Detected:**"));
//-------------------------------------------
mfrc522.PICC_DumpDetailsToSerial(&(mfrc522.uid)); //dump some details about the card
//mfrc522.PICC_DumpToSerial(&(mfrc522.uid)); //uncomment this to see all blocks in hex
//-------------------------------------------
Serial.print(F("Name: "));
byte buffer1[18];
block = 4;
len = 18;
//------------------------------------------- GET FIRST NAME
status = mfrc522.PCD_Authenticate(MFRC522::PICC_CMD_MF_AUTH_KEY_A, 4, &key, &(mfrc522.uid)); //line 834 of MFRC522.cpp file
if (status != MFRC522::STATUS_OK) {
Serial.print(F("Authentication failed: "));
Serial.println(mfrc522.GetStatusCodeName(status));
return;
}
status = mfrc522.MIFARE_Read(block, buffer1, &len);
if (status != MFRC522::STATUS_OK) {
Serial.print(F("Reading failed: "));
Serial.println(mfrc522.GetStatusCodeName(status));
return;
}
//PRINT FIRST NAME
for (uint8_t i = 0; i < 16; i++)
{
if (buffer1[i] != 32)
{
Serial.write(buffer1[i]);
}
}
Serial.print(" ");
//---------------------------------------- GET LAST NAME
byte buffer2[18];
block = 1;
status = mfrc522.PCD_Authenticate(MFRC522::PICC_CMD_MF_AUTH_KEY_A, 1, &key, &(mfrc522.uid)); //line 834
if (status != MFRC522::STATUS_OK) {
Serial.print(F("Authentication failed: "));
Serial.println(mfrc522.GetStatusCodeName(status));
return;
}
status = mfrc522.MIFARE_Read(block, buffer2, &len);
if (status != MFRC522::STATUS_OK) {
Serial.print(F("Reading failed: "));
Serial.println(mfrc522.GetStatusCodeName(status));
return;
}
//PRINT LAST NAME
for (uint8_t i = 0; i < 16; i++) {
Serial.write(buffer2[i] );
}
//----------------------------------------
Serial.println(F("\n**End Reading**\n"));
delay(1000); //change value if you want to read cards faster
mfrc522.PICC_HaltA();
mfrc522.PCD_StopCrypto1();
}
2.8inch-TFT-UserManual.pdf (313 KB)