Hello everyone,
I confess I am an Arduino noob but I do catch on fast
I have a program that reads and parses line by line a CSV file on a SD Card. It includes String.h and SD.h. and appears to work properly. I want to use the values on a line to determine a delay and the values of the intensity of fixtures on a DMX system. Sounds easy enough, right? Well as soon as I try to include DmxSimple.h, #include <DmxSimple.h>, well the previously working programs starts to behave very strangely, erratically and sometimes appears to freeze up. Remember, I have not included any DMX functions, just included the header in my program. I am at wits end. I have no new hypothesis to try and solve this. So if anyone here has an idea, all reasonable suggestions will be accepted and welcome.
Regards
Simon
//Program by Pascal-Simon Houle
//SD CSV File Read
#include <SD.h>
#include <String.h>
//#include <DmxSimple.h>
//Set by default for the SD Card Library
//MOSI = Pin 11
//MISO = Pin 12
//SCLK = PIN 13
//We always need to set the CS Pin
int CS_Pin = 10;
//int PowerPin = 8;
// Declare DMXValues Array and DMXValueIndex Counter. Keep Unsigned Integers below 65535
unsigned int DMXValues[15] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
int DMXValueIndex = 0;
int IterationCounter = 0;
int AvailableCounter = 0;
// Declare CSVStringBuffer Input Character Buffer, SimpleToken "container" and IntermediateBuffer Temporary Location for Read char from File
char CSVStringBuffer[80];
char *SimpleToken = NULL;
char IntermediateBuffer = NULL;
void setup()
{
 Serial.begin(9600);
 Serial.println("Initializing Card");
 //CS Pin is an output
 pinMode(CS_Pin, OUTPUT);
Â
 //Card will Draw Power from Pin 8, so set it high
 //Strange Arduino Idea... Arrrrggghhh them Software Designer they're so naughty!
 //This May not survive in Final Design
 //pinMode(PowerPin, OUTPUT);Â
 //digitalWrite(PowerPin, HIGH);
Â
 if (!SD.begin(CS_Pin))
 {
   Serial.println("Card Failure");
   return;
 }
 Serial.println("Card Ready");
Â
 // Read DMX Sequence information (CSVTest1.csv)
 File CSVCommandFile = SD.open("CSVTest1.csv");
 if (CSVCommandFile)
 {
  Serial.println("Reading DMXSequence File");
 Â
  AvailableCounter = CSVCommandFile.available();
  Serial.print("Available Character(s): ");
  Serial.println(AvailableCounter);
Â
 // As long as there are characters and that the Index is less than 80 characters read the file
 while(CSVCommandFile.available() && (IterationCounter <= 79))
 {
  IntermediateBuffer = CSVCommandFile.read();
   // Look for the first exception, 0x0D or carriage return. May be absent in a Mac generated CSV file
  if (IntermediateBuffer == 0x0D)
  {
   continue; // If found, re-iterate the while loop
  }
  // Look for the second exception, 0x0A or line feed
  else if (IntermediateBuffer == 0x0A)
  {
   CSVStringBuffer[IterationCounter] = NULL;
  Â
   // Put strtok and atoi processing here
  Â
   // Actual Parsing of CSVStringBuffer to find Tokens
   // This is where the magic happens :-)
   SimpleToken = strtok(CSVStringBuffer, ",");
   while(SimpleToken)
   {
    // Do something with this token
    DMXValues[DMXValueIndex] = atoi(SimpleToken);
   Â
    Serial.print(DMXValues[DMXValueIndex]);
    Serial.print(" was read into Integer Array at position ");
    Serial.println(DMXValueIndex);
   Â
    DMXValueIndex++;
   Â
    // Get the next token...
    SimpleToken = strtok(NULL, ",");
   }
  Â
   // Various progress messages
   Serial.println("Done Acquiring Character from 1 Line in CSVTest1.csv");
  Â
   Serial.print("Integer Array is: ");
   for(int j = 0; j <= (DMXValueIndex - 1); j++)
   {
    Serial.print(DMXValues[j]);
    Serial.print(" ");
   }
   Serial.println(" ");
  Â
   // Reset Index for Values Array before exiting and re-looping for the next line in CSVCommandFile
   DMXValueIndex = 0;
   // Reset Index for CharBuffer before exiting and re-looping for the next line in CSVCommandFile
   IterationCounter = 0;
  }
 Â
  // This section is where the CSVStringBuffer is filled with the characters from the file
  else
  {
   CSVStringBuffer[IterationCounter] = IntermediateBuffer;
   Serial.println(CSVStringBuffer[IterationCounter]);
   //Serial.print("Iteration Counter = ");
   //Serial.println(IterationCounter);
   IterationCounter++;
  }
 }
 }
Â
 // If upon exit of while loop i hasn't been reset there was a problem. Should test to determine the problem and print to log file
 if (IterationCounter != 0)
 {
  Serial.println("Aborted Character Acquisition");
  Serial.print("IterationCounter= ");
  Serial.println(IterationCounter);
  Serial.print("Available Character(s): ");
  Serial.println(AvailableCounter);
 }
 // Succes message
 else
 {
  Serial.print("Read total of ");
  Serial.print(AvailableCounter);
  Serial.println(" characters");
  Serial.print("DMXValueIndex= ");
  Serial.println(DMXValueIndex);
  Serial.println("Operation Succesful");
 }
}
void loop()
{
}