2014年12月28日

なのぼ〜どに Arduino スケッチを書き込む

 大掃除(+床のワックスかけ)終了、年賀状終了。少し時間ができたので、久しぶりになのぼ〜どをいじってみる。なのぼ〜どに Arduino スケッチを書き込める、という話を見かけたので、やってみた。まずは、現状復帰ができるようにする。

 使ったのは、Mac OS 10.6 上の Arduino 1.0.6。ちゃんとうまくいきましたよ。

  • cd /Applications/Arduino.app/Contents/Resources/Java/hardware/arduino/bootloaders/optiboot
  • Makefileを以下のように変更。

    --- Makefile.orig 2014-09-16 16:11:12.000000000 +0900 +++ Makefile 2014-12-28 23:20:58.000000000 +0900 @@ -393,6 +393,29 @@ atmega328_pro8_isp: EFUSE = 05 atmega328_pro8_isp: isp +# ATmega8-8m +# Ref: http://tiisai.dip.jp/?p=1413 +# +atmega8-8m: TARGET = atmega8 +atmega8-8m: MCU_TARGET = atmega8 +atmega8-8m: CFLAGS += '-DLED_START_FLASHES=3' '-DBAUD_RATE=115200' +atmega8-8m: AVR_FREQ = 8000000L +atmega8-8m: LDSECTIONS = -Wl,--section-start=.text=0x1e00 -Wl,--section-start=.version=0x1ffe +atmega8-8m: $(PROGRAM)_atmega8-8m.hex +atmega8-8m: $(PROGRAM)_atmega8-8m.lst + +atmega8-8m_isp: atmega8-8m +atmega8-8m_isp: TARGET = atmega8-8m +atmega-8m8_isp: MCU_TARGET = atmega8 +# SPIEN, CKOPT, Bootsize=512B +atmega8-8m_isp: HFUSE = DC +# 2.7V brownout, Internal 8MHz osc (8MHz) +atmega8-8m_isp: LFUSE = 94 +atmega8-8m_isp: isp + +### + + # 1MHz clocked platforms # # These are capable of 9600 baud

  • sh omake atmega8-8m
    optiboot_atmega8-8m.hex が作成される。これは内蔵 8MHz クロックを使った ATMega8 用のブートローダ。
  • cd ../../variants
    ハードウェアの違いを設定するためのディレクトリ。
  • cp -r standard RCduino
  • RCduino/pins_arduino.h に以下のように追記。

    --- ../standard/pins_arduino.h 2014-09-16 16:11:14.000000000 +0900 +++ pins_arduino.h 2014-12-28 22:50:40.000000000 +0900 @@ -131,6 +131,9 @@ (uint16_t) &PIND, }; +/* Modified for using PB6/PB7 as digital port 20/21 */ +/* Ref. http://morecatlab.akiba.coocan.jp/lab/index.php/aruino/rcduino/ */ +/* By Yoshitaka Kuwata */ const uint8_t PROGMEM digital_pin_to_port_PGM[] = { PD, /* 0 */ PD, @@ -152,6 +155,8 @@ PC, PC, PC, + PB, /* 20 */ + PB, /* 21 */ }; const uint8_t PROGMEM digital_pin_to_bit_mask_PGM[] = { @@ -175,6 +180,8 @@ _BV(3), _BV(4), _BV(5), + _BV(6), /* 20 port B */ + _BV(7), /* 21 port B */ }; const uint8_t PROGMEM digital_pin_to_timer_PGM[] = { @@ -213,6 +220,8 @@ NOT_ON_TIMER, NOT_ON_TIMER, NOT_ON_TIMER, + NOT_ON_TIMER, /* 20 */ + NOT_ON_TIMER, /* 21 */ }; #endif

  • cd .. arduino ディレクトリに戻ります。
  • boards.txt に以下のように追記。

    --- boards.orig.txt 2014-09-16 16:11:12.000000000 +0900 +++ boards.txt 2014-12-28 22:52:55.000000000 +0900 @@ -565,3 +565,21 @@ robotMotor.build.core=robot robotMotor.build.variant=robot_motor +############################################################## +# Ref. http://chum-up.blogspot.jp/2012/07/arduino-100-nanoboardag2.html +############################################################## +atmega8o8.name=[Optiboot] ATmega8 8MHz +atmega8o8.upload.protocol=arduino +atmega8o8.upload.maximum_size=7680 +atmega8o8.upload.speed=115200 +atmega8o8.bootloader.low_fuses=0x94 +atmega8o8.bootloader.high_fuses=0xDC +atmega8o8.bootloader.path=optiboot +atmega8o8.bootloader.file=optiboot_atmega8-8m.hex +atmega8o8.bootloader.unlock_bits=0x3F +atmega8o8.bootloader.lock_bits=0x0F +atmega8o8.build.mcu=atmega8 +atmega8o8.build.f_cpu=8000000L +atmega8o8.build.core=arduino +atmega8o8.build.variant=RCduino +##############################################################

  • Prolific のウェブサイトから PL2303 Mac OS X ドライバをダウンロード、インストールする(URL は変わるかも知れませんので自力で探してください)。
  • 超音波距離センサーを使ってみる ページにある「NewPing をなのぼ〜どの ATMega8 用に修正」したものをダウンロードしておく。

 これで準備完了。実際にスケッチをアップロードする手順は、下の通り。

  • ちっちゃいものくらぶさんの「最新ファームウェアの Arduino スケッチ」(NanoBoardAGWithMotorTrio_diag_sonerm4.ino) を上の Arduino IDE 1.0.6 で開く。
  • 「スケッチ」→「ライブラリを使用」→「Add Library...」で、修正された NewPing.zip を追加しておく。
  • なのぼ〜ど AG を USB ケーブルで接続する。
  • 「マイコンボード」を "[Optiboot] ATMega8 8MHz"、「シリアルポート」を "/dev/tty.usbserial" にする。
  • 「検証」、「マイコンボードに書き込む」。

 実はここに至るまでに、エラーが出たり Arduino IDE が OS を巻き込んでフリーズしたり、いろいろありました。上の参考ページを全部読んでからやったのに、ですよ。ちょっと苦労することを想定して取りかかった方が、精神衛生上よろしいかと思います。(えっ、苦労したのは僕だけ?)

 これでなのぼ〜どが「2系統のモータドライバ付き Arduino」というおいしい基板として使えるようになった(はず)。さあ、自律型マイコンカーへの応用がうまくいくかどうか。

タグ:工作
Posted at 2014年12月28日 18:49:29
email.png