UNIHIKERGeneral

How to use Unihiker with Linux I2C devices using Python

userHead Ralph.Yamamoto 2024-08-07 20:39:37 892 Views1 Replies

I am trying to use Unihiker to connect to a Blues Notecard.  I would like to use the Blues note-python library which connects to the standard i2c devices in /dev.

 

If I run i2cdetect -l it returns

i2c-1   i2c             rk3x-i2c                                I2C adapter
i2c-2   i2c             rk3x-i2c                                I2C adapter

 

I can see both these devices in /dev.

crw-rw---- 1 root i2c      89,   1 Feb 14  2019 i2c-1
crw-rw---- 1 root i2c      89,   2 Feb 14  2019 i2c-2

 

Is there a way to use these devices on the Unihiker or is there an example of how to modify code that uses these devices?

 

For some reason I can't attach the code file even though it is only 3KB it complains about a max size of 10MB.

 

Here is anexcerpt from the code:

 

*****   

import notecard

from periphery import I2C

 

 

"""Connect to Notcard and run a transaction test."""
   print("Opening port...")
   try:
       port = I2C("/dev/i2c-1")
   except Exception as exception:
       raise Exception("error opening port: "
                       + NotecardExceptionInfo(exception))

   print("Opening Notecard...")
   try:
       card = notecard.OpenI2C(port, 0, 0, debug=True)
   except Exception as exception:
       raise Exception("error opening notecard: "
                       + NotecardExceptionInfo(exception))

 

*****

 

I don't get an error from “Opening port” but it occurs when "Opening Notecard"

 

root@unihiker:~/python_code/blues# python3 note-python_i2c.py 
Opening port...
Opening Notecard...
Resetting Notecard I2C communications.
[Errno 6] I2C transfer: No such device or address

 

2024-08-08 08:31:55

from pinpong.board import Board, I2C  

On documentation page (https://www.unihiker.com/wiki/system-framework) you will see that I2C is available via MCU. So in case of Python you should use the pinpong library.

userHeadPic Lupin