Vous êtes sur la page 1sur 17

Raspberry Pi as an Embedded

Platform

Bob Clough
@thinkl33t
thinkl33t.co.uk

Me

In Real Life

Software Developer

Sysadmin

In my 'Free' time

Maker

HACMan Organiser

Roboticist

Builder of Big Stupid Toys!

What we'll cover

Booting straight into a python script

Chatting with an Arduino

Direct IO from python

Booting straight into a python script

Two steps needed

Auto login

Making a script run automatically

Auto Login
Edit /bin/autologin.sh
#!/bin/bash
/bin/loginfroot

Make the script runnable


>chmoda+x/bin/autologin.sh

Auto Login
Edit /etc/inittab
Find the line: (it should be line 54)
1:2345:respawn:/sbin/getty115200tty1

Change it to:
1:2345:respawn:/sbin/gettynl\
/bin/autologin.sh115200tty1

Woohoo!

Your Pi should now be automatically logging in


as root.
Now lets run a script...

Making a script run automatically

Edit /root/.bashrc

if[[$(tty)=='/dev/tty1']];then
/root/operation/op.py
endif

What?

If we are in the first terminal, run the script at


/root/operation/op.py

Chatting with an Arduino

Talk to the serial port

Seriously, thats it

Chatting with an arduino

Install pyserial

sudoaptgetinstallpythonserial

Within python

importserial
ser=serial.Serial("/dev/ttyACM0",9600)
while1:
line=ser.readline().strip()
print(line)

Show Screamin' Frank Video

http://www.youtube.com/watch?v=j5s-SlHvb_c

Direct IO from python

IO using the pins on the Pi

17 GPIO

UART (serial port)

SPI

I2C

GPIO Pins

3.3V
2mA 16mA per pin
maximum
Completely
unprotected!

Dont put 5V into


them
Dont pull too much
current

GPIO Pins

Hardware

Slice of Pi from
Ciseco
Devboard for Pi,
prototype area

GPIO Pins

Install Python IO support

>wget
http://pypi.python.org/packages/source/R/
RPi.GPIO/RPi.GPIO0.1.0.tar.gz
>tarzxfRPi.GPIO0.1.0.tar.gz
>cdRPi.GPIO0.1.0
>sudopythonsetup.pyinstalla

GPIO Pins

Twiddle the pins!

importRPi.GPIOasGPIO
GPIO.setup(18,GPIO.OUT)
GPIO.setup(11,GPIO.IN)
while1:
ifGPIO.input(11):
GPIO.output(18,False)
else:
GPIO.output(18,True)

Yaaaaay!

Vous aimerez peut-être aussi