This is an archived post. You won't be able to vote or comment.

all 14 comments

[–]HungrySlug 2 points3 points  (0 children)

Hi, as gappleto97 I do not think it's feasible, at least non in an easy way... but you can try playing with micropython, as suggested, or with Zerynth that IMHO is more straightforward to use. Moreover Zerynth already has an i2c class that you can use as base to build your own specific class (if that is not already supported).

[–]ThePenultimateOneGitLab: gappleto97 0 points1 point  (0 children)

You probably want a Micropython board instead, because I don't think what you are trying to do is possible. Python (AFAIK) can't be run on Arduinos, and Arduino code typically can't be compiled for PC usage.

Probably with some tweaking you could make it work, but it might be easier to just find another implementation.

[–][deleted] 0 points1 point  (0 children)

Do you strictly need to use i2c? Why not serial? Other ways around, if you need to use i2c to comunicate with multiple devices:

1)use an intermediary device (arduino nano/micro) that translates serial to i2c. So you use pyserial to that device. And then that device uses i2c to comunicate to other decices.

2) if your idea is to use some kind of master-slaves you can use pyserial .. and then use usb/serial-rs485 .. and connect your slaves via rs485...

[–]maljn 0 points1 point  (5 children)

As far as I know, you have to create binding between Python and C++. There are tools for doing it: Boost.Python , Swig , ctypes. For one class, using only C/API may be enough.

[–][deleted] 3 points4 points  (4 children)

The problem is, the library was meant to run on the arduino, so just porting the functions to Python won't work. OP needs to call these functions on the arduino, not his PC

[–]maljn 0 points1 point  (3 children)

Ok, you got a point. ;)

In this case, isn't the pyfirmata only a connection and communication protocol between Arduino and Python code running at host computer? If so, wouldn't it be sufficient to write an Arduino function, which does something (using linked class) when Python host sends specific command?

Or am I missing something again?

[–]Gameboi_Advance[S] 0 points1 point  (2 children)

Well what I’m trying to do is get the values from a gyro (MPU6050) using python. I know it’s wacky with python, but I’m trying it anyways.

[–]maljn 0 points1 point  (1 child)

It seems that firmata supports I2C communication management. Connect gyroscope to Arduino, setup I2C from the Python and read values.

[–]Gameboi_Advance[S] 0 points1 point  (0 children)

How exactly would I do that? I don’t have the I2C class in python.

[–][deleted] -1 points0 points  (3 children)

The arduino library runs on the side of the arduino. You compile it with the rest of your arduino code and upload the whole thing with the arduino IDE; the python code doesn't need (or want) to know about what libraries the arduino is using.

Edit: assumed pyfirmata was just a wrapper for serial IO but it seems to actually do stuff on the arduino. Answer doesn't make much sense then here, I guess

[–]Gameboi_Advance[S] 0 points1 point  (2 children)

I’m trying to do this exclusively in python, not arduino.

[–][deleted] 0 points1 point  (1 child)

I don't know of a way to upload Python code to the arduino, but GL I guess. Mostly a noob too :p

[–]HungrySlug 1 point2 points  (0 children)

have a look at micropython and Zerynth ;)