ExplorerHAT Pro function reference
ExplorerHAT Pro + Python 3
Program motors, sensors & other inputs/outputs in Python 3 using the ExplorerHAT Pro & Raspberry Pi
Adapted by Amanda Haughs from Raspberry Pi lessons
ExplorerHAT & Python 3
Get to know your electrical components!
jumper cables
LEDs
resistors
photoresistor
capacitor (1uF)
button
motor
potentiometer
motion sensor
Adapted by Amanda Haughs from Raspberry Pi lessons
Get to know the ExplorerHAT Pro
ExplorerHAT & Python 3
Breadboard
Capacitive touch (5=8)
Buttons (1-4)
Analog inputs/outputs (1-4)
Inputs up to 5V (1-4)
5V power x2
GND x2
Outputs (1-4)
Motors (1-2)
3.3V safe inputs/outputs
LEDs (blue, yellow, red, green)
Adapted by Amanda Haughs from Raspberry Pi lessons
To Do: Putting on the Explorer HAT
ExplorerHAT & Python 3
Slide Explorer HAT down onto all 40 pins of Raspberry Pi.
HAT should cover top of the Pi.
STOP!
Make sure your Raspberry Pi is completely shut down before attaching Explorer HAT
Adapted by Amanda Haughs from Raspberry Pi lessons
#1: Light up an onboard LED
ExplorerHAT & Python 3
The setup
**Click F5 or “run” button to start program**
The code
# Light an onboard LED
import explorerhat
from time import sleep
explorerhat.light.green.on()
sleep(2)
explorerhat.light.green.off()
Adapted by Amanda Haughs from Raspberry Pi lessons
#2: Light up more onboard LEDs
ExplorerHAT & Python 3
The setup
The code
# Light an onboard LED
import explorerhat
from time import sleep
explorerhat.light.green.on()
sleep(2)
explorerhat.light.green.off()
sleep(2)
explorerhat.light.yellow.on()
sleep(2)
explorerhat.light.yellow.off()
sleep(2)
Can you also light up the blue & red LEDs?
Adapted by Amanda Haughs from Raspberry Pi lessons
#3: Spin a motor
ExplorerHAT & Python 3
The setup
The code
#spin a motor�
import explorerhat
from time import sleep
explorerhat.motor.one.forward(100)
sleep(2)
explorerhat.motor.one.stop()
sleep(2)
explorerhat.motor.one.backward(100)
sleep(2)
explorerhat.motor.one.stop()
Can you figure out how to spin the motor more slowly?
Adapted by Amanda Haughs from Raspberry Pi lessons
#4: Connect another motor
ExplorerHAT & Python 3
The setup
The code
#spin 2 motors�
import explorerhat
from time import sleep
explorerhat.motor.one.forward(100)
explorerhat.motor.two.forward(100)
sleep(2)
explorerhat.motor.one.stop()
explorerhat.motor.two.stop()
Adapted by Amanda Haughs from Raspberry Pi lessons
#5: Use onboard buttons
ExplorerHAT & Python 3
The setup
The code
#button press to spin motor
import explorerhat
from time import sleep
def spin(channel,event):
explorerhat.motor.one.forward(100)
explorerhat.motor.two.forward(100)
sleep(5)
explorerhat.motor.one.stop()
explorerhat.motor.two.stop()
explorerhat.touch.one.pressed(spin)
defining a function called “spin”
calling function “spin”
Run code then press button
Adapted by Amanda Haughs from Raspberry Pi lessons
#6: Use alligator clip pads
ExplorerHAT & Python 3
The setup
The code
Attach other end of alligator clip to conductive material.
Press conductive material to trigger touch pad.
#press alligator clip pad to spin motor
import explorerhat
from time import sleep
def spin(channel,event):
explorerhat.motor.one.forward(100)
explorerhat.motor.two.forward(100)
sleep(5)
explorerhat.motor.one.stop()
explorerhat.motor.two.stop()
explorerhat.touch.eight.pressed(spin)
Adapted by Amanda Haughs from Raspberry Pi lessons
#7: Turn it up with a potentiometer
ExplorerHAT & Python 3
The setup
The code
Potentiometer pins from left to right:
GND
Analog pin
5V
#turn potentiometer to adjust speed of motor
import explorerhat
from time import sleep
while True:
explorerhat.analog.one.read()
speed = int(explorerhat.analog.one.read())
print(speed)
if speed == 0:
explorerhat.motor.one.stop()
elif speed > 0 and speed < 2:
explorerhat.motor.one.forward(50)
elif speed > 2:
explorerhat.motor.one.foward(100)
sleep(0.1)
analog pin reads values from 0V - 5V
Adapted by Amanda Haughs from Raspberry Pi lessons
#8: Potentiometer v.2
ExplorerHAT & Python 3
The setup
The code
Potentiometer pins from left to right:
GND
Analog pin
5V
#turn potentiometer to adjust speed of motor
import explorerhat
from time import sleep
speed = int(explorerhat.analog.one.read()) * 20
explorerhat.motor.one.forward(speed)
Adapted by Amanda Haughs from Raspberry Pi lessons
#9: Connect & program an LED
ExplorerHAT & Python 3
The setup
The code
#light an LED diode�
import explorerhat
from time import sleep
explorerhat.output.four.on()
sleep(2)
explorerhat.output.four.off()
Adapted by Amanda Haughs from Raspberry Pi lessons
#10: More LED methods
ExplorerHAT & Python 3
The setup
The code
#more output methods to try�
import explorerhat
from time import sleep
explorerhat.output.four.blink()
sleep(2)
explorerhat.output.four.off()
sleep(2)
explorerhat.output.four.pulse()
sleep(2)
explorerhat.output.four.off()
sleep(2)
explorerhat.output.four.fade(0,100,5)
sleep(1)
explorerhat.output.four.fade(100,0,5)
Adapted by Amanda Haughs from Raspberry Pi lessons
#11: Add a button
ExplorerHAT & Python 3
The setup
The code
#add a button
import explorerhat
from time import sleep
while True:
button = explorerhat.input.one.read()
if button == 1:
explorerhat.output.four.on()
else:
explorerhat.output.four.off()
Adapted by Amanda Haughs from Raspberry Pi lessons
#12: Photoresistor for sensing light
ExplorerHAT & Python 3
The setup
The code
#add a photoresistor
import explorerhat
from time import sleep
while True:
sensor = explorerhat.input.one.read()
if sensor == 0:
explorerhat.light.green.on()
else:
explorerhat.light.green.off()
n
Long leg of capacitor goes in same column as one photoresistor leg & jumper cable to “input1”
Adapted by Amanda Haughs from Raspberry Pi lessons
#13: PIR motion sensor
ExplorerHAT & Scratch 1.4
The setup
The code
VCC → 5 V; GND → GND; Out → “input 1”
#add a motion sensor
import explorerhat
from time import sleep
while True:
motion = explorerhat.input.one.read()
if motion == 1:
explorerhat.light.red.on()
else:
explorerhat.light.red.off()
Adapted by Amanda Haughs from Raspberry Pi lessons