Boarduino

- 2008-07-03

#この記事は5月頃に書かれたものを再度投稿した物です。

20080604-boarduino.jpg

韓国でのワークショップで Boarduinoをつかったのでそれに関するメモ。

BoArduinoはArduinoのクローンでATmega168チップを使っているのでArduino Dicimilaボードと同じ用に動作する。Arduinoより少し安い。

スパコではquarksに arduinoライブラリがあるのでこれを使うと便利。

SimpleMessageSystemって言うArdino側のファームウエアのためにかかれているので、今回これを使用した。 最初 Firmataというわりとスタンダードらしいファームを焼いたが、挙動がおかしいのであきらめる。

簡単なデジタルreadがやりたかったんだけど、手持ちに抵抗が無かったのでちゃんとしたスイッチ回路が組めない事に気付く。 チップ側でどうにかならないかなーと思っていたら..あった。

本来ならちゃんとアクティブハイ、ローの回路を組まなきゃ行けないんだけど、そこを省くためにチップ側でI/Oピンを常にハイかローを書き込んであげるという技。なんて言うんだか忘れたけど(チャタリング防止?ちがうか)、そいうのがあるらしい。

で、ファーム側で44行目からのreadpins()を少し修正


void readpins (){ // Read pins (analog or digital)

  switch (messageGetChar ()) { // Gets the next word as a character

    case 'd': // READ digital pins

    messageSendChar ('d');  // Echo what is being read
    for (char i= 2;i< 14;i++ ) {
      pinMode (i, INPUT); //ここ
      analogWrite (i, 0); //毎ループI/Oピンにlowを書き込む
      messageSendInt (digitalRead (i )); // Read pins 2 to 13

    }
    messageEnd (); // Terminate the message being sent
    break; // Break from the switch

  case 'a': // READ analog pins

    messageSendChar ('a');  // Echo what is being read
    for (char i= 0;i< 6;i++ ) {
      messageSendInt (analogRead (i )); // Read pins 0 to 5
    }
    messageEnd (); // Terminate the message being sent

  }

}
 

これでok

スパコ側はArdino.scdのヘルプを参考に


p = ArduinoSMS("/dev/tty.usbserial-A6004uzj", 9600); // was 9600 (changed by thor)

(
p. action = { |... msg|
        msg. postln;
        };

)       
       
       

// read digital pins

(
t= Task( {
        inf. do {
                p. send($r, $d ); //here is comunication with BoArduino
                0.025. wait; //適せんsleepをさせて

        }

}). play;

)
t. stop;
  あれ、でもこれよくかんがえたらなぜかanalogWriteしてる。 でも動作はokなんだよな、なんでだろ?わけわからん。Boarduino