0

Control just 3 neopixels
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

Control just 3 neopixels

by Scoobie on Sun Oct 02, 2016 3:57 am

Hi there,

i've been tinkering with 3 5mm diff neopixel leds on my arduino micro. As a neopixel newbie i hope someone here can help me on my way.

First i connect just one led and used the sketch code to make a rainbow; this works. I connected two extra leds (now total of 3), changed the code (#define amountofleds 3) and tried it. Now the first led blinks blue and then stops.

My code starts within a very large piece of code which i won't post. Herunder is the code that starts from within the void loop by command: Rainbow(20).

Code: Select all | TOGGLE FULL SIZE
void rainbow(uint8_t wait) {
  uint16_t ib, jb;

  for(jb=0; jb<256; jb++) {
    for(ib=0; ib<strip.numPixels(); ib++) {
      strip.setPixelColor(ib, Wheel((ib+jb) & 255));
    }
    strip.show();
    delay(wait);
  }
}

// Input a value 0 to 255 to get a color value.
// The colours are a transition r - g - b - back to r.
uint32_t Wheel(byte WheelPos) {
  WheelPos = 255 - WheelPos;
  if(WheelPos < 85) {
    return strip.Color(255 - WheelPos * 3, 0, WheelPos * 3);
  }
  if(WheelPos < 170) {
    WheelPos -= 85;
    return strip.Color(0, WheelPos * 3, 255 - WheelPos * 3);
  }
  WheelPos -= 170;
  return strip.Color(WheelPos * 3, 255 - WheelPos * 3, 0);


As i lack this neopixel knowledge i really hope some of you ca nhelp me out. How do i make 2 leds glow brown and a third led moving between purple and blue??

Many thanks!!

Scoobie
 
Posts: 7
Joined: Sun Sep 25, 2016 5:01 am

Re: Control just 3 neopixels

by adafruit_support_bill on Sun Oct 02, 2016 6:31 am

First i connect just one led and used the sketch code to make a rainbow; this works. I connected two extra leds (now total of 3), changed the code (#define amountofleds 3) and tried it. Now the first led blinks blue and then stops.

Please post the whole code so that we can see how your strip is defined.

Also please post some photos showing your soldering and connections to the leds.

adafruit_support_bill
 
Posts: 67303
Joined: Sat Feb 07, 2009 10:11 am

Re: Control just 3 neopixels

by Scoobie on Sun Oct 02, 2016 6:50 am

Hope this helps!

Code: Select all | TOGGLE FULL SIZE
                                                                   #include <AddicoreRFID.h>
#include <SPI.h>

#define   uchar   unsigned char
#define   uint   unsigned int
#include <Adafruit_NeoPixel.h>

#ifdef __AVR__
  #include <avr/power.h>
#endif

#define PIN 4
#define AANTALLEDS 3

uchar fifobytes;
uchar fifoValue;

AddicoreRFID myRFID; // create AddicoreRFID object to control the RFID module

const int chipSelectPin = 10;
const int NRSTPD = 5;
int teller;
String coordinaat ="N5203265E00423071";
String opbouw ="";
String teststring ="";

//Maximum length of the array
#define MAX_LEN 16


  // Parameter 1 = number of pixels in strip
  // Parameter 2 = Arduino pin number (most are valid)
  // Parameter 3 = pixel type flags, add together as needed:
  //   NEO_KHZ800  800 KHz bitstream (most NeoPixel products w/WS2812 LEDs)
  //   NEO_KHZ400  400 KHz (classic 'v1' (not v2) FLORA pixels, WS2811 drivers)
  //   NEO_GRB     Pixels are wired for GRB bitstream (most NeoPixel products)
  //   NEO_RGB     Pixels are wired for RGB bitstream (v1 FLORA pixels, not v2)
  //   NEO_RGBW    Pixels are wired for RGBW bitstream (NeoPixel RGBW products)
  Adafruit_NeoPixel strip = Adafruit_NeoPixel(AANTALLEDS, PIN, NEO_RGB + NEO_KHZ800);

void setup() {   
         
    strip.begin();
    strip.show(); // Initialize all pixels to 'off'
     
  Serial.begin(9600);                        // RFID reader SOUT pin connected to Serial RX pin at 9600bps
 
  // start the SPI library:
  SPI.begin();
 
  pinMode(chipSelectPin,OUTPUT);              // Set digital pin 10 as OUTPUT to connect it to the RFID /ENABLE pin
    digitalWrite(chipSelectPin, LOW);         // Activate the RFID reader
  pinMode(NRSTPD,OUTPUT);                     // Set digital pin 10 , Not Reset and Power-down
    digitalWrite(NRSTPD, HIGH);

  myRFID.AddicoreRFID_Init(); 
}

void loop()
{
     uchar i, tmp, checksum1;
   uchar status;
        uchar str[MAX_LEN];
        uchar RC_size;
        uchar blockAddr;   //Selection operation block address 0 to 63
        String mynum = "";

        str[1] = 0x4400;
   //Find tags, return tag type
   status = myRFID.AddicoreRFID_Request(PICC_REQIDL, str);   
   if (status == MI_OK)
   {
          Serial.println("RFID tag detected");
          Serial.print("Tag Type:\t\t");
          uint tagType = str[0] << 8;
          tagType = tagType + str[1];
          switch (tagType) {
            case 0x400:
              Serial.println("Mifare One (S50)");
              break;
            default:
              Serial.println("Unknown");
              break;
          }
   }

   //Anti-collision, return tag serial number 4 bytes
   status = myRFID.AddicoreRFID_Anticoll(str);
   if (status == MI_OK)
   {
          checksum1 = str[0] ^ str[1] ^ str[2] ^ str[3];
          Serial.print("The tag's number is:\t");
           Serial.print(str[0]);
            Serial.print(" , ");
           Serial.print(str[1]);
            Serial.print(" , ");
           Serial.print(str[2]);
            Serial.print(" , ");
           Serial.println(str[3]);
                   
          Serial.print("Read Checksum:\t\t");
             Serial.println(str[4]);
          Serial.print("Calculated Checksum:\t");
            Serial.println(checksum1);
 uint8_t wait;
            // Should really check all pairs, but for now we'll just use the first
            if(str[0]==20 && str[1]==200 && str[2]==201 && str[3] == 28)                      //20 , 200 , 201 , 28
            {
                Serial.println("\nWelkom Piet!!\n");
                teststring=opbouw + '5';
                if (coordinaat.startsWith(teststring)) {
                  opbouw=teststring;
                  rainbow(20);
                  }
            } else if(str[0]==116 && str[1]==160 && str[2]==202 && str[3] == 28)     {             //116 , 160 , 202 , 28
                teststring=opbouw + 'N';
                if (coordinaat.startsWith(teststring)) {
                  opbouw=teststring;
                  rainbow(10);
                    }
            } else if(str[0]==151 && str[1]==80 && str[2]==227 && str[3] == 220)     {             //151 , 80 , 227 , 220
                teststring=opbouw + '0';
                if (coordinaat.startsWith(teststring)) {
                  opbouw=teststring;
                  rainbow(20);
                    }
            } else if(str[0]==148 && str[1]==77 && str[2]==201 && str[3] == 28)     {             //148 , 77 , 201 , 28
                teststring=opbouw + '2';
                if (coordinaat.startsWith(teststring)) {
                  opbouw=teststring;
                  rainbow(20);
                    }
            } else if(str[0]==196 && str[1]==225 && str[2]==203 && str[3] == 28)     {             //196 , 225 , 203 , 28
                teststring=opbouw + '3';
                if (coordinaat.startsWith(teststring)) {
                  opbouw=teststring;
                  rainbow(20);
                    }
            }  else if(str[0]==183 && str[1]==161 && str[2]==229 && str[3] == 220)     {             //183 , 161 , 229 , 220
                teststring=opbouw + '2';
                if (coordinaat.startsWith(teststring)) {
                  opbouw=teststring;
                  rainbow(20);
                    }
            } else if(str[0]==247 && str[1]==139 && str[2]==222 && str[3] == 220)     {             //247 , 139 , 222 , 220
                teststring=opbouw + '6';
                if (coordinaat.startsWith(teststring)) {
                  opbouw=teststring;
                  rainbow(20);
                    }
            } else if(str[0]==52 && str[1]==150 && str[2]==201 && str[3] == 28)     {             //52 , 150 , 201 , 28
                teststring=opbouw + '5';
                if (coordinaat.startsWith(teststring)) {
                  opbouw=teststring;
                  rainbow(20);
                    }
             } else if(str[0]==100 && str[1]==244 && str[2]==209 && str[3] == 28)     {             //100 , 244 , 209 , 28
                teststring=opbouw + 'E';
                if (coordinaat.startsWith(teststring)) {
                  opbouw=teststring;
                  rainbow(20);
                    }
            } else if(str[0]==199 && str[1]==143 && str[2]==222 && str[3] == 220)     {             //199 , 143 , 222 , 220
                teststring=opbouw + '0';
                if (coordinaat.startsWith(teststring)) {
                  opbouw=teststring;
                  rainbow(20);
                    }
            }  else if(str[0]==100 && str[1]==103 && str[2]==203 && str[3] == 28)     {             //100 , 103 , 203 , 28
                teststring=opbouw + '0';
                if (coordinaat.startsWith(teststring)) {
                  opbouw=teststring;
                  rainbow(20);
                    }
            } else if(str[0]==7 && str[1]==244 && str[2]==231 && str[3] == 220)     {             //7 , 244 , 231 , 220
                teststring=opbouw + '4';
                if (coordinaat.startsWith(teststring)) {
                  opbouw=teststring;
                  rainbow(20);
                    }
            } else if(str[0]==196 && str[1]==228 && str[2]==203 && str[3] == 28)     {             //196 , 228 , 203 , 28
                teststring=opbouw + '2';
                if (coordinaat.startsWith(teststring)) {
                  opbouw=teststring;
                  rainbow(20);
                    }
            } else if(str[0]==7 && str[1]==140 && str[2]==222 && str[3] == 220)     {             //7 , 140 , 222 , 220
                teststring=opbouw + '3';
                if (coordinaat.startsWith(teststring)) {
                  opbouw=teststring;
                  rainbow(20);
                    }
            }  else if(str[0]==52 && str[1]==163 && str[2]==201 && str[3] == 28)     {             //52 , 163 , 201 , 28
                teststring=opbouw + '0';
                if (coordinaat.startsWith(teststring)) {
                  opbouw=teststring;
                  rainbow(20);
                    }
            } else if(str[0]==52 && str[1]==157 && str[2]==201 && str[3] == 28)     {             //52 , 157 , 201 , 28
                teststring=opbouw + '7';
                if (coordinaat.startsWith(teststring)) {
                  opbouw=teststring;
                  rainbow(20);
                    }
            } else if(str[0]==100 && str[1]==253 && str[2]==209 && str[3] == 28)     {             //100 , 253 , 209 , 28
                teststring=opbouw + '1';
                if (coordinaat.startsWith(teststring)) {
                  opbouw=teststring;
                  rainbow(20);
                    }
            }
            Serial.println();
            delay(1000);
   }
      
        myRFID.AddicoreRFID_Halt();         //Command tag into hibernation             
}

void rainbow(uint8_t wait) {
  uint16_t ib, jb;

  for(jb=0; jb<256; jb++) {
    for(ib=0; ib<strip.numPixels(); ib++) {
      strip.setPixelColor(ib, Wheel((ib+jb) & 255));
    }
    strip.show();
    delay(wait);
  }
}

// Input a value 0 to 255 to get a color value.
// The colours are a transition r - g - b - back to r.
uint32_t Wheel(byte WheelPos) {
  WheelPos = 255 - WheelPos;
  if(WheelPos < 85) {
    return strip.Color(255 - WheelPos * 3, 0, WheelPos * 3);
  }
  if(WheelPos < 170) {
    WheelPos -= 85;
    return strip.Color(0, WheelPos * 3, 255 - WheelPos * 3);
  }
  WheelPos -= 170;
  return strip.Color(WheelPos * 3, 255 - WheelPos * 3, 0);
}

Scoobie
 
Posts: 7
Joined: Sun Sep 25, 2016 5:01 am

Re: Control just 3 neopixels

by adafruit_support_bill on Sun Oct 02, 2016 7:32 am

OK. It looks like they are defined properly. Must be a wiring problem. Also please post some photos showing your soldering and connections to the leds.

adafruit_support_bill
 
Posts: 67303
Joined: Sat Feb 07, 2009 10:11 am

Re: Control just 3 neopixels

by Scoobie on Sun Oct 02, 2016 7:37 am

IMG_0010.JPG
IMG_0010.JPG (862.79 KiB) Viewed 153 times


As the code gives away, i also have rfid module attached.

Scoobie
 
Posts: 7
Joined: Sun Sep 25, 2016 5:01 am

Re: Control just 3 neopixels

by adafruit_support_bill on Sun Oct 02, 2016 7:54 am

When working with discrete neopixels, we recommend wiring a 0.1uF decoupling capacitor between 5v and GND for stable operation.

Another possible issue is the RF generated by your RFID module. This can be picked up by your neopixel wiring and potentially interfere with the signal. Try disconnecting the RFID temporarily to see if this has an effect.

adafruit_support_bill
 
Posts: 67303
Joined: Sat Feb 07, 2009 10:11 am

Re: Control just 3 neopixels

by Scoobie on Sun Oct 02, 2016 9:38 am

So i added the capcitor and disconnected the rfid module. No luck.
But my friendly neighbour (who was so kind as to donate the capacitor) gave me the insight...

When placing the leds serial, the voltage drops. Somi had to wire them paralell... duhhh... totally forgot that part of school ;))

All is working like a charm and all my tinkering in the code only made me wiser in neopixel coding. No there yet... but i like to learn. Many thanks for your assistance!

Scoobie
 
Posts: 7
Joined: Sun Sep 25, 2016 5:01 am

Re: Control just 3 neopixels

by adafruit_support_bill on Sun Oct 02, 2016 9:55 am

Good to hear you got it working!

adafruit_support_bill
 
Posts: 67303
Joined: Sat Feb 07, 2009 10:11 am

Please be positive and constructive with your questions and comments.