I just bought these components from Adafruit and I'm trying to get them to work together. I have taken some code from another example used by Adafruit and I have gotten most of the way there I think but just need some help getting it right.
The graphics come up on the screen and the touch sense registers but the calibration is way off and I could use a direction to go to figure out how to fix it. I used a calibration test from the RA8875 library that isn't from Adafruit to get the numbers I'm using now, Adafruit didn't have a calibration example for the Adafruit RA8875 library.
The second problem is when I was uploading the code to the Arduino after a bit it would lose the STMPE610 touch controller. The serial window would say touchscreen didn't start and I would unplug the USB and let it sit a bit and come back to it and then it would find it, am I overheating it somehow, the screen has 125mA draw plus whatever the RA8875 and STMPE610 draw. I'm currently powering everything from the Arduino but in my project it will be powered seperately.
Thanks for any help.
//This example implements a simple sliding On/Off button. The example
// demonstrates drawing and touch operations.
//
//Thanks to Adafruit forums member Asteroid for the original sketch!
//
#include <Adafruit_GFX.h>
#include <SPI.h>
#include <Wire.h>
#include <Adafruit_RA8875.h>
#include <Adafruit_STMPE610.h>
// This is calibration data for the raw touch data to the screen coordinates
#define TS_MINX 281
#define TS_MINY 127
#define TS_MAXX 871
#define TS_MAXY 701
#define RA8875_CS 10
#define RA8875_RESET 9
Adafruit_RA8875 tft = Adafruit_RA8875(RA8875_CS, RA8875_RESET);
uint16_t tx, ty;
Adafruit_STMPE610 ts = Adafruit_STMPE610();
boolean RecordOn = false;
#define FRAME_X 210
#define FRAME_Y 180
#define FRAME_W 100
#define FRAME_H 50
#define REDBUTTON_X FRAME_X
#define REDBUTTON_Y FRAME_Y
#define REDBUTTON_W (FRAME_W/2)
#define REDBUTTON_H FRAME_H
#define GREENBUTTON_X (REDBUTTON_X + REDBUTTON_W)
#define GREENBUTTON_Y FRAME_Y
#define GREENBUTTON_W (FRAME_W/2)
#define GREENBUTTON_H FRAME_H
void drawFrame()
{
tft.drawRect(FRAME_X, FRAME_Y, FRAME_W, FRAME_H, RA8875_BLACK);
}
void redBtn()
{
tft.fillRect(REDBUTTON_X, REDBUTTON_Y, REDBUTTON_W, REDBUTTON_H, RA8875_RED);
tft.fillRect(GREENBUTTON_X, GREENBUTTON_Y, GREENBUTTON_W, GREENBUTTON_H, RA8875_BLUE);
drawFrame();
tft.setCursor(GREENBUTTON_X + 6 , GREENBUTTON_Y + (GREENBUTTON_H / 2));
tft.setTextColor(RA8875_WHITE);
tft.setTextSize(2);
tft.println("ON");
RecordOn = false;
}
void greenBtn()
{
tft.fillRect(GREENBUTTON_X, GREENBUTTON_Y, GREENBUTTON_W, GREENBUTTON_H, RA8875_GREEN);
tft.fillRect(REDBUTTON_X, REDBUTTON_Y, REDBUTTON_W, REDBUTTON_H, RA8875_BLUE);
drawFrame();
tft.setCursor(REDBUTTON_X + 6 , REDBUTTON_Y + (REDBUTTON_H / 2));
tft.setTextColor(RA8875_WHITE);
tft.setTextSize(2);
tft.println("OFF");
RecordOn = true;
}
void setup() {
Serial.begin(9600);
tft.begin(RA8875_800x480);
if (!ts.begin()) {
Serial.println("Unable to start touchscreen.");
}
else {
Serial.println("Touchscreen started.");
}
tft.displayOn(true);
tft.GPIOX(true); // Enable TFT - display enable tied to GPIOX
tft.PWM1config(true, RA8875_PWM_CLK_DIV1024); // PWM output for backlight
tft.PWM1out(255);
tft.fillScreen(RA8875_BLUE);
// origin = left,top landscape (USB left upper)
tft.setRotation(1);
redBtn();
}
void loop()
{
// See if there's any touch data for us
if (! ts.bufferEmpty())
{
// Retrieve a point
TS_Point p = ts.getPoint();
// Scale using the calibration #'s
// and rotate coordinate system
p.x = map(p.x, TS_MINY, TS_MAXY, 0, tft.height());
p.y = map(p.y, TS_MINX, TS_MAXX, 0, tft.width());
int y = tft.height() - p.x;
int x = p.y;
if (RecordOn)
{
if ((x > REDBUTTON_X) && (x < (REDBUTTON_X + REDBUTTON_W))) {
if ((y > REDBUTTON_Y) && (y <= (REDBUTTON_Y + REDBUTTON_H))) {
Serial.println("Red btn hit");
redBtn();
}
}
}
else //Record is off (RecordOn == false)
{
if ((x > GREENBUTTON_X) && (x < (GREENBUTTON_X + GREENBUTTON_W))) {
if ((y > GREENBUTTON_Y) && (y <= (GREENBUTTON_Y + GREENBUTTON_H))) {
Serial.println("Green btn hit");
greenBtn();
}
}
}
Serial.println(RecordOn);
}
}
[/img]
[/img]
[/img]