Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.
Micro Python 䛷 
⤌䜏㎸䜏 Python 
@hktechno 
Hirotaka Kawata
@hktechno 
ᕝ⏣ ⿱㈗ (䛛䜟䛯 䜂䜝䛯䛛) 
● PyCon JP 2013-2014 Staff (Program Team) 
● ⟃Ἴ኱Ꮫ 䝅䝇䝔䝮᝟ሗᕤᏛ◊✲⛉ 
䝁䞁䝢䝳䞊䝍䝃䜲䜶䞁䝇ᑓᨷ 
○ ಟኈ 1ᖺ 
● Open...
Micro Python 
● Python for microcontrollers 
○ 䝬䜲䝁䞁䛷౑䛘䜛 Python 
○ KICKSTARTER 䛷 97,803 GBP (⣙1500୓෇) ⋓ᚓ 
● The pyboard 
○ ...
Micro Python 
● Python 3 ஫᥮䛾 Python ฎ⌮⣔ 
○ 䝬䜲䝁䞁ྥ䛡䛻෌ᐇ⿦ (CPython 䛷䛿䛺䛔) 
○ 䝷䜲䝤䝷䝸䜒ᇶᮏⓗ䛺䜒䛾䛿౑䛘䜛 
● 䝬䜲䝁䞁ୖ䛷 Python 䛜ື䛟 
○ Arduino 䛾...
The pyboard 
● Micro Python board 
○ STM32F4 (Cortex-M4) 
○ microSD slot 
○ microUSB 
○ Accelerometer 
○ 4 LED 
○ Switch… ...
vs Raspberry Pi 
● GPIO 
○ Raspberry Pi 䛿䛱䜗䛳䛸ᑡ䛺䜑 
○ (Type B+ 䛷ᑡ䛧ቑ䛘䜎䛧䛯) 
● Price 
○ 3940෇... 
● 㛤Ⓨ䛜㠃ಽ䛟䛥䛔 
○ Raspberry Pi 䛾 ...
vs mruby 
ᛮ᝿䛾㐪䛔 
● mruby 
○ ⤌䜏㎸䜏ᶵჾ䛷 C 䛛䜙 Ruby 䜢ᢅ䛖 
○ 䝋䝣䝖䜴䜵䜰䛻⤌䜏㎸䜏䜒䛷䛝䜛 (Lua 䛾䜘䛖䛺) 
○ ୺䛻䚸䝞䜲䝖䝁䞁䝟䜲䝹䛧䛯䝞䜲䝘䝸䜢ᢞධ 
● Micro Python 
○...
䛧䛛䛧... 
● pyboard 䛿⌧ᅾධᡭ୙ྍ⬟ 
○ KICKSTARTER 䛾㉎ධศ䛿Ⓨ㏦῭䜏 
○ ḟ䛾䝻䝑䝖䜢⏕⏘䛩䜛䜙䛧䛔䠛 
○ 䛹䛱䜙䛻䛧䛶䜒䛩䛠䛻䛿ධᡭ୙ྍ⬟... 
● ண䜑Ⓩ㘓䛧䛶䛒䛳䛯ே䛾ඛ⾜㈍኎䜒... 
○ ᡭඖ䛻...
ㅉ䜑䜛䛾䛿䜎䛰᪩䛔䟿
ᡭ㍍䛻 Micro Python 
● STM32F4 Discovery 
○ ST Micro ⣧ṇ䛾 STM32F407 ホ౯䝪䞊䝗 
○ ⛅᭶㟁Ꮚ㏻ၟ䛷 1,750 ෇ 
● ᶵ⬟ 
○ 192KB RAM 
○ 1MB Flash 
...
STM32F4 Disvoery ‽ഛ 
● Micro Python 䝉䝑䝖䜰䝑䝥᪉ἲ 
○ https://github. 
com/micropython/micropython/wiki/Board- 
STM32F407-Discov...
᥋⥆䞉᭩䛝㎸䜏 
● USB 䝇䝖䝺䞊䝆䛸䛧䛶ㄆ㆑䛩䜛 
○ boot.py: ㉳ື᫬䛻ᐇ⾜䛥䜜䜛 
○ main.py: 䝯䜲䞁䝥䝻䜾䝷䝮 
○ 䝋䞊䝇 (main.py) 䜢䝁䝢䞊䛩䜛䛰䛡䛷Ⰻ䛔 
○ ⮬ศ䛷స䛳䛯䝰䝆䝳䞊䝹䜒᭩䛝㎸䜏䞉฼⏝...
pyb Module 
● pyboard 䜢᧯స䛩䜛䝰䝆䝳䞊䝹 
○ pyb.Pin 
○ pyb.LED 
○ pyb.Switch 
○ pyb.SPI 
○ pyb.I2C 
○ pyb.UART... 
○ http://microp...
Micro Python REPL 
● Python 䛾 REPL 䛸䜋䜌ྠ䛨 
○ 䜲䞁䝍䝷䜽䝔䜱䝤䛻䝬䜲䝁䞁䜢᧯స䛷䛝䜛 
○ 䝕䝞䝑䜾䛻౽฼ 
○ 䝰䝆䝳䞊䝹䜢᭩䛝㎸䜣䛷䛚䛡䜀䚸䛭䜜䜒౑䛘䜛 
● Ctrl-D 䛷 soft-reset...
LED ON / OFF 
● 䛸䜚䛒䛘䛪 L 䝏䜹 
led = pyb.LED(1) 
while True: 
led.off() 
pyb.delay(500) 
led.on() 
pyb.delay(500) 
䛣䜜䛷䜒䜘䛔 
le...
Switch 
● Switch 䛷 Callback 䛜౑䛘䜛 
def toggle(): 
pyb.LED(1).toggle() 
pyb.delay(10) 
sw = pyb.Switch() 
sw.callback(toggle...
GPIO 
● pyb.Pin 䜢౑䛖 
pin = pyb.Pin(pyb.Pin.board.PD2, 
pyb.Pin.OUT_PP) 
pin.high() 
pin.low() 
pin_value = pin.value() 
pi...
STM32F4DISC STAccel 
● 䠎✀㢮䛾ຍ㏿ᗘ䝉䞁䝃䞊 
○ 䝪䞊䝗䛾䝻䝑䝖䛻䜘䛳䛶㐪䛖 
○ LIS302DL (ྂ䛔) 
○ LIS3DSH (᪂䛧䛔, 㧗ᶵ⬟) 
● staccel.py : STAccel # pyb.A...
LCD 
ᕷ㈍䛾 LCD 䜢౑䛖 # pyb.LCD 䛿䚸pyboard ᑓ⏝ 
● SC1602 䝅䝸䞊䝈 (ᐃ␒䛾䜰䝺) 
○ ⛅᭶㟁Ꮚ㏻ၟ䛷኎䛳䛶䜎䛩 
○ 䝞䝑䜽䝷䜲䝖䛺䛧䛷䛒䜜䜀 500 ෇䛛䜙 
● Python 䛷 LCD 䝗䝷䜲...
䛔䜝䛔䜝 DEMO
Performance 
● (ᙜ䛯䜚๓䛰䛡䛹) ⤖ᵓ㐜䛔 
○ Teensy 3.1 (96MHz ARM) 
○ C++ (Arduino like) 䛸䛟䜙䜉䛶䚸⣙ 100 ಸ㐜䛔 
○ https://github. 
com/micr...
Inline Assembly 
䜲䞁䝷䜲䞁䜰䝉䞁䝤䝷䛾౛ 
@micropython.asm_thumb 
def asm_add(r0, r1): 
add(r0, r0, r1)
Development Sprint 
● 14᪥ Development Sprint 䜔䜚䜎䛩 
○ http://pyconjp.connpass.com/event/8105/ 
● Micro Python Sprint 
○ ゐ䛳䛯...
௚䛾䝬䜲䝁䞁䜈䛾⛣᳜ 
● GR-SAKURA 䜈⛣᳜䜢ヨ䜏䛯 
○ Renesas RX63N 
● 㐍ᤖ 
○ 䜲䞁䝍䝥䝸䝍䛿ື䛔䛯 
○ print 䛿䛷䛝䜛 
○ 䜎䛰: pyb 䝰䝆䝳䞊䝹 
○ 䜎䛰: REPL 
⤖ㄽ: 䜎䛰STM...
䜎䛸䜑 
● Micro Python 䛺䛛䛺䛛䜘䛥䛭䛖 
○ 䛯䛰䛧䚸䜎䛰䜎䛰ᨵၿ䛾వᆅ䛜䛒䜚䛭䛖 
○ ௚䛾䝪䞊䝗䜈䛾⛣᳜䛻ᮇᚅ 
● Raspberry Pi ౑䛳䛯䜋䛖䛜Ⰻ䛥䛭䛖䛺⏝㏵ 
○ 䝛䝑䝖䝽䞊䜽 
○ Wi-Fi, Bluet...
Micro Python で組み込み Python
Upcoming SlideShare
Loading in …5
×

Micro Python で組み込み Python

18,596 views

Published on

Micro Python を使って組み込み Python プログラミングを行う方法を紹介

Published in: Engineering
  • Hello! Get Your Professional Job-Winning Resume Here - Check our website! https://vk.cc/818RFv
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here

Micro Python で組み込み Python

  1. 1. Micro Python 䛷 ⤌䜏㎸䜏 Python @hktechno Hirotaka Kawata
  2. 2. @hktechno ᕝ⏣ ⿱㈗ (䛛䜟䛯 䜂䜝䛯䛛) ● PyCon JP 2013-2014 Staff (Program Team) ● ⟃Ἴ኱Ꮫ 䝅䝇䝔䝮᝟ሗᕤᏛ◊✲⛉ 䝁䞁䝢䝳䞊䝍䝃䜲䜶䞁䝇ᑓᨷ ○ ಟኈ 1ᖺ ● Open Design Computer Project ○ 2011 ᮍ㋃IT䛺䜣䛸䛛 䝇䞊䝟䞊䜽䝸䜶䜲䝍䞊 ○ http://open-arch.org/
  3. 3. Micro Python ● Python for microcontrollers ○ 䝬䜲䝁䞁䛷౑䛘䜛 Python ○ KICKSTARTER 䛷 97,803 GBP (⣙1500୓෇) ⋓ᚓ ● The pyboard ○ Micro Python ⏝䛾䝬䜲䝁䞁ᇶᯈ http://micropython.org/ 㠃ⓑ䛭䛖
  4. 4. Micro Python ● Python 3 ஫᥮䛾 Python ฎ⌮⣔ ○ 䝬䜲䝁䞁ྥ䛡䛻෌ᐇ⿦ (CPython 䛷䛿䛺䛔) ○ 䝷䜲䝤䝷䝸䜒ᇶᮏⓗ䛺䜒䛾䛿౑䛘䜛 ● 䝬䜲䝁䞁ୖ䛷 Python 䛜ື䛟 ○ Arduino 䛾䜘䛖䛺ᡭ㍍䛥 ○ 䛧䛛䜒 Python 䛷᭩䛡䜛 ○ Python ෆ䛷䜲䞁䝷䜲䞁䜰䝉䞁䝤䝷䛜౑䛘䛯䜚... (!!) ● REPL 䜒౑䛘䜛 ○ 䝬䜲䝁䞁ୖ䛷䜲䞁䝍䝷䜽䝔䜱䝤䝅䜵䝹
  5. 5. The pyboard ● Micro Python board ○ STM32F4 (Cortex-M4) ○ microSD slot ○ microUSB ○ Accelerometer ○ 4 LED ○ Switch… ● KICKSTARTER ○ $20 (early-bird price) ○ $24
  6. 6. vs Raspberry Pi ● GPIO ○ Raspberry Pi 䛿䛱䜗䛳䛸ᑡ䛺䜑 ○ (Type B+ 䛷ᑡ䛧ቑ䛘䜎䛧䛯) ● Price ○ 3940෇... ● 㛤Ⓨ䛜㠃ಽ䛟䛥䛔 ○ Raspberry Pi 䛾 Linux 䛷㛤Ⓨ䛩䜛 or SSH ○ 䛭䜒䛭䜒䝬䜲䝁䞁䛷䛿䛺䛔...
  7. 7. vs mruby ᛮ᝿䛾㐪䛔 ● mruby ○ ⤌䜏㎸䜏ᶵჾ䛷 C 䛛䜙 Ruby 䜢ᢅ䛖 ○ 䝋䝣䝖䜴䜵䜰䛻⤌䜏㎸䜏䜒䛷䛝䜛 (Lua 䛾䜘䛖䛺) ○ ୺䛻䚸䝞䜲䝖䝁䞁䝟䜲䝹䛧䛯䝞䜲䝘䝸䜢ᢞධ ● Micro Python ○ Python 䛷ᇶᮏⓗ䛻᏶⤖䛩䜛 ○ 䝬䜲䝁䞁䚸䝩䝡䞊⏝㏵ྥ䛡 ○ Python 䝇䜽䝸䝥䝖䜢᭩䛝㎸䜐 ○ REPL 䛷䜲䞁䝍䝷䜽䝔䜱䝤䛻䜒᧯సྍ⬟
  8. 8. 䛧䛛䛧... ● pyboard 䛿⌧ᅾධᡭ୙ྍ⬟ ○ KICKSTARTER 䛾㉎ධศ䛿Ⓨ㏦῭䜏 ○ ḟ䛾䝻䝑䝖䜢⏕⏘䛩䜛䜙䛧䛔䠛 ○ 䛹䛱䜙䛻䛧䛶䜒䛩䛠䛻䛿ධᡭ୙ྍ⬟... ● ண䜑Ⓩ㘓䛧䛶䛒䛳䛯ே䛾ඛ⾜㈍኎䜒... ○ ᡭඖ䛻౑䛘䜛䜹䞊䝗䛜䛺䛟䛶Ỵ῭ኻᩋ ○ Out of stock! orz
  9. 9. ㅉ䜑䜛䛾䛿䜎䛰᪩䛔䟿
  10. 10. ᡭ㍍䛻 Micro Python ● STM32F4 Discovery ○ ST Micro ⣧ṇ䛾 STM32F407 ホ౯䝪䞊䝗 ○ ⛅᭶㟁Ꮚ㏻ၟ䛷 1,750 ෇ ● ᶵ⬟ ○ 192KB RAM ○ 1MB Flash ○ LED x 4 ○ Accelerometer ○ D-class AMP ○ Microphone ○ USB (mini + micro)
  11. 11. STM32F4 Disvoery ‽ഛ ● Micro Python 䝉䝑䝖䜰䝑䝥᪉ἲ ○ https://github. com/micropython/micropython/wiki/Board- STM32F407-Discovery $ cd stmhal $ make BOARD=STM32F4DISC ● 䝣䜯䞊䝮䜴䜵䜰䜢᭩䛝᥮䛘䜛ᚲせ䛜䛒䜛 ○ BOOT0 - Vdd 䜢䝅䝵䞊䝖 ■ ⿬ഃ䛾䝆䝱䞁䝟䜢౑䛖䛸䜘䛔 (JP2, JP3) ○ DFU (dfu-util) 䛷 build/flash.dfu 䜢᭩䛝㎸䜏 ■ microUSB 䛾᪉䜢౑䛖䚹䛯䛰䛧㟁※౪⤥䛥䜜䛺䛔䛾䛷୧᪉่䛩䚹
  12. 12. ᥋⥆䞉᭩䛝㎸䜏 ● USB 䝇䝖䝺䞊䝆䛸䛧䛶ㄆ㆑䛩䜛 ○ boot.py: ㉳ື᫬䛻ᐇ⾜䛥䜜䜛 ○ main.py: 䝯䜲䞁䝥䝻䜾䝷䝮 ○ 䝋䞊䝇 (main.py) 䜢䝁䝢䞊䛩䜛䛰䛡䛷Ⰻ䛔 ○ ⮬ศ䛷స䛳䛯䝰䝆䝳䞊䝹䜒᭩䛝㎸䜏䞉฼⏝䛷䛝䜛 ● REPL 䜢❧䛱ୖ䛢䜛 ○ USB ௬᝿䝅䝸䜰䝹䝫䞊䝖䜒స䜙䜜䜛 ■ Linux 䛾ሙྜ /dev/ttyACM0 ○ ᥋⥆䛩䜛䛸 Micro Python REPL 䝅䜵䝹䛜౑䛘䜛
  13. 13. pyb Module ● pyboard 䜢᧯స䛩䜛䝰䝆䝳䞊䝹 ○ pyb.Pin ○ pyb.LED ○ pyb.Switch ○ pyb.SPI ○ pyb.I2C ○ pyb.UART... ○ http://micropython.org/doc/module/pyb/ ● pyboard ྥ䛡䛰䛜... ○ Discovery 䝪䞊䝗䛷䜒୍㒊䛿฼⏝ྍ⬟
  14. 14. Micro Python REPL ● Python 䛾 REPL 䛸䜋䜌ྠ䛨 ○ 䜲䞁䝍䝷䜽䝔䜱䝤䛻䝬䜲䝁䞁䜢᧯స䛷䛝䜛 ○ 䝕䝞䝑䜾䛻౽฼ ○ 䝰䝆䝳䞊䝹䜢᭩䛝㎸䜣䛷䛚䛡䜀䚸䛭䜜䜒౑䛘䜛 ● Ctrl-D 䛷 soft-reset ○ main.py 䜔䝰䝆䝳䞊䝹䜢᭩䛝᥮䛘䛯᫬䛻౑䛖 ● Ctrl-C 䛷 interrupt ○ main.py 䛾ᐇ⾜䜢Ṇ䜑䜛
  15. 15. LED ON / OFF ● 䛸䜚䛒䛘䛪 L 䝏䜹 led = pyb.LED(1) while True: led.off() pyb.delay(500) led.on() pyb.delay(500) 䛣䜜䛷䜒䜘䛔 led = pyb.LED(1) while True: led.toggle() pyb.delay(500)
  16. 16. Switch ● Switch 䛷 Callback 䛜౑䛘䜛 def toggle(): pyb.LED(1).toggle() pyb.delay(10) sw = pyb.Switch() sw.callback(toggle)
  17. 17. GPIO ● pyb.Pin 䜢౑䛖 pin = pyb.Pin(pyb.Pin.board.PD2, pyb.Pin.OUT_PP) pin.high() pin.low() pin_value = pin.value() pin.value(False) # => pin.low()
  18. 18. STM32F4DISC STAccel ● 䠎✀㢮䛾ຍ㏿ᗘ䝉䞁䝃䞊 ○ 䝪䞊䝗䛾䝻䝑䝖䛻䜘䛳䛶㐪䛖 ○ LIS302DL (ྂ䛔) ○ LIS3DSH (᪂䛧䛔, 㧗ᶵ⬟) ● staccel.py : STAccel # pyb.Accel 䛿 pyboard ᑓ⏝ ○ ᡭ㍍䛻ຍ㏿ᗘ䝉䞁䝃䜢ᢅ䛘䜛䝰䝆䝳䞊䝹 ○ stmhal/boards/STM32F4DISC/staccel.py ○ LIS3DSH ᑐᛂ䝟䝑䝏䜢ᢞ䛢䛶 merge 䛥䜜䛯 ○ https://github.com/micropython/micropython/pull/852
  19. 19. LCD ᕷ㈍䛾 LCD 䜢౑䛖 # pyb.LCD 䛿䚸pyboard ᑓ⏝ ● SC1602 䝅䝸䞊䝈 (ᐃ␒䛾䜰䝺) ○ ⛅᭶㟁Ꮚ㏻ၟ䛷኎䛳䛶䜎䛩 ○ 䝞䝑䜽䝷䜲䝖䛺䛧䛷䛒䜜䜀 500 ෇䛛䜙 ● Python 䛷 LCD 䝗䝷䜲䝞䜢᭩䛔䛶䜏䜎䛧䛯 ○ https://github.com/techno/micropython_modules ○ sc1602.py
  20. 20. 䛔䜝䛔䜝 DEMO
  21. 21. Performance ● (ᙜ䛯䜚๓䛰䛡䛹) ⤖ᵓ㐜䛔 ○ Teensy 3.1 (96MHz ARM) ○ C++ (Arduino like) 䛸䛟䜙䜉䛶䚸⣙ 100 ಸ㐜䛔 ○ https://github. com/micropython/micropython/wiki/Performance ● Arduino 䛷༑ศ䛺⏝㏵䛺䜙ၥ㢟䛻䛺䜙䛺䛔 ○ Arduino Pro Mini (C++) 䛛䜙ẚ䜉䛶4ಸ䛠䜙䛔 ○ 䛫䛳䛛䛟㏿䛔䜽䝻䝑䜽ᩘ䛿↓㥏䛻䛺䜛䛜...
  22. 22. Inline Assembly 䜲䞁䝷䜲䞁䜰䝉䞁䝤䝷䛾౛ @micropython.asm_thumb def asm_add(r0, r1): add(r0, r0, r1)
  23. 23. Development Sprint ● 14᪥ Development Sprint 䜔䜚䜎䛩 ○ http://pyconjp.connpass.com/event/8105/ ● Micro Python Sprint ○ ゐ䛳䛯䛣䛸䛺䛔ே䛷䜒 OK ○ STM32F4 Discovery 䝪䞊䝗䜢ᣢ䛳䛶䛟䜛䛸 Better ● 䜔䜚䛯䛔䛣䛸䛸䛛 ○ 䝪䞊䝗ᦚ㍕䛾D⣭䜰䞁䝥䞉䝬䜲䜽䛾䝗䝷䜲䝞 ○ ௚䛾䝪䞊䝗䜈⛣᳜
  24. 24. ௚䛾䝬䜲䝁䞁䜈䛾⛣᳜ ● GR-SAKURA 䜈⛣᳜䜢ヨ䜏䛯 ○ Renesas RX63N ● 㐍ᤖ ○ 䜲䞁䝍䝥䝸䝍䛿ື䛔䛯 ○ print 䛿䛷䛝䜛 ○ 䜎䛰: pyb 䝰䝆䝳䞊䝹 ○ 䜎䛰: REPL ⤖ㄽ: 䜎䛰STM32௨እ䛻⛣᳜䛩䜛䛾䛿኱ኚ䛭䛖 ⯆࿡䛜䛒䛳䛯䜙 Sprint or Office hour 䛷...
  25. 25. 䜎䛸䜑 ● Micro Python 䛺䛛䛺䛛䜘䛥䛭䛖 ○ 䛯䛰䛧䚸䜎䛰䜎䛰ᨵၿ䛾వᆅ䛜䛒䜚䛭䛖 ○ ௚䛾䝪䞊䝗䜈䛾⛣᳜䛻ᮇᚅ ● Raspberry Pi ౑䛳䛯䜋䛖䛜Ⰻ䛥䛭䛖䛺⏝㏵ ○ 䝛䝑䝖䝽䞊䜽 ○ Wi-Fi, Bluetooth ○ USB… 䝪䞊䝗䛰䛡䛷᏶⤖䛩䜛䛺䜙 Micro Python䟿

×