async def run(): c = controller.CioRoot() caps = await c.init() pprint(caps) pwm = await c.acquire('PWMs') n = await pwm.num_pins() print("# PWM-capable pins:", n) frequency = 50 # Hz for pin_index in range(n): print('Running on pin #', pin_index) await pwm.enable(pin_index, frequency) for i in range(10): for duty in range(5, 10): await pwm.set_duty(pin_index, duty) await asyncio.sleep(0.1) await asyncio.sleep(2) await pwm.disable(pin_index) await c.release(pwm) await c.close()
async def run13(): c = controller.CioRoot() caps = await c.init() pprint(caps) pwm = await c.acquire('PWMs') frequency = 20000 # Hz await pwm.enable(1, frequency) await pwm.enable(3, frequency//2) for j in range(100): for i in range(41): await pwm.set_duty(1, 15+i) await pwm.set_duty(3, 40+i) await asyncio.sleep(0.1) for i in range(40, -1, -1): await pwm.set_duty(1, 15+i) await pwm.set_duty(3, 40+i) await asyncio.sleep(0.1) #await asyncio.sleep(100) await pwm.disable(1) await pwm.disable(3) await c.release(pwm) await c.close()
async def run(): c = controller.CioRoot() caps = await c.init() pprint(caps) enc = await c.acquire('Encoders') enc_index = 1 # the _second encoder n = await enc.num_encoders() print('# encoders:', n) await enc.enable(enc_index) def fmt(val): return "{:6d}".format(val) for i in range(100000): counts = await enc.read_counts(enc_index) counts_str = ''.join([fmt(c) for c in counts]) timing = await enc.read_timing(enc_index) timing_str = ''.join([fmt(t) for t in timing]) print(counts_str + timing_str) await asyncio.sleep(0.1) await enc.disable(enc_index) await c.release(enc) await c.close()
async def run(): c = controller.CioRoot() caps = await c.init() pprint(caps) b = await c.acquire('Buzzer') await asyncio.sleep(2) #await b.play() # defaults to the 'on' sound #await b.play('o4l16ceg>c8') # the 'on' sound (explicit this time) #await b.play('v10>>g16>>>c16') # the soft reset sound #await b.play('>E>E>E R >C>E>G') #await b.play('!L16 V12 cdefgab>cbagfedc') # C-major scale up and down print(await b.is_currently_playing()) await b.play('!T240 L8 agafaea dac+adaea fa<aa<bac#a dac#adaea f4') # "Bach's fugue in D-minor" print(await b.is_currently_playing()) await b.wait() await asyncio.sleep(2) await c.release(b) await c.close()
async def run(): c = controller.CioRoot() caps = await c.init() pprint(caps) fd = c.fd await eeprom_store(fd, 0xA0, b'0000') buf = await eeprom_query(fd, 0xA0, 4) print(buf) assert buf == b'0000' await eeprom_store(fd, 0xA0, b'1234') buf = await eeprom_query(fd, 0xA1, 3) print(buf) assert buf == b'234' buf = await eeprom_query(fd, 0xA2, 2) print(buf) assert buf == b'34' buf = await eeprom_query(fd, 0xA3, 1) print(buf) assert buf == b'4' buf = await eeprom_query(fd, 0xA0, 4) print(buf) assert buf == b'1234'
async def run(): c = controller.CioRoot() caps = await c.init() pprint(caps) camera = await c.acquire('Camera') frame = await camera.capture() await c.release(camera) await c.close() print(frame)
async def run(): c = controller.CioRoot() caps = await c.init() pprint(caps) iface = await c.acquire('VersionInfo') name = await iface.name() version = await iface.version() await c.release(iface) await c.close() print(name, version)
async def run(): c = controller.CioRoot() caps = await c.init() pprint(caps) loop = await c.acquire('LoopFrequency') for i in range(50): print(await loop.read()) await asyncio.sleep(0.05) await c.release(loop) await c.close()
async def run(): c = controller.CioRoot() caps = await c.init() pprint(caps) p = await c.acquire('Photoresistor') for i in range(1000): print(await p.read(), await p.read_millivolts(), await p.read_ohms()) await asyncio.sleep(0.1) await c.release(p) await c.close()
async def run(): c = controller.CioRoot() caps = await c.init() pprint(caps) accel = await c.acquire('Accelerometer') for i in range(1000): fmt(await accel.read()) await asyncio.sleep(0.05) await c.release(accel) await c.close()
async def run(): c = controller.CioRoot() caps = await c.init() pprint(caps) ahrs = await c.acquire('AHRS') for i in range(10000): fmt(await ahrs.read()) await asyncio.sleep(0.05) await c.release(ahrs) await c.close()
async def run(): c = controller.CioRoot() caps = await c.init() pprint(caps) power = await c.acquire('Power') for i in range(1000): mv = await power.millivolts() mi = await power.estimate_remaining() sd = await power.should_shut_down() print(mv, mi, sd) await asyncio.sleep(0.1) await c.release(power) await c.close()
async def run(): c = controller.CioRoot() caps = await c.init() pprint(caps) motors = await c.acquire('CarMotors') await motors.set_params( top=40000, steering_left=3600, steering_mid=3000, steering_right=2400, steering_millis=1000, throttle_forward=4000, throttle_mid=3000, throttle_reverse=2000, throttle_millis=1000, ) await motors.save_params() await motors.on() await asyncio.sleep(1) for i in range(2): for v in range(-45, 45): print(v) await motors.set_steering(v) await motors.set_throttle(20) await asyncio.sleep(0.02) for v in range(45, -45, -1): print(v) await motors.set_steering(v) await motors.set_throttle(20) await asyncio.sleep(0.02) await motors.off() await asyncio.sleep(3) await c.release(motors) await c.close()
async def run(): c = controller.CioRoot() caps = await c.init() pprint(caps) b = await c.acquire('PushButtons') print('There are', await b.num_buttons(), 'buttons.') bi, action = await b.wait_for_action('released') print("Button", bi, "was", action) while True: event = await b.wait_for_event() pprint(event) await c.release(b) await c.close()
async def run(): c = controller.CioRoot() caps = await c.init() pprint(caps) gyro = await c.acquire('Gyroscope') gyro_accum = await c.acquire('Gyroscope_accum') for i in range(500): fmt(await gyro.read()) fmt(await gyro_accum.read()) print() if i % 50 == 0: await gyro_accum.reset() await asyncio.sleep(0.1) await c.release(gyro) await c.release(gyro_accum) await c.close()
async def run(): c = controller.CioRoot() caps = await c.init() pprint(caps) leds = await c.acquire('LEDs') mode_map = await leds.mode_map() print(mode_map) for mode, _ in mode_map.items(): print('Setting to mode', mode) await leds.set_mode(mode) await asyncio.sleep(3) print('Clearing the mode...') await leds.set_mode(None) led_map = await leds.led_map() print(led_map) print('Turning on red...') await leds.set_led('red', True) await asyncio.sleep(2) print('Turning off red...') await leds.set_led('red', False) await asyncio.sleep(1) for i in range(8): binary = "{0:{fill}3b}".format(i, fill='0') print('Showing binary:', binary) red, green, blue = [int(b) for b in binary] await leds.set_many_leds( zip(['red', 'green', 'blue'], [red, green, blue])) await asyncio.sleep(1) await c.release(leds) await c.close()
async def run(): c = controller.CioRoot() caps = await c.init() pprint(caps) print('Acquiring PID_steering and CarMotors...') pid = await c.acquire('PID_steering') motors = await c.acquire('CarMotors') p, i, d = 1.0, 0.1, 0.1 await pid.set_pid(p, i, d) await pid.set_point(0.0) print('Enabling PID loop...') await pid.enable() await asyncio.sleep(5) print('Turning on CarMotors and setting throttle...') await motors.on() await motors.set_throttle(25) await asyncio.sleep(10) print('Disabling PID loop...') await pid.disable() await asyncio.sleep(5) print('Turning off CarMotors...') await motors.off() await asyncio.sleep(5) print('Releasing PID_steering and CarMotors...') await c.release(pid) await c.release(motors) await c.close()
async def run(): c = controller.CioRoot() caps = await c.init() pprint(caps) iface = await c.acquire('VersionInfo') n = 0 start = time.time() while True: _ = await iface.version() n += 1 now = time.time() if (now - start) >= 1.0: print(n) start = now n = 0 await c.release(iface) await c.close()