Reading bytes from Arduino SD Card to DMX Lighting

1.5k views Asked by At

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

There are 2 answers

0
joshjingles On BEST ANSWER

Thanks with your help everything is now working.

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

3
Stian Skjelstad On
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();
}