2

I am using the "busio" and "board" module for this. I wanted to know if I can remove them and replace them with just the "smbus" module. Excuse the ignorance, but I am surprised that for the other components that I have connected in sda scl, I do not need those modules and for adafruit led backpack yes (in fact with the module that I use now, with the previous one I did not need it.) ... perhaps they can be "ignored" for that reason I ask. Thanks.

import board as rasp
import busio
from adafruit_ht16k33 import matrix
i2c = busio.I2C(rasp.SCL, rasp.SDA)
1

Factual

Yes, you can use smbus to talk to your I2C devices rather than using the busio and/or board modules.

Opinion

Personally I would always use smbus for control unless the underlying device being controlled is very complex.

If you use smbus you can more easily port the code to a different board and more easily tailor the code to your own needs. The knowledge gained will also help if you ever need to interface a new I2C device.

2
  • How can i use smbus? is for this adafruit.com/product/1427 on a raspberry pi zero. – 9acca9 Mar 16 at 13:39
  • Did you ask the wrong question? If you don't know how to use smbus you will have to learn how. It's not the point of this site to teach you how to do that. – joan Mar 16 at 16:16
1

Question

How to use python packages with importing "busio" and "board"?


Answer

  1. Well I guess you are using modules/boards/HATs from AdaFruit. For a particular modules, eg temperature sensor, AdaFruit has different version for different MCU and SBC, say M0, Arduino, and Rpi.

  2. If you are using a Rpi compatible module, then your corresponding python program would:

    (a) import "board" and "busio", and

    (b) set i2c as "busio.I2C(rasp.SCL, rasp.SDA)"

    This way, AdaFruit knows which specific, fixed GPIO pins to talk I2C.

  3. If you are not using AdaFruit modules, then you need to tell the sensor module software/driver which GPIO pins are used for I2C by /boot/config.txt, and which drivers to use etc.

  4. In short, AdaFruit software is very newbie friendly because you don't need to do your configuration by modifying statements in config files like /boot/config.txt. But the results is that their sensor drivers not very open source.

    Luckily many open source guys develop AdaFruit like sensor driver for use without doing the Ada import and config I2C pins.

  5. Let me give an example on the very popular ADC MCP3008. AdaFruit has a very newbie friendly tutorial and demo python code. However, their python code imports "board" and "busio", and also other AdaFruit modules not 100% compatible to Rpi.

    The workaround is the use PyPi's library which is ported from AdaFruit but does not use "busio" and "board". I have listed the references below.

  6. The OP is using the AdaFruit's HT16K33 library for 16x8 LED Matrix Driver Backpack.

  7. One workaround might be using MicroPython which is compatible to Rpi Pico (Ref 7 below). AdaFruit CircuitPython is not very compatible to Rpi .


References

(1) AdaFruit MCP3008 Tutorial

(2) AdaFruit MCP30087 Python Script (importing AdaFruit modules busio, board)

(3) PyPi MCP3008 Python Script (without importing AdaFruit busio and board)

(4) Adafruit 16x8 LED Matrix Driver Backpack - HT16K33 Breakout

(5) HT16k33 Datasheet - Digichip

(6) Adafruit's Legacy Raspberry Pi Python Code Library

(7) hybotics/Hybotics_Micropython_HT16K33 - GitHub


Appendices

Appendix A - Adafruit's Legacy Raspberry Pi Python Code Library

(6) Adafruit's Legacy Raspberry Pi Python Code Library

(a) What happened to all the Raspberry Pi Python code!?

In the past this repository held all of the Raspberry Pi related Python code that Adafruit published. For example code to talk to sensors like the BMP085, TCS34725, and other hardware like character LCD plates.

Over time we found it difficult to manage so much code in a single repository, and couldn't easily put the code on Python's package index for simple installation.

Now we've broken out all of the previous Python code into individual GitHub repositories, and we've loaded all of these repositories on the Python package index so they can be installed with pip

(note that pip won't install example code so for most users it's recommended to install from source).

(b) Where do I find the new Raspberry Pi Python code?

All of the Python libraries now support Python 3.x and a wide variety of Linux/Single Board Computers.

(c) This library has been deprecated in favor of our python3 Blinka library. We have replaced all of the libraries that use this repo with CircuitPython libraries that are Python3 compatible, and support a wide variety of single board/linux computers!

Visit https://circuitpython.org/blinka for more information

(d) CircuitPython has support for almost 200 different drivers, and a as well as FT232H support for Mac/Win/Linux!

(e) But I need the old code! What can I do?

Don't worry the old Adafruit Raspberry-Pi Python code can be found in the legacy branch of this repository. This is a snapshot of the old code before it was refactored into individual libraries. Note this legacy code will not be maintained!


4
  • #9acca9. Pleasde let me know which sensor etc you are using, I would try to find open source drivers which don't need to use AdaFruit's "board" and "busio". Another thing is that you are using AdaFruit's Circuit Python for their Arm Cortex M0 MCU boards, then you can try the Rpi Pico M0 MCU MicroPython which is open source. Google "MciroPython" to learn more. – tlfong01 Mar 16 at 8:49
  • 1
    Hello. The library i used has no function for the LEDs to blink. This was handled by turning on the led, setting a time.sleep and turning it off and on in a loop, but due to what I'm doing it is not convenient for me to have that "time.sleep". I saw that this new module does blink, so I switched to it. But to make the previous module work I didn't have to use those libraries ... which I would now like to get rid of. adafruit.com/product/1427 – 9acca9 Mar 16 at 13:33
  • #9acca9. So you are using AdaFruit's HT16K33 LED matrix driver library. As you can read from Appendix A of my answer, AdaFruit has moved all their old python code into individual GitHub repositories. So you need you search their GitHub repositories to pip install. I think HT16K33 is a old device used in the Arduino days, so I am afraid it is unlikely to find Rpi compatible base python ports. Or you might like to switch to Circuit Python. Good luck. Cheers. – tlfong01 Mar 16 at 14:00
  • Update: Just now I use Rpi4B buster GUI Desktop Add/Remove Software to search HT16K33 but found nothing.So I guess HT16K33 is too old for the Rpi guys to update their installation index pages. – tlfong01 Mar 22 at 7:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.