このページはEtoJ逐語翻訳フィルタによって翻訳生成されました。

翻訳前ページへ


Setting the RTC in the nuElectronics datalogging 保護物,者 for Arduinos - ar3ne1rtc2 HOME  > >  ARDUINO MAIN PAGE > >  HINTS AND HOW-TOs > >  NuELEC DATALOG  t.o.c.    

Setting the RTC in the nuElectronics datalogging 保護物,者 for Arduinos

Page's URL: Ar3Ne1Rtc2.htm


This tutorial shows you how to 始める,決める the 保護物,者's real time clock, its DS1302. Don't be 脅すd by the "DS"... yes, this is a 半導体素子 from Dallas's 1-wire family , but you don't have to を取り引きする the usual 1-Wire programming things. You DON'T need the general Arduino "OneWire" library.

This "essay" is 天然のまま for the moment... sorry. You will need to 任命する/導入する the "sensor_pff" library from nuElectronics on your system for what is 述べるd here to work. At 3/13, the nuElectronics 場所/位置 had been unreachable for some time. I have put a copy of the "sensor_pff" library, as a .zip とじ込み/提出する, on my 場所/位置 for you to download. (Still there 3/21). I didn't look at it very closely, if you see things in it I should not be 分配するing, please let me know. Also, long bef 3/21, I did a tutorial on ソフトウェア libraries if you don't already know about 任命する/導入するing them.... it isn't hard. (I did it!) And I think that today it is even easier that it was when I did the tutorial.)

A 詳細(に述べる): You will see "one wire" and "one wire interface" in the nuElectronics documentation. This is not always connected with "1-Wire" (a Dallas trademark) at all, and even when you are connecting a 1-Wire 装置 to a nuElectronics "one wire" 関係 point, you won't often (ever?) get dragged into some of the more コンビナート/複合体 1-Wire 問題/発行するs. Don't get me wrong... I like 1-Wire... it is powerful. But to get everything you can from 1-Wire gets 危険に の近くに to Serious Work. neElectonics lets you use some of the (marvelous) 1-Wire 装置s without the work! (I've written a 簡潔な/要約する 公式文書,認める about the use of the 条件, if you want to read more.)

Basic code...

The に引き続いて is 実験(する)d, and 異なるs in some 尊敬(する)・点s from the 構成要素 nuElectronics has put online for your use.

When run, the に引き続いて will start spitting out (to the serial 監視する) a date/time about once per second. If you enter a line, STARTING WITH a t followed by a space, then, say 2010 5 10 1 12 15 0, and then 圧力(をかける) enter, you will, if you've entered a valid line, reset the date/time in the RTC. The spitting out of date/times will 再開する, with your new settings as the starting point. See the inline comments for the meaning of the string of digits, but 公式文書,認める in particular....

Here's the code....

/*SetRTC
6 Jly 2010
*/

//Yes... all three needed for に引き続いて...
#含む <avr/pgmspace.h>
#含む <sensor_pff.h>
#含む <DS1302.h>

DS1302 ds1302;
RTC rtc;
byte bLine;

char buff[128];	/* i/o 衝撃を和らげるもの */

//  === (米ソ間の)戦略兵器削減交渉 OF GET_LINE ===
//The に引き続いて looks worse than it is. It fetches a line
//of text from the serial 監視する, and puts it someplace
//for その上の use. You don't need to worry about the
//内部のs.

static 無効の get_line (char *buff, byte len)
{
  byte c;
  int idx = 0;

  for (;;) {//1 Start infinite 宙返り飛行... will only 出口 経由で "break"
	if(Serial.利用できる()){//2
		c = Serial.read();
		if (((byte)c >= ' ') && (idx < len - 1)) {//3
			buff[idx++] = c; Serial.print(c);
		}//3
	}else break;//2
  }//1 (ends "for...")
  buff[idx] = 0;
  Serial.print(c);
  Serial.print('\n');
}
//  === END OF GET_LINE ===


// === (米ソ間の)戦略兵器削減交渉 OF CONVERT_RTC ====
//As with "get_line", the に引き続いて looks worse than
//it is. It fetches a line of text from the
//serial 監視する, and puts it someplace for その上の
//use. You don't need to worry about the 内部のs.

/* 変える string "<year> <day in month> <month> <dow> <hour> <min> <sec>"
to RTC value, return 1 if successful. e.g., to 始める,決める RTC for...
2010, 5th of October, Monday, 12:15:00
... you enter....
t 2010 5 10 1 12 15 0
公式文書,認める the space after the t. Important.

("Monday=1" is 独断的な, up to you. "Day" numbers are 1-7.
  Make, say, Thursday "day 1"... if you wish to be 半端物!
  You can MIS-始める,決める a dow to, for instance, "0"... but
  rollover, 支援する to "1" will occur at midnight at the end of day "7")

The error checking isn't 100% reliable.
*/

byte convert_RTC(char *ptr, RTC* rtc_p)
{
  int val[7];
  byte i = 0;
  int value=0;

  while(*ptr++ && i<7)
	{
	if( *ptr >='0' &&  *ptr<='9' )
		value = value * 10 + *ptr - '0';
	else if (*ptr == ' '|| !*ptr){
		val[i++] = value;
		value = 0;
                }
         }
/* 変える string "<year> <day in month> <month> <dow> <hour> <min> <sec>"  to RTC value, return 1 if successful. e.g., to 始める,決める RTC for...
2010, 5th of October, Monday, 12:15:00
... you enter....
2010 5 10 1 12 15 0*/

  if (i==7) {
   		rtc_p->year = (unsigned int) val[0];
		rtc_p->mday = (byte) val[1];
		rtc_p->month = (byte) val[2];
		rtc_p->wday = (byte) val[3];
		rtc_p->hour = (byte) val[4];
		rtc_p->min = (byte)val[5];
		rtc_p->sec = (byte) val[6];
		return 1;
	}
   else return 0;
}
// === END OF CONVERT_RTC ====

無効の 体制/機構()
{
  byte res;
  bLine=6;
  Serial.begin(9600);
  Serial.println("RTC setting 公共事業(料金)/有用性.");
}

無効の 宙返り飛行()
{
  char *ptr;
  long p1, p2;
  byte res;
  unsigned short w;

  if(Serial.利用できる() == FALSE){
	  ds1302.gettime(&rtc);

          bLine++;
          if (bLine==7){
            Serial.println("Yr / day of month / month , day of week , time");
            bLine=0;
          }

          sprintf_P(buff, PSTR("%u/%u/%u, %u, %02u:%02u:%02u"), rtc.year, rtc.mday, rtc.month, rtc.wday, rtc.hour, rtc.min, rtc.sec);
	      Serial.println(buff);
          延期する(1002);
     }
  else
     {
          Serial.println();// Make gap, to show starting from new date/time
	  Serial.println();

          get_line(buff, sizeof(buff));
	  ptr = buff;

	  switch (*ptr++) {

          事例/患者 't' :
          /* 過程 line in form....
      t [<year> <day of month> <mon> <dow> <hour> <min> <sec>]
      .. which SETS rtc. Not all 無効の 命令(する) lines result
      in a "誤った" return from convert_RTC*/

          if (convert_RTC(ptr, &rtc)) {
  		ds1302.settime(&rtc);
             }
          //Needs(??) something like "else 報告(する)/憶測 命令(する) was
          //malformed?
	}
	  	}
}

The "get_line" 機能(する)/行事 has been 修正するd from what is in the nuElectronics デモs because, I think, I needed to do that to get it to work with the Arduino serial 監視する. For more 詳細(に述べる)s on that, and other general 詳細(に述べる)s, see my page about my working 環境.





-------------------

See Also: The Arduino programming course from Sheepdog Guides:

その上の to the Arduino ideas the page you are reading now will take you to, I have 地位,任命するd a 一連の essays which try to help you become a better Arduino programmer and engineer... but, for the best result, you will have to buckle 負かす/撃墜する and work your way through them in sequence. The "How To's" here can be 接近d in whatever order you like.


Feel 解放する/自由な to use this (警察などへの)密告,告訴(状) in programming courses, etc, but a credit of the source would be 高く評価する/(相場などが)上がるd. If you 簡単に copy the pages to other web pages you will do your readers a disservice: Your copies won't stay 現在の. Far better to link to these pages, and then your readers see up-to-date 見解/翻訳/版s. For those who care- thank you- I have 地位,任命するd a page with more (警察などへの)密告,告訴(状) on what copyright 権利放棄s I 延長する, and suggestions for those who wish to put this 構成要素 on CDs, etc.





編集(者)の Philosophy

See the discussion 近づく the 底(に届く) of the "最高の,を越す level" page covering the 本体,大部分/ばら積みの of my Arduino 出資/貢献s. There is (警察などへの)密告,告訴(状) there, too, about things like "May I copy your 構成要素?", and the system of とじ込み/提出する 指名するs I am trying to work to.


   Search this 場所/位置 or the web        力/強力にするd by FreeFind
 
  場所/位置 search Web search
場所/位置 地図/計画する    What's New    Search

The search engine is not intelligent. It 単に 捜し出すs the words you 明示する. It will not do anything sensible with "What does the 'could not 収集する' error mean?" It will just return 言及/関連s to pages with "what", "does", "could", "not".... etc.
In 新規加入 to the (警察などへの)密告,告訴(状) about the nuElectronics data 保護物,者 of which this page is part, I have other 場所/位置s with 構成要素 you might find useful.....

Tutorials about the 解放する/自由な database which is part of the 解放する/自由な Open Office.
Sequenced 始める,決める of tutorials on Pascal programming and electronics interfacing.
Some pages for programmers.
Using the 平行の port of a Windows computer.

If you visit 1&1's 場所/位置 from here, it helps me. They host my website, and I wouldn't put this link up for them if I wasn't happy with their service... although I was いっそう少なく than pleased the other day to have what I was doing interrupted by a telephone call from their sales team, trying to get me to 延長する my 関与. Sigh. Hardly a rare event, but I'd thought 1&1 were a bit classier that some of the people who have my telephone number.



広告 from page's editor: Yes.. I do enjoy 収集するing these things for you... hope they are helpful. However.. this doesn't 支払う/賃金 my 法案s!!! If you find this stuff useful, (and you run an MS-DOS or Windows PC) please visit my freeware and shareware page, download something, and 循環させる it for me? Links on your page to this page would also be 高く評価する/(相場などが)上がるd!

Click here to visit editor's Sheepdog ソフトウェア (tm) freeware, shareware pages.


And if you liked that, or want different things, here are some more pages from the editor of these tutorials....

Click here to visit the homepage of my biggest 場所/位置.

Click here to visit the homepage of Sheepdogsoftware.co.uk. 陳謝s if the "?Frmar3ne1rtc2" I 追加するd to that link 原因(となる)s your browser problems. Please let me know, if so?

Click here to visit editor's pages about using computers in Sensing and 支配(する)/統制する, e.g. 天候 logging.



To email this page's editor, Tom Boyd.... Editor's email 演説(する)/住所. Suggestions welcomed! Please 特記する/引用する the page's URL, "ar3ne1rtc2.htm".

Click to check for W3.org HTML validity tester Page has been 実験(する)d for 同意/服従 with INDUSTRY (not MS-only) 基準s, using the 解放する/自由な, 公然と accessible validator at validator.w3.org. Mostly passes.

AND passes... Click to check CSS validity


One last bit of advice: Be sure you know all you need to about spyware.

. . . . . P a g e . . . E n d s . . . . .