Spark Logic

8-bit|16-bit parallell ILI9341

andreas_ferm Tue Oct 06, 2015 12:16 pm

Good day everyone, I’m all new to stm32 and have previously only done smaller projects on arduiono boards, mostly using already-finished libraries.

Now I reached a point where my programmings skills lack, so instead of optimizing my code i started to look at maple mini and thought it would be excellent to also add a “nice” GUI to my project.

I ended up ordering a chinese 3.2″ tft+touch+sd card combo, but what i didn’t know or think of beforehand was to check the connectivity needed (i just read here and saw all the included libraries for the aforementioned display controller), but all of them are using SPI. So the display came in the mail and i became aware that it didn’t have any SPI interface, (at least not for the display, only for the touch and sd card)

Are there any working options that is available to use with stm32duino? What would be my best chance of getting this to work? (i was initially thinking about going for a MEGA, but choose the maple mini clone as i was impressed with the various tft demos i’ve seen )

I’ve tried looking through “all” of the internet, but have only found small pointers, and none of the really targeted for stm32duino. (i found one post where someone had posted an utft version with support for stm32, which was based on some teensy port, but it was also done for SPI only, and i couldn’t find any ILI9341 tft ‘drivers’ for parallel communication… well there was one for an ILI9481 but i’m not sure if that can be used in direct replacement.

Anyone has a similar display and has it working with a maple mini?

Thanks!
Andreas

Replies

zoomx Tue Oct 27, 2015 9:16 am

On Arduino UTFT can’t work with these shield because it uses pins 0-7 instead of pins 2-9 that are used by this shield.
I believe that Madias has a port of this library.

ahull Tue Oct 27, 2015 11:51 am

Hold fire on this, I have a library that may work, but there is an issue with the display (poor quality soldering). I’ll see if I can bring it back to life, and if so I’ll take a crack at porting something stable for it.

These displays are as cheap as chips and have an SD card thrown in, and are parallel, so theoretically they are faster than SPI so it would be good to get it working. They appear to come in a couple of different variants, so I’ll need to take a guess which one I have :D

andreas_ferm Tue Oct 27, 2015 2:32 pm

If the displaydriver is supported by UTFT it should work. For my 16bit display i did the changes like the attached file (for 16bit only)

It’s not the fastest approach, since i wasn’t sure how to do the operations on a whole (or parts of a) port.

Same approach would work for 8bit as well i guess

e-dredon Tue Nov 17, 2015 4:55 pm

andreas_ferm wrote:Good day everyone, I’m all new to stm32 and have previously only done smaller projects on
Anyone has a similar display and has it working with a maple mini?

Thanks!
Andreas

konczakp Thu Jul 14, 2016 5:43 pm

Awesome work! I’m new here so hello everyone!

Did You also changed a library for touch screen for stm32? I’ve tried few examples but none of them works for me. Can You help me with that?

konczakp Sun Jul 17, 2016 10:58 am

can anyone help me with this screen to get the touch screen working (Spfd5408) ? When I’m tying to use TouchScreen_STM library I’m getting errors like below and none of other libraries is working or I’m missing something. Does anyone have a working touch screen for this tft ?

hardware/Arduino_STM32/STM32F1/variants/generic_stm32f103c/variant.h:18:14: error: 'uint8_t' does not name a type
static const uint8_t SCK = BOARD_SPI1_SCK_PIN;

ahull Sun Jul 17, 2016 11:07 am

You might like to take a look at https://github.com/JoaoLopesF/SPFD5408
I haven’t had a play with this particular screen for a while, and I’m not getting much spare time.
Real life keeps throwing in large bunches of spanners..

konczakp Sun Jul 17, 2016 11:24 am

I’ve seen this library but this one is for Arduino and I don’t have enough skills to port it for STM32 and I need to get it run on STM32 using Arduino IDE

ahull Sun Jul 17, 2016 11:38 am

Have you tried the library “as is”. It appears to use pretty standard Arduino syntax to talk to the touch device.

int TouchScreen::readTouchY(void) {
pinMode(_xp, INPUT);
pinMode(_xm, INPUT);
digitalWrite(_xp, LOW);
digitalWrite(_xm, LOW);

pinMode(_yp, OUTPUT);
digitalWrite(_yp, HIGH);
pinMode(_ym, OUTPUT);
digitalWrite(_ym, LOW);

return (1023-analogRead(_xm));
}

konczakp Sun Jul 17, 2016 1:43 pm

It is not possible to use this library “as is” because #error “Board type unsupported / not recognized” and many other errors which I don’t understand :( that is why I was trying to use Touch_Screen_Library_STM included into STM32 Arduino hardware package. At first I was getting errors like this one :

In file included from /home/pilot/Pulpit/arduino-1.6.9/hardware/Arduino_STM32/STM32F1/variants/generic_stm32f103c/pins_arduino.h:6:0,
from /home/pilot/Pulpit/arduino-1.6.9/hardware/Arduino_STM32/STM32F1/libraries/Touch-Screen-Library_STM/TouchScreen_STM.cpp:8:
/home/pilot/Pulpit/arduino-1.6.9/hardware/Arduino_STM32/STM32F1/variants/generic_stm32f103c/variant.h:17:29: error: 'BOARD_SPI1_NSS_PIN' was not declared in this scope
static const uint8_t SS = BOARD_SPI1_NSS_PIN;

^
/home/pilot/Pulpit/arduino-1.6.9/hardware/Arduino_STM32/STM32F1/variants/generic_stm32f103c/variant.h:18:29: error: 'BOARD_SPI2_NSS_PIN' was not declared in this scope
static const uint8_t SS1 = BOARD_SPI2_NSS_PIN;

^
/home/pilot/Pulpit/arduino-1.6.9/hardware/Arduino_STM32/STM32F1/variants/generic_stm32f103c/variant.h:19:29: error: 'BOARD_SPI1_MOSI_PIN' was not declared in this scope
static const uint8_t MOSI = BOARD_SPI1_MOSI_PIN;

^
/home/pilot/Pulpit/arduino-1.6.9/hardware/Arduino_STM32/STM32F1/variants/generic_stm32f103c/variant.h:20:29: error: 'BOARD_SPI1_MISO_PIN' was not declared in this scope
static const uint8_t MISO = BOARD_SPI1_MISO_PIN;

^
/home/pilot/Pulpit/arduino-1.6.9/hardware/Arduino_STM32/STM32F1/variants/generic_stm32f103c/variant.h:21:29: error: 'BOARD_SPI1_SCK_PIN' was not declared in this scope
static const uint8_t SCK = BOARD_SPI1_SCK_PIN;

martinayotte Sun Jul 17, 2016 2:26 pm

You should not comment out those in variant.h, leave them there.
The error you got is that those defines are not loaded from STM32F1/variants/maple/board/board.h where they are defined, probably because this file never loaded, probably because your sketch doesn’t include “Arduino.h” as the first header.

konczakp Sun Jul 17, 2016 3:17 pm

adding arduino.h at the bigining of the sketch doesn’t change anything. still same errors.

konczakp Sun Jul 17, 2016 4:44 pm

Guys, I do really need to get this working. I will donate $$ person who can help me with this

martinayotte Sun Jul 17, 2016 5:45 pm

It seems that the problem is related to the fact that Touch-Screen-Library_STM/TouchScreen_STM.cpp is wrongly including “pins_arduino.h”, by simply commenting that include, I’ve it compiled …

konczakp Sun Jul 17, 2016 6:45 pm

Yes it is now compiling but still not working. Not getting any response from touch screen. I tried pin configuration like this:

#define YP PB6 // LCD_RS
#define XM PB7 // LCD_CS
#define YM PA0 // LCD_D0
#define XP PA1 // LCD_D1

martinayotte Sun Jul 17, 2016 8:19 pm

Unfortunately, I don’t have such TFT display, so, I can’t help you for runtime debugging.

konczakp Mon Jul 18, 2016 12:18 pm

OK, so I took working example from Arduino UNO. I’ve cut off everything from library that I don’t need and from rest I have created function in simple sketch. On Arduino UNO it is working perfectly and now it is not relying on any external library. But …. there is always some but at the end … I’m getting compilation errors.

sketch:

// Touch screen library with X Y and Z (pressure) readings as well
// as oversampling to avoid 'bouncing'
// This demo code returns raw readings, public domain

//for STM32
#define YP PB3 // must be an analog pin, use "An" notation!
#define XM PB4 // must be an analog pin, use "An" notation!
#define YM PB5 // can be a digital pin
#define XP PB6 // can be a digital pin

//for arduino
//#define YP A2 // must be an analog pin, use "An" notation!
//#define XM A3 // must be an analog pin, use "An" notation!
//#define YM 8 // can be a digital pin
//#define XP 9 // can be a digital pin

#define pressureThreshhold 20
#define platform 1 //1 for arduino, 2 for STM32

void setup(void) {
Serial.begin(115200);
}

void loop(void) {

// For better pressure precision, we need to know the resistance
// between X+ and X- Use any multimeter to read it
// For the one we're using, its 300 ohms (rxplate) across the X plate

getPoint_new(XP, YP, XM, YM, 300);

}

void getPoint_new(byte xp, byte yp, byte xm, byte ym, int rxplate) {

int x, y, z;
int samples[2];
byte i, valid;

byte xp_port = digitalPinToPort(xp);
byte yp_port = digitalPinToPort(yp);
byte xm_port = digitalPinToPort(xm);
byte ym_port = digitalPinToPort(ym);

byte xp_pin = digitalPinToBitMask(xp);
byte yp_pin = digitalPinToBitMask(yp);
byte xm_pin = digitalPinToBitMask(xm);
byte ym_pin = digitalPinToBitMask(ym);

valid = 1;

pinMode(yp, INPUT);
pinMode(ym, INPUT);

*portOutputRegister(yp_port) &= ~yp_pin;
*portOutputRegister(ym_port) &= ~ym_pin;

pinMode(xp, OUTPUT);
pinMode(xm, OUTPUT);

*portOutputRegister(xp_port) |= xp_pin;
*portOutputRegister(xm_port) &= ~xm_pin;

delayMicroseconds(20); // Fast ARM chips need to allow voltages to settle

for (i=0; i<2; i++) {
samples[i] = analogRead(yp);
}

// Allow small amount of measurement noise, because capacitive
// coupling to a TFT display's signals can induce some noise.

if (samples[0] - samples[1] < -4 || samples[0] - samples[1] > 4) {
valid = 0;
} else {
samples[1] = (samples[0] + samples[1]) >> 1; // average 2 samples
}

x = (1023-samples[1]);

pinMode(xp, INPUT);
pinMode(xm, INPUT);

*portOutputRegister(xp_port) &= ~xp_pin;

pinMode(yp, OUTPUT);
*portOutputRegister(yp_port) |= yp_pin;
pinMode(ym, OUTPUT);

delayMicroseconds(20); // Fast ARM chips need to allow voltages to settle

for (i=0; i<2; i++) {
samples[i] = analogRead(xm);
}

// Allow small amount of measurement noise, because capacitive
// coupling to a TFT display's signals can induce some noise.
if (samples[0] - samples[1] < -4 || samples[0] - samples[1] > 4) {
valid = 0;
} else {
samples[1] = (samples[0] + samples[1]) >> 1; // average 2 samples
}

y = (1023-samples[1]);

// Set X+ to ground
pinMode(xp, OUTPUT);
*portOutputRegister(xp_port) &= ~xp_pin;

// Set Y- to VCC
*portOutputRegister(ym_port) |= ym_pin;

// Hi-Z X- and Y+
*portOutputRegister(yp_port) &= ~yp_pin;
pinMode(yp, INPUT);

int z1 = analogRead(xm);
int z2 = analogRead(yp);

if (rxplate != 0) {

// now read the x
float rtouch;
rtouch = z2;
rtouch /= z1;
rtouch -= 1;
rtouch *= x;
rtouch *= rxplate;
rtouch /= 1024;
z = rtouch;

} else {

z = (1023-(z2-z1));

}

if (! valid) {
z = 0;
}

if (z > pressureThreshhold && z < 1000){
Serial.print("X = "); Serial.print(x);
Serial.print("\tY = "); Serial.print(y);
Serial.print("\tPressure = "); Serial.println(z);
}

}

Sign in to reply