Hello, I am trying to display text from i " .txt " file to a ST7735 driven 128x160 TFT "Full Color" display(link will be below).
I am able to get 2 sketches to work separately, but when i try to combine the display and the SD card together in one code, the display stops working once i use the SD card and the other way around.
The code that worked for the SD card reader:
#include <SPI.h>
#include <SD.h>
File myFile;
void setup() {
Serial.begin(9600);
Serial.println("Initializing SD card...");
if (!SD.begin(4)) {
Serial.println("initialization Failed.\n");
while (true);
}
Serial.println("initialization done.\n");
myFile = SD.open("test.txt", FILE_WRITE);
if (myFile) {
Serial.print("Writing to test.txt...");
myFile.println("testing 1, 2, 3.");
myFile.close();
Serial.println("done.\n");
} else Serial.println("error opening test.txt");
myFile = SD.open("test.txt");
if (myFile) {
Serial.println("test.txt:");
while (myFile.available()) {
Serial.write(myFile.read());
}
myFile.close();
} else Serial.println("error opening test.txt");
}
void loop() {}
The code that worked for the display:
#include <SPI.h>
#include <Adafruit_GFX.h>
#include <Arduino_ST7735_STM.h>
#define TFT_CS PA2
#define TFT_DC PA1
#define TFT_RST PA0
#define SCR_WD 128
#define SCR_HT 160
Arduino_ST7735 lcd = Arduino_ST7735(TFT_DC, TFT_RST, TFT_CS);
void setup() {
lcd.init();
lcd.setRotation(1);
lcd.fillScreen(BLACK);
lcd.setCursor(10, 20);
lcd.print("Starting");
delay(1000);
}
void loop() {
lcd.fillScreen(BLACK);
delay(500);
lcd.fillScreen(RED);
delay(500);
}
And then the code that did not work:
#include <SPI.h>
#include <Adafruit_GFX.h>
#include <Arduino_ST7735_STM.h>
#include <SD.h>
#define TFT_CS PA2
#define TFT_DC PA1
#define TFT_RST PA0
#define SCR_WD 128
#define SCR_HT 160
Arduino_ST7735 lcd = Arduino_ST7735(TFT_DC, TFT_RST, TFT_CS);
File myFile;
int SB = PB9;
int PB = PB8;
void setup() {
pinMode(SB, INPUT);
pinMode(PB, INPUT);
Serial.begin(9600);
if (!SD.begin(4)) while (true);
lcd.init();
lcd.setRotation(1);
lcd.fillScreen(BLACK);
lcd.setCursor(0, 3);
delay(500);
lcd.print("initialization done.");
delay(100);
while (digitalRead(PB)) delay(10);
}
void loop() {
lcd.fillScreen(BLACK);
lcd.setCursor(0, 3);
lcd.print("opening file");
myFile = SD.open("test.txt", FILE_READ);
lcd.fillScreen(BLACK);
lcd.setCursor(0, 3);
lcd.print("!!!BEGIN OF FILE!!!");
if (myFile) {
while (myFile.available()) {
lcd.write(myFile.read());
}
myFile.close();
lcd.println("");
lcd.println("!!!END OF FILE!!!");
} else lcd.println("error opening file");
while (1);
}
It stops as soon as it try's to open a file in the third line of the loop.
The pinout that i use:
SD card - STM32
GND - GND
VCC - 5V
MISO - PA6
MOSI - PA7
SCK - PA5
CS - PA4
Display - STM32
GND - GND
VCC - 5V
SCL - PA5
SDA - PA7
RES - PA0
DS - PA1
CS - PA2
BL - 5V
The buttons are on: PB8 and PB9 to GND
TTL uploader is connected to PA9 and PA10
I am using:
-Arduino IDE 1.8.13
-STM32F103C "Bluepill"
-ST7735 driver 128x160 TFT color dislpay
-Micro SD card reader
-2 4pin buttons
-TFDI to TTL uploader
Libraries: (installed at least, might not be used)
-Adafruit_GFX_Library 1.7.5, Adafruit
-Adafruit_ILI9341 1.5.6, Adafruit
-Adafruit_STMPE610 1.1.3, Adafruit
-Adafruit_TouchScreen 1.1.1, Adafruit
-Arduino_ST7735_STM-master 1.0.1, Pawel A. Hernik
Links:
-Bluepill Ebay.com
-ST7735 128x160 TFT
-SD card reader
-FTDI USB to TTL
-Buttons
