Difference between revisions of "LinkerKit for Raspberry Pi"

From LinkSprite Playgound
Jump to: navigation, search
(Tutorial)
 
(17 intermediate revisions by one other user not shown)
Line 21: Line 21:
 
==Tutorial==
 
==Tutorial==
  
In this tutorial, we are going to explain how to use Python to do the experiments:
+
In this tutorial, we are going to explain how to use Python to do the experiments.
 +
 
 +
Please refer to:
 +
 
 +
*[http://learn.linksprite.com/?p=1170 Bring up Raspberry Pi]
 +
*[http://learn.linksprite.com/?p=1193 Guide on how to program GPIOs on Raspberry Pi]
  
 
=== Environment Setup ===
 
=== Environment Setup ===
Line 45: Line 50:
 
===Linker Button===
 
===Linker Button===
  
Connect linker_led to pin 27 of RPI, connect linker_button to pin 23 of RPI
+
Connect linker_led to pin 24 of RPI, connect linker_button to pin 23 of RPI
 +
 
  
 
Python code:
 
Python code:
 +
 +
<syntaxhighlight lang="c">
  
 
import RPi.GPIO as GPIO
 
import RPi.GPIO as GPIO
  
led_pin = 27
+
led_pin = 24
 
button_pin = 23
 
button_pin = 23
  
Line 58: Line 66:
 
GPIO.setup( button_pin, GPIO.IN, pull_up_down=GPIO.PUD_UP)
 
GPIO.setup( button_pin, GPIO.IN, pull_up_down=GPIO.PUD_UP)
  
print ("\nlinker_led pin 27 , linker_button pin 23\n")
+
print ("\nlinker_led pin 24 , linker_button pin 23\n")
  
 
while True:
 
while True:
Line 65: Line 73:
 
else :
 
else :
 
GPIO.output(led_pin,False)
 
GPIO.output(led_pin,False)
 +
</syntaxhighlight>
 +
 +
===Linker LED===
 +
 +
 +
Connect linker led  to pin 24 of RPI.
 +
 +
Python code:
 +
 +
 +
<syntaxhighlight lang="c">
 +
 +
import RPi.GPIO as GPIO
 +
import time
 +
 +
led_pin = 24
 +
 +
GPIO.setmode(GPIO.BCM)
 +
GPIO.setup(led_pin,GPIO.OUT)
 +
 +
print "\nlinker led pin 24\n"
 +
 +
while True:
 +
 +
GPIO.output(led_pin,True)
 +
time.sleep(0.5)
 +
GPIO.output(led_pin,False)
 +
time.sleep(0.5)
 +
</syntaxhighlight>
 +
 +
===Linker Light Sensor===
 +
 +
To use this module with RPI, we need a [http://linksprite.com/wiki/index.php5?title=Linker_kit_Base_Shield_for_Raspberry_Pi_with_ADC_Interface  shield ].
 +
 +
If you don't have this shield, you can follow the instructions at [http://scruss.com/blog/2013/02/02/simple-adc-with-the-raspberry-pi/ here].
 +
 +
Python code:
 +
 +
<syntaxhighlight lang="c">
 +
 +
import RPi.GPIO as GPIO
 +
import spidev
 +
import time
 +
 +
led_pin = 24
 +
 +
# A0 = 0, A1 = 1, A2 = 2, A3 =3
 +
temp_channel = 0
 +
 +
GPIO.setmode( GPIO.BCM )
 +
GPIO.setup( led_pin,GPIO.OUT )
 +
spi = spidev.SpiDev()
 +
spi.open(0,0)
 +
 +
print "\nlinker led pin 24"
 +
print ("Please the linker_temperature is connected to A%1d\n" % temp_channel)
 +
time.sleep(3)
 +
 +
def readadc(adcnum):
 +
# read SPI data from MCP3004 chip, 4 possible adc's (0 thru 3)
 +
    if adcnum > 3 or adcnum < 0:
 +
        return -1
 +
    r = spi.xfer2([1,8+adcnum <<4,0])
 +
    adcout = ((r[1] &3) <<8) + r[2]
 +
    return adcout
 +
 +
while True:
 +
value = readadc(temp_channel)
 +
volts = (value * 3.3) / 1024
 +
print("value = %4d/1023" % value)
 +
print("volts = %5.3f V\n" % volts )
 +
if value > 10 :
 +
GPIO.output(led_pin,True)
 +
else :
 +
GPIO.output(led_pin,False)
 +
time.sleep(0.5)
 +
 +
</syntaxhighlight>
 +
 +
===Linker Relay===
 +
 +
To use this module with RPI, connect it to pin 23 of RPI:
 +
 +
Python code:
 +
 +
<syntaxhighlight lang="c">
 +
import RPi.GPIO as GPIO
 +
import time
 +
 +
relay_pin = 23
 +
 +
GPIO.setmode( GPIO.BCM )
 +
GPIO.setup( relay_pin,GPIO.OUT )
 +
 +
print "\nlinker relay pin 23\n"
 +
 +
while True:
 +
 +
GPIO.output(relay_pin,True)
 +
time.sleep(0.5)
 +
GPIO.output(relay_pin,False)
 +
time.sleep(0.5)
 +
 +
</syntaxhighlight>
 +
 +
===Linker Slide Potentiometer===
 +
 +
To use this module with RPI, we need a [http://linksprite.com/wiki/index.php5?title=Linker_kit_Base_Shield_for_Raspberry_Pi_with_ADC_Interface  shield ].
 +
 +
If you don't have this shield, you can follow the instructions at [http://scruss.com/blog/2013/02/02/simple-adc-with-the-raspberry-pi/ here].
 +
 +
Python code:
 +
 +
<syntaxhighlight lang="c">
 +
import spidev
 +
import time
 +
 +
# A0 = 0, A1 = 1, A2 = 2, A3 =3
 +
temp_channel = 1
 +
print ("Please the linker_temperature is connected to A%1d\n" % temp_channel)
 +
 +
spi = spidev.SpiDev()
 +
spi.open(0,0)
 +
 +
def readadc(adcnum):
 +
# read SPI data from MCP3004 chip, 4 possible adc's (0 thru 3)
 +
    if adcnum > 3 or adcnum < 0:
 +
        return -1
 +
    r = spi.xfer2([1,8+adcnum <<4,0])
 +
    adcout = ((r[1] &3) <<8)+r[2]
 +
    return adcout
 +
 +
while True:
 +
value = readadc(temp_channel)
 +
volts = (value * 3.3) / 1024
 +
 +
print("value = %4d/1023" % value)
 +
print("volts = %5.3f V" % volts )
 +
print"------------------"
 +
time.sleep(0.5)
 +
 +
 +
</syntaxhighlight>
 +
 +
 +
===Linker Temperature===
 +
 +
To use this module with RPI, we need a [http://linksprite.com/wiki/index.php5?title=Linker_kit_Base_Shield_for_Raspberry_Pi_with_ADC_Interface  shield ].
 +
 +
If you don't have this shield, you can follow the instructions at [http://scruss.com/blog/2013/02/02/simple-adc-with-the-raspberry-pi/ here].
 +
 +
Python code:
 +
 +
<syntaxhighlight lang="c">
 +
import spidev
 +
import time
 +
 +
# A0 = 0, A1 = 1, A2 = 2, A3 =3
 +
temp_channel = 0
 +
print ("\nPlease the linker_temperature is connected to A%1d\n" % temp_channel)
 +
time.sleep(3)
 +
 +
spi = spidev.SpiDev()
 +
spi.open(0,0)
 +
 +
def readadc(adcnum):
 +
# read SPI data from MCP3004 chip, 4 possible adc's (0 thru 3)
 +
    if adcnum > 3 or adcnum < 0:
 +
        return -1
 +
    r = spi.xfer2([1,8+adcnum <<4,0])
 +
    adcout = ((r[1] &3) <<8)+r[2]
 +
    return adcout
 +
 +
while True:
 +
value = readadc(temp_channel)
 +
volts = (value * 3.3) / 1024
 +
temperature_C = (volts - 0.5) * 100
 +
temperature_F = (temperature_C * 9 / 5) + 32
 +
 +
print("volts = %5.3f V" % volts )
 +
print("%4.1f  degrees C" % temperature_C)
 +
print("%4.1f  degrees F" % temperature_F)
 +
print("-------------------------")
 +
time.sleep(0.5)</syntaxhighlight>
 +
 +
===Linker Tilt===
 +
 +
To use this module with RPI, please connect led module to pin 24 of RPI, and tilt module to pin 23.
 +
 +
Python code:
 +
 +
<syntaxhighlight lang="c">
 +
 +
import RPi.GPIO as GPIO
 +
 +
led_pin = 24
 +
tilt_pin = 23
 +
 +
GPIO.setmode( GPIO.BCM )
 +
GPIO.setup( led_pin,GPIO.OUT )
 +
GPIO.setup( tilt_pin, GPIO.IN, pull_up_down = GPIO.PUD_UP)
 +
 +
print "\nlinker_led pin 27 , linker_tilt pin 23\n"
 +
 +
while True:
 +
if GPIO.input(tilt_pin):
 +
GPIO.output(led_pin,True)
 +
else :
 +
GPIO.output(led_pin,False)
 +
 +
</syntaxhighlight>
 +
 +
 +
===Linker Touch Sensor ===
 +
 +
To use this module with RPI, please connect led module to pin 24 of RPI, and touch module to pin 23.
 +
 +
Python code:
 +
 +
<syntaxhighlight lang="c">
 +
 +
import RPi.GPIO as GPIO
 +
 +
led_pin = 24
 +
touch_sensor_pin = 23
 +
 +
GPIO.setmode( GPIO.BCM )
 +
GPIO.setup( led_pin,GPIO.OUT )
 +
GPIO.setup( touch_sensor_pin, GPIO.IN, pull_up_down=GPIO.PUD_UP)
 +
 +
print "linker_led pin 24 , linker touch_sensor pin 23"
 +
 +
while True:
 +
if GPIO.input(touch_sensor_pin):
 +
GPIO.output(led_pin,True)
 +
else :
 +
GPIO.output(led_pin,False)
 +
 +
 +
</syntaxhighlight>
 +
 +
==How to buy==
 +
Here to buy on [http://store.linksprite.com/linker-kit-for-raspberry-pi-pcduino/ store]

Latest revision as of 10:00, 20 February 2014


LK raspberry 02.jpg LK raspberry 01.jpg


This pack includes the following components:



Tutorial

In this tutorial, we are going to explain how to use Python to do the experiments.

Please refer to:

Environment Setup

Now we will install python-pip (pip is a package used to install and manage python software package, and it is used replace esay_install):

sudo apt-get install python-imaging python-imaging-tk python-pip python-dev git

Next, we will install spidev using pip:

sudo pip install spidev

Then we will install WiringPi (the driver for IOs on Raspberry pi, that can be used in C, shell script or Python, etc):

sudo pip install wiringpi

Linker Button

Connect linker_led to pin 24 of RPI, connect linker_button to pin 23 of RPI


Python code:

<syntaxhighlight lang="c">

import RPi.GPIO as GPIO

led_pin = 24 button_pin = 23

GPIO.setmode( GPIO.BCM ) GPIO.setup( led_pin,GPIO.OUT ) GPIO.setup( button_pin, GPIO.IN, pull_up_down=GPIO.PUD_UP)

print ("\nlinker_led pin 24 , linker_button pin 23\n")

while True: if GPIO.input(button_pin): GPIO.output(led_pin,True) else : GPIO.output(led_pin,False) </syntaxhighlight>

Linker LED

Connect linker led to pin 24 of RPI.

Python code:


<syntaxhighlight lang="c">

import RPi.GPIO as GPIO import time

led_pin = 24

GPIO.setmode(GPIO.BCM) GPIO.setup(led_pin,GPIO.OUT)

print "\nlinker led pin 24\n"

while True:

GPIO.output(led_pin,True) time.sleep(0.5) GPIO.output(led_pin,False) time.sleep(0.5) </syntaxhighlight>

Linker Light Sensor

To use this module with RPI, we need a shield .

If you don't have this shield, you can follow the instructions at here.

Python code:

<syntaxhighlight lang="c">

import RPi.GPIO as GPIO import spidev import time

led_pin = 24

  1. A0 = 0, A1 = 1, A2 = 2, A3 =3

temp_channel = 0

GPIO.setmode( GPIO.BCM ) GPIO.setup( led_pin,GPIO.OUT ) spi = spidev.SpiDev() spi.open(0,0)

print "\nlinker led pin 24" print ("Please the linker_temperature is connected to A%1d\n" % temp_channel) time.sleep(3)

def readadc(adcnum):

  1. read SPI data from MCP3004 chip, 4 possible adc's (0 thru 3)
   if adcnum > 3 or adcnum < 0:
       return -1
   r = spi.xfer2([1,8+adcnum <<4,0])
   adcout = ((r[1] &3) <<8) + r[2]
   return adcout

while True: value = readadc(temp_channel) volts = (value * 3.3) / 1024 print("value = %4d/1023" % value) print("volts = %5.3f V\n" % volts ) if value > 10 : GPIO.output(led_pin,True) else : GPIO.output(led_pin,False) time.sleep(0.5)

</syntaxhighlight>

Linker Relay

To use this module with RPI, connect it to pin 23 of RPI:

Python code:

<syntaxhighlight lang="c"> import RPi.GPIO as GPIO import time

relay_pin = 23

GPIO.setmode( GPIO.BCM ) GPIO.setup( relay_pin,GPIO.OUT )

print "\nlinker relay pin 23\n"

while True:

GPIO.output(relay_pin,True) time.sleep(0.5) GPIO.output(relay_pin,False) time.sleep(0.5)

</syntaxhighlight>

Linker Slide Potentiometer

To use this module with RPI, we need a shield .

If you don't have this shield, you can follow the instructions at here.

Python code:

<syntaxhighlight lang="c"> import spidev import time

  1. A0 = 0, A1 = 1, A2 = 2, A3 =3

temp_channel = 1 print ("Please the linker_temperature is connected to A%1d\n" % temp_channel)

spi = spidev.SpiDev() spi.open(0,0)

def readadc(adcnum):

  1. read SPI data from MCP3004 chip, 4 possible adc's (0 thru 3)
   if adcnum > 3 or adcnum < 0:
       return -1
   r = spi.xfer2([1,8+adcnum <<4,0])
   adcout = ((r[1] &3) <<8)+r[2]
   return adcout

while True: value = readadc(temp_channel) volts = (value * 3.3) / 1024

print("value = %4d/1023" % value) print("volts = %5.3f V" % volts ) print"------------------" time.sleep(0.5)


</syntaxhighlight>


Linker Temperature

To use this module with RPI, we need a shield .

If you don't have this shield, you can follow the instructions at here.

Python code:

<syntaxhighlight lang="c"> import spidev import time

  1. A0 = 0, A1 = 1, A2 = 2, A3 =3

temp_channel = 0 print ("\nPlease the linker_temperature is connected to A%1d\n" % temp_channel) time.sleep(3)

spi = spidev.SpiDev() spi.open(0,0)

def readadc(adcnum):

  1. read SPI data from MCP3004 chip, 4 possible adc's (0 thru 3)
   if adcnum > 3 or adcnum < 0:
       return -1
   r = spi.xfer2([1,8+adcnum <<4,0])
   adcout = ((r[1] &3) <<8)+r[2]
   return adcout

while True: value = readadc(temp_channel) volts = (value * 3.3) / 1024 temperature_C = (volts - 0.5) * 100 temperature_F = (temperature_C * 9 / 5) + 32

print("volts = %5.3f V" % volts ) print("%4.1f degrees C" % temperature_C) print("%4.1f degrees F" % temperature_F) print("-------------------------") time.sleep(0.5)</syntaxhighlight>

Linker Tilt

To use this module with RPI, please connect led module to pin 24 of RPI, and tilt module to pin 23.

Python code:

<syntaxhighlight lang="c">

import RPi.GPIO as GPIO

led_pin = 24 tilt_pin = 23

GPIO.setmode( GPIO.BCM ) GPIO.setup( led_pin,GPIO.OUT ) GPIO.setup( tilt_pin, GPIO.IN, pull_up_down = GPIO.PUD_UP)

print "\nlinker_led pin 27 , linker_tilt pin 23\n"

while True: if GPIO.input(tilt_pin): GPIO.output(led_pin,True) else : GPIO.output(led_pin,False)

</syntaxhighlight>


Linker Touch Sensor

To use this module with RPI, please connect led module to pin 24 of RPI, and touch module to pin 23.

Python code:

<syntaxhighlight lang="c">

import RPi.GPIO as GPIO

led_pin = 24 touch_sensor_pin = 23

GPIO.setmode( GPIO.BCM ) GPIO.setup( led_pin,GPIO.OUT ) GPIO.setup( touch_sensor_pin, GPIO.IN, pull_up_down=GPIO.PUD_UP)

print "linker_led pin 24 , linker touch_sensor pin 23"

while True: if GPIO.input(touch_sensor_pin): GPIO.output(led_pin,True) else : GPIO.output(led_pin,False)


</syntaxhighlight>

How to buy

Here to buy on store