├── Dockerfile.template ├── README.md ├── gpio_example.py └── requirements.txt /Dockerfile.template: -------------------------------------------------------------------------------- 1 | # base-image for python on any machine using a template variable, 2 | # see more about dockerfile templates here: https://www.balena.io/docs/learn/develop/dockerfile/ 3 | FROM balenalib/%%BALENA_MACHINE_NAME%%-python:3.7-latest-build 4 | 5 | # Set our working directory 6 | WORKDIR /usr/src/app 7 | 8 | # Copy requirements.txt first for better cache on later pushes 9 | COPY requirements.txt requirements.txt 10 | 11 | # pip install python deps from requirements.txt on the resin.io build server 12 | RUN pip install -r requirements.txt 13 | 14 | # This will copy all files in our root to the working directory in the container 15 | COPY . ./ 16 | 17 | CMD ["python", "gpio_example.py"] -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Basic GPIO with Python on Balena 2 | This is a basic example of GPIO control on the Rasperry Pi using Python 3 | 4 | We use the GPIO board pin mapping and we also need few LEDs on two sets of GPIO pin: 5 | 6 | Set A: 3,5,7,8,10,11,12,13,15 (pin number) 7 | Set B: 16.18,19,21,22,23,24,26 (pin number) 8 | 9 | In this example, the LEDs on two sets will be switched between on and off after one sec. If set A is on then set B is off and vice versa. 10 | 11 | All you need to do is : 12 | 13 | * clone this repo locally and cd into the folder. 14 | * connect some LEDs to two pin sets 15 | * add the resin remote repo with `git remote add balena git@git.balena-cloud.com:myGithubName/myResinAppName.git` , with the correct github and app name, or just copy if from the top right hand corner of your device dashboard on resin.io. 16 | * now just `git push balena master` wait a minute or so for the code to upload and start. 17 | * enjoy the all the LED goodness... -------------------------------------------------------------------------------- /gpio_example.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | import RPi.GPIO as GPIO 3 | from time import sleep 4 | 5 | # Set GPIO mode: GPIO.BCM or GPIO.BOARD 6 | GPIO.setmode(GPIO.BOARD) 7 | 8 | # GPIO pins list based on GPIO.BOARD 9 | gpioList1 = [3,5,7,8,10,11,12,13,15] 10 | gpioList2 = [16,18,19,21,22,23,24,26] 11 | 12 | # Set mode for each gpio pin 13 | GPIO.setup(gpioList1, GPIO.OUT) 14 | GPIO.setup(gpioList2, GPIO.OUT) 15 | 16 | while True: 17 | # Change gpio pins in list 1 from low to high and list 2 from high to low 18 | GPIO.output(gpioList1, 1) 19 | GPIO.output(gpioList2, 0) 20 | sleep(1) 21 | 22 | # Change gpio pin in list 1 from high to low and list 2 from low to high 23 | GPIO.output(gpioList1, 0) 24 | GPIO.output(gpioList2, 1) 25 | sleep(1) 26 | 27 | # Reset all gpio pin 28 | GPIO.cleanup() -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | RPi.Gpio==0.7.1 2 | 3 | --------------------------------------------------------------------------------