Skip to content

Latest commit

 

History

History
289 lines (210 loc) · 7.36 KB

Workshops02.md

File metadata and controls

289 lines (210 loc) · 7.36 KB

The Grove Starter Kit Plus Workshop

Time

  • 90 minutes

Requirements

Agenda

Grove Starter Kit Plus

Grove – Button

Author: Sarah Knepper [email protected] Copyright (c) 2014 Intel Corporation.

root@edison:~# vi button.py
import time
import pyupm_grove as grove

# Create the button object using GPIO pin 2
button = grove.GroveButton(2)

# Read the input and print, waiting one second between readings
while 1:
    print button.name(), ' value is ', button.value()
    time.sleep(1)

# Delete the button object
del button
root@edison:~# python button.py

Grove - Touch Sensor

Author: Sarah Knepper [email protected] Copyright (c) 2014 Intel Corporation.

root@edison:~# vi touch.py
import time
import pyupm_grove as grove

# Create the button object using GPIO pin 3
touch = grove.GroveButton(3)

# Read the input and print, waiting one second between readings
while 1:
    print touch.name(), ' value is ', touch.value()
    time.sleep(1)

# Delete the touch object
del touch
root@edison:~# python touch.py

Grove - Buzzer

Author: Sarah Knepper [email protected] Copyright (c) 2015 Intel Corporation.

root@edison:~# vi buzzer.py
import time
import pyupm_buzzer as upmBuzzer

# Create the buzzer object using GPIO pin 4
buzzer = upmBuzzer.Buzzer(4)

chords = [upmBuzzer.DO, upmBuzzer.RE, upmBuzzer.MI, upmBuzzer.FA, 
          upmBuzzer.SOL, upmBuzzer.LA, upmBuzzer.SI, upmBuzzer.DO, 
          upmBuzzer.SI];

# Print sensor name
print buzzer.name()

# Play sound (DO, RE, MI, etc.), pausing for 0.1 seconds between notes
for chord_ind in range (0,7):
    # play each note for one second
    print buzzer.playSound(chords[chord_ind], 1000000)
    time.sleep(0.1)

print "exiting application"

# Delete the buzzer object
del buzzer
root@edison:~# python buzzer.py

Grove - Rotary Angle Sensor(P)

Author: Mihai Tudor Panu [email protected] Copyright (c) 2014 Intel Corporation.

root@edison:~# vi .py
from time import sleep
import pyupm_grove as grove

# New knob on AIO pin 0
knob = grove.GroveRotary(0)

# Loop indefinitely
while True:

    # Read values
    abs = knob.abs_value()
    absdeg = knob.abs_deg()
    absrad = knob.abs_rad()

    rel = knob.rel_value()
    reldeg = knob.rel_deg()
    relrad = knob.rel_rad()

    print "Abs values: %4d" % int(abs) , " raw %4d" % int(absdeg), "deg = %5.2f" % absrad , " rad ",
    print "Rel values: %4d" % int(rel) , " raw %4d" % int(reldeg), "deg = %5.2f" % relrad , " rad"

    # Sleep for 2.5 s
    sleep(2.5)
root@edison:~# python .py

Grove - Light Sensor

Author: Sarah Knepper [email protected] Copyright (c) 2014 Intel Corporation.

root@edison:~# vi light.py
import time
import pyupm_grove as grove

# Create the light sensor object using AIO pin 1
light = grove.GroveLight(1)

# Read the input and print both the raw value and a rough lux value,
# waiting one second between readings
while 1:
    print light.name() + " raw value is %d" % light.raw_value() + \
        ", which is roughly %d" % light.value() + " lux";
    time.sleep(1)

# Delete the light sensor object
del light
root@edison:~# python light.py

Grove - Temperature Sensor

Author: Brendan Le Foll [email protected] Contributions: Sarah Knepper [email protected] Copyright (c) 2014 Intel Corporation.

root@edison:~# vi temperature.py
import time
import pyupm_grove as grove

# Create the temperature sensor object using AIO pin 2
temp = grove.GroveTemp(2)
print temp.name()

# Read the temperature ten times, printing both the Celsius and
# equivalent Fahrenheit temperature, waiting one second between readings
for i in range(0, 10):
    celsius = temp.value()
    fahrenheit = celsius * 9.0/5.0 + 32.0;
    print "%d degrees Celsius, or %d degrees Fahrenheit" \
        % (celsius, fahrenheit)
    time.sleep(1)

# Delete the temperature sensor object
del temp
root@edison:~# python temperature.py

Grove - LCD RGB Backlight

Author: Brendan Le Foll [email protected] Copyright (c) 2014 Intel Corporation.

root@edison:~# vi lcd.py
import pyupm_i2clcd as lcd

# Initialize Jhd1313m1 at 0x3E (LCD_ADDRESS) and 0x62 (RGB_ADDRESS) 
myLcd = lcd.Jhd1313m1(0, 0x3E, 0x62)

myLcd.setCursor(0,0)
# RGB Blue
#myLcd.setColor(53, 39, 249)

# RGB Red
myLcd.setColor(255, 0, 0)

while True:
    myLcd.write('Hello World')
    myLcd.setCursor(1,2)
    myLcd.write('Hello World')
root@edison:~# python lcd.py

Challenge

Create an application using all components...