You are here

Intro to my Raspberry Pi

Wednesday, June 19, 2013

So, this week I finally got started on physically playing with the RaspberryPi, nothing particularly fancy, just getting it configured, working with my camera board, and a short piece of code to run it on a timelapse. Hence this post, it's the general steps I went through to setup my Pi and camera, along with a few tricks I found from a bit of searching. I will post more next week I expect, as there are still several bugs and issues (possibly some to do with my wigi card being broken - it rattles when shaken).

 

The basic steps

So, sat down at computer on Monday, and whirled through a few steps to get it up and running on a basic level.

  • Laptop decided not to play ball with SD cards, but rebooted (off and on again) and all was well
  • Read through page 3 (http://www.raspberrypi.org/wp-content/uploads/2012/04/quick-start-guide-...)
  • Opened gparted (disk was already FAT32)
  • Downloaded NOOBS (http://downloads.raspberrypi.org/download.php?file=/images/NOOBS/NOOBS_v...)
  • Ran
    unzip NOOBS_v1_1.zip -d NOOBS
  • Copied contents onto SD card
  • Put SD card into pi
  • Connected HDMI to pi
  • Connected power to Pi
  • Marvelled at it working first time :-)
  • Connected keyboard via USB hub, again, worked instantly
  • Connected other USB dongles into HUB ready (mouse, wifi)
  • Moved onto NOOBS docs (http://www.raspberrypi.org/archives/4100)
  • Stuck with Raspbian for now
  • Waited for a few minutes during installation (made a cup of tea)
  • Now its installed, I went through each step to get it running
    • Expand filesystem: Unnecessary with NOOBS, but for a regular OS you will need to do this if you want all the space available
    • Change User Password: security, so just do it
    • Enable boot to desktop: I did this as am playing, but once I start writing scripts, will probably just go to command line for the sake of performance
    • Internationalization: Confirm settings (en_GB.UTF-8 UTF-8)
    • Enable camera: Sweet, this is all there waiting for me, ON ON ON (http://www.raspberrypi.org/archives/3890)
    • Enable to Rastrack: Why not, it's kinda cool to view all the data (http://www.raspberrypi.org/archives/1298)
    • Overclock: Not at that stage yet, but may be later ;-)
    • Advanced: Definately go in here to configure hostname/ssh/update
    • Finish
  • First thing I noticed is that it didn't boot into x automatically, so opened manually with
    startx
    (note: after a reboot, it went into x instantly)
  • Mouse works instantly, which is great

 

Shutdown/Reboot

The usual way when you either have a bug, or finished some config, turn it off and on again. As we know, pulling the power plug, whilst effective, can cause disk corruption, so we will do it the good old command-line way first. The best way to do this is:

  • Open terminal
  • type
    sudo shutdown -h now
  • Screen goes blank (no signal)
  • Pull the powerplug AND the HUB USB cable
  • Ensure lights are off

To reboot, replace the command with

sudo shutdown -r now

 

WiFi

Sadly, my WiFi dongle (Tenda w322u) didn't appear to work out of the box, so had to get this working with a few steps.

Worth noting that when I ran the install, nothing installed, so may have been working all along, and all I did was give it a nudge along. OR when you boot up the Pi, you may need to disconnect the dongle, and plug it in once loaded to be recognised. Also, it worked instantly after a reboot, no further config required.

update: It did work just fine, you just need to make sure you have checked the 'enabled' setting, and then run the scan. Be patient though. Also, I found that later it dropped my wifi completely, thinking there is a problem with my wifi dongle completely, so going to get a new one ordered now, opted for this USB dongle from Amazon PiHut.

 

Cool NOOBS notes

NOOBS is awesome for learning the basics of your Pi, and trying several of the different OSs available (Rasbian, RaspBMC as examples).

Also, after you have used it, you can wipe it completely by holding down shift on boot to change OS to another one (this will loose data) - very handy if you manage to lock yourself out completely when playing with init.d/vnc scripts - ahem!!!

 

Remote Communications

One thing that I was well aware of was that when in co-working environments I will not have a monitor, which is fine as I can SSH into the device to manage it. But wait, I need the IP to be able to do that, and without a monitor, how do I find out the devices IP. So, I decided to jump onto my android tablet and start installing apps to help. The winner by a long way is something called 'ezNetScan', whilst I have only so far used it on my network at home, it does a fantastic job of explaining devices to me with their names (I can also give custom names if I like). So in theory, so long as I setup my RaspberryPi at home first to allow SSH and have a respectable machine name (eg. 'RaspberryBadger') then I should be okay, will trial all this out on Tuesday and report back.

To go alongside this on my android, I have JuiceSSH setup, I usually use it for checking error logs on my mediacentre, or running updates, but now I can also connect to my Pi to run things if I want to check anything but not boot up the laptop. I resisted purchasing a tablet as tbh they don't have a purpose unless you make one for it. My purposes are: email, social media, news reader, management tool

 

VNC

Sometimes, SSH just wont cut the mustard, you want full desktop control from a remote machine. This is where VNC comes in handy, tips for this were taken from Neil Blacks blog post

  • Install tightVNC on the Pi:
    sudo apt-get install tightvncserver
  • Start server with
    vncserver
  • Install and open VNC software on your main machine (Ubuntu it's called Remote Desktop Viewer)
  • Connect to the IP of your Pi (remember to include the :1 at the end, as this is the desktop session setup
  • Setup a new init.d file for the vncserver: sudo vim /etc/init.d/tightvncserver
  • Paste in:
    #!/bin/sh
    # /etc/init.d/tightvncserver
    VNCUSER='pi'
    case "$1" in
        start)
            su $VNCUSER -c '/usr/bin/tightvncserver :1'
            echo "Starting TightVNC Server for $VNCUSER "
            ;;
        stop)
            pkill Xtightvnc
            echo "TightVNC Server stopped"
            ;;
        *)
            echo "Usage: /etc/init.d/tightvncserver {start|stop}"
            exit 1
            ;;
    esac
    exit 0
    
  • Save/exit vim Make script executable:
    sudo chmod 755 /etc/init.d/tightvncserver
    Add this script to the bootup defaults: sudo update-rc.d tightvncserver defaults Check this script runs:
    sudo /etc/init.d/tightvncserver stop
    then restart Ensure you have ssh access to the box (it locked me out first time I tried this) Reboot, it should setup vnc server under your pi username (with equiv password)

 

Camera

So, most of the projects I want to play with on my Pi (at least in the short term) involve the Pi camera. So, let's see if we can get that running easily.

  • Open terminal
  • go to Desktop:
    cd Desktop/
  • take photo:
    raspistill -o image.jpg
  • Done

Wow, it all works out of the box, that is nice and simple.

 

Mini tip

No matter whether you think you have everything you need, you probably dont. I have HDMI cables and USB hubs, so wasn't concerned, until I realised I had to start unplugging other things to get this to work. May get some Pi dedicated cables. Also, a cheap case for the pi is tempting, as it feels delicate, and so transporting it to co-working environments is not the easiest of things as a bare board.

 

Next Steps on my Pi config

A few things I still need to do to be completely happy with my Pi setup

  • File sharing - relying on a USB is a pain, so should look into getting SAMBA working nicely

 

The timelapse code

Okay, so the project I wanted to write was a timelapse piece to take photos over a long period of time. I have been writing this in Python, and so far it works nicely. Opted for a loop instead of the built in raspistill timelapse functionality as this allows for a little more control to escape out of it and monitor the progress.

If you want to take a look at the code so far, head in over to my GIThub project and look at the 'develop' branch at the moment. I'm afraid there is nothing in the README or anything yet as still got a few bugs to resolve around the camera failing overnight (had to disconnect and reconnect to resolve), aswell as my wifi dongle no longer connecting (grrr).

Also, there is of course lots more functionality to add, mainly things like:

  • Ability to manage the Pi and camera without a monitor (at present, I can trigger the camera, but the preview appears on the Pi desktop, not the VNC desktop
  • Some slightly easier feedback using LEDs because I want to
  • A physical button which when pressed allows me to start a timelapse for 12hours using the built-in default, and also a button to stop the current timelapse

Finally, to create an mpg with the still photos. I used ffmpeg and it seemed to just know what to do instantly, which is great, just move into the folder with all the photos in, and run a modified version of the below command:

ffmpeg -f image2 -i 1371571083_%d.jpg output.mpg
  • -f = force format
  • -i = filename

To view the first video, go to YouTube

Technologies: 

Blog & News

Monday, March 7, 2016

Okay, I know it is awful practice to put 2 things into one article, but I didn't want to write two tbh, so I will keep this tidy, and you can grab out what you need.

 

Subscribe to Blog & News

About

Cultivating a better future, with the seeds of better websites

For several years I have evolved through one of the largest media charities in the UK to the role of Senior developer.  I loved it there, but have to stepped out on my own as a freelance developer.

My main skills are with the Drupal CMS, developing code for it, ensuring standards through projects (whether that design, development, or planning), and leading teams to build applications they can be proud of.

Digital Consultancy, Web Development and Project Architecture are where I try to focus my skills, supporting my passion and desire to create stunning websites on time, in budget, and meeting your objectives.

To build a powerful web presence, I combine my creative, technical, and managerial experience (alongside a good splash of passion) which I have cultivated over 10 years in the industry, creating websites people want to shout about.

More on how I can help