firmata/ConfigurableFirmata

Servo not working on pins above 11 or 15 (depending on board) in Configurable Firmata

Closed this issue · 20 comments

From @soundanalogous on June 8, 2013 15:44

via Christopher Coleman:

One thing we noticed is that while standard firmata allows for servos on many (pretty much all) digital pins, in Configurable Firmata they fail or act super irregularly above pins 11-15 (depending on the board).

Copied from original issue: firmata/arduino#62

The issue here is that MAX_SERVOS is mapped to pin numbers in Boards.h starting from pin 2 (or from pin 0 for boards that don't have RX and TX pins at 0 and 1) rather than allowing a servo on all pins that a servo could be attached to (https://github.com/firmata/arduino/blob/master/Boards.h#L194). MAX_SERVOS is defined in the Servo library. There are 12 servos allocated per 16 bit timer (note that some 16 bit timers are not included in this count: https://github.com/soundanalogous/Arduino/blob/master/libraries/Servo/Servo.h#L94). For many arduino boards this results in a max of 12 servos. This is why servos are not working on pins higher than 14 on some boards (because pins 0 and 1 are not counted when they are TX and RX pins).

To fix this issue we could change Boards.h to allow a Servo on any digital pin and then track the number of attached servos in Firmata and make sure the max number of attached servos is not exceeded (MAX_SERVOS).

From @rwaldron on March 5, 2014 17:30

Experiment: Change this line:

// Arduino Mega
#elif defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__)
...
#define IS_PIN_SERVO(p)         ((p) >= 2 && (p) - 2 < MAX_SERVOS)

To:

// Arduino Mega
#elif defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__)
...
#define IS_PIN_SERVO(p)         IS_PIN_DIGITAL(p)

As far as I can tell, this has solved the issues I was encountering. I will report back any further findings.

That should work as long as you don't exceed 12 servos.

Also have you tried a higher pin number after making that change? I'm curious if it's working up to the highest digital pin number on a Mega.

From @rwaldron on March 5, 2014 18:40

That should work as long as you don't exceed 12 servos.

Interesting that you mention this—I had 14 connected.

Also have you tried a higher pin number after making that change? I'm curious if it's working up to the highest digital pin number on a Mega.

Despite my earlier success, I've encountered some issue where power is no longer being properly supplied, so I'm trying to address that. Once I get past this issue I will test servos on the higher end pins.

From @rwaldron on March 5, 2014 19:28

I resolved the power issue and have moved on to other experiments.

Controlling from firmata_test.app

  • Doesn't display any pins beyond 46 (no idea why), but servos can be controlled on 46.
  • I've successfully attached 14 active servos.

Controlling from node via node-firmata

  • Servos are only controllable on pins 2-12

Still experimenting, but I thought this discrepancy was interesting enough to report back sooner.

From @rwaldron on March 5, 2014 22:44

I thought the issue might be caused by node-firmata not having support for EXTENDED_ANALOG in analogWrite, so I wrote a patched it to match firmata_test. Unfortunately, this doesn't seem to make a difference. I've added calls to Firmata.sendString right up to the point where servos[PIN_TO_SERVO(pin)].write(value); but still don't see any movement from the servo on that pin. Will post more as I go...

From @rwaldron on March 5, 2014 22:52

Holy shit... It helps to switch on your external power source.

To do for Firmata 2.4:

To fix this issue we could change Boards.h to allow a Servo on any digital pin and then track the number of attached servos in Firmata and make sure the max number of attached servos is not exceeded (MAX_SERVOS).

@rwaldron could have have a few J5 users try the Firmata update: http://www.jeffhoefs.com/downloads/Firmata-2.4.0-beta2.zip. Replace the Arduino Firmata library with the download (save a backup of the old version first).

It enables servos to be used on a wider range of pins. On an Uno you'll be able to use servos on pins D2-D13 and even on pins A0-A5. On a Mega you can use servos on pins D2-D53 and pins A0-A9 (there's an issue in the Servo library that prevents use on pins A10-A15 of a Mega... may be an issue with any pin over 63 actually). I haven't tested on other boards yet.

If someone would rather clone from source they can pull this branch: https://github.com/firmata/arduino/tree/servo-fix. Then run sh release.sh and unzip the file that's created, copying it over the exiting Firmata library in the Arduino application.

From @rwaldron on August 10, 2014 14:56

@dtex @julianduque can you two try this out?

From @dtex on August 10, 2014 18:11

I'll try when I get back to Houston tonight.

I only have 2 servos so if you can try this with a lot of servos in the expanded servo pin ranges that would be helpful. The number of servos per board remains the same (12 for an Uno or other standard format arduino, 48 for a Mega, and I still need to check the max for other boards).

From @dtex on August 10, 2014 19:14

Will do. I should be able to test up to ~30 at a time on the mega.

From @rwaldron on August 10, 2014 19:59

Will do. I should be able to test up to ~30 at a time on the mega.

:D

From @dtex on August 10, 2014 23:44

So I'm using StandardFirmata from the library in the zip correct?

Correct
On Aug 10, 2014 4:44 PM, "Donovan Buck" notifications@github.com wrote:

So I'm using StandardFirmata from the library in the zip correct?


Reply to this email directly or view it on GitHub
firmata/arduino#62 (comment).

From @rwaldron on August 10, 2014 23:49

@dtex I would just copy your existing Firmata elsewhere and drop the contents of the zip into /libraries/

You'll need to copy over the entire Firmata directory, not just StandardFirmata because this is a much newer version of Firmata than the one that ships with Arduino.

The diff for reference: https://github.com/firmata/arduino/compare/servo-fix

Opened a new issue that's more descriptive of the actual problem and the options for resolving it: #25