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

Read/write I2C #37

Closed
zawilliams opened this issue Mar 26, 2015 · 2 comments
Closed

Read/write I2C #37

zawilliams opened this issue Mar 26, 2015 · 2 comments

Comments

@zawilliams
Copy link

Is there a way to read and write over I2C? I may be totally missing it.

@tino
Copy link
Owner

tino commented Mar 26, 2015

Not directly, but I2C message are just sysex messages (https://github.com/firmata/protocol/blob/master/i2c.md), so you should be able to do something like:

my_board.send_sysex(pyfirmata.I2C_REQUEST, my_data)

You also want to write a method that does something with the reply. Subclass Board and add a command handler for the I2C_REPLY command:

class MyBoard(pyfirmata.Board):
    def _handle_i2c(self, *data):
        # do your thing

# instantiate and register the cmd handler
my_board = MyBoard()
my_board.add_cmd_handler(pyfirmata.I2C_REPLY, my_board._handle_i2c)
# use my_board

@zawilliams
Copy link
Author

Got it - thought that was the case. Thanks @tino!

zurgeg added a commit to zurgeg/pyFirmata that referenced this issue Mar 19, 2020
Add easier access to I2C control because I know there was tino#37 that was caused by confusion over how to use I2C on PyFirmata. This will do some simplifying by adding a send_i2c function.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants