Using Raspberry Pi Zero for Flight Control and Transmission

Source: Raspberry Pi Chinese Station Author: knowncold

Using Raspberry Pi Zero for Flight Control and Transmission

Although ready-made products can be purchased, which are more aesthetically pleasing and have stronger performance specifications, the joy of learning through tinkering, optimizing and modifying according to one’s own needs, and enjoying the creation is the true maker spirit.

This project uses existing hardware to aim to use the Raspberry Pi Zero as a flight control transmission system. Initially, I thought it would be simple, but I encountered some issues with software adaptation that troubled me for a long time.

1. Hardware Part

First, let’s take a look at the hardware list:

  • Raspberry Pi Zero v1.3

  • OTG table & USB Wi-Fi dongle (Xiaomi Wi-Fi)

  • Raspberry Pi Camera Module v1.3

  • LattePanda With LCD Display

Using Raspberry Pi Zero for Flight Control and Transmission

1.1 Introduction to RPi Zero

The Zero is compact (can be used as a keychain), has sufficient performance, and is compatible with Raspberry Pi’s software and hardware resources, making it very suitable for some hardware-related creative projects. If it is used as a smaller version of the Raspberry Pi, is it really just a case of buying the box and discarding the pearl? Let’s take a look at its specifications:

  • 1GHz single-core CPU

  • 512MB RAM

  • Micro-USB OTG port (can be used for power supply)

  • Micro-USB power port

  • Raspberry Pi 40-pin GPIO pins

  • CSI camera interface (only supports v1.3)

Here we plan to power through the GPIO interface, connect the USB Wi-Fi dongle via the OTG interface to communicate with the LattePanda, and set up a web server to transmit video streams. At the time of writing this article, the new version of RPi Zero W (wireless) has already been released, adding a Bluetooth wireless module for greater convenience, but I don’t have one, and it’s hard to buy T_T.

1.2 Power Supply for Zero

“You need power — Genesis”

Although the official documentation only states to use the Micro USB PWR port for power supply, during use, it can be found that the OTG port and GPIO pins can also be used, but are not recommended (lacking protection circuits). For OTG power supply, please refer to my previous article “Playing with Raspberry Pi Zero using a Data Cable,” which will not be elaborated on here. Since you can’t just use a power bank and a data cable on the flight controller, I plan to connect the GPIO interface for reverse power supply using Dupont wires, which requires a stable 5V voltage, otherwise there may be a risk of damaging the Zero!

Using Raspberry Pi Zero for Flight Control and Transmission

As shown in the figure, pin 2 is connected to +5V, pin 6 is connected to ground.

For more discussions and circuit diagrams, please visit:

  • How do I supply power through the GPIO?

  • Power Through GPIO

  • How do I power my Raspberry Pi?

Of course, you can also use dedicated power expansion modules, such as Pimoroni Zero LiPo:

Using Raspberry Pi Zero for Flight Control and Transmission

1.3 RPi Camera Module

The Zero only supports RPi Camera v1.3, as there was no v2 camera module at the time of the Zero’s release. For detailed information about the RPi camera module, please be sure to read the eLinux page.

v1.3 uses the OmniVision OV5647 camera component, supporting 5 million pixels, with good results in practice, quite clear.

It is important to note that the sizes of the RPi and RPi Zero CSI camera interfaces are different. The v1.3 default only has a cable suitable for the larger RPi interface, so if you want to use it on the Zero, you need to purchase an additional cable. An acrylic bracket also needs to be purchased.

1.4 Wireless Communication

Because the operation is outdoors, the signal attenuation is small. Our solution here is OTG line + Xiaomi portable Wi-Fi (using MT7601U chip) for wireless transmission. The reason for using Xiaomi Wi-Fi is that the MT7601U has low power consumption, and its stability/heat generation/transmission speed and distance are acceptable. In the future, we may switch to a module or add an antenna.

Using Raspberry Pi Zero for Flight Control and Transmission

Of course, you can also choose ready-made modules, such as Red Bear IoT pHAT:

Using Raspberry Pi Zero for Flight Control and Transmission

2. Software Part

2.1 Choosing the Zero Operating System

The operating system is like the driver of a car; choosing a suitable and convenient system for the Zero is like adding wings to a tiger. Due to project needs, we choose to operate in headless mode without a graphical interface. Here, I will talk about two systems: Raspbian and DietPi.

2.1.1 DietPi

DietPi has always been the Raspberry Pi operating system that I have used and highly praised. There have been some introductions related to it, but it hasn’t been updated for a long time. Now it has added many new features. Its characteristics include performance optimization, the ability to quickly and conveniently install and configure various software automatically, and painless learning to get started with Raspberry Pi. Additionally, the author’s scripts are well written, and you can learn a lot from them.

Although DietPi supports Zero, it does not support the OTG virtual network card very well. Therefore, I have been trying to adapt it recently and have encountered many problems, getting stuck here for a long time, and recording as follows.

Following the method in “Playing with Raspberry Pi Zero using a Data Cable,” I changed the cmdline.txt and config.txt files in the boot partition to enable the USB gadget ether function and pre-added the settings file related to the usb0 virtual network card in /etc/network/interfaces. After connecting the MicroUSB to the Host, it can recognize the LAN connection after normal power-up, but

  • Using ssh to log into Zero, even if network sharing is enabled, Zero cannot access the internet;

  • Windows can ping Zero, but reverse ping does not respond.

The above issues do not exist when using Raspbian Lite. After being reminded, I used Wireshark software to analyze the local area network packets and directly debugged with the USB2TTL serial module to find and analyze the problem. The results are as follows: Wireshark can capture the ICMP protocol packets pinging Zero from the host, but there is no response in the reverse direction. Finally, I tried to turn off the Windows firewall to solve it, suspecting that Raspbian was used normally and did not test the ping command, so I assumed that it did not need to turn off the firewall. I went around a big bend here.

Note, when enabling the network card obfuscation mode to listen to data packets, the ping command will return (DUP!), indicating that the data packet is duplicated.

At this point, I still cannot access the internet. The ping www.baidu.com command prompts unknown host, but directly pinging the IP address works. The cat /etc/resolv.conf command did not find the correct DNS server address. After manually adding dns-nameservers 114.114.114.114 in the interfaces file, the problem was solved, and I could access the internet and update the system normally.

Note, after plugging and unplugging Zero, it may be unable to connect to the internet. In this case, just close/reopen the host network card's network sharing and wait a moment.

After completing the above settings and installing the Lighttpd web server, php, etc., it failed to restart, and there was no output from the serial port. Despite repeated attempts, I was met with silence and crashes, so I gave up. After reading the DietPi script source code, perfecting and modifying related settings, and reviewing many Gadget-related driver descriptions and other documentation, I was ready to submit a commit on GitHub, and then I returned to square one, feeling utterly helpless.

Note, when using OTG, it is recommended to use Raspbian. In a formal environment (GPIO power supply + USB Wi-Fi dongle), DietPi is fine.

2.1.2 Raspbian Jessie Lite

After calming down, we return to the official recommended Raspbian Lite from the Raspberry Pi Foundation, which has no graphical interface and does not come pre-installed with various bloatware. The previous articles were based on this for demonstration, and everything was relatively complete. The installation and usage process was relatively smooth.

2.2 RPi Cam Web Interface

For camera image transmission and control, the first thought is to use the RPi Cam Web Interface to manage the camera and transmit images:

Web based interface for controlling the Raspberry Pi Camera, includes motion detection, time lapse, and image and video recording. A web front end for controlling the Raspberry Pi camera, supporting motion detection, timed shooting, as well as image and video recording.
  • eLinux wiki introduction: http://elinux.org/RPi-Cam-Web-Interface

  • GitHub project homepage: https://github.com/silvanmelchior/RPi_Cam_Web_Interface

  • Related discussions: http://www.raspberrypi.org/forums/viewtopic.php?f=43&t=63276

The project architecture is as follows, mainly including motion — responsible for motion detection, raspimjpeg — image capture and video stream transmission, Web Server (Apache|Nginx|Lighttpd) — web control interface. Due to the performance limitations of Zero and the fact that not many advanced features are needed, I chose the lighter Lighttpd for the web server. Using Raspberry Pi Zero for Flight Control and Transmission

I was originally obsessed with DietPi because it could automatically install and configure various software with one click, and RPi-Cam-Web-Interface was included. However, due to unresolved issues, I manually operated according to Daniel Knight’s script, but still failed… Ultimately, I successfully installed it on Raspbian following the official method.

  1. Enable RPi Camera: sudo raspi-config command

  2. Correctly connect the camera: golden fingers facing down (the same for LattePanda)

  3. Install RCWI:

# Update the system and install git 
sudo apt update && sudo apt dist-upgrade && sudo apt install git 
# Download the source code and install 
git clone https://github.com/silvanmelchior/RPi_Cam_Web_Interface.git 
cd RPi_Cam_Web_Interface 
chmod u+x *.sh 
sudo ./install.sh

During this process, a command line dialog box will pop up:

Using Raspberry Pi Zero for Flight Control and Transmission

Using the Backspace key to delete, and the Del key cannot be used. As shown in the figure, you can access the Web Interface by entering [pi_ip]:80/rcam in the browser, and it will run automatically on boot. Here, [pi_ip] is the IP address of the Raspberry Pi, which is 192.168.137.2 in my case.

Note:

  • To turn off the red LED on the camera, you can add disable_camera_led=1 in the /boot/config.txt file.

  • If you only want the simplest image interface, you can access [pi_ip]/rcam/min.php.

Zero Image Transmission Part

Using Raspberry Pi Zero for Flight Control and Transmission

They are a. OTG cable + USB Wi-Fi dongle (using RT3070 as an example, I couldn’t find Xiaomi Wi-Fi); b. Zero body; c. RPi Camera + cable; d. CH340G TTL to USB module, which can be used for debugging while providing 5V power to the Raspberry Pi through GPIO pins. The formal version only needs two wires to power the Zero.

LattePanda Obtaining Zero Real-Time Images (Web Page)

Using Raspberry Pi Zero for Flight Control and Transmission

The frame rate and clarity are quite good; the image is a bit blurry, but it’s acceptable to look at. If you can’t see clearly, just imagine it. You only need to open the webpage in LattePanda and enter the address [pi_ip/dietpicam]. Note to set it to Default Stream in System for smoother than MJPEG Stream.

Mobile Devices Obtaining Zero Real-Time Images (Web Page)

Using Raspberry Pi Zero for Flight Control and Transmission

Basically the same as the PC version, but it seems to only support streaming to one device at a time.

Mobile Devices Obtaining Zero Real-Time Images (APP)

You can use the free version of IP Cam Viewer Lite (supports Android and iPhone), or you can buy the Pro version, but the Lite version is sufficient. ICVL natively supports RPi-Cam-Web-Interface, as shown in the figure to add the camera and modify related parameters.

Using Raspberry Pi Zero for Flight Control and Transmission

Using Raspberry Pi Zero for Flight Control and Transmission

PC Software Obtaining Zero Real-Time Images (To Be Supplemented)

Since RPi-Cam-Web-Interface supports video streaming, we can use VLC or write our own software (such as a QT-based GUI program) to play the video stream directly. Due to some issues encountered, I will improve the related content later.

Summary

Through various methods, we have obtained real-time images transmitted from the Raspberry Pi Zero, with clarity and frame rates quite good, meeting our project expectations. Outdoors, the Raspberry Pi or LattePanda can establish a wireless hotspot to provide communication means between the two. Of course, WiFi Direct is also an option, pending verification.

Scan to follow MBH Maker Hive, the maker’s home is waiting for you to join!!

Using Raspberry Pi Zero for Flight Control and Transmission

Leave a Comment

Your email address will not be published. Required fields are marked *