Examples of I2c in Python
#1
I want to try to use a RFID reader that is i2c controlled, Is there any example code on using the i2c on the Pine64?
How close is it to the Pi i.e. can I reference tutorials and examples from the Pi?
  Reply
#2
You can grab this library : https://github.com/swkim01/RPi.GPIO-PineA64
I've contribute to add I2c and SPI almost 4 weeks ago.
There is no example provided, but it should look like :

Code:
from RPi import I2C as i2c

i2c.init("/dev/i2c-1")
i2c.open(0x20)
i2c.write([0x00, 0x00])
  Reply
#3
(12-15-2016, 03:37 PM)martinayotte Wrote: You can grab this library : https://github.com/swkim01/RPi.GPIO-PineA64
I've contribute to add I2c and SPI almost 4 weeks ago.

I attempted to update my RPi.GPIO-PineA64 by cloning from GitHub and when I run Python setup.py install I get the  errors shown below. I'm sure somehow I've probably misconfigured my system or am overlooking something obvious or simple. Does anyone have any suggestions on correctly installing the RPi.GPIO-PineA64 package with all its new goodies?

_______________________________________

In file included from source/i2c/i2c_lib.c:34:0:
/usr/include/linux/i2c-dev.h:37:8: error: redefinition of ‘struct i2c_msg’
 struct i2c_msg {
        ^
In file included from source/i2c/i2c_lib.c:33:0:
/usr/include/linux/i2c.h:68:8: note: originally defined here
 struct i2c_msg {
        ^
In file included from source/i2c/i2c_lib.c:34:0:
/usr/include/linux/i2c-dev.h:89:7: error: redefinition of ‘union i2c_smbus_data’
 union i2c_smbus_data {
       ^
In file included from source/i2c/i2c_lib.c:33:0:
/usr/include/linux/i2c.h:129:7: note: originally defined here
 union i2c_smbus_data {
       ^
error: command 'aarch64-linux-gnu-gcc' failed with exit status 1
  Reply
#4
you might try installing the build-essential package and see if that helps.
  Reply
#5
It seems that your kernel header files are no consistent each others, maybe one come from one version and the other from other.
Check the date of both /usr/include/linux/i2c.h and /usr/include/linux/i2c-dev.h to see if they are the same.
Which image are you using ? I strongly recommend one that use the longsleep kernel.
  Reply
#6
(12-30-2016, 03:39 PM)martinayotte Wrote: It seems that your kernel header files are no consistent each others, maybe one come from one version and the other from other.
Check the date of both /usr/include/linux/i2c.h and /usr/include/linux/i2c-dev.h to see if they are the same.
Which image are you using ? I strongly recommend one that use the longsleep kernel.

you were correct about the dates of the files being out of sync. copied over those two from a new image and the compile ran successfully.
  Reply
#7
Hello,
I have been working on a project that needs to use I2C from python.
With a small hack, I managed to get the adafruit I2C libraries working.
I have submitted a pull request via github to include the changes into adafruit's version.
If you need to, you can also find my modifications on github...

https://github.com/henryirvine/Adafruit_Python_GPIO.git

Happy hacking.
Henry
  Reply
#8
I have been working on getting the Adafruit library for the BN055  9DOF IMU working.
The adafruit code only needs to be modified to set which pin you are using to run the reset pin.
The catch was that the GPIO needed to be identified as the RPi equivalent GPIO.
After that, everything works great.

It's a one line change in the example code, but I have forked the adafruit library and it is available on github here:
https://github.com/henryirvine/Adafruit_...BNO055.git

The base adafruit GPIO library I have also patched to work with Pine64, it is available on github here:
https://github.com/henryirvine/Adafruit_Python_GPIO.git

Have fun with your Pine64, I sure am!
  Reply
#9
(10-02-2017, 08:25 PM)GliderHenry Wrote: I have been working on getting the Adafruit library for the BN055  9DOF IMU working.
The adafruit code only needs to be modified to set which pin you are using to run the reset pin.
The catch was that the GPIO needed to be identified as the RPi equivalent GPIO.
After that, everything works great.

It's a one line change in the example code, but I have forked the adafruit library and it is available on github here:
https://github.com/henryirvine/Adafruit_...BNO055.git

The base adafruit GPIO library I have also patched to work with Pine64, it is available on github here:
https://github.com/henryirvine/Adafruit_Python_GPIO.git

Have fun with your Pine64, I sure am!

Appreciated and thanks on the code.
  Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Getting Temperature/Humidity/Ambient Light data with Python Yomet 8 6,664 10-02-2016, 02:36 PM
Last Post: tllim

Forum Jump:


Users browsing this thread: 1 Guest(s)