Torizon Python for Dummies

Hiya Team,

We are pretty new to using torizon as a platform and we are coding predominantly in python. When we use the vscode extension to setup a new python project, we are able to deploy the hello world script no problem. The problems only start when we try and add new packages.

We have been struggling with gpiod, but now we have tried other packages and we dont seem to be able to get even things like numpy on the device.

Would really appreciate a more in depth rundown on how to add these without such headache. We are using a veridin imx8+ on a mallow carrier board.

Any help would be greatly appreciated!

1 Like

How are you trying to add the packages?

The easiest way to add a package is through the requirements-debug.txt file in your project files. This file is called from your dockerfile during deployment. You can also add packages through the torizonPackages.json

If you are trying to access the GPIO on the mallow carrier, you will need to expose all the gpio chips as devices or you will run into some errors (this is if you are using the chipiterator function, which you probably will be).

To expose the gpio chips, add them under “devices” in the docker-compose.yml file. Here is an example:

version: “3.9”
services:
emittancescanner-debug:
build:
context: .
dockerfile: Dockerfile.debug
image: ${LOCAL_REGISTRY}:5002/project:${TAG}
ports:
- 6502:6502
- 6512:6512
devices:
- dev/gpiochip0
- dev/gpiochip1
- dev/gpiochip2
- dev/gpiochip3
- dev/gpiochip4
- dev/gpiochip5

1 Like

Greetings @btj2,

Adding on to what @justincunningham has said we do have an article here on adding additional packages in our extension: Add Packages, Libraries and Tools | Toradex Developer Center

We have been struggling with gpiod, but now we have tried other packages and we dont seem to be able to get even things like numpy on the device.

Just to clear up a possible misconception here. With our extension you’re developing a container that will have your application along with all it’s dependencies. You’re not exactly installing these packages directly on the device itself. This container will the run on the device but these packages will only be available in that specific container. Just wanted to clear that up since it does make a difference.

Best Regards,
Jeremias

Hi there,
I got it working thank you ! I am struggling to find material on how to control the pin for python code. Is there a simple example script to trigger the pin on and off?

Kind regards,

Ben

Is there a simple example script to trigger the pin on and off?

With gpiod there’s some example code from us here: https://github.com/toradex/torizon-samples/blob/bookworm/gpio/python/main.py

There’s also the python3-gpiod documentation which has some references here: Python gpiod | loliot by HHK

Best Regards,
Jeremias

Hi Jeremias,

Thank you for that, i got it working also. I have just added opencv to my container and I was wondering how to view the output image by rtsp? is there any material that you would recommend to make this work easier for my python application ?

Kind regards,

Ben

We have this example here: https://github.com/toradex/torizon-samples/tree/bookworm/tflite/tflite-rtsp

Otherwise I’m sure you can find other example code out there online.

Best Regards,
Jeremias