Tuesday, 27 October 2020

NeoPixels with Arduino

 For the Prototyping module I'm studying at University of Sussex right now, I'm doing a lot of new things with Arduino which I've never done before. Today's new thing is using a strip of 30 NeoPixel multi-coloured LEDs which I have purchased from Pimorani


These LEDs come in a strip with just three connectors; two for power and one for data.

These are built by Adafruit, and they provide a guide to basic connections on their site.

My strip came with a handy connector fitted to one end, but I also purchased a set of additional connectors. As ti turned out, this was a sensible thing to do.

The circuit for connecting the NeoPixels is relatively simple; and I have added a diagram below

The data line is connected to pin 6 with a series resistor to limit the current. There is also a 1000microFarad capacitor across the +5v and GND leads to avoid power spikes on switch on damaging the LEDs

I plugged my set in and switched it on, but I couldn't get it to work. I wasn't sure if there was a problem with the supply, as some advise to connect the power to another supply from the Arduino.

However, looking closely, I noticed that there was a problem with the pre-soldered connector


Looking closely, I could see that the connector was soldered to the wrong end of the strip. When Ihad used one of my spares to connect the leads to the other end, the test program started working and the LEDs lit up.

The software for the NeoPixels comes from Adafruit. I had in install the Library into the Arduino IDE following the instructions on the Adafruit site. This was easy, and once installed, gave me access to an example test program, "strandtest"

I have edited the strandtest code to just give me a gently changing rainbow of colours, and I have included my code below.

All of this looks really good as it runs, and is going to be a key part of the Prototyping project I'm working on.




// A basic rainbow NeoPixel strip test program.

#include <Adafruit_NeoPixel.h>

// Which pin on the Arduino is connected to the NeoPixels?
// On a Trinket or Gemma we suggest changing this to 1:
#define LED_PIN    6

// How many NeoPixels are attached to the Arduino?
#define LED_COUNT 30

// Declare our NeoPixel strip object:
Adafruit_NeoPixel strip(LED_COUNT, LED_PIN, NEO_GRB + NEO_KHZ800);
// Argument 1 = Number of pixels in NeoPixel strip
// Argument 2 = Arduino pin number (most are valid)
// Argument 3 = Pixel type flags, add together as needed:
//   NEO_KHZ800  800 KHz bitstream (most NeoPixel products w/WS2812 LEDs)
//   NEO_GRB     Pixels are wired for GRB bitstream (most NeoPixel products)


// setup() function -- runs once at startup --------------------------------

void setup() {
    strip.begin();           // INITIALIZE NeoPixel strip object (REQUIRED)
  strip.show();            // Turn OFF all pixels ASAP
  strip.setBrightness(50); // Set BRIGHTNESS to about 1/5 (max = 255)
}


// loop() function -- runs repeatedly as long as board is on ---------------

void loop() {
  
  rainbow(10);             // Flowing rainbow cycle along the whole strip
  
}



// Rainbow cycle along whole strip. Pass delay time (in ms) between frames.
void rainbow(int wait) {
  // Hue of first pixel runs 5 complete loops through the color wheel.
  // Color wheel has a range of 65536 but it's OK if we roll over, so
  // just count from 0 to 5*65536. Adding 256 to firstPixelHue each time
  // means we'll make 5*65536/256 = 1280 passes through this outer loop:
  for(long firstPixelHue = 0; firstPixelHue < 5*65536; firstPixelHue += 256) {
    for(int i=0; i<strip.numPixels(); i++) { // For each pixel in strip...
      // Offset pixel hue by an amount to make one full revolution of the
      // color wheel (range of 65536) along the length of the strip
      // (strip.numPixels() steps):
      int pixelHue = firstPixelHue + (i * 65536L / strip.numPixels());
      // strip.ColorHSV() can take 1 or 3 arguments: a hue (0 to 65535) or
      // optionally add saturation and value (brightness) (each 0 to 255).
      // Here we're using just the single-argument hue variant. The result
      // is passed through strip.gamma32() to provide 'truer' colors
      // before assigning to each pixel:
      strip.setPixelColor(i, strip.gamma32(strip.ColorHSV(pixelHue)));
    }
    strip.show(); // Update strip with new contents
    delay(wait);  // Pause for a moment
  }
}


Here's a link to the Tinkercad model I created of the same design

CH32V203 Big Round Button

Having successfully uploaded the Blink code to the  CH32V203 , the next task is to try the HID button demo. The circuit I’m using has two bu...