You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Need help to change the code of SW2801 chipset to SW2812 clockless chipset #39
Your pasted code is nearly impossible to read because of a bunch of control codes - any chance you can clean it up?
From what I can make out, however, this is code that uses the first version of the FastSPI_LED library, which is no longer supported.
Also - there is no SW2812 chipset - are you thinking of the WS2812? It is the same as the WS2811 chipset - and the code that you posted to the g+ group was correct as far as talking to the leds goes - which is why I was focusing on (assuming you had power, data, ground wired correctly) the communication between boblight and the arduino and the arduino code.
Do you think this code of the 2811 attached with this message can is up to date and compatible with my project?
Best regards,
Nicholas
On Friday, March 14, 2014 10:49:12 PM, Daniel Garcia [email protected] wrote:
Your pasted code is nearly impossible to read because of a bunch of control codes - any chance you can clean it up?
From what I can make out, however, this is code that uses the first version of the FastSPI_LED library, which is no longer supported.
Also - there is no SW2812 chipset - are you thinking of the WS2812? It is the same as the WS2811 chipset - and the code that you posted to the g+ group was correct as far as talking to the leds goes - which is why I was focusing on (assuming you had power, data, ground wired correctly) the communication between boblight and the arduino and the arduino code.
—
Reply to this email directly or view it on GitHub.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
Required Connections
pin 2: LED Strip #1 OctoWS2811 drives 8 LED Strips.
pin 14: LED strip #2 All 8 are the same length.
pin 7: LED strip #3
pin 8: LED strip #4 A 100 ohm resistor should used
pin 6: LED strip #5 between each Teensy pin and the
pin 20: LED strip #6 wire to the LED strip, to minimize
pin 21: LED strip #7 high frequency ringining & noise.
pin 5: LED strip #8
pin 15 & 16 - Connect together, but do not use
pin 4 - Do not use
pin 3 - Do not use as PWM. Normal use is ok.
*/
#include <OctoWS2811.h>
const int ledsPerStrip = 60;
DMAMEM int displayMemory[ledsPerStrip_6];
int drawingMemory[ledsPerStrip_6];
void loop() {
// make sure the serial port is connected
if (!Serial) {
while (!Serial) ; // wait for Processing's Adalight.pde
delay(250);
Serial.print("Ada\n");
}
// receive the Adalight header
int count = receiveAdalightHeader();
// if no header, shut off all the lights
if (count <= 0) {
for (int i=0; i < ledsPerStrip*8; i++) {
leds.setPixel(i, 0);
}
leds.show();
// if we did get the header, try to receive the LED data
} else {
int numLed = count;
// if Adalight sends too many LEDs, only receive the ones we can use
if (numLed > ledsPerStrip_8) numLed = ledsPerStrip_8;
// receive the incoming LED data
for (int i=0; i < numLed; i++) {
byte rgb[3];
int n = Serial.readBytes((char *)rgb, 3);
if (n != 3) return; // error receiving LED data
leds.setPixel(i, rgb[2], rgb[1], rgb[0]);
}
// now update the display
leds.show();
// receive any extra unusable data
while (count > numLed) {
byte rgb[3];
Serial.readBytes((char *)rgb, 3);
count = count - 1;
}
}
}
int receiveAdalightHeader() {
int b;
int state=0;
int count;
elapsedMillis msec=0;
// wait for a character
while (1) {
b = Serial.read();
if (b >= 0) {
msec = 0;
break;
}
if (msec > 15000) return 0; // timeout
if (!Serial) return 0; // serial disconnected
}
// parse the 6 character header
switch (state) {
case 0:
if (b == 'A') state = 1;
break;
case 1:
if (b == 'd') state = 2;
else state = 0;
break;
case 2:
if (b == 'a') state = 3;
else state = 0;
break;
case 3:
count = b << 8;
state = 4;
break;
case 4:
count = count | b;
state = 5;
break;
case 5:
if (b == ((count & 255) | ((count >> 8) & 255) | 0x55)) return count;
state = 0;
}
}
#define NUM_LEDS 60 // Max LED count
#define LED_PIN 12 // arduino output pin
#define GROUND_PIN 10
#define BRIGHTNESS 96 // maximum brightness
#define SPEED 115200 // virtual serial port speed, must be the same in boblight_config
// A 'magic word' (along with LED count & checksum) precedes each block
// of LED data; this assists the microcontroller in syncing up with the
// host-side software and properly issuing the latch (host I/O is
// likely buffered, making usleep() unreliable for latch). You may see
// an initial glitchy frame or two until the two come into alignment.
// The magic word can be whatever sequence you like, but each character
// should be unique, and frequent pixel values like 0 and 255 are
// avoided -- fewer false positives. The host software will need to
// generate a compatible header: immediately following the magic word
// are three bytes: a 16-bit count of the number of LEDs (high byte
// first) followed by a simple checksum value (high byte XOR low byte
// XOR 0x55). LED data follows, 3 bytes per LED, in order R, G, B,
// where 0 = off and 255 = max brightness.
// If no serial data is received for a while, the LEDs are shut off
// automatically. This avoids the annoying "stuck pixel" look when
// quitting LED display programs on the host computer.
static const unsigned long serialTimeout = 150000; // 150 seconds
// Dirty trick: the circular buffer for serial data is 256 bytes,
// and the "in" and "out" indices are unsigned 8-bit types -- this
// much simplifies the cases where in/out need to "wrap around" the
// beginning/end of the buffer. Otherwise there'd be a ton of bit-
// masking and/or conditional code every time one of these indices
// needs to change, slowing things down tremendously.
uint8_t
buffer[256],
indexIn = 0,
indexOut = 0,
mode = MODE_HEADER,
hi, lo, chk, i, spiFlag;
int16_t
bytesBuffered = 0,
hold = 0,
c;
int32_t
bytesRemaining;
unsigned long
startTime,
lastByteTime,
lastAckTime,
t;
int32_t outPos = 0;
Serial.begin(SPEED); // Teensy/32u4 disregards baud rate; is OK!
// loop() is avoided as even that small bit of function overhead
// has a measurable impact on this code's overall throughput.
for(;;) {
// Implementation is a simple finite-state machine.
// Regardless of mode, check for serial input each time:
t = millis();
if((bytesBuffered < 256) && ((c = Serial.read()) >= 0)) {
buffer[indexIn++] = c;
bytesBuffered++;
lastByteTime = lastAckTime = t; // Reset timeout counters
} else {
// No data received. If this persists, send an ACK packet
// to host once every second to alert it to our presence.
if((t - lastAckTime) > 1000) {
Serial.print("Ada\n"); // Send ACK string to host
lastAckTime = t; // Reset counter
}
// If no data received for an extended time, turn off all LEDs.
if((t - lastByteTime) > serialTimeout) {
memset(leds, 0, NUM_LEDS * sizeof(struct CRGB)); //filling Led array by zeroes
FastLED.show();
lastByteTime = t; // Reset counter
}
}
switch(mode) {
case MODE_HEADER:
// In header-seeking mode. Is there enough data to check?
if(bytesBuffered >= HEADERSIZE) {
// Indeed. Check for a 'magic word' match.
for(i=0; (i<MAGICSIZE) && (buffer[indexOut++] == magic[i++]););
if(i == MAGICSIZE) {
// Magic word matches. Now how about the checksum?
hi = buffer[indexOut++];
lo = buffer[indexOut++];
chk = buffer[indexOut++];
if(chk == (hi ^ lo ^ 0x55)) {
// Checksum looks valid. Get 16-bit LED count, add 1
// (# LEDs is always > 0) and multiply by 3 for R,G,B.
bytesRemaining = 3L * (256L * (long)hi + (long)lo + 1L);
bytesBuffered -= 3;
outPos = 0;
memset(leds, 0, NUM_LEDS * sizeof(struct CRGB));
mode = MODE_DATA; // Proceed to latch wait mode
} else {
// Checksum didn't match; search resumes after magic word.
indexOut -= 3; // Rewind
}
} // else no header match. Resume at first mismatched byte.
bytesBuffered -= i;
}
break;
case MODE_DATA:
if(bytesRemaining > 0) {
if(bytesBuffered > 0) {
if (outPos < sizeof(leds))
ledsRaw[outPos++] = buffer[indexOut++]; // Issue next byte
bytesBuffered--;
bytesRemaining--;
}
// If serial buffer is threatening to underrun, start
// introducing progressively longer pauses to allow more
// data to arrive (up to a point).
} else {
// End of data -- issue latch:
startTime = micros();
mode = MODE_HEADER; // Begin next header search
FastLED.show();
}
} // end switch
} // end for(;;)
}
void loop()
{
// Not used. See note in setup() function.
}
This is just the code that you started off your g+ post with - there is nothing new/different that I would say here about it than I said over there.
This is not really a valid issue - I'm trying to use issues to deal with bugs in the library and/or new feature requests, not support or "help me port my code" - that's what the g+ community is for.
At this point, I will say again what I said in the g+ community - you need to find someone who uses/has used boblight and/or adalight, and get help from them.
Activity
focalintent commentedon Mar 15, 2014
Your pasted code is nearly impossible to read because of a bunch of control codes - any chance you can clean it up?
From what I can make out, however, this is code that uses the first version of the FastSPI_LED library, which is no longer supported.
Also - there is no SW2812 chipset - are you thinking of the WS2812? It is the same as the WS2811 chipset - and the code that you posted to the g+ group was correct as far as talking to the leds goes - which is why I was focusing on (assuming you had power, data, ground wired correctly) the communication between boblight and the arduino and the arduino code.
sccwireless commentedon Mar 15, 2014
Good morning Daniel,
Thank you very much for your precious help.
Do you think this code of the 2811 attached with this message can is up to date and compatible with my project?
Best regards,
Nicholas
On Friday, March 14, 2014 10:49:12 PM, Daniel Garcia [email protected] wrote:
Your pasted code is nearly impossible to read because of a bunch of control codes - any chance you can clean it up?
From what I can make out, however, this is code that uses the first version of the FastSPI_LED library, which is no longer supported.
Also - there is no SW2812 chipset - are you thinking of the WS2812? It is the same as the WS2811 chipset - and the code that you posted to the g+ group was correct as far as talking to the leds goes - which is why I was focusing on (assuming you had power, data, ground wired correctly) the communication between boblight and the arduino and the arduino code.
—
Reply to this email directly or view it on GitHub.
sccwireless commentedon Mar 15, 2014
revision: OctoWS2811 requires the DMA (Direct Memory Access) engine which is available only in Teensy 3.0 and Teensy 3.1.
So the code below is not valid for me. Since I use an Arduino Uno r3... Sorry for the confusion everybody!
/* OctoWS2811 Adalight.ino - Receive Adalight and display on WS2811 LEDs
http://www.pjrc.com/teensy/td_libs_OctoWS2811.html
Copyright (c) 2013 Paul Stoffregen, PJRC.COM, LLC
Required Connections
*/
#include <OctoWS2811.h>
const int ledsPerStrip = 60;
DMAMEM int displayMemory[ledsPerStrip_6];
int drawingMemory[ledsPerStrip_6];
const int config = WS2811_GRB | WS2811_800kHz;
OctoWS2811 leds(ledsPerStrip, displayMemory, drawingMemory, config);
void setup() {
Serial.begin(115200);
Serial.setTimeout(2000);
leds.begin();
}
void loop() {
// make sure the serial port is connected
if (!Serial) {
while (!Serial) ; // wait for Processing's Adalight.pde
delay(250);
Serial.print("Ada\n");
}
// receive the Adalight header
int count = receiveAdalightHeader();
// if no header, shut off all the lights
if (count <= 0) {
for (int i=0; i < ledsPerStrip*8; i++) {
leds.setPixel(i, 0);
}
leds.show();
// if we did get the header, try to receive the LED data
} else {
int numLed = count;
// if Adalight sends too many LEDs, only receive the ones we can use
if (numLed > ledsPerStrip_8) numLed = ledsPerStrip_8;
// receive the incoming LED data
for (int i=0; i < numLed; i++) {
byte rgb[3];
int n = Serial.readBytes((char *)rgb, 3);
if (n != 3) return; // error receiving LED data
leds.setPixel(i, rgb[2], rgb[1], rgb[0]);
}
// now update the display
leds.show();
// receive any extra unusable data
while (count > numLed) {
byte rgb[3];
Serial.readBytes((char *)rgb, 3);
count = count - 1;
}
}
}
int receiveAdalightHeader() {
int b;
int state=0;
int count;
elapsedMillis msec=0;
// wait for a character
while (1) {
b = Serial.read();
if (b >= 0) {
msec = 0;
break;
}
if (msec > 15000) return 0; // timeout
if (!Serial) return 0; // serial disconnected
}
// parse the 6 character header
switch (state) {
case 0:
if (b == 'A') state = 1;
break;
case 1:
if (b == 'd') state = 2;
else state = 0;
break;
case 2:
if (b == 'a') state = 3;
else state = 0;
break;
case 3:
count = b << 8;
state = 4;
break;
case 4:
count = count | b;
state = 5;
break;
case 5:
if (b == ((count & 255) | ((count >> 8) & 255) | 0x55)) return count;
state = 0;
}
}
sccwireless commentedon Mar 15, 2014
Here is another code definition or description of that code. But not sure if this is good:
// Slightly modified Adalight protocol implementation that uses FastLED
// library (http://fastled.io) for driving WS2811/WS2812 led stripe
// Was tested only with Prismatik software from Lightpack project
#include "FastLED.h"
#define NUM_LEDS 60 // Max LED count
#define LED_PIN 12 // arduino output pin
#define GROUND_PIN 10
#define BRIGHTNESS 96 // maximum brightness
#define SPEED 115200 // virtual serial port speed, must be the same in boblight_config
CRGB leds[NUM_LEDS];
uint8_t * ledsRaw = (uint8_t *)leds;
// A 'magic word' (along with LED count & checksum) precedes each block
// of LED data; this assists the microcontroller in syncing up with the
// host-side software and properly issuing the latch (host I/O is
// likely buffered, making usleep() unreliable for latch). You may see
// an initial glitchy frame or two until the two come into alignment.
// The magic word can be whatever sequence you like, but each character
// should be unique, and frequent pixel values like 0 and 255 are
// avoided -- fewer false positives. The host software will need to
// generate a compatible header: immediately following the magic word
// are three bytes: a 16-bit count of the number of LEDs (high byte
// first) followed by a simple checksum value (high byte XOR low byte
// XOR 0x55). LED data follows, 3 bytes per LED, in order R, G, B,
// where 0 = off and 255 = max brightness.
static const uint8_t magic[] = {'A','d','a'};
#define MAGICSIZE sizeof(magic)
#define HEADERSIZE (MAGICSIZE + 3)
#define MODE_HEADER 0
#define MODE_DATA 2
// If no serial data is received for a while, the LEDs are shut off
// automatically. This avoids the annoying "stuck pixel" look when
// quitting LED display programs on the host computer.
static const unsigned long serialTimeout = 150000; // 150 seconds
void setup()
{
pinMode(GROUND_PIN, OUTPUT);
digitalWrite(GROUND_PIN, LOW);
FastLED.addLeds<WS2811, LED_PIN, BRG>(leds, NUM_LEDS);
// Dirty trick: the circular buffer for serial data is 256 bytes,
// and the "in" and "out" indices are unsigned 8-bit types -- this
// much simplifies the cases where in/out need to "wrap around" the
// beginning/end of the buffer. Otherwise there'd be a ton of bit-
// masking and/or conditional code every time one of these indices
// needs to change, slowing things down tremendously.
uint8_t
buffer[256],
indexIn = 0,
indexOut = 0,
mode = MODE_HEADER,
hi, lo, chk, i, spiFlag;
int16_t
bytesBuffered = 0,
hold = 0,
c;
int32_t
bytesRemaining;
unsigned long
startTime,
lastByteTime,
lastAckTime,
t;
int32_t outPos = 0;
Serial.begin(SPEED); // Teensy/32u4 disregards baud rate; is OK!
Serial.print("Ada\n"); // Send ACK string to host
startTime = micros();
lastByteTime = lastAckTime = millis();
// loop() is avoided as even that small bit of function overhead
// has a measurable impact on this code's overall throughput.
for(;;) {
} // end for(;;)
}
void loop()
{
// Not used. See note in setup() function.
}
focalintent commentedon Mar 15, 2014
This is just the code that you started off your g+ post with - there is nothing new/different that I would say here about it than I said over there.
This is not really a valid issue - I'm trying to use issues to deal with bugs in the library and/or new feature requests, not support or "help me port my code" - that's what the g+ community is for.
At this point, I will say again what I said in the g+ community - you need to find someone who uses/has used boblight and/or adalight, and get help from them.