
Arduino due and tft
I’ve been playing with a 5″ TFT touch screen. I bought the TFT a while ago and quickly came to the conclusion that an adaptor shield is the best solution to connect it to an Arduino. These touch screen TFT’s use a lot of pins. Another issue is that the controller chip for the TFT works at 3.3V. So you need to level shift all those pins if you want to connect it to a 5V Arduino. I bought an adaptor shield for the Arduino Mega. I then started writing some simple code for it and came to another conclusion. You need a fast micro controller if you want to show some fancy things on your TFT. So I spent some more money and bought an Arduino Due (32bit ARM @ 84MHz). The adaptor shield for the mega doesn’t work with the Due so I also bought a new adaptor shield for the Due on Ebay.
You need 2 libraries to make the TFT and touch function work. I’m using the UTFT and UTouch libraries, I found them here. These libraries are not the most simple, but luckily they come with a manual that explains the libraries functions. When you first use the TFT touch screen you must calibrate it. The UTouch library comes with a sketch to calibrate your display.
One of the things I wanted to try out was using the touch screen as a remote control. I have a lot of cheap nRF24L01 modules so I soldered one to the adaptor shield. Thankfully someone has ported the RF24 library to make it work with the Arduino Due. I made a simple sketch to remotely control 4 leds with the touch screen using the wireless nRF24L01 modules:
Here is the code for the Arduino Due with the touch screen and nRF24L01 module:
// Arduino Due + 5" TFT touch screen + nRF24L01 = bling bling remote control // http://www.bajdi.com #include <UTFT.h> #include <UTouch.h> #include <UTFT_Buttons.h> #include <SPI.h> #include "nRF24L01.h" #include "RF24.h" RF24 radio(8, 9); const uint64_t pipe = 0xE8E8F0F0E1LL; uint8_t remote; extern uint8_t SmallFont[]; extern uint8_t BigFont[]; extern uint8_t Dingbats1_XL[]; UTFT myGLCD(CTE50, 25, 26, 27, 28); UTouch myTouch(6, 5, 4, 3, 2); UTFT_Buttons myButtons(&myGLCD, &myTouch); int pressed_button; const int X = 90; const int Y = 50; int led1OnBut, led2OnBut, led3OnBut, led4OnBut, led1OffBut, led2OffBut, led3OffBut, led4OffBut; void setup() { Serial.begin(57600); radio.begin(); radio.setPALevel( RF24_PA_MAX ) ; radio.setDataRate(RF24_1MBPS); radio.openWritingPipe(pipe); myGLCD.InitLCD(); myGLCD.clrScr(); myGLCD.fillScr(VGA_WHITE); myGLCD.setFont(BigFont); myTouch.InitTouch(); myTouch.setPrecision(PREC_HI); myButtons.setTextFont(BigFont); led1OnBut = myButtons.addButton(X, Y, 150, 80, "Led 1 On"); led2OnBut = myButtons.addButton(X + 155, Y, 150, 80, "Led 2 On"); led3OnBut = myButtons.addButton(X + 310, Y, 150, 80, "Led 3 On"); led4OnBut = myButtons.addButton(X + 465, Y, 150, 80, "Led 4 On"); led1OffBut = myButtons.addButton(X, Y + 100, 150, 80, "Led 1 Off"); led2OffBut = myButtons.addButton(X + 155, Y + 100, 150, 80, "Led 2 Off"); led3OffBut = myButtons.addButton(X + 310, Y + 100, 150, 80, "Led 3 Off"); led4OffBut = myButtons.addButton(X + 465, Y + 100, 150, 80, "Led 4 Off"); myButtons.drawButtons(); } void loop() { if (myTouch.dataAvailable() == true) { pressed_button = myButtons.checkButtons(); if (pressed_button == led1OnBut) { remote = 1; } else if (pressed_button == led2OnBut) { remote = 2; } else if (pressed_button == led3OnBut) { remote = 3; } else if (pressed_button == led4OnBut) { remote = 4; } else if (pressed_button == led1OffBut) { remote = 5; } else if (pressed_button == led2OffBut) { remote = 6; } else if (pressed_button == led3OffBut) { remote = 7; } else if (pressed_button == led4OffBut) { remote = 8; } } radio.write( &remote, sizeof(remote) ); }
And the code for the receiver:
#include <SPI.h> #include "nRF24L01.h" #include "RF24.h" uint8_t remote; const int led1 = 18; const int led2 = 17; const int led3 = 16; const int led4 = 15; // nRF24L01 radio RF24 radio(1,2); const uint64_t pipe = 0xE8E8F0F0E1LL; void setup(){ Serial.begin(57600); pinMode(led1, OUTPUT); pinMode(led2, OUTPUT); pinMode(led3, OUTPUT); pinMode(led1, OUTPUT); radio.begin(); radio.setPALevel( RF24_PA_MAX ); radio.setDataRate(RF24_1MBPS); radio.openReadingPipe(1,pipe); radio.startListening(); } void loop(){ if ( radio.available() ) { // Dump the payloads until we've gotten everything bool done = false; while (!done) { // Fetch the payload, and see if this was the last one. done = radio.read( &remote, sizeof(remote) ); } } switch (remote){ case 1: digitalWrite(led1, HIGH); break; case 2: digitalWrite(led2, HIGH); break; case 3: digitalWrite(led3, HIGH); break; case 4: digitalWrite(led4, HIGH); break; case 5: digitalWrite(led1, LOW); break; case 6: digitalWrite(led2, LOW); break; case 7: digitalWrite(led3, LOW); break; case 8: digitalWrite(led4, LOW); break; } // Serial stuff Serial.print("remote = "); Serial.println(remote); // end of serial stuff }
This is cool, though I gotta say it would have provably worked out cheaper to use a cheap android mobile (or tablet) and control it via Bluetooth.
Wouldn’t require an extra arduino, and would probably be a lot more reliable.
Also, the code would’ve been a lot simpler. Though I can see how from a learning point of view it would be appealing to roll your own thing.
This is more fun then using an off the shelf solution 🙂
kindly tell me the connections of rf module with the lcd touch screen???
The nrf24L01 module is connected to the SPI pins on the Arduino.