Raspberry Pi for IPRUG

24
Raspberry Pi Frank Carver frankcarver.me raspberryalphaomega.org.u k

description

A short talk about the Raspberry Pi for the Ipswich Ruby User Group

Transcript of Raspberry Pi for IPRUG

Page 1: Raspberry Pi for IPRUG

Raspberry Pi

Frank Carver

frankcarver.me

raspberryalphaomega.org.uk

Page 2: Raspberry Pi for IPRUG
Page 3: Raspberry Pi for IPRUG
Page 4: Raspberry Pi for IPRUG

• ARM1176 CPU @700MHz

• Broadcom BCM2835 chipset & GPU

• 512MB* RAM

• USB, Ethernet, 1080p HDMI, audio

• 8 GPIO pins + UART, SPI, 12C

• Storage on SD/SDHC Card

• Linux, RiscOS etc. or “bare metal”

• About £25

Page 5: Raspberry Pi for IPRUG

Arduino Uno

Page 6: Raspberry Pi for IPRUG

• ATmega328 CPU @16MHz

• No GPU

• 32K Flash, 2K SRAM, 1K EEPROM

• USB, no network or video

• 14 GPIO pins, 6 analogue inputs

• No storage

• “Bare metal” cross-compile only

• About £18

Page 7: Raspberry Pi for IPRUG

Cheap Dell PC

Page 8: Raspberry Pi for IPRUG

• Intel CPU @2.8GHz

• Intel HD GPU

• 2GB RAM

• USB,Ethernet,SATA,HDMI,Wireless,…

• No IO pins

• 500GB hard drive, DVD

• Windows, Linux, etc.

• About £300

Page 9: Raspberry Pi for IPRUG
Page 10: Raspberry Pi for IPRUG

Software Development

Bare Metal• Assembler• Cross-compiled C/C+

+ etc.• Hand-built languages

Linux• Pretty much anything• Python• Ruby• Java• perl• PHP• bash• …

Page 11: Raspberry Pi for IPRUG

So let’s do some Ruby

Page 12: Raspberry Pi for IPRUG

So let’s do some Ruby

Step 1: installation

Page 13: Raspberry Pi for IPRUG

So let’s do some Ruby

Step 1: installation

• sudo apt-get install ruby1.9.3

That wasn’t so hard

Page 14: Raspberry Pi for IPRUG

Ruby talks to hardware

File.open('/sys/class/gpio/export', 'w') { |file| file.write("17") }File.open('/sys/class/gpio/gpio17/direction', 'w') { |file| file.write("out") }File.open('/sys/class/gpio/export', 'w') { |file| file.write("27") }File.open('/sys/class/gpio/gpio27/direction', 'w') { |file| file.write("out") }File.open('/sys/class/gpio/export', 'w') { |file| file.write("22") }File.open('/sys/class/gpio/gpio22/direction', 'w') { |file| file.write("out") }

begin

while true do for r in 0..1 File.open('/sys/class/gpio/gpio17/value', 'w') { |file| file.write("#{r}") } for g in 0..1 File.open('/sys/class/gpio/gpio27/value', 'w') { |file| file.write("#{g}") } for b in 0..1 File.open('/sys/class/gpio/gpio22/value', 'w') { |file| file.write("#{b}") } sleep 1 end end endend

rescue SignalException File.open('/sys/class/gpio/gpio17/value', 'w') { |file| file.write("0") } File.open('/sys/class/gpio/gpio27/value', 'w') { |file| file.write("0") } File.open('/sys/class/gpio/gpio22/value', 'w') { |file| file.write("0") }end

Page 15: Raspberry Pi for IPRUG

A nicer way

require "pi_piper"

pin_r = PiPiper::Pin.new(:pin => 17, :direction => :out)pin_g = PiPiper::Pin.new(:pin => 27, :direction => :out)pin_b = PiPiper::Pin.new(:pin => 22, :direction => :out)

begin

while true do for r in 0..1 if r==1 ; pin_r.on else pin_r.off end for g in 0..1 if g==1 ; pin_g.on else pin_g.off end for b in 0..1 if b==1 ; pin_b.on else pin_b.off end sleep 1 end end endend

rescue SignalException pin_r.off pin_g.off pin_b.offend

Page 16: Raspberry Pi for IPRUG

Another way

require "wiringpi"

io = WiringPi::GPIO.new(WPI_MODE_GPIO)

begin

while true do for r in 0..1 io.write(17,r) for g in 0..1 io.write(27,g) for b in 0..1 io.write(22,b) sleep 1 end end endend

rescue SignalException io.write(17,0) io.write(27,0) io.write(22,0)end

Page 17: Raspberry Pi for IPRUG

Input

require 'pi_piper'include PiPiper

watch :pin => 23 do puts "Pin changed from #{last_value} to #{value}"end

#Or

after :pin => 23, :goes => :high do puts "Button pressed"end

PiPiper.wait

Page 18: Raspberry Pi for IPRUG

So what makes it special?

Page 19: Raspberry Pi for IPRUG
Page 20: Raspberry Pi for IPRUG
Page 21: Raspberry Pi for IPRUG

Raspberry Pi

is the gateway drug

to microelectronics

Page 22: Raspberry Pi for IPRUG
Page 23: Raspberry Pi for IPRUG

More Fun – Ruby USB

• wget http://sourceforge.net/projects/libusb/files/libusb-1.0/libusb-1.0.9/libusb-1.0.9.tar.bz2

• tar xjf libusb-1.0.9.tar.bz2• cd libusb-1.0.9• ./configure• make• sudo make install

• sudo apt-get install libusb-1.0-0-dev• sudo gem install libusb

Page 24: Raspberry Pi for IPRUG