I had a long strip of WS2812 lights (300 LEDs) and had some code that was working completely fine. I decided to cut the strip so it would be the length of my desk but now the lights are acting strange and not following my code at all. I modified the code so it would work with the new length but now it doesn't work. I'm not sure if this is a hardware or software issue so I'll share the code I used and we can narrow it down from there. I simplified the code to light up just one LED but all the LEDs light up and are random colors which I have not had happen before. Here is the code:
#include <FastLED.h>
#define NUM_LEDS 10
#define LED_PIN 6
CRGB led[NUM_LEDS];
void setup() {
delay(100);
FastLED.addLeds<WS2812, LED_PIN>(led, NUM_LEDS);
}
void loop() {
led[0] = CHSV(100, 255, 255);
FastLED.show();
}
Let me know if there is more information you need and I will be happy to provide, thanks!
Related
I'm trying to turn on a LED on a pic24FV16KA301 microcontroller, through a button press. The problem is the LED automatically goes on. After some altering it looks like the PIC is automatically pressed. The button is connected with a pull up resistor.
Here is part of the code(since some of the code is irrelavent to the problem).
#include <xc.h>
#include "Header_School_Project.h"
#include <stdlib.h>
#include <stdio.h>
#include <libpic30.h>
#define _XTAL_FREQ 20000000
#define LED_LOW LATAbits.LATA4
#define BUTTON_LOW PORTAbits.RA1
void main(void)
{
TRISAbits.TRISA4 = 0;
TRISAbits.TRISA1 = 1;
while(1)
{
if(!BUTTON_LOW)
{
__delay_ms(100);
if(!BUTTON_LOW)
{
LED_LOW = 1;
}
}
else if(BUTTON_LOW)
{
LED_LOW = 0;
}
return;
}
If anyone can help me with this, that would be much appreciated.
EDIT: After changing the __delay_ms(100) to __delay_ms(1000) I see that the LED is flickering on and off really fast
First configure the pins of porta as digital pins as mentioned in the datasheet of corresponding microcontroller using ANSEL register.
One more thing is increase de-bouncing delay to about 300ms, this much can solve your problem.
As mentioned by Kozmotronik you need to set the pin to digital first. PICs default to analog inputs... this "defualt" has wasted enormous number of man hours.
I purchased a 5 meter strip of WS2812B LEDs to be used in conjunction with a motion detector (WS2812B 5 Pins RGBW RGBWW 4 IN 1 LED Strip Light Non-Waterproof DC5V).
The strips are hooked up to a 5V power supply (USB powerbank) and GND/5V/signal on pin 6 on an arduino UNO.
I should note that I so far have not cut the LED strip, so all 5 meters are intact.
I've tried getting the LEDs to emit simple colors using the FASTLED library using the code below. The Blue/blue/blue combination results in the colors Blue/Red/Green on LEDs 0-2
Changing to Red/Red/Red produces Yellow-ish/blue/off
Changing to Green/Green/Green produces the colors Red/lightgreen-ish/off
I've tried shifting from RGB to RBG color scheme to no avail
I don't have much information on the LED strip apart from what I have already provided you with
Can you give me any ideas on how to proceed?
#include "FastLED.h"
#define NUM_LEDS 5
#define DATA_PIN 6
// Define the array of leds
CRGB leds[NUM_LEDS];
void setup()
{
//FastLED.addLeds<WS2812B, DATA_PIN, RGB>(leds, NUM_LEDS);
FastLED.addLeds<WS2812, DATA_PIN, RGB>(leds, NUM_LEDS); // for GRB LEDs
}
void loop()
{
leds[0] = CRGB::Blue;
leds[1] = CRGB::Blue;
leds[2] = CRGB::Blue;
FastLED.show();
delay(500);
This might not be the exact answer you are looking for, but I’d suggest using the Adafruit_Neopixel.h library for your LED’s. Just did a Projekt with that library and the exact LED strip you are using and it is working great so far.
#include "Adafruit_NeoPixel.h"`
#define LED_PIN 6
#define LED_COUNT 60
Adafruit_NeoPixel strip(LED_COUNT, LED_PIN, NEO_GRB + NEO_KHZ800);
int red = 100;
int green = 0;
int blue = 0;
void setup() {
strip.begin(); // INITIALIZE NeoPixel strip object (REQUIRED)
strip.show(); // Turn OFF all pixels ASAP}
}
void loop() {
for (i=0; i<LED_COUNT; i++){
strip.setPixelColor(i, strip.Color(Red, Green, Blue));
strip.show();
}
}
This should make 60 LED’s red. I’ve also got an LED Project on my GitHub page if you want to look that up. If the code above still doesn’t work I assume your wiring is wrong. I power my chip and LEDs off a power supple and also use the ground of the power supply.
I've got an Arduino with a WS2812 hooked up to it, powered by the USB on my computer and I am trying to run the following code:
#include <FastLED.h>
#define NUM_LEDS 144
#define DATA_PIN 6
#define LED_TYPE WS2812B
#define COLOR_ORDER GRB
CRGB leds[NUM_LEDS];
void setup() {
FastLED.addLeds<LED_TYPE, DATA_PIN, COLOR_ORDER>(leds, NUM_LEDS);
FastLED.show();
}
void loop() {
for(int dot = 0; dot < NUM_LEDS; dot++) {
fill_solid(leds, NUM_LEDS, CRGB::Red);
leds[dot] = CRGB::Black;
leds[dot] = CRGB::Blue;
FastLED.show();
leds[dot] = CRGB::Red;
delay(30);
}
}
void setAll() {
FastLED.show();
}
What this does is sets all the LEDs to red, then goes through each one turning it off, then to blue and then back to red.
For some reason, it gets X number of LEDs along and then crashes. By crashes I mean the Arduino disconnects itself from the computer, but the Arduino stays on with the LED strip still powered up.
Any ideas? This is a genuine Uno.
Also. If I plug the LED into the 3.3v pin, the animations works just fine, but the LED flashes black and doesn't complete the Blue part.
I never used the NeoPixels, so I'm not really sure about this, but I'm pretty confident these will solve your problem.
First of all, your program. I don't think it is doing what you think it should do. Try with this loop, instead:
void loop()
{
fill_solid(leds, NUM_LEDS, CRGB::Red);
FastLED.show();
delay(100);
for(int dot = 0; dot < NUM_LEDS; dot++)
{
leds[dot] = CRGB::Black;
FastLED.show();
delay(100);
leds[dot] = CRGB::Blue;
FastLED.show();
delay(100);
leds[dot] = CRGB::Red;
FastLED.show();
delay(100);
}
}
and remove the SetAll function, since it is useless.
Try this code with NUM_LEDS set to 5, and it should work.
Now the main problem: are you really using 144 leds powered by the USB? I suggest you to read this link about powering the neopixels. Particularly the part stating that at full brightness each neopixel draws 60mA. Doing the math, 144 neopixels draw at most 8.64A, so you need a 5V 10A power supply to power them all! a USB with 5V 0.5A will just shut itself down when you try to turn them on, thus giving you strange behaviors.
So lower the number of leds you are using (7 at most), or use an external power supply. And by external I do not mean use the barrel jack on the arduino, but connect a 5V 10A (or more amps) to the neopixel strip, then the ground and data wire to the arduino (not the +5v) and power the arduino through the usb port: it should work.
UPDATE:
According to the chat with the author, the problem was indeed the power supply
The datasheet from adafruit https://cdn-shop.adafruit.com/datasheets/WS2812.pdf says that you need a power supply between 6v and 7v but USB cannot provide more than 5v, I am guessing the arduino crashes because it cannot find enough power.
Can you try using an external power supply?
I have a problem with flickering neopixel leds. I'm using a setup of 6 strips of 8xWS2812 5050 leds. I've connected these to a 5v power supply (USB charger) and an Arduino Uno running the Neopixel simple example code:
// NeoPixel Ring simple sketch (c) 2013 Shae Erisson
// released under the GPLv3 license to match the rest of the AdaFruit NeoPixel library
#include <Adafruit_NeoPixel.h>
#ifdef __AVR__
#include <avr/power.h>
#endif
#define PIN 6
#define NUMPIXELS 48
Adafruit_NeoPixel pixels = Adafruit_NeoPixel(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);
int delayval = 50; // delay for half a second
void setup() {
// This is for Trinket 5V 16MHz, you can remove these three lines if you are not using a Trinket
#if defined (__AVR_ATtiny85__)
if (F_CPU == 16000000) clock_prescale_set(clock_div_1);
#endif
// End of trinket special code
pixels.begin(); // This initializes the NeoPixel library.
}
void loop() {
for(int i=0;i<NUMPIXELS;i++){
pixels.setPixelColor(i, pixels.Color(200,200,200)); // Moderately bright green color.
pixels.show(); // This sends the updated pixel color to the hardware.
delay(delayval); // Delay for a period of time (in milliseconds).
}
}
I've connected a 500uf 10v capacitor between the 5v and the gnd. And a 470 ohm resister between the arduino and the datapin.
I've noticed that the leds also flicker when the leds are on and the datapin is disconnected. The flickering is subtle, but annoying.
I've also tried an alternative power supply. For this I used a adjustable lab power supply. But the same problem persists.
I have to use these leds for a project that I need to finish tomorrow. (I know i should have done this earlier) Is there anyone who could offer me some help? I could really use some.
EDIT: The flickering had to do with the quality of the leds. These weren't real neopixels, instead I received some bad fake ones.
I just purchased Seeed's TFT Touch Shield 2.0 for Arduino, but I cannot seem to figure out how to access the SD card while maintaining the ability to draw to the screen. The tutorials and documentation are quite insubstantial (for me), and most questions on the product site seem to be directed to the same wiki page, which doesn't explain anything about the SD interface, other than what example file draws bitmaps from the card.
I've used the SD interface with the Ethernet Shield before, but it's been a long time since then, so I can't quite remember the ins and outs. From my old code, it seems that, for normal usage of the SD library, you simply do:
#include <SD.h>
void setup()
{
pinMode(4, OUTPUT);
if (!SD.begin(4))
{
//Fail
}
... //Open file, read, etc.
}
To use the TFT screen normally (with the exception of drawing bitmaps), you do as such:
#include <SD.h>
#include <TFTv2.h>
#include <SPI.h>
void setup()
{
TFT_BL_ON; //Enable Backlight
Tft.TFTinit(); //Initialize TFT Screen
Tft.drawCircle(100, 100, 30,YELLOW); //Draw
}
In the provided example program on the wiki page for drawing bitmaps from the SD card, the setup code looks like this:
#include <SD.h>
#include <TFTv2.h>
#include <SPI.h>
#define chipSelect 4
Sd2Card card;
void setup()
{
pinMode(11,INPUT);
pinMode(12,INPUT);
pinMode(13,INPUT);
TFT_CS_HIGH;
pinMode(chipSelect,OUTPUT);
digitalWrite(chipSelect,HIGH);
Serial.begin(38400);
SPI.begin();
Tft.TFTinit();
//SPI.setClockDivider(SPI_CLOCK_DIV4);
//SDcard_info();
/**/
DDRB |= 0x04;
card.init(SPI_FULL_SPEED,chipSelect);
if(!SD.begin(chipSelect))//SPI_QUARTER_SPEED,
{ //53 is used as chip select pin
Serial.println("failed!");
while(1);
}
Serial.println("SD OK!");
Tft.setCol(0,239);
Tft.setPage(0,319);
Tft.sendCMD(0x2c);//start to write to display ram
TFT_BL_ON;
}
In loop() bitmaps are sequentially opened with SD.open(), drawn, and then closed with SD.close().
What I assume is happening is that pins 11 through 13 are set to input for some SPI-related reason, the TFT chip select 'enabled' mode is set to HIGH, and then the screen is subsequently enabled. Serial moniter is started, followed by SPI, and then the TFT. After those things happen, it does something unknown to me, starts the card, and then uses the standard card initialization method. It finishes up by preparing to draw the bitmaps and sends this 'command 0x2c', which is used frequently in the underlying libraries to "start to write to display ram".
The problem is that I have tried initializing the TFT and SD card using this code, and then attempted to draw graphics as shown in my second example, but this did not work. I need to be able to read bytes from the SD card, and then be able to draw simple graphics on-screen, and repeat.
So my question is: Is anyone who has used this shield before or has experience with this able to explain how one should go about writing the code to allow usage of both the SD card and screen or how the initialization and SPI processes work to make this possible?
Thanks for your answers in advance!
(Also, if this is not the correct SE site for this question, please feel free to migrate it accordingly.)
The solution to this problem is quite simple actually, and I must have been doing something wrong when I had combined the source files before.
The initialization code looks like this:
#include <SD.h>
#include <TFTv2.h>
#include <SPI.h>
Sd2Card card;
void setup()
{
pinMode(11, INPUT); //Pin mode changes; not sure what for
pinMode(12, INPUT);
pinMode(13, INPUT);
TFT_CS_HIGH; //Something with chipselect and the TFT
pinMode(4, OUTPUT); //Set chipselect pin to OUTPUT
digitalWrite(4, HIGH); //Set chipselect mode
SPI.begin(); //Start SPI
Tft.TFTinit(); //Initialize the TFT
TFT_BL_ON; //Turn on the TFT Backlight
Serial.begin(9600); //Start serial output
DDRB |= 0x04; //Some sort of processor IO port?
if(!SD.begin(4)) //Start the SD card
{
while(true) { } //Fail
}
}
It is basically the bitmap initialization code, with the extra TFT commands at the end left out. After this, both the screen and the SD card are usable, as was desired.