4
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.

micro:bitのコンパイル環境をArduino IDEで構築する

Posted at

■micro:bit購入のきっかけ

2020年のお正月、実家のある大阪に帰省した際、日本橋の共立電子で「micro:bit」を購入したことがきっかけです。

何年か前から名前だけは聞いたことがあって、『おもちゃ』と思って購入することはなかったのですが、子供が5歳になり『こういうおもちゃに興味をもってくれたらな~』と思うようになり、micro:bitを購入しました。

■Arduino IDEを選択したわけ

じゃあ、なぜ開発環境はArduinoなの?
micro:bitの開発環境なら、下記のようなものがあるじゃないか?
オフラインで開発できるMuエディターというのもあるのですが、それは少し置いておいて...

開発環境 URL
Microsoft MakeCode https://makecode.microbit.org/#
Pythonエディター https://python.microbit.org/v/2.0

image.png
その通りなのですが、Web経由で開発する必要があるのが面倒くさい。
正直、仕事でArduinoを使う機会が多いのと、自宅にArduinoUnoがあるのに未だ開封すらしていないので、この機会にArduinoも弄ろうと思ったのがArduino IDEを選択した一番の動機です。

■手順

1.Arduino IDEを以下の場所からDLする。
https://www.arduino.cc/

2.ボードマネージャーの追加
Arduino IDEでMicro:bitを使えるようにするため、ボードマネージャにMicro:bitのURLを追加する。
[ファイル]→[開発環境]を選択し、下記URLを設定する。
https://sandeepmistry.github.io/arduino-nRF5/package_nRF5_boards_index.json
image.png
※上記URLは、ここに記載されています。

3.ボードマネージャーからnFR5をインストール
nRF5をインストールした後、「BBC micro:bit」を選択する。
image.png
image.png
image.png
S110を選択
image.png

4.サンプルプログラムの書き込み

const int buttonA = 5; // the number of the pushbutton pin
const int buttonB = 11; // the number of the pushbutton pin

void setup() {
  Serial.begin(9600);
  Serial.println("microbit is ready!");
  
  pinMode(buttonA, INPUT);
  pinMode(buttonB, INPUT);
}

void loop(){
  if (! digitalRead(buttonA)) {
    Serial.println("Button A pressed");
  }
  if (! digitalRead(buttonB)) {
    Serial.println("Button B pressed");
  }
  delay(500);
}

AボタンまたはBボタンを押下したら、シリアルに押された事をプリントアウトするプログラム。
[ツール]→[シリアルモニタ]で、シリアル出力を確認するウィンドウを表示し、以下の通り表示されていればOK。
image.png

4
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
4
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?