Raspberry Pi で Arduino UNO とシリアル通信をする

Raspberry Pi の赤外線リモコンがうまく動かなくなり、別の方法をいろいろ試している。

ふと Arduino UNO が押し入れに眠っていることを気付き、それで作ってみることにした。とりあえず、コマンドラインで Arduino にプログラムを書き込む段階までの方法をメモ。

操作はすべて Raspberry Pi と SSH 接続した Mac から行う。

環境:Raspberry Pi 3 Model B(Raspbian Jessie)、Mac、Arduino UNO

(1)Raspberry Pi の /boot/config.txt を編集し、末尾に以下の行を追加する。

dtoverlay=pi3-miniuart-bt

(2)Raspberry Pi の /boot/cmdline.txt を以下のように変更する。

変更前:dwc_otg.lpm_enable=0 console=serial0,115200 console=tty1 root=/dev/mmcblk0p2 rootfstype=ext4 elevator=deadline fsck.repair=yes rootwait quiet splash plymouth.ignore-serial-consoles
変更後:dwc_otg.lpm_enable=0 console=tty1 console=serial0,115200 root=/dev/mmcblk0p2 rootfstype=ext4 elevator=deadline fsck.repair=yes rootwait

(3)Raspberry Pi を再起動。

(4)Arduino を Raspberry Pi に USB 接続する。

参考:
Raspberry Pi3とArduino Unoのシリアル通信 – Qiita
https://qiita.com/yumatsud/items/03281b32d49dfe9e59fd

(5)パッケージ情報を最新にする。

$ sudo apt-get update

(6)Arduino パッケージをインストールする。

$ sudo apt-get install arduino

(7)ino をインストールする。

$ sudo pip install ino

(8)適当なディレクトリを作成し、そこへ移動。

$ mkdir arduino-light
$ cd arduino-light

(9)プロジェクトを作成する。

$ ino init

lib と src というディレクトリができる。

(10)src/sketch.ino を編集し、Arduino のプログラムを書く。保存。

$ sudo nano src/sketch.ino

(11)コンパイルする。

$ ino build

(12)Arduino へ書き込む。

$ ino upload

(13)シリアル通信をするため、picocom をインストールする。

$ sudo apt-get install picocom

Linking Arduino to the Raspberry Pi – Raspberry Pi Pod
http://www.recantha.co.uk/blog/?p=1103

(14)以下のコマンドでシリアル通信には入れる。

$ ino serial

終了するには、Ctrl+s、Ctrl+x 。

実際に Arduino のプログラムを動かす段階までは試していない。

参考:
橋本商会 » ino使うとCUIでArduinoをビルドできて便利
http://shokai.org/blog/archives/7454

Raspberry Pi で Arduino の F/W を書き換える – もみあげあしめ
http://shima-nigoro.hatenablog.jp/entry/2016/12/25/113000

その他関連サイト:
Ed’s Blog: Uploading Arduino sketch from Raspberry Pi (command line)
http://pblog.ebaker.me.uk/2014/01/uploading-arduino-sketch-from-raspberry.html

RaspberryPiとArduinoを連携する【USBシリアル編】 – uepon日々の備忘録
http://uepon.hatenadiary.com/entry/2017/01/01/141220

Arduino + Raspberry Pi をUSBでシリアル通信して温度湿度センサーのデータを取得してみる – まえちゃんろぐ
https://blog.seiyamaeda.com/7592

赤外線リモコンを作る | Make.
http://make.bcde.jp/arduino/赤外線リモコンを作る/