Search code examples
arduinofirmata

How do I send arduino a firmata command to turn on a pin


I'm trying to implement the firmata protocol and having a bit of a difficult time deciphering the spec for writing digital pins:

I have noted the following parts of the spec of Firmata 2.3

* type                command  channel    first byte            second byte 
------------------------------------------------------------------------------
* digital I/O message   0x90   port       LSB(bits 0-6)         MSB(bits 7-13)

and

/* two byte digital data format, second nibble of byte 0 gives the port number (e.g. 0x92 is the third port, port 2)
 * 0  digital data, 0x90-0x9F, (MIDI NoteOn, but different data format)
 * 1  digital pins 0-6 bitmask
 * 2  digital pin 7 bitmask 
 */

I'm having some difficulty interpreting the spec. I've looked at other implementations, but haven't been able to see the relationship between the spec and implementation.

So let's say I am wanting to turn on the Arduino LED (pin 13), I know it will be on the second port, port 1, so the first byte will be #{91}.

I'm getting confused about the bitmask for the second two bytes though. I know what a bitmask is, so I want to enable the right bit for the pin.

  • Why is the bitmask so large for the digital pins? I'm familiar with using bitmasks on the digital outputs of PLCs, which seems much different (one pin, one bit)

  • My thought is that pin 13 would be the 7th pin on port 1. Since I don't care about the other pins, I would mark the pin in the 2nd byte #{40} and I don't need any pins set for the third byte #{00}?

I don't think my interpretation of the bitmasks is correct, and it's probably where my error is

Am I on the right track for this? Is this the right command for setting a pin high or low?


Solution

  • After some strace debugging with the firmata test application, I discovered the simple command to turn on Pin 13 was:

    #{912000}
    

    and to turn it off:

    #{910000}