DIY Guide: Using Raspberry Pi Zero for Flight Control and Video Transmission

DIY Guide: Using Raspberry Pi Zero for Flight Control and Video Transmission

Although it is possible to buy finished products that look better and have stronger performance specifications, the joy of creating and optimizing according to one’s own needs while learning through experimentation embodies the spirit of makers.

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

1. Hardware Section

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

  • Raspberry Pi Zero v1.3

  • OTG table & USB WiFi dongle (Xiaomi WiFi)

  • Raspberry Pi Camera Module v1.3

  • LattePanda With LCD Display

DIY Guide: Using Raspberry Pi Zero for Flight Control and Video 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 software and hardware resources, making it very suitable for some hardware-related creative projects. If we treat it as a small version of the Raspberry Pi, is that really 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 prepare to power through the GPIO interface, connect the USB WiFi dongle via the OTG interface, and set up a web server to transmit video streams to the LattePanda. At the time of writing this article, the new version of RPi Zero W (Wireless) has been released, which adds Bluetooth wireless modules, making it more convenient, but I don’t have it, and it’s hard to buy T_T.

1.2 Power Supply for Zero

“There must be 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 it is not recommended (lacking protective circuits). Powering through OTG can refer to my previous article “Playing with Raspberry Pi Zero using a Data Cable”, which will not be elaborated here. Since we cannot use a power bank with a data cable on the flight control, we prepare to connect the GPIO pins for reverse power supply. Here, we need a stable 5V voltage, otherwise, there is a risk of damaging the Zero!

DIY Guide: Using Raspberry Pi Zero for Flight Control and Video Transmission

As shown, pin 2 connects to +5V, and pin 6 connects 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, specialized power expansion modules can also be used, such as Pimoroni Zero LiPo:

DIY Guide: Using Raspberry Pi Zero for Flight Control and Video Transmission

1.3 RPi Camera Module

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

The v1.3 uses the OmniVision OV5647 camera component, supporting 5 million pixels, and the actual effect is quite good and clear.

It is worth noting that the size of the RPi and RPi Zero CSI camera interfaces is different; the v1.3 default only has the larger RPi interface ribbon cable, and if you want to use it on the Zero, you need to purchase an additional ribbon cable. An acrylic bracket also needs to be purchased.

1.4 Wireless Communication

Since we are operating outdoors, where signal attenuation is minimal, our solution here is OTG line + Xiaomi portable WiFi (using mt7601u chip) for wireless transmission. The reason for using Xiaomi WiFi is that the mt7601u has low power consumption, and stability/heat/transmission speed and distance are acceptable; we may switch to a module or add an antenna later.

DIY Guide: Using Raspberry Pi Zero for Flight Control and Video Transmission

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

DIY Guide: Using Raspberry Pi Zero for Flight Control and Video Transmission

2. Software Section

2.1 Choosing the Operating System for Zero

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 chose to operate in headless mode, which does not require a graphical interface. Here, I will talk about two systems: Raspbian and DietPi.

2.1.1 DietPi

This is the Raspberry Pi operating system that I have always used and highly praised. There are related introductions, but it has not been updated for a long time, and now it has added many new features. Its features include performance optimization, quick and easy automatic installation and configuration of various software, painless learning and getting started with Raspberry Pi, and the author’s scripts are well written, allowing you to learn a lot.

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

According to the method described 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 added the related settings file for the usb0 virtual network card in /etc/network/interfaces. After connecting the Host with MicroUSB, the LAN connection can be recognized normally when powered on, but

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

  • Windows can ping Zero, but reverse ping has no response.

The above problems do not exist when using Raspbian Lite. After being reminded, I used Wireshark software to analyze the local network packet capture and the USB2TTL serial module for direct debugging to find and analyze the problem. The result is as follows: Wireshark can capture the ICMP protocol packets when the host pings Zero, but there is no response in the reverse direction. Finally, I tried closing the Windows firewall to resolve it, suspecting that Raspbian works normally and that the ping command was not tested, so I assumed that the firewall did not need to be turned off, which led to a lot of detours.

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

At this time, still unable to access the internet, ping www.baidu.com prompts unknown host, directly pinging the IP address is ok, cat /etc/resolv.conf did not find the correct DNS server address. After manually adding dns-nameservers 114.114.114.114 to the interfaces file, the problem was resolved, and it could connect to the internet and update the system normally.

Note that after plugging and unplugging Zero, it may not be able to connect to the internet. At this time, turn off or restart the host network card's network sharing and wait a moment.

After completing the above settings, installing Lighttpd web server, php, etc., the reboot failed, and there was no output from the serial port. This was the case repeatedly. After a long silence and crashes, I gave up. After reading the DietPi script source code, improving and modifying related settings, and reviewing many Gadget-related driver instructions and other documentation, I was ready to submit a commit on GitHub, and then I returned to the starting point, feeling helpless.

Note that when using OTG, it is recommended to use Raspbian. In a formal environment (GPIO power supply + USB wireless network card), DietPi is fine.

2.1.2 Raspbian Jessie Lite

After calming down, we return to the Raspbian Lite recommended by the Raspberry Pi Foundation, which has no graphical interface and does not come pre-installed with various Bloatware. The previous article was based on this for demonstration, and it is relatively complete in all aspects. The installation and use process was quite 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. The web front end for controlling the Raspberry Pi camera supports motion detection, scheduled shooting, and 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 the Zero and the fact that not many advanced features are needed, a lighter web server is chosen: Lighttpd. DIY Guide: Using Raspberry Pi Zero for Flight Control and Video Transmission

Originally, I was obsessed with DietPi because it could 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… Eventually, I successfully installed it on Raspbian following the official method.

  1. Enable RPi Camera: sudo raspi-config command

  2. Correctly connect the camera: the golden finger faces down (the same applies to 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:

DIY Guide: Using Raspberry Pi Zero for Flight Control and Video Transmission

Use the Backspace key to delete; the Del key cannot be used. As shown, 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 filled with the Raspberry Pi’s IP address, 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 want the simplest image interface, you can access [pi_ip]/rcam/min.php

Zero Image Transmission Section

DIY Guide: Using Raspberry Pi Zero for Flight Control and Video Transmission

They are a. OTG line + USB WiFi dongle (RT3070 as an example, unable to find Xiaomi WiFi); b. Zero body; c. RPi Camera + ribbon cable; d. CH340G TTL to USB module, which can be used for debugging while providing 5V power to the Raspberry Pi through the GPIO pins. The official version only requires two wires to power the Zero.

LattePanda Obtaining Real-time Images from Zero (Web Page)

DIY Guide: Using Raspberry Pi Zero for Flight Control and Video Transmission

The frame rate and clarity are quite good; the photos are somewhat blurry, but everyone can make do with it. If it is not clear, just imagine. You only need to open the web page in LattePanda and enter the address [pi_ip/dietpicam]. Note to set it to Default Stream in System for smoother streaming than MJPEG Stream.

Mobile Devices Obtaining Real-time Images from Zero (Web Page)

DIY Guide: Using Raspberry Pi Zero for Flight Control and Video Transmission

Basically the same as the PC version; note that it seems to only support streaming to one device at a time.

Mobile Devices Obtaining Real-time Images from Zero (APP)

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

DIY Guide: Using Raspberry Pi Zero for Flight Control and Video Transmission

DIY Guide: Using Raspberry Pi Zero for Flight Control and Video Transmission

PC Software Obtaining Real-time Images from Zero (To be supplemented)

Since RPi-Cam-Web-Interface supports video streaming, we can use VLC or write our own software (for example, a GUI program written in QT) to directly play the video stream. Due to some issues encountered, related content will be supplemented later.

Summary

Through various methods, we have obtained real-time images transmitted from the Raspberry Pi Zero, and both clarity and frame rate are quite good, meeting our project expectations. Outdoors, it allows the Raspberry Pi or LattePanda to establish a wireless hotspot, providing a means of communication between the two, and of course, WiFi Direct can also be used, pending verification.

Source: Raspberry Pi Chinese Station Author: knowncold

DIY Guide: Using Raspberry Pi Zero for Flight Control and Video Transmission

Focusing on robots, drones/cars, the “Robot Network” that engineers pay attention to

Leave a Comment

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