Project Description

 

In the book “Designing the Internet of Things”, one sample application which is mentioned is an alarm clock which is internet enabled, can check railway timetables, and if there is a delay, allow the user some extra time to sleep in.


This is possible using Raspberry Pi, it has even already been shown to work with pulling down railway timetables: PiFace – PiFace Control And Display train times guide – Running PiFace Control And Display traintimes

 

The goal is to have the following functionality:

  • Flexible and adapting alarm times by tapping into railway timetables and adjust the alarm based upon a selected train.
  • Control of the alarm clock via a mobile phone app.
  • Be able to program different radio stations according to different alarms; e.g., news channel for weekdays, music for weekends.
  • Quality stereo sound, using the Wolfson Audio Card.
  • If possible, provide voice control of the alarm clock.

 

The build would consist of:

  • Raspberry Pi with Wifi dongle for wireless connectivity
  • Wolfson audio card with speakers using the onboard amplifier (and microphone)
  • Arduino Micro connected via USB to add a bunch of I/O for buttons, etc ...
  • Pi-Lite LED Matrix as a display

 

 

Project Execution

 

Preparing the SD Card

 

First thing is to flash an SD card using the Wolfson image. Make sure you use an 8Gb SD card when using the Wolfson image!

 

I started off by listing the disks available on my machine, so I don't accidentally flash the wrong one.

 

diskutil list

/dev/disk0
   #:                       TYPE NAME                    SIZE       IDENTIFIER
   0:      GUID_partition_scheme                        *251.0 GB   disk0
   1:                        EFI EFI                     209.7 MB   disk0s1
   2:                  Apple_HFS Macintosh HD            250.1 GB   disk0s2
   3:                 Apple_Boot Recovery HD             650.0 MB   disk0s3
/dev/disk1
   #:                       TYPE NAME                    SIZE       IDENTIFIER
   0:     Apple_partition_scheme                        *16.1 MB    disk1
   1:        Apple_partition_map                         32.3 KB    disk1s1
   2:                  Apple_HFS Flash Player            16.1 MB    disk1s2
/dev/disk2
   #:                       TYPE NAME                    SIZE       IDENTIFIER
   0:     FDisk_partition_scheme                        *7.9 GB     disk2
   1:                 DOS_FAT_32 NO NAME                 7.9 GB     disk2s1






























 

Once I identified the proper disk, I unmounted it.

 

diskutil unmountDisk /dev/disk2

Unmount of all volumes on disk2 was successful





















 

And finally, I used "dd" to write the Wolfson image on to my SD card.

 

sudo dd if=wolfson_3.10_master.img of=/dev/disk2 bs=1m

Password:
dd: /dev/disk2: end of device
7498+0 records in
7497+1 records out
7861178368 bytes transferred in 4681.741917 secs (1679114 bytes/sec)




























 

 

Booting the Pi for the first time

 

With the SD card flashed and ready to use, I connected the Pi to my HDMI display, connected a keyboard and ethernet cable and booted the Pi.

The Pi booted properly and went straight to the graphical environment.

 

From a terminal, I ran the configuration tool and performed following actions:


sudo raspi-config

 

  • expanded the filesystem
  • enabled SSH access
  • disabled the boot to desktop
  • updated the system

 

After these changes, I could shut down the Pi and disconnect keyboard and monitor.

When the Pi had rebooted, I could log in via SSH.

 

ssh pi@192.168.0.249

The authenticity of host '192.168.0.249 (192.168.0.249)' can't be established.
RSA key fingerprint is 27:77:5b:01:7f:71:0a:2f:2e:a3:b0:16:14:f3:9e:6c.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '192.168.0.249' (RSA) to the list of known hosts.
pi@192.168.0.249's password:
Linux raspberrypi 3.10.25+ #622 PREEMPT Fri Jan 3 18:41:00 GMT 2014 armv6l

The programs included with the Debian GNU/Linux system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.

Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent
permitted by applicable law.
Last login: Fri Mar 28 16:18:05 2014
pi@raspberrypi ~ $






























 

 

Connecting to Wifi

 

Via SSH, I edited the network config as follows, in order to enable wifi:

 

sudo nano /etc/network/interfaces

auto lo

iface lo inet loopback
iface eth0 inet dhcp

allow-hotplug wlan0
auto wlan0
iface wlan0 inet dhcp
        wpa-ssid "ssid"
        wpa-psk "password"






























 

Powered off the Pi again, disconnected the Ethernet cable, inserted the Wifi dongle and booted the Pi.

With the wifi working, it was time to connect the Wolfson Audio Card.

 

 

Wolfson Audio Card

 

Before connecting the audio card to the Pi, I soldered headers to the SPKOUT connections.

This is where I plan to connect loudspeakers and use them with the card's onboard amplifier.

 

IMG_3671.JPGIMG_3677.JPG

 

I connected the audio card, ensuring the pins aligned properly and that the plastic screw was fastened.

When booting the Pi, a green LED lights up on the audio card.

 

Time for a test. I connected my headset with microphone and configured the card/pi to use the correct audio input/output:

 

./Playback_to_Headset.sh
./Record_from_Headset.sh

























 

These commands generate a lot of output, but as long as it doesn't contain any error messages, you should be fine.

 

I made a small recording:

 

arecord -Dhw:0 -r 44100 -c 2 -f S32_LE file

























 

And played it out to verify the contents:

 

aplay -Dhw:0 -r 44100 -c 2 -f S32_LE file

























 

The contents of the file matched the expected results. Test successful.

 

More information on the command line recording, playout and the commands used, can be found here: Wolfson Audio Card - Command Line recording

 

 

Speakers

 

As stated earlier, the goal is to connect speakers to the audio card. The advantage of using the SPKOUT on the Wolfson card, is that it uses an onboard amplifier.

It is however required to connect the audio card to an external 5V power supply in that case.

 

I got myself two small speakers and replaced the end connectors to be able to plug them on to the audio card.

 

IMG_3683.JPGIMG_3684.JPG

IMG_3687.JPGIMG_3689.JPG

With the speakers connected, I could now redirect the output to the speakers instead of the headset, but also use the onboard microphones for recording

 

./Playback_to_Speakers.sh
./Record_from_DMIC.sh










 

 

Pi-Lite Display

 

The Pi-Lite is a board for the Raspberry Pi, which was on Kickstarter a while back. It's inspired by the LoL shield for Arduino.

I had it lying around for a while and decided it was time to use it in one of my projects.

 

It can be connected to the Raspberry Pi's serial interface, which is also made available on the Wolfson audio card.

I also searched for a 5V and a GND pin on the Wolfson card, in order to power it.

 

DSCN3105.JPGDSCN3106.JPG

 

To display text on the Pi-Lite, the serial interface needs to be used. In order to do that, I installed "minicom":

 

sudo apt-get install minicom








 

Running a test command to display the current time in HH:MM format:

 

date +"%H:%M" | sudo minicom -b 9600 -o -D /dev/ttyAMA0













 

 

 

Timezone

 

For the alarm clock to be reliable, it is important the time is correct. By default, the time is set to UTC.

Using below commands, I configured the proper timezone.

 

date

Wed May  7 18:17:39 UTC 2014












 

sudo cp /usr/share/zoneinfo/Europe/Brussels /etc/localtime












 

date

Wed May  7 20:19:47 CEST 2014












 

It is also possible to check if the Pi's time is being synchronized:

 

ntpq -p

     remote           refid      st t when poll reach   delay   offset  jitter
==============================================================================
+brussels52.firs 194.50.97.34     4 u  57m 1024  210   19.815   -0.098   1.955
*ntp.katho.be    193.190.230.66   2 u  385 1024    5   17.591    2.047   2.556
leela.isw.stude 195.13.23.5      3 u  49m 1024    4   13.219   -0.833   0.461
net1.uni-paderb 131.234.137.64   2 u 163m 1024    0   34.317   -4.637   0.000






 

 

Next

 

I will continue to work on the alarm clock, more specifically on:

  • adding buttons to manually control the alarm clock (display time, train status, etc ...)
  • start working on a mobile application to configure the alarm clock and its settings
  • start working on the enclosure for this project
  • ...

 

Until next time!

 

riotboarda_hp.png