ドットマトリックスLEDをインテリジェントブロックNXTに接続する


▲秋月のドットマトリックスLEDをインテリジェントブロックNXTに接続してみました。


▲回路図です。マイコンを介してつないでるだけです。I2Cで通信します。
ドットマトリックスLEDは秋月電子通商で売ってる32x16pixelのモジュールを使います。
マイコンはAttiny26Lです。
NXT用のモジュラージャックはmindsensors.comのものを使いました。mindsensors.comから直接買うと送料が大変なので、代理店から買ったほうがいいかもしれません。参考までに↓
http://roboproduct.com/MS02NXTAccessories.html



▲完成した様子。
ドットマトリックスLEDは点灯すると電流が一杯流れるので、裏側のR4とR5の抵抗値を大きめに付け直します(たとえば1.5kオーム)。

http://nicotak.com/robot/nxt/akiled1.zip
▲ファームとインテリジェントブロック側のプログラムです。

http://www.youtube.com/watch?v=oXAn3waeUMU
▲動画です。
ストップウォッチ機能とライトセンサの動作テストを行ってます。

▼アルファベットによる文章を横スクロール表示します。

// dot matrix led program(original sensor)
// by takuya matsubara
#include "NXCDefs.h"

#define IN_I2C IN_1
//INPUT PORT(1/2/3/4)
#define I2CWAIT 80

#define CNTPARTURN 216
// 360 * 12 / 20

byte writebuf[3];    //send command
byte readbuf[1];    //recv command

           // 0123012301230123012301230123012301230123
string font0=" xx   x  xx  xx   x xxxx xxxxxxx xx  xx ";
string font1="x  x xx x  xx  x xx x   x      xx  xx  x";
string font2="x  x  x x  x   xx x x   x     x x  xx  x";
string font3="x  x  x    x xx x x xxx xxx   x  xx x  x";
string font4="x  x  x   x    xxxxx   xx  x x  x  x xxx";
string font5="x  x  x  x     x  x    xx  x x  x  x  x ";
string font6="x  x  x x   x  x  x    xx  xx   x  x x  ";
string font7=" xx  xxxxxxx xx   x xxx  xx x    xx x   ";

           // 012301230123012301230123012301230123012301230123012301230123012301230123012301230123
string fnta0=" xx xxx  xx xxx xxxxxxxx xx x  xxxx xxx x  xx   x  xx  x xx xxx  xx xxx  xxxxxxxx  xx  xx  xx  xx  xxxxx";
string fnta1="x  xx  xx  xx  xx   x   x  xx  x x   x  x x x   xxxxxx xx  xx  xx  xx  xx    x  x  xx  xx  xx  xx  x   x";
string fnta2="x  xx  xx   x  xx   x   x  xx  x x   x  x x x   xxxxxx xx  xx  xx  xx  xx    x  x  xx  xx  x xx x  x   x";
string fnta3="x  xxxx x   x  xxxxxxxxxx   xxxx x   x  xx  x   x  xxx xx  xx  xx  xxxx  xx  x  x  xx  xx  x xx  xx   x ";
string fnta4="xxxxx  xx   x  xx   x   x xxx  x x   x  xx  x   x  xx xxx  xxxx x  xx x    x x  x  xx  xx  x xx  x   x  ";
string fnta5="x  xx  xx   x  xx   x   x  xx  x x   x  x x x   x  xx xxx  xx   xxxxx  x   x x  x  xx x x  x xx  x  x   ";
string fnta6="x  xx  xx  xx  xx   x   x  xx  x x   x  x x x   x  xx xxx  xx   x  xx  x   x x  x  xxx  xxxxx  x x  x   ";
string fnta7="x  xxxx  xx xxx xxxxx    xx x  xxxx x   x  xxxxxx  xx  x xx x    xxxx  xxxx  x   xx x   x  xx  x x  xxxx";

void put_space(void){
  int readcnt = 0;     //sensor to NXT. input bytes
  byte cnt = 4;

  while(cnt--){
    writebuf[2] = 0;
    I2CBytes(IN_I2C, writebuf, readcnt, readbuf);
    Wait(I2CWAIT);     //delay[msec]
  }
}

void put_abc(int num)
{
  byte tmp;
  byte cnt = 4;
  int readcnt = 0;     //sensor to NXT. input bytes

  num *= 4;

  while(cnt--){
     tmp = 0;
     if(SubStr(fnta0,num,1) !=" ") tmp |= (0x01 << 0);
     if(SubStr(fnta1,num,1) !=" ") tmp |= (0x01 << 1);
     if(SubStr(fnta2,num,1) !=" ") tmp |= (0x01 << 2);
     if(SubStr(fnta3,num,1) !=" ") tmp |= (0x01 << 3);
     if(SubStr(fnta4,num,1) !=" ") tmp |= (0x01 << 4);
     if(SubStr(fnta5,num,1) !=" ") tmp |= (0x01 << 5);
     if(SubStr(fnta6,num,1) !=" ") tmp |= (0x01 << 6);
     if(SubStr(fnta7,num,1) !=" ") tmp |= (0x01 << 7);
     writebuf[2] = tmp;
     I2CBytes(IN_I2C, writebuf, readcnt, readbuf);
     Wait(I2CWAIT);     //delay[msec]
     num++;
  }
  writebuf[2] = 0;
  I2CBytes(IN_I2C, writebuf, readcnt, readbuf);
  Wait(I2CWAIT);     //delay[msec]
}

void put_num(int num)
{
  byte tmp;
  byte cnt;
  int readcnt = 0;     //sensor to NXT. input bytes

  num *= 4;

  cnt=4;
  while(cnt--){
     tmp = 0;
     if(SubStr(font0,num,1) !=" ") tmp |= (0x01 << 0);
     if(SubStr(font1,num,1) !=" ") tmp |= (0x01 << 1);
     if(SubStr(font2,num,1) !=" ") tmp |= (0x01 << 2);
     if(SubStr(font3,num,1) !=" ") tmp |= (0x01 << 3);
     if(SubStr(font4,num,1) !=" ") tmp |= (0x01 << 4);
     if(SubStr(font5,num,1) !=" ") tmp |= (0x01 << 5);
     if(SubStr(font6,num,1) !=" ") tmp |= (0x01 << 6);
     if(SubStr(font7,num,1) !=" ") tmp |= (0x01 << 7);
     writebuf[2] = tmp;

     I2CBytes(IN_I2C, writebuf, readcnt, readbuf);
     Wait(I2CWAIT);     //delay[msec]
     num++;
  }
  writebuf[2] = 0;
  I2CBytes(IN_I2C, writebuf, readcnt, readbuf);
  Wait(I2CWAIT);     //delay[msec]
}

task main()
{
  string msg="SYMPOSIUM ON ROBOTICS IN SCIENCE AND TECHNOLOGY EDUCATION ";
  byte temp[60];
  int chrcode;
  char i;

  StrToByteArray(msg, temp);

  SetSensorLowspeed (IN_I2C);
  Wait(I2CWAIT);     //delay[msec]

  writebuf[0] = 0x02;   // slave address
  writebuf[1] = 0x44;   // command

  i=0;
  while(1){
    if(i>= StrLen(msg))
		i=0;

    chrcode = temp[i];
    
    if(chrcode==0x20){
      put_space();
    }else if(chrcode >= 0x41){
  		put_abc( chrcode - 0x41 );
  	}else if(chrcode <= 0x39){
   	 	put_abc( chrcode - 0x30 );
	  }
    i++;
  }
}


▲上のプログラムを実行したときの様子。