Archive for the ‘ Electronics ’ Category

Raspberry Salad…

…or Groovy Pi.
One of my favorite internet radio stations is soma fm, and in particular, their Groove Salad station.  I figured what better to do than to turn my Raspberry Pi into a Groove Salad music streamer.

After searching the internets, I came upon MPlayer, which you can execute via the command-line.  To install on the Pi:

$ sudo apt-get install mplayer

Then to start streaming Groove Salad via it’s playlist:

$ mplayer http://streamer-dtc-aa01.somafm.com:80/stream/1018

I got the address info by downloading the pls file from soma fm, opening it in a text-editor and extracting that line.

Plug in some headphones (or better yet, hook it to your stereo), and you’re good to go!

Go to Raspberry Salad Part 2: Raspberry FM

Printing PLA with the Replicator

I’ve been printing in ABS since receiving my Replicator last year.  Today I finally made the switch over to PLA.  The ‘why’ is mainly to try something new… see how a new medium prints.  But there are other benefits:

  • PLA doesn’t need to have the HBP (heated build platform) heated to 110 deg Celsius like ABS does :  I read it dosen’t need to be heated at all, but many people find success at around 40 deg C.  What this means is the HBP heats a lot faster…. meaning things print faster.
  • You don’t have to affix kapton tape to the HPB:  ABS sticks really well to kapton tape, and that’s why it’s used.  But it’s difficult and time consuming to get the tape applied to the HPB:  PLA can print on ‘blue painters tape‘, which is much more forgiving when being applied to the HBP.
  • PLA is biodegradable:  More ‘green’ than ABS.

First test run successfull, pic below.  Some notes on the process:

  • Extruder temp set to 210 deg C.
  • HBP temp set to 40 deg C.
  • Purged the ABS by ‘loading’ the PLA for 5 minutes straight, per online docs.
  • GCode compiled via ReplicatorG 0040, Replicator firmware 6.2.
  • Used ‘natural’ colored PLA, it’s semi-transparent.

I’m still getting a ‘bug’ where when during the pre-heat, filament ‘leaks’ out of the extruder nozzle.  On the ABS it would happen slowly, but with the PLA, I can physically see it leak out.  The side effect is the ‘anchor’ it first builds on the corner of the HBP doesn’t always fully form… which can screw up the start of the printing session.  But this first print tured out a-ok.

Tiny PLA vase : Success!

Raspberry Pi WebIDE & making things blink

On the Raspberry Pi, just like on the Arduino, the first thing you learn how to do is make an LED blink.  The Raspberry Pi Users Guide walks you through this process, but this was one of the few areas (so far) with the Pi that I ran into trouble, namely over proper access to the GPIO pins, the Pi Cobbler‘s ribbon-header orientation, and how to physically code on the Pi itself.

Look at that LED blink!

GPIO Pin issues

There appears to be two different ways to access the pins via the RPi.GPIO Python library: Via the ‘board pin numbers’ (1->32), or via the ‘GPIO numbers’, which many sites (like this one) refer to.  In addition, hardware expansions like Adafruit’s Pi Cobbler (which I’m using) base their silk-screens on the ‘GPIO numbers’.  Long story short, you simply need to tell your code ahead of time which method you’re using:
To use the physical board numbers:

import RPi.GPIO as GPIO
# Set to use physical board pin nums, rather than GPIO nums:
GPIO.setmode(GPIO.BOARD)

To use the ‘GPIO’ numbers:

import RPi.GPIO as GPIO
# Set to use GPIO nums, rather than physical board nums:
GPIO.setmode(GPIO.BCM)

Pi Cobbler Issues

I got the Pi Cobbler via the Maker Shed’s “Raspberry Pi Starter Kit“.  The kit comes with a lot of good stuff to get your started (including the LED that’s blinking next to me).  The Cobbler cable has a header on each end (one plugs into the Pi, one into the Cobbler itself), and each header has a notch on the side to help you understand how to orient it.  At first glance, it looks like the headers are interchangeable… meaning, you could plug either one into the Pi, or the Cobbler.  Very long story short, that’s not true:  To get the side of the cable with the stripe to line up properly with the GPIO pins on the Pi… only one side will work.  I was convinced I had a defective cable that required me to plug it in backwards.  But two days later I realized if I simply flipped the whole cable around everything ‘just worked’.  The Cobbler documentation stresses you insert the cable with the side with the stripe to the left side of the Pi,… but since I thought mine was screwed up…. chaos ensued.  Funny that I didn’t figure this out until I finished this blog post.  The above pic in fact shows the ‘flipped’ insertion in the Pi before I corrected it.

Coding Issues

The final issue I hit was how to actually code Python on the Pi:  I use Wing IDE Professional, and have grown very used to it… but they have no Linux ARM distribution (that I’m aware of).  Going back to IDLE is painful… and I’ve never been a VIM user.  Based on a previous post I can SSH and VNC into the Pi from my Mac, allowing me to code on the mac and copy\paste over to the Pi for execution… but this is still pretty clunky.  After researching for a while I realized, why don’t I try Adafruit’s Raspberry Pi WebIDE?  Installation was easy based on their tutorial, and I was up and running in no time.

Here is my code to make the LED blink, running in the WebIDE\Pi as I type…

#!/user/bin/env python
"""
gpiooutput.py
Modified from pg 195 of "Raspberry Pi Users Guide"

Make a LED flash on\off.
Hardware Setup:
* LED+ lead hooked to GPIO 17 (board pin 11)
* LED- lead connected to resistor.
* Resistor connected to ground (board pin 6)
"""
import time
import RPi.GPIO as GPIO

# This is the GPIO number.  The actual board pin is number 11.
PINOUT = 17

def main():
    GPIO.setmode(GPIO.BCM) # Set to use GPIO nums, rather than physical board nums
    GPIO.setup(PINOUT, GPIO.OUT)
    print "Blink begins!  Press ctrl+c to exit"
    try:
        i = 1
        while True:
            GPIO.output(PINOUT, True)
            print "Blink %s ON!!"%i
            time.sleep(2)
            GPIO.output(PINOUT, False)
            print "Blink %s OFF!!"%i
            time.sleep(2)
            i += 1
    except KeyboardInterrupt:
        GPIO.output(PINOUT, False)
        print "\nBlink DONE!"
        return

if __name__ == "__main__":
    main()

The WebIDE doesn’t have any fancy features yet (that I’m aware of) like debugging & code-completion, but it is alpha software, so hopefully it will become more robust as time goes on.  On the plus side, it will auto-connect to the Pi over the network (no need for SSH), gives you a built-in terminal for the Pi, and stores all the code  in the cloud via Bitbucket (if you’re into that sort of thing).

And thus, the fruits of my labor:

Raspberry Pi + Pi Cobbler + WebIDE = blinky LED

 

Connecting the Mac to the Pi

The main hurdle I’ve had with the Raspberry Pi is simply seeing the screen:  Since I don’t have  a spare monitor laying around, it’s plugged in over HDMI to my livingroom TV.  Sitting on my couch,… the text is really small.

Thanks to the awesome people at Adafruit Learning Systems, they’ve provided two tutorials specifically for logging into your Pi remotely over SSH (Secure SHell), and remote-controlling the desktop via VNC (Virtual Network Computing).  This gives you the advantage of not needing a spare monitor, keyboard & mouse to control the Pi:  You can use your current PC’s setup.

I don’t know anything about Linux or sysadmin work, but their tutorials worked exactly as shown and I was connected in no time.  I’m posting this mainly as a reminder to myself how I got all this stuff hooked up…

  • First, you need to get a SSH connection from your computer (in my case, Macbook Air) to the Pi:  Adafruit’s Raspberry Pi Lesson 6: Using SSH shows you how.  Once this is setup, you can easily remotely login from a Terminal on your PC, and take control of the Pi.  But you don’t have access to it’s gui system, only the command-line.
  • Second, to control the Pi’s gui, you need to install a VNC server on the Pi, and a client on your PC (Adafruit recomends RealVNC’s ‘VNC Viewer’).  Their tutorial covers all of this: Adafruit’s Raspberry Pi Lesson 7: Remote Control with VNC.

Once all that software is installed\setup\configured, how do you make the connection?

  • Boot the Pi, wait for it to ‘be ready’.
  • Open a terminal on your PC:  SSH into the pi (put in appropriate ifnet address of the Pi and login name):
    • ssh 192.168.2.97 -l myPiLogin
  • The terminal is now controlling the Pi.
  • Next, start the VNC server on the Pi:
    • vncserver :1
  • Now that you have a SSH connection to the Pi, and the VNC server running on the Pi, you can connect via VNC Viewer on your PC:
  • Open the VNC Viewer app, and connect to the pre-configured server you made earlier:   For example, 192.168.2.97:1
  • After entering in the password, the Pi’s desktop should spring to existence on your PC.
If you forget the address of your Pi, you can run ifconfig from the pi itself (which of couse means hooking it back up to a monitor\keyboard) to get it.
Programming Python on the Pi will be so much easier now…

Pi's desktop on my Mac's desktop: Success!

 

Raspberry Pi

I was lucky enough for my birthday to get not one, but two Raspberry Pi‘s (model B).  And since it’s holiday time, I thought it worked well with the Christmas tree:

Here you can see the Pi with it’s “Maker Pi” box, HDMI, Ethernet, USB, SD, and GPIO all connected.

In addition, the gifts came with:

Upon arrival I got the USB cards flashed with the Raspian “Wheezy” Linux distro (something I’d never done), got myself setup with a custom Linux login (something I’d never done), installed the Python GPIO library, and even got Chromium installed as the web browser.  I had to buy a powered USB hub, and through that hooked up a wireless keyboard and mouse (the Pi powers itself over the usb directly).  I have no spare monitor, so right now it’s hooked up to my main LED flatscreen in the living-room over HDMI:  The text is so small… and so far away….  I recently just soldered up the Adafruit Pi Cobbler which will let me interface its GPIO pins with a breadboard.  And shortly I hope to make some LED’s blink.

It’s nice to be back on the command-line again… reminds me of my DOS days (and the Apple ][ before that), and Linux is turning out to not be as scary as I thought it would be.  And it doesn’t hurt that my neighbor is IT 😉  It will be interesting to see how this compares to the Arduino, already I’m learning that the Pi is 3.3v compared to the Arduino’s 5v, it has no ADC, nor realtime clock.  All things that can be purchased separately.  But I’m excited to see what it can do.

Here’s a few other interesting links I’ve ran across: