Added corrected Lab11 directory and code
This commit is contained in:
parent
a37409e5e7
commit
3d2736ac57
48 changed files with 8548 additions and 1 deletions
Binary file not shown.
Binary file not shown.
BIN
Lab11/CircuitPython/Code.tar
Normal file
BIN
Lab11/CircuitPython/Code.tar
Normal file
Binary file not shown.
32
Lab11/CircuitPython/Code/blink_external2.py
Executable file
32
Lab11/CircuitPython/Code/blink_external2.py
Executable file
|
|
@ -0,0 +1,32 @@
|
|||
# Program for CircuitPython on a Pico W
|
||||
|
||||
import board
|
||||
import digitalio
|
||||
import time
|
||||
|
||||
led = digitalio.DigitalInOut(board.LED)
|
||||
led15 = digitalio.DigitalInOut(board.GP15)
|
||||
led16 = digitalio.DigitalInOut(board.GP16)
|
||||
|
||||
led.direction = digitalio.Direction.OUTPUT
|
||||
led15.direction = digitalio.Direction.OUTPUT
|
||||
led16.direction = digitalio.Direction.OUTPUT
|
||||
|
||||
print("\nCircuitPython example code")
|
||||
print("Blink the onboard LED and LED's connected to GP15 & GP16\n")
|
||||
|
||||
while True:
|
||||
print("Start")
|
||||
led.value = True #turn on the LED
|
||||
led15.value = False #turn on the LED
|
||||
led16.value = True #turn on the LED
|
||||
time.sleep(1) #wait for one second
|
||||
print("Off")
|
||||
led.value = False #turn off the LED
|
||||
led15.value = True #turn off the LED
|
||||
led16.value = False #turn off the LED
|
||||
time.sleep(1) #wait for one second
|
||||
|
||||
|
||||
|
||||
|
||||
21
Lab11/CircuitPython/Code/blink_internal.py
Executable file
21
Lab11/CircuitPython/Code/blink_internal.py
Executable file
|
|
@ -0,0 +1,21 @@
|
|||
# Program for CircuitPython on a Pico W
|
||||
|
||||
import board
|
||||
import digitalio
|
||||
import time
|
||||
|
||||
led = digitalio.DigitalInOut(board.LED)
|
||||
led.direction = digitalio.Direction.OUTPUT
|
||||
|
||||
print("Hello, CircuitPython!")
|
||||
|
||||
while True:
|
||||
|
||||
print("On!")
|
||||
led.value = True
|
||||
time.sleep(1)
|
||||
|
||||
print("Off!")
|
||||
led.value = False
|
||||
time.sleep(1)
|
||||
|
||||
11
Lab11/CircuitPython/Code/certificates/certificate-chain.pem
Executable file
11
Lab11/CircuitPython/Code/certificates/certificate-chain.pem
Executable file
|
|
@ -0,0 +1,11 @@
|
|||
-----BEGIN CERTIFICATE-----
|
||||
MIIBozCCAQwCCQCwlOkfTi8J9zANBgkqhkiG9w0BAQsFADAWMRQwEgYDVQQDDAtw
|
||||
aWNvdy5sb2NhbDAeFw0yMzAyMjgwNTQyNTZaFw0yNDAyMjgwNTQyNTZaMBYxFDAS
|
||||
BgNVBAMMC3BpY293LmxvY2FsMIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDq
|
||||
UQiuhGBzHCLaesEjk6e6Kx7iNAKneaPht0Q6TsvF+IgOpuQFNkvQTU5S7POKDl2c
|
||||
UGkMT9Q1x4xRdM3u3qT3OmutyAtfL94RkK1qsblJwIH8xop5p7P+gwHTT4UOEicj
|
||||
MOSYBmkI6YvO/QImGdEoezWBqxKjOzyYLnv4UrwtYQIDAQABMA0GCSqGSIb3DQEB
|
||||
CwUAA4GBABuzaLw1tcFNYZ0ViWnii1j97otemOFkM31TW8Ohm3zRS6f/aQi+hujN
|
||||
BYMWIhxlK2cr0zsN+mXCVZN5u2BY0Q/w/7cNMBPNcGG7dJCGoBJRKRbEoBb/AMaO
|
||||
vjp0giQ8kFOtRcf0Gun5gPdDcmZayZwU1n/V1Q7UjwKXcqe0+eXu
|
||||
-----END CERTIFICATE-----
|
||||
16
Lab11/CircuitPython/Code/certificates/key.pem
Executable file
16
Lab11/CircuitPython/Code/certificates/key.pem
Executable file
|
|
@ -0,0 +1,16 @@
|
|||
-----BEGIN PRIVATE KEY-----
|
||||
MIICdwIBADANBgkqhkiG9w0BAQEFAASCAmEwggJdAgEAAoGBAOpRCK6EYHMcItp6
|
||||
wSOTp7orHuI0Aqd5o+G3RDpOy8X4iA6m5AU2S9BNTlLs84oOXZxQaQxP1DXHjFF0
|
||||
ze7epPc6a63IC18v3hGQrWqxuUnAgfzGinmns/6DAdNPhQ4SJyMw5JgGaQjpi879
|
||||
AiYZ0Sh7NYGrEqM7PJgue/hSvC1hAgMBAAECgYEAvZ05s0/4ZO493iM8LDgOoP7I
|
||||
DTEdfL1Yuw19LtoY2GmYYJL5LqaTj0sfuMd7BRs+8YG4oHfxOFv01u34v/Z38vRa
|
||||
E0tzSMVz29CRF0LUcko7c8Q2TzeTVsk3tEb3Kuf3tfVh5bhhjSakhUIY7D+Gb6LT
|
||||
GRIUg72tP9wjayTDsCkCQQD6oyJqxUhxuuiL5D+e0ssp582YruEJK4f5CzRsjmVV
|
||||
COBbqzRkIMCxPMCJCB+DbiMPlu/6CuxGh6i8rczDlkdfAkEA71SAt9PFx3hLW0hu
|
||||
OBR9w7BF6B2YTR3cG5+SQXOiF1feMUIaAn/dDr1OxqAQ/hQ/QKUk5JDwquy6phYT
|
||||
9qWDPwJBAPMqGLccBkgI/ZrTbIILov5aHdcXO88ow7f0jf0QPfG9NebZ+G94c1rB
|
||||
RU7taZ2a2jtCxjqCJG/dJ/E+cZ4Ei+MCQFu3O3i2/FU7wU0jDbIKEEQc2j1gkgwD
|
||||
hGVFmovgn15ouuqPlV4d1/4dCAJQNxLXeYHxh5jb/o7SF5ksXswnk4sCQA7Jlj5M
|
||||
8+7qQV9DrOieFGpXMqlc9J6u9L0Tev2P9uE7a7z61NvLIdskGDpiaYOmADob5nHo
|
||||
Duv3lSMQg6ql7EE=
|
||||
-----END PRIVATE KEY-----
|
||||
BIN
Lab11/CircuitPython/Code/lib/adafruit_connection_manager.mpy
Executable file
BIN
Lab11/CircuitPython/Code/lib/adafruit_connection_manager.mpy
Executable file
Binary file not shown.
BIN
Lab11/CircuitPython/Code/lib/adafruit_dht.mpy
Executable file
BIN
Lab11/CircuitPython/Code/lib/adafruit_dht.mpy
Executable file
Binary file not shown.
BIN
Lab11/CircuitPython/Code/lib/adafruit_httpserver/__init__.mpy
Executable file
BIN
Lab11/CircuitPython/Code/lib/adafruit_httpserver/__init__.mpy
Executable file
Binary file not shown.
BIN
Lab11/CircuitPython/Code/lib/adafruit_httpserver/authentication.mpy
Executable file
BIN
Lab11/CircuitPython/Code/lib/adafruit_httpserver/authentication.mpy
Executable file
Binary file not shown.
BIN
Lab11/CircuitPython/Code/lib/adafruit_httpserver/exceptions.mpy
Executable file
BIN
Lab11/CircuitPython/Code/lib/adafruit_httpserver/exceptions.mpy
Executable file
Binary file not shown.
BIN
Lab11/CircuitPython/Code/lib/adafruit_httpserver/headers.mpy
Executable file
BIN
Lab11/CircuitPython/Code/lib/adafruit_httpserver/headers.mpy
Executable file
Binary file not shown.
BIN
Lab11/CircuitPython/Code/lib/adafruit_httpserver/interfaces.mpy
Executable file
BIN
Lab11/CircuitPython/Code/lib/adafruit_httpserver/interfaces.mpy
Executable file
Binary file not shown.
BIN
Lab11/CircuitPython/Code/lib/adafruit_httpserver/methods.mpy
Executable file
BIN
Lab11/CircuitPython/Code/lib/adafruit_httpserver/methods.mpy
Executable file
Binary file not shown.
BIN
Lab11/CircuitPython/Code/lib/adafruit_httpserver/mime_types.mpy
Executable file
BIN
Lab11/CircuitPython/Code/lib/adafruit_httpserver/mime_types.mpy
Executable file
Binary file not shown.
BIN
Lab11/CircuitPython/Code/lib/adafruit_httpserver/request.mpy
Executable file
BIN
Lab11/CircuitPython/Code/lib/adafruit_httpserver/request.mpy
Executable file
Binary file not shown.
BIN
Lab11/CircuitPython/Code/lib/adafruit_httpserver/response.mpy
Executable file
BIN
Lab11/CircuitPython/Code/lib/adafruit_httpserver/response.mpy
Executable file
Binary file not shown.
BIN
Lab11/CircuitPython/Code/lib/adafruit_httpserver/route.mpy
Executable file
BIN
Lab11/CircuitPython/Code/lib/adafruit_httpserver/route.mpy
Executable file
Binary file not shown.
BIN
Lab11/CircuitPython/Code/lib/adafruit_httpserver/server.mpy
Executable file
BIN
Lab11/CircuitPython/Code/lib/adafruit_httpserver/server.mpy
Executable file
Binary file not shown.
BIN
Lab11/CircuitPython/Code/lib/adafruit_httpserver/status.mpy
Executable file
BIN
Lab11/CircuitPython/Code/lib/adafruit_httpserver/status.mpy
Executable file
Binary file not shown.
0
Lab11/CircuitPython/Code/lib/adafruit_io/__init__.py
Executable file
0
Lab11/CircuitPython/Code/lib/adafruit_io/__init__.py
Executable file
BIN
Lab11/CircuitPython/Code/lib/adafruit_io/adafruit_io.mpy
Executable file
BIN
Lab11/CircuitPython/Code/lib/adafruit_io/adafruit_io.mpy
Executable file
Binary file not shown.
BIN
Lab11/CircuitPython/Code/lib/adafruit_io/adafruit_io_errors.mpy
Executable file
BIN
Lab11/CircuitPython/Code/lib/adafruit_io/adafruit_io_errors.mpy
Executable file
Binary file not shown.
0
Lab11/CircuitPython/Code/lib/adafruit_minimqtt/__init__.py
Executable file
0
Lab11/CircuitPython/Code/lib/adafruit_minimqtt/__init__.py
Executable file
BIN
Lab11/CircuitPython/Code/lib/adafruit_minimqtt/adafruit_minimqtt.mpy
Executable file
BIN
Lab11/CircuitPython/Code/lib/adafruit_minimqtt/adafruit_minimqtt.mpy
Executable file
Binary file not shown.
BIN
Lab11/CircuitPython/Code/lib/adafruit_minimqtt/matcher.mpy
Executable file
BIN
Lab11/CircuitPython/Code/lib/adafruit_minimqtt/matcher.mpy
Executable file
Binary file not shown.
BIN
Lab11/CircuitPython/Code/lib/adafruit_motor/__init__.mpy
Executable file
BIN
Lab11/CircuitPython/Code/lib/adafruit_motor/__init__.mpy
Executable file
Binary file not shown.
BIN
Lab11/CircuitPython/Code/lib/adafruit_motor/motor.mpy
Executable file
BIN
Lab11/CircuitPython/Code/lib/adafruit_motor/motor.mpy
Executable file
Binary file not shown.
BIN
Lab11/CircuitPython/Code/lib/adafruit_motor/servo.mpy
Executable file
BIN
Lab11/CircuitPython/Code/lib/adafruit_motor/servo.mpy
Executable file
Binary file not shown.
BIN
Lab11/CircuitPython/Code/lib/adafruit_motor/stepper.mpy
Executable file
BIN
Lab11/CircuitPython/Code/lib/adafruit_motor/stepper.mpy
Executable file
Binary file not shown.
BIN
Lab11/CircuitPython/Code/lib/adafruit_ntp.mpy
Executable file
BIN
Lab11/CircuitPython/Code/lib/adafruit_ntp.mpy
Executable file
Binary file not shown.
BIN
Lab11/CircuitPython/Code/lib/adafruit_requests.mpy
Executable file
BIN
Lab11/CircuitPython/Code/lib/adafruit_requests.mpy
Executable file
Binary file not shown.
BIN
Lab11/CircuitPython/Code/lib/adafruit_ticks.mpy
Executable file
BIN
Lab11/CircuitPython/Code/lib/adafruit_ticks.mpy
Executable file
Binary file not shown.
177
Lab11/CircuitPython/Code/picowServo1.py
Executable file
177
Lab11/CircuitPython/Code/picowServo1.py
Executable file
|
|
@ -0,0 +1,177 @@
|
|||
# SPDX-FileCopyrightText: 2021 jedgarpark for Adafruit Industries
|
||||
# SPDX-License-Identifier: MIT
|
||||
|
||||
# Pico servo demo
|
||||
# Hardware setup:
|
||||
# Servo on GP0 with external 5V power supply
|
||||
# Button on GP3 and ground
|
||||
|
||||
import time
|
||||
import board
|
||||
from digitalio import DigitalInOut, Direction, Pull
|
||||
import pwmio
|
||||
from adafruit_motor import servo
|
||||
|
||||
import os
|
||||
import sys
|
||||
import ssl
|
||||
import wifi
|
||||
import socketpool
|
||||
import microcontroller
|
||||
import board
|
||||
import busio
|
||||
import adafruit_requests
|
||||
import adafruit_dht
|
||||
from adafruit_io.adafruit_io import IO_HTTP, AdafruitIO_RequestError
|
||||
from microcontroller import cpu
|
||||
|
||||
|
||||
|
||||
print("Servo test")
|
||||
mode = -1 # track state of button mode
|
||||
|
||||
def setupLED():
|
||||
led = DigitalInOut(board.LED)
|
||||
led.direction = Direction.OUTPUT
|
||||
led.value = True
|
||||
return led
|
||||
|
||||
def setupButton():
|
||||
# Mode button setup
|
||||
button = DigitalInOut(board.GP3)
|
||||
button.direction = Direction.INPUT
|
||||
button.pull = Pull.UP
|
||||
return button
|
||||
|
||||
|
||||
|
||||
def blink(led,count):
|
||||
for _ in range(count):
|
||||
led.value = False
|
||||
time.sleep(0.1)
|
||||
led.value = True
|
||||
time.sleep(0.1)
|
||||
|
||||
def setupServo():
|
||||
# Servo setup
|
||||
pwm_servo = pwmio.PWMOut(board.GP0, duty_cycle=2 ** 15, frequency=50)
|
||||
servo1 = servo.Servo(pwm_servo, min_pulse=500, max_pulse=2200) # tune pulse for specific servo
|
||||
|
||||
return servo1
|
||||
|
||||
def setServoAngle(servo1,angle):
|
||||
# Servo setup
|
||||
print("servo set angle =",angle)
|
||||
servo1.angle = angle
|
||||
servoData = angle
|
||||
data = [servoData]
|
||||
# send sensor data to respective feeds
|
||||
# io.send_data(picowServo,servoData)
|
||||
io.send_data("myservo",angle)
|
||||
print("sent")
|
||||
|
||||
return servo1
|
||||
|
||||
# Servo test
|
||||
def servo_direct_test1():
|
||||
print("Servo Direct Test 1")
|
||||
setServoAngle(servo1,90)
|
||||
time.sleep(2)
|
||||
setServoAngle(servo1,0)
|
||||
time.sleep(2)
|
||||
setServoAngle(servo1,90)
|
||||
time.sleep(2)
|
||||
setServoAngle(servo1,180)
|
||||
time.sleep(2)
|
||||
|
||||
|
||||
# Servo test
|
||||
def servo_direct_test():
|
||||
print("Servo Direct Test")
|
||||
print("servo test: 90")
|
||||
servo1.angle = 90
|
||||
time.sleep(2)
|
||||
print("servo test: 0")
|
||||
servo1.angle = 0
|
||||
time.sleep(2)
|
||||
print("servo test: 90")
|
||||
servo1.angle = 90
|
||||
time.sleep(2)
|
||||
print("servo test: 180")
|
||||
servo1.angle = 180
|
||||
time.sleep(2)
|
||||
|
||||
|
||||
# Servo smooth test
|
||||
def servo_smooth_test():
|
||||
counter = 1
|
||||
print("servo smooth test: 180 - 0, -1º steps")
|
||||
for angle in range(180, 0, -1): # 180 - 0 degrees, -1º at a time.
|
||||
servo1.angle = angle
|
||||
|
||||
if(counter > 10): # This is used to rate limit the data to Adafruit
|
||||
servoData = angle
|
||||
data = [servoData]
|
||||
# send sensor data to respective feeds
|
||||
# io.send_data(picowServo,servoData)
|
||||
io.send_data("myservo",angle)
|
||||
print("sent ", angle)
|
||||
counter = 1
|
||||
else:
|
||||
counter += 1
|
||||
|
||||
time.sleep(0.1)
|
||||
# time.sleep(0.01)
|
||||
time.sleep(1)
|
||||
print("servo smooth test: 0 - 180, 1º steps")
|
||||
for angle in range(0, 180, 1): # 0 - 180 degrees, 1º at a time.
|
||||
servo1.angle = angle
|
||||
time.sleep(0.01)
|
||||
time.sleep(1)
|
||||
|
||||
|
||||
def run_test(testnum):
|
||||
if testnum is 0:
|
||||
print("servo direct test")
|
||||
servo_direct_test1()
|
||||
elif testnum is 1:
|
||||
print("servo direct test")
|
||||
servo_smooth_test()
|
||||
|
||||
led = setupLED()
|
||||
button = setupButton()
|
||||
servo1 = setupServo()
|
||||
print("Type of servo = ",type(servo))
|
||||
|
||||
wifi.radio.connect(os.getenv('CIRCUITPY_WIFI_SSID'), os.getenv('CIRCUITPY_WIFI_PASSWORD'))
|
||||
|
||||
aio_username = os.getenv('ADAFRUIT_IO_USERNAME')
|
||||
aio_key = os.getenv('ADAFRUIT_IO_KEY')
|
||||
|
||||
pool = socketpool.SocketPool(wifi.radio)
|
||||
requests = adafruit_requests.Session(pool, ssl.create_default_context())
|
||||
# Initialize an Adafruit IO HTTP API object
|
||||
io = IO_HTTP(aio_username, aio_key, requests)
|
||||
print("connected to io")
|
||||
|
||||
|
||||
try:
|
||||
# get feed
|
||||
picowServo = io.get_feed("myservo")
|
||||
except AdafruitIO_RequestError:
|
||||
# if no feed exists, create one
|
||||
print("Feed error")
|
||||
sys.exit(-1)
|
||||
|
||||
# pack feed names into an array for the loop
|
||||
feed_names = [picowServo]
|
||||
print("Connected to feed.")
|
||||
|
||||
|
||||
while True:
|
||||
if not button.value:
|
||||
blink(led,2)
|
||||
mode = (mode + 1) % 2
|
||||
print("switch to mode %d" % (mode))
|
||||
time.sleep(0.8) # big debounce
|
||||
run_test(mode)
|
||||
68
Lab11/CircuitPython/Code/picowServo2CloudTest.py
Executable file
68
Lab11/CircuitPython/Code/picowServo2CloudTest.py
Executable file
|
|
@ -0,0 +1,68 @@
|
|||
# SPDX-FileCopyrightText: 2022 Liz Clark for Adafruit Industries
|
||||
# SPDX-License-Identifier: MIT
|
||||
|
||||
import os
|
||||
import sys
|
||||
import time
|
||||
import ssl
|
||||
import wifi
|
||||
import socketpool
|
||||
import microcontroller
|
||||
import board
|
||||
import busio
|
||||
import adafruit_requests
|
||||
import adafruit_dht
|
||||
from adafruit_io.adafruit_io import IO_HTTP, AdafruitIO_RequestError
|
||||
from microcontroller import cpu
|
||||
|
||||
|
||||
wifi.radio.connect(os.getenv('CIRCUITPY_WIFI_SSID'), os.getenv('CIRCUITPY_WIFI_PASSWORD'))
|
||||
|
||||
aio_username = os.getenv('ADAFRUIT_IO_USERNAME')
|
||||
aio_key = os.getenv('ADAFRUIT_IO_KEY')
|
||||
|
||||
pool = socketpool.SocketPool(wifi.radio)
|
||||
requests = adafruit_requests.Session(pool, ssl.create_default_context())
|
||||
# Initialize an Adafruit IO HTTP API object
|
||||
io = IO_HTTP(aio_username, aio_key, requests)
|
||||
print("connected to io")
|
||||
|
||||
|
||||
try:
|
||||
# get feed
|
||||
picowServo = io.get_feed("myservo")
|
||||
except AdafruitIO_RequestError:
|
||||
# if no feed exists, create one
|
||||
print("Feed error")
|
||||
sys.exit(-1)
|
||||
|
||||
# pack feed names into an array for the loop
|
||||
feed_names = [picowServo]
|
||||
print("Connected to feed.")
|
||||
|
||||
clock = 11
|
||||
|
||||
|
||||
while True:
|
||||
# when the clock runs out..
|
||||
print("") # Prints a blank line after clock print.
|
||||
# read sensor
|
||||
servoData = clock
|
||||
data = [servoData]
|
||||
# send sensor data to respective feeds
|
||||
# io.send_data(picowServo,servoData)
|
||||
io.send_data("myservo",servoData)
|
||||
print("sent")
|
||||
time.sleep(15)
|
||||
# print sensor data to the REPL
|
||||
print()
|
||||
|
||||
#time.sleep(1)
|
||||
time.sleep(1)
|
||||
print(clock)
|
||||
clock = clock + 1
|
||||
if clock >50:
|
||||
clock = 11
|
||||
|
||||
|
||||
|
||||
88
Lab11/CircuitPython/Code/picowServoTest1.py
Executable file
88
Lab11/CircuitPython/Code/picowServoTest1.py
Executable file
|
|
@ -0,0 +1,88 @@
|
|||
# SPDX-FileCopyrightText: 2021 jedgarpark for Adafruit Industries
|
||||
# SPDX-License-Identifier: MIT
|
||||
|
||||
# Pico servo demo
|
||||
# Hardware setup:
|
||||
# Servo on GP0 with external 5V power supply
|
||||
# Button on GP3 and ground
|
||||
|
||||
import time
|
||||
import board
|
||||
from digitalio import DigitalInOut, Direction, Pull
|
||||
import pwmio
|
||||
from adafruit_motor import servo
|
||||
|
||||
print("Servo test")
|
||||
|
||||
led = DigitalInOut(board.LED)
|
||||
led.direction = Direction.OUTPUT
|
||||
led.value = True
|
||||
|
||||
|
||||
def blink(times):
|
||||
for _ in range(times):
|
||||
led.value = False
|
||||
time.sleep(0.1)
|
||||
led.value = True
|
||||
time.sleep(0.1)
|
||||
|
||||
|
||||
# Mode button setup
|
||||
button = DigitalInOut(board.GP3)
|
||||
button.direction = Direction.INPUT
|
||||
button.pull = Pull.UP
|
||||
mode = -1 # track state of button mode
|
||||
|
||||
# Servo setup
|
||||
pwm_servo = pwmio.PWMOut(board.GP0, duty_cycle=2 ** 15, frequency=50)
|
||||
servo1 = servo.Servo(
|
||||
pwm_servo, min_pulse=500, max_pulse=2200
|
||||
) # tune pulse for specific servo
|
||||
|
||||
|
||||
# Servo test
|
||||
def servo_direct_test():
|
||||
print("servo test: 90")
|
||||
servo1.angle = 90
|
||||
time.sleep(2)
|
||||
print("servo test: 0")
|
||||
servo1.angle = 0
|
||||
time.sleep(2)
|
||||
print("servo test: 90")
|
||||
servo1.angle = 90
|
||||
time.sleep(2)
|
||||
print("servo test: 180")
|
||||
servo1.angle = 180
|
||||
time.sleep(2)
|
||||
|
||||
|
||||
# Servo smooth test
|
||||
def servo_smooth_test():
|
||||
print("servo smooth test: 180 - 0, -1º steps")
|
||||
for angle in range(180, 0, -1): # 180 - 0 degrees, -1º at a time.
|
||||
servo1.angle = angle
|
||||
time.sleep(0.01)
|
||||
time.sleep(1)
|
||||
print("servo smooth test: 0 - 180, 1º steps")
|
||||
for angle in range(0, 180, 1): # 0 - 180 degrees, 1º at a time.
|
||||
servo1.angle = angle
|
||||
time.sleep(0.01)
|
||||
time.sleep(1)
|
||||
|
||||
|
||||
def run_test(testnum):
|
||||
if testnum is 0:
|
||||
print("servo direct test")
|
||||
servo_direct_test()
|
||||
elif testnum is 1:
|
||||
print("servo smooth test")
|
||||
servo_smooth_test()
|
||||
|
||||
|
||||
while True:
|
||||
if not button.value:
|
||||
blink(2)
|
||||
mode = (mode + 1) % 2
|
||||
print("switch to mode %d" % (mode))
|
||||
time.sleep(0.8) # big debounce
|
||||
run_test(mode)
|
||||
117
Lab11/CircuitPython/Code/picowServoTest2.py
Executable file
117
Lab11/CircuitPython/Code/picowServoTest2.py
Executable file
|
|
@ -0,0 +1,117 @@
|
|||
# SPDX-FileCopyrightText: 2021 jedgarpark for Adafruit Industries
|
||||
# SPDX-License-Identifier: MIT
|
||||
|
||||
# Pico servo demo
|
||||
# Hardware setup:
|
||||
# Servo on GP0 with external 5V power supply
|
||||
# Button on GP3 and ground
|
||||
|
||||
import time
|
||||
import board
|
||||
from digitalio import DigitalInOut, Direction, Pull
|
||||
import pwmio
|
||||
from adafruit_motor import servo
|
||||
|
||||
print("Servo test")
|
||||
mode = -1 # track state of button mode
|
||||
|
||||
def setupLED():
|
||||
led = DigitalInOut(board.LED)
|
||||
led.direction = Direction.OUTPUT
|
||||
led.value = True
|
||||
return led
|
||||
|
||||
def setupButton():
|
||||
# Mode button setup
|
||||
button = DigitalInOut(board.GP3)
|
||||
button.direction = Direction.INPUT
|
||||
button.pull = Pull.UP
|
||||
return button
|
||||
|
||||
|
||||
|
||||
def blink(led,count):
|
||||
for _ in range(count):
|
||||
led.value = False
|
||||
time.sleep(0.1)
|
||||
led.value = True
|
||||
time.sleep(0.1)
|
||||
|
||||
def setupServo():
|
||||
# Servo setup
|
||||
pwm_servo = pwmio.PWMOut(board.GP0, duty_cycle=2 ** 15, frequency=50)
|
||||
servo1 = servo.Servo(pwm_servo, min_pulse=500, max_pulse=2200) # tune pulse for specific servo
|
||||
|
||||
return servo1
|
||||
|
||||
def setServoAngle(servo1,angle):
|
||||
# Servo setup
|
||||
print("servo set angle =",angle)
|
||||
servo1.angle = angle
|
||||
|
||||
return servo1
|
||||
|
||||
# Servo test
|
||||
def servo_direct_test1():
|
||||
print("Servo Direct Test 1")
|
||||
setServoAngle(servo1,90)
|
||||
time.sleep(2)
|
||||
setServoAngle(servo1,0)
|
||||
time.sleep(2)
|
||||
setServoAngle(servo1,90)
|
||||
time.sleep(2)
|
||||
setServoAngle(servo1,180)
|
||||
time.sleep(2)
|
||||
|
||||
|
||||
# Servo test
|
||||
def servo_direct_test():
|
||||
print("Servo Direct Test")
|
||||
print("servo test: 90")
|
||||
servo1.angle = 90
|
||||
time.sleep(2)
|
||||
print("servo test: 0")
|
||||
servo1.angle = 0
|
||||
time.sleep(2)
|
||||
print("servo test: 90")
|
||||
servo1.angle = 90
|
||||
time.sleep(2)
|
||||
print("servo test: 180")
|
||||
servo1.angle = 180
|
||||
time.sleep(2)
|
||||
|
||||
|
||||
# Servo smooth test
|
||||
def servo_smooth_test():
|
||||
print("servo smooth test: 180 - 0, -1º steps")
|
||||
for angle in range(180, 0, -1): # 180 - 0 degrees, -1º at a time.
|
||||
servo1.angle = angle
|
||||
time.sleep(0.01)
|
||||
time.sleep(1)
|
||||
print("servo smooth test: 0 - 180, 1º steps")
|
||||
for angle in range(0, 180, 1): # 0 - 180 degrees, 1º at a time.
|
||||
servo1.angle = angle
|
||||
time.sleep(0.01)
|
||||
time.sleep(1)
|
||||
|
||||
|
||||
def run_test(testnum):
|
||||
if testnum is 0:
|
||||
print("servo direct test")
|
||||
servo_direct_test1()
|
||||
elif testnum is 1:
|
||||
print("servo smooth test")
|
||||
servo_smooth_test()
|
||||
|
||||
led = setupLED()
|
||||
button = setupButton()
|
||||
servo1 = setupServo()
|
||||
print("Type of servo = ",type(servo))
|
||||
|
||||
while True:
|
||||
if not button.value:
|
||||
blink(led,2)
|
||||
mode = (mode + 1) % 2
|
||||
print("switch to mode %d" % (mode))
|
||||
time.sleep(0.8) # big debounce
|
||||
run_test(mode)
|
||||
7
Lab11/CircuitPython/Code/settings.toml
Executable file
7
Lab11/CircuitPython/Code/settings.toml
Executable file
|
|
@ -0,0 +1,7 @@
|
|||
CIRCUITPY_WIFI_SSID = "cset@stcc"
|
||||
CIRCUITPY_WIFI_PASSWORD = "c1s2e3t4"
|
||||
|
||||
|
||||
# Replace the next two lines with your Adafruit username and key.
|
||||
ADAFRUIT_IO_USERNAME = "csetuser"
|
||||
ADAFRUIT_IO_KEY = "aio_whil751ZM389iWH4GR20r90cTb0R"
|
||||
10
Lab11/CircuitPython/README.md
Executable file
10
Lab11/CircuitPython/README.md
Executable file
|
|
@ -0,0 +1,10 @@
|
|||
# CircuitPython Files
|
||||
|
||||
---
|
||||
Directories & Files
|
||||
---
|
||||
CircuitPython: CircuitPython firmware for the Pico 2 W
|
||||
|
||||
Code: CircuitPython code for the lab.
|
||||
|
||||
Documentation: Any additional documentation files.
|
||||
Loading…
Add table
Add a link
Reference in a new issue