Required:
Step 1
Step 2
Step 3
Step 4
① Hold the lid still to make it align with the hole.
② Insert the rod.
ATTENTION: Keep the lid flatwise.
Step 5
Step 6
Step 7
Step 8
Step 9
Step 10
The servo need to be calibrated before using. Connect the servo to pin io19 on the board and link the board to computer via USB cable.
Open Servo_Calibration.py and click .
'''
* Filename : Servo_Calibration
* Thonny : Thonny 4.1.4
* Auther : http//www.keyestudio.com
'''
from machine import Pin, PWM
import time
servo = PWM(Pin(19))
servo.freq(50) #T = 1/f = 20ms
def angle(x):
return int((((x + 45) * 1.8 / 270) + 0.6 )/ 20 *65535)
while True:
servo.duty_u16(angle(90))
After calibration, disconnect the board to computer and continue to mount.
ATTENTION: During mounting, please hold and keep the lid flatwise.
Step 11
Step 12
Completed!
Open 4.4Smart bin_Manual mode.py and click .
'''
* Filename : Smart bin_Manual mode
* Thonny : Thonny 4.1.4
* Auther : http//www.keyestudio.com
'''
from machine import Pin,PWM
import time
from ROCKER import rocker
servo = PWM(Pin(19))
servo.freq(50) #T = 1/f = 20ms
def angle(x):
return int((((x + 45) * 1.8 / 270) + 0.6 )/ 20 *65535)
scl = Pin(5)
sda = Pin(4)
bus = 0
snsr = rocker (bus, scl, sda)
while True:
x,y,z = snsr.readXYZ()
print('y:',y)
time.sleep(0.1)
if 0 <= y < 490:
servo.duty_u16(angle(-45))
else:
servo.duty_u16(angle(90))
<=
Comparison operator: less than or equal to, it determines whether the left value is less than or equal to the right, and then True or False will be returned.
Conceive:
Initialization: set the pins of IIC and servo, set the servo output frequency.
Loop:
① read the value of joystick in y-axis and refresh it every 0.1 seconds, and print it on Shell.
② determine whether the value in y-axis is within 0 to 490 (with the servo being calibrated, the trash can lid is closed at this time).
True: the servo rotates to -45° to open the lid.
False: the servo rotates to 90° to close the lid.