#contents //¤â¤¯¤¸¤Ç¤¹ #pcomment(reply) //¤³¤á¤ó¤È¤Ç¤¹ *2014/4/26 I2C¥«¥é¡¼¥»¥ó¥µ£Ó£±£±£°£µ£¹¡Ý£°£²£Ä£Ô¤Î»È¤¤Êý [#de0b747a] -ironeÍÑ¡£I2C¤ÇÆ°¤¯¡£¿§¤ÎÂбþ¤¬ÌÌÅݤ¯¤µ¤«¤Ã¤¿¤Î¤ÇºÜ¤»¤Æ¤ª¤¯¡£ »²¹ÍURL¡§http://blog.kemushicomputer.com/2013/08/i2c.html ~ Á°Äó¤È¤·¤Æ¡¢3¥ª¥¯¥¿¡¼¥Ö¤Ë¹ç¤ï¤»¤ë°Ù36¼ïÎर¤é¤¤¤Î¿§¤¬Íߤ·¤¤ ~ ¢ªRGB¤Ç¹Í¤¨¤ë¤È3*3*4¤°¤é¤¤¤¬ÂÅÅö ~ ¢ªÄ¾Àܼè¤Ã¤Æ¤¤¿Ãͤò¶ãÌ£¤·¤Æ¤â¾å¼ê¤¯¤¤¤«¤Ê¤¤(ÌÀ¤ë¤µ¤Ë¤è¤Ã¤ÆƱ¤¸¿§¤¬°ã¤¦Ãͤˤʤ롤¤½¤â¤½¤â65535ÉÕ¶á¤ÎÌÀ¤ë¤µ¤Ë¹Ô¤«¤Ê¤¤) ~ ¢ªÀÖ³°Àþ¿®¹æ¤ò¼è¤Ã¤ÆÍè¤ì¤ë¤È¤¤¤¦ÊØÍø¤Êµ¡Ç½¤Ëµ¤ÉÕ¤¯¡£ÌÀ¤ë¤µ¤Ë¤è¤Ã¤ÆÊѲ½¤¹¤ë¤Î¤« ~ ¢ª¤¤ì¤¤¤ËÊѲ½¤·¤¿¡£¤È¤¤¤¦¤ï¤±¤ÇrgbÃÍ/IRÃͤÇÊäÀµ¤Ç¤¤ë¡£¤Þ¤¿¡¢¤½¤ÎÃͤÏÂçÂÎ0¡Á12¤ÎÈϰϤ˼ý¤Þ¤ë ~ ¢ª¤³¤ì¤ò3*3*4Åùʬ¤·¤¿¤â¤Î¤òºÇ½ªÅª¤Ê¿§È½ÃǤ˻Ȥ¦ ~ /******************************************************************************* * * S11059_02dt I2C color sensor test sketch v20130818 by KentN * * http://www.hamamatsu.com/jp/ja/product/new/S11059-02DT/index.html (Ja * http://www.hamamatsu.com/jp/en/product/new/S11059-02DT/index.html (EN * * tested boards * MSP430 LaunchPad(G2553) (Energia IDE 0101E009 & patched latest¡¡ MSP430/cores library) * Arduino 1.0 or later (need 3.3V board or I2C level converter) * * MSP430LaunchPad (& Energia) * before enabling I2C bus, remove led2 JUMPER PIN * Energia IDE must be patched with latest cores library on github * (In energiaIDEdirectory/hardware/MSP430/cores) ********************************************************************************/ #include "Wire.h" #define device_address 0x2A #define control_reg 0x00 /* //¿§¤Î¼ïÎà¡£3¥ª¥¯¥¿¡¼¥Ö¤Ë¹ç¤ï¤»¤Æ36¼ïÎà¤Ë¤Ê¤Ã¤Æ¤¤¤ë #define black 0 #define dark_blue 1 #define navy 2 #define blueblue 3 #define greenteamilk 4 #define emerald 5 #define sky 6 #define aqua 7 #define yellowgreen 8 #define lightemerald 9 #define shallowsea 10 #define lightaqua 11 #define redblack 12 #define lightredpurple 13 #define lightpurple 14 #define lightbluepurple 15 #define mastard 16 #define ash 17 #define lightblueash 18 #define lightbluewhiteash 19 #define neonyellowgreen 20 #define lightashyellowgreen 21 #define lightashemerald 22 #define lightashwhiteblue 23 #define redred 24 #define pink 25 #define pinkpurple 26 #define purple 27 #define orange 28 #define fleshcolor 29 #define whitepink 30 #define kirby 31 #define yellow 32 #define lightyellow 33 #define verylightyellow 34 #define white 35 */ //¥»¥ó¥µ¡¼¤«¤é¤ÎÃͤò»ý¤Ã¤Æ¤¯¤ë¡£16bit¤Ê¤Î¤Ç0¡Á65535 uint16_t red = 0; uint16_t green = 0; uint16_t blue = 0; uint16_t IR = 0; //¥»¥ó¥µ¡¼¤ÎRGBÃͤ«¤é¿§¤ò·èÄꤹ¤ëºÝ¤Ë»È¤¦ uint16_t r = 0; uint16_t g = 0; uint16_t b = 0; //group¡¡¥»¥ó¥µ¡¼¤«¤éÊäÀµ¸å¤ÎÃͤ¬ÂçÂÎ12¤°¤é¤¤¤Þ¤Ç¤Ê¤Î¤Ç¡¢ uint16_t r_1 = 4; uint16_t r_2 = 8; uint16_t r_3 = 20; uint16_t g_1 = 4; uint16_t g_2 = 8; uint16_t g_3 = 20; uint16_t b_1 = 3; uint16_t b_2 = 6; uint16_t b_3 = 9; uint16_t b_4 = 20; uint16_t color = 0; uint16_t colorGroup[3][3][4] = { { {0,1,2,3}, {4,5,6,7}, {8,9,10,11} }, { {12,13,14,15}, {16,17,18,19}, {20,21,22,23} }, { {24,25,26,27}, {28,29,30,31}, {32,33,34,35} } }; void getRGB(); void getColor(); void getColor() { if(red <= r_1){r = 0;} else if(red <= r_2){r = 1;} else if(red <= r_3){r = 2;} if(blue <= b_1){b = 0;} else if(blue <= b_2){b = 1;} else if(blue <= b_3){b = 2;} else if(blue <= b_4){b = 3;} if(green <= g_1){g = 0;} else if(green <= g_2){g = 1;} else if(green <= g_3){g = 2;} color = colorGroup[r][g][b]; } void setup() { Wire.begin(); Serial.begin(9600); } void loop() { getRGB(); Serial.print(red); Serial.print(','); Serial.print(green); Serial.print(','); Serial.print(blue); Serial.print(','); Serial.println(IR); red= red/IR; green=green/IR; blue=blue/IR; getColor(); Serial.print(red); Serial.print(','); Serial.print(green); Serial.print(','); Serial.print(blue); Serial.print(','); Serial.println(color); delay(500); } void getRGB() { uint16_t colordata= 0; //¤³¤ÎÊդΥץí¥È¥³¥ë¤Ï¥Ç¡¼¥¿¥·¡¼¥È¤ËºÜ¤Ã¤Æ¤¤¤ë Wire.beginTransmission(device_address); Wire.write(control_reg); Wire.write(0x83); // ADC reset, wakeup, low gain, fixed time mode, 179.2ms Wire.endTransmission(false); Wire.beginTransmission(device_address); Wire.write(control_reg); //ADC start, wakeup, low gain, fixed time mode, 179.2ms Wire.write(0x03); Wire.endTransmission(true); //probably for RGB+IR delay(180*4); //total exposure time Wire.beginTransmission(device_address); Wire.write(0x03); Wire.endTransmission(false); Wire.requestFrom(0x2A,8,true); //read data colordata = Wire.read(); colordata <<= 8; colordata |= Wire.read(); red = colordata; colordata =0; colordata = Wire.read(); colordata <<= 8; colordata |= Wire.read(); green = colordata; colordata =0; colordata = Wire.read(); colordata <<= 8; colordata |= Wire.read(); blue = colordata; colordata =0; colordata = Wire.read(); colordata <<= 8; colordata |= Wire.read(); IR = colordata; return; } ¾å¼ê¤¯Æ°¤¤¤¿¤¬²þÁ±¤ÏÅÔÅÙ¤·¤Æ¤¤¤¤¿¤¤¡£ *2014/4/26 OZV¤Î»È¤¤Êý [#q72fd410] -ironeÍÑ¡£XBee¤È¤¢¤Þ¤êÊѤï¤é¤Ê¤¤¤¬¡¢¥Ñ¥±¥Ã¥È¤òºîÀ®¤·¤¿¤ê¥Ç¡¼¥¿¤ò¼è¤ê½Ð¤¹É¬Íפ¬¤¢¤ë¡£ -¥×¥í¥°¥é¥à ~ -send¦ ~ #include <SoftwareSerial.h> SoftwareSerial ozvSerial(10, 11); // RX, TX //send packet, for the last 3elements, length, data and check sum byte send[10]={0xFE, 0x05, 0x2A, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; //length of data int length = 0x01; //data int data = 0xCA; int i = 0; //loop void setup(){ Serial.begin(9600); ozvSerial.begin(38400); //complete send packet send[sizeof(send) - 3] = length; send[sizeof(send) - 2] = data; //culculate checksum and complete send command for(i = 1; i < sizeof(send) - 1; i++){ send[sizeof(send) - 1] = send[i] ^ send[sizeof(send) - 1]; } } void loop(){ //send delay(1000); ozvSerial.write(send,sizeof(send)); } -receive¦ ~ #include <SoftwareSerial.h> SoftwareSerial ozvSerial(10, 11); // RX, TX // for the last 2elements, data and SUM //receive packet byte receive[12]; //data from received packet int getData = 0x00; //serial received data byte receivebyte = 0x00; int i = 0;//loop int count = 0;//insert data into receive array int start = 0;//start inserting int receiveLen = 12;//receive packet length is 12 void setup(){ Serial.begin(9600); ozvSerial.begin(38400); } void loop(){ //receive if(ozvSerial.available()){ receivebyte = ozvSerial.read(); //0xFE is start of a paket if(receivebyte == 0xFE){ start = 1; //other than 0xFE, 11elements remaining to receive }else if(start == 1 && count < receiveLen - 1){ receive[count] = receivebyte; count++; //when finished inserting, get data from the packet }else if(count == receiveLen - 1){ count = 0; start = 0; getData = receive[receiveLen - 3]; Serial.print("data = "); Serial.println(getData, HEX); } } } ¾Ü¤·¤¯¤Ï˺¤ì¤¿¤Î¤Ç¥×¥í¥°¥é¥à¤À¤±¤Ç¤â˺È÷Ï¿¤È *2014/1/10 Äɵ [#q314a404] -ÆüËܸì¤Îencoding¤Ï¡¢%!TEX encoding = UTF-8 Unicode¤Î°ìʸ¤ò.tex¥Õ¥¡¥¤¥ë¤ÎºÇ½é10¹Ô°ÊÆâ¤ËÆþ¤ì¤ë *2014/1/10 TeX¤òMac¤Ë¥¤¥ó¥¹¥È¡¼¥ë¡¦¥³¥Þ¥ó¥É¤Î¥Ñ¥¹¤òÄ̤¹ [#i29e5e51] -º£¹¹¤Ê¤¬¤é¥Þ¥Ã¥¯¤ËTeX´Ä¶¤ò¹½ÃÛ¤·¤¿¡£LaTeX¤â»È¤¨¤Æpdf¥Õ¥¡¥¤¥ë¤â½ÐÎϤǤ¤¿¤Î¤Ç¡¢¤Þ¤È¤á¡£ -sasada¤µ¤ó¤Îºî¶ÈÆü»ï¤ò¥Ò¥ó¥È¤Ë¿Ê¤á¤¿¢ªhttp://ifdl.ec.t.kanazawa-u.ac.jp/diary/index.php?sasada#b53f5bea -¡¥¤¥ó¥¹¥È¡¼¥ë¡¦½é´üÀßÄê ~ http://d.hatena.ne.jp/lucky_pool/20120209/1328758735 ¤³¤Î¥µ¥¤¥È¤Î¼ê½ç¤Ë½¾¤¦¡£~ 1. Drag & Drop UpTeX ~ 2. ESP Ghostscript¤Ë²Ã¤¨¤Æ¡¢~ 3. UpTeXº¹Ê¬¥Õ¥¡¥¤¥ë ~ ¤â¡¢¤ÈÊ̤ΤȤ³¤í¤Ç½ñ¤¤¤Æ¤¢¤Ã¤¿¤Î¤Ç¥À¥¦¥ó¥í¡¼¥É¡£3¤Ë¤Ä¤¤¤Æ¤Ï¡¢²òÅà¸å¤Îdvipdfmx¥Õ¥¡¥¤¥ë¤ò ~ /Applications/UpTeX.app/teTeX/bin¤Ë¥É¥é¥Ã¥°&¥É¥í¥Ã¥×¤·¤ÆÁ´¤Æ¤Î¥¤¥ó¥¹¥È¡¼¥ë´°Î»¡£ ~ ¥µ¥¤¥È¤Ë½ñ¤¤¤Æ¤¢¤ë½é´üÀßÄê¤Ï¤·¤Æ¤ª¤¯¡£ ~ ¤µ¤é¤Ë¡¢¥¢¥×¥ê¥±¡¼¥·¥ç¥óÆâ¤ÎTeXPad¤Ï¡¢°ìÅÙ¥À¥Ö¥ë¥¯¥ê¥Ã¥¯¤Ç³«¤¤¤Æ½é´üÀßÄê¤òok¤È²¡¤·¤Æ¤ª¤¯¡£ -¢¥Ñ¥¹¤òÄ̤¹ ~ ¥³¥Þ¥ó¥É¤«¤éľÀÜ¥³¥ó¥Ñ¥¤¥ë¤ädiv¥Õ¥¡¥¤¥ë¤òºî¤ëºÝ¤Ë¤Ï¡¢¥³¥Þ¥ó¥É·´(?)¤Ë¥Ñ¥¹¤òÄ̤·¤Æ¤ª¤¯É¬Íפ¬¤¢¤ë¡£ ~ http://xn--p8ja5bwe1i.jp/wiki/%E3%81%9D%E3%81%AE%E4%BB%96/Mac%E3%81%A7%E3%83%91%E3%82%B9%E3%82%92%E9%80%9A%E3%81%99/ ~ ¤³¤Îµ»ö¤¬¤È¤Æ¤â»²¹Í¤Ë¤Ê¤ë¡£¤¿¤À¤·¡¢.bashrc¤ÎºîÀ®¤Î»ÅÊý¤ÈPATH¤ÎÁ°¤ËexportÉÕ¤±¤ë¤È¤«¤Ï½ñ¤¤¤Æ¤Ê¤¤¤Î¤ÇÉÕ¤±²Ã¤¨¡£ ~ https://gist.github.com/disktnk/4104284 ¾åµ2¤Ä¤Î²ò·èË¡¤¬ºÜ¤Ã¤Æ¤¤¤¿¡£ ~ ¤µ¤é¤Ë¡¢ÊÔ½¸¤Î»ÅÊý¤ÈÊݸ¡¦½ªÎ»¤Î»ÅÊý¤Ï ~ http://www14.plala.or.jp/campus-note/vine_linux/operation/vi.html ~ Íפ¹¤ë¤Ë¡¢.bashrc¤ò³«¤¤¤Æi¤ò²¡¤¹¤ÈÊÔ½¸²èÌ̤ˤʤꡢ¥³¥Þ¥ó¥É¥â¡¼¥É¤ËÌá¤ë»þ¤Ïesc¤ò²¡¤¹¡£Êݸ¡Ü½ªÎ»¤Ïwq¤ò¥³¥Þ¥ó¥ÉÆþÎϤ¹¤ë¡£ ~ ¤³¤³¤Þ¤Ç¤¬½ª¤ï¤ë¤È¥Ñ¥¹¤Î³Îǧ¤ò¤¹¤ë¡£¥¿¡¼¥ß¥Ê¥ë¤Ë¡¡platex -v¡¡¤òÆþÎϤ·¤Æcommand not found°Ê³°¤Îplatex¤Ë´Ø¤¹¤ëÀâÌÀ¤¬½Ð¤Æ¤¤¿¤éok ~ ¤¢¤È¤Ï¥Á¥å¡¼¥È¥ê¥¢¥ëhttp://www.comp.tmu.ac.jp/tsakai/lectures/intro_tex.html¤Ë¤¢¤ë¥³¥Þ¥ó¥ÉÆþÎÏ ~ platex sample.tex ¤Ç¥¨¥é¡¼¤¬¤Ê¤±¤ì¤Ðdvi¥Õ¥¡¥¤¥ë¤¬¤Ç¤¤Æ¡¢ ~ dvipdfmx sample.dvi ~ ¤Çpdf¥Õ¥¡¥¤¥ë¤¬¤Ç¤¤ë¡£ ~ *2013/12/8 RFM12B(Èù¼å̵Àþ¥â¥¸¥å¡¼¥ë)¤ò»È¤Ã¤Æ¤ß¤¿ [#y7e8e6c5] -ÀèÀ¸¤Ë夤¤¿¥é¥¤¥Ö¥é¥ê¤ò¤¤¤¸¤Ã¤Æ¤ß¤¿ -̤´°À®Éôʬ(Åž춯Å٤η׻»¡¦ironeÍѤ˴°Á´arduino UNOÈ´¤¤Ç¤ÎÄÌ¿®¡¦ÄÌ¿®µ÷Υ¬Äê) -´°À®Éôʬ(¥Ç¡¼¥¿¤ÎÁ÷¿®¡¦¼õ¿®) -SPIÄÌ¿®¤Ë¤è¤Ã¤ÆÀ©¸æ¤¹¤ë¡£ ¡½àÈ÷¡§ ¥Ç¡¼¥¿¥·¡¼¥È http://www.hoperf.com/upload/rf/rfm12b.pdf ¥³¥Þ¥ó¥É http://www.hoperf.com/upload/rf/rfm12b.pdf ¥³¥Þ¥ó¥ÉÁḫɽ¡¡ http://tools.jeelabs.org/rfm12b.html http://www.sevenwatt.com/main/ ÅÅÇȶ¯ÅÙ¡¡ http://eleclog.quitsq.com/2011/11/rfm12b-radio-act.html Arduino cookbook https://www.inkling.com/read/arduino-cookbook-michael-margolis-2nd/chapter-14/recipe-14-6 ¥Ñ¥±¥Ã¥ÈÆâÍÆ¡¡ http://lowpowerlab.com/blog/2012/12/28/rfm12b-arduino-library/#more-109 http://lowpowerlab.com/blog/2013/06/20/rfm69-library/ http://jeelabs.org/2011/12/11/inside-the-rf12-driver-part-2/ 2¿Ê¿ô·×»»¡¡ http://hogehoge.tk/tool/number.html Arduino¥Ô¥óÇÛÃÖ¡¡ http://wiki.onakasuita.org/pukiwiki/?Arduino%2F%E3%83%94%E3%83%B3%E9%85%8D%E7%BD%AE ¢²óÏ©¡§ #ref(rfm_1.png) º£²ó¤Ï¤³¤ì¤é¤Ë²Ã¤¨¤ÆnINT/VDI, FSK/DATA/nFFS, DCLK/CFIL/FFIT, nRES¥Ô¥ó¤ò¥Þ¥¤¥³¥ó¤È·Ò¤¤¤À¡£ Arduino UNO¤Ï5V¤ÇÆ°ºî¤¹¤ë¤Î¤Ç¡¢RFM12B¤ËÆþ¤ë¿®¹æ¤òʬ°µ¤¹¤ë¡£¤É¤Î¿®¹æ¤¬Æþ¤ë¤«¤Ï¥Ç¡¼¥¿¥·¡¼¥È¤ÎDI¤ò¸«¤ë¤Èʬ¤«¤ë¡£ £¥é¥¤¥Ö¥é¥ê¡§ -RF12.cpp /*useful command: http://tools.jeelabs.org/rfm12b.html arduino¤ò»ÈÍѤ¹¤ë¤È¤¤Ï16MHz¤Ë¤Ê¤Ã¤Æ¤¤¤ë¤Î¤Ç/4(¥Ç¥Õ¥©¥ë¥È)¤Ë²Ã¤¨¤Æ/2¤Î¤Ëʬ°µ¤·¤Æ»È¤¦¡£(RFM12B¤¬ 2.5MHz¤Þ¤Ç¤·¤«¼õ¤±ÉÕ¤±¤Ê¤¤ÀßÄê¤Î¤¿¤á) #define arduino ÀèÀ¸¤Î¥é¥¤¥Ö¥é¥ê¤«¤éÊѹ¹¤·¤¿²Õ½ê */ #define changed /*commands*/ #define SET_TX 0x8279 #define SET_RX 0x82D9 #define RESET 0x0000 #define STATUS_CHECK 0x0000 #define TX_SEND 0xB800 //+ data #define RX_RECEIVE 0xB000 #define CONFIGURATION 0x80D7 // el(enable tx regigter), ef(enable FIFO) 12.0pF, 433MHz #define SET_FREQUENCY 0xA4B0 // 433MHz #define SET_DATARATE 0xC623 // 9.6kbps #define SET_PLL 0xCC17 // CLK=2.5MHz, !ddy ddit, PLL BW=256k #define RX_CONTROL 0x94C2 // VDI,FAST,67kHz,LNA=0dBm,RSSI=-91dBm #define Data_Filter_Clock_Recovery 0xC2AC // AL,!ml,DIG,DQD4 #define FIFO_RESET_MODE 0xCA83 // FIFO8,2byte-SYNC,!AL,ff,DR #define TX_CONTROL 0x9850 // !mp,90kHz,MAX OUT TXpower=0(max) #define AUTO_FREQUENCY_CONTROL 0xC483 // @PWR,NO RSTRIC,!st,!fi,OE,EN #define SET_WAKEUP_TIMER 0xE000 // wake up timer / NOT USE #define SET_LOW_DUTY_CYCLE 0xC800 // low duty cycle / NOT USE//status #define SET_LOW_BATTERY_DETECT_uC_CLK 0xC049 // 1.66MHz,3.1V #define SET_SYNC_PATTERN 0xCED4 // SYNC=2DD4 //status #define TX_READY 0x8000 #define FIFO_REACHED 0x8000 //pin #define SPI_MOSI 11 #define SPI_MISO 12 #define SPI_SCK 13 #include <pins_arduino.h> #include <avr/interrupt.h> #include <Arduino.h> #include <RF12.h> int nIRQ_pin, SS_pin, RST_pin; int mode; uint8_t RF12::spi_byte(uint8_t out) { SPDR = out; while (!(SPSR & _BV(SPIF))); return SPDR; } uint16_t RF12::xfer_byte(uint16_t cmd) { uint16_t dat = 0; digitalWrite(SS_pin, 0); dat = spi_byte(cmd >> 8) << 8; dat |= spi_byte(cmd); digitalWrite(SS_pin, 1); return(dat); } void RF12::send_byte(byte data) { uint16_t d; // while(!((d = xfer_byte(0x0000)) & 0x8000)) Serial.println(d, HEX); //send 0000(status check). when returned 8000 TX is ready while(!(xfer_byte(STATUS_CHECK) & TX_READY)); // wait for TX ready xfer_byte(TX_SEND + data); delay(1); } //sending 1bit per time //would I need this? void RF12::send_data(byte *data, byte len) { byte cksum = 0; for (int i = 0; i < len; i++){ send_byte(data[i]); cksum += data[i]; } send_byte(cksum); } //wait(blocks) until it receives -> it's okay cuz used only for speaker #ifdef changed byte RF12::receive_byte() { //interrupt request output(from RFM12B), active low while(digitalRead(nIRQ_pin) == 1); // wait for any data received //status check, reset functions //xfer_byte(0x0000); // while(!(xfer_byte(0x0000) & 0x8000))Serial.println(xfer_byte(0x0000), HEX); // wait for RX ready //read 8 bits from the receiver FIFO (even if FIFO not used it still shares the same pin with RX(pin6)) xfer_byte(RESET); return(xfer_byte(RX_RECEIVE)); } #else byte RF12::receive_byte() { //interrupt request output(from RFM12B), active low while(digitalRead(nIRQ_pin) == 1); // wait for any data received //status check, reset functions xfer_byte(0x0000); //read 8 bits from the receiver FIFO (even if FIFO not used it still shares the same pin with RX(pin6)) return(xfer_byte(0xB000)); } #endif //needed to recaive less than a byte? byte *RF12::receive_data(byte *data, byte len) { int i; for (i = 0; i < len; i++){ data[i] = receive_byte(); } return(data); } void RF12::begin(uint8_t nIRQ, uint8_t SS, uint8_t RST) { nIRQ_pin = nIRQ; SS_pin = SS; RST_pin = RST; pinMode(RST_pin, INPUT); // digitalWrite(RST_pin, 0); digitalWrite(SS_pin, 1); pinMode(SS_pin, OUTPUT); //digital 11,12,13 is fixed //faster when set it directly? #ifdef changed DDRB |= ((1<<DDB3)|(1<<DDB4)|(1<<DDB5)); #else pinMode(SPI_MOSI, OUTPUT); pinMode(SPI_MISO, INPUT); pinMode(SPI_SCK, OUTPUT); #endif //need to make this smaller than 2.5MHz? arduino is 16MHz SPCR = _BV(SPE) | _BV(MSTR); // SPI master enable, Mode0 #ifdef arduino SPSR |= _BV(SPI2X); #endif pinMode(nIRQ_pin, INPUT); digitalWrite(nIRQ_pin, 1); // pull-up, active low //status check for return and initialization xfer_byte(RESET); // intitial SPI transfer added to avoid power-up problem // wait until RFM12B is out of power-up reset, this takes several *seconds* //empty Tx buffer xfer_byte(TX_SEND); // in case we're still in OOK mode //reset again and again while (digitalRead(nIRQ_pin) == 0) xfer_byte(RESET); //yes, commands start //enable internal register and FIFO mode ---> why? needed for real time and 1 byte transmission? xfer_byte(CONFIGURATION); // el, ef 12.0pF, 433MHz //fastest way it might be: turning on the whole receiver chain, synthesizer, and oscillator //I don't understand here according to datasheet #ifdef changed xfer_byte(0x82d9); // RX mode -> in case didn't set the mode? xfer_byte(SET_FREQUENCY); // 433MHz xfer_byte(SET_DATARATE); // 9.6kbps xfer_byte(SET_PLL); // CLK=2.5MHz, !ddy ddit, PLL BW=256k //especially here //xfer_byte(TX_CONTROL); // !mp,90kHz,MAX OUT TXpower=0(max) xfer_byte(RX_CONTROL); // VDI,FAST,67kHz,LNA=0dBm,RSSI=-91dBm #else //receiver baseband circuite separately switched on xfer_byte(0x82d9); // RX mode -> in case didn't set the mode? xfer_byte(0xA640); // 437MHz (430+0.0025*(0x640)[MHz]) xfer_byte(0xC647); // 4.8kbps xfer_byte(0xCC77); // CLK=2.5MHz, !ddy ddit, PLL BW=256k xfer_byte(0x94A2); // VDI,FAST,134kHz,LNA=0dBm,RSSI=-91dBm #endif //Data Filter & Clock Recovery xfer_byte(Data_Filter_Clock_Recovery); // AL,!ml,DIG,DQD4 //FIFO and reset mode xfer_byte(FIFO_RESET_MODE); // FIFO8,2byte-SYNC,!AL,ff,DR //Automatic Frequency Control xfer_byte(AUTO_FREQUENCY_CONTROL); // @PWR,NO RSTRIC,!st,!fi,OE,EN //replaced---------------------------------------------------------------- //TX control xfer_byte(TX_CONTROL); // !mp,90kHz,MAX OUT TXpower=0(max) //------------------------------------------------------------------------ xfer_byte(SET_WAKEUP_TIMER); // wake up timer / NOT USE xfer_byte(SET_LOW_DUTY_CYCLE); // low duty cycle / NOT USE //Low Battery Detect and µC Clock xfer_byte(SET_LOW_BATTERY_DETECT_uC_CLK); // 1.66MHz,3.1V //Synchronization Pattern xfer_byte(SET_SYNC_PATTERN); // SYNC=2DD4 delay(1); } void RF12::set_tx_power(uint8_t pow) { //just setting the power on TX Configuration Command xfer_byte(TX_CONTROL + (pow & 0x07)); } uint16_t RF12::read_status(void) { return(xfer_byte(STATUS_CHECK)); } RF12::RF12(void) { } void RF12::set_mode(uint8_t md) { mode = md; // xfer_byte(0x8239); // !er, !ebb, et, es, ex, !eb, !ew, dc (for tx) // xfer_byte(0x82D9); // er, ebb, !et, es, ex, !eb, !ew, dc (for rx) //new------------------------------------------------------------------- //xfer_byte(0x8279); // !er, ebb, et, es, ex, !eb, !ew, dc (for tx) // xfer_byte(0x82D9); // er, ebb, !et, es, ex, !eb, !ew, dc (for rx) #ifdef changed if (md == RF12_MODE_TX) xfer_byte(SET_TX); else if (md == RF12_MODE_RX) xfer_byte(SET_RX); #else if (md == RF12_MODE_TX) xfer_byte(0x8239); else if (md == RF12_MODE_RX) xfer_byte(0x82d9); #endif } int RF12::available(void) { if (digitalRead(nIRQ_pin) == 0) return(1); else return(0); } -Á÷¼õ¿®¤Îino¥Õ¥¡¥¤¥ë Rx: #include <RF12.h> int RF12_SS = 10; int RF12_nIRQ = 9; int RF12_RST = 8; uint8_t payload[16]; uint16_t pckt; RF12 rf12 = RF12(); byte data; byte packet[16]; void setup() { Serial.begin(9600); rf12.begin(RF12_nIRQ, RF12_SS, RF12_RST); rf12.set_mode(RF12_MODE_RX); Serial.println("Ready Rx"); } int header = 4; int tail = 6; int index = 0, check = 0; void loop() { //uint8_t c; if (rf12.available()){ data = rf12.receive_byte(); if((data == 0xAA) || (data == 0x55)) ; else Serial.write(data); } //Serial.println(); } Tx: #include <RF12.h> int RF12_SS = 10; int RF12_nIRQ = 9; int RF12_RST = 8; uint16_t payload[16]; uint16_t c; RF12 rf12 = RF12(); void setup() { Serial.begin(9600); pinMode(4, OUTPUT); rf12.begin(RF12_nIRQ, RF12_SS, RF12_RST); rf12.set_mode(RF12_MODE_TX); Serial.println("TX ready"); c = '!'; } void loop() { //packet format - only activating necessary parts for just 1 byte transmission //see http://jeelabs.org/2011/12/11/inside-the-rf12-driver-part-2/ //or http://lowpowerlab.com/blog/2012/12/28/rfm12b-arduino-library/#more-109 //for full packet information //necessary part(5 bytes) //preamble rf12.send_byte(0xAA); rf12.send_byte(0xAA); rf12.send_byte(0xAA); //SYN-ox2d rf12.send_byte(0x2D); //SYN-network ID (network group (can be in the range 1-255) -> 212) rf12.send_byte(0xD4); //header //CTLflag + DestID(unique node ID of receiver (1 through 30) -> 85) //0 + 55 //rf12.send_byte(c); rf12.send_byte(0x55); //ACK + SourceID(unique node ID of receiver (1 through 30)) //1 + 42? rf12.send_byte(0xaa); //DataLength rf12.send_byte(0x55); //Data rf12.send_byte(0xaa); rf12.send_byte(c); //CRC rf12.send_byte(c+1); rf12.send_byte(c+2); rf12.send_byte(0x55); //CRC rf12.send_byte(0xaa); rf12.send_byte(0x55); rf12.send_byte(0xaa); rf12.send_byte(0xaa); rf12.send_byte(0xaa); //Serial.println("Sent."); digitalWrite(4, HIGH); delay(250); digitalWrite(4, LOW); delay(250); //} } Ãí°Õ¡§Serial.print¤ò»È¤¦¤ÈSerial¤¬¥Ï¥¤¤Ë¤Ê¤Ã¤Æ¤¤¤ë»þ¤Ë²¿¸Î¤«0¤òÆɤࡣ¤¹¤ë¤È¥Ó¥Ã¥È¤¬¤º¤ì¤ÆÃͤ¬¤ª¤«¤·¤¯¤Ê¤ë¤Î¤ÇSerial.write¤ò»È¤¦Êý¤¬Îɤ«¤Ã¤¿¡£(1byte¤ÎÄÌ¿®¤Ï¤³¤Á¤é¤ÎÊý¤¬¤¤¤¤¤È¤¤¤¦¤³¤È¤â½ñ¤¤¤Æ¤¢¤Ã¤¿) 100²ó¤Ë1²ó¤°¤é¤¤Ãͤò´Ö°ã¤¨¤ë¤³¤È¤¬¤¢¤ë¡£ ¾åµ¥×¥í¥°¥é¥à¤ÎºÙ¤«¤¤ÆâÍƤˤĤ¤¤Æ¤Ï¸å¤Û¤É¹¹¿·Í½Äê *2013/12/8 Serial.print¤ÈSerial.write [#hdc93cf4] -»²¹Í: http://arduino.cc/en/Serial/write 1byte¤¢¤ë¤¤¤Ï¤½¤ì°Ê¾å¤Î¥Ð¥¤¥Èñ°ÌËè¤Ë¡¢Serial.write¤Ï¥Ð¥¤¥Ê¥ê¡¼¥Ç¡¼¥¿¤½¤Î¤Þ¤Þ¤ò¥·¥ê¥¢¥ë¥Ý¡¼¥È¤ËÁ÷¤ë¤é¤·¤¤¡£¢ª1byteËè¤Î¥Ç¡¼¥¿ÄÌ¿®¤Ë¤Ïwrite¤ÎÊý¤¬¤¤¤¤¤Î¤«¤â *2013/9/30 unsigned¤Ëµ¤¤ò¤Ä¤±¤ë [#m66236ad] -¤¿¤À¤Îint¤Ç-¤¬¤Ä¤¯¤Î¤ÏÃͤ¬Â礤¤¾ì¹ç *2013/9/26 ATmega3238P¥Ö¡¼¥È¥í¡¼¥À¸å¤Î¥¹¥±¥Ã¥Á½ñ¤¹þ¤ß¥á¥â [#q6db51f1] -¥ê¥»¥Ã¥È¥¹¥¤¥Ã¥Á¤Ë¤Ä¤±¤ë¥³¥ó¥Ç¥ó¥µ¤Ï0.1¦ÌF¤À¤È¾å¼ê¤¯¤¤¤¯¤±¤ì¤É¤â22pF¤À¤È½ñ¤¹þ¤ß¤Ç¤¤Ê¤¤(ÍÆÎ̤¬¾®¤µ¤¹¤®¤Æ¾å¼ê¤¯¥ê¥»¥Ã¥È¤µ¤ì¤Æ¤¤¤Ê¤¤¤Î¤«¤â?) * 2013/9/24 ATmega328P¤Î¥Ö¡¼¥È¥í¡¼¥À¡¼½ñ¤¹þ¤ß¥á¥â(PU) [#p9c3868b] -¥Ò¥å¡¼¥ºÀßÄêɽ #ref(3_1.png) -¤É¤Î¥Ö¡¼¥È¥í¡¼¥À¡¼¤ò»È¤¦¤«¤Ïbootloader.txt¤ËºÜ¤Ã¤Æ¤¤¤ë -ATmega328p¤Ç¤Ïhttp://ifdl.ec.t.kanazawa-u.ac.jp/~akita/lt/index.php?Hardware%2FLED_Tile%2F328 #ref(3_2.png) -¼ê½ç(µð¾¢¤µ¤ó¤Îºî¶ÈÆü»ï¤â»²¹Í¤Ë¤µ¤»¤Æĺ¤¤Þ¤·¤¿¡£) -¿Þ¤¬¤¿¤¯¤µ¤ó¤Çʬ¤«¤ê¤ä¤¹¤¤¡¢¡¢¡¢ -http://mizupc8.bio.mie-u.ac.jp/pukiwiki/index.php?Arduino%2F%E8%87%AA%E4%BD%9C * 2013/9/23 ˺È÷Ï¿-Sparkfun.com MP3 Player Shield¤ò»È¤¦»þ¤Î¥Á¥å¡¼¥È¥ê¥¢¥ë»ØÄê¥Õ¥¡¥¤¥ë¤¬Â¸ºß¤·¤Ê¤¤ [#s4a9511f] -Sparkfun.com MP3 Player Shield¤òUNO¤Ç»È¤¦»þ¤Ë¥¤¥ó¥¹¥È¡¼¥ë¤¹¤ë¥é¥¤¥Ö¥é¥ê¤Î¥Ô¥ó(SS¤ò10¢ª9)¤ËÊѹ¹¤·¤Ê¤¤¤È¤¤¤±¤Ê¤¤¡£ -https://www.sparkfun.com/tutorials/295 ¤Î #ref(2_1.png) ¡¡¤¬Â¸ºß¤·¤Ê¤¤¤Î¤Ç¤¹¤¬¡¢Arduino/libraries/SdFat/SdFatConfig.h¤Î°ìÈÖ²¼ #ref(2_2.png) ¡¡¤Ë¤¢¤ê¤Þ¤·¤¿¡£¤³¤³¤ÎCS¤ò10¢ª9¤ËÊѤ¨¤ë¤ÈÆ°¤¤Þ¤·¤¿¡£ * Eclipse¤ò»È¤Ã¤ÆJava¤Ç¥·¥ê¥¢¥ëÄÌ¿® [#ga87d6a8] - Æ°ºî´Ä¶¡§Windows7 64bit - ¼ê½ç ¡¥·¥ê¥¢¥ëÄÌ¿®¤ò¹Ô¤¤¤¿¤¤Eclipse¤Îpackage²¼¤ËÄɲå饤¥Ö¥é¥êÍѤΥե©¥ë¥À¤òºî¤ë¡Ê̾Á°¤Ï²¿¤Ç¤â¤¤¤¤¤±¤É¼Ì¿¿¤Ç¤Ïlib¡Ë #ref(1.png) ¢ÄɲÃÍѤΥ饤¥Ö¥é¥ê¤ò¥¤¥ó¥¹¥È¡¼¥ë -- http://mfizz.com/oss/rxtx-for-java ¡¡¡¡¤³¤Î¥Õ¥©¥ë¥À¤ò²òÅष¤¿Ãæ¤Î¡¢ ¡¡¡¡¡¡rxtxParallel.dll ¡¡¡¡¡¡rxtxSerial.dll ¡¡¡¡¡¡RXTXcomm.jar ¡¡¡¡¤ò¥³¥Ô¡¼¤·¤Æ¡¢¡¤Î¥Õ¥©¥ë¥ÀÆâ¤Ë¥Ú¡¼¥¹¥È -¤â¤·¤â¥Ñ¥½¥³¥ó¼«ÂΤ˥¤¥ó¥¹¥È¡¼¥ë¤·¤¿¤¤¾ì¹ç¤Ï¡¢Program FilesÆâ¤ÎJava¥Õ¥¡¥¤¥ë¤Î¥é¥¤¥Ö¥é¥ê¤ËÆþ¤ì¤ë¡Ê¤ä¤Ã¤Æ¤Ê¤¤¤Î¤ÇÆ°¤¯¤«¤ÏÉÔÌÀ¡Ë £Eclipse¤ÇLibrary Path¤òÄɲ乤ë -Eclipse¤òµ¯Æ° -¤Þ¤º¡¢¿·¤·¤¯ºî¤Ã¤¿¥Õ¥©¥ë¥À¤¬Æþ¤Ã¤Æ¤¤¤ëPackage̾¤ò±¦¥¯¥ê¥Ã¥¯¤·¤Æ¡¢Refresh¤òÁªÂò¡£¡Ê¤Þ¤¿¤Ï¡¢Package̾¤òÁªÂò¸å¡¢F5¤ò²¡¤¹¡£¡Ë ¡¡¡¡ ¤³¤ì¤Ç¡¢¿·¥Õ¥©¥ë¥À¤¬Package¤ËÃç´ÖÆþ¤ê¡£ ¡¡ -Project¥¿¥Ö¤ÎProperties¤ò¥¯¥ê¥Ã¥¯¤¹¤ë¡£Properties¤Îº¸¤ËJava Build Path¤¬¤¢¤ë¤Î¤Ç¥¯¥ê¥Ã¥¯¡£ -Libraries¥¿¥Ö¤ò¥¯¥ê¥Ã¥¯¡£Add Jars...¤ò¥¯¥ê¥Ã¥¯¤·¤Æ¡¢¡¤Çºî¤Ã¤¿¥Õ¥©¥ë¥ÀÆâ¤ÎRXTXcomm.jar¤òÁªÂò¡£ #ref(2.png) -¤³¤ì¤ÇÀßÄê¤Ï´°Î»¡£¤¢¤È¤Ï¥×¥í¥°¥é¥à¤ò½ñ¤¯¤Î¤ß¡£ ¤¥×¥í¥°¥é¥àºîÀ® -CommLight.java¡Ê¥á¥¤¥ó¤¬¤¢¤ë¥Õ¥¡¥¤¥ë¡Ë //port check //JDK check import java.io.*; public class CommLight{ static File sharedText; public static void main(String[] args){ SerialComm serialcomm = new SerialComm(); serialcomm.open(); int i = 10; while(i>0){ serialcomm.write((byte)0x34); try{ Thread.sleep(500); }catch(Exception e){ } serialcomm.write((byte)0x20); try{ Thread.sleep(500); }catch(Exception e){ } serialcomm.write((byte)0x78); try{ Thread.sleep(500); }catch(Exception e){ } i--; } System.out.println("Hello, World"); } } -SerialComm.java import gnu.io.*; import java.io.*; import java.util.*; public class SerialComm implements SerialPortEventListener{ private SerialPort port; // private static BufferedReader reader; private InputStream in; private OutputStream out; SerialComm(){ super(); } public void open(){ try { // Serial port initialize CommPortIdentifier portId = CommPortIdentifier.getPortIdentifier("COM6"); port = (SerialPort)portId.open("USB Serial Port", 2000); port.setSerialPortParams( 9600, // í êM롯ìx[bps] SerialPort.DATABITS_8, // ÉfÅ[É^ÉrÉbÉgêî SerialPort.STOPBITS_1, // ÉXÉgÉbÉvÉrÉbÉg SerialPort.PARITY_NONE // ÉpÉäÉeÉB ); port.setFlowControlMode(SerialPort.FLOWCONTROL_NONE); try{ port.addEventListener(this); port.notifyOnDataAvailable(true); in = port.getInputStream(); out = port.getOutputStream(); }catch(TooManyListenersException ex){ System.out.println("Error1: "+ex); } } catch (Exception e) { System.out.println("Error2: " + e); System.exit(1); } } public void close(){ try{ in.close(); out.close(); port.close(); }catch(Exception e){ System.out.println("close: "+e); } } public void read(){ try{ byte[] buffer; int temp = in.available(); if(temp>0){ System.out.println("temp: "+temp); buffer = new byte[temp]; temp = in.read(buffer); int num = 0; while(num<temp){ System.out.println("b "+num+": "+Integer.toHexString((byte)buffer[num])); num++; } } in.close(); }catch(Exception e){ System.out.println("error4: "+e); } } public static String toHex(byte[] digest) { StringBuilder sb = new StringBuilder(); for (byte b : digest) { sb.append(String.format("%1$02X", b)); } return sb.toString(); } public void write(byte data){ try{ out.write((byte)data); out.flush(); //ÉXÉgÉäÅ[ÉÄÇ∆COMÉ|Å[ÉgÇï¢ÌÇ¢ßÇÈèàóù }catch(Exception e){ System.out.println("port exception: "+e); } } public void run() { try { InputStreamReader isr = new InputStreamReader(System.in); BufferedReader br = new BufferedReader(isr); OutputStream out = port.getOutputStream(); boolean flagQuit = false; while (!flagQuit) { String input = br.readLine(); if (input.length() > 0) { if (input.equals(":quit")) break; input += "\r"; out.write(input.getBytes("US-ASCII")); } } port.close(); } catch (Exception e) { System.out.println("Error3: " + e); } } public void serialEvent(SerialPortEvent event) { if (event.getEventType() == SerialPortEvent.DATA_AVAILABLE) { read(); } } } ¥´°À®