gobot icon indicating copy to clipboard operation
gobot copied to clipboard

firmata: analog pin number to digital mapping is not always +14

Open 1lann opened this issue 8 years ago • 1 comments
trafficstars

In firamta_adaptor.go line 221: https://github.com/hybridgroup/gobot/blob/51f6aba47c369d95e395fca722d91ea48037ecda/platforms/firmata/firmata_adaptor.go#L221

The digital mapping for analog pins is hard coded as + 14, however, this is not always true for some boards. For example, on the Arduino Yún, it's + 18. This should be documented and/or changed to allow people to specify offset, have a database of boards, or somehow detect the correct offset value.

1lann avatar May 14 '17 09:05 1lann

Hello @1lann was finally looking into this, and I see that actually the Client is doing a AnalogMapping query, and so obtains the actual pin mappings for any board on initial connection.

The problem is that the Adaptor is not using this information, instead using the "hard wired" value as you pointed out. I have not had a chance to actually work on the code, but https://github.com/hybridgroup/gobot/blob/master/platforms/firmata/client/client.go#L450 is where the values are populated.

The solution could be that the https://github.com/hybridgroup/gobot/blob/master/platforms/firmata/firmata_adaptor.go#L239 function should probably be renamed to analogPinLookup() and the implementation use f.Board.Pins() to lookup the actual mapping.

Hopefully this makes sense. I will try to get to working in the next weeks on an improvement to handle this case, but if someone else wanted to write a PR to handle this, it would be greatly appreciated!

deadprogram avatar Nov 16 '17 08:11 deadprogram