1

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

  • What makes you believe it boots with all pins LOW? They should be high impedance. Could you share the schematic of how you connect the Arduino to the optocoupler, to the the relays and to the motors? – Edgar Bonet May 22 '17 at 11:19
  • @EdgarBonet added schematics in the question ;) – FabioEnne May 22 '17 at 12:45
  • 3
    This is not a schematic. And it only shows how you are powering your relay module, not how you are driving it, nor how it works internally (reference please). – Edgar Bonet May 22 '17 at 12:47
  • @EdgarBonet added the references link to the constructor wiki page – FabioEnne May 22 '17 at 12:51
  • @EdgarBonet I forgot in the schema above to connect the pin 7 to the ch1, sorry – FabioEnne May 22 '17 at 12:52
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.

  • yep, my same conclusion but I think that setting all the pins to INPUT will cause the same but opposite problem for other components.. best would be set the desired pin number – FabioEnne May 22 '17 at 18:26
  • 2
    Irrespective of how you patch Firmata, the pins will be set to INPUT when you power the Arduino, and during the time the bootloader runs. You should manage for you circuit to accommodate that initial state. A pullup or pulldown resistor may be suitable for the pins driving those other components. – Edgar Bonet May 22 '17 at 18:48
  • how does it take to boot less than a second would be acceptable – FabioEnne May 22 '17 at 19:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.