Tuesday, November 6, 2012

Overdue Updates

For my one reader (Thanks Mom!) I know the updates for the Ultrasound Phantoms are overdue. There is progress. Unfortunately, you don't get to read about it today.

 A couple of months ago I read about this cool new computer, the Raspberry Pi. As far as I know, they've only shipped the model B board, which is $35. That money gets you a Linux computer that is slightly bigger than a credit card. You need to supply a keyboard, SD card, and that's really it. If you want to run a Windows-like GUI, you'll want to have a mouse as well. It's got a couple of dozen general purpose I/O pins to let you build in your own gadgets and stuff (Read a pushbutton, blink an LED, etc).

 The board supports at least half a dozen types of Linux. I went with the Adafruit Occidentalis build. It's build off of Debian Linux, with some added extras, This incorporates libraries for SPI, I2C, One Wire, and WiFi built right into the distro. Couple this with the already included Python (Version 2.7 and Version 3.2) and you have a junior hacker's dream.

 I'll reiterate: $35. I had everything else lying around the house (SD card, spare keyboard and spare mouse). I have a computer that will hook up to pretty much any video display I'll run into. It supports HDMI 1080p right out of the box. It plays nice audio. It surfs the web (slowly, sometimes). For less than the price of a copy of Windows, a new video game, or a tank of gas (holy crap! Yeah, and I drive a Prius).

 It's Linux. For some people that will be a deal breaker (Again, less than the cost of...). I'm having to relearn a fair amount. I used Linux a couple of times, years ago. I had a Linux box once, to toy around with. I had a dual boot netbook where I utilized Ubuntu to run some network diagnostics.

This time around, I'm really focusing on the command line interactions. The little gizmo is decent with the GUI but it does slow down a fair amount at times. However, this thing screams from the command line.

 I'm re-discovering Python as well. I learned 2.7 during college (Thank you, Dan Fleck. You got me excited about programming, and changed my life). It looks like there is a serious attempt to use Python 3 in the Raspberry Pi world.

 I wrote a quick utility to poll the Adafruit Pi Cobbler pin-breakout board. Eventually I want to get the pin states over a network.
import RPi.GPIO as io 
io.setmode(io.BOARD) 
for i in range (26): 
     try: 
          io.setup(i,io.IN,pull_up_down=io.PUD_UP) 
     except: 
          continue 
     try:
                    print(io.input(i),i)
               except:
                   
                    print('invalid pin ')
                    print(i)
          print('Complete')

I'm running the program over SSH, so I guess, technically, I'm checking the pin state over the network.

It's important to note:
First, you have to run the program with superuser permissions (sudo).
Second, the program numbers the pins differently than the pins are numbered on the Adafruit breakout. Third, you probably need to be REALLY careful with this code. It attempts to mess with all of the pins, some of which aren't GPIO pins. So far, it doesn't seem to have bothered anything.

I'm waiting for some more parts so that I can start messing around with I2C sensors. Eventually I want to build an environmental monitoring system.

No comments: