Question about SPI and spidev

Hi, I’m new to Torizon. I’m trying to communicate with an SPI sensor using a verdin-imx8m-mini, and I’m having trouble enabling spidev in python . I’m working on Windows 11 and using VS Code extension.
I followed the steps from:

https://developer.toradex.com/linux-bsp/application-development/peripheral-access/spi-linux/#verdin

https://developer.toradex.com/torizon/application-development/use-cases/peripheral-access/how-to-use-spi-on-torizon/

When testing with /dev/verdin-spi-cs0 → spidev1.0, I get:

lrwxrwxrwx 1 root root 9 May 5 20:27 /dev/verdin-spi-cs0 → spidev1.0

Even running # spidev_test -D /dev/verdin-spi-cs0, I can see data frames being sent on the oscilloscope. However, when I try to import spidev in Python or install it from the requirements.txt file, I get an error.

How can I properly use SPI from Python in this environment?

You could try the example here :
RaspberryPIExample

So your problem is that you can’t import spidev library for python ? Can you supply the error ?

Yes, that’s the main problem.


When I try to run my python code I receive this error
I tried to install spidev over the requirements-local, requirements-debug and requirements-release txt and in the Dockerfile using pip and apt-get.
When I debug and try to install over requeriments-release.txt I had this message

Hi @LuisSerrano !

Welcome to the Toradex Community!

Could you please share the OS version you are currently using? You can find this information by running the tdx-info command on your module.

The issue you’re facing occurs because, by default, the container does not include the necessary cross-compilers. I was able to reproduce the issue here, and the key error message is:

15.41       aarch64-linux-gnu-gcc -Wsign-compare -DNDEBUG -g -fwrapv -O2 -Wall -g -fstack-protector-strong -Wformat -Werror=format-security -g -fwrapv -O2 -fPIC -I/home/torizon/app/.venv/include -I/usr/include/python3.11 -c spidev_module.c -o build/temp.linux-aarch64-cpython-311/spidev_module.o
15.41       error: command 'aarch64-linux-gnu-gcc' failed: No such file or directory
15.41       [end of output]

To resolve this, you’ll need to ensure that the cross-compilers and the required headers are available in the container. You can do this by updating your torizonPackages.json file as follows:

{
  "prodRuntimeDeps": [],
  "devRuntimeDeps": [
    "build-essential",
    "python3-dev"
  ]
}

Please try the solution above and let us know if it works or if you have any other doubts.

Best regards,
Daniel Morais

1 Like

Hi @daniel_m.tx I’m running

Distro name: NAME=“Torizon OS”
Distro version: VERSION_ID=7.2.0-build.13

Thank you, it works