Since I’ve been really astonished from the difficulties I’ve had searching for this on the web lately, I’m writing this (really short) blog post hoping to save other people’s time.
If you want to change the DNS server of the default Raspbian installation on a raspberry PI – this probably goes for most of the recent linux distributions too – you just have to edit your /etc/network/interfaces file specifying, under the desired interface, this code:
Of course replace 220.127.116.11 with your desired DNS server’s IP address.
Ok, lately I’ve been approaching the fine art of chess, mostly by watching youtube videos on the matter, and with some playing on lichess.org too. So I couldn’t avoid watching tons of video of the croatian youtuber Agadmator, which is really putting a lot of effort in getting people closer to chess, by publishing one or more videos every day.
So if you’ve been watching some of his videos, you might have noticed that aside the obvious personal contribute he puts in analyzing the games, the rest of the videos is generally just showing the moves and maybe adding some kind-of-predictable comments on them. When the idea came to my mind, I couldn’t help it. I *had to* do algorithmize agadmator.
Long story short, I spent three nights developing a web app which receives a PGN game in input and then generates an (fake) agadmator video for it.
I think it’s quite funny, I’ve really been enjoying the making of it and the end result, however it’s obviously improvable.
The link (for chrome or firefox only, desktop only – sorry for that, didn’t have time to optimize it) is here: Agadmatorizer
Of course I don’t think anyone will really read this, but if someone does, and if agadmator does, I hope you enjoyed this webapp, thank you for reading this post and I’ll see you soon.
Today i’m going to write about my new project, a Raspberry PI powered radio car. For now it can provide only basic functionalities, but it can be easily improved by upgrading the software, on which i didn’t focus very much so far.
In this post i will explain how I configured the PI to accomplish the task.
What I used in this project?
a Raspberry PI
a standard 16×2 character LCD display (HDD44780 compatible)
a wheel from an old mouse
The idea is to make a car radio capable of playing music from a usb pen plugged in the PI. My radio can only shuffle the songs found, but that’s just about software, it can be improved in many ways, that is where a lot of customization may take place.
Getting the display working with the PI
The first thing to do is to understand how to drive the LCD display from the PI. This is made by connecting the display to the PI’s GPIO, and then sending the commands from the programming language, usually using a library for the HDD44780 standard.
After I was able to write to the display, I wrote a little python script to print something to the display from the command line, which could be useful to write something to the lcd from a shell script later:
To play music through a USB device, the PI must be configured properly. In my case, I had some operation to do before everything worked, and my speakers are still showing some problems when playing from the PI (I hear a little noise, but i didn’t search enough to tell it can’t be resolved).
Anyway, if you want to use your PI as a car radio, you probably want the USB speakers to be the default audio device for it. You can do this by editing the /etc/modprobe.d/alsabase.conf adding the following line, or modifying the relative line if it already exists with another value (which in raspbian should be the case):
options snd-usb-audio index=0
I had also another problem which seemed to be quite common, and I also had to add another line at the end of that file, to avoid an “expected delay” error which I discovered running dmesg:
options snd-usb-audio nrpacks=3
I choose the higher value which didn’t give me errors in the log. After modifying the file i restarted alsa with
sudo service alsa-utils restart
This wasn’t enough to play music through the speakers, I also had to specify the right device when i played the music with mplayer. I had to discover the name of the device running the following command:
which gives a list of the recognized devices, from which i selected the right one, and finally got mplayer to play some mp3s:
mplayer -ao alsa:device=front my_music_file.mp3
Usb automount and autoplay
Now that the display is working correctly and we can play music through the speakers, let’s figure out how to handle the mounting/umounting actions:
The next step is to configure the PI to automatically mount any usb drive plugged in. This can be done by using the usbmount software avaiable in the raspbian repository:
sudo apt-get install usbmount
Now, I want to autoplay music when the usb is plugged in, so I add a custom script to the default usbmount script folder /etc/usbmount/mount.d :
python /home/pi/lcd/char/print.py "Madre foca:
sudo -u pi mplayer -slave -input file=/home/pi/fifofile -ao alsa:device=front -shuffle $UM_MOUNTPOINT/* $UM_MOUNTPOINT/*/* $UM_MOUNTPOINT/*/*/*
The first command uses the python script I created before to print something to the LCD when music is starting, while the third line starts the playback.
As you can guess, the $UM_MOUNTPOINT variable contains the path to the mounted drive.
The -slave mplayer option is a very useful way to let you send commands to mplayer even if it’s backgrounded. It tells mplayer to read input commands from a file, but if we provide a fifo file instead of a normal one, mplayer will read from it only when we will write something. This allows mplayer to be controlled by writing to a file, from python, shell or whatever you prefer. To create a fifo file you should use
If you want to know more on the -slave option of mplayer, see here.
I had to add the sudo -u pi part because it seemed that the user of usbmount wasn’t allowed to read from the fifo, I don’t know exactly why.
Finally, I also created a script for the umount event, which simply killed mplayer, and placed it in the /etc/usbmount/umount.d directory:
python /home/pi/lcd/char/print.py "Music stopped.
I'm a super PI."
Connecting the inputs: the button and the wheel
I’m not very good with electronics, so i won’t explain this part very deeply, also because that’s pretty basic.
The scheme to read the state of a button should be something like this:
The mouse wheel should have three connectors, and it behave like two button together, with the central pin in common. The only thing to know about it is that the two “buttons” are switched on and off while you turn the wheel, but one of them is triggered a little before the other, giving you information about the direction.
I decided to use a wheel (or two button) and an additional button to provide basic input for a “menu” structured OS for the radio, which is the minimal input for a fair usability.
Reacting to the inputs
The last thing to do is to react to the input of the user, writing the real “operating system” for our radio. I wrote this in python, and the interface is really minimal, providing the wheel to control the volume and the button to skip to the next song.
As usual the code is really bad written, and it should be used only to understand how it works. I encourage you to write a real interface, you could really do anything with that.
The script (bad written of course) is this:
import RPi.GPIO as GPIO
from Adafruit_CharLCD import Adafruit_CharLCD
lcd = Adafruit_CharLCD()
lcd.message("Hello!nI'm the SuperPI.")
os.system("amixer set PCM 5+");
os.system("amixer set PCM 5-");
lcd.message("Skipping tonnext song")
f = open('/home/pi/fifofile','w')
f.write('seek 100 1n')
last_a = False
last_b = False
last_c = True
paired = True
a = GPIO.input(4)
b = GPIO.input(18)
c = GPIO.input(2)
#print "4: "+str(a)+ " 18: " + str(b)
if c == False and c != last_c:
if a != b and paired:
if a != last_a:
paired = False
paired = True
last_a = a
last_b = b
last_c = c
Note that it uses the previous created fifo to send to mplayer the command to skip to the next song.
I’m sure that anyone can assemble this project better than I did. And to prove it i’ll show a picture:
Here’s a little video (in italian) in which I show the (few) functionalities of the radio:
I’m thinking, when I have some spare time, to extend its functions by attaching a webcam and trying to do something more complex, given the wide range of possibilities the PI can offer.
UPDATE: This method works but the embedded video expires after about a month, and the code must be updated. It might be possible to try to modify the embedded code to make it expire later, but I didn’t test it.
With the introduction of Google+ instant upload, many people started automatically backing up their photos and videos in Google Plus (and many started actively using G+ for this reason).
This is of course great, but there’s also a limitation: you can share the uploaded photos/videos only in Google Plus. I think it works this way to increase the popularity of the social network but that’s not very comfortable, expecially when you have ~300Mb videos already uploaded but you can’t even move them to Youtube, to share and embed them where you do prefer (eg. facebook, twitter, personal website).
I searched the Internet a lot before understanding that probably Google doesn’t want you to share Google Plus videos outside its social network, and i decided to “manually” find a way.
After a little trying i found out how to to embed Google+ videos in your personal website. I found that you can easily extract the html code to embed the video directly from G+:
The steps are few and pretty easy (i assume you use Chrome/Chromium browser because it is very comfortable for inspecting the DOM, but it can certainly be done in Firefox too):
Go to Google Plus, find the video you want to embed and simply play it.
When the video is playing, pause it and inspect the html (you can do this with chrome/chromium browsers by right-clicking -> Inspect Element). Be sure to right click near the video, but not on it (you can’t, it’s flash content)
Search the DOM tree for the “<embed>” tag (See the picture)
Then right click on it -> Copy as HTML (on Chrome/Chromium)
Now you have an HTML code representing the video: we’re almost done! It should look like this: