Change a Space with a Raspberry Pi

This slideshow requires JavaScript.

The assignment here is to pick a space on campus that’s boring and make it interesting. The only requirement is that you use either a Raspberry Pi single-board computer or an Arduino microcontroller to do it. This is another project in our Design Engineering class. Students tackle this project after having learned to program with the Beauty through Processing project. Unfortunately I’ve lost most of the photos from this year.

This idea is based on a cool project that Jaymes Dec at Marymount School showed me where students had turned a staircase into a musical instrument.

Materials and Tools

Raspberry Pi boards. Adafruit is a good source in the US.
Arduino boards, if you want to use these too.
Pi Camera(s) if students will be working with images or video
(Note: new versions of all of the above are constantly being released, check current specs)
Breadboards, jumpers, resistors, diodes – see below for specifics
Sensors for light, sound, movement (PIR), etc
Arcade-style buttons
5-12V power supplies
Old computer speakers
Basic woodshop
Wood scraps and other junk

Learning goals

This project is a chance to transfer programming skills learned while making graphics to physical computing, wherein computers interact with the physical world. The programming will be very different, but the underlying concepts – controlling a program’s flow, evaluating data and acting upon it, being able to figure out how a language works using a reference – are the same. Ideally these concepts sunk in in the previous project. If they didn’t, the teacher will know and can act to shore things up. New skills for this project include advanced circuit design with electronic components, hardware programming, reading and creating schematics, and in most cases, some form of interface design. Some students choose projects that require programming languages other than Processing, like Python.

Method

Note: I’ve put some technical notes at the end of this post that can help with getting set up.

I started the project by sticking a Raspberry Pi, a motion sensor, and a sawed-off computer speaker inside an Oscar the Grouch puppet. When the motion sensor was triggered, the pi was programmed to play different audio files according to the time – a growly voice saying either “Thanks for getting here early”, “You barely made it”, “You’re late!”, and “You should feel shame for being so late”. I mounted Oscar on a table by the door and waited. It got funnier as more kids came in, because we were all waiting for the next victim.

This simple demo showed the most basic kind of interaction – a project reacting to movement. Oscar had changed the space – the entry to the maker lab – and made it more interesting. We talked about what else was possible. A Pi can gather information through a variety of sensors you can attach to it, but also from the internet. It can output information to a screen, but also by turning physical switches on and off – which means it can do almost anything. We looked at some cool examples.

After doing some brainstorming, students came up with the following projects:

  • A machine that sprays you with water if you get close enough to it
  • An installation that senses your approach, yells at you to “look up!”, snaps your photo and adds it to a gallery
  • A hidden unit that makes fart sounds when you walk by
  • A Spanish vocabulary video game kiosk
  • A teddy bear that insults you more intensely the closer you get
  • A sound level sensing traffic light for the library

..And we got to work. Before starting, students needed to learn how to operate the Pi (or in the case of the traffic light, an Arduino, which is easier to use with analog inputs like sound levels). I set up the Pi’s to run headless, which means without a monitor, keyboard, or mouse. Instead, you use a regular computer to connect to the Pi via wifi, and control it using that computer’s screen, keyboard and mouse. Setup notes below. We did a lesson on using the Pi’s GPIO (general purpose input/output) pins with Processing, the language they used in the previous project. In this lesson each student had to get a simple circuit working wherein pressing a button on the breadboard made an led light up. This would be simple to do with a battery, a switch, and an led, but we were aiming higher- students had to program the Pi to sense the button being pressed, then have the Pi turn on the led. Hooking up the button requires one to understand  how a pull-down resistor works.

 If you have a button attached on one side to 3.3V, the other to a pin, that pin is going to be connected to 3.3V when you pullDownResistorpress the button, and when you digitalRead() the pin, it will read HIGH (meaning on). The problem is what will digitalRead() come up with when you’re not pressing the button? In this case the pin isn’t connected to anything, which can lead to unpredictable results. So what we do is connect the pin to ground with a resistor. Electric current is like water, it likes to take the easiest path. A resistor is like a spigot, it slows down the flow of current. When you’re not pushing the button, current will flow through the resistor to the ground because it has no other choice and the pin will read LOW (meaning off). When you press the button, you’re giving the current a resistance-free path to the 3.3V pin that it much prefers, and the pin will read HIGH. This circuit is called a pull-down resistor because it “pulls” the pin to LOW when nothing is happening.

Once kids get their minds around this and get this circuit working, they’re ready to start figuring out the circuits they’ll need for their projects. We go over simple circuit diagramming (schematics). Readable circuit diagrams are one of the requirements for the project. Students who want to use a motor (like this making the water spraying project) will need to understand a trickier circuit that uses a MOSFET transistor, as the Pi isn’t powerful enough to drive a motor, just to turn it on and off. The motor needs its own power supply.

Students experienced plenty of setbacks, particularly with the more complex projects. The camera project required the kids to learn Python, as Processing currently doesn’t work with the Pi camera. The Spanish vocabulary video game required more complex programming than the kids expected. The water spraying students had trouble getting a coffee-grinder motor to pull the trigger on a spray bottle, which required more torque than they expected – the lesson being, test early and often. Except for the sprayer, all the student projects worked by the end. We spent about a month on this.

Technical notes: How to set up a headless Pi

I cobbled this together from various tutorials and my own testing. The idea is to set the Pi’s wifi adapter to a fixed ip address to it joins the wifi network on boot. I had to ask our tech dept to reserve an ip for each Pi (by its MAC address) that we used in the class, otherwise the Pi won’t connect. This next bit requires some familiarity with Linux.

  1. start with pi / raspberry. startx. raspi-config. internationalization, keyboard, US. restart.
  2. sudo su; edit /etc/network/interfaces to say:
    auto wlan0
    allow-hotplug wlan0
    iface lo inet loopback
    iface wlan0 inet dhcp
    wpa-ap-scan 1
    wpa-scan-ssid 1
    wpa-ssid YOUR-WIFI-NETWORK-NAME
    wpa-key-mgmt WPA-PSK (or whatever your network uses)
    wpa-psk broadcast (or whatever your network uses)
  3. install tightvnc
    sudo apt-get install tightvncserver
  4. run vncserver to set password
  5. Get tightvnc to start on boot:
    sudo su
    cd /etc/init.d/

    Create a new file here containing the following script:

    #! /bin/sh
    # /etc/init.d/vncboot
    ### BEGIN INIT INFO
    # Provides: vncboot
    # Required-Start: $remote_fs $syslog
    # Required-Stop: $remote_fs $syslog
    # Default-Start: 2 3 4 5
    # Default-Stop: 0 1 6
    # Short-Description: Start VNC Server at boot time
    # Description: Start VNC Server at boot time.
    ### END INIT INFOUSER=root
    HOME=/root
    export USER HOME
    case “$1” in
    start)
    echo “Starting VNC Server”
    #Insert your favoured settings for a VNC session
    su – $USER -c “/usr/bin/vncserver :1 -geometry 1280×800 -depth 16 -pixelformat rgb565”
    ;;
    stop)
    echo “Stopping VNC Server”
    /usr/bin/vncserver -kill :1
    ;;
    *)
    echo “Usage: /etc/init.d/vncboot {start|stop}”
    exit 1
    ;;
    esac
    exit 0
  6. Save this file as vncboot (for example)
  7. Make this file executable:
    chmod 755 vncboot
  8. Enable dependency-based boot sequencing:
    update-rc.d lightdm remove
    update-rc.d vncboot defaults
  9. enable cut and paste from pi to mac:
    sudo apt-get update
    sudo apt-get install autocutsel
    cd ~/.vnc
  10. and edit the xstartup file to add the line “autocutsel -fork”, e.g.
    #!/bin/sh
    xrdb $HOME/.Xresources
    xsetroot -solid grey
    autocutsel -fork
    #x-terminal-emulator -geometry 80×24+10+10 -ls -title “$VNCDESKTOP Desktop” &
    #x-window-manager &
    # Fix to make GNOME work
    export XKL_XMODMAP_DISABLE=1
    /etc/X11/Xsession
  11. and reboot
  12. Now you should be able to connect (from a mac) to your Pi like this:
    vnc://xxx.xxx.xxx.xxx:5901 (5900 is port, 1 is level, xxx is your ip)
  13. If you want to be able to paste mac to pi, download chicken vnc 2.2b2 here:
    https://sourceforge.net/projects/chicken/?source=typ_redirect
  14. install processing on the Pi via VNC
    curl https://processing.org/download/install-arm.sh | sudo sh
If students aren’t hearing audio from speakers connected to a pi, try this:
sudo raspi-config -> advanced options -> audio -> force to 3.5mm jack. Turn volume all the way up.

Categories

Share & Print

0 0 100 0

No Comments

Leave a Reply