0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

ラズパイ→Arduinoへ基本連係方法

0
Last updated at Posted at 2026-03-25

ラズパイとArduinoを接続し、ラズパイからの情報をArduinoが読み、Arduinoが挙動する実験を行った。
単にLEDを点滅させているだけですが、ラズパイ Zero → Arduino に文字を送り、Arduino が LED を点滅させる という、最小構成の例をまとめます。

環境

HW/SW バージョン他
筐体 Arduino Uno R3 互換機
筐体 Rasberry zero
IDE Arduino IDE 2.3.7
部品 ジャンパーワイアー(メス-オス)×4

注意
ラズパイ→Arduinoへの回路を組んだ状態で、Arduinoへ書き込もうとすると失敗するので、Arduinoへのプログラムを書き込み後に回路を組んでください。

上記、注意より、本記事では、プログラム→回路の順で記載します。

プログラムソース(ラズパイ)

ラズパイ→Arduinoに、1を送信

to_arduino.py
import serial
import time

ser = serial.Serial('/dev/serial0', 9600)

while True:
    ser.write(b'1')
    time.sleep(1)

プログラムソース(Arduino)

受信したら、内臓LED点灯

from_pi.ico
int led = 13;

void setup() {
  pinMode(led, OUTPUT);
  Serial.begin(9600);
}

void loop() {
  if (Serial.available()) {
    char c = Serial.read();
    if (c == '1') {
      digitalWrite(led, HIGH);
      delay(500);
      digitalWrite(led, LOW);
      delay(500);
    }
  }
}

回路

テキスト回路図(RasberryPi Zero → Arduino)

RasberryPi Zero               Arduino
----------------------        -------------------
GPIO14(TXD) 物理ピン8 -------> D0(RX)
GPIO15(RXD) 物理ピン10 ------> D1(TX)
GND 物理ピン6 ---------------> GND
5V 物理ピン2 ----------------> 5V

5Vピンを利用して、ラズパイ→Arduinoで電源供給を行っています。
こちらをなくして、それぞれ個別に電源供給しても問題ないです。

実行結果

・実行すると、Arduinoの内臓LEDが、0.5秒ごとに点灯

実行結果

pi@pi32lite2:~/gpio $ python to_arduino.py

最後に

今回は、ラズパイ→Arduinoの片方向通信の実験でしたが、
次回はラズパイ↔Arduinoの双方向通信などできればと思います。

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?