How do I extract data from arduino library over firmata to processing?

Hi!

I’m working on a project that involves sending and receiving the data through the Firmata Library to Processing and it works wonderfully with the StandardFirmata sketch as long as it only uses built-in arduino functions.
However, I have a DHT-11 sensor that uses its own library, so of course Firmata is not pre-coded for that. I have been looking around for a solution, but so far the only conclusion I could draw from other people’s questions is that one cannot import an arduino-specific library into processing.

So, I was thinking, instead of importing the library into processing, what if I import the library into arduino into the StandardFirmata sketch and only send the output-data to Processing? This would circumvent the issue of having to translate external libraries in Processing - at least in theory. I have been googling for precedent projects that would have had the same problem, but I was not able to find a good explanation/example on how to do such a thing.
Does anyone have experience with this? Would it be potentially easier to not use Firmata and write a code for serial communication myself? Alternatively, how hard is it to add the necessary firmata code to my existing sketch without uploading the StandardFirmata sketch?

Thanks!

If you can tell me about Firmata and maybe provide a current link to Firmata, I may be able to help a little. Last time I tried to look Firmata up (more than a year ago), all I found only old partial information.

There must be a sketch loaded on the Arduino/Wiring side for Firmata on the PC to work with right?

When you loaded Firmata on the Arduino, you turned it into a moron. You can't expect it to do all the wonderful things it can do, like intelligently read DHT-11 sensors, while it is a moron. You'd have to make Processing ask the moron to do the stuff the Arduino knows (with the appropriate library) how to do.

If you don't know how to make Processing do that, get rid of Firmata and vow never to use that crap again.

Writing code in Processing to ask the Arduino to do something (turn on a pin, report the value of a pin, etc.) isn't hard. Writing the code for the Arduino to determine what Processing wants it to do isn't difficult, either.

It's difficult when you don't know how. Learning curve can be a beotch. What to do? Wait to be handed a complete answer or start hacking into the material? Or both?

GoForSmoke: If you can tell me about Firmata and maybe provide a current link to Firmata, I may be able to help a little. Last time I tried to look Firmata up (more than a year ago), all I found only old partial information.

There must be a sketch loaded on the Arduino/Wiring side for Firmata on the PC to work with right?

I had exactly the same issue - being only able to find incomplete information. I used the StandardFirmata sketch already provided with the arduino library. I'd really like to set up my own firmata code, but wasn't able to quite figure it out. I found this guy asking the same question, but he got no replies at all...

Other than that, I've been looking at the Firmata reference on the arduino page. Still messing around with it, but it's going really slow, as I'm not really a programmer. I guess what I really need is a overview/tutorial that explains what is required to set up a basic custom arduino-to-processing sketch using firmata. Or even better, how to add a library to the StandardFirmata sketch and set it up so it sends/receives data from that library to processing.

PaulS: When you loaded Firmata on the Arduino, you turned it into a moron. You can't expect it to do all the wonderful things it can do, like intelligently read DHT-11 sensors, while it is a moron. You'd have to make Processing ask the moron to do the stuff the Arduino knows (with the appropriate library) how to do.

If you don't know how to make Processing do that, get rid of Firmata and vow never to use that crap again.

Writing code in Processing to ask the Arduino to do something (turn on a pin, report the value of a pin, etc.) isn't hard. Writing the code for the Arduino to determine what Processing wants it to do isn't difficult, either.

GoForSmoke: It's difficult when you don't know how. Learning curve can be a beotch. What to do? Wait to be handed a complete answer or start hacking into the material? Or both?

I'm totally open to writing my own code, however I am somewhat limited by my lack of expertise. If you could point me to a good source that details how to integrate arduino using a library with processing would be very helpful! Thanks!

You don’t seem to be having any trouble posting here, and replying to questions. That means that you understand something about protocols (an agreed up means of exchanging information), whether you recognize the term, or not. That is all that Firmata is doing. Each end knows what the other expects.

You can define your own protocol. For instance, R,3 would mean read pin 3. S,5,1 would mean set pin 5 to 1. T,2 would mean get the temperature from sensor 2. Once you define all the commands that Processing should send, it isn’t difficult to write code to send them, with start and end delimiters ("<R,3>"). It isn’t difficult to write code to read delimited serial data.

#define SOP '<'
#define EOP '>'

bool started = false;
bool ended = false;

char inData[80];
byte index;

void setup()
{
   Serial.begin(57600);
   // Other stuff...
}

void loop()
{
  // Read all serial data available, as fast as possible
  while(Serial.available() > 0)
  {
    char inChar = Serial.read();
    if(inChar == SOP)
    {
       index = 0;
       inData[index] = '\0';
       started = true;
       ended = false;
    }
    else if(inChar == EOP)
    {
       ended = true;
       break;
    }
    else
    {
      if(index < 79)
      {
        inData[index] = inChar;
        index++;
        inData[index] = '\0';
      }
    }
  }

  // We are here either because all pending serial
  // data has been read OR because an end of
  // packet marker arrived. Which is it?
  if(started && ended)
  {
    // The end of packet marker arrived. Process the packet

    // Reset for the next packet
    started = false;
    ended = false;
    index = 0;
    inData[index] = '\0';
  }
}

It isn’t difficult to parse the instructions to get the command and other relevant data. It is not difficult to execute the commands, and return some data.

http://www.firmata.org/wiki/Main_Page

It says the Due has Firmata, that's not ancient.