Open thorikawa opened 8 years ago
if (IS_PIN_DIGITAL(pin) && !IS_PIN_SERIAL(pin)) {
would prevent setting the pinMode of any HW serial pins to OUTPUT if the UART is not used. This could be a common case for the Due or Mega since they each have 4 UARTs.
One approach could be:
if (Firmata.getPinMode(pin) == PIN_MODE_PWM) {
// disable PWM
digitalWrite(PIN_TO_DIGITAL(pin), LOW);
}
That way it's only called if changing a pin's mode from PWM to digital output.
PR submitted but needs testing before it can be merged: https://github.com/firmata/arduino/pull/311.
@thorikawa please checkout the issue-302 branch and report if it fixes your issue. There is a slight chance it still could be a problem due to the RX pin being set to OUTPUT, however this should correct that as long as it doesn't generate a state change on the pin.
@soundanalogous Thanks, I just tested against with the new branch, but did not work. I will dig into the issue more later.
When I use StandardFirmata on Arduino Due and connect it with a serial servo motor with Serial1 on pins 19 (RX) and 18 (TX), the servo motor does not work.
I found a issue that an extra preceding LOW bit is always sent here from
setPinModeCallback
function which is called fromsystemResetCallback
function at the initial setup of the sketch. Call stack is as below.The servo motor I am using is so sensitive that this extra bit prevent it from interpreting the serial command properly. When I change the condition line here from
if (IS_PIN_DIGITAL(pin)) {
toif (IS_PIN_DIGITAL(pin) && !IS_PIN_SERIAL(pin)) {
, everything works well. So I am really sure this line is the cause of my issue.Do we really need this
digitalWrite(PIN_TO_DIGITAL(pin), LOW);
line for all digital pins including hardware serial pins at the initial setup? If not, I can send the pull request to fix it as I mentioned above.By the way, this issue might be related with #272 which is also an issue with Arduino Due and Hardware Serial 1.