Can smbus only run under Python 2.7? Can't it run under Python 3.8?

No, SMBus does not only run under Python 2.7, it can also run under Python 3.8 and higher. SMBus is a Python library for accessing I2C devices (Inter-Integrated Circuit, a serial communication protocol) on your system, and it should be compatible with Python 3.8.

To use SMBus under Python 3.8, you can install the SMBus library via:

bash
Copy code

pip install smbus2

Then, in your Python 3.8 code, you can import the SMBus2 library and use it to access the I2C device. For example:

python
Copy code

import smbus2

Create an SMBus object

bus = smbus2.SMBus(1) # Normally, the I2C bus number is 1

Using SMBus objects for read and write operations

data = bus.read_byte_data(device_address, register)
Please ensure that your system has correctly configured the I2C bus and that you have the appropriate permissions to access the I2C device. If you encounter problems under Python 3.8, it may be an issue related to system configuration or permissions, rather than an issue with the SMBus library itself.

Guess you like

Origin blog.csdn.net/pvmsmfchcs/article/details/132632389