19 Wenet TX Payload Instructions
Mark Jessop edytuje tę stronę 2023-10-08 14:25:19 +10:30

Last Updated: 2023-10-8

This page documents the steps required to set up a Raspberry Pi (2A, Zero, ZeroW) as a Wenet transmitter. These instructions assume that you already have a Raspbian installation set up on a Raspberry Pi, and have SSH access to it.

WARNING - Wenet still depends on the Python PiCamera library, which is starting to be deprecated. For now support is still available in Raspbian bullseye, but I'll look into updating to whatever comes next. There's some initial support for the PiCamera2 library now in this repository (wenet_picamera2_gps.py), though it should be treated as 'very very beta'.

IMPORTANT NOTE: On Raspberry Pi units with Bluetooth (Pi 3, Pi Zero W), you will need to enable the pi3-disable-bt hardware overlay. Refer to this guide (about halfway down the page) for more information. In short, you will probably want to add the dtoverlay=pi3-disable-bt line to your /boot/config.txt file.

1. Required Hardware

1.1 Radio Module

The Wenet codebase currently supports using either a HopeRF RFM22B or a HopeRF RFM98W radio module as the FSK modulator. The RFM22B is now obsolete, so the RFM98W option is probably better.

UpuTronics sells a suitable RFM98W Raspberry Pi shield, with shield sizes suitable for a RPi2 Model A, and a Pi Zero/W.

In both cases, the shield must be modified with the addition of a single wire, connecting the DIO2 pin (GPIO2 on the RFM98W) to the TXD pin (pin 8) on the Raspberry Pi's header. We use this wire to modulate the RFM98W in 'direct asynchronous' 2-FSK mode.

RFM98W Shield Modifications

The above image shows how this can be implemented on one of the UpuTronics shields. A length of re-work wire is used to join the two pins, and is held down with silicone.

1.2 Camera

The Wenet code is intended to be used with a PiCamera. Both the v1, v2 and HQ cameras have been used and work well.

1.3 GPS Unit (Optional)

The Wenet transmitter code can optionally get payload position information from a uBlox GPS module (accessed via USB-Serial), and overlay the position on the downlinked image. This must be a uBlox module, as we use uBlox protocol to ensure the module is in airborne mode.

USB-connected uBlox GPS units are available fairly cheaply on eBay, under the name 'VK-172 G-mouse'. These have a uBlox 7 chipset (or at least a very good clone of one...) and have been tested up to 37km altitude. They appear as an ACM serial device, and later on in the setup process a udev rule is added to provide a symlink to the serial port at /dev/ublox.

Mount them away from everything else in your payload box (especially the camera cables!) to avoid GPS lock issues due to RFI.

2. Software Installation

Install the required dependencies from apt-get using:

$ sudo apt-get install git build-essential vim python3-dev python3-numpy python3-picamera python3-crcmod python3-spidev python3-pip python3-serial python3-rpi.gpio imagemagick

2.1 SSDV

We need fsphil's 'slow-scan digital video' compression utility available on the system. From the home directory, run:

$ git clone https://github.com/fsphil/ssdv.git
$ cd ssdv 
$ make
$ sudo make install

2.2 Downloading Wenet

Run:

$ cd
$ git clone https://github.com/projecthorus/wenet.git
$ sudo cp ~/wenet/tx/99-usb-serial.rules /etc/udev/rules.d/

In turn, this:

  • Grabs a copy of the Wenet git repository
  • Copies udev rules to be able to easily access a uBlox GPS unit at /dev/ublox

Finally, we need to compile the LDPC Encoding library:

$ cd ~/wenet/tx/
$ gcc -fPIC -shared -o ldpc_enc.so ldpc_enc.c

2.3 Raspi-Config

Run sudo raspi-config, and under Interfacing options, enable:

  • Camera (This is called Legacy-Camera in Raspbian bullseye)
  • SPI
  • Serial (When prompted, set 'Enable Login Shell' to NO, and 'Serial Port Hardware Enabled' to YES.)

2.4 GPS-NTPD Sync (Optional)

If required, the attached GPS unit can be used to synchronise the system clock, via NTPd's Shared Memory Interface.

To use this, we need to grab the ntpdshm python library from pip, and also install the NTPD server:

$ sudo apt-get install ntp
$ sudo pip3 install ntpdshm

The NTP config file (/etc/ntp.conf) then need to be edited, and the following lines added at the end of the file:

server 127.127.28.2 minpoll 4 maxpoll 4
fudge 127.127.28.2 time1 0.09 flag1 1 refid PYTH stratum 2

Restart NTPD using sudo systemctl restart ntp

3. Testing

3.1 FSK Modulator

This section assumes you have a Wenet Receiver available.

Before testing with a camera, is is useful to transmit some test images to check the FSK modulator is working. The test_images directory contains a set of test images that you can transmit. Run:

$ cd ~/wenet/test_images
$ python3 compress_test_images.py

This will produce SSDV-compressed versions of the JPEG images, and may take a few minutes to run (depending on the RPi board in use).

Now, we need to start up the radio module:

$ cd ~/wenet/tx
$ python3 init_rfm98w.py --frequency <freq>

Replace <freq> with a frequency in MHz that you are licensed to use. Note that the transmitted signal is over 300 kHz wide, so is in breach of the ISM regulations in most countries. Here in Australia, we run our Wenet payloads on 443.500 MHz, under an Advanced amateur radio licence, though it's possibly to run this with even a Foundation level license.

A carrier should now be transmitted a bit above the supplied frequency.

We can now start transmitting the test images using:

$ python3 tx_test_images.py

Hopefully images will start appearing on your Wenet receiver!

3.2 GPS Check

To check that the RPi can communicate with an attached uBlox GPS unit, run:

$ cd ~/wenet/tx
$ python3 ublox.py /dev/ublox

A large amount of JSON objects should be written to the terminal, containing the various GPS parameters (latitude, longitude, time, etc)

If you set up NTPD earlier, you can run ntpq -p, and you should see a SHM(2) entry in the list of NTP peers.

3.3 Pi Camera Check

The WenetPiCam.py file contains a test script which will capture and transmit images. This can be run with:

$ python3 WenetPiCam.py YOURCALL

Debug information on the scripts current actions will be written to the terminal. Images should be captured, re-sized, and transmitted via the FSK modulator.

3.4 Setting the Focus

$ raspivid -t 0 -l -o tcp://0.0.0.0:3333

VLC: tcp/h264://your.pi.ip.address:3333

3.5 Hardware Watchdog

https://diode.io/raspberry%20pi/running-forever-with-the-raspberry-pi-hardware-watchdog-20202/

4. Setup for Automatic Transmissions

The tx_picam_gps.py Python script will automatically capture images and GPS data, overlay GPS position information at the top of the image, and transmit images. Note that this needs to be run as root, as it will try and write into NTPD shared memory by default to set the system time.

The start_tx.sh script in ~/wenet is designed to be run from /etc/rc.local on boot, and starts up the radio and the tx_picam_gps.py script. Edit this file and adjust the MYCALL and TXFREQ parameters as necessary.

You can then add the following line into /etc/rc.local (just before the exit 0 line) to start it at boot:

/home/pi/wenet/start_tx.sh &

Some further configuration may be required depending on your payload setup. The main things you may want to change are the capture & transmit resolutions, and whether horizontal/vertical flip is used (depends on your camera orientation). These settings are all around line 138.

You should now be able to reboot the Raspberry Pi, and have it transmit images automatically!