06. Automated Wind Mill
New project was to make a rotating Wind Mill with a 360º servo that I bough by mistake instead of a 180º for the Train Crossing.
So... nothing is lost, just a new challenge.
The challenge here was not the programming but transferring servo movement to the Wind Mill Mast through a set of gears.
Material:
1x 360º servo
1x set of small plastic gears
1x paper clip
1x Wind Mill from modelismoartesanal
1x Micropython board
Here you can watch full video of the build
Python code
# turn on_off wild mill and internal LEDs,
# ver 1.3
# Libraries
import time, pyb, machine, utime, urandom
from pyb import Pin, Servo
from array import array
dict_data = {"closed_1": -10, "open_1": 0,} # Creates default dict_data
def read_file():
with open("config.txt", "r") as file_in:
line = file_in.readline() # reads each line in file
while line != '': # The EOF char is an empty string
list = [] # Creates empty List to store data from config.txt in dict_data
dummy_r = line.strip("\n").split(",") # reads items from line
for i in dummy_r:
list.append(i)
dict_data[list[0]] = list[1] # Add list content to Dictionary
dummy_r = '' # Cleans Var
i = '' # Cleans Var
line = file_in.readline() # Advances one line
closed_1 = int(dict_data["closed_1"]) # Closed position Servo_1
# closed_2 = int(dict_data["closed_2"]) # Closed position Servo_2
open_1 = int(dict_data["open_1"]) # Open position Servo_1
# open_2 = int(dict_data["open_2"]) # Open position Servo_2
if line == '':
file_in.close() # Closes File
def mill_slow_up(x):
for y in range (1,9):
servo_1.angle(y,1000) # close PN servo in X1 (azimuth + speed)
time.sleep(x) # sleep for xseg
pyb.LED(2).toggle() # internal LED(2) RESET ( 1=red, 2=green, 3=yellow, 4=blue )
def mill_slow_down(x):
for y in range (9,1,-1):
servo_1.angle(y,1000) # close PN servo in X1 (azimuth + speed)
time.sleep(x) # sleep for xseg
pyb.LED(1).toggle() # internal LED(1) RESET ( 1=red, 2=green, 3=yellow, 4=blue )
while True:
read_file() # Load config file servo data
sw = pyb.Switch().value() # act internal USR switch
led_1 = Pin('Y11', Pin.OUT_PP) # set LED1 to out Y11
servo_1 = pyb.Servo(1) # set Servo_1 on position 1 (X1, VIN, GND)
# servo position (Closed/Open)
closed_1 = int(dict_data["closed_1"]) # Closed position Servo_1
open_1 = int(dict_data["open_1"]) # Open position Servo_1
# check status of iR input trigger for loop ativation
# pyb.LED(4).off() # internal LED(3) RESET ( 1=red, 2=green, 3=yellow, 4=blue )
led_1.high() # external LED1 ON
time.sleep(1) # sleep for xseg
pyb.LED(3).on() # internal LED(3) RESET ( 1=red, 2=green, 3=yellow, 4=blue )
mill_slow_up(2) # activate mill_slow_up with x time spacing
servo_1.angle(closed_1,1000) # set mill speed to config file close_1 (azimuth + speed)
time.sleep(25) # sleep for xseg
mill_slow_down(2) # activate mill_slow_up with x time spacing
pyb.LED(3).off() # internal LED(3) RESET ( 1=red, 2=green, 3=yellow, 4=blue )
# set all to standard rest position
servo_1.angle(open_1) # set mill speed to config file open_1 (azimuth + speed)
time.sleep(1) # sleep for xseg
led_1.low() # external LED1 RESET
# pyb.LED(4).toggle() # internal LED(4) ON_OFF ( 1=red, 2=green, 3=yellow, 4=blue )
pyb.LED(2).off() # internal LED(3) RESET ( 1=red, 2=green, 3=yellow, 4=blue )
pyb.LED(2).off() # internal LED(3) RESET ( 1=red, 2=green, 3=yellow, 4=blue )
utime.sleep(urandom.randint(30, 60)) # Delay for random time between 15 and 30 seconds
create a config.txt file with wind mill speed settings with content below:
closed_1,10
open_1,0
Comments
Post a Comment