How to Use NeoPixel LED Strip with Arduino and TFT LCD - Internet of Things

How to Use NeoPixel LED Strip with Arduino and TFT LCD

How to Use Neopixel RGB LED Strip with Arduino and TFT LCD

Any color is made up of three colors: Red, Green and Blue, using a simple RGB LED you can generate any color. But the limitation of RGB LED is that it has three separate LEDs inside it and requires three Pins of any microcontroller to operate one RGB LED. So it is not possible to connect hundreds of LEDs with one microcontroller.
To overcome this problem Adafruit has created NeoPixel LED Strip. It requires only three pins to drive several RGB NeoPixel LEDs. Two pins are for power and ground and one Pin is for Data In (DI). Data IN pin is used to address and control the different LEDs in the strip with their color, brightness etc. But it requires a Microcontroller to run NeoPixels. Arduino is very commonly used with NeoPixel, so today we will learn to Interface NeoPixel LEDs with Arduino. You can learn more about NeoPixels at AdaFruit.
Here in this project we are Controlling NeoPixel LED using Arduino and TFT LCD touch Screen. We have created 7 touch buttons of different colors on 2.4 inch TFT LCD and when we tap the button of certain color on the LCD, the NeoPixel LED strip illuminates with the same color of that button. Here we have used NeoPixel Digital RGB LED strip of 30 LEDs.
NeoPixel RGB LED can be illuminated in any color and so we can add more buttons on the LCD to glow the LED in more colors on tapping on those buttons. Other beautiful effects and patterns can also be added using Coding. You can build a full Arduino controlled Decoration System using NEO Pixel LEDs and can control this system by LCD lying near to you.

Required components:
·         Arduino Mega or any other Arduino model
·         2.4 inch TFT LCD Shield with SPFD5408 controller
·         NeoPixel RGB LED Strip
·         Connecting Wires
·         USB Cable or 12 V 1A adapter

Circuit Connections:
To connect NeoPixels Strip to Arduino Mega simply connect Arduino 5V pin to NeoPixels 5V pin and Megas GND to NeoPixels GND and then connect NeoPixel DI pin (data in) to Digital Pin no 36 of Arduino Mega. Carefully mount the TFT LCD Touch Shield over Arduino such that GND of MEGA lies beneath GND of LCD and 5V pin of Arduino connects to 5V pin of LCD.
 
Take care not to interchange GND and 5V pin of NeoPixel LED strip while connecting it to Arduino, otherwise it will damage the NeoPixel LED strip. Also note that here we have used Arduino Mega but you can use any other Arduino model.
Connections to Arduino to NeoPixel RGB LED Strip:
Arduino Pins
NeoPixel Strips Pins
5v
5v
GND
GND
Digital Pin no. 36
DI (data in)

Working Explanation:
Working of NeoPixel LED with Arduino is very easy. Just tap the touch button of any color on the LCD in which you want to glow the NeoPixel LED strip. The LED will light according to that color. Code is written in such a way so that you can repeat this task endlessly without having to reset the Arduino Mega. You can check the Code and Demo Video at the end of this article.
When any button is tapped on the LCD, data is sent to Arduino and Arduino further sends instruction to NeoPixel Strip to light accordingly. For example NeoPixel LED strip glows in Green color when we tap the Green button on the LCD and LED strip glows in Red color when we press the Red button and so on.

Programming Explanation:
To Interface TFT LCD with Arduino we have used some libraries. All the libraries come in one rar file and can be downloaded from this link. Click on Clone or downloadand Download ZIPfile and add to your Arduino library folder. This library is needed for proper functioning of TFT LCD.
#include <SPFD5408_Adafruit_GFX.h>    // Core graphics library
#include <SPFD5408_Adafruit_TFTLCD.h> // Hardware-specific library
#include <SPFD5408_TouchScreen.h>

You should test your TFT LCD by burning Arduino with examples codes given in the Library and check if codes are working properly. First check the graphics test, then calibrate test and finally paint test. If you find that all features all working fine then start with code given in this tutorial.

Also for proper functioning of NeoPixel RGB LED strip, you will need one more library, which can be downloaded from here.
#include <Adafruit_NeoPixel.h>

As described earlier Digital Pin 36 of MEGA is connected to DI pin of NeoPixel LED Strip as shown in code below. Also the numbers of LEDs in the Strip are 30 so as is written in code:
#define PIN 36
#define NUM_LEDS 30

Display colors of LCD buttons are denoted by some Codes. You can change these codes according to your LCD.
#define BLACK   0x0000
#define YELLOW    0x001F
#define GREEN     0xF800
#define RED   0x07E0
#define CYAN    0x07FF
#define MAGENTA 0xF81F
#define BLUE  0xFFE0
#define WHITE   0xFFFF

Some parameters for the buttons like size and position are defined in the code:
uint16_t width = 0;
uint16_t height = 0;
uint16_t x = 40;
uint16_t y = height - 20;
uint16_t w = 75;
uint16_t h = 20;
h parameter is used to adjust the size of button on LCD. If you make it 40, then the size of button will get doubled.  y parameter is y coordinate of LCD.

Touch buttons are denoted by numbers as shown in code:
#define BUTTONS 9
#define BUTTON_Red 0
#define BUTTON_DarkRed 1
#define BUTTON_RED 2
#define BUTTON_DarkGreen 3
#define BUTTON_DeepRed 4
#define BUTTON_Blue 5
#define BUTTON_LightBlue 6
#define BUTTON_LightBlue1 7

Some functions are used to emit the color out of NeoPixel like:
void EmitCyan();
void EmitWhite();
void EmitGreen();
void EmitYellow();
void EmitPink();
void EmitBlack();

To find the digital RGB values to be entered for the given color, you can follow this link. Just enter the color you want your NeoPixel strip to glow, find the RGB values for that color and put in above functions.
void initializeButtons() function is used for giving text and color to buttons and also for placing them at required place on LCD.
void initializeButtons() {

  uint16_t x = 40;
  uint16_t y = height - 20;
  uint16_t w = 75;
  uint16_t h = 40;
  uint8_t spacing_x = 5
  ..... .....
  .... ......

void showCalibration() function is used to draw the buttons on the LCD.
void showCalibration() {
  tft.setCursor (40, 0);  
      for (uint8_t i = 0; i < 8; i++) {
        buttons[i].drawButton();
    }
  }

  Demo & Code


How to Use NeoPixel LED Strip with Arduino and TFT LCD How to Use NeoPixel LED Strip with Arduino and TFT LCD Reviewed by XXX on สิงหาคม 27, 2560 Rating: 5

ไม่มีความคิดเห็น