1

Anyone have reco's on where I'm going wrong extracting data from a text file (SD) and sending along DMX? The code works for the P9813 portion and the DMX works in general but not the SD data.

Pastebin Code Here

I believe my issue is at line 68. I think this is reading too many values. IE currentColor is storing 5 values (5 lights) vs 1 Hex or 3xR/G/B.

The values in the SD for consideration are..."727a 6276 3030 ...". I believe these bytes should be each DMX channels PWM value, no?

Thanks

2 Answers2

0
currentColor = fxdata.readBytes((char*)leds, NUM_LEDS*3); //attempt to store SD card read data as RGB

I do not know your library, but I would expect a readBytes() call like this to actually store the data you want into leds, and returning how many bytes it was able to read.

result = fxdata.readBytes((char*)leds, NUM_LEDS*3); //attempt to store SD card read data as RGB
if (result != (NUM_LEDS*3))
{
  /* Handle the error here.. an action can be fill inn default values in leds[] if SD card is not working
}
/* from this point, use leds[], not currentColor */

revised example (not compile tested, lacking environment used, datatype of CRGB unknown):

void sendDMX(int theStrip, CRGB *theColor) {
  for(int z=0; z<3; z++) {
    DmxSimple.write((theStrip + z), theColor[z]); //DMX Channel, PWM Value
  }
}

void loop()
{
  fxdata = SD.open("TCL_DMX.dat");  // read only
  if (fxdata)
    {
      Serial.println("file open ok");      
    }

  while (fxdata.available())
  {
    fxdata.readBytes(leds, sizeof (leds)); //attempt to store SD card read data as RGB

    Serial.println(fxdata);

    sendDMX(1, leds); //RGB Strip #, RGB bytes from SD .dat file
    FastLED.show();
    delay(500);
  }  

  // close the file in order to prevent hanging IO or similar throughout time
  fxdata.close();
}
Stian Skjelstad
  • 2,277
  • 1
  • 9
  • 19
  • I'll give that a try in the next couple days. Could you elaborate on what the first line is achieving? I understand it's reading bytes, but what would "results" hold? Does it simply go through "byte 1" in the first time through the loop, "byte 2" the second time, etc. Or is the readBytes storing multiple bytes in "result"? Reason I ask is the DMX.write ends up requiring a single value 0-255. The leds[] variable should be holding the 3 character RGB value which can be accessed individually by leds[0].r, leds[0].g, leds[0].b. – joshjingles Apr 27 '16 at 21:32
  • DMX should have a total av 512 channels of data. If DMX.write takes two numeric values, it probably sets one of these, so if you want to set 3 channels, call ot three times. (Add the dmx and sd card header files in pastebin, so that I can take a peek) – Stian Skjelstad Apr 28 '16 at 05:41
  • Yep, re DMX. The 1st # is the channel (1-512), the 2nd PWM (0-255). I'm trying to understand what is in the variable that is being pulled from the SD card. My previous code had a serial.println and the result was '1' despite the text file having 4 digit bytes. If the variable only ever has 1 byte at a time, then I it's likely a PWM value. If the variable "results" holds multiple bytes then would I need a loop to read the first byte, write it to ch1 DMX, skip to second byte, write to ch2 DMX, etc? The leds[0] is defined as CRGB which in the library means it's holding 3 PWM values. – joshjingles Apr 28 '16 at 14:30
0

Thanks with your help everything is now working.

Here's the result: http://pastebin.com/wHAT6dZB