How to use import libs (ex. firmata) in sketches

I’ve started a sketch and I want to use some of the communication cabability within the firmata library. However, when I include firmata.h, I get a bunch of compile errors regarding “first defined here”. How do you properly include these various libraries? I can’t find any examples that utilize these plus I notice that firmata.cpp has it’s own loop(), setup() etc. I’m obviously missing some very fundamental aspect to using the Arduino IDE. Can someone help me?

example:

o: In function FirmataClass::sendDigital(unsigned char, int)': C:\DOCUME~1\pzflkw\LOCALS~1\Temp\build8566.tmp/Firmata.cpp:278: multiple definition of FirmataClass::sendDigital(unsigned char, int)’

hardware\libraries\Firmata\Firmata.o:C:\Program Files\arduino-0013/hardware\libraries\Firmata/Firmata.cpp:278: first defined here

I can’t find any examples that utilize these plus I notice that firmata.cpp has it’s own loop(), setup() etc.

Isn’t Firmata designed to be used unmodified on the Arduino while being accessed over the serial connection?

–Phil.

Ok. If that is true then why does the IDE have the ability to import libraries by adding the appropriate .h file to your sketch?

Good question, it would appear I’m wrong. :slight_smile:

But, I don’t see any loop() or setup() in arduino-0013/hardware/libraries/Firmata/Firmata.cpp either.

I think you need to post both your code and the full error message you are getting.

–Phil.

Well I will try and post some code soon but I direct you to the tutorial on creating a library. This particular tutorial removes the setup() and loop() functions. This makes sense to me as libraries are intended to be included in sketches. I’m starting to think that the previous reply is correct…that firmata is intended to be a standalone.

http://arduino.cc/en/Hacking/LibraryTutorial

You can use Firmata in your own sketches.

Here is some very simple Test I used successfully:

#include <Firmata.h>

byte analogPin;

void analogWriteCallback(byte pin, int value)
{
  pinMode(pin,OUTPUT);
  analogWrite(pin, value);
}

void setup()
{
  Firmata.setFirmwareVersion(0, 1);
  Firmata.begin();
}

void loop()
{
  while(Firmata.available()) {
    Firmata.processInput();
  }
  Firmata.sendAnalog(4, analogRead(4)); 
  Firmata.sendAnalog(5, analogRead(5)); 
}

Carsten