MicroPythonに
手出してみないか?
でじぽろ #13
自己紹介
札幌駅北口前のとあるソフトウェア会社のソ
フトウェアエンジニア
昨年から業務でPython使い出す
Python Boot Camp in 札幌に参加
PyCon mini hiroshima のスライド眺めていて
、MicroPythonネタにはまりこむ
MicroPython
マイコン用に再実装したPython、OS要らず
CPythonよりも小さく、効率がよい
言語としてはPython3.4とほぼ互換
軽量pythonとして組込みLinux上でも使われ
ていたりする(OpenWrtなど)
https://micropython.org/
Lチカ
from machine import Pin
from time import sleep_ms
led = Pin(0, Pin.OUT)
while True:
led.value(1)
sleep_ms(500)
led.value(0)
sleep_ms(500)
MicroPython に手出してみないか?
鮨を廻す
from machine import *
from ssd1306 import *
import time
class RollingSushi:
icon = [
[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],
[0,0,0,0,0,0,0,0,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],
[0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],
[0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],
[0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],
[0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],
[0,0,0,1,1,1,1,1,1,1,1,1,1,0,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0],
[0,0,1,1,1,1,1,1,1,1,1,1,1,0,1,1,1,1,1,1,1,0,1,1,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1,1,1,1,0,0,1,0,0],
[0,0,0,0,0,0,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,1,1,0,0],
[0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,0,0,0,0,0,0,0,1,1,1,1,1,0,0,1,1,1,1,1,0,0,0,1,0,0,0],
[0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,0,0,1,1,0,0,1,1,0,0,0,0,0,0,0,1,1,0,0,0,0,1,0,0,0],
[0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,0,1,1,1,1,0,0,0,0,1,1,1,0,0,1,1,0,0,0,1,1,0,0,0],
[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,0,0,1,1,1,1,1,0,1,0,0,0,1,1,0,0,0,0],
[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,0,0,1,1,1,1,0,0,0,0,0,1,1,0,0,0,0,0],
[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,0,0,0,1,0,1,1,0,0,0,0,0,0],
[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,0,1,1,1,1,0,0,0,0,0,0,0],
[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,0,0,0,0,0,0,0,0],
[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],
]
def __init__(self):
self.i2c = I2C(sda=Pin(25),scl=Pin(26))
self.lcd = SSD1306_I2C(128, 64, self.i2c)
self.x0 = 0
self.y0 = 0
self.xlen = len(RollingSushi.icon[0])
self.ylen = len(RollingSushi.icon)
self.xmax = 128 - self.xlen
self.ymax = 64 - self.ylen
self.direction = 0
self.lcd.init_display()
self.lcd.show()
def __init__(self):
self.i2c = I2C(sda=Pin(25),scl=Pin(26))
self.lcd = SSD1306_I2C(128, 64, self.i2c)
self.x0 = 0
self.y0 = 0
self.xlen = len(RollingSushi.icon[0])
self.ylen = len(RollingSushi.icon)
self.xmax = 128 - self.xlen
self.ymax = 64 - self.ylen
self.direction = 0
self.lcd.init_display()
self.lcd.show()
def draw_image(self):
for y in range(self.ylen):
for x in range(self.xlen):
self.lcd.pixel(self.x0+x,self.y0+y,RollingSushi.icon[y][x])
self.lcd.show()
if self.direction == 0:
for y in range(self.ylen):
self.lcd.pixel(self.x0, self.y0+y,0)
if self.x0 >= self.xmax:
self.direction = 1
else:
self.x0 += 1
elif self.direction == 1:
for x in range(self.xlen):
self.lcd.pixel(self.x0+x, self.y0,0)
if self.y0 >= self.ymax:
self.direction = 2
else:
self.y0 += 1
elif self.direction == 2:
for y in range(self.ylen):
self.lcd.pixel(self.x0+x+self.xlen-1, self.y0+y,0)
if self.x0 <= 0:
self.direction = 3
else:
self.x0 -= 1
else:
for x in range(self.xlen):
self.lcd.pixel(self.x0+x, self.y0+self.ylen-1,0)
if self.y0 <= 0:
self.direction = 0
else:
self.y0 -= 1
sushi = RollingSushi()
while True:
sushi.draw_image()
MicroPython に手出してみないか?
どんなもので動く?
pyboard
STM32F4 Discovery
ESP8266 (ESP-WROOM-02)
ESP32 (ESP-WROOM-32)
Teensy
ARDUINO M0
wipy
どれも、ちょっと敷居が高いな
ラズパイで普通のPython動かすのでよくね?
MicroPython に手出してみないか?
chibi:bit
英国で100万台を小学校高学年に無料配布した micro:bit
の互換機
スイッチサイエンスから3,456円で販売
Cortex-M0、256KB Flash ROM、16KB RAM
5x5マトリクスLED、ボタンx2、
加速度センサ、コンパスセンサー、BLE
開発環境はWebブラウザ上で使える
ファームウェアのインストールとか小難しいこと不要
コレ!
http://microbit.org
MicroPython に手出してみないか?
GPIOもそれなりに
muエディタ
Jupyter
まとめ
MicroPythonはマイコン向けにPython3を再実
装したもの
組込み開発の経験がないなら micro:bit からは
じめるのが一番やさしい
組込み開発の経験があるならESP8266が低価
格で入手しやすい
質問などは懇親会、「Python 札幌」 Slack で
http://python-sapporo.github.io/

More Related Content

PDF
C++のライブラリを簡単に眺めてみよう
PPTX
C#/Java & Linux で始める ET ロボコン(leJOS編)
PDF
Boost.勉強会 #21 札幌「C++1zにstring_viewが導入されてうれしいので紹介します」
PDF
関数の最小値を求めることから機械学習へ
PDF
ヒューマンコンピュテーションのための専門家発見(ステアラボ人工知能シンポジウム2017)
PDF
自然言語処理分野の最前線(ステアラボ人工知能シンポジウム2017)
PDF
How to make GAE adapt the Great Firewall
PDF
JSON Schema in Web Frontend #insideFE
C++のライブラリを簡単に眺めてみよう
C#/Java & Linux で始める ET ロボコン(leJOS編)
Boost.勉強会 #21 札幌「C++1zにstring_viewが導入されてうれしいので紹介します」
関数の最小値を求めることから機械学習へ
ヒューマンコンピュテーションのための専門家発見(ステアラボ人工知能シンポジウム2017)
自然言語処理分野の最前線(ステアラボ人工知能シンポジウム2017)
How to make GAE adapt the Great Firewall
JSON Schema in Web Frontend #insideFE
Ad

MicroPython に手出してみないか?