My post [Luckfox RV1106 Linux Development Board Review] link:
1. Unboxing and testing
2. SDK acquisition and image compilation
3. GPIO Lighting
1. Access the Internet
The GPIO section of Luckfox also mentioned the method of controlling IO with Python, but the Buildroot image does not include Python. Then I saw the content of configuring Buildroot to add software packages through menuconfig in the Buildroot configuration section of the document, but when I checked the downloaded SDK directory, there was no relevant content in the corresponding location. After that, I asked a question in the Luckfox forum, and the administrator answered quickly: "The Python source code is not in the SDK."
Figure 4-1 There is no Buildroot related content in the SDK
So, I decided to plug in the TF card and switch to the Ubuntu image (the image compiled by me in the second review), and then tried to install Python in Ubuntu using apt, only to find that the development board could not access the Internet. It makes sense, the development board is a local area network built by RNDIS and PC, so of course it cannot access the Internet. The board has an RJ45 connector, and plugging the development board into the router should allow access to the Internet, but the router at home is hung on the wall, and it is troublesome to connect a long network cable. Later, I found a method on the Internet to share the network adapter of the PC connected to the Internet with the development board. The details are as follows:
First, share the network adapter in the Win10 system, and share the PC's Internet adapter (WLAN here) to the development board's RNDIS, which is Ethernet 3 in the figure below. However, after sharing, the IP address of RNDIS will become 192.168.137.1, which is an inevitable change in the shared network in Windows - there will also be a pop-up reminder when clicking Share.
Figure 4-2 Sharing the “Internet access” adapter in the PC to the RNDIS adapter
Next, we need to modify the static IP of the development board to the same network segment. Because the RNDIS of the development board does not have DHCP, it cannot automatically obtain an IP. Fortunately, the board has the ifconfig command, which can be used to modify it. Still, log in to the development board console through adb shell, and then enter the command:
# Modify the static IP of the development board
ifconfig usb0 192.168.137.2
# Set the gateway, which is the IP address of the RNDIS in the PC
route add default gw 192.168.137.1
Figure 4-3 Development board pinging Baidu IP result
At this point, the development board can access the Internet and ping Baidu IP successfully. However, the domain name cannot be used yet because the development board does not have a DNS service, so the last step is to edit the "/etc/resolv.conf" file and write: "nameserver 114.114.114.114".
Figure 4-4 Adding a domain name server IP
Figure 4-5 Result of pinging www.baidu.com
2. Python controls IO
The development board is connected to the Internet. Since it is an Ubuntu system, it can download software through apt, so I executed sudo apt update, sudo apt install python3. It turned out that the system image comes with Python3. Previously, when I used the "python" command, it prompted that it could not be found. I should use the "python3" command. However, it is still necessary for the development board to be able to access the Internet, because there is also pip to install Python packages.
According to the sample code in the document, you need to install the python-periphery library - note that the library name has the python- prefix. Looking at the code, I directly wrote periphery. As a result, I spent a long time and found out that the library name was wrong after searching on Baidu.
Figure 4-6 Python library on the development board Ubuntu system
The Python sample program in the document is as follows. It controls the output of IO55 and flips it, and then reads the value of IO54. However, there is a delay missing in the sample code. Without this delay, the LED will not turn off but remain on.
from periphery import GPIO
import time
Write_Pin = 55
Read_Pin = 54
Write_GPIO = GPIO(Write_Pin, "out")
Read_GPIO = GPIO(Read_Pin, "in")
try:
while True:
try:
Write_GPIO.write(True)
pin_state = Read_GPIO.read()
print(f"Pin state: {pin_state}")
# 示例没有这个延时,所以IO输出高观测不到,加上就可以闪烁灯了
time.sleep(1)
Write_GPIO.write(False)
pin_state = Read_GPIO.read()
print(f"Pin state: {pin_state}")
time.sleep(1)
except KeyboardInterrupt:
Write_GPIO.write(False)
break
except IOError:
print("Error")
finally:
Write_GPIO.close()
Read_GPIO.close()