0

neopixels strip with teensy 3.2
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

neopixels strip with teensy 3.2

by jbsauret on Thu Oct 12, 2017 4:31 am

Hi,

I'm using a 4m ledstrip of Neopixels (https://www.adafruit.com/product/1138) with Teensy 3.2.


1/ The strip don't work when I connect the ground to the teensy. I have to disconncet it to light Leds (I don't understand why, and i know it can be dangerous for the led strip).
(blue jumper on picture)
20171012_102249.jpg
Blue jumper (ground) disconnected
20171012_102249.jpg (92.6 KiB) Viewed 61 times



2/ The strip works when I use a simple test program, but I've a problem of really fast blinking leds when I use MadMapper. I'm afraid of a lack of power, but 240 pixels are not a lot, and i don't have this problem with other programs. (I have 5V 10A power supply, as recommanded, but I live in France, and order from Adafruit, US)...
and maybe it's beacause of 1/

I use MadLight protocol, with FastLED library (code below).

If anybody knows about this, let me know. Thx for your help.

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

#define MAD_LED_PACKET_HEADER 0xFF
#define MAD_LED_DATA 0xBE
#define MAD_LED_DETECTION 0xAE
#define MAD_LED_DETECTION_REPLY 0xEA
#define MAD_LED_PROTOCOL_VERSION 0x01

//#define DEBUG_MODE
// To test LEDs (FastLED) without the need of MadMapper or MadRouter sending data on serial port
//#define JUST_TEST_LEDS

#define NUM_LEDS 240
#define DATA_PIN 14
//#define CLOCK_PIN 6

// Fast LED Buffers
CRGB leds[NUM_LEDS];

// MadLED protocol buffer
char dataFrame[4086];
int readingFrameOnLine=-1;
bool gotNewDataFrame=false;

enum State {
  State_WaitingNextPacket,
  State_GotPacketHeader,
  State_WaitingLineNumber,
  State_WaitingChannelCountByte1,
  State_WaitingChannelCountByte2,
  State_ReadingDmxFrame
};

State inputState=State_WaitingNextPacket;
unsigned int channelsLeftToRead=0;
char* frameWritePtr=dataFrame;

void setup() {
  Serial.begin(250000);
  while (!Serial) {
    ; // wait for serial port to connect. Needed for Leonardo only
  }
 
  for (unsigned int i=0; i<sizeof(dataFrame); i++) dataFrame[i]=0;

  // Here setup FastLED first LED line protocol
  // Uncomment/edit one of the following lines for your leds arrangement.
  // FastLED.addLeds<TM1803, DATA_PIN, RGB>(leds, NUM_LEDS);
  // FastLED.addLeds<TM1804, DATA_PIN, RGB>(leds, NUM_LEDS);
  // FastLED.addLeds<TM1809, DATA_PIN, RGB>(leds, NUM_LEDS);
  //FastLED.addLeds<WS2811, DATA_PIN, RGB>(leds, NUM_LEDS);
  // FastLED.addLeds<WS2812, DATA_PIN, RGB>(leds, NUM_LEDS);
  // FastLED.addLeds<WS2812B, DATA_PIN, RGB>(leds, NUM_LEDS);
  FastLED.addLeds<NEOPIXEL, DATA_PIN>(leds, NUM_LEDS);
  // FastLED.addLeds<APA104, DATA_PIN, RGB>(leds, NUM_LEDS);
  // FastLED.addLeds<UCS1903, DATA_PIN, RGB>(leds, NUM_LEDS);
  // FastLED.addLeds<UCS1903B, DATA_PIN, RGB>(leds, NUM_LEDS);
  // FastLED.addLeds<GW6205, DATA_PIN, RGB>(leds, NUM_LEDS);
  // FastLED.addLeds<GW6205_400, DATA_PIN, RGB>(leds, NUM_LEDS);
  // FastLED.addLeds<APA102, DATA_PIN, CLOCK_PIN, RGB, DATA_RATE_MHZ(2)>(leds, NUM_LEDS);
  // FastLED.addLeds<WS2801, DATA_PIN, CLOCK_PIN, RGB>(leds, NUM_LEDS);
  // FastLED.addLeds<SM16716, DATA_PIN, CLOCK_PIN, RGB>(leds, NUM_LEDS);
  // FastLED.addLeds<LPD8806, DATA_PIN, CLOCK_PIN, RGB>(leds, NUM_LEDS);
  // FastLED.addLeds<P9813, DATA_PIN, CLOCK_PIN, RGB>(leds, NUM_LEDS);
  // FastLED.addLeds<DOTSTAR, DATA_PIN, CLOCK_PIN, RGB>(leds, NUM_LEDS);

  Serial.print("Setup done");
}

void processByte(unsigned char currentByte) {
  #ifdef DEBUG_MODE
    Serial.print("GOT BYTE: "); Serial.print(currentByte,HEX);
  #endif
  if (currentByte==MAD_LED_PACKET_HEADER) {
    inputState=State_GotPacketHeader;
    #ifdef DEBUG_MODE
      Serial.print("GOT PH ");
    #endif
  } else
  if (inputState == State_WaitingNextPacket) {
    // Just ignore this byte, we're not processing a packet at the moment
    // Wait for next packet start (xFF)
  } else
  if (inputState == State_GotPacketHeader) {
    if (currentByte==MAD_LED_DETECTION) {
      // Send back detection reply
      Serial.write(MAD_LED_DETECTION_REPLY);
      Serial.write(MAD_LED_PROTOCOL_VERSION);
      inputState=State_WaitingNextPacket;
    } else if (currentByte==MAD_LED_DATA) {
      inputState=State_WaitingLineNumber;
      #ifdef DEBUG_MODE
        Serial.print("GOT LD ");
      #endif
    } else {
      // Unknown packet start, reset
      inputState=State_WaitingNextPacket;
    }
  } else
  if (inputState == State_WaitingLineNumber) {
    if (currentByte>0x7F) {
      // Error, reset
      inputState=State_WaitingNextPacket;
      #ifdef DEBUG_MODE
        Serial.print("ErrLineNum: "); Serial.print(currentByte);
      #endif
    } else {
      readingFrameOnLine=currentByte;
      inputState=State_WaitingChannelCountByte1;
      #ifdef DEBUG_MODE
        Serial.print("GOT LN ");
      #endif
    }
  } else
  if (inputState == State_WaitingChannelCountByte1) {
    if (currentByte>0x7F) {
      // Error, reset
      inputState=State_WaitingNextPacket;
      #ifdef DEBUG_MODE
        Serial.print("ErrChCNT1: "); Serial.print(currentByte);
      #endif
    } else {
      channelsLeftToRead=currentByte;
      inputState=State_WaitingChannelCountByte2;
      #ifdef DEBUG_MODE
        Serial.print("GOT CHC1 ");
      #endif
    }
  } else
  if (inputState == State_WaitingChannelCountByte2) {
    if (currentByte>0x7F) {
      // Error, reset
      inputState=State_WaitingNextPacket;
      #ifdef DEBUG_MODE
        Serial.print("ErrChCNT2: "); Serial.print(currentByte);
      #endif
    } else {
      channelsLeftToRead+=(int(currentByte)<<7);
      if (channelsLeftToRead==0) {
        // Error, reset
        inputState=State_WaitingNextPacket;
        #ifdef DEBUG_MODE
          Serial.print("ErrChCNT=0");
        #endif
      } else {
        frameWritePtr=dataFrame;
        inputState=State_ReadingDmxFrame;
        #ifdef DEBUG_MODE
          Serial.print("GOT CHC2 ");
        #endif
      }
    }
  } else
  if (inputState==State_ReadingDmxFrame) {
    *frameWritePtr++ = currentByte;
    channelsLeftToRead--;
    if (channelsLeftToRead==0) {
      // Finished reading DMX Frame
      inputState=State_WaitingNextPacket;
      gotNewDataFrame=true;
      #ifdef DEBUG_MODE
        Serial.print("GOT DATA ");
      #endif
    }
  }
}

void loop() {
  // We read a maximum of 30000 bytes before we should call FastLED.show again
  // This is a good setting for the teensy, it depends on CPU speed, so it should be set lower on a slower CPU (ie arduino)
  // This limit (bytesRead<30000) is useless for protocols with a clock
  // But necessary when controlling more than 600 hundred RGB leds with WS2811 / WS2812
  int bytesRead=0;
  while (Serial.available() > 0 && bytesRead<30000) {
    processByte(Serial.read()); bytesRead++;
  }

  #ifdef JUST_TEST_LEDS
    static int value=0;
    value = (value + 1) % 254;
    for (int i=0; i<NUM_LEDS; i++) leds[i]=CRGB(value,value,value);
  #else
    if (gotNewDataFrame) {
      gotNewDataFrame=false;
      char* dataPtr=dataFrame;
      // Copy the data frame we received in the correct FastLED buffer
      for (int i=0; i<NUM_LEDS; i++) {leds[i]=CRGB(dataPtr[0],dataPtr[1],dataPtr[2]); dataPtr+=3;}
    }
  #endif
 
  FastLED.show();
}

jbsauret
 
Posts: 1
Joined: Thu Oct 12, 2017 3:47 am

Please be positive and constructive with your questions and comments.