Mega 2560 Board & FirmataVB/Firmata Compatibility?

I have been attempting to interface a Mega 2560 board with the FirmataVB example program on the FirmataVB site (w w w acraigie com / programming / firmatavb /). Unfortunately, the board does not appear to recognize/respond to any of the commands. Are there any compatibility issues with the Mega 2560 board and Firmata, and if so, are there any alternatives for controlling the board using C, C# or VB? Thanks.

Are there any compatibility issues with the Mega 2560 board and Firmata

Yes. Firmata is not fully compatible with the Mega. It should work on all the pins that the Mega shares with the other Arduinos, but not on any of the higher pins.

are there any alternatives for controlling the board using C, C# or VB?

Of course. You can implement your own protocol. It's pretty simple.

Paul,

Thank you for getting back to me so quickly. I guess than that I am not executing this correctly then. I had assumed that since the VB program was effectively sending commands to the Mega 2560 board, there was no need to upload a sketch - is that so? If I do need to upload a sketch to control the arduino (light an LED on pin 13, or 12, 11, etc.), what sketch would I upload? Sorry to be so thick and I do very much appreciate your advice as I become more familiar with Arduino. Thanks again. Bill

Thank you for your direction Richard. Unfortunately, I had not noticed the specific instruction to "Use File -> Open -> Examples > Library-Firmata > StandardFirmata (it's still all very new for me) for the standard firmware that works with most host implementations". Accordingly, I uploaded the StandardFirmata sketch to the Arduino Mega 2560.

Unfortunately however, when I still attempt to set a pin (pin 9) to OUTPUT and then toggle between HIGH and LOW through a C# app, there is no effect on the associated LED on pin 9. I can see that the board receives the instruction (the RX light shows activity); however the LED on pin 9 does not react (the polarity for the LED is correct). I would appreciate any further thoughts you may have. Thanks. Bill

Unfortunately however, when I still attempt to set a pin (pin 9) to OUTPUT and then toggle between HIGH and LOW through a C# app, there is no effect on the associated LED on pin 9.

Oh, I love guessing games. NOT.

Show some code!

Paul,

Sorry to make this so difficult. I am using the C# library available at http://www.imagitronics.org/projects/firmatanet/ with the following code:

namespace Firmata.NET
{
public partial class Form1 : Form
{
public Arduino arduino = new Arduino();

public Form1()
{ InitializeComponent(); }

private void Form1_Load(object sender,EventArgs e)
{ arduino.pinMode(9, Arduino.OUTPUT); }

private void btnOn_Click(object sender,EventArgs e)
{ arduino.digitalWrite(9, Arduino.HIGH); }

private void btnOff_Click(object sender, EventArgs e)
{ arduino.digitalWrite(9, Arduino.LOW); }
}

}

Bill

Does a simple sketch on the Arduino turn the LED off and on? This would rule out a hardware issue.

Paul,

Yes the "blink" sketch runs perfectly on the Arduino. Additionally, if I switch the application OUTPUT pin from pin 9 to pin 13, the Arduino LED will light up as expected during the downloading of the StandardFirmata sketch to the Arduino, but will not light up when the application's LED ON button is pressed and the arduino.digitalWrite(13, Arduino.HIGH) command is sent to the Arduino.

Bill

All I can suggest now then is that you need to develop your own protocol. It really isn't that difficult. Something like <D 13 H> sent to the serial port can be read by the Arduino, and parsed, to turn digital pin 13 on. Similar command to turn it off. <D 9 45> to set the PWM value of pin 9 to 45.

<A 4> would request the value of analog pin 4. <R 8> to read the value of digital pin 8. <S 3 I> to set pinMode for pin 3 to INPUT.

You could add additional commands for things like pulseIn(), etc., if you needed/wanted.

Paul,

Thank you for the suggestion. Would that mean that the firmata protocol and firmatanet software (above) aren't compatible with the Mega 2560, or is it just my Arduino (in your opinion)? If it is the Mega 2560 model that has created the issue (and not something specific to my board), I wanted to at least post some kind of conclusion here so as to be a resource for the next person that sooner or later will ask a similar question.

Thanks once again Paul and Richard.

Bill

No one has reported making Firmata compatible with the Mega1280 yet, so I doubt that it is compatible with the Mega2560 either.

I'm not, because I don't have either one of them.

The whole source is right there. What is stopping anyone from tweaking it for Mega1280 or Mega 2560?

Paul,

Is the source that needs to be tweaked for the Mega 2560 the "StandardFirmata" sketch that was loaded onto the Arduino initially? Are the proper programming specifications located within the Mega 2560 datasheet? Would the Arduino UNO also be subject to rewritting Firmata for compatibility?

Bill

Is the source that needs to be tweaked for the Mega 2560 the "StandardFirmata" sketch that was loaded onto the Arduino initially?

No, it's the Firmata.h and Firmata.cpp files that form the Firmata library that the sketch references.

Would the Arduino UNO also be subject to rewritting Firmata for compatibility?

The UNO uses the same ATMega328 chip as the Duemilanove, so the Firmata library should work just fine on the UNO.

Thanks Paul - I appreciate your guidance.

May I ask another question?

In the \arduino-0021\libraries\Firmata directory, there is a header file "Boards.h". It appears that the "Boards.h" file is called by the Firmata.h header file and is used to define a number of board specific variables (as shown below).

// Arduino Mega
#elif defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__)
#define TOTAL_ANALOG_PINS         16
#define TOTAL_PINS                70 // 54 digital + 16 analog
#define VERSION_BLINK_PIN         13
#define IS_PIN_DIGITAL(p)         ((p) >= 2 && (p) < TOTAL_PINS)
#define IS_PIN_ANALOG(p)          ((p) >= 54 && (p) < TOTAL_PINS)
#define IS_PIN_PWM(p)             IS_PIN_DIGITAL(p)
#define IS_PIN_SERVO(p)           ((p) >= 2 && (p) - 2 < MAX_SERVOS)
#define IS_PIN_I2C(p)             (0)
#define PIN_TO_DIGITAL(p)         (p)
#define PIN_TO_ANALOG(p)          ((p) - 54)
#define PIN_TO_PWM(p)             PIN_TO_DIGITAL(p)
#define PIN_TO_SERVO(p)           ((p) - 2)

Having said that, there does not appear to be any reference within Firmata.cpp or Firmata.h files that would define which board (AVR_ATmega2560) is being used; thereby defining the appropriate board-specific variables. Does the Arduino Mega 2560 hardware provide any information to the software behind the scenes so that the appropriate board-specific variables are defined? If not, would I just include a "#define AVR_ATmega2560" line within either the Firmata.cpp or Firmata.h files so that the software includes the appropriate board definitions?

Thanks again,
Bill

It appears that the "Boards.h" file is called by the Firmata.h header file and is used to define a number of board specific variables (as shown below).

This snippet DOES include the 2560...

there does not appear to be any reference within Firmata.cpp or Firmata.h files that would define which board (AVR_ATmega2560) is being used

That variable is set when you choose the board you are building for.

Does the Arduino Mega 2560 hardware provide any information to the software behind the scenes so that the appropriate board-specific variables are defined?

How could it? The compiler isn't even talking to the hardware.

If not, would I just include a "#define AVR_ATmega2560" line within either the Firmata.cpp or Firmata.h files so that the software includes the appropriate board definitions?

This is where you lost me. The AVR_ATmega2560 name is defined when a board is selected in the Tools + Board menu item. That variable allows Boards.h to #define a set of names, with values that are appropriate for the 2560. Those names ARE referred to in the Firmata.cpp file.

Paul,

Ahh... now I understand -

The AVR_ATmega2560 name is defined when a board is selected in the Tools + Board menu item.

Again, thanks for your help Paul. I thought I might have stumbled on an easy solution for getting the 2560 to respond to Firmata, but alas - it's back to the drawing board.

Regards,
Bill