Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Extended Analog #5

Open
tino opened this issue Jan 13, 2013 · 2 comments
Open

Add Extended Analog #5

tino opened this issue Jan 13, 2013 · 2 comments

Comments

@tino
Copy link
Owner

tino commented Jan 13, 2013

Extended Analog (added in version 2.2) As an alternative to the normal analog message, this extended version allows addressing beyond pin 15, and supports sending analog values with any number of bits. The number of data bits is inferred by the length of the message.

/* extended analog

0 START_SYSEX (0xF0) (MIDI System Exclusive)
1 extended analog message (0x6F)
2 pin (0 to 127)
3 bits 0-6 (least significant byte)
4 bits 7-13
... additional bytes may be sent if more bits needed
N END_SYSEX (0xF7) (MIDI End of SysEx - EOX)
/

@tino
Copy link
Owner Author

tino commented Jan 13, 2013

Paul Stanley wrote:

If you're running into this restriction here's a diff of changes for pyfirmata.py that worked for me. Tested with a Raspberry Pi running python 2.7 and a teensy 2.0++ with the StandardFirmata sketch from Arduino 1.0.1 (PWM tested only)
(Can't work out how to display this diff properly!)

diff pyfirmata.py pyfirmata_extended_analog.py
30a31

EXTENDED_ANALOG = 0x6F # analog write (PWM, Servo, etc) to any pin
488a490,494

  # use the extended analog feature if the pin no. >15
  # this will allow PWM and SERVO on all possible pins,
  # for teensy boards for example. 
  # Keep the old message format for pins <=15 for
  # compatibility with older firmata versions.

491,494c497,506 < msg = chr(ANALOG_MESSAGE + self.pin_number) < msg += chr(value % 128) < msg += chr(value >> 7) < self.board.sp.write(msg)

        if self.pin_number < 16:
            msg = chr(ANALOG_MESSAGE + self.pin_number)
            msg += chr(value % 128)
            msg += chr(value >> 7)
            self.board.sp.write(msg)
        else:
            msg = chr(self.pin_number)
            msg += chr(value % 128)
            msg += chr(value >> 7)
            self.board.send_sysex(EXTENDED_ANALOG, msg)

497,500c509,518 < msg = chr(ANALOG_MESSAGE + self.pin_number) < msg += chr(value % 128) < msg += chr(value >> 7) < self.board.sp.write(msg)

        if self.pin_number < 16:
            msg = chr(ANALOG_MESSAGE + self.pin_number)
            msg += chr(value % 128)
            msg += chr(value >> 7)
            self.board.sp.write(msg)
        else:
            msg = chr(self.pin_number)
            msg += chr(value % 128)
            msg += chr(value >> 7)
            self.board.send_sysex(EXTENDED_ANALOG, msg)

@setnicka
Copy link

What tests are needed to adopt this solution?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants