My Raspberry Pi Projects
Contact:
  1. Headless Setup - ie. without using a monitor or keyboard for setup/control -> 
  2. - control an LED on the RasPi via web -> 
  3. - CPU load, temp, procs, mem, network traffic, etc -----> 
  4. ...

  1. Headless Setup
Nueva Gorgona, 27 Aug 2013 -  now using "wheezy" 2013-07-26.  Also note that since I wrote this last September, Adafruit has posted tutorials for using VNC with the RasPi and using the TTL Serial Cable.

The Quick start guide calls for a USB keyboard and mouse plus an HDMI or composite video monitor to set up the RasPi.  I found a number of articles showing how to set it up without these (aka "headless").  They seem to revolve around booting the RasPi on a LAN with SSH enabled, either having set a static IP address for it in the boot image or finding it's IP address using DHCP, then SSH'ing into it.  I came across the USB to TTL Serial Cable on Adafruit.  It seems a little more straightforward.  And is only $10 and can be used elsewhere, such as communicating with their GPS module.
 
Gainesville, 18 Oct 2015
 Note that if you have an Ethernet network ...
you should be able to simply plug the Raspi into it and connect from a Mac or Windows system, and skip Steps 2-4.  I just tried it with the latest version of Rasbian Wheezy (2016-05-05 v3.18) downloaded from their download page.  I used MobiXterm on my new Windows 10 system to connect to the Raspi.  After installing the X11 clients as in Step 8, xeyes& worked just fine from the MobiXterm session, displaying xeyes on my Windows 10 display.  When I started this article a couple years ago, all I had was a MacBook and USB-to-TTL Serial Cable to connect to the Raspi (being off the beaten track in Panama).  Now, back in the US (the land of stuff), I have in hand the bits I'd need to make most of the following article moot - a USB keyboard, USB mouse and HDMI monitor.  And an Ethernet network if I'm too lazy to switch the keyboard, mouse and display from my Windows system over to the Raspi.. a block away from the apartment is a 24-hour McDonalds serving breakfast all day.. oh, the decadence.

 
Here is how I set up my Raspberry Pi Rev 2 using Mountain Lion (10.8.4) and an Adafruit USB to TTL Serial Cable:
  1. Initialized the boot SD card ...
    I downloaded the raw image of Raspbian "wheezy" ("2013-07-26") from raspberrypi.org/downloads and initialized the SD card per the instructions in the Raspberry Pi User Guide.  To quote from that guide:
    On Mac OS X:
     
    1. In the Mac OS X Application menu, select Utilities->Terminal.
    2. Plug your blank SD card into a card reader connected to the Mac.
    3. Type
          diskutil list
      to see a list of disks.  Find the SD card by its size, and note the device address (/dev/diskX, where X is a letter identifying the storage device).
    4. If the SD card has been automatically mounted and is displayed on the desktop, type
          diskutil unmountdisk /dev/diskX
      to unmount it before proceeding.  [Note: you can also see it mounted in Finder.]
    5. Use cd to change to the directory with the .img file you extracted from the Zip archive.
    6. Type
          sudo dd if=imagefilename.img of=/dev/diskX bs=2m
      to write the file imagefilename.img to the SD card connected to the device address from step 3.  Replace imagefilename.img with the actual name of the file extracted from the Zip archive.  [Note: This step takes a while, so be patient!  For me, it took about 27 minutes on a new 13" MacBook Retina.  There is no CPU activity while the command is running, so it's not clear that it's doing anything.  Just give it a while.  If you cancel it before it's done, and mount the card again (pull it out of the SD slot and put it back in), you should see a bunch of files have been copied to the card.  Then I'd suggest erasing the card again and restarting at Step 3.  The /dev/diskX name may have changed, so watch for that.
    Then insert the SD card in the Raspi.
     
  2. Hooked up the wires according to the USB-to-TTL Serial Cable forum:
    Cable pin-out is as follows:
        Red = +5V
        Black = gnd
        White = RX
        Green = TX
     
    To connect to Raspberry Pi:
        Red to pin 2 (+5V)
        Black to pin 6 (GND)
        White to pin 8 (GPIO14, TXD)
        Green to pin 10 (GPIO15, RXD)
     
    This will power the RPi from the USB port of the computer you're using to communicate with the RPi.
    If The RPi is getting power thru its micro USB power connector, leave the red wire unconnected.

    Here is how it looks (using either Adafruit's old (black cased) or their newer (blue cased) USB-to-TTL Serial Cable), connected directly to the header on the Pi board.
    Ie. to pins 2, 6, 8 and 10 of the GPIO port.

    I have a notion of interfacing to hardware triggering sensors in the future, so I'm using the Adafruit Pi Cobbler Breakout Kit.  It has the 5V, GND, TXD and RXD pins clearly marked on the little breakout plug PCB.  Then you use jumper wires from the prototyping breadboard to the wire ends of the USB-to-TTL Cable.  I got the Adafruit Starter Pack which included all this stuff (jeez, I'm starting to sound like a shill for Adafruit, but I have no affiliation with them - just a satisfied customer).
     
  3. Installed the cable's driver and started the RasPi console in a Terminal window ...
    Man-O-War, 4 Nov 2014
    For Yosemite, I switched to the newer blue cased cable from Adafruit and the Prolific driver for it.  See their product page for the latest info, but (at the time of this writing) they point to the driver at
    www.prolific.com.tw/us/showproduct.aspx?p_id=229&pcid=41.  Presently (4 Nov 2014), the download file is named, "md_PL2303_MacOSX_10_6up_v1_5_1.zip".  It installed cleanly on the current version of Yosemite (10.10) on my 13" MBP.  There is a helpful Installation Guide inside the zip file.  But basically, after installing the driver (double click on the .pkg file contained in the zip file) and rebooting, you plug the USB-to-TTL cable into your Mac, open a Terminal window and type into it:
    screen -L /dev/tty.usbserial 115200.
     Here is what I did with Lion, Mountain Lion and Mavericks ...
    Man-O-War, 4 Nov 2014
    When I first did this a couple years ago (and later as Apple updated Mac OS X to Mountain Lion and then Mavericks), I used Adafruit's (current at that time) USB-to-TTL cable (the one with the black cover).  Their product page (apparently gone now) pointed to the "OSX Lion" PL2303 driver on xbsd.nl/2011/07/pl2303-serial-usb-on-osx-lion.html.  I installed it using the instructions on that page.  To slightly paraphrase xbsd.nl's instructions:
    Download and extract the driver.  This should work for extracting the .kext file (following the instructions for "Unpacking .tar.gz files", where "tgz" is the same as "tar.gz").
    Then, in a Terminal window:
      $ cd /path/to/osx-pl2303.kext
      $ sudo cp -R osx-pl2303.kext /System/Library/Extensions/
     
    Next you need to fix permissions and execute bits:
      $ cd /System/Library/Extensions
      $ sudo chmod -R 755 osx-pl2303.kext
      $ sudo chown -R root:wheel osx-pl2303.kext
      $ sudo kextload ./osx-pl2303.kext
      $ sudo kextcache -system-cache
    Note: As they point out, somebody has also created an installer for it here
    Before plugging in the USB-to-TTL cable, typing  ls /dev/tty.*  in a Terminal window showed:
    /dev/tty.Bluetooth-Modem /dev/tty.Bluetooth-PDA-Sync

    Then with the USB-to-TTL cable plugged in,  ls /dev/tty.*  in a Terminal window showed (for me):
    /dev/tty.Bluetooth-Modem /dev/tty.Bluetooth-PDA-Sync /dev/tty.PL2303-00001014

    So, the /dev/tty.PL2303-00001014 had been added.  Yours may be different.  Note what it is to use in the next step.
     
    Then to start up the serial link in a Terminal window on the Mac, type:
    screen -L /dev/tty.PL2303-00001014 115200
    into the Terminal window.  The -L flag causes logging to screenlog.n in the local directory.

     
  4. After applying power to the RasPi (either by hooking up the red jumper wire on the USB-to-TTL Cable or by plugging in the micro-USB/wall-wart cable) you should see startup messages in the Terminal window like the following (they are also logged to screenlog.0 because I used the -L flag on the screen command):
    [ 0.000000] Booting Linux on physical CPU 0
    [ 0.000000] Initializing cgroup subsys cpu
    [ 0.000000] Linux version 3.6.11+ (dc4@dc4-arm-01) (gcc version 4.7.2 20120731 (prerelease) (crosstool-NG linaro-1.13.1+bzr2458 - Linaro GCC 2012.08) ) #474 PREEMPT Thu Jun 13 17:14:42 BST 2013
    [ 0.000000] CPU: ARMv6-compatible processor [410fb767] revision 7 (ARMv7), cr=00c5387d
    [ 0.000000] CPU: PIPT / VIPT nonaliasing data cache, VIPT nonaliasing instruction cache
    [ 0.000000] Machine: BCM2708
     
    ... more startup messages ...
     
    [ 3.043891] smsc95xx v1.0.4
    [ 3.107101] smsc95xx 1-1.1:1.0: eth0: register 'smsc95xx' at usb-bcm2708_usb-1.1, smsc95xx USB 2.0 Ethernet, b8:27:eb:54:a7:50
    [ 3.228344] EXT4-fs (mmcblk0p2): mounted filesystem with ordered data mode. Opts: (null)
    [ 3.240655] VFS: Mounted root (ext4 filesystem) on device 179:2.
    [ 3.260192] devtmpfs: mounted
    [ 3.265767] Freeing init memory: 128K
    [ 4.648739] udevd[154]: starting version 175
    [ 21.979806] EXT4-fs (mmcblk0p2): re-mounted. Opts: (null)
    [ 22.443055] EXT4-fs (mmcblk0p2): re-mounted. Opts: (null)
    Debian GNU/Linux 7 raspberrypi ttyAMA0

    raspberrypi login:

    If you don't see the messages above when you connect the red wire, try connecting the red wire before plugging in the USB-to-TTL Cable, then connect the cable between the RasPi and your computer, then type the screen command (Step 5) in a Terminal window.  You'll probably miss first few messages in the Terminal window.  They should be logged, or if you do a sudo reboot at any time, don't disconnect the cable and the same window should start showing the messages from the beginning.

  5. Logged in with the userid of pi and password of raspberry.  There are a few more messages until the shell's $ prompt:
    raspberrypi login: pi

    Password:
    Linux raspberrypi 3.6.11+ #474 PREEMPT Thu Jun 13 17:14:42 BST 2013 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.

    NOTICE: the software on this Raspberry Pi has not been fully configured. Please run 'sudo raspi-config'

    pi@raspberrypi:~$

    For that warning message,
    NOTICE: the software on this Raspberry Pi has not been fully configured. Please run 'sudo raspi-config'
    simply type sudo raspi-config in the Terminal window.  The RasPi should
    then show you a menu in the Terminal window with it's various setup options, e.g. on my MacBook->
    You can invoke this utility anytime later (with
    sudo raspi-config ).  But for now, the most useful settings to change are:
    • "Expand Filesystem" will expand the root partition to fill the SD card
    • "Change User Password" will change the password of the "pi" userid
    • "Internationalization Options" changes the locale (if you need to)
    Use your up/down keys to move up and down in the menu.  Hitting return will invoke the option or enter a submenu.  Hitting the Tab key brings you down to the <Select> and <Finish> options at the bottom of the menu.
     
  6. Installed the X11 package for Mountain Lion on my Mac per About X11 and OS X Mountain Lion.
     
    Man-O-War, 11 Sep 2014
    For Mavericks, I am presently using the XQuartz 2.7.7 package.

    Gainesville, 15 Oct 2015
    XQuartz 2.7.7 is also working for me on Yosemite (10.10.5).

  7. Up until now, we've been using the USB-to-TTL Serial Cable connection and the terminal interface from the Mac to the RasPi.  Next we want to setup a network connection (so we can download some updates to the RasPi's operating system), and make sure I can communicate with the internet.  The two most likely ways to do this are via either an Ethernet connection or a WiFi connection.  I want to have a WiFi connection later (to be able to access the webserver on the RasPi from my iPod) so next, I setup WiFi for the dongle recommended by Adafruit that I have plugged into one of the RasPi's USB ports.  I used the Adafruit tutorial.  First, I edited /etc/network/interfaces:
    sudo nano /etc/network/interfaces
    The router here broadcasts it's SSID, so I changed the original contents of the file:
    auto lo

    iface lo inet loopback
    iface eth0 inet dhcp

    allow-hotplug wlan0
    iface wlan0 inet manual
    wpa-roam /etc/wpa_supplicant/wpa_supplicant.conf
    iface default inet dhcp
    to:
    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"
    • replacing ssid and password with the ones from here - note, you need the double-quotes, so wpa-ssid "apt208" and wpa-psk "beachnut",
    • shutdown the RasPi (sudo shutdown now),
    • plugged in the WiFi adapter and
    • started it again.
    It connected to the router automatically.
     
    Note: if you make a change (say a new SSID or password) and simply want to restart the interface, you can /etc/init.d/networking restart.
     
    BTW, Adafruit's tutorial also includes the settings if the router is not broadcasting it's SSID.
     
    I issued a test ping to raspberry.org to make sure I can get out:
    pi@raspberrypi:~$ ping raspberry.org
    PING raspberry.org (208.87.35.103) 56(84) bytes of data.
    64 bytes from 208-87-35-103.securehost.com (208.87.35.103): icmp_req=1 ttl=51 time=347 ms
    64 bytes from 208-87-35-103.securehost.com (208.87.35.103): icmp_req=2 ttl=51 time=123 ms
    64 bytes from 208-87-35-103.securehost.com (208.87.35.103): icmp_req=3 ttl=51 time=111 ms
    64 bytes from 208-87-35-103.securehost.com (208.87.35.103): icmp_req=4 ttl=51 time=123 ms
    (sort of like ET's "Phone home" :-).
     
    Then, found the IP address of the RasPi using sudo ifconfig:
    pi@raspberrypi:~$ sudo ifconfig

    ...

    wlan0 Link encap:Ethernet HWaddr 00:e0:4c:10:3c:de
    inet addr:192.168.0.102 Bcast:192.168.0.255 Mask:255.255.255.0
    UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
    RX packets:31 errors:0 dropped:41 overruns:0 frame:0
    TX packets:27 errors:0 dropped:0 overruns:0 carrier:0
    collisions:0 txqueuelen:1000
    RX bytes:6852 (6.6 KiB) TX bytes:3862 (3.7 KiB)
    And finally, a test ping from my Mac to the RasPi:
    dontp-MBP:~ dontp$ ping 192.168.0.102
    PING 192.168.0.102 (192.168.0.102): 56 data bytes
    64 bytes from 192.168.0.102: icmp_seq=0 ttl=64 time=119.037 ms
    64 bytes from 192.168.0.102: icmp_seq=1 ttl=64 time=11.186 ms
    64 bytes from 192.168.0.102: icmp_seq=2 ttl=64 time=2.666 ms
    64 bytes from 192.168.0.102: icmp_seq=3 ttl=64 time=3.606 ms
    64 bytes from 192.168.0.102: icmp_seq=4 ttl=64 time=11.922 ms^Z

  8. Now that I had an internet connection, I installed some X11 apps and updated the system:
    sudo apt-get install x11-apps
    ...
    sudo apt-get install x11-xserver-utils
    ...
    sudo apt-get install xterm
    ...
    sudo apt-get update
    ...
    sudo apt-get upgrade
    ...
    sudo apt-get dist-upgrade

  9. Finally, I started an X11 connection using ssh -X pi@192.168.0.102 from a Terminal window on my laptop.  Make sure you have xterm running on your Mac.  Otherwise you get an error message about not being able to open the XDisplay.  You should be able to do the ssh -X pi@192.168.0.102 from either the xterm window or a Terminal window.  Don't forget to use your IP address.
     
    Then, from that RasPi session on the Mac, I invoked the venerable xeyes and xclock, as well as the python IDE, idle:
    dontp-MBP:~ dontp$ ssh -X pi@192.168.0.102
    pi@192.168.0.102's password:
    Linux raspberrypi 3.6.11+ #474 PREEMPT Thu Jun 13 17:14:42 BST 2013 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: Wed Aug 28 17:18:10 2013

    NOTICE: the software on this Raspberry Pi has not been fully configured. Please run 'sudo raspi-config'

    pi@raspberrypi ~ $ xeyes&
    [1] 3112
    pi@raspberrypi ~ $ xclock&
    [2] 3115
    pi@raspberrypi ~ $ idle&
    [3] 3118
    pi@raspberrypi ~ $
    Here is a screen capture from my Mac's desktop - - - ->
     
    The response time seems reasonable.

    Nueva Gorgona, 1 Sep 2013
    After installing kdevelop and geany, I tried invoking each from an X11 connection as shown above.  The response time of kdevelop over my connection makes it unusable.  If you have an Ethernet or really fast wireless network, you may find it tolerable.  On the other hand, the response time of geany seems pretty good.  gedit didn't build cleanly with this version of Debian so I didn't get a chance to try it.
     
    Here is a screen capture from my Mac's desktop - - - ->

    Man-O-War, 11 Sep 2014
    Update: for Mavericks, I am presently using the XQuartz 2.7.7 package.  Say, I want to run an X11 app on the RPi over the Ethernet connection between my RPi and MacBook.  And say ifconfig on the RPi shows:
    eth0  Link encap:Ethernet  HWaddr b8:27:eb:54:a7:50
          inet addr:192.168.2.2  Bcast:192.168.2.255  Mask:255.255.255.0
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:1011 errors:0 dropped:0 overruns:0 frame:0
          TX packets:618 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:131251 (128.1 KiB)  TX bytes:195489 (190.9 KiB)
    We see the RasPi's IP address
    is 192.168.2.2. In this case I have an Ethernet cable connected between the RasPi and my MacBook.
     
    Then, first start the XQuartz app on the Mac OS X system.  This should open up an Xterm window.  Type "ssh -X pi@192.16.2.2" (or whatever the IP address of your RPi).  This should log you onto the pi userid on the RPi in the Xterm window.  Then enter your X11 command in that window.
    E.g. "geany&" shown here to the right.
     
    For X11 over WiFi, connect to your LAN's SSID (to which the RPi is connect) and use the IP address of your RPi's WiFi connection (as shown in the next step).

  10. I then shutdown the RasPi (sudo shutdown now), unplugged the USB-to-TTL Serial Cable, and plugged in a micro-USB cable to restart the RasPi.  Just to reiterate, from a Terminal window on my Mac I am now able to control the RasPi over WiFi on the LAN:
    ping 192.168.0.102
    ssh pi@192.168.0.102
    ssh -X pi@192.168.0.102

  11. Last but not least, I installed some common services on the RasPi:
    • I installed the LAMP web server and a little PHP test page (per http://community.linuxmint.com/tutorial/view/486).  So, on the RasPi:
      sudo apt-get install apache2 php5 php5-mysql mysql-server
      ...
      sudo sh -c 'echo "<?php phpinfo(); ?>" > /var/www/phptest.php'
      and tested it from a browser on my Mac.  So, enter this in the address bar of a browser on your laptop/desktop on the same LAN (changing the IP address to that of your RasPi, of course):
      http://192.168.0.102
      http://192.168.0.102/phptest.php
    • installed an FTP server per http://richardquick.co.uk/raspberry-pi-web-server/.  See their instructions under Step 9 - FTP Server, but to summarize:
      sudo chown -R pi /var/www
      sudo apt-get install vsftpd
         and
      sudo nano /etc/vsftpd.conf
         changing
         anonymous_enable=YES to anonymous_enable=NO
         #local_enable=YES to local_enable=YES
         #write_enable=YES to write_enable=YES
         restarted the ftp service:
      sudo service vsftpd restart
         and finally:
      sudo apt-get autoremove
         which freed up a little space for me (84KB).
       
         Then I tested it from a Terminal window on my Mac:
      ftp pi@192.168.0.102
         and from Filezilla on my Mac:
      Host:192.168.0.102 Username:pi Password:raspberry
    • installed a monitor, phpsysinfo,
    • installed gkrellm (entering the following command all on one line):
      sudo apt-get install gkrellm lm-sensors fancontrol sensord read-edid i2c-tools libi2c-dev python-smbus rrdtool librrds-perl
         which installed cleanly.  Then I started an X11 session
         by typing in a Terminal window on my Mac:
      ssh -X pi@192.168.0.102
         and after logging onto the RasPi, typed:
      gkrellm &
         After a few seconds, a CPU monitor of the RasPi
         popped up on the Mac's desktop - - - - - - - - - - - - ->
    • and for the RasPi desktop, I installed the VNC server per RPi VNC Server:
      sudo apt-get install tightvncserver
      ...
      tightvncserver
         I rebooted the RasPi and started the VNC server:
      vncserver :0 -geometry 1024x768 -depth 24
      Then, per Screen Sharing, I used the Mac's built-in VNC client as follows:  In a Terminal window on the Mac:
      open "/System/Library/CoreServices/Screen Sharing.app"
      This (fairly quickly) resulted in the RasPi's LXDE desktop popping up on my Mac desktop - - - - - - - ->
       
      The response time isn't too bad for basic static apps IMO but definitely not adequate for say, games.  In any case, I'll probably use geany and the RasPi's command line interface for the most part.

      Nueva Gorgona, 6 Sep 2013
      After using it for a couple days (on the dedicated WiFi LAN in the apartment), I'm finding that the response time for Geany - running on the RasPi with it's UI running on my Mac desktop - to be pretty good.  I had thought I'd do most of my development on the Mac using XCode and the Mac's Apache server, then FTP the working CGIs and HTML to the RasPi for final shakedown.  But I'm finding, with decent response time from Geany and the network, it is a lot easier to simply work it out on the RasPi in the first place.  Geany's features and usability are pretty good too.

      Man-O-War, 14 Jan 2014
      Note: On the shared WiFi LAN here in the marina, response time between Geany and my laptop is pretty slow.

  12. Drank a beer.
Man-O-War, 15 Jan 2014
 15.
Well.. one more thing.  After going through this a second time (after my first SD card has apparently failed), I made sure that I backed up this image.  To backup the SD image (created above), I used the instructions (specific to Mac OS X) on Back-up a Raspberry Pi SD card using a Mac.  See his instructions, but to summarize..  on my Mac, I:
diskutil list
   then plugged in my SD card and did it again:
diskutil list
   noting the new disk# that is added.  My SD card was mounted as disk1.
   So, then I did:
sudo dd if=/dev/rdisk1 bs=1m | gzip > ~/Desktop/pi.img.gz
   As he warns on his page, be VERY careful about the if and of device
   and file names.  You could wipe out one of your systems otherwise.
 
   To copy the image back to an SD card (assumming it is mounted as disk1):
diskutil unmountDisk /dev/disk1
gzip -dc ~/Desktop/pi.img.gz | sudo dd of=/dev/rdisk1 bs=1m

-- FIN --
References
Monitors WiFi GPIO VNC Clients for the Mac Misc