Dearest ninjas,
We are working on an interactive installation project where we are using LED strips inside transparent human sculptures to highlight 7 chakras through different light changes. At the moment, we are having some difficulties to make vvvv (RS232 node) “fluently” communicate through serial port (via Arduino) with LEDs APA102 (“DotStar”).
We tried many things with the patch, code and different Arduino pins, but still didn't manage to properly send packets of values from vvvv > Arduino Code (buffer) > Array of 360 LEDs (6 strips, 60 LEDs each, serially connected with 4 wires GND, DATA, CLOCK & 5V).
DATA wire is currently connected to A9 (analog) pin and CLOCK to A10 (analog) pin on Arduino Mega 2560.
Screenshot of vvvv patch:
Arduino code, version 1:
// Awakening Circle ~ Interactive Visionary Installation
// vulkai studio
// https://github.com/sivinjski/AwakeningCircle
// This Arduino code should understand packets of values from vvvv serial port and send them
// via Arduino Mega 2560 board, DATA Pin A9 (analog), CLOCK Pin A10 (analog)
// to an array of 360 [APA102] LEDs, 6 strips x 60 pixels.
#include <FastLED.h>
#define NUM_LEDS 360
#define DATA_PIN A9 // Analog 9
#define CLOCK_PIN A10 // Analog 10
CRGB leds[NUM_LEDS]; // Array for RGB LEDs
int LEDValues[NUM_LEDS][3]; // 2D array (360,3) to store RGB values for every LED
char packetBuffer[1080]; // Buffer to store incoming string from vvvv
void setup()
{
FastLED.addLeds<APA102, DATA_PIN, CLOCK_PIN>(leds, NUM_LEDS); // initiate RGB LED strip
Serial.begin(9600); // start Serial Communication
}
void loop() {
if (Serial.available() > 0) // Check if data is coming in through serial
{
Serial.readBytes(packetBuffer,1080);// 1080 is the packetsize = 1080 values + '<' and '>'
if( packetBuffer[0]=='<' && packetBuffer[1080-1]=='>') // if first and last chars of string are '<' and '>' we know the whole package has arrived
{
unsigned char CleanBuffer [1080-2]; // new Array to store string without starting and closing tag
memcpy(CleanBuffer,packetBuffer+1,1080-2); // copies the content from packetBuffer to CleanBuffer excluding the first and last element
int index=0; // helper to point to a specific data point
for(int i=0; i<NUM_LEDS; i++) // nested for loop to run through two dimensional array
{
for(int j=0; j<3; j++)
{
LEDValues[i][j] = CleanBuffer[index]; // store values of CleanBuffer in 2D Array
index++; // increase index to get next data point in next run through the loop
}
}
}
}
for(int i=0; i<NUM_LEDS; i++) // for loop to push values to LEDs
{
leds[i] = CRGB(LEDValues[i][0],LEDValues[i][1],LEDValues[i][2]);
}
FastLED.show(); // updated RGB LED strip
delay(5);
}
Arduino code, version 2 (still needs 'some' work):
// Awakening Circle ~ Interactive Visionary Installation
// vulkai studio
// https://github.com/sivinjski/AwakeningCircle
// This Arduino code should understand packets of values from vvvv serial port and send them
// via Arduino Mega 2560 board, DATA Pin A9 (analog), CLOCK Pin A10 (analog)
// to an array of 360 [APA102] LEDs, 6 strips x 60 pixels.
// In this second version (SendSerial2Arduno_v2) there could be some mess between
// FastLED.h and Adafrit_DotStar.h libraries: such as NUM_LEDS vs. NUMPIXELS, etc. etc.
#include <FastLED.h>
#include <SPI.h>
#include <Adafruit_DotStar.h> // Library for APA102, labeled by Adafruit as DotStar
// https://github.com/adafruit/Adafruit_DotStar
#define NUM_LEDS 360
//FastLED// #define DATA_PIN A9
//FastLED// #define CLOCK_PIN A10
#define NUMPIXELS 360
#define DATAPIN A9
#define CLOCKPIN A10
CRGB leds[NUM_LEDS]; // Array for RGB LEDs
int LEDValues[NUM_LEDS][3]; // 2D array (360,3) to store RGB values for every LED
char packetBuffer[1080]; // Buffer to store incoming string from vvvv
void setup()
{
Adafruit_DotStar strip = Adafruit_DotStar(NUM_LEDS, DATAPIN, CLOCKPIN, DOTSTAR_BRG);
//// FastLED.addLeds<DOTSTAR, DATA_PIN, CLOCK_PIN>(leds, NUM_LEDS); // initiate RGB LED strip
Serial.begin(9600); // start Serial Communication
}
void loop() {
if (Serial.available() > 0) // Check if data is coming in through serial
{
Serial.readBytes(packetBuffer,1080);// 1080 is the packetsize = 1080 values + '<' and '>'
if( packetBuffer[0]=='<' && packetBuffer[1080-1]=='>') // if first and last chars of string are '<' and '>' we know the whole package has arrived
{
unsigned char CleanBuffer [1080-2]; // new Array to store string without starting and closing tag
memcpy(CleanBuffer,packetBuffer+1,1080-2); // copies the content from packetBuffer to CleanBuffer excluding the first and last element
int index=0; // helper to point to a specific data point
for(int i=0; i<NUM_LEDS; i++) // nested for loop to run through two dimensional array
{
for(int j=0; j<3; j++)
{
LEDValues[i][j] = CleanBuffer[index]; // store values of CleanBuffer in 2D Array
index++; // increase index to get next data point in next run through the loop
}
}
}
}
for(int i=0; i<NUM_LEDS; i++) // for loop to push values to LEDs
{
leds[i] = CRGB(LEDValues[i][0],LEDValues[i][1],LEDValues[i][2]);
}
FastLED.show(); // updated RGB LED strip
delay(5);
}
There is probably something wrong with the Arduino code or the vvvv patch. Maybe we are sending wrong values from vvvv or they are correct but the Arudino code doesn't understand them.
Does anybody have experience with this and is willing to have a quick look at our patch and the code? Any help will be greatly appreciated. Thank you very very much.
If anything is unclear about the hardware or software don't hesitate to ask.
vvvv patch and two versions of Arudino code are attached in this post and are also available here GitHub - sivinjski/AwakeningCircle: Interactive Visionary Installation
- FastLED library GitHub - FastLED/FastLED: The FastLED library for colored LED animation on Arduino. Please direct questions/requests for help to the FastLED Reddit community: http://fastled.io/r We'd like to use github "issues" just for tracking library bugs / enhancements.
- Adafruit_DotStar library GitHub - adafruit/Adafruit_DotStar
AwakeningCircle.zip (743 KB)
SendSerial2Arduino_v1.ino (2 KB)
SendSerial2Arduino_v2.ino (2.49 KB)