Streaming internet radio on FM

An FM radio showing RDS radio station name 'fip'Years ago I remember thinking how amazing it was that the Raspberry Pi could be turned into an FM radio transmitter with nothing more than a short piece of wire and some code. Back then you could only transmit audio files in a very particular format and it very much seemed like a novelty.

Fast forward to 2022 and it seems things have moved on a bit. Reading a blog post about reviving old radio pagers, I finally caught up with rptix. This suite allows you to turn an old Raspberry Pi into a little radio transmitter that can broadcast in a stunning range of formats and frequencies: FM, AM and SSB radio, slow-scan TV, pager data and many, many more.

Now you probably won’t be doing this as it’s probably illegal to broadcast on most frequencies where you live, and if you find a legal frequency you’d need to add some filtering before attaching any kind of physical antenna, or indeed a wire, to pin 4. The only other things you’d need are an old Raspberry Pi, an internet connection and an old FM radio (with RDS if you have one).

Years ago in Brighton, I’m told, someone used to illegally rebroadcast my favourite radio station, the French music station fip, on FM. I was curious to know if a Raspberry Pi could do the same trick, albeit on a much smaller scale, within a couple of rooms.

I didn’t do this, of course, but if you were so minded, it looks like this is, hypothetically, possible. You could even broadcast RDS station name and text too. This is what you might, hypothetically, do:

Install rpitx per the instructions atΒ https://github.com/F5OEO/rpitx

Install sox:

sudo apt-get install sox

Install lame and some associated tools for handling mp3 streams:

sudo apt-get install lame
sudo apt-get install libsox-fmt-mp3
sudo apt install libsox-fmt-all

At the command line, navigate to the rpitx directory, and type this to pipe the output of the fip internet stream to rpitx:

sox -t mp3 http://icecast.radiofrance.fr/fip-midfi.mp3 -t wav
 - | sudo ./pifmrds -freq 107.5 -ps fip -rt 'en direct a Paris' -audio -

This would stream fip radio and broadcast it on FM on 107.5 MHz FM, with the RDS station name ‘fip’ and the scrolling text ‘en direct a Paris’ (You could try an accented Γ  but it doesn’t seem to support unicode!).

All very, very hypothetically of course.

 

 

Posted in computers, hardware, radio, Raspberry Pi | Tagged , , | Leave a comment

Emojify your Python

Screen shot of Emojifier

I’ve been thinking of ways of sharing Python programs on Twitter and I’ve come up with something a bit crazy, but which might have other uses.

The micro:bit Python emojifier encodes and condenses Python programs using emojis. It also decodes them too, and turns strings of emojis back into full Python programs.

Many keywords are tokenised, in effect, into a single character. This means the programs take up less space, and so you could, for example, share longer programs in a tweet. I used carefully-chosen emojis so even the encoded programs can be read by humans. Our old friend the teleporting duck:

from microbit import *
import radio
radio.config(group=23)
radio.on()

while True:
    message = radio.receive()
    if message:
        display.show(Image.DUCK)
    if accelerometer.was_gesture('shake'):
        display.clear()
        radio.send('duck')

becomes:

πŸ”
πŸ“²πŸ“»
πŸ“»βš™(πŸ‘₯=23)
πŸ“»πŸ”›β†©
πŸ”
γ€°message = πŸ“».πŸ“₯
〰❓message:
γ€°γ€°πŸ“ΊπŸ’(πŸ–ΌπŸ¦†)
γ€°β“πŸ“³.was_🀟('πŸ₯€'):
γ€°γ€°πŸ“ΊπŸšΏ
γ€°γ€°πŸ“».πŸ“€('duck')

I think this might have other uses.

It may also encourage reluctant students to engage with coding concepts by presenting them in a new, but familiar visual language. The emojis are, in effect, a visual abstraction of programming concepts.

Programs written pictorially could appeal to those who struggle with reading or find large blocks of text hard to process, in a way not even block coding can manage,

Maybe students could even write Python programs using emojis. It might make Python more accessible to those who only have mobile devices.

This is very much optimised for Python on the BBC micro:bit, but perhaps it could be applied to other languages.

What do you think? Let me know!

Posted in computers, microbit | Tagged , , , | Leave a comment

micro:bit numbers station

Numbers stations are / were spooky shortwave radio stations, best known from the Cold War, which broadcast human voices reading numbers, usually in groups of five. It’s widely assumed these were / are used by many nations for communicating with secret agents in foreign countries, using an unbreakable one-time pad cipher.

You can spook yourself by listening to The Conet Project.

Or you can code a BBC micro:bit to be come your very own numbers station!

Use one of the micro:bit Python editors (such as the lovely new official online one) to flash the program below on to a micro:bit. If you have a micro:bit V2 you can hear the numbers from the built-in speaker, otherwise attach some headphones or an amplified speaker to pin 0 and GND.

If someone can add some code to play The Lincolnshire Poacher as well, I’d be very happy indeed.

from microbit import *
import speech
import random

numbers = ['zero', 'won', 'too', 'three', 'for',
          'five', 'six', 'seven', 'ate', 'nine']

while True:
    for i in range(5):
        speech.say(random.choice(numbers))
        sleep(500)
    sleep(1000)
Posted in computers, microbit | Tagged , , , , | Leave a comment

micro:bit Wordle game

screenshot of micro:bit Wordle game

I made a Wordle-like game in Python for the BBC micro:bit.

The code is pretty compact and easy to understand, so I think getting students to create their own version of this popular game or pick apart this one would make a nice activity. There are plenty of opportunities to improve it.

You could use it to:

  • teach some Python
  • learn about functions
  • learn about using global variables in functions
  • learn about slicing strings
  • use imports – I hide the word list in an import
  • experiment with the serial console in the new alpha micro:bit Python editor

You’ll need a micro:bit and a Chrome or Edge browser as it uses webUSB – you interact with the micro:bit using your computer’s keyboard and screen.

You get 5 guesses. It shows your progress on the micro:bit’s LED display: a bright LED means the right letter in the right place, a dim LED means the right letter in the wrong place.

It also prints out your progress in the serial console. Capital letters are in the right place, lower case in the wrong place: So

--a-T

means the word ends in T and has an ‘a’ in 1st, 2nd or 4th place.

You can download a hex file to flash direct onto a micro:bit or drag and drop onto the Python editor, plus the raw Python files over on GitHub: https://github.com/blogmywiki/wordobit.

You’ll probably want to add more words to words.py. You could also improve the program in lots of ways, for example add some simple encryption like ROT13 to the word list or add more word checking.

I also made a video to explain how it works and how to play it:

main.py code

from microbit import *
import random
import music
from words import wordlist

def newWord():
    print('New game!')
    display.clear()
    global word
    global turn
    word = random.choice(wordlist)
    turn = 0

newWord()

while True:
    print('Turn',turn+1)
    if turn > 4:
        print('You lose. Your score is X/5. The word was ' + word)
        music.play(music.POWER_DOWN)
        sleep(5000)
        newWord()
    guess = input('What is your guess? ')
    if len(guess) != 5:
        print('Not a 5 letter word!')
    else:
        progress = ''
        for a in range(5):
            if guess[a] in word:
                if guess[a] == word[a]:
                    display.set_pixel(a,turn,9)
                    progress = progress + guess[a].upper()
                else:
                    display.set_pixel(a,turn,4)
                    progress = progress + guess[a].lower()
            else:
                progress = progress + '-'
        print(progress)
        turn += 1
        if guess == word:
            print('Congratulations! Your score is ' + str(turn) + '/5')
            music.play(music.POWER_UP)
            sleep(5000)
            newWord()

words.py code

# List of 5 letter words hidden from main Python program view
wordlist = ['heart', 'aloft', 'float', 'banjo', 'scoop']
Posted in Uncategorized | Tagged , , , , | Leave a comment

Simple micro:bit video out

I love making little computers and getting video out from Arduinos and even micro:bits – IchiconQuest is a lovely self-contained, if eccentric, computer you can make with a micro:bit that has video out.

I stumbled upon the video above remarkably late – it’s just a simple demo by Kevin Moonlight to generate text on an NTSC composite video output on a TV using just a V1 micro:bit and 1 or 2 resistors. I had a go at re-making it, and succeeded!

How to wire up video out from a micro:bit

I’m grateful to @wifisheep for telling me that to make it work better, you should also put a 1K resistor on the red line between the phono and the clip. I had all sorts of weird earth issues without adding that – but still, quite impressive with two resistors.

screenshot of text from a micro:bit

Because very, very accurate timing is so crucial when generating video, the code for this is in C++, not in MakeCode or Python.

You can find the source code and HEX files you can flash direct on to a V1 micro:bit to try this for yourself on my GitHub: https://github.com/blogmywiki/microbit-video

I even made my own font!

wide font on a micro:bit

Posted in computers, microbit | Tagged , , , | Leave a comment