In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-25 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly introduces how to use Fedora IoT to light LED lights, the article is very detailed, has a certain reference value, interested friends must read it!
What is Fedora IoT?
Fedora IoT is one of the goals of the current Fedora project and plans to become a complete version of Fedora. Fedora IoT will be a system running on ARM (currently limited to aarch74) devices (such as raspberry pie), as well as on the x86x64 architecture.
Fedora IoT is based on OSTree development, just like Fedora Silverblue and previous Atomic Host.
Download and install Fedora IoT
The official Fedora IoT image will be released with Fedora 29. But in the meantime, you can download an image based on Fedora 28 to do this experiment. (LCTT translation note: as of the release of this translation, Fedora 29 has been released, but the IoT version has not been released with it, maybe it will be released with Fedora 30? )
You have two ways to install this system: either use the dd command to burn the SD card, or use the fedora-arm-installer tool. Fedora's Wiki provides more information about setting up physical devices for IoT. In addition, you may need to resize the third partition.
After inserting the SD card into the device, you need to create a user to complete the installation. This step requires a serial connection or a HDMI monitor and keyboard to interact with the device.
When the system installation is complete, the next step is to set up the network connection. Using the user login system you just created, you can complete the network connection settings in one of the following ways:
If you need to configure your network manually, you may need to execute a command similar to the following, and you need to make sure you set the correct network address:
$nmcli connection add con-name cable ipv4.addresses\
192.168.0.10 Compact 24 ipv4.gateway 192.168.0.1\
Connection.autoconnect true ipv4.dns "8.8.8.8, 1.1.1.1"\
Type ethernet ifname eth0 ipv4.method manual
If you have a DHCP service running on your network, you may need a command similar to the following:
$nmcli con add type ethernet con-name cable ifname eth0
GPIO Interface in Fedora
Many tutorials on GPIO on Linux focus on the traditional GPIO sysfis interface. This interface is no longer recommended, and the upstream Linux kernel community intends to remove it completely due to security and other issues.
Fedora no longer compiles this traditional interface into the kernel, so there is no / sys/class/gpio file on the system. This tutorial uses a new character device / dev/gpiochipN provided by an upstream kernel. This is the current way to interact with GPIO.
To interact with this new device, you need to use a library and a series of command-line interface tools. Commonly used command-line tools such as echo and cat do not work properly on this device.
You can install the command line interface tools by installing the libgpiod-utils package. The python3-libgpiod package provides the corresponding Python library.
Use Podman to create a container
Podman is a container runtime environment with a command line interface similar to Docker. A big advantage of Podman is that it doesn't run any daemons in the background. This is especially useful for devices with limited resources. Podman also allows you to start containerization services using systemd unit files. In addition, it has many other functions.
We use the following two steps to create a container:
Hongmeng official Strategic Cooperation to build HarmonyOS Technology Community
Create a hierarchical image that contains the required packages.
Create a new container using a hierarchical mirror.
First create a Dockerfile file with the following contents. This tells Podman to build our hierarchical image based on the available * * Fedora images. Then update the system and install some software packages:
FROM fedora:latestRUN dnf-y updateRUN dnf-y install libgpiod-utils python3-libgpiod
In this way, you have completed the pre-generation configuration of the image, which is based on Fedora and contains software packages that interact with GPIO.
Now you can run the following command to build your basic image:
$sudo podman build-- tag fedora:gpiobase-f. / Dockerfile
You have successfully created your custom image. In this way, instead of rebuilding the environment every time, you can do your work based on the image you create.
Use Podman to get the job done
To confirm whether the current image is ready, run the following command:
$sudo podman imagesREPOSITORY TAG IMAGE ID CREATED SIZElocalhost/fedora gpiobase 67a2b2b93b4b 10 minutes ago 488MBdocker.io/library/fedora latest c18042d7fac6 2 days ago 300MB
Now, start the container and do some actual experiments. Containers are usually isolated and cannot access the host system, including the GPIO interface. Therefore, you need to mount the container in the container when you start it. You can use the-device option in the following command to solve the problem:
$sudo podman run-it-name gpioexperiment-device=/dev/gpiochip0 localhost/fedora:gpiobase / bin/bash
After running, you enter the container that is running. Before continuing, here are some container commands. Type exit or press Ctrl+D to exit the container.
Show that all existing containers can run the following commands, including those that are not currently running, such as the one you just created:
$sudo podman container ls-aCONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES64e661d5d4e8 localhost/fedora:gpiobase / bin/bash 37 seconds ago Exited (0) Less than a second ago gpioexperiment
Create a new container using the following command:
$sudo podman run-it-name newexperiment-device=/dev/gpiochip0 localhost/fedora:gpiobase / bin/bash
If you want to delete a container, you can use the following command:
$sudo podman rm newexperiment lights the LED lamp
You can now use the containers you have created. If you have already exited from the container, start it again using the following command:
$sudo podman start-ia gpioexperiment
As mentioned earlier, you can use the command-line tools provided by the libgpiod-utils package in Fedora. To list the available GPIO chips, use the following command:
$gpiodetectgpiochip0 [pinctrl-bcm2835] (54 lines)
To get a list of connections for a specific chip, run:
$gpioinfo gpiochip0
Note that there is no correlation between the number of physical pins and the number of connections printed by the previous command. What matters is the BCM number, as shown in pinout.xyz. It is recommended that you do not use a connection without a corresponding BCM number.
Now, connect the LED to physical pin 40, which is BCM 21. Remember: the short leg (negative pole, called cathode) of the LED must be connected to the raspberry pie GND pin with a 330ohm resistance, and the long leg (anode) to the physical pin 40.
Run the following command to light up LED and press Ctrl + C to close:
$gpioset-- mode=wait gpiochip0 2131
To light up for a while, add the-b (running in the background) and-s NUM (how many seconds) parameters, as shown below. For example, to light up LED for 5 seconds, run the following command:
$gpioset-b-s 5-- mode=time gpiochip0 2131
Another useful command is gpioget. It can obtain the state of the pin (high or low) and can be used to detect buttons and switches.
The above is all the contents of the article "how to use Fedora IoT to light up LED lights". Thank you for reading! Hope to share the content to help you, more related knowledge, welcome to follow the industry information channel!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.