Hey there,
I've been dealing with a pretty frustrating problem and couldn't find any answers on Google / This Forum / Adafruit's.
I've purchased the following 3 items for my project:
- NeoPixels 24 LED Ring - NeoPixel Ring - 24 x 5050 RGB LED with Integrated Drivers : ID 1586 : $16.95 : Adafruit Industries, Unique & fun DIY electronics and kits
- NeoPixels 8 LED Stick - NeoPixel Stick - 8 x 5050 RGB LED with Integrated Drivers : ID 1426 : $5.95 : Adafruit Industries, Unique & fun DIY electronics and kits
- 2.2 TFT LCD Screen - 2.2 18-bit color TFT LCD display with microSD card breakout [EYESPI Connector] : ID 1480 : $24.95 : Adafruit Industries, Unique & fun DIY electronics and kits
I am trying to make them three work together on the same Arduino Uno, in accordance with a Java Processing code which holds the logic of the whole project, using Serial communication.
My Processing code Serial.write()s a byte[] everytime it wants the Arduino to "bring something to life" through the LED and Screen components. The array at 0 holds an "opcode" to navigate inside the code, operating the different components.
The first two LED components are working relatively fine. The problem occurs when I try to synchronize the third component to work with them.
I used the only working thing to operate this third component (TFT Screen): ILI9340 Libraby. I used the graphicstest and spitftbitmap to check it works seperately and wired as needed. All works on its own.
However, as soon as I only use a single command to operate it, even in setup(), it messes everything up with the LED components.
Things I have tried:
-
Running the Processing code without any screen-related-Arduino-code.
LED components work, so I know the Processing code is not the problem. -
Running the screen-related-Arduino-code separately.
The screen works, so it's not the problem nor it's connections. -
Running everything on a different Arduino Uno.
Still doesn't work. The Arduino is not the problem. -
Commenting everything that Serial.print()s in the bmpdraw() method I am using in the code (see below), in case it messes up the Serial port.
Nothing has changed (however if I run it separately it still works so I didn't comment anything I shouldn't have). -
Connecting the screen to 3.3V instead of 5V.
The screen doesn't work with this voltage. -
Using this TFT Arduino library on the website: http://www.arduino.cc/en/Tutorial/TFTBitmapLogo.
I figured maybe the ILI Library is the problem... However I couldn't use it. Even with the most simple code trying to paint the background red, the screen starts flickering:
#include <SD.h>
#include <SPI.h>
#include <TFT.h>
#define TFT_RST 9
#define TFT_DC 8
#define TFT_CS 10
#define SD_CS 4
TFT myScreen = TFT(TFT_CS, TFT_DC, TFT_RST);
void setup() {
Serial.begin(9600);
for (int p = 8; p < 14; p++) {
pinMode(p, OUTPUT);
}
myScreen.begin();
myScreen.background(255, 0, 0);
}
void loop() {
}
PLEASE HELP!
How can I make it work?
P.S - if it matters at all, my final intention is to make the screen show bitmap photos.
Here's my full Arduino code:
#include <Adafruit_NeoPixel.h> // Leds library
#include <avr/power.h>
#include <Adafruit_GFX.h> // Core graphics library
#include "Adafruit_ILI9340.h" // Hardware-specific library
#include <SPI.h>
#include <SD.h>
#if defined(__SAM3X8E__)
#undef __FlashStringHelper::F(string_literal)
#define F(string_literal) string_literal
#endif
// TFT display and SD card will share the hardware SPI interface.
// Hardware SPI pins are specific to the Arduino board type and
// cannot be remapped to alternate pins. For Arduino Uno,
// Duemilanove, etc., pin 11 = MOSI, pin 12 = MISO, pin 13 = SCK.
#define TFT_RST 9
#define TFT_DC 8
#define TFT_CS 10
#define SD_CS 4
Adafruit_ILI9340 tft = Adafruit_ILI9340(TFT_CS, TFT_DC, TFT_RST);
// LED Variables
int r, g, b;
int location;
int amount;
byte byteValues[5];
// Set the pin to digital I/O
int stripPin = 2;
int ringPin = 3;
byte opCode;
Adafruit_NeoPixel ring = Adafruit_NeoPixel(60, ringPin, NEO_GRB + NEO_KHZ800);
Adafruit_NeoPixel strip = Adafruit_NeoPixel(60, stripPin, NEO_GRB + NEO_KHZ800);
void setup() {
Serial.begin(9600);
// Sets screen
tft.begin();
SD.begin(SD_CS);
// As soon as I use this, LED components stops working!
// tft.fillScreen(ILI9340_BLACK);
// bmpDraw("woof.bmp", 0, 0);
// Sets LEDs
pinMode(ringPin, OUTPUT);
pinMode(stripPin, OUTPUT);
ring.begin();
strip.begin();
// Initialize all pixels to 'off'
ring.show();
strip.show();
}
void loop() {
// // Turning off all leds
// for (int i = 0; i < 24; i++) {
// ring.setPixelColor(i, 0, 0, 0);
// }
while (Serial.available() > 4) {
// Read values
for (int i = 0; i < 5; i++) {
byteValues[i] = Serial.read();
}
opCode = byteValues[0];
if (opCode == 10) {
generateRing();
}
else if (opCode == 20) {
generateStrip();
}
else if (opCode == 30) {
generateScreen();
}
}
}
void generateRing() {
r = byteValues[1];
g = byteValues[2];
b = byteValues[3];
location = byteValues[4];
ring.setBrightness(20);
ring.setPixelColor(location, r, g, b);
Serial.flush();
ring.show();
}
void generateStrip() {
// Turning off all leds
for (int i = 0; i < 8; i++) {
strip.setPixelColor(i, 0, 0, 0);
}
r = byteValues[1];
g = byteValues[2];
b = byteValues[3];
amount = byteValues[4];
for (int i = 0; i < amount; i++) {
strip.setBrightness(20);
strip.setPixelColor(i, r, g, b);
}
Serial.flush();
strip.show();
}
void generateScreen() {
// Currently does nothing
Serial.flush();
}
Thanks in advance!