{"id":3302,"date":"2020-07-29T15:30:29","date_gmt":"2020-07-29T06:30:29","guid":{"rendered":"http:\/\/oohito.com\/nqthm\/?p=3302"},"modified":"2020-07-29T15:30:29","modified_gmt":"2020-07-29T06:30:29","slug":"micropython%e3%81%a7df-robot-microbit-driver-expansion-boardv2-0%e3%82%92%e4%bd%bf%e3%81%86","status":"publish","type":"post","link":"https:\/\/oohito.com\/nqthm\/archives\/3302","title":{"rendered":"MicroPython\u3067DF-ROBOT micro:bit Driver Expansion Board(v2.0)\u3092\u4f7f\u3046"},"content":{"rendered":"\n<p>DF-ROBOT\u306emicro:bit Driver Expansion Board(v2.0)\u306f\u3001\u5b89\u4fa1\u306a\u5272\u306b\u6a5f\u80fd\u306e\u591a\u3044\u30e2\u30fc\u30bf\u30fc\u5236\u5fa1\u30dc\u30fc\u30c9\u3067\u3042\u308b\u3002<\/p>\n\n\n<p><a href=\"https:\/\/www.dfrobot.com\/product-1738.html\">https:\/\/www.dfrobot.com\/product-1738.html<\/a><\/p>\n\n\n<p>micro:bit \u4e0a\u306eGPIO\u3078\u306e\u30a2\u30af\u30bb\u30b9\u306b\u52a0\u3048\u3066\u30018\u500b\u306e\u30b5\u30fc\u30dc\u30e2\u30fc\u30bf\u30684\u500b\u306eDC\u30e2\u30fc\u30bf\u3092\u72ec\u7acb\u3057\u3066\u5236\u5fa1\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u308b\u3002\uff08\u5168\u3066\u3092\u4f7f\u3063\u305f\u8a33\u3067\u306f\u306a\u3044\u304c\uff09<\/p>\n\n\n<p>\u305f\u3060\u3001\u5236\u5fa1\u306e\u305f\u3081\u306e\u30d7\u30ed\u30b0\u30e9\u30e0\u3092\u4f5c\u6210\u3059\u308b\u306b\u306f MakeCode \u306a\u308a\u306e\u30d6\u30ed\u30c3\u30af\u30d7\u30ed\u30b0\u30e9\u30df\u30f3\u30b0\u74b0\u5883\u3092\u5fc5\u8981\u3068\u3057\u3066\u304a\u308a\u3001MicroPython \u3067\u4f7f\u3048\u308b\u30b3\u30fc\u30c9\u3092\u898b\u3064\u3051\u308b\u3053\u3068\u304c\u3067\u304d\u306a\u304b\u3063\u305f\u3002<\/p>\n\n\n<p><a href=\"https:\/\/github.com\/DFRobot\/pxt-motor\">https:\/\/github.com\/DFRobot\/pxt-motor<\/a><\/p>\n\n\n<p>\u3053\u306e\u30dc\u30fc\u30c9\u306f PCA9685 \u3068\u3044\u3046\u5b9a\u756a\u306e\u30b5\u30fc\u30dc\u30c9\u30e9\u30a4\u30d0\u3092\u4f7f\u3063\u3066\u304a\u308a\u3001I2C\u63a5\u7d9a\u3067\u4f55\u3068\u304b\u306a\u308b\u3068\u601d\u3063\u305f\u3089\u3001\u4f55\u3068\u304b\u306a\u3063\u305f\u306e\u3067\u8a18\u4e8b\u306b\u3057\u305f\u3002<\/p>\n\n\n<p>\u5f8c\u8ff0\u3059\u308b\u30d7\u30ed\u30b0\u30e9\u30e0\u30ea\u30b9\u30c8\u306f\u3001\u4e0a\u306eMakeCode\u30d6\u30ed\u30c3\u30af\u5bfe\u5fdc\u30b3\u30fc\u30c9\u306b\u3001SG90\u3078\u5bfe\u5fdc\u3059\u308b\u3088\u3046\u4fee\u6b63\u3092\u52a0\u3048\u305f Javascript \u306e\u30d7\u30ed\u30b0\u30e9\u30e0\u3092\u3001micro:bit\u7528\u306e MicroPython \u306b\u79fb\u690d\u3057\u305f\u3060\u3051\u306e\u5358\u7d14\u306a\u3082\u306e\u3067\u3042\u308b\u3002\u53c2\u8003\u306b\u3057\u305f\u306e\u306f\u3053\u3061\u3089\u3002<\/p>\n\n\n<p><a href=\"https:\/\/github.com\/nekoma-seisakusho\/pxt-motor\">https:\/\/github.com\/nekoma-seisakusho\/pxt-motor<\/a><\/p>\n\n\n<p>\u30dd\u30a4\u30f3\u30c8\u306f\u3001\u30b5\u30fc\u30dc\u30e2\u30fc\u30bf\u3082DC\u30e2\u30fc\u30bf\u3082PCA9685\u3092\u4f7f\u3063\u3066\u5236\u5fa1\u3059\u308b\u3068\u3044\u3046\u3053\u3068\u3067\u3042\u308b\u3002\u5f53\u521d\u3001DC\u30e2\u30fc\u30bf\u30c9\u30e9\u30a4\u30d0\u3082I2C\u3067\u5225\u306b\u63a5\u7d9a\u3055\u308c\u3066\u3044\u308b\u304b\u3068\u601d\u3063\u3066\u8abf\u3079\u3066\u3044\u305f\u306e\u3060\u304c\u3001PWM\u5165\u529b\u306eDC\u30e2\u30fc\u30bf\u30c9\u30e9\u30a4\u30d0\u306b\u3001PCA9685\u306ePWM\u51fa\u529b\u3092\u3064\u306a\u3052\u305f\u3082\u306e\u306e\u3088\u3046\u3060\u3002\u3061\u306a\u307f\u306bDC\u30e2\u30fc\u30bf\u30c9\u30e9\u30a4\u30d0\u3068\u3057\u3066\u3001HR8835 \u304c2\u500b\u4f7f\u308f\u308c\u3066\u3044\u308b\u3002<\/p>\n\n\n<p>\u3068\u3044\u3046\u3053\u3068\u3067\u3001MicroPython \u306e\u30b3\u30fc\u30c9\u306f\u4ee5\u4e0b\u306e\u901a\u308a\u3002<\/p>\n\n\n<pre class=\"wp-block-code\"><code>import microbit\nimport utime\ninitialized = False\ndef i2cWrite(addr, reg, value):\n    buf = &#91;0, 0]\n    buf&#91;0] = reg\n    buf&#91;1] = value\n    microbit.i2c.write(addr, bytes(buf))\ndef i2cRead(addr, reg):\n    microbit.i2c.write(addr, bytes(&#91;reg]))\n    ret = microbit.i2c.read(addr, 1)\n    return ret&#91;0]\ndef initPCA9685():\n    global initialized\n    i2cWrite(64, 0, 0)\n    oldmode = i2cRead(64, 0)\n    newmode = (oldmode &amp; 127) | 16\n    i2cWrite(64, 0, newmode)\n    i2cWrite(64, 254, 121)\n    i2cWrite(64, 0, oldmode)\n    utime.sleep_us(5000)\n    i2cWrite(64, 0, oldmode | 161)\n    initialized = True\ndef setPwm(channel, off):\n    if channel &lt; 0 or channel > 15:\n        return\n    print(\"setPWM\",channel,off)\n    buf = &#91;0] * 5\n    buf&#91;0] = 6 + 4 * channel\n    buf&#91;1] = 0\n    buf&#91;2] = 0\n    buf&#91;3] = off &amp; 255\n    buf&#91;4] = (off >> 8) &amp; 255\n    microbit.i2c.write(64, bytes(buf))\ndef Servo(index, degree):\n    if not initialized:\n        initPCA9685()\n    value = (degree * 10 + 600) * 4095 \/\/ 20000\n    setPwm(16 - index, value)\ndef MotorRun(index, speed):\n    if index &lt; 1 or index > 4:\n        return\n    if not initialized:\n        initPCA9685()\n    speed = speed * 16\n    if speed >= 4096:\n        speed = 4095\n    if speed &lt;= -4096:\n        speed = -4095\n    dp = speed\n    dn = 0\n    if speed &lt; 0:\n        dp = 0\n        dn = -speed\n    ch = (4 - index) * 2\n    setPwm(ch + 1, dp)\n    setPwm(ch, dn)<\/code><\/pre>\n\n\n<p>\u4f7f\u3044\u65b9\u306f\u3001Servo(\u30c1\u30e3\u30cd\u30eb\u756a\u53f7, \u89d2\u5ea6) \u3067\u3001\u30c1\u30e3\u30cd\u30eb\u756a\u53f7\u306b1\u304b\u30898\u3092\u3001\u89d2\u5ea6\u306f\u6570\u5024\u3092\u4e0e\u3048\u308c\u3070\u5bfe\u5fdc\u3059\u308b\u30b5\u30fc\u30dc\u30e2\u30fc\u30bf\u304c\u52d5\u304f\u3002\u307e\u305f\u3001MotorRun(\u30c1\u30e3\u30cd\u30eb\u756a\u53f7, \u901f\u5ea6) \u3067\u3001\u30c1\u30e3\u30cd\u30eb\u756a\u53f7\u306b1\u304b\u30894\u3092\u3001\u901f\u5ea6\u306b -255 \u304b\u3089 255 \u306e\u6570\u5024\u3092\u4e0e\u3048\u308c\u3070DC\u30e2\u30fc\u30bf\u304c\u52d5\u304f\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>DF-ROBOT\u306emicro:bit Driver Expansion Board(v2.0)\u306f\u3001\u5b89\u4fa1\u306a\u5272\u306b\u6a5f\u80fd\u306e\u591a\u3044\u30e2\u30fc\u30bf\u30fc\u5236\u5fa1\u30dc\u30fc\u30c9\u3067\u3042\u308b\u3002 https:\/\/www.dfrobot.com\/product-1738&#8230;.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[37,9],"tags":[],"class_list":["post-3302","post","type-post","status-publish","format-standard","hentry","category-microbit","category-python"],"_links":{"self":[{"href":"https:\/\/oohito.com\/nqthm\/wp-json\/wp\/v2\/posts\/3302","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/oohito.com\/nqthm\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/oohito.com\/nqthm\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/oohito.com\/nqthm\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/oohito.com\/nqthm\/wp-json\/wp\/v2\/comments?post=3302"}],"version-history":[{"count":0,"href":"https:\/\/oohito.com\/nqthm\/wp-json\/wp\/v2\/posts\/3302\/revisions"}],"wp:attachment":[{"href":"https:\/\/oohito.com\/nqthm\/wp-json\/wp\/v2\/media?parent=3302"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/oohito.com\/nqthm\/wp-json\/wp\/v2\/categories?post=3302"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/oohito.com\/nqthm\/wp-json\/wp\/v2\/tags?post=3302"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}