背景:Maqueenはmicro:bitで制御する設計だが、WiFiも使えるESP32で制御したい
取り組み:micro:bitユニバーサル基板によりコネクタ仕様をmicro:bitとコンバチにしてESP32とMaqueenのバスを接続する
結果:マイコン用のソケットを買っていないので空中配線でmicro:bitユニバーサル基板のI2CとESP32-C3のI2Cを接続、サーボ制御までは行えた
詳細:
ESP32-C3のGPIO6,GPIO7とmicro:bitユニバーサル基板のSDA,SCLと接続(空中配線)
[:W400]
以下はサーボ制御用ドライバとテストプログラム
# # motor control for Maqueen # MPU: ESP32-C3 # CTLR_ADDR=0x10 MOTOR_L = 0 MOTOR_R = 2 FORWARD=0 BACK=1 DEFAULT_SPEED=30 from machine import Pin, I2C i2c = I2C(0, scl=Pin(7), sda=Pin(6), freq=100000) def stop(i2c): i2c.writeto(0x10,bytes((MOTOR_L,FORWARD,00))) i2c.writeto(0x10,bytes((MOTOR_R,FORWARD,00))) def go(i2c,speed=DEFAULT_SPEED): i2c.writeto(0x10,bytes((MOTOR_L,FORWARD,speed))) i2c.writeto(0x10,bytes((MOTOR_R,FORWARD,speed))) def back(i2c,speed=DEFAULT_SPEED): i2c.writeto(0x10,bytes((MOTOR_L,BACK,speed))) i2c.writeto(0x10,bytes((MOTOR_R,BACK,speed))) def rotate(i2c,direction,speed=DEFAULT_SPEED): if direction == 'L': i2c.writeto(0x10,bytes((MOTOR_L,BACK,speed))) i2c.writeto(0x10,bytes((MOTOR_R,FORWARD,speed))) elif direction == 'R': i2c.writeto(0x10,bytes((MOTOR_L,FORWARD,speed))) i2c.writeto(0x10,bytes((MOTOR_R,BACK,speed))) def turn(i2c,direction,speed=DEFAULT_SPEED): slow_speed = int(speed * 0.7) if direction == 'L': i2c.writeto(0x10,bytes((MOTOR_L,FORWARD,slow_speed))) i2c.writeto(0x10,bytes((MOTOR_R,FORWARD,speed))) elif direction == 'R': i2c.writeto(0x10,bytes((MOTOR_L,FORWARD,speed))) i2c.writeto(0x10,bytes((MOTOR_R,FORWARD,slow_speed))) # # test program # def test(i2c): go(i2c) time.sleep(3) stop(i2c) time.sleep(3) rotate(i2c,'L') time.sleep(3) rotate(i2c,'R') time.sleep(3) turn(i2c,'L') time.sleep(3) turn(i2c,'R') time.sleep(3) stop(i2c) # # test # import time test(i2c)
■参考にした記事
情報ありがとうございます。
12月 | 2021 | macsbug
Seeed Studio XIAO ESP32C3でMicroPython - Seeed K.K. エンジニアブログ
Micro:Maqueen × Python – 生源寺研究室
DT robot Maqueen Plus V2 Micro Python Microbit