Voting resources, early voting, and poll worker information - VOTE. ... Adafruit is open and shipping.
0

Adding NeoPixel string to the playground
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

Adding NeoPixel string to the playground

by Spolyoka1 on Sun Jun 21, 2020 2:34 pm

Hello,

I have been trying to add a string of 10-15 pixels to the circuit playground with color picker. I am able to get the circuit playground leds to work with the app and the strand to light up separately when doing strand tests. But have had difficulty getting both simultaneously. Any advice on adjusting the base Cplay color pick sketch to add functionality to a string of pixels as well?

Thanks!

Spolyoka1
 
Posts: 16
Joined: Wed Jun 10, 2020 10:29 pm

Re: Adding NeoPixel string to the playground

by dastels on Sun Jun 21, 2020 6:40 pm

I think you're stuck with controlling them independently. To have both work, you'll need to create a NeoPixel object for each (with their respective pin and number of pixels). Then it's up to your code to coordinate their use.

Dave

dastels
 
Posts: 3519
Joined: Tue Oct 20, 2015 3:22 pm

Re: Adding NeoPixel string to the playground

by Spolyoka1 on Mon Jun 22, 2020 1:08 pm

Thanks for the reply. Is there anything I could pull from the existing neo pixel sketches to create that item. I think I have gotten close by copying over the beginning of the strand test which does create the string as an object (or it compiles with no errors). From there should I just copy the loop that illuminates the circuit playground and change the object? When i have tried this it says there is no scope defined. Appreciate the help!

Spolyoka1
 
Posts: 16
Joined: Wed Jun 10, 2020 10:29 pm

Re: Adding NeoPixel string to the playground

by dastels on Mon Jun 22, 2020 2:35 pm

Which language are you using?

Dave

dastels
 
Posts: 3519
Joined: Tue Oct 20, 2015 3:22 pm

Re: Adding NeoPixel string to the playground

by Spolyoka1 on Mon Jun 22, 2020 2:50 pm

I am using the Cplay Color Picker sketch in Arduino that I found in the Bluefruit Library provided here. https://github.com/adafruit/Adafruit_BluefruitLE_nRF51

It complies and loads perfectly and I can use the Adafruit app to control the pixels on the board.

Spolyoka1
 
Posts: 16
Joined: Wed Jun 10, 2020 10:29 pm

Re: Adding NeoPixel string to the playground

by dastels on Mon Jun 22, 2020 3:13 pm

OK, and you're using a CircuitPlayground Bluefruit?

dastels
 
Posts: 3519
Joined: Tue Oct 20, 2015 3:22 pm

Re: Adding NeoPixel string to the playground

by Spolyoka1 on Mon Jun 22, 2020 11:01 pm

So I’ve been trying with the circuit playground classic with the flora Bluefruit wired in and that works. Just got the circuit playground express with bluefruit in the mail so hoping to use that for my final project but was using the classic as practice.

Spolyoka1
 
Posts: 16
Joined: Wed Jun 10, 2020 10:29 pm

Re: Adding NeoPixel string to the playground

by dastels on Tue Jun 23, 2020 9:19 am

Ah, got it. FYI, there are 3 distinct models: Classic, Express, and Bluefruit. Very similar sensors and such and the library does a good job of abstracting away the differences. I don't expect you'll run into anything when you switch.

The strand test should be a good base to work from. I don't recall seeing anything that coordinates two strips. But it's a matter of creating 2 NeoPixel objects. One is buried in the CircuitPlayground library as I recall, so you'll have to create the second in your code, giving it the pin and number of pixels in the external strip.

Dave

dastels
 
Posts: 3519
Joined: Tue Oct 20, 2015 3:22 pm

Re: Adding NeoPixel string to the playground

by Spolyoka1 on Tue Jun 23, 2020 7:19 pm

Alrighty, so first thanks again for the help. I have added the below code at the top with the other Defined items


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

Then I copied this from the strand test to try and create the strand as an object.


Code: Select all | TOGGLE FULL SIZE
// 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 20

// 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_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)

Once I get to that point how should I adjust the below code to have it light up both the onboard Neo Pixels and the strand.


Code: Select all | TOGGLE FULL SIZE
// Last selected color.
uint8_t currentRed, currentGreen, currentBlue;

// Light up a chain of 10 pixels starting at offset global variable value.
void lightPixels(uint8_t red, uint8_t green, uint8_t blue, int offset) {
  CircuitPlayground.strip.clear();
  for (int i = offset; i < offset+NUMPIXELS; ++i) {
    if ((i >= 0) && (i < NUMPIXELS)) {
      CircuitPlayground.strip.setPixelColor(i, red, green, blue);
    }
  }
  CircuitPlayground.strip.show();
}



Thanks!

Spolyoka1
 
Posts: 16
Joined: Wed Jun 10, 2020 10:29 pm

Re: Adding NeoPixel string to the playground

by dastels on Tue Jun 23, 2020 10:40 pm

You need to add another loop to lightPixels for the external strip. Something like:

Code: Select all | TOGGLE FULL SIZE
 
  strip.clear();
  for (int i = offset; i < offset+LED_COUNT; ++i) {
    if ((i >= 0) && (i < LED_COUNT)) {
      strip.setPixelColor(i, red, green, blue);
    }
  }
  strip.show();


Use CircuitPlayground.strip to work with the onboard pixels and strip to work with the external ones.

Dave

dastels
 
Posts: 3519
Joined: Tue Oct 20, 2015 3:22 pm

Re: Adding NeoPixel string to the playground

by Spolyoka1 on Wed Jun 24, 2020 11:57 pm

So i added that code above after the circuit playground code I was trying to duplicate and I got the below error message. Was able to get it to compile prior to adding that new code to light the strand.

Arduino: 1.8.13 (Windows Store 1.8.39.0) (Windows 10), Board: "Adafruit Circuit Playground"





















cplay_neopixel_picker_4:109:3: error: 'strip' does not name a type

strip.clear();

^~~~~

cplay_neopixel_picker_4:110:3: error: expected unqualified-id before 'for'

for (int i = offset; i < offset+LED_COUNT; ++i) {

^~~

cplay_neopixel_picker_4:110:24: error: 'i' does not name a type

for (int i = offset; i < offset+LED_COUNT; ++i) {

^

cplay_neopixel_picker_4:110:46: error: expected unqualified-id before '++' token

for (int i = offset; i < offset+LED_COUNT; ++i) {

^~

cplay_neopixel_picker_4:115:3: error: 'strip' does not name a type

strip.show();

^~~~~

exit status 1

'strip' does not name a type



This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.


Thanks!

Spolyoka1
 
Posts: 16
Joined: Wed Jun 10, 2020 10:29 pm

Re: Adding NeoPixel string to the playground

by dastels on Thu Jun 25, 2020 9:56 am

Hmm...

Can you post the entire code file as it is? Something is a little off.

Dave

dastels
 
Posts: 3519
Joined: Tue Oct 20, 2015 3:22 pm

Re: Adding NeoPixel string to the playground

by Spolyoka1 on Thu Jun 25, 2020 2:47 pm

Of Course! Thank you!

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

#include "Adafruit_BLE.h"
#include "Adafruit_BluefruitLE_SPI.h"
#include "Adafruit_BluefruitLE_UART.h"
#include "BluefruitConfig.h"

#include <Adafruit_NeoPixel.h>

#if SOFTWARE_SERIAL_AVAILABLE
  #include <SoftwareSerial.h>
#endif

#include <Adafruit_CircuitPlayground.h>

// Configuration (you don't need to change these, but can!):
#define FACTORYRESET_ENABLE     1   // Set to 1 to factory reset the Bluefruit LE
                                    // module.  In general this is a smart idea to
                                    // put the module into a known good state.
                                    // A value of 1 means perform a factory reset
                                    // on start, and 0 means no factory reset.

#define NUMPIXELS               10  // Number of NeoPixels on the board.

#define BRIGHTNESS              255 // NeoPixel brightness (0...255, low to max brightness)

/*=========================================================================*/

// 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 20

// 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_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)

// Create the bluefruit object, for Circuit Playground this needs to be
// hardware serial.
Adafruit_BluefruitLE_UART ble(BLUEFRUIT_HWSERIAL_NAME, BLUEFRUIT_UART_MODE_PIN);

// A small helper
void error(const __FlashStringHelper*err) {
  Serial.println(err);
  while (1);
}

// function prototypes over in packetparser.cpp
uint8_t readPacket(Adafruit_BLE *ble, uint16_t timeout);
float parsefloat(uint8_t *buffer);
void printHex(const uint8_t * data, const uint32_t numBytes);

// the packet buffer
extern uint8_t packetbuffer[];

// Offset that controls which pixels are turned on/off.
// Pressing the left/right controller button moves this offset
// up/down and 'slides' the chain of 10 pixels around.
int currentOffset = 0;

// Last selected color.
uint8_t currentRed, currentGreen, currentBlue;

// Light up a chain of 10 pixels starting at offset global variable value.
void lightPixels(uint8_t red, uint8_t green, uint8_t blue, int offset) {
  CircuitPlayground.strip.clear();
  for (int i = offset; i < offset+NUMPIXELS; ++i) {
    if ((i >= 0) && (i < NUMPIXELS)) {
      CircuitPlayground.strip.setPixelColor(i, red, green, blue);
    }
  }
  CircuitPlayground.strip.show();
}

  strip.clear();
  for (int i = offset; i < offset+LED_COUNT; ++i) {
    if ((i >= 0) && (i < LED_COUNT)) {
      strip.setPixelColor(i, red, green, blue);
    }
  }
  strip.show();
void setup() {


  // Wait for serial port before starting.  Not required but helps with debugging.
  //while (!Serial);
  //delay(500);
 
  // Initialize Circuit Playground library and turn off the Pixels.
  CircuitPlayground.begin(BRIGHTNESS);
  CircuitPlayground.clearPixels();
 

  // Initialize serial output.
  Serial.begin(115200);
  Serial.println(F("Adafruit Circuit Playground Bluefruit Neopixel Color Picker Example"));
  Serial.println(F("-------------------------------------------------------------------"));

  // Initialise the module
  Serial.print(F("Initialising the Bluefruit LE module: "));

  if ( !ble.begin(VERBOSE_MODE) )
  {
    error(F("Couldn't find Bluefruit, make sure it's in DATA mode & check wiring...."));
  }
  Serial.println( F("OK!") );

  if ( FACTORYRESET_ENABLE )
  {
    // Perform a factory reset to make sure everything is in a known state
    Serial.println(F("Performing a factory reset: "));
    if (!ble.factoryReset()) {
      Serial.println(F("Couldn't factory reset, making another attempt..."));
      delay(1000);
      if (!ble.factoryReset()) {
        error(F("Couldn't factory reset!"));
      }
    }
  }

  // Disable command echo from Bluefruit
  ble.echo(false);

  Serial.println("Requesting Bluefruit info:");
  // Print Bluefruit information
  ble.info();

  // Change advertised name to Circuit_Playground_BLE
  ble.println("AT+GAPDEVNAME=CPlay_BLE");
  delay(100);
  ble.println("ATZ");
  delay(100);

  Serial.println(F("Please use Adafruit Bluefruit LE app to connect in Controller mode"));
  Serial.println(F("Then activate/use the sensors, color picker, game controller, etc!"));
  Serial.println();

  ble.verbose(false);  // debug info is a little annoying after this point!

  // Wait for connection
  while (! ble.isConnected()) {
      delay(500);
  }

  Serial.println(F("***********************"));

  // Set Bluefruit to DATA mode
  Serial.println( F("Switching to DATA mode!") );
  ble.setMode(BLUEFRUIT_MODE_DATA);

  Serial.println(F("***********************"));

}

void loop()
{
  /* Wait for new data to arrive */
  uint8_t len = readPacket(&ble, BLE_READPACKET_TIMEOUT);
  if (len == 0) {
    return;
  }

  /* Got a packet! */
  //printHex(packetbuffer, len);

  // Color
  if (packetbuffer[1] == 'C') {
    // Parse out the red, green, blue values and save them.
    uint8_t red = packetbuffer[2];
    uint8_t green = packetbuffer[3];
    uint8_t blue = packetbuffer[4];
    // Change the color.
    currentRed = red;
    currentGreen = green;
    currentBlue = blue;
  }

  // Left/right adjust the offset that turns on/off pixels.
  if (packetbuffer[1] == 'B') {
    if (memcmp(packetbuffer, "!B705", 5) == 0) {
      // Left button release.
      currentOffset -= 1;
    }
    else if (memcmp(packetbuffer, "!B804", 5) == 0) {
      // Right button release.
      currentOffset += 1;
    }
    currentOffset = constrain(currentOffset, -NUMPIXELS, NUMPIXELS);
  }

  // Update the pixels again since either the color or offset position
  // must have changed above.
  lightPixels(currentRed, currentGreen, currentBlue, currentOffset);
}

Spolyoka1
 
Posts: 16
Joined: Wed Jun 10, 2020 10:29 pm

Re: Adding NeoPixel string to the playground

by dastels on Thu Jun 25, 2020 3:50 pm

Ah. The code you added for strip has to be inside the lightPixels function.

dastels
 
Posts: 3519
Joined: Tue Oct 20, 2015 3:22 pm

Re: Adding NeoPixel string to the playground

by Spolyoka1 on Thu Jun 25, 2020 4:55 pm

So I think I understood what you meant. I moved the Strip code inside the {} for the light pixels function. It came out like this.

Code: Select all | TOGGLE FULL SIZE
// Last selected color.
uint8_t currentRed, currentGreen, currentBlue;

// Light up a chain of 10 pixels starting at offset global variable value.
void lightPixels(uint8_t red, uint8_t green, uint8_t blue, int offset) {
  CircuitPlayground.strip.clear();
  for (int i = offset; i < offset+NUMPIXELS; ++i) {
    if ((i >= 0) && (i < NUMPIXELS)) {
      CircuitPlayground.strip.setPixelColor(i, red, green, blue);
    }
  }
  CircuitPlayground.strip.show();
  strip.clear();
  for (int i = offset; i < offset+LED_COUNT; ++i) {
    if ((i >= 0) && (i < LED_COUNT)) {
      strip.setPixelColor(i, red, green, blue);
    }
  }
  strip.show();
}


Then I get an error that says error Symbol "HeadA" already defined, all the way through "HeadF". Appreciate it!

Spolyoka1
 
Posts: 16
Joined: Wed Jun 10, 2020 10:29 pm

Please be positive and constructive with your questions and comments.