Python IO on rPi

My next ‘real’ project involves implementing a web interface to control some of the things around swan tron global HQ, the half of the garage I reserved for my lab. I’ve been a huge fan of the Raspberry Pi since the mission was announced. Linux and IO…you have my attention. Add in the $35 price tag and my penchant for destroying hardware…huge fan is correct.

Before I start planning my real project, I need to figure out how this differs from the microcontrollers I’ve used in the past to deal with similar implementations. I know the CPU is going to show itself, but not to what extent. Time to start poking around.

I decided to horse around and knock out a few birds with one stone…python library, digital out, and basic pin function. Oh, and LEDs. Everyone loves LEDs.

the 80s called, they want their printer cable back

cobbler and bread

Prior to this effort, I have mainly explored the rPi via x. I’ve spent a decent amount of time inspecting the file structure (Debian, no surprises) and the xwin UI. It is no speed demon, but it does the trick. I have the wireless adapter configured and set to auto-start, which was most of the battle. It basically performs as advertised, which on paper is very awesome for the price.

My general setup for this was very simple. I bought a cobbler set from Adafruit, which acts simply to pull the IO pins out to a breadboard. Two LEDs, two resisters. A few jumpers. Very simple.

I booted the device, and used aptitude to update and snag the rPi GPIO library.
sudo apt-get update
sudo apt-get install python-rpi.gpio
That does the heavy lifting with the python implementation…sample code is available on the main python site. The update was I used vim to create a dirty python script…unworthy of a repository, but worth a pic:

fugly code

no comments, no worries

The digital outs worked as anticipated. Timing was a bit odd…I ended up playing around a bit with some pauses in order to tune the blinks as I wanted. It looks like coordinating pin outs might be tricky for more complex operations, but at least the library and hardware is up and running.

Don’t take my word for it:

The next steps will be interesting. Figuring out how to ssh into the box in order to run a script of this magnitude will be next, followed by profiling the voltage on the pinout. It should be able to throw my 5v relay with a little tweaking…if not I’ll figure out PWM and tackle the switching mechanically. Fun stuff to come…happy to be playing with the rPi finally. Stay tuned.

Android Side Project

Much like the girl has decided to keep at the in-womb thing, I have decided to keep at the Java thing. Little brat. I decided to figure out how to dump accelerometer / orientation data off of the phone, for use with the IOIO.

In short, I am roughly attempting to see how the data exists in its natural state, in order to figure out how to scrub and interface with my physical components.

android side project beta

warning beta stage warning

So far, I have nice looking code that blasts a force close scenario. Great.

Anyhow, I’m hoping my time on this effort comes to a close and the girl decides to join us. Teamwork…I’ll code, she can practice her singing.

Twitter CLI Teaser

I sort of forget what my original project entailed…something about tweeting via the command line, for Arduino purposes. You can pretty much just toss a bunch of words in a hat, and add ‘Arduino’ and ‘Command Line’ to them, and there you have one of my typical projects.

Anyhow, here we find ourselves. I am missing some dependencies with OAuth, but have managed to get twitter working from an interactive python shell:

cli twitter

command line-y

This section is as much for my reference as it is for public knowledge…I snagged the commands that I ran to snag my comments. It first prints swantr0n (my dev account) and then my primary Twitter feed, @swantron

swantron@mini9:~$ python
Python 2.7.1+ (r271:86832, Apr 11 2011, 18:05:24)
[GCC 4.5.2] on linux2
Type “help”, “copyright”, “credits” or “license” for more information.
>>> import twitter
>>> api = twitter.Api()
>>> feedSwantron = api.GetUserTimeline(‘swantron’)
>>> feedSwantr0n = api.GetUserTimeline(‘swantr0n’)
>>> print [ x.text for x in feedSwantr0n]
['development account for @swantron | tune into http://t.co/SpDFBkK for projects', 'hello world']
>>> print [ x.text for x in feedSwantron]
['@vftb ...you better believe it', 'Twitter Project Teaser : http://t.co/7ZrOLUn | one step closer to tweeting from the #CLI ... might take a run at make it tweet', 'Might need to implement some sleeves into my wardrobe... @adafruit just flipped the script with open source cuff links', 'unsafe at any speed... updating #ubuntu on the road http://t.co/Q8gfc56', 'Upgrading Mini 9 to #Ubuntu Natty http://t.co/7yT9w81 | posting to kill time... review here ( http://t.co/RM675lX ) lunch-aft on the morrow', 'http://swantron.com/basic-mower-cord-repair/ #DIY lawn mower repair from a #math major. spoiler: it works', "#arduino no you didn't http://swantron.com/html-to-python-to-arduino-to-lcd/ #LCD project, stepped up a bit", 'working on a python script to dump info from web to LCD http://swantron.com/python-teaser/ #arduino', 'http://youtu.be/MpomhE6dgww video of #boc unboxing (for the win)', '#woot bag-o-crap unboxing @ http://swantron.com/woot-boc-unboxing/ not too shabby', 'http://swantron.com/compiz-error-in-ubuntu-natty/ still finding some compiz issues in #ubuntu 11.04', '#Arduino project @ http://swantron.com/command-line-lcd-arduino-interface/ | driving LCD screen via command line', '@RobotGrrl... what version are you running? I had no problems with IOIO / Droid 2 (froyo 2.2)', 'Easy LCD #Arduino Display | http://swantron.com/easy-lcd-arduino-display/ | feels good to have a warm soldering iron and functional hardware']
>>>

I will keep plugging away until I get this thing hammered out. If not, I can print this suff to my LCD for a real-time Twitter display. Could be cool either way.

Command Line LCD Arduino Interface

Liquid crystal displays are pretty awesome. Command line interfaces are very awesome. Hmm…

I started daydreaming at work about how to go about making hardware interface with an RSS feed. I have seen some projects that use Arduinos with ethernet shields to check Twitter, for example, but they seem unnecessarily bulky. Or clumsy. I spend a lot of time working on the command line, and love to put together dirty little scripts to solve problems. It sort of goes along the lines of ‘when you have a hammer, everything looks like a nail’…I figured that the same thing could be implemented with a little shell scripting and my trusty Arduino, sans anything complicated.

So far, so good.

bad lab mobile

bad lab mobile

I put together a sketch (after the bump) to drive my LCD, writing serial output to the screen. After verifying that the sketch worked via the Arduino IDE’s serial monitor, I popped open a CLI and got to work. FWIW, I am using Ubuntu 11.04 still…ctrl-alt-t pops open a terminal window…unity has me all over shortcuts these days. Anyhow, I was able to verify that I could echo text and direct it to the USB port that the Arduino was mounted to. No sweat.

As a proof of concept, I decided to display the number of times that I had the word “awesome” on swantron.com. Once the LCD was shown to work, the sky is the limit…see some regex, pipes, wget, and so forth in action:

CLI

CLI FTW

Survey says:

+1 awesome

+11 awesome

Eleven “awesome”s. Awesome.
(Hit the bump for some code, an oddity, and more fun…)
Continue reading

Network Admin Fail

I haven’t had much to publish as of late. Not for lack of trying; I have been quiet because of a damned roadblock. I figured I could smash my way through a few MAC/IP settings, and have my Ethernet Shield doing all sorts of cool stuff with my Arduino. I was sorely mistaken.

This afternoon, I took another stab at the thing. Even after attempting to put together a cross-over setup…I still cannot telnet to my goddamned card. I don’t know how many arp and ifconfig commands I have sent, but it has to be in the triple digits. To no avail.

Looks like it is back to network 101 for this guy. Son of a bitch. We’re going manual. On the bright side, I worked inside today…

pledge

+1 counter-height table

Bonus Pledge, courtesy of Katie.

For what it is worth, I found a few commands that don’t seem to work on the command line…

arp -a

command not found

I think I will pack this thing to work and tackle it on my lunch breaks. Enough is enough.