NanpPi, NetBSD, and Pika Pika
https://i.gyazo.com/4fc0db51aa873a9395d317be96180510.png]
Introduction
In recent years, there have been a lot of shiny and beautiful PCs, especially gaming PCs.
We want our microcomputers to be shiny too, don't we?
With the NanoPi, you can do just that!
So, let's try it!
NanoPi NEO2
https://wiki.friendlyarm.com/wiki/images/2/27/NEO2_pinout-02.jpg
Friendly ARM's NanoPi NEO2 is a one-board microcontroller that packs a lot of functions into a small body.
The NanoPi NEO2 has the following features. The features in red are especially recommended.
SoC: Allwinner's 64-bit H5 quad-core (Cortex-A53)
GPU: Mail450
RAM: 512M DDR3
I/O: microSD, Ethernet 10/100/1000M, USB, Serial, GPIO, Audio
Size: 40 x 40mm, 13g
OS: UbuntuCore 16.04, Debian, NetBSD
In addition to the official UbuntuCore, the device can run on a variety of operating systems, including Armbian.
It is usually run on Linux OS, but of course it can run on NetBSD, which is known for the spirit of "Of course it runs NetBSD. This time, we will use NetBSD as the OS.
Using GPIO with NetBSD
In NetBSD, GPIO devices are recognized as follows, and the device file for GPIO is /dev/gpio*.
code:dmesg
$ grep gpio /var/run/dmesg.boot
sunxigpio0 at simplebus1: PIO
gpio0 at sunxigpio0: 94 pins
sunxigpio0: interrupting on GIC irq 43
sunxigpio1 at simplebus1: PIO
gpio1 at sunxigpio1: 12 pins
sunxigpio1: interrupting on GIC irq 77
gpioleds0 at simplebus0: nanopi:green:pwr nanopi:blue:status
In order to use GPIO on NetBSD, you need to do some initial configuration.
First, add gpio=YES to /etc/rc.conf.
Furthermore, set the GPIO mode in /etc/gpio.conf as shown below.
Note that this setting can only be changed at boot time.
code:/etc/gpio.conf
## GPIO
gpio0 0 set out PA0
gpio0 1 set out PA1
gpio0 2 set out PA2
gpio0 3 set out PA3
gpio0 6 set out PA6
gpio0 11 set out PA11
gpio0 12 set out PA12
## for my Blinkt!
# gpio0 0 set out dat
# gpio0 2 set out clk
## NanoPi OLED hat
# gpio0 0 set in b1
# gpio0 2 set in b2
# gpio0 3 set in b3
gpioleds0 is. The built-in green LED (nanopi:green:pwr) and the blue LED (nanopi:blue:status). As described below, you can control the LED on/off by using the sysctl(8) command to change system-related variables.
For other GPIOs, you can use the gpioctl(8) command.
A C library is also available, which can be used with open and ioctl.
On NetBSD, the system hierarchy when using blinkt is as follows.
https://gyazo.com/f796568ced7bea775ae53c834299cdb8
Case 1:Display of load average by blue LED
First, let's try to display the load average using the built-in LED.
You can write the status of the LED with sysctl to make it blink easily.
code:loadavg.sh
while true
do
INTERVAL=uptime|awk '{print $(NF-2)}'|sed -e 's/,//'|sed -e 's/^/e(-/' -e 's/$/)/'|bc -l
echo ${INTERVAL}
sysctl -qw hw.led.nanopi_blue_status=1 #NetBSD NanoPi NEO sleep ${INTERVAL}
sysctl -qw hw.led.nanopi_blue_status=0 #NetBSD NanoPi NEO sleep ${INTERVAL}
done
The operation is shown in the following video; NanoPi NEO2 is located in the lower right corner of the screen.
https://youtu.be/C2xbhGp5R9c
Case 2:Knight2000 Challenge!
If you have a lot of LEDs connected to GPIOs, the first thing to make is the Knight2000 thing.
The pin assignments for this connection are as follows
table:pin assign
Pin# Name gpio0 dev#
3 PA12 12
5 PA11 11
12 PA6 6
15 PA3 3
22 PA1 1
The following shell script will cause the five blue LEDs to blink repeatedly in a constant direction.
code:knight_rider.sh
PINS="12 11 6 3 1"
while true
do
for l in $PINS
do
sudo gpioctl gpio0 $l 1
done
for l in $PINS
do
sudo gpioctl gpio0 $l 0
done
done
The operation is shown in the following video.
https://youtu.be/YL3kHWc577A
Full Color 8 LEDs: Blinkt!
Blinkt!" is a set of 8 full-color LEDs that can be connected to the 40-pin GPIO of the Raspberry Pi. 8 full-color LEDs can be controlled using only two GPIOs.
https://gyazo.com/c2d0b9273f0977a33beba637edcd7370
Blinkt!: 8 Full Color LEDs for Raspberry Pi 40pin GPIO (APA102)
The two GPIOs used in Blinkt! are DATA (pin 16) and CLOCK (pin 18), which are the data to be sent to the LEDs and the clock that specifies when to send the data, respectively.
We are supposed to send the value of data (orange) on the falling edge of the clock (blue).
It sends 8bit x 4 data per LED in the following order.
blightness(valid 5bit/8bit)
b
g
r
https://gyazo.com/ebb3b30d0bd5eedaa1cda52c04421fc0
Case 3:Blinkt! and shiny
Here, you can find GPIO.py written using gpioctl and GPIO.c, a python module version written in C. The former is for running the command every time.
The former is very slow because it executes the command every time.
So, we will use the latter to make it shine.
You can choose any two GPIO ports to use in NanoPi NEO2.
At this time, since we have specified the ports as DAT and CLK in blinkt.py, we need to change the port number to the port number we have connected Blinkt!
This time, we assigned the pins as follows.
table:pin assign
Pin# Name gpio0 dev#
DAT 16 PG8 88
CLK 18 PG9 89
In this case, we will specifically use the following patch. In this patch, we assign PG8 of the GPIO port of NanoPi NEO2 to DAT and PG9 to CLK.
code:blinkt.py.diff
% diff -u library/blinkt.py{.org,}
--- library/blinkt.py.org 2021-09-04 19:02:16.000000000 +0900
+++ library/blinkt.py 2021-09-04 19:02:30.000000000 +0900
@@ -7,8 +7,8 @@
__version__ = '0.1.2'
-DAT = 23
-CLK = 24
+DAT = 88
+CLK = 89
NUM_PIXELS = 8
BRIGHTNESS = 7
The operation is shown in the following video.
https://youtu.be/c4HuA0kCc2I
Furthermore, you can run multiple Blynkt!'s by connecting them to other GPIO's and making a modified version of blinkt.py.
Conclusion
How did you like it?
Now your NanoPi is ready to be used by
Now you can use your NanoPi as a shiny, young, and naive computer.
You can now use your NanoPi as a PC.
I really wanted to play with more devices using I2C, but unfortunately the current NetBSD for NanoPi NEO2 does not recognize I2C, so I can only play with GPIOs.
If I have another chance, I would like to shine with I2C.
References
My old artclies in Japanese.
Nano Pi Official
https://gyazo.com/ab412746069515fc60e2657b4f787d75