3
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Raspberry Pi 4とmicro:bitをシリアルで繋ぐ

Posted at

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側のサンプル

microbit.png

結果

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
3
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?