Hi,
I bought a TFT screen and I want to create a program that will continuously send data to it. Here's the prototype for now:
#include "Adafruit_GFX.h"
#include "MCUFRIEND_kbv.h"
#include "bitmap_RGB.h"
#include "SPI.h"
#include "SD.h"
// Inicjalizacja obiektu TFT
MCUFRIEND_kbv tft(A3, A2, A1, A0, A4);
#define BLACK 0x0000
#define NAVY 0x000F
#define DARKGREEN 0x03E0
#define DARKCYAN 0x03EF
#define MAROON 0x7800
#define PURPLE 0x780F
#define OLIVE 0x7BE0
#define LIGHTGREY 0xC618
#define DARKGREY 0x7BEF
#define BLUE 0x001F
#define GREEN 0x07E0
#define CYAN 0x07FF
#define RED 0xF800
#define MAGENTA 0xF81F
#define YELLOW 0xFFE0
#define WHITE 0xFFFF
#define ORANGE 0xFD20
#define GREENYELLOW 0xAFE5
#define PINK 0xF81F
void setup() {
Serial.begin(9600);
uint16_t ID = tft.readID();
tft.begin(ID);
tft.fillScreen(YELLOW);
}
int a = 0;
void loop() {
if (Serial.available() > 0) {
// Odczytaj dane przychodzące
String incomingData = Serial.readStringUntil('\n');
tft.fillScreen(YELLOW);
tft.setCursor(100, 0);
tft.setTextColor(PINK);
tft.setTextSize(1);
tft.print(incomingData);
}
}
If I'm using the serial port built into the Arduino IDE, everything works fine, and I can see my text on the screen. However, I want the data sending process to be more automated, so I want to use Python. Here's the code:
import serial
import time
ser = serial.Serial('COM3', 9600)
try:
while True:
ser.write(b'h\n')
time.sleep(0.1)
response = ser.readline().decode('utf-8').strip()
print("Odpowiedź z Arduino:", response)
except KeyboardInterrupt:
ser.close()
The program starts simultaneously when Arduino is using the other one. Unfortunately, nothing happens. The text doesn't display on Arduino, and Python doesn't receive any feedback either. Why is this happening? Do you have any ideas on what to do about it?