From @Lalieu on September 23, 2014 12:49
Hi all,
I have been trying to print a .bmp image on the arduino 1.77" TFT screen using the Arduino Yún, but I have some trouble opening the file using the FileIO library of the Yún. Although I can find the .bmp file on the SD card installed on the Yún, and can open it using: FileSystem.open(filename), it is not loaded as an image file properly when using: PImage logo = tft.loadImage(filename), causing logo.isValid() to return false.
Here is how far I got:
System:
- Arduino Yún
- Arduino 1.77" TFT LCD Screen
- Micro SD card installed to the Yún (using YunDiskSpaceExpander.iso).
- Image: arduino.bmp stored on the SD card (/mnt/sd/arduino.bmp).
With the system I was able to:
- Create .txt file on the SD card, read it, and print the text in the file on the TFT screen.
- Store arduino.bmp file on the SD card and find it in the sketch using
Code:
FileSystem.open("/mnt/sd/arduino.bmp")
- print image on the TFT screen with SD card inserted in the TFT screen (instead of the Yún) and using the Arduino TFT Bitmap Logo example to print the logo on the screen.
So, from this I conclude that the connection between the TFT screen and Yún is fine and the image on the SD card installed in the Yún is accessible using the FileIO library of the Yún.
However, when the .bmp is stored on the SD card in the Yún, the FileIO library is needed to access the file. To display the image, the TFT library is needed, which in turn needs the SD library. The SD and FileIO library interfere with each other, due to double declarations of the File class.
The TFT library just uses the Adafruit_ST7735 and Adafruit_GFX libraries. Looking at these libraries it seems that the SD library is only needed to open the file on the SD card:
bmpFile = SD.open(fileName)
Therefore the PImage class and image handling functions needed to print the image on the screen are only declared when the SD library is loaded (#if defined(SD_H)).
In order to use the Adafruit libraries in combination with the FileIO library instead of the SD library I changed:
bmpFile = SD.open(fileName)
into:
File bmpFile = FileSystem.open(fileName);
and
#if defined(SD_H)
into
#if defined(FILEIO_H)
in the Adafruit library files and Pimage.h file.
With these modifications the different libraries are able to work with each other, and I can access the image on the SD card in the Yún, while using the Adafruit libraries, which should allow to print the image on the screen using the following code:
#include Bridge.h
#include FileIO.h
#include SPI.h
#include "Adafruit_ST7735.h"
#include "Adafruit_GFX.h"
// pin definitions
#define cs 7
#define dc 5
#define rst 6
Adafruit_ST7735 tft = Adafruit_ST7735(cs, dc, rst);
void setup() {
tft.initG();
tft.setRotation(1);
Bridge.begin();
Serial.begin(9600);
tft.fillScreen(ST7735_WHITE);
tft.setTextColor(ST7735_BLACK);
tft.setTextSize(1);
tft.println("Initializing FileSystem...");
if (!FileSystem.begin()) {
tft.println("failed!");
return;
}
tft.println("OK!");
PImage logo = tft.loadImage("/mnt/sda1/arduino.bmp");
if (!logo.isValid()) {
tft.println("error while loading Image");
return;
}
tft.println("Image loaded");
_
delay(5000);
tft.fillScreen(ST7735_WHITE);
tft.image(logo, 0, 0);
}
void loop() {
}
However, logo.isValid() returns false. So I guess the image is loaded differently now I’m using:
File bmpFile = FileSystem.open(fileName);
instead of:
bmpFile = SD.open(fileName);
However, until now I haven’t been able to figure out what is going wrong.
Therefore I hope there is someone who knows what is going wrong, or who encountered the problem before and discovered a solution.
Cheers,
Mark
Copied from original issue: arduino/Arduino#2320