Some mad stuff to remember - UART2, GPIO, Python and stuff

I am running an DietPi (downloaded on dietpi -> NanoPi Air) on a NanoPi Air. These are the huddles I had:


Theme: UART2 and i2c0

Afer reading and reading and reading the web, there was one simple solution. And I mean really simple!!

Error: serial.serialutil.SerialException: Could not configure port: (5, 'Input/output error')

connected to the SSH:

sudo vim /boot/armbianEnv.txt

and changed this line:

overlays=usbhost2 usbhost3 uart2 i2c0

Theme: GPIO with python3

After trying to use RPi.GPIO or NPi.GPIO or RPi.GPIO_NP or whatever, I always got the error that my NanoPi Air isn't a Raspberry or with the NPi.GPIO not an NanoPI device. Which is really strange. 
 
Error Message:
RuntimeError: This module can only be run on a Raspberry Pi!
RuntimeError: This module can only be run on a NanoPi! 
But one of the RPi.GPIO helped me out:
https://github.com/auto3000/RPi.GPIO_NP/blob/master/INSTALL.txt
 
If you are using armbian on NanoPi Neo/Neo2:
1. clone repository and install to your home dir

git clone https://github.com/auto3000/RPi.GPIO_NP
cd RPi.GPIO_NP

2. install library

python3 setup.py install
or if you are using python 2.x
python2 setup.py install

3. Test installation. Run python console and try to import RPi.GPIO
python
>>> import RPi.GPIO as GPIO

if above command didn't throw error everything should be ok.
If you received:
File "<stdin>", line 1, in <module>
ImportError: No module named 'RPi.GPIO'

try:
>>> import RPi._GPIO

If you still get error something went wrong. Try to reboot and check if import works OK.

5. Run your first python code using GPIO:

create file test.py:
nano ./test.py

paste following code:
#!/usr/bin/python3
import RPi.GPIO as GPIO
import time
led = 12
GPIO.setmode(GPIO.BOARD)
GPIO.setwarnings(False)
GPIO.setup(led,GPIO.OUT)
i=0
while i<10:
print("LED on")
time.sleep(1)
print("LED off")
GPIO.output(led,GPIO.LOW)
time.sleep(1)
i=i+1

save file with ctrl+x and run the code:
sudo ./test.py
please remeber /dev/mem is writeprotected under Armbian and only root can access this device. This feature prevents anyone (even those in kmem group) to access GPIO ports! Original RPi.GPIO library under raspbian use /dev/gpiomem that allow anyone access to gpio memory connected to GPIO and forbids access to other addresses. At the moment there is no solution to freely access GPIO ports.

Theme: GPIO with bash

Source: https://raspberrypi-aa.github.io/session2/bash.html

#   Exports pin to userspace
echo "18" > /sys/class/gpio/export                  

# Sets pin 18 as an output
echo "out" > /sys/class/gpio/gpio18/direction

# Sets pin 18 to high
echo "1" > /sys/class/gpio/gpio18/value

# Sets pin 18 to low
echo "0" > /sys/class/gpio/gpio18/value 

Keine Kommentare:

Kommentar veröffentlichen

Datei in einer windows.wim image ändern

 Um Dateien in einer Datei.wim zu ändern, und zwar nicht im 1. Index sondern 2. öffnet man Powershell (ich habs jetzt im admin Modus gestart...