RaspberryPi側の準備
Pythonのシリアルパッケージをインストール
$ pip install pyserial
以前使っていたラズパイだとインストールが必要でしたが、今回はインストールしなくてもserialが使えました。
何かをインストールした時に入っていたのかも。
サンプルプログラムの作成
import serial
import time
ser = serial.Serial('/dev/ttyACM0', 115200)
while True:
String_data = ser.readline()
print(String_data.decode())
time.sleep(0.5)
ser.close()
micro:bit側のサンプル
結果
micro:bitで取得したセンサ情報をRaspberry Piで無事受け取れました。
$ python3 sample1.py
direction:295
accel x:16
accel y:16
accel z:-1024
accel abs:1009
brightness:39
temperature:25
direction:295
temperature:25
direction:296
accel x:32
accel y:32
accel z:-1008