print("--- RAM free ---> " + str(mem_free())) pinout = set_pinout() built_in_led = Led(pinout.BUILT_IN_LED) num_neo = 16 # 30 # number of Leds np = Rgb(pinout.WS_LED_PIN, num_neo) ws_r = 0 ws_g = 0 ws_b = 0 boot_pin = Pin(0, Pin.IN) boot_button = Button(boot_pin, release_value=1) servo = Servo(pinout.PWM1_PIN) d7 = disp7_init() def parse_rgba_msg(msg): """ parse rgba message to dict from following formats: #ff00C3 #ff00C3FF RGBA(255,0,200,255) or rgba(255,0,200,255) RGB(255,0,200,255) or rgb(255,0,200) [255,0,200,255] [255,0,200] """ ret = {'RED': 0, 'GREEN': 0, 'BLUE': 0, 'ALPHA': 0}
# servo laser pointer - example from time import sleep_ms from utils.transform import * from components.servo import Servo # todo: PWM double setup error s1 = Servo(17) s2 = Servo(16) dist = 100 # distance and size of board delay = 5 def move_servo2(p1, p2, delay = delay): steps = move_2d_line(p1, p2) for step in steps: alfa = cosangle(step[0], dist, dist)[0] beta = cosangle(step[1], dist, dist)[0] print(step, alfa, beta) s1.set_degree(alfa) s2.set_degree(beta) sleep_ms(delay) def run_test(): p1 = 0, 0 # strart point p2 = 50, 50 # stop point move_servo2(p1, p2)
def servo_init(pin = PIN_SER): servo = Servo(PIN_SER) return servo
# octopusLAB - BLE and BlueFruit mobile app. ## uPyShell:~/$ run examples/ble/ble_servo.py # 13.6.2020 print("---> BLE and BlueFruit mobile app. - pwm") print("This is simple Micropython example | ESP32 & octopusLAB") from utils.octopus_lib import getUid uID5 = getUid(short=5) from time import sleep from utils.pinout import set_pinout from components.servo import Servo pinout = set_pinout() s1 = Servo(pinout.PWM1_PIN) # s2 = Servo(pinout.PWM2_PIN) # s3 = Servo(pinout.PWM3_PIN) import blesync_server import blesync_uart.server import utils.ble.bluefruit as bf angle = 45 s1.set_degree(angle) angle_min = 10 angle_max = 150 @blesync_uart.server.UARTService.on_message def on_message(service, conn_handle, message):
# servo test - example from time import sleep from utils.pinout import set_pinout from components.servo import Servo # todo: PWM double setup error pinout = set_pinout() # s1 = Servo(pinout.PWM1_PIN) # s2 = Servo(pinout.PWM2_PIN) s3 = Servo(pinout.PWM3_PIN) angles = [0, 20, 50, 70, 90] while True: for a in angles: # s1.set_degree(a) # s2.set_degree(a) s3.set_degree(a) sleep(1)
class SensorBlock: def __init__(self, servo, ultrasonic): self.servo = servo self.ultrasonic = ultrasonic pass def __del__(self, ): pass def move(self, theta): self.servo.move_to(theta) def tilt_down(self): self.servo.inc_angle() def tilt_up(self): self.servo.dec_angle() if __name__ == "__main__": servo11 = Servo(11, min_pulse=950, max_pulse=1600, initial_angle=180) depth_sensor = DepthSensor(11, 8) sensor_block = SensorBlock(servo11, depth_sensor) while (True): key = input() if (key == 'w'): sensor_block.tilt_up() else: sensor_block.tilt_down()
ENABLE_COMPENSATION = True LR_COMPENSATION = +10 # %, -10 slows L motor comared to R ULTRASONIC_SAMPLING = 60 # ms, how often detect obstacle moto_L1 = Pin(pinout.MOTOR_1A, Pin.OUT) moto_L2 = Pin(pinout.MOTOR_2A, Pin.OUT) moto_L = PWM(Pin(pinout.MOTOR_12EN, Pin.OUT), freq=500, duty = 0) moto_R3 = Pin(pinout.MOTOR_3A, Pin.OUT) moto_R4 = Pin(pinout.MOTOR_4A, Pin.OUT) moto_R = PWM(Pin(pinout.MOTOR_34EN, Pin.OUT), freq=500, duty = 0) echo = HCSR04(trigger_pin=pinout.PWM2_PIN, echo_pin=pinout.PWM1_PIN) servo = Servo(pinout.PWM3_PIN) servo.set_degree(50) def read_distance(echo): d = echo.distance_cm() if d < 0: sleep_ms(50) d = echo.distance_cm() print('distance', d) return d def compensate_speed_left(speed): return speed + int(speed/100 * LR_COMPENSATION/2) * ENABLE_COMPENSATION def compensate_speed_right(speed): return speed - int(speed/100 * LR_COMPENSATION/2) * ENABLE_COMPENSATION
# octopusLAB - BLE and BlueFruit mobile app. ## uPyShell:~/$ run examples/ble/ble_servo.py # 13.6.2020 print("---> BLE and BlueFruit mobile app. - pwm") print("This is simple Micropython example | ESP32 & octopusLAB") from utils.octopus_lib import getUid uID5 = getUid(short=5) from time import sleep from utils.pinout import set_pinout from components.servo import Servo pinout = set_pinout() s1 = Servo(pinout.PWM1_PIN) s2 = Servo(pinout.PWM2_PIN) # s3 = Servo(pinout.PWM3_PIN) import blesync_server import blesync_uart.server import utils.ble.bluefruit as bf angle1 = 45 angle2 = 45 s1.set_degree(angle1) s2.set_degree(angle2) angle_min = 10 angle_max = 150
# octopusLAB simple example from time import sleep from components.analog import Analog # from utils.octopus_lib import map from components.servo import Servo an2 = Analog(35) s1 = Servo(16) s1.set_degree(0) # 0-150 amin = 0 amax = 150 while True: data = an2.get_adc_aver(2) sleep(0.05) angle = map(data, 0, 4000, amin, amax) print(data,angle) s1.set_degree(angle)
import urequests from utils.octopus import disp7_init from time import time, sleep from utils.octopus import w from components.servo import Servo s1 = Servo(17) from components.rgb import Rgb from utils.pinout import set_pinout pinout = set_pinout() from utils.io_config import get_from_file io_conf = get_from_file() ws = Rgb(pinout.WS_LED_PIN,io_conf.get('ws')) w() # You can change it to what you want # This server have /set.php?name=[name]&data=[data] wich will set data for the given name # And get.php?name=[name] wich will give back the data # At the root there is a simple form to put data SERVER_URL = "http://ark.smee.ovh:8088/get.php?name=bryan" d7 = disp7_init() global cursor cursor = 0 global total_text total_text = "Octopus" last_time = -10000 def set_text(text): global cursor global total_text cursor = 0 total_text = text
print("servos init") from config import Config setup = Config("draw2servos") setup.print_all() try: L1 = int(setup.get("L1")) L2 = int(setup.get("L2")) except: print("config.Err") print("L1, L2: " + str(L1) + ", " + str(L2)) print("servos init") from components.servo import Servo s1 = Servo(17) s2 = Servo(16) s1.set_degree(90) s2.set_degree(0) def move_servo2(p1, p2, delay=5): steps = move_2d_line(p1, p2) for step in steps: alfa, beta = invkin2(step, L1, L2) print(step, alfa, beta) s1.set_degree(alfa) s2.set_degree(beta)