ArduinoとFon

ArduinoとLa Fonera(FON2201)をつなぐ。

ふたを開ける。

星形ドライバ。macbookのHDD交換の時につかったやつ(T8)でOK。
本体裏側のゴムの後ろに隠れているのを2個外せば簡単に開く。

電源

FON2201に付属のACアダプタは7.5V 1A。ルータ本体の表示も7.5V 1A。

シリアルコンソール

(直接digital0,digital1につなぐ方法のほうがよいかもしれない→このページの下の方参照)


FON2201の4ピンはLANコネクタ側から順番に「NC,Tx,Rx,GND」だそうで、
Txとdigital2、Rxとdigital3、GNDとGNDをつなぐ。

availableが使えるSoftwareSerialを使って、
http://arduiniana.org/libraries/NewSoftSerial/
/* FON */
#include <NewSoftSerial.h>

#define rxPin 2
#define txPin 3
#define ledPin 13
NewSoftSerial mySerial(rxPin, txPin);

void setup()
{
 pinMode(ledPin, OUTPUT);
 pinMode(rxPin, INPUT);
 pinMode(txPin, OUTPUT);
 Serial.begin(9600);
 mySerial.begin(9600);
}

void loop()
{
 if(mySerial.available()){
   Serial.print((char)mySerial.read());
 }
 if(Serial.available()){
   mySerial.print((char)Serial.read());
 }
}
このスケッチを動かして、
screen /dev/tty.usbserial*
で、FON2201の電源を入れると、
+Ethernet eth0: MAC address 00:18:84:a4:36:d0
IP: 192.168.1.1/255.255.255.0, Gateway: 0.0.0.0
Default server: 192.168.1.254

RedBoot(tm) bootstrap and debug environment [ROMRAM]
OpenWrt certified release, version 1.1 - built 22:32:28, May  7 2007

Copyright (C) 2000, 2001, 2002, 2003, 2004 Red Hat, Inc.

Board: FON 2201 
RAM: 0x80000000-0x81000000, [0x80040290-0x80e1000]availble
LASH 0xa800000  0xa8f0000,128 bocks o 0x0010000bytes ach.
                                                         == Eecutig boo scrip in 2000 seonds  ente ^C toabot
RedBoot> fis load -b 0x80100000 loader
RedBoot>  go 0x80100000
Failsafe loader v0.2

Looking for board config data... found at offset 0xa87f0000
Reset button GPIO: 6
Reading flash from 0xa8040000 to 0xa825c4e9... done.
Verifying CRC... OK - 0x7fd5bb48
Uncompressing Linux... Ok, booting the kernel.
[sighandler]: No more events to be processed, quitting.
[cleanup]: Waiting for children.
[cleanup]: All children terminated.
Unlocking rootfs ...
Could not open mtd device: rootfs
switching to jffs2
init started:  BusyBox v1.4.1 (2007-09-26 18:40:28 CEST) multi-call binary
: ifconfig: SIOCSIFADDR: No such device

: ifconfig: SIOCSIFADDR: No such device

: udhcpc (v1.4.1) started

: route: fscanf

: Sending discover...

: Sending discover...

なんかブートしてる。

OpenWRTかDD-WRTか

なにが違うのかよくわからないが、DD-WRTのほうが情報が多そうなのでDD-WRT。

macでFON2201にdd-wrtをインストール

FONまとめwikiのDD-WRTのページ( http://fon-wiki.maniado.com/index.php?DD-WRT )を参考に進める。


インストール作業時は、
FON2201のWANポートとmacをLANケーブルで直接接続し、
macの有線LANを固定で192.168.1.11/255.255.255.0、FON2201を192.168.1.22/255.255.255.0に設定している。

(mac)
cd ~/tmp
mkdir ddwrt
cd ddwrt
wget http://www.dd-wrt.com/dd-wrtv2/downloads/stable/dd-wrt.v24%20SP1/Consumer/Fon/Fonera/fonera-firmware.bin
wget http://www.dd-wrt.com/dd-wrtv2/downloads/stable/dd-wrt.v24%20SP1/Consumer/Fon/Fonera/fonera_flashing.txt
wget http://www.dd-wrt.com/dd-wrtv2/downloads/stable/dd-wrt.v24%20SP1/Consumer/Fon/Fonera/linux.bin
sudo /sbin/service tftp start
sudo cp linux.bin /private/tftpboot/

(シリアルコンソールでRedBoot起動直後にCtrl-C)
ip_address -l 192.168.1.22/24 -h 192.168.1.11
fis init
load -r -v -b 0x80041000 linux.bin

(mac)
sudo /sbin/service tftp stop
sudo rm /private/tftpboot/linux.bin

(シリアルコンソール)
RedBoot> fis create linux ←30分かかる
RedBoot> fconfig
Run script at boot: true
Boot script: 
.. fis load -b 0x80100000 loader
..  go 0x80100000
Enter script, terminate with empty line
>> fis load -l linux (←ここ入力)
>> exec              (←ここ入力)
>>                   (←ここ入力)
Boot script timeout (1000ms resolution): 2
Use BOOTP for network configuration: false
Gateway IP address: 
Local IP address: 192.168.1.1
Local IP address mask: 255.255.255.0
Default server IP address: 192.168.1.254
Console baud rate: 9600
GDB connection port: 9000
Force console for special debug messages: false
Network debug at boot time: false
Update RedBoot non-volatile configuration - continue (y/n)? y (←ここ入力)
... Erase from 0xa87e0000-0xa87f0000: .
... Program from 0x80ff0000-0x81000000 at 0xa87e0000: .
RedBoot> reset

FON2201がリブートした後、http://192.168.1.1/を開けば管理画面が出る。

9600bps

stty -F /dev/tts/0 9600
「管理→コマンド実行」からコマンド入力すればコンソールが9600bpsになってなんとか使えるようになる。
が、ちょっと文字化けする。

DuemilanoveのUSBシリアルで直接通信する

DD-WRT本体のコンソールの通信速度が115200なので上のスケッチ経由だと文字化けする。

なにもしないスケッチを動作させておいて、
Txとdigital1、Rxとdigital0、GNDとGNDをつないで
screen /dev/tty.usbserial* 115200
とすればOK.

FON2201を無線クライアントにする

FON2201には普通の無線LANクライアントになってもらいたい。
もともとある家のルータ(親ルータ)を経由して家庭内LAN、インターネットに接続する。

基本→基本
インターネット接続 手動 or DHCP ...
LAN側接続→IPアドレス 他とかぶらないように
(固定にするなり、親ルータ側で固定なDHCPで振るなり・・・)

無線LAN→基本
Regulatory Domain JAPAN
無線LAN MAC動作モード Client
ネットワーク名 (SSID) 親ルータのSSID

無線LAN→無線LANセキュリティ
自分の設定に。

セキュリティ→Firewall保護
SPI Firewall 無効


ArduinoとFON2201でシリアル通信

DDWRTがログインプロンプトを出すし、動作状態のログ的なものが出てくる。
これらをOFFにしてArduinoとのやりとり専用にしたい。

http://www.geocities.jp/arduino_diecimila/wifi/index.html
ログインプロンプトからDDWRTにログインし、telnetしている。
管理画面でボタンをおしたりしない限り余計な出力は無いのかも?

http://blog.xole.net/article.php?id=689
ruby入れられるかなあ。

http://www.dd-wrt.com/wiki/index.php/Ipkg
以外に簡単に入るかもしれない。

ipkg


jffs


flash領域にデータを保存するファイルシステム。
flashなのであまりたくさん書き換えると壊れちゃう?
(SDカード増設する方法もあるみたい。 http://www.dd-wrt.com/wiki/index.php/LaFonera_Hardware_SD-Card

とりあえず、内蔵flashで試す。

管理→管理の「JFFS2 の設定」で、
1. 「JFFS2」を「有効」(「JFFS2の保存領域を初期化」は無効のまま)
2. 設定(保存のみ) を押す。
3. 設定 を押す。
4. 「JFFS2の保存領域を初期化」を「有効」
5. 設定 を押す。領域がフォーマットされる。設定(保存のみ)は押さない!
6. 「JFFS2の保存領域を初期化」を「無効」
7. 設定(保存のみ) を押す。
8. 再起動 を押す。

(前)
root@DD-WRT:~# df -h
Filesystem                Size      Used Available Use% Mounted on
rootfs                    5.4M      5.4M         0 100% /
/dev/root                 5.4M      5.4M         0 100% /

(後)
root@DD-WRT:~# df -h
Filesystem                Size      Used Available Use% Mounted on
rootfs                    5.4M      5.4M         0 100% /
/dev/root                 5.4M      5.4M         0 100% /
/dev/mtdblock/3           1.4M    196.0k      1.2M  13% /jffs

これで/jffs以下に書き込み可能になった。

rubyのパッケージ


まずは練習でram(/tmp)にインストールしてみる。
cd /tmp
wget http://downloads.openwrt.org/kamikaze/8.09/atheros/packages/ruby_1.8.6-p36-1_mips.ipk
ipkg -d ram install ruby_1.8.6-p36-1_mips.ipk
rm ruby_1.8.6-p36-1_mips.ipk
wget http://downloads.openwrt.org/kamikaze/8.09/atheros/packages/ruby-core_1.8.6-p36-1_mips.ipk
ipkg -d ram install ruby-core_1.8.6-p36-1_mips.ipk
rm ruby-core_1.8.6-p36-1_mips.ipk
wget http://downloads.openwrt.org/kamikaze/8.09/atheros/packages/libruby_1.8.6-p36-1_mips.ipk
ipkg -d ram install libruby_1.8.6-p36-1_mips.ipk
rm libruby_1.8.6-p36-1_mips.ipk
LD_LIBRARY_PATH=/tmp/usr/lib /tmp/usr/bin/ruby -v
LD_LIBRARY_PATH=/tmp/usr/lib /tmp/usr/bin/ruby -e "p 'hello from FON2201.'"
成功。動きますな。



http://downloads.openwrt.org/kamikaze/8.09/atheros/packages/ruby-cgi_1.8.6-p36-1_mips.ipk
http://downloads.openwrt.org/kamikaze/8.09/atheros/packages/ruby-erb_1.8.6-p36-1_mips.ipk
http://downloads.openwrt.org/kamikaze/8.09/atheros/packages/ruby-webrick_1.8.6-p36-1_mips.ipk



しかし、
(before)
root@DD-WRT:/tmp# du -h -s
116.0k  .
(after)
root@DD-WRT:/tmp# du -h -s
3.4M    .
root@DD-WRT:/tmp# df -h
Filesystem                Size      Used Available Use% Mounted on
rootfs                    5.4M      5.4M         0 100% /
/dev/root                 5.4M      5.4M         0 100% /
/dev/mtdblock/3           1.4M    196.0k      1.2M  13% /jffs
入らなさそう。

FONにSDカードを増設

結構大変そうなのでやりたくない。特にFON2201の情報がない。GPIOの場所すらわからない。


その他

La FoneraのGPIOでAVRに書き込む


LaFonera改造大全集

タグ:

+ タグ編集
  • タグ:

このサイトはreCAPTCHAによって保護されており、Googleの プライバシーポリシー利用規約 が適用されます。

最終更新:2009年05月03日 22:05
ツールボックス

下から選んでください:

新しいページを作成する
ヘルプ / FAQ もご覧ください。