Python and Arduino (part 1)

It’s been a while since I last played with an arduino . I think it was while making some demos for bike lazer tag (more of that to come)… There seem to be a few examples online of how to get your arduino playing with python, but most of then seem to focus on getting servos to move around – which is cool, but surely the fun to be had with an arduino is getting it to talk ‘to’ your computer.

So… with this in mind, and my little box of components that I brought with me from London, we will see what we can get going. I’m not going to put everything up here, but if you are interested in anything just drop me an email ben(at)beoliver(dot com).

Firstly, I would recommend downloading pyserial. It works with both 2.X and 3.X python. ( i will be using 2.X for the moment ).

Secondly, you are obviously going to need an arduino for this !

LETS BEGIN…

1. upload an Arduino sketch with the following :

void setup() {
Serial.begin(9600);
}

void loop() {
int sensorValue = analogRead(A0);
Serial.println(sensorValue);
}

All we are doing here is telling the Arduino to start a serial connection, and any value that is recorded on Analog pin 0 should be sent via the Serial connection.

2. after installing pyserial we will begin by writing the following:

#!/bin/env python
import serial
import time
# plug in your arduino and look in /dev
name = '/dev/tty.usbserial-A9007W1P'
baud = 9600

arduino = serial.Serial(name, baud)
time.sleep(2)
# pause as the Arduino is restarted by the serial connection
while True:
  output = arduino.readline()
  print output

And there you go! you are reading the output from your arduino (this is just the same as the serial monitor in the Arduino app).

Now the first thing you might notice is that the output is read as a string. and secondly you sometimes get non numerical characters :

’1023′
’100?30′
’1023′

we will write a tiny function that will test the output and return an int if possible:

def str2int(input):
  try:
    return int(input)
  except ValueError:
    pass

# our output can now be:
output = str2int( arduino.readline() )

This now means that our output can be evaluated as an integer.

KIND WORDS & FOG

I got an email the other day from Matt at Beautiful/Decay, he has written a very nice little post about In Search of Our senses. See it – here
In other news there was some crazy fog in Oslo today. I’m sure it wasn’t actually that crazy, but I enjoyed it anyway. there are some photo’s up on flickr – here

THE FUTURE OF BANKING?

Off shore data centers for optimal trading…

SUPER COMPUTER

I have been spending a lot of time with UNIX Bash recently… And for some reason I was looking at youtube videos of supercomputers… This particular one is run by the US Navy, and is comprised of a couple of thousand PS3′s. There is something about it that I love, perhaps it is the hazard tape on the floor, of the fact that it looks like milk crate holders are being used.

NEWSPAPER INFO-GRAPHICS (A PLAY)

Designer1: “Can you do an illustration for this interview… ”

Designer2: “Yeah, sure”

Designer1: “Do you want a rough translation?”

Designer2: “It’s OK… Im sure Google Translate will work”

… GOOGLE TRANSLATE

Designer2: “Right So I’ve got an idea, and according to the Google Translation its going to sum up the piece – perfectly – … Just give me a couple of minutes to get it going”

… SOME MINUTES LATER

Editor: “What’s that?”

Designer2: “It’s an info graphic, I translated the interview and I thought this would be perfect!”

Editor: “You know we need to show the face of the interviewee”

Designer2: “I did not know that”

PAUSE

Designer2: “I’ve got an idea… just give me half an hour”

Designer1: – looking at the screen of Designer2 – “I’m not sure… what is it?”

Designer2: “Well it’s using the info graphic… but… It’s also going to be the guys face…”

Designer1: “(Designers ‘hmmm’) “Are you sure”

Designer2: “If it works it will work, I think it will work…”

Designer2 finishes image and makes a pdf

LATER THAT NIGHT

Editor: “Designer2 can you come with me a minute?”

Designer2 walks with Editor into office

Editor: “look at this! and then stand over here! look at it now!”

Designer2: “I know, If people work it out I think they will like it…”

CURTAIN CLOSE

To read the full interview have a look on Universitas.no. It’s the largest Student Paper in Norway with a weekly circulation of 17,000. God Stemning!

LE GLITCH FICTION


LibĂ©ration has written an article on the recent Glitch Fiction Show in Paris – I am not sure in which edition ( I got an email from Nelly Ben Hayoun today with a pdf of the article ) but I am super chuffed that they have used on of my images for the lead. I am going to try and get hold of a hard copy. I also saw something on the Wired blog, I really don’t have my finger on the pulse…

pdf HERE

PHOTOSHOP LOOTER (OLD)


I never posted this but it was a submission of mine to the tumblr-site photoshoplooter. I think it’s on page three somewhere. They are planning to make a book – but have some copyright problems…

UNIVERSITAS (WEDNESDAY UPDATE)


mellomfagtest

UNIVERSITAS

I spent most of today working on the cover page for the magazine section “Mellom Fag” of next weeks edition of Universitas. While I would love to post the cover today, I suppose I should wait until the Edition comes out. Meanwhile you can enjoy one of my last contributions to the paper.

JUVENARTE (UPDATE)

Norwegian Customs… Routine Search… Well it got here in the end. Thanks to Alex Prior back in London for getting the package sent (and for the masterful use of Comic Sans!)… If I had a fancy phone I would have taken a picture. 20 minutes after arriving at the local Post office the jumper was delivered to Gallery Ramfjord. The next day there was an opening. I went – remembered why I don’t like openings – left and got drunk. Ahh, to be an artist…