Arduino - Neopixel control via cayenne


#1

I am looking for an example of code that I can use manage a neo pixel strip which can be activated via wifi/cayenne … The following code manages neopixel via a “uno” - I am looking to have the ability to trigger this code via the cayene

… thanks

#include "FastLED.h"
// How many leds in your strip?
#define NUM_LEDS 64 
#define DATA_PIN 7
#define CLOCK_PIN 13
// Define the array of leds
CRGB leds[NUM_LEDS];

void setup() { 
	Serial.begin(57600);
	Serial.println("resetting");
	LEDS.addLeds<WS2812,DATA_PIN,RGB>(leds,NUM_LEDS);
	LEDS.setBrightness(84);
}

void fadeall() { for(int i = 0; i < NUM_LEDS; i++) { leds[i].nscale8(250); } }

void loop() { 
	static uint8_t hue = 0;
	Serial.print("x");
	// First slide the led in one direction
	for(int i = 0; i < NUM_LEDS; i++) {
		// Set the i'th led to red 
		leds[i] = CHSV(hue++, 255, 255);
		// Show the leds
		FastLED.show(); 
		// now that we've shown the leds, reset the i'th led to black
		// leds[i] = CRGB::Black;
		fadeall();
		// Wait a little bit before we loop around and do it again
		delay(10);
	}
	Serial.print("x");

	// Now go in the other direction.  
	for(int i = (NUM_LEDS)-1; i >= 0; i--) {
		// Set the i'th led to red 
		leds[i] = CHSV(hue++, 255, 255);
		// Show the leds
		FastLED.show();
		// now that we've shown the leds, reset the i'th led to black
		// leds[i] = CRGB::Black;
		fadeall();
		// Wait a little bit before we loop around and do it again
		delay(10);
	}
}

#2

@cewmjtm,

Do you have a wifi or ethernet shield for your Uno or do you have an “Uno” with an integrated networking shield?

You can also connect through your USB connection using CayenneSerial.h as shown here. Arduino USB help

Cheers,

Craig


#3

wifi 101 board … I have made connection with Cayenne - no problem …


#4

Here is a copy of my current code:

/*
Cayenne WiFi Shield 101 Example

This sketch connects to the Cayenne server using an Arduino WiFi Shield 101
and runs the main communication loop.

The Cayenne Library is required to run this sketch. If you have not already done so you can install it from the Arduino IDE Library Manager.

Steps:
1. Install the WiFi101 library (https://github.com/arduino-libraries/WiFi101) from the Arduino Library Manager if you have not done so already.
2. Set the token variable to match the Arduino token from the Dashboard.
3. Set the network name and password.
4. Compile and upload this sketch.

For Cayenne Dashboard widgets using digital or analog pins this sketch will automatically
send data on those pins to the Cayenne server. If the widgets use Virtual Pins, data
should be sent to those pins using virtualWrites. Examples for sending and receiving
Virtual Pin data are under the Basics folder.
*/

//#define CAYENNE_DEBUG         // Uncomment to show debug messages
#define CAYENNE_PRINT Serial  // Comment this out to disable prints and save space
#include <CayenneWiFi101.h>

// Cayenne authentication token. This should be obtained from the Cayenne Dashboard.
char token[] = "gmbf0vxpaq";
// Your network name and password.
char ssid[] = "xxxxxxxxxxxx";
char password[] = "zzzzzzzzzzzzz";

void setup()
{
	Serial.begin(9600);
	Cayenne.begin(token, ssid, password);
}

void loop()
{
	Cayenne.run();
}

#5

Try this :slight_smile:

//#define CAYENNE_DEBUG         // Uncomment to show debug messages
#define CAYENNE_PRINT Serial  // Comment this out to disable prints and save space
#include CayenneWiFi101.h;
#include "FastLED.h"
// How many leds in your strip?
#define NUM_LEDS 64 
#define DATA_PIN 7
#define CLOCK_PIN 13
// Define the array of leds
CRGB leds[NUM_LEDS];

// Cayenne authentication token. This should be obtained from the Cayenne Dashboard.
char token[] = "gmbf0vxpaq";
// Your network name and password.
char ssid[] = "xxxxxxxxxxxx";
char password[] = "zzzzzzzzzzzzz";

void setup()
{
	Serial.begin(9600);
    Serial.println("resetting");
	LEDS.addLeds<WS2812,DATA_PIN,RGB>(leds,NUM_LEDS);
	LEDS.setBrightness(84);
	Cayenne.begin(token, ssid, password);
}

void loop()
{
	Cayenne.run();
}

void fadeall() 
{
    for(int i = 0; i < NUM_LEDS; i++) 
    {
         leds[i].nscale8(250); 
    }
}

//Create a pushbutton and connect to virtual channel 1
//Every time it is toggled, this function will be called
VIRTUAL_OUT(1)
{
	static uint8_t hue = 0;
	Serial.print("x");
	// First slide the led in one direction
	for(int i = 0; i < NUM_LEDS; i++) 
    {
		// Set the i'th led to red 
		leds[i] = CHSV(hue++, 255, 255);
		// Show the leds
		FastLED.show(); 
		// now that we've shown the leds, reset the i'th led to black
		// leds[i] = CRGB::Black;
		fadeall();
		// Wait a little bit before we loop around and do it again
		delay(10);
	}
	Serial.print("x");

	    // Now go in the other direction.  
    for(int i = (NUM_LEDS)-1; i >= 0; i--) 
    {
		// Set the i'th led to red 
		leds[i] = CHSV(hue++, 255, 255);
		// Show the leds
		FastLED.show();
		// now that we've shown the leds, reset the i'th led to black
		// leds[i] = CRGB::Black;
		fadeall();
		// Wait a little bit before we loop around and do it again
		delay(10);
    }
}

Cheers,

Craig