kuroの覚え書き

96の個人的覚え書き

Arduino クローン



ま、Arduinoなんて3000円程度なんで製作ごとに完成基板で使えばいいんだけど、結構大きいのが難点。だからこそLilyPad arduinoなど小型の物も作られていたりはするわけだが。

今回秋月電子で買い物するついでがあったので最近売り出されたAVR atmega168pを買ってみた。

http://arms22.blog91.fc2.com/blog-entry-219.html

こちらのエントリーを参考にArduinoブートローダーを書き込んでやろうというわけだ。

実際にやってみる。

http://www.arduino.cc/playground/uploads/Code/programmer2.txt

これをダウンロードし、ARDUINO-0016でDuemilanoveを書き換えてやる。

ブレッドボードでDuemilanoveとatmega168pを接続し、シリアルモニタを起動し"*s"と打ち込んでみると

SIGNATURES1e,94,06,ff,

と出ればちゃんと接続されているということなんだが、

SIGNATURES1e,94,0b,ff,

となる。

やっぱりというかatmega168とatmega168pは別物なんだな。

仕方が無いのでFTDI BitBang Modeというのを試してみる

http://www.geocities.jp/arduino_diecimila/bootloader/index.html

最初

http://www15.atwiki.jp/arduino/pages/23.html

こちらを参考にOSX環境でなんとかしようと思い、D2XXドライバを導入するところまではうまくいった。

serjtag-0.3 + avrdude-5.3.1のビルドを行い、コマンドを入れてみるも、これもまたエラーが出てうまくいかない。

というか上記のページではなんだかtiny2313に書き込みを行っているような?

kkuro-mac-mini:~/mac_bitbang/avrdude-5.3.1 kkuro$ avrdude -C avrdude.conf -c diecimila -p m168p -vv -B 4800

とやると


avrdude: Version 5.3.1.osxintelhack, compiled on Feb 2 2007 at 03:18:01
Copyright (c) 2000-2005 Brian Dean, http://www.bdmicro.com/

System wide configuration file is "./avrdude.conf"
error at ./avrdude.conf:364 unrecognized character: "s"

こんな感じで、364行目を見てもとくにおかしなところはないし。

いろいろ探していてこんな情報を発見。

http://www.geocities.jp/arduino_diecimila/bootloader/index.html#mega8_328

m168pに対応したavrdude.confだそうで。

これを早速コピーしてディレクトリに配置。結果は同じ。

結局諦めてWindowsで作業することにした。とほほ。

Mac上のVirtualPCで操作するため、Arduino IDEのドライバを一旦止めなければならない。

sudo kextunload /System/Library/Extensions/FTDIUSBSerialDriver.kext


C:\serjtag-0.3\avrdude-serjtag\binary>avrdude -c diecimila -P ft0 -p m168p -t -B 4800
avrdude: BitBang OK
avrdude: pin assign miso 3 sck 5 mosi 6 reset 7
avrdude: drain OK
ft245r: bitclk 4800 -> ft baud 2400
avrdude: AVR device initialized and ready to accept instructions
Reading | ################################################## | 100% 0.00s
avrdude: Device signature = 0x1e9406

avrdude> erase
>>> erase
avrdude: erasing chip
ft245r: bitclk 4800 -> ft baud 2400

avrdude> w efuse 0 0x00
>>> w efuse 0 0x00

avrdude> w hfuse 0 0xdd
>>> w hfuse 0 0xdd

avrdude> w lfuse 0 0xff
>>> w lfuse 0 0xff

avrdude> quit


C:\serjtag-0.3\avrdude-serjtag\binary> avrdude -c diecimila -P ft0 -p m168p -U flash:w:ATmegaBOOT_168_diecimila.hex
avrdude: BitBang OK
avrdude: pin assign miso 3 sck 5 mosi 6 reset 7
avrdude: drain OK
ft245r: bitclk 230400 -> ft baud 115200
avrdude: AVR device initialized and ready to accept instructions
Reading | ################################################## | 100% 0.02s
avrdude: Device signature = 0x1e9406
avrdude: NOTE: FLASH memory has been specified, an erase cycle will be performed
To disable this feature, specify the -D option.
avrdude: erasing chip
ft245r: bitclk 230400 -> ft baud 115200
avrdude: reading input file "ATmegaBOOT_168_diecimila.hex"
avrdude: input file ATmegaBOOT_168_diecimila.hex auto detected as Intel Hex
avrdude: writing flash (16154 bytes):

Writing | ################################################## | 100% 145.75s

avrdude: 16154 bytes of flash written
avrdude: verifying flash memory against ATmegaBOOT_168_diecimila.hex:
avrdude: load data flash data from input file ATmegaBOOT_168_diecimila.hex:
avrdude: input file ATmegaBOOT_168_diecimila.hex auto detected as Intel Hex
avrdude: input file ATmegaBOOT_168_diecimila.hex contains 16154 bytes
avrdude: reading on-chip flash data:

Reading | ################################################## | 100% 236.05s

avrdude: verifying ...
avrdude: 16154 bytes of flash verified
avrdude: safemode: Fuses OK

avrdude done. Thank you.

C:\serjtag-0.3\avrdude-serjtag\binary>

C:\serjtag-0.3\avrdude-serjtag\binary>avrdude -c diecimila -P ft0 -p m168p -t
avrdude: BitBang OK
avrdude: pin assign miso 3 sck 5 mosi 6 reset 7
avrdude: drain OK
ft245r: bitclk 230400 -> ft baud 115200
avrdude: AVR device initialized and ready to accept instructions
Reading | ################################################## | 100% 0.00s
avrdude: Device signature = 0x1e9406
avrdude> w lock 0 0x0f
>>> w lock 0 0x0f

avrdude> quit

VirtualPCだと書き込みには結構時間がかかる。

終わったら

sudo kextload /System/Library/Extensions/FTDIUSBSerialDriver.kext

でドライバを戻しておく。