STM32F103C, ST7735 TFT, SDcard reader HELP PLS

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

Go on. Arduino_ST7735_STM was originally written for the weird Roger Clark "Maple" core.

Nowadays you would use the official STM32 Core that was written by and is maintained by STMicroelectronics i.e. the company that makes STM32.

I would expect Arduino_ST7735_STM to "work" but since the Adafruit_ST7735 library from Adafruit works on STM32 it seems wise to use an officially supported library that is maintained by Adafruit.

My advice is:
STM32 Core
Adafruit_ST7735 library

Both of which can be installed via the Arduino IDE.

Yes, Pawel's library will have a better performance due to DMA. It would be nice if the official STM32 Core SPI library supported DMA.
Note that Bodmer's TFT_eSPI library runs on proper STM32 Core and uses DMA.

David.

With those installed and trying to upload "graphicstest" from GFX i get this error

Arduino: 1.8.13 (Windows 10), Board: "Generic STM32F103C series, STM32F103C8 (20k RAM. 64k Flash), Serial, 72Mhz (Normal), Smallest (default)"
C: \Users\guido\AppData\Local\Temp\arduino_modified_sketch_390395\graphicstest.ino: In function 'void setup()':
C: \Users\guido\AppData\Local\Temp\arduino_modified_sketch_390395\graphicstest.ino: 123: 397: warning: deprecated conversion from string constant to 'char*' [-Wwrite - strings]
testdrawtext("Lorem ipsum dolor sit amet, consectetur adipiscing elit. Curabitur adipiscing ante sed nibh tincidunt feugiat. Maecenas enim massa, fringilla sed malesuada et, malesuada sit amet turpis. Sed porttitor neque ut ante pretium vitae malesuada nunc bibendum. Nullam aliquet ultrices massa eu hendrerit. Ut sed nisi lorem. In vestibulum purus a tortor imperdiet posuere. ", ST77XX_WHITE);
C: \Users\guido\OneDrive\Arduino Save Location\libraries\Adafruit_BusIO\Adafruit_I2CDevice.cpp: In member function 'bool Adafruit_I2CDevice::write(const uint8_t*, size_t, bool, const uint8_t*, size_t)':
C: \Users\guido\OneDrive\Arduino Save Location\libraries\Adafruit_BusIO\Adafruit_I2CDevice.cpp: 88: 47: error: invalid conversion from 'const uint8_t* {aka const unsigned char*}' to 'uint8* {aka unsigned char*}' [-fpermissive]
if (_wire->write(prefix_buffer, prefix_len) != prefix_len) {
In file included from C: \Users\guido\AppData\Local\Arduino15\packages\stm32duino\hardware\STM32F1\2021.3.18\libraries\Wire / Wire.h: 42: 0,
from C: \Users\guido\OneDrive\Arduino Save Location\libraries\Adafruit_BusIO / Adafruit_I2CDevice.h: 1,
from C: \Users\guido\OneDrive\Arduino Save Location\libraries\Adafruit_BusIO\Adafruit_I2CDevice.cpp: 1:
C: \Users\guido\AppData\Local\Arduino15\packages\stm32duino\hardware\STM32F1\2021.3.18\libraries\Wire / utility / WireBase.h: 123: 12: error:   initializing argument 1 of 'size_t WireBase::write(uint8*, int)' [-fpermissive]
  size_t write(uint8*, int);
C: \Users\guido\OneDrive\Arduino Save Location\libraries\Adafruit_BusIO\Adafruit_I2CDevice.cpp: 97: 31: error: invalid conversion from 'const uint8_t* {aka const unsigned char*}' to 'uint8* {aka unsigned char*}' [-fpermissive]
  if (_wire->write(buffer, len) != len) {
In file included from C: \Users\guido\AppData\Local\Arduino15\packages\stm32duino\hardware\STM32F1\2021.3.18\libraries\Wire / Wire.h: 42: 0,
from C: \Users\guido\OneDrive\Arduino Save Location\libraries\Adafruit_BusIO / Adafruit_I2CDevice.h: 1,
from C: \Users\guido\OneDrive\Arduino Save Location\libraries\Adafruit_BusIO\Adafruit_I2CDevice.cpp: 1:
C: \Users\guido\AppData\Local\Arduino15\packages\stm32duino\hardware\STM32F1\2021.3.18\libraries\Wire / utility / WireBase.h: 123: 12: error:   initializing argument 1 of 'size_t WireBase::write(uint8*, int)' [-fpermissive]
    size_t write(uint8*, int);
    Meerdere bibliotheken gevonden voor "Wire.h"
Gebruikt: C: \Users\guido\AppData\Local\Arduino15\packages\stm32duino\hardware\STM32F1\2021.3.18\libraries\Wire
Niet gebruikt: C: \Users\guido\AppData\Local\Arduino15\packages\stm32duino\hardware\STM32F1\2021.3.18\libraries\WireSlave
    exit status 1
    Fout bij het compileren voor board Generic STM32F103C series
    Dit rapport zou meer informatie bevatten met
    "Uitgebreide uitvoer weergeven tijden compilatie"
    optie aan in Bestand -> Voorkeuren.

This is the code

/**************************************************************************
  This is a library for several Adafruit displays based on ST77* drivers.

  Works with the Adafruit 1.8" TFT Breakout w/SD card
    ----> http://www.adafruit.com/products/358
  The 1.8" TFT shield
    ----> https://www.adafruit.com/product/802
  The 1.44" TFT breakout
    ----> https://www.adafruit.com/product/2088
  The 1.14" TFT breakout
  ----> https://www.adafruit.com/product/4383
  The 1.3" TFT breakout
  ----> https://www.adafruit.com/product/4313
  The 1.54" TFT breakout
    ----> https://www.adafruit.com/product/3787
  The 2.0" TFT breakout
    ----> https://www.adafruit.com/product/4311
  as well as Adafruit raw 1.8" TFT display
    ----> http://www.adafruit.com/products/618

  Check out the links above for our tutorials and wiring diagrams.
  These displays use SPI to communicate, 4 or 5 pins are required to
  interface (RST is optional).

  Adafruit invests time and resources providing this open source code,
  please support Adafruit and open-source hardware by purchasing
  products from Adafruit!

  Written by Limor Fried/Ladyada for Adafruit Industries.
  MIT license, all text above must be included in any redistribution
 **************************************************************************/

#include <Adafruit_GFX.h>    // Core graphics library
#include <Adafruit_ST7735.h> // Hardware-specific library for ST7735
#include <Adafruit_ST7789.h> // Hardware-specific library for ST7789
#include <SPI.h>

#if defined(ARDUINO_FEATHER_ESP32) // Feather Huzzah32
#define TFT_CS         14
#define TFT_RST        15
#define TFT_DC         32

#elif defined(ESP8266)
#define TFT_CS         4
#define TFT_RST        16
#define TFT_DC         5

#else
// For the breakout board, you can use any 2 or 3 pins.
// These pins will also work for the 1.8" TFT shield.
#define TFT_CS        PA2
#define TFT_RST        PA0 // Or set to -1 and connect to Arduino RESET pin
#define TFT_DC         PA1
#endif

// OPTION 1 (recommended) is to use the HARDWARE SPI pins, which are unique
// to each board and not reassignable. For Arduino Uno: MOSI = pin 11 and
// SCLK = pin 13. This is the fastest mode of operation and is required if
// using the breakout board's microSD card.

// For 1.44" and 1.8" TFT with ST7735 use:
Adafruit_ST7735 tft = Adafruit_ST7735(TFT_CS, TFT_DC, TFT_RST);

// For 1.14", 1.3", 1.54", and 2.0" TFT with ST7789:
//Adafruit_ST7789 tft = Adafruit_ST7789(TFT_CS, TFT_DC, TFT_RST);


// OPTION 2 lets you interface the display using ANY TWO or THREE PINS,
// tradeoff being that performance is not as fast as hardware SPI above.
//#define TFT_MOSI 11  // Data out
//#define TFT_SCLK 13  // Clock out

// For ST7735-based displays, we will use this call
//Adafruit_ST7735 tft = Adafruit_ST7735(TFT_CS, TFT_DC, TFT_MOSI, TFT_SCLK, TFT_RST);

// OR for the ST7789-based displays, we will use this call
//Adafruit_ST7789 tft = Adafruit_ST7789(TFT_CS, TFT_DC, TFT_MOSI, TFT_SCLK, TFT_RST);


float p = 3.1415926;

void setup(void) {
  Serial.begin(9600);
  Serial.print(F("Hello! ST77xx TFT Test"));

  // Use this initializer if using a 1.8" TFT screen:
  tft.initR(INITR_BLACKTAB);      // Init ST7735S chip, black tab

  // OR use this initializer if using a 1.8" TFT screen with offset such as WaveShare:
  //tft.initR(INITR_GREENTAB);      // Init ST7735S chip, green tab

  // OR use this initializer (uncomment) if using a 1.44" TFT:
  //tft.initR(INITR_144GREENTAB); // Init ST7735R chip, green tab

Bla bla bla didnt edit the rest of the code, its too long to upload

I've added my libraries as attachment

Seriously. If you want to use the weird "Maple" Core you should ask the "Maple Core" people.

I am happy to help with regular libraries and official "STM32 Core".

I can assure you that you can read/write SD files, BMP images, JPG images, PNG images, GIF animations, ...
both with Adafruit_ST7735 and TFT_eSPI libraries.

Yes, they will probably work with "Maple Core" but it is a mug's game expecting any reliability from a dog's breakfast.

Likewise, ILI9341 displays work fine with Adafruit_ILI9341 and TFT_eSPI libraries on STM32 Core.
Likewise, ST7796S and ILI9488 displays work fine with TFT_eSPI library on STM32 Core.

David.

I am sorry if i confused you, i dont care about wich library i use, i just need it to do what i want it to do. I dont know what Maple core and such means, i just downloaded the stuff that i thought you said. Could you pls give me some details on the libraries you think are usefull.

I just installed the STM32 Core, at first i thought you ment a library, but now i see that its a repo for the board!

Dangggg this is so much easier xD

The official STM32 Core works fine with a BluePill.
But it is a little fiddly to configure all the options in the IDE. But you only set it up once.

Ask if you want help.

I agree that the "Maple / stm32duino" versus official "STM32" is confusing.

Historically, Roger Clark created an Arduino Core that worked with only STM32F103.
The upkeep and maintenance got a bit too much for Roger. He no longer works on it.

A few years ago ST created the official Core. It works with many, many different STM32 chips.
It supports Arduino "better". And is maintained by ST employees.

It would have been wise if ST had got "stm32duino" name changed to "obsolete32duino"
Then there would be less confusion.

David.

david_prentice:
The official STM32 Core works fine with a BluePill.
But it is a little fiddly to configure all the options in the IDE. But you only set it up once.

Ask if you want help.

I agree that the "Maple / stm32duino" versus official "STM32" is confusing.

Historically, Roger Clark created an Arduino Core that worked with only STM32F103.
The upkeep and maintenance got a bit too much for Roger. He no longer works on it.

A few years ago ST created the official Core. It works with many, many different STM32 chips.
It supports Arduino "better". And is maintained by ST employees.

It would have been wise if ST had got "stm32duino" name changed to "obsolete32duino"
Then there would be less confusion.

David.

Thank you mate, Ill yell if i have another question :smiley:

This topic was automatically closed after 91 days. New replies are no longer allowed.