2

I'm working on a project that use J5, so is using the standard firmata, this project is using an opto 4 channel relay, when the board is booting the pins state are set to low, so as soon as I power the board my relay goes to a close state and make my motor run... this is a wrong behaviour for my purpose. How can I avoid that? By googleing around I stumble acros this:

A possible solution

but I can't uderstand if this is what I'm looking for.. plus I need only the PIN 7 to be set high on boot, any help please?

EDIT: SCHEMATICS

4 Channel 5V Relay Module

enter image description here

FabioEnne
  • 233
  • 7
  • 19

2 Answers2

3

It would seem you are right. If I understood the source correctly, Firmata initializes all digital pins as OUTPUT LOW. Hard to believe, as this seems like a silly thing to do... My understanding is that:

  1. setup() calls systemResetCallback() in order to set the initial pin configuration (line 779)
  2. systemResetCallback() loops over all pins and calls setPinModeCallback(i, OUTPUT) for every pin i that is not an analog pin (line 732)
  3. setPinModeCallback() calls pinMode() to set the pin to OUTPUT (line 325).

If my understanding is correct, then the simplest solution would seem to patch systemResetCallback() and replace OUTPUT by INPUT on lineĀ 732.

Edgar Bonet
  • 45,094
  • 4
  • 42
  • 81
1

Just put digitalWrite(anyPin,HIGH) in void setup() this will make that specific pin HIGH to reset. It works for me.

void setup()
{
  digitalWrite(8,HIGH);
  Firmata.setFirmwareVersion(FIRMATA_FIRMWARE_MAJOR_VERSION, FIRMATA_FIRMWARE_MINOR_VERSION);

Firmata.attach(ANALOG_MESSAGE, analogWriteCallback); Firmata.attach(DIGITAL_MESSAGE, digitalWriteCallback); Firmata.attach(REPORT_ANALOG, reportAnalogCallback); Firmata.attach(REPORT_DIGITAL, reportDigitalCallback); Firmata.attach(SET_PIN_MODE, setPinModeCallback); Firmata.attach(SET_DIGITAL_PIN_VALUE, setPinValueCallback); Firmata.attach(START_SYSEX, sysexCallback); Firmata.attach(SYSTEM_RESET, systemResetCallback);

// to use a port other than Serial, such as Serial1 on an Arduino Leonardo or Mega, // Call begin(baud) on the alternate serial port and pass it to Firmata to begin like this: // Serial1.begin(57600); // Firmata.begin(Serial1); // However do not do this if you are using SERIAL_MESSAGE

Firmata.begin(57600); while (!Serial) { ; // wait for serial port to connect. Needed for ATmega32u4-based boards and Arduino 101 }

systemResetCallback(); // reset to default config }

sa_leinad
  • 3,218
  • 2
  • 23
  • 51