Translate

Showing posts with label Raspberry Pi. Show all posts
Showing posts with label Raspberry Pi. Show all posts

Tuesday 3 November 2020

Raspberry Pi400

Well, the latest in the line of Raspberry Pi's is here, the Pi 400 ...
Lord knows why people seem to like unboxing videos ... is it a kind of bragging?

No idea. The kids seem to like it , so here's some pictures...

Oh look a box from Farnell...











It's got some packing in it ... the excitement... 









... the product box...










... behold the Pi400...










... the official power supply, and official mouse ... I can hardly contain myself (if you have detected a shade of sarcasm, you're correct)








Our lovely marketing lady, Jilly.. "Where's the rest of it?"

And LP showing the rear panel. 










Plugged in and booted..










Official mouse ...










.. set up and updated...









So that's the silly unboxing rubbish dealt with. I would have made a video, except I couldn't be bothered, just close your eyes and picture it, with some ghastly music playing over the top. 

Now to the real stuff...

What do you really get for your £90? 

It's a Pi4 with 4GB of ram, only rather than running at 1.5GHz, the same ARM v8 Cortex-A72 is running a bit faster at 1.8GHz, all packaged inside a chiclet keyboard, a 16GB memory card, loaded with the Raspberry OS, a 3A power supply and the offcial mouse.

A review... It performs just like a Pi4, so really that's just fine. The chiclet keyboard works nicely. The offical mouse is ,well, barely adequate, it works, but ergonomics had passed this one by. 
You get one less USB than on a Pi4, and the GPIO port is available on the rear. 

Why would you want one?

I actually bought this for two reasons. One is it's easier to set up projects (destined for a Pi4) on this, as it's compact, and avoids having (yet) even more wires and keyboards hanging about in the workshop.. similar reasons I have an arduino uno board for developing projects that will eventually exist on a stand alone ATMEGA328.

The second is to run the excellent HAMPI radio ham image by Dave Slotter W3DJS. This should give me a flexible, small, quiet, low power platform to run some ham radio experiments on. 








Oh, and yes, there's a third reason. It reminds me of the computers I had in the 80's .. the Oric-1 , C64 and Spectrum. It gives me a nice warm feeling.

Monday 8 June 2020

Raspberry Pi Zero NOAA finishing touches.

I'm chuffed with the Pi Zero receiver in the last post, and I'm going to install it in my workshop in Evesham, to take over the job done by the laptop and my FT-817.

I needed to pretty it up a bit.

I found a suitable small case to house the Pi, the SDR and an old LNA (previously failed, but a new amp chip and all is well) 

I got to thinking.... 

Nice if we had some status LEDs on the front panel.

Power (obv.), READY (we've got a pass schedule, so ready to go when a bird pops up), AOS (Acquisition of Satellite) and PROC (processing images).

A front panel is created and printed on a piece of clear acetate, which is then stuck to the front panel with lacquer. It's OK if you don't look too closely...











To drive the LEDs, there are two bash scripts to alter ...

schedule_all.sh and receive_and_process.sh

both are found in ~weather/predict/

schedule_all.sh needs the following lines at the end..

#Switch READY led ON
sudo echo "24" > /sys/class/gpio/export
sudo echo "out" > /sys/class/gpio/gpio24/direction
sudo echo "1" > /sys/class/gpio/gpio24/value

receive_and_process.sh now looks like this..

#!/bin/bash

# $1 = Satellite Name

# $2 = Frequency
# $3 = FileName base
# $4 = TLE File
# $5 = EPOC start time
# $6 = Time to capture

# reads and creates folder with current date / time (i.e 05-30-2019_07-48 *windows friendly*)

NOW=$(date +%m-%d-%Y_%H-%M)
mkdir /home/pi/weather/pics/Folder${NOW}
#switch on AOS led, switch off READY LED
sudo echo "22" > /sys/class/gpio/export
sudo echo "out" > /sys/class/gpio/gpio22/direction
sudo echo "1" > /sys/class/gpio/gpio22/value
sudo echo "0" > /sys/class/gpio/gpio24/value
sudo timeout $6 rtl_fm -f ${2}M -s 60k -g 45 -p 55 -E wav -E deemp -F 9 - | sox -t wav - $3.wav rate 11025
PassStart=`expr $5 + 90`

if [ -e $3.wav ]

then
#switch off AOS led, switch on PROC led
sudo echo "0" > /sys/class/gpio/gpio22/value 
sudo echo "23" > /sys/class/gpio/export
sudo echo "out" > /sys/class/gpio/gpio23/direction
sudo echo "1" > /sys/class/gpio/gpio23/value
/usr/local/bin/wxmap -T "${1}" -H $4 -p 0 -l 0 -o $PassStart ${3}-map.png
/usr/local/bin/wxtoimg -m ${3}-map.png -e ZA $3.wav ${3}.png
/usr/local/bin/wxtoimg -m ${3}-map.png -e CLASS $3.wav ${3}.CLASS.png
/usr/local/bin/wxtoimg -m ${3}-map.png -e MCIR $3.wav ${3}.MCIR.png
/usr/local/bin/wxtoimg -m ${3}-map.png -e MSA $3.wav ${3}.MSA.png
/usr/local/bin/wxtoimg -m ${3}-map.png -e MSA-precip $3.wav ${3}.MSAPRECIP.png
/usr/local/bin/wxtoimg -m ${3}-map.png -e MCIR-PRECIP $3.wav ${3}.MCIRPRECIP.png

fi


# PROC LED off

sudo echo "0" > /sys/class/gpio/gpio23/value

# copies files to the new folder and deletes the original ones

cp /home/pi/weather/*.png /home/pi/weather/pics/Folder${NOW}/
rm /home/pi/weather/pics/Folder${NOW}/*-map.png
rm /home/pi/weather/*.png
rm /home/pi/weather/*.wav
wput -B -u --dont-continue --reupload --tries=5 --binary --verbose --reupload ftp://mywebspaceusername:mypassword@myurl ~/weather/pics/Folder*/*.*
# READY led on
sudo echo "1" > /sys/class/gpio/gpio24/value

You can see from the script that the GPIO pins 22,23 and 24 are used for the LEDs (The POWER LED is driven from the supply). Because only one LED is on at anytime, we can cheat and use only one 220 ohm current limiting resistor to a ground pin, and drive the LEDs directly from the GPIOs, a huge saving of ~3p. Every little helps...

GPIO pin 22 is the AOS LED drive, 23 is PROC, and 24 is READY.

The finished receiver...


In situ, waiting for a pass...

        


Saturday 6 June 2020

More NOAA APT shenanigans , the £25 NOAA receiver


"Shenanigans" ... that probably doesn't translate well... Wiki says "silly or high-spirited behaviour; mischief."
... anyway ...

There's a bit of talk on the noaa and Raspberry Pi forums, that the new Pi Zero (W) hasn't got enough poke to run a NOAA receiver... so we shall see....

£9.80 is duly shelled out on a Pi Zero W from the lovely people at PiHut.

I thought I'd just clone the existing memory card ... no such luck, the drivers for the Zero's wifi aren't included in Stretch. 

So a new install of Raspberry OS lite is created, and set up. You can follow the instructions here.

You'll need to install wput and lsftp if you want to upload to your webspace.

sudo apt-get wput
sudo apt-get lsftp
You also need to create the pic directory

mkdir ~/weather/pics

Things didn't exactly work out....

That's no good at all...


















Now, there are issues with predict on the newer OS. 

When you run predict, and enter your station "callsign", lat, long and height, quitting out leaves the screen in an odd condition, logout, and log back in again.

I had to run predict a number of times before I could get it to swallow all the data... keep running it until it finally shows all fields correctly filled in.

In the previous picture, the receiver had thought it was at 0 degrees long, and 0 degrees lat ... just off the coast of africa! 

After finally getting predict sorted ....  superb pictures are received.

So ... a £14 SDR receiver, and a £9.80 Pi Zero! well, nearly... You'll need a micro SD card and an antenna, but we've saved some money on the computer!

Excellent!

Now my good friend Ben is keen to implement a receiver in Gloucester, and is going this route... once he's up and running, I'll add another page on the NOAA extension to this website, so you can enjoy his pictures as well!





Saturday 11 April 2020

NOAA APT reception on Raspberry Pi



Having been caught by the APT bug again recently (as you may have seen in a previous post) I thought I have a go at building a stand alone system.
I've had some results using my ageing Icom IC-706MKIIB and WXtoIMG on my Ubuntu computer, connected to my ham-radio 2m antenna, but this is less than ideal.
The Evesham receiver uses my employer's wide band Discone antenna, and manages to pull some decent signals in mostly, but doesn't have the required receiver bandwidth, as it's using my FT-817 under CAT control.

OK, Lets start with an antenna....

A QFH antenna would be perfect, but are difficult to make accurately. I found a superb article on a V-dipole antenna here. Some aluminium was duly ordered, and an antenna formed. Tests with the IC-706 gave much improved results. 

The antenna was mounted to a box, using some ordinary chock-block, and also added a low noise RF pre-amp, and bias-tee to power the whole thing from the co-ax (I eventually shortened that piece of co-ax looped round!)








Some pipe clips were fitted so it would be easy to mount.











The box was sealed from the elements with some liquid rubber.












A low current LED was also added to show the presence of bias.












The Receiver

Raspberry Pi 3 Model B+
I loved the idea of a self-contained receiver. It can sit on the shelf, doing it's thing. Some parts were duly procured, a small case, a Raspberry Pi 3 Model B+, an appropriate micro SD card, and a slightly posher SDR tuner with a TXCO (big mistake).


I followed this Instructable to get the basic receiver up and running. It didn't work, so I've updated it...

Grab yourself a fresh install of Raspian stretch lite. I did try a later Raspbian, but Predcit doesn't play nicely with it. Set up SSH, because it helps...

sudo raspi-config

and set up your Pi if you want to change the password, sort out the wifi, I always expand the filesystem too... Allow the Pi to reboot.

then

sudo apt-get update
sudo apt-get upgrade
sudo reboot

So everything's up to date, once we're going again...

sudo apt-get install libusb-1.0 cmake git sox at predict libxft2:armhf

sudo nano /etc/modprobe.d/no-rtl.conf

and add the following to the text file.


blacklist dvb_usb_rtl28xxu
blacklist rtl2832
blacklist rtl2830

CTRL+X to save and quit.

cd ~
git clone https://github.com/keenerd/rtl-sdr.git
cd rtl-sdr/
mkdir build
cd build
cmake ../ -DINSTALL_UDEV_RULES=ON
make
sudo make install
sudo ldconfig
cd ~
sudo cp ./rtl-sdr/rtl-sdr.rules /etc/udev/rules.d/

sudo reboot

wget http://www.wxtoimgrestored.xyz/beta/wxtoimg-armhf-2.11.2-beta.deb
sudo dpkg -i wxtoimg-armhf-2.11.2-beta.deb

Now reboot, and plug in your SDR....

sudo rtl_test

You should see something like the following...

pi@raspberrypi:~ $ rtl_test
Found 1 device(s):
  0:  Generic, RTL2832U, SN: 77771111153705700

Using device 0: Generic RTL2832U
Found Rafael Micro R828D tuner
Supported gain values (29): 0.0 0.9 1.4 2.7 3.7 7.7 8.7 12.5 14.4 15.7 16.6 19.7 20.7 22.9 25.4 28.0 29.7 32.8 33.8 36.4 37.2 38.6 40.2 42.1 43.4 43.9 44.5 48.0 49.6 
Sampling at 2048000 S/s.

Info: This tool will continuously read from the device, and report if
samples get lost. If you observe no further output, everything is fine.

Reading samples in async mode...

Press CTRL+C to get out of that ... 

As the original instructable says, if you get any errors there, you'll need to troubleshoot them...


You can now type

predict

and follow the instructable from part 3, until you get to "Once all three scripts have been created, we need to make the executable, by issuing the following commands:"

You'll need to add sudo ...

sudo chmod +x *.sh

Now you can proceed with crontab-e as described...

OK, except thing's weren't OK.

Every time I recorded I just got static :(

Nothing, nada.

I checked my dongle on my main PC, and it worked great. On the Raspberry Pi, it passed the rtl_test every time.... I was convinced there was something incompatible with the "posh" SDR receiver. This project stopped here, for about a year... then Covid-19 struck, and it's time to resurrect it!

So I bit the bullet and purchased the cheapest RTL dongle I could find....

Bingo...!

I modified the receive_and_process_satellite script to create some prettier pictures, add some friendly folder names, put the received files there, delete the .wav and map files, and chuck the lot onto my web space. I also added samba on to the raspberry pi to make accessing it directly a doddle.

#!/bin/bash

# $1 = Satellite Name
# $2 = Frequency
# $3 = FileName base
# $4 = TLE File
# $5 = EPOC start time
# $6 = Time to capture

# reads and creates folder with current date / time (i.e 05-30-2019_07-48 *windows friendly*)
NOW=$(date +%m-%d-%Y_%H-%M)
mkdir /home/pi/weather/Folder${NOW}

sudo timeout $6 rtl_fm -f ${2}M -s 60k -g 45 -p 55 -E wav -E deemp -F 9 - | sox -t wav - $3.wav rate 11025
PassStart=`expr $5 + 90`
if [ -e $3.wav ]
then
/usr/local/bin/wxmap -T "${1}" -H $4 -p 0 -l 0 -o $PassStart ${3}-map.png
/usr/local/bin/wxtoimg -m ${3}-map.png -e ZA $3.wav ${3}.png
/usr/local/bin/wxtoimg -m ${3}-map.png -e NO $3.wav ${3}.NO.png
/usr/local/bin/wxtoimg -m ${3}-map.png -e MCIR $3.wav ${3}.MCIR.png
/usr/local/bin/wxtoimg -m ${3}-map.png -e MSA $3.wav ${3}.MSA.png
fi

# copies files to the new folder and deletes the original ones
cp /home/pi/weather/*.png /home/pi/weather/Folder${NOW}/
rm /home/pi/weather/Folder${NOW}/*-map.png
rm /home/pi/weather/*.png
rm /home/pi/weather/*.wav
wput -B -u --dont-continue --reupload --tries=5 --binary --verbose --reupload ftp://yourusername:andpassword@yourwebspaceprovider.com/ ~/weather/Folder*/*.*

The Raspberry Pi, Bias T (getting it's 5 volt supply from the raspberry Pi itself), and the SDR receiver are all mounted up in a small case. Sadly I didn't notice the Raspberry Pi had moved to an odd angle before the epoxy set :( ... nevermind. 







The case has an attractive smoked top, which allows me to see the status LEDs. Workshop penny shown for scale.










And finally Mrs Doz states the antenna can live on the corner of the shed.  Mr Pigeon agrees.




















.... and quite unbelievably, whilst the antenna was on the ground during assembly....













... it managed to receive this!

Saturday 28 March 2020

Hospital radio streaming codec and monitor.

Things have been getting a bit, well, unreliable at the hospital radio studio of late. We've been plagued with power outages, and things don't recover well.

Mainly the old Ubuntu 16 box, which supplies shoutca.st with the MP3 stream.

It usually comes back on OK, but half the time fails to run the darkice service on start-up. No amount of fiddling the cron job that starts the service has helped.

What's needed is a system that checks and monitors itself, and attempts to repair what's broken.

Here's what I've got in mind.

Two Raspberry Pi's, one transmitting, one receiving. The receiver will be monitored to ensure that the stream is up.

The Pi's audio will be fed into and internet-equipped Arduino of some description, which will do the monitoring for us.

It'll work something like this:


  • If the received audio is ok, do nothing. All is well.
  • If the received audio is missing, check there's audio coming in to the transmitter. If there isn't then there's nothing we can do except to flash a "something's up" LED to get someone to fix it.
  • If the received audio is not present, but there's audio to the transmitter, check there's internet access; If there isn't there's little we can do, except for flash a "something's up" LED and wait for it to come back. If there is, then we need to take some action:


  1. Shut down and restart the receiver, just in case it's crashed. If that doesn't work, then ...
  2. Shut down and restart the transmitter, just in case that's crashed.


OK, so there are a good few guides on getting internet radio receivers to run on a headless Pi. I've tried a couple, and have found one that is very tolerant of dodgy internet connections, it's called mplayer, it's a bit processor hungry for what it is, but runs on a model A+ Pi I have.  It comes back if the internet goes missing as soon as it recovers, and starts reliably on boot. I did this a while back, and it's been sat on the workshop shelf for ages, reliably receiving :)

It's dead easy to install..

apt-get install mplayer

add a cron job...

crontab -e

and add the following line...

@reboot     sleep 29; nohup mplayer -loop 0 http://188.165.192.5:8525/stream 2>&1 > /dev/null

(replacing the IP address and mount point with your own, unless you want to listen to Cotswold hospital radio!)

You may need to adjust the output volume.. Just type

alsamixer

adjust as required, then type

sudo alsactl store

to store the setting.

Now we need to add a bit of Python script in to safely reboot the monitor receiver in the event of a failure, and also add a shutdown function, so we can safely shut our unit down, without risking corruption of the memory card.

We are going to use the Pi's GPIO pins 18 and 23. Pulling 18 low will instigate a safe shutdown. Pin 23 will force a shutdown and restart.

I've copied the code from here, but duplicated it here as well, just in case it ever goes missing.

First off SSH into the Pi...

Once logged in, type

mkdir Scripts

cd Scripts

touch shutdown_pi.py

sudo nano shutdown_pi.py

Then cut and paste this code into the editor.

#!/bin/python
# Simple script for shutting down the raspberry Pi at the press of a button.
# by Inderpreet Singh https://www.element14.com/community/docs/DOC-78055/l/adding-a-shutdown-button-to-the-raspberry-pi-b

import RPi.GPIO as GPIO
import time
import os

# Use the Broadcom SOC Pin numbers
# Setup the Pin with Internal pullups enabled and PIN in reading mode.
GPIO.setmode(GPIO.BCM)
GPIO.setup(18, GPIO.IN, pull_up_down = GPIO.PUD_UP)
GPIO.setup(23, GPIO.IN, pull_up_down = GPIO.PUD_UP)

# Our function on what to do when the button is pressed
def Shutdown(channel):
        os.system("sudo shutdown -h now")
def Restart(channel):
        os.system("sudo shutdown -r now")

# Add our function to execute when the button pressed event happens
GPIO.add_event_detect(18, GPIO.FALLING, callback = Shutdown, bouncetime = 2000)
GPIO.add_event_detect(23, GPIO.FALLING, callback = Restart, bouncetime = 2000)

# Now wait!
while 1:
        time.sleep(1)


Press CTRL + X and yes to save and exit

now type

sudo nano /etc/rc.local

and add this line just above the last exit 0

python /home/pi/Scripts/shutdown_pi.py &

now safely shutdown the pi

sudo shutdown now

wait for a minute and remove the power.

Remove the memory card and make an image of it and keep that safe, just in case...

Job done.

The transmitter is a new Raspberry Pi 3, and I followed the instructions here to load up darkice. I don't need to run icecast, as this is provided to us by remotely by shoutca.st, I just need to send the stream to them. I also ignored the warning about not installing the latest version of Raspbian. Seems to work great, never fails to start reliably, and seems to be tolerant of errant internet connections. You'll need an external USB sound card, as the pi's inbuilt card can't record.

Also, add in the shutdown and reboot python script in the same manner as before.

Image the memory card just in case!

Now our incoming audio is balanced, so we need a balanced line receiver, a buffer for the received audio monitoring, and whilst we're there, a couple of little drivers for some VU meters (because meters are cool), which we can also use to feed our Arduino monitor.

As an aside, I've now made the jump to Kicad, as since Autodesk have purchased Eagle, they no longer wish to honour my original Cadsoft licence, without incurring unwanted expense.

A circuit is conjured up ...



A board designed... 

And modelled ...
And turned into reality using toner transfer.
Loving Kicad...

U1 and U2 form the balanced to unbalanced audio receiver, and it's output level is adjusted by RV3. This then feeds the transmitting Pi's external sound card. There's also a buffer (U2A) which feeds a small monitoring amp. ICU2B is a variable gain precision rectifier, the output of which is used to drive the VU meter, and also feed one of the Arduino's A to D converters.

The same circuit is also duplicated and used to buffer the audio from our receiving Pi to drive the monitoring amp, and to drive a VU meter and the Arduino. 

There's a regulated +/- 15V supply. As it turns out I had a suitable switched mode supply, with +/- 12V and 5V outputs, so I utilised that, and just bypassed the regulators.

An Arduino nano was pressed into service, to do the monitoring and control.


Received rectified monitor audio is passed from the analogue PCB from the VU drive circuit to A0 , rectified transmitted audio is received likewise, and fed to A3. A front panel mounted LED is connected to Digital pin 3, to serve as our error indicator. I'll also make the Arduino Nano's USB interface available on the rear panel to facilitate debugging/ updating as required.

An Ethernet module (EN28J60) is connected to the Arduino's SPI interface, and is powered from a 3.3V regulator derived from the main +5V supply. The EN28J60 consumes around 120mA, and that's more than the available 3.3V supply on board the nano. The EN28J60 module is provided with network access from the same hub that distributes the network to the Raspberry Pi's.

Two additional outputs (D5 & D6) on the Arduino are used to pull a GPIO pin low on the respective Pi to initiate a graceful reboot, and D7 is diode "anded" to shutdown the two Pi's. A push button is connected to D2 to shut down the system. 

If it all goes really badly wrong, I've also added two reset buttons on the front panel to manually hard reset the Raspberry Pi's (and arduino, via a diode "and").

D4 is coupled back to the arduino's reset pin, to reset the controller completely. This is coded to happen if we fail to obtain a DHCP lease more than 5 times.
The VU illumination is connected to D8 via a BC547 transistor. This is used to flash the VU illumination during shutdown to give the user some feedback that shutdown is in progress.

In the event of failure of the monitor audio, the transmit audio is checked.

If the transmit audio has failed, the error LED on the front panel will flash 3 times. The monitor circuit will repeat these tests until audio is resumed.

If the monitor audio has failed, and transmit audio is present, the controller checks internet connectivity. If the internet connectivity is not present, attempts are made to restore DHCP. If this process fails, the fault is presumed to be external, and the error led will flash 5 times, followed by illuminating permanently. If the internet does not recover after 5 DHCP renew attempts, the controller will restart and repeat the process.

If the monitor audio has failed, TX audio present, and internet OK, two possibilities remain. Either the monitor receiver computer has crashed, or the TX computer has crashed. Firstly the controller will shut down and restart the monitor computer. If this fails , the TX computer is restarted.


A board is designed, but I've made it up on perfboard...










Arduino code can be found on my git https://github.com/andydoswell/transmitter-monitor

Power is supplied to the whole rack from a switched mode supply, recovered from some redundant equipment... It supplies +/-12V and 5V. Excellent.

Putting things together and running some tests, and there's an irritating 4KHz whistle on the audio, both transmitted and on the in built monitor amp... nasty

Scoping up the outputs from the power supply shows there's a 4KHz tone superimposed on our 5V rail. It's about 170mV, and enough to cause the annoying whistle. Tests show this isn't down to a failure in the supply (I suspected caps, but changing them out made no discernible improvement)

A simple C-L-C filter is quickly made up from some junque parts, and greatly improves the situation.

Much improved.

And the finished product, ready for installation once this damn virus goes away...