Firmata and RS485

Good evening fellow Arduino community!

I'm new here, and since I couldn't find any topic to suit this combo, I'll just leave it here. I do also apologize for any inconvenience regarding my English in advance.

I am using RS485 for communication between Arduino w/Firmata installed and a host computer. RS485 is half-duplex, therefore readout/writing is possible only on demand.

Now I'd like to use one of the pins, let's say DigitalPin3 to act as transmission enabler permanently, being initialized as LOW (listen for incoming signal, like Serial.available() > 0). As soon as any readout query to host has been initiated by Firmata:

  • DigitalPin3 must be set to HIGH to enable transmission
  • Wait until data has been sent over Serial (flush)
  • DigitalPin3 set back to LOW to disable transmission and enter the "listen" mode

Obviously, doing this for every "case" with Firmata.write in it inside sysexCallBack function does nothing. What would be the best way to achieve this?

I asked this question on github, where Jeff Hoefs was very nice by providing me with this:

Due to the coordination between the data pin and the read an write cycles this is not going to be an easy fix. However you have a couple of options:

Option A: Fork this repository and change Firmata.cpp to handle the digital pin at the lower level. You then need to change StandardFirmata to ignore digital pin 3 because it will be set to a digital output each time the board is reset (see this line). Skip that line when i == 3 and make sure the user can never set pin mode for digital pin 3 from the Firmata client.

Option B: Write a new class that extends HardwareSerial (call if "RS485Serial"). In this new class, override the read and write functions to add the digital pin toggle. You'll still need to update StandardFirmata as described above to ignore digital pin 3. You'll use the extended serial class (RS485Serial) in StandardFirmata like this:

// at the top of StandardFirmata (below the constants):
#define SerialRX  0
#define SerialTX  1
RS485Serial RS485(SerialRX, SerialTX); // could also add toggle pin as 3rd parameter

// in the setup function
RS485.begin(57600); // change the baud if you use something different
Firmata.begin(RS485); // instead of Firmata.begin(57600)

(see this topic on github)

I am not very familiar with programming Arduinos for now, so maybe somebody could share his/her knowledge/experience regarding this topic. Any input is greatly appreciated. Meanwhile, I'll try to get along as far as I can :P

Thank you!

Just a quick update: ended up writing my own protocol while simply using serial object in MaxMSP.

Ehm, less > more.