Skip to content
Snippets Groups Projects
Commit d7b081d0 authored by Holger Dinkel's avatar Holger Dinkel
Browse files

add raspberry files

parent fd87aeeb
No related branches found
No related tags found
No related merge requests found
......@@ -28,3 +28,4 @@
- 19.02.2014 Daniel Mende: ConfigParser
- 26.03.2014 Discussion: Python Course, External Teacher (Pandas)
- 09.04.2014 Luis Pedro Coelho: JUG - A Task Based Parallelization Framework
- 07.05.2014 Holger Dinkel: Hacking Hardware with Raspberry Pi
{
"metadata": {
"name": "BlinkenPi"
},
"nbformat": 3,
"nbformat_minor": 0,
"worksheets": [
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": "Import the GPIO module and set the board layout:"
},
{
"cell_type": "code",
"collapsed": false,
"input": "import random\nimport time\nimport RPi.GPIO as GPIO\nGPIO.setmode(GPIO.BCM)",
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 25
},
{
"cell_type": "markdown",
"metadata": {},
"source": "Initialize the Pins:"
},
{
"cell_type": "code",
"collapsed": false,
"input": "red=27\nblue=18\nyellow=22\npins = [red,blue,yellow]\n\nGPIO.setup(red, GPIO.OUT)\nGPIO.setup(blue, GPIO.OUT)\nGPIO.setup(yellow, GPIO.OUT)\n\ndef turn_off():\n for pin in pins:\n GPIO.output(pin, False)\n\nturn_off()",
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 26
},
{
"cell_type": "markdown",
"metadata": {},
"source": "Now switch the LEDs:"
},
{
"cell_type": "code",
"collapsed": false,
"input": "GPIO.output(red, True)\nGPIO.output(yellow, False)\nGPIO.output(blue, True)",
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 27
},
{
"cell_type": "code",
"collapsed": false,
"input": "for i in range(100):\n pin = random.choice(pins)\n mode = random.choice((True, False))\n GPIO.output(pin, mode)\n time.sleep(0.1)\nprint 'done'\nturn_off()",
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
"text": "done\n"
}
],
"prompt_number": 28
},
{
"cell_type": "code",
"collapsed": false,
"input": "",
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 28
}
],
"metadata": {}
}
]
}
\ No newline at end of file
# -*- coding: utf-8 -*-
# <nbformat>3.0</nbformat>
# <markdowncell>
# Import the GPIO module and set the board layout:
# <codecell>
import random
import time
import RPi.GPIO as GPIO
GPIO.setmode(GPIO.BCM)
# <markdowncell>
# Initialize the Pins:
# <codecell>
red=27
blue=18
yellow=22
pins = [red,blue,yellow]
GPIO.setup(red, GPIO.OUT)
GPIO.setup(blue, GPIO.OUT)
GPIO.setup(yellow, GPIO.OUT)
def turn_off():
for pin in pins:
GPIO.output(pin, False)
turn_off()
# <markdowncell>
# Now switch the LEDs:
# <codecell>
GPIO.output(red, True)
GPIO.output(yellow, False)
GPIO.output(blue, True)
# <codecell>
for i in range(100):
pin = random.choice(pins)
mode = random.choice((True, False))
GPIO.output(pin, mode)
time.sleep(0.1)
print 'done'
turn_off()
# <codecell>
{
"metadata": {
"name": "PiR"
},
"nbformat": 3,
"nbformat_minor": 0,
"worksheets": [
{
"cells": [
{
"cell_type": "code",
"collapsed": false,
"input": "import random\nimport time\nimport RPi.GPIO as GPIO\nGPIO.setmode(GPIO.BCM)",
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 6
},
{
"cell_type": "code",
"collapsed": false,
"input": "red=27\npir=4\n\nGPIO.setup(red, GPIO.OUT)\nGPIO.setup(pir, GPIO.IN)\n\nGPIO.output(red, False)\n",
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": "*"
},
{
"cell_type": "code",
"collapsed": false,
"input": "print 'start'\nfor i in range(100):\n if GPIO.input(pir):\n print \"detected!\"\n GPIO.output(red, True)\n time.sleep(1)\n GPIO.output(red, False)\nprint 'end'",
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
"text": "start\ndetected!"
},
{
"output_type": "stream",
"stream": "stdout",
"text": "\ndetected!"
},
{
"output_type": "stream",
"stream": "stdout",
"text": "\ndetected!"
},
{
"output_type": "stream",
"stream": "stdout",
"text": "\ndetected!"
},
{
"output_type": "stream",
"stream": "stdout",
"text": "\ndetected!"
},
{
"output_type": "stream",
"stream": "stdout",
"text": "\ndetected!"
},
{
"output_type": "stream",
"stream": "stdout",
"text": "\ndetected!"
},
{
"output_type": "stream",
"stream": "stdout",
"text": "\ndetected!"
},
{
"output_type": "stream",
"stream": "stdout",
"text": "\ndetected!"
},
{
"output_type": "stream",
"stream": "stdout",
"text": "\ndetected!"
}
],
"prompt_number": "*"
},
{
"cell_type": "code",
"collapsed": false,
"input": "GPIO.output(red, False)",
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": "*"
}
],
"metadata": {}
}
]
}
\ No newline at end of file
# -*- coding: utf-8 -*-
# <nbformat>3.0</nbformat>
# <codecell>
import random
import time
import RPi.GPIO as GPIO
GPIO.setmode(GPIO.BCM)
# <codecell>
red=27
pir=4
GPIO.setup(red, GPIO.OUT)
GPIO.setup(pir, GPIO.IN)
GPIO.output(red, False)
# <codecell>
print 'start'
for i in range(100):
if GPIO.input(pir):
print "detected!"
GPIO.output(red, True)
time.sleep(1)
GPIO.output(red, False)
print 'end'
# <codecell>
GPIO.output(red, False)
users/dinkel/raspberry/GPIO/gpio-pinout-rev2.jpg

89.3 KiB

#. Get a Raspberry Pi
#. Grab the NOOBS (New Out Of the Box Software) image at http://www.raspberrypi.org/downloads/ and put it on a SD card.
#. Boot it & install Raspbian
iPython setup:
--------------
#. Start iPython notebook::
ipython notebook --no-browser --port=7777
#. Create a ssh tunnel (pi's IP address here is 10.10.0.100)::
ssh -N -f -L localhost:7777:localhost:7777 pi@10.10.0.100
#. Browse to the Ipython notebook at http://127.0.0.1:7777/
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment