Auf meinem Schreibtisch liegt ein Display, das ich nach der Beschreibung Touch Screen TFT Shield for Arduino Uno und IDE 1.6.5 versuche zu betreiben. Als Test nehme ich eine Mischung aus Adafruit_TFTLCD\examples\tftbmp\tftbmp.pde und Arduin-o-Phone Sketch. Mit freundlicher Unterstützung durch @stern ist es mir gelungen, das Bild eines Hundes (bmp-Datei) und eine Tastatur abzubilden:
Leider werden alle Farben invertiert dargestellt, siehe links. Wenn ich die bmp-Datei auf dem PC invertiere, hat der Hund ein braunes Fell (Mitte). Auch wenn ich alle Farbdefinitionen bitweise invertiere, werden gemalte Farben richtig dargestellt.
Desweiteren liefert tft.readID() immer den Wert Null.
Nun grüble ich, wo der Fehler liegen könnte. Als Controller habe ich ILI9341 angegeben, was aus den Möglichkeiten der Adafruit-Bbliothek das beste Ergebnis brachte. Auch bei HX8357D wird was angezeigt, aber beim invertierten Bild ist das Fell braun (richtig) mit hellen Augen (falsch).
Ich hoffe auf sachdienliche Hinweise zur Ergreifung des Fehlers
Mein Testsketch Teil 1:
// Shield und UNO
#include <Adafruit_GFX.h> // Core graphics library
#include <Adafruit_TFTLCD.h> // Hardware-specific library
#include <TouchScreen.h>
#include <SD.h>
#include <SPI.h>
#define SD_CS 10 // Set the chip select line to whatever you use (10 doesnt conflict with the library)
#define YP A2 // must be an analog pin, use "An" notation!
#define XM A1 // must be an analog pin, use "An" notation!
#define YM 6 // can be a digital pin
#define XP 7 // can be a digital pin
#define TS_MINX 130
#define TS_MINY 90
#define TS_MAXX 900
#define TS_MAXY 910
TouchScreen ts = TouchScreen(XP, YP, XM, YM, 300);
#define LCD_CS A3
#define LCD_CD A2
#define LCD_WR A1
#define LCD_RD A0
// optional
#define LCD_RESET A4
// Assign human-readable names to some common 16-bit color values:
#define BLACK 0xFFFF
#define BLUE 0xFFE0
#define RED 0x07FF
#define GREEN 0xF81F
#define CYAN 0xF800
#define MAGENTA 0x07E0
#define YELLOW 0x001F
#define WHITE 0x0000
Adafruit_TFTLCD tft(LCD_CS, LCD_CD, LCD_WR, LCD_RD, LCD_RESET);
// Color definitions
#define ILI9341_BLACK 0xFFFF
#define ILI9341_NAVY 0xFFF0
#define ILI9341_DARKGREEN 0xFC1F
#define ILI9341_DARKCYAN 0xFC10
#define ILI9341_MAROON 0x87FF
#define ILI9341_PURPLE 0x87F0
#define ILI9341_OLIVE 0x841F
#define ILI9341_LIGHTGREY 0x39E7
#define ILI9341_DARKGREY 0x8410
#define ILI9341_BLUE 0xFFE0
#define ILI9341_GREEN 0xF81F
#define ILI9341_CYAN 0xF800
#define ILI9341_RED 0x07FF
#define ILI9341_MAGENTA 0x07E0
#define ILI9341_YELLOW 0x001F
#define ILI9341_WHITE 0x0000
#define ILI9341_ORANGE 0x02DF
#define ILI9341_GREENYELLOW 0x501A
#define ILI9341_PINK 0x07E0
/******************* UI details */
#define BUTTON_X 40
#define BUTTON_Y 100
#define BUTTON_W 60
#define BUTTON_H 30
#define BUTTON_SPACING_X 20
#define BUTTON_SPACING_Y 20
#define BUTTON_TEXTSIZE 2
// text box where numbers go
#define TEXT_X 10
#define TEXT_Y 10
#define TEXT_W 220
#define TEXT_H 50
#define TEXT_TSIZE 3
#define TEXT_TCOLOR ILI9341_MAGENTA
// the data (phone #) we store in the textfield
#define TEXT_LEN 12
char textfield[TEXT_LEN + 1] = "";
uint8_t textfield_i = 0;
// We have a status line for like, is FONA working
#define STATUS_X 10
#define STATUS_Y 65
Adafruit_GFX_Button buttons[15];
/* create 15 buttons, in classic candybar phone style */
char buttonlabels[15][5] = {"Send", "Clr", "End", "1", "2", "3", "4", "5", "6", "7", "8", "9", "*", "0", "#" };
uint16_t buttoncolors[15] = {ILI9341_DARKGREEN, ILI9341_DARKGREY, ILI9341_RED,
ILI9341_BLUE, ILI9341_BLUE, ILI9341_BLUE,
ILI9341_BLUE, ILI9341_BLUE, ILI9341_BLUE,
ILI9341_BLUE, ILI9341_BLUE, ILI9341_BLUE,
ILI9341_ORANGE, ILI9341_BLUE, ILI9341_ORANGE
};
void setup(void) {
Serial.begin(9600);
Serial.println(F("TFT LCD test"));
tft.reset();
uint16_t identifier = 0x9341;
Serial.println(F("Using 0x9341 LCD driver"));
tft.begin(identifier);
Serial.print(F("Initializing SD card..."));
if (!SD.begin(SD_CS)) {
Serial.println(F("failed!"));
return;
}
Serial.println(F("OK!"));
tft.setRotation(2);
bmpDraw("woof.bmp", 0, 0);
delay(5000);
bmpDraw("woof_neg.bmp", 0, 0);
delay(5000);
// tft.fillScreen(BLACK);
// create buttons
for (uint8_t row = 0; row < 5; row++) {
for (uint8_t col = 0; col < 3; col++) {
buttons[col + row * 3].initButton(&tft, BUTTON_X + col * (BUTTON_W + BUTTON_SPACING_X),
BUTTON_Y + row * (BUTTON_H + BUTTON_SPACING_Y), // x, y, w, h, outline, fill, text
BUTTON_W, BUTTON_H, ILI9341_WHITE, buttoncolors[col + row * 3], ILI9341_WHITE,
buttonlabels[col + row * 3], BUTTON_TEXTSIZE);
buttons[col + row * 3].drawButton();
}
}
// create 'text field'
tft.drawRect(TEXT_X, TEXT_Y, TEXT_W, TEXT_H, ILI9341_WHITE);
}
// Print something in the mini status bar with either flashstring
void status(const __FlashStringHelper *msg) {
tft.fillRect(STATUS_X, STATUS_Y, 240, 8, ILI9341_BLACK);
tft.setCursor(STATUS_X, STATUS_Y);
tft.setTextColor(ILI9341_WHITE);
tft.setTextSize(1);
tft.print(msg);
}
// or charstring
void status(char *msg) {
tft.fillRect(STATUS_X, STATUS_Y, 240, 8, ILI9341_BLACK);
tft.setCursor(STATUS_X, STATUS_Y);
tft.setTextColor(ILI9341_WHITE);
tft.setTextSize(1);
tft.print(msg);
}