Showing posts with label raspberry pi. Show all posts
Showing posts with label raspberry pi. Show all posts

Thursday, 1 May 2014

Enabling the watchdog on a Raspberry Pi (Raspbian)

I have a Raspberry Pi that's connected to a PICAXE which listens for sensor data that's being broadcast from a couple of nodes in my house (one measures mains power consumption, two others measure ambient temperature). In summer the Raspberry Pi gets a bit warm and randomly locks up, so I've enabled the hardware watchdog to automatically reboot it if the system locks up.

A hardware watchdog is usually a watchdog timer: a register which is hooked up to a clock and when either the register overflows or hits zero it triggers a hardware reset. Your system writes to the register periodically to stop it triggering the hardware reset. If for some reason you stopped writing to the register, something went wrong and the system resets.

Here are some short notes on how to enable the onboard watchdog on the Raspberry Pi:

Run the following command to attempt loading the watchdog kernel module:
sudo modprobe bcm2708_wdog

Now run "lsmod" and look for the line in bold below:

Module Size Used by
bcm2708_wdog 3537 0


This verifies that the watchdog module was loaded successfully. Now edit /etc/modules and add bcm2708_wdog to load the module on boot by running the following command:
sudo echo bcm2708_wdog >> /etc/modules

Install the watchdog package:
sudo apt-get install watchdog

Configure starting the watchdog daemon on boot:
sudo update-rc.d watchdog defaults
sudo chkconfig watchdog on

Edit the watchdog daemon's configuration files and tell it to use the watchdog device. Change the line:
#watchdog-device = /dev/watchdog
to
watchdog-device = /dev/watchdog

Start the watchdog:
/etc/init.d/watchdog start


Saturday, 22 March 2014

RuneAudio with HiFiBerry

At home I have a Raspberry Pi with a HiFiBerry DAC plugged in, in a UniPi case, running RuneAudio (phew that's a lot of COTS integration). It's an awesome high quality audio source!

With the lid off

With the lid on - nice and neat

I've desoldered the original 3.5mm jack and composite video connectors and used the 3.5mm jack hole to mount a new 3.5mm jack (it's just one of these Altronics P0086 screw together jacks).

Here's some quick notes on how to get HiFiBerry working with Rune Audio 0.2:

Flash and update to latest

Flash RuneAudio 0.2 onto a SD card and plug it into the Raspberry Pi.
Log into the Raspberry Pi using SSH with user name "root" and password "rune".

Update: Midnight on the Rune Audio forum says you don't need to update everything, just update the kernel with the following commands so give this a try first:
pacman -Sy linux-raspberrypi linux-api-headers kmod
pacman -Sy linux-firmware raspberrypi-firmware-bootloader raspberrypi-firmware-bootloader-x raspberrypi-firmware-tools


Previously this blog post had the following, you probably don't need to update everything:
Run "pacman -Syu" and wait a while for the system to update.

Reboot the Raspberry Pi by running the command "reboot".

Load kernel modules

Log into the Raspberry Pi using SSH again, but note that the IP address allocated to the Raspberry Pi will probably be different due to the network subsystem being upgraded.
Edit /etc/modules-load.d/raspberrypi.conf (use nano or vim). Comment out snd-bcm2835, and add snd_soc_pcm5102a and snd_soc_hifiberry_dac. Your raspberrypi.conf file should contain the following after edits:

bcm2708-rng
#snd-bcm2835
snd_soc_pcm5102a
snd_soc_hifiberry_dac

Save the file and reboot by running the command "reboot".

Configure MPD

Log into the Raspberry Pi using SSH again.
Run the command "aplay -l" and examine the output. On mine the following showed:

**** List of PLAYBACK Hardware Devices ****
card 2: sndrpihifiberry [snd_rpi_hifiberry_dac], device 0: HifiBerry DAC HiFi pcm5102a-hifi-0 []
  Subdevices: 0/1
  Subdevice #0: subdevice #0

Note the number next to card and device (in my case 2 for card and 0 for device).
Edit the file /etc/mpd.conf (use nano or vim). 
Look for the mixer_type setting and change it to software:
mixer_type      "software"

Look for the first audio_output entry and change it to the following (enabled should be set to yes, change name to HiFiBerry or another name of your choosing, and change the device value):
audio_output {
enabled         "yes"
type            "alsa"
name            "HiFiBerry"
device          "hw:2,0"
dsd_usb         "yes"
}

Note that for the device setting, the numbers following hw: need to match your card and device numbers shown by "aplay -l" previously. For mine, this needed to be set to "hw:2,0".

Final Restart

Reboot the Raspberry Pi by running the command "reboot". After the Raspberry Pi boots back up, you should be able to play music :)

Wednesday, 26 December 2012

Pandora on Raspberry Pi

It's pretty hot today so we're trying to reduce the number of powered on devices in the house (less heat produced = less work the air conditioning has to do). I normally switch on the HTPC to play music through Pandora, but that's a hundred or so watts heating up the living room!

Since I have a Raspberry Pi hooked up and recording mains power consumption and temperature data in my house (more posts on that stuff to follow), I thought it could do a little more work and play music too.

So here's a quick set of instructions on how to get Pandora working on a Raspberry Pi using Pianobar (a command line Pandora client).

Equipment needed:


  • Raspberry Pi
  • USB Sound Adaptor
I'm using a USB Sound Adaptor because the onboard Raspberry Pi sound makes thumps whenever the audio is switched off (I guess they're powering off the audio part of the SOC when it's not being used). The thumps are pretty annoying, and the easiest solution is to plug in an extra sound adaptor which doesn't have this problem.

Steps:

Install Pianobar

Log into the pi and run "sudo apt-get install pianobar".

Configure alsa's modprobe order so the usb soundcard appears as the primary sound card

Edit /etc/modprobe.d/alsa-base.conf and change the lines that say:
# Keep snd-usb-audio from beeing loaded as first soundcard
options snd-usb-audio index=-2

To:
# load usb audio first
options snd-usb-audio index=0

Reboot your Raspberry Pi.

Create the Pianobar Configuration File

Log in as the "pi" user, and create the directory "~/.config/pianobar" if it doesn't already exist. Create a file in that directory called "config" and write the contents if the config file described on this page into it:

Don't forget to update the config file with your username and password (or command to decrypt your password from a key store). You will also need to update the tls_fingerprint setting with Pandora's current TLS fingerprint (they seem to change this from time to time). The contributed script here will fetch the fingerprint from Pandora's tuner:

Getting Started

Run "pianobar" as the pi user and it should start up and ask you which station to play! You might want to install screen or a similar to so you can background the pianobar process.

Saturday, 24 November 2012

Asus USB-N13 with Raspberry Pi

This weekend I set up my Raspberry Pi to connect to my home wireless network using an Asus USB-N13. The process was quite painless:
  • Install debian wheezy on a SD card, boot the Raspberry Pi off it.
  • Plug in a wired network connection.
  • As root (run "sudo -s") run "apt-get update".
  • As root, run "apt-get upgrade".
  • Plug in the Asus USB-N13.
  • Do a "lsusb" and make sure you see an entry for the wireless adaptor (the Bus and Device values may change):
Bus 001 Device 004: ID 0b05:17ab ASUSTek Computer, Inc. USB-N13 802.11n Network Adapter (rev. B1) [Realtek RTL8192CU]

  • As root, run "apt-get install firmware-realtek" to make sure we have the Realtek firmware binaries installed.
  • As root, run "apt-get install wicd" to install Wicd: a network connection manager.
  • Start up the GUI (run "startx" from console if you booted into console).
  • Start "wicd-gtk".
  • Use the UI to configure your wireless adaptor.
  • Disconnect the wired ethernet and reboot your Raspberry Pi.
  • A few minutes after booting, Wicd should do its magic and the Raspberry Pi will appear on your network.