Adafruit_Blinka: OSError running sample script for MCP3008 on Libre Computer aml-s905x-cc "Le Potato"

I am running into an OSError trying to run sample code for MCP3008 on the Libre Computer aml-s905x-cc “Le Potato”. I have made slight changes to sample code, changing the pin numbers, putting the print statements in a loop, and I’ve tried busio and extendid bus with the same results .

Here is the script I am trying to run:

import time
import busio
import digitalio
import board
import adafruit_mcp3xxx.mcp3008 as MCP
from adafruit_mcp3xxx.analog_in import AnalogIn
from adafruit_extended_bus import ExtendedSPI as SPI

# create the spi bus
#spi = busio.SPI(clock=board.P23, MISO=board.P21, MOSI=board.P19)
spi = SPI(0, 0)

# create the cs (chip select)
cs = digitalio.DigitalInOut(board.P22)

# create the mcp object
mcp = MCP.MCP3008(spi, cs)

# create an analog input channel on pin 0
chan = AnalogIn(mcp, MCP.P0)

while True:
	print('Raw ADC Value: ', chan.value)
	print('ADC Voltage: ' + str(chan.voltage) + 'V')
	time.sleep(5)

Here is the error:

angus@aml-s905x-cc:~/scripts$ python3 mpc3008_test.py 
Traceback (most recent call last):
  File "/home/angus/scripts/mpc3008_test.py", line 23, in <module>
    print('Raw ADC Value: ', chan0.value)
  File "/usr/local/lib/python3.10/dist-packages/adafruit_mcp3xxx/analog_in.py", line 60, in value
    self._mcp.read(self._pin_setting, is_differential=self.is_differential) << 6
  File "/usr/local/lib/python3.10/dist-packages/adafruit_mcp3xxx/mcp3xxx.py", line 91, in read
    spi.write_readinto(self._out_buf, self._in_buf)
  File "/home/angus/.local/lib/python3.10/site-packages/busio.py", line 396, in write_readinto
    return self._spi.write_readinto(
  File "/home/angus/.local/lib/python3.10/site-packages/adafruit_blinka/microcontroller/generic_linux/spi.py", line 133, in write_readinto
    data = self._spi.transfer(list(buffer_out[out_start : out_end + 1]))
  File "/home/angus/.local/lib/python3.10/site-packages/Adafruit_PureIO/spi.py", line 420, in transfer
    ioctl(self.handle, SPI._IOC_MESSAGE, spi_ioc_transfer)
OSError: [Errno 22] Invalid argument

System Info:

angus@aml-s905x-cc:~/scripts$ neofetch
           `:+shmNNMMNNmhs+:`              angus@aml-s905x-cc 
        .odMMMMMMMMMMMMMMMMMMdo.           ------------------ 
      /dMMMMMMMMMMMMMMMmMMMMMMMMd/         OS: Ubuntu MATE 22.04.2 LTS aarch64 
    :mMMMMMMMMMMMMNNNNM/`/yNMMMMMMm:       Host: aml-s905x-cc 
  `yMMMMMMMMMms:..-::oM:    -omMMMMMy`     Kernel: 6.1.21-04467-gc1663d8fbf25 
 `dMMMMMMMMy-.odNMMMMMM:    -odMMMMMMd`    Uptime: 9 hours, 14 mins 
 hMMMMMMMm-.hMMy/....+M:`/yNm+mMMMMMMMh    Packages: 2404 (dpkg), 9 (snap) 
/MMMMNmMN-:NMy`-yNMMMMMmNyyMN:`dMMMMMMM/   Shell: bash 5.1.16 
hMMMMm -odMMh`sMMMMMMMMMMs sMN..MMMMMMMh   Resolution: 1680x1050 
NMMMMm    `/yNMMMMMMMMMMMM: MM+ mMMMMMMN   DE: MATE 1.26.0 
NMMMMm    `/yNMMMMMMMMMMMM: MM+ mMMMMMMN   WM: Metacity (Marco) 
hMMMMm -odMMh sMMMMMMMMMMs oMN..MMMMMMMh   Theme: Yaru-MATE-dark [GTK2/3] 
/MMMMNNMN-:NMy`-yNMMMMMNNsyMN:`dMMMMMMM/   Icons: Yaru-MATE-dark [GTK2/3] 
 hMMMMMMMm-.hMMy/....+M:.+hNd+mMMMMMMMh    Terminal: tilix 
 `dMMMMMMMMy-.odNMMMMMM:    :smMMMMMMd`    CPU: (4) @ 1.512GHz 
   yMMMMMMMMMms/..-::oM:    .+dMMMMMy      Memory: 1573MiB / 1924MiB 
    :mMMMMMMMMMMMMNNNNM: :smMMMMMMm:
      /dMMMMMMMMMMMMMMMdNMMMMMMMd/                                 
        .odMMMMMMMMMMMMMMMMMMdo.                                   
           `:+shmNNMMNNmhs+:`

angus@aml-s905x-cc:~/scripts$ pip3 list | grep adafruit
adafruit-circuitpython-busdevice 5.2.4
adafruit-circuitpython-mcp3xxx   1.4.14
adafruit-circuitpython-pixelbuf  2.0.0
adafruit-circuitpython-requests  1.13.0
adafruit-circuitpython-seesaw    1.11.7
adafruit-circuitpython-typing    1.9.0
adafruit-extended-bus            1.0.2
angus@aml-s905x-cc:~/scripts$ pip3 list | grep Adafruit
Adafruit-bitfield                1.5.1
Adafruit-Blinka                  8.16.1
Adafruit-GPIO                    1.0.3
Adafruit-PlatformDetect          3.42.0
Adafruit-PureIO                  1.1.10

I was made aware of this issue by this forum post:

https://hub.libre.computer/t/problems-accessing-mcp3008-via-spi-invalid-argument/1844

About this issue

  • Original URL
  • State: open
  • Created a year ago
  • Comments: 15 (5 by maintainers)

Most upvoted comments

hiya we dont have any plans to have Blinka use the kernel interfaces for any sensors: most folks are not able to compile a kernel with new drivers or understand using device trees, and adding new kernel drivers is non-trivial. finally, tbh i find many of the kernel drivers are minimal and unable to be expanded or improved. if there’s bugs its a much bigger effort to get upstreamed C code patches than PRing against the python libs we maintain. we dont necessarily need root perms, altho its easier than researching each distro’s method of granting GPIO access.

so - the best way we’ve found to get hundreds of different devices working is the raspi way: expose the standard digital io gpio, i2c and spi devices and then control those within python. if someone from libre can document how to do that on their distro, we can point to that doc & it will make users pretty happy 😃