pythonpython-3.xraspberry-piadafruit

Python 3.7.3 SystemError: error return without exception set


I am trying to install libraries by Adafruit for MCP3008 AD converter. All installation process was successful, but after running a basic program, it shows me a error message. I am running this program on RPi4 with python 3.7.3. Here is my code:

import time
import Adafruit_GPIO.SPI as SPI
import Adafruit_MCP3008

SPI_PORT   = 0
SPI_DEVICE = 0
mcp = Adafruit_MCP3008.MCP3008(spi=SPI.SpiDev(SPI_PORT, SPI_DEVICE))

print('Reading MCP3008 values, press Ctrl-C to quit...')
print('| {0:>4} | {1:>4} | {2:>4} | {3:>4} | {4:>4} | {5:>4} | {6:>4} | {7:>4} |'.format(*range(8)))
print('-' * 57)

while True:
    values = [0]*8
    for i in range(8):
        values[i] = mcp.read_adc(i)
    print('| {0:>4} | {1:>4} | {2:>4} | {3:>4} | {4:>4} | {5:>4} | {6:>4} | {7:>4} |'.format(*values))
    time.sleep(0.5)

And after calling specific program from my RPi4 using command:

sudo python3 adc.py

Console shows me this message:

Traceback (most recent call last):
  File "adc.py", line 7, in <module>
    mcp = Adafruit_MCP3008.MCP3008(spi=SPI.SpiDev(SPI_PORT, SPI_DEVICE))
  File "/usr/local/lib/python3.7/dist-packages/Adafruit_GPIO-1.0.4-py3.7.egg/Adafruit_GPIO/SPI.py", line 46, in __init__
SystemError: error return without exception set

It is really annoying, because I can not figure out where the problem is. I am pretty new in Python, but I read that it has something to do with C-2-Python interpreter. Can you please help me solve this problem? It is for reading photodiode input using MCP3008 ADC. Thank you a lot!


Solution

  • Solved! The library I used is no longer supported for new RasPi OS. If you have the same problem, you have to use this command sudo pip3 install adafruit-circuitpython-mcp3xxx instead of git clone https://github.com/adafruit/Adafruit_Python_GPIO.git. Of course, you have to make some other steps to reach full functionality of MCP3008. For more info or steps do not hesitate to contact me. I'll help if I'll know how.