|
このページはEtoJ逐語翻訳フィルタによって翻訳生成されました。 |
This page is 本気で 時代遅れの, 1/17.
In 12/16, I wrote a NEW explanation of using 1-Wire 気温 sensing 半導体素子s like the DS18B20 with an Arduino (or ESP8266, Teensy, etc!). Read that FIRST if you are new to the topic
However, for now, I am leaving the 残り/休憩(する) of this page here, in 事例/患者 you have read everything else, and are still 捜し出すing that "Eureka" moment which WILL come, if you just bang your 長,率いる against the 塀で囲む long enough, and come at it again and again from differnt angles!
This tutorial shows you how to 接近 a DS18B20 気温 sensor to an Arduino. It was written in 関係 with the nuelectronics datalogging 保護物,者, but you don't need a 保護物,者 to use the (警察などへの)密告,告訴(状) here.
This may not be the best tutorial on the web about using the Dallas 気温 sensors with Arduinos... but it does come with the sourcecode to make at least one of them accessible! And I have tried to keep the code simple, to help people who are making a start.
Don't be 脅すd by the "DS"... yes, this is a 半導体素子 from the Dallas 半導体 1-wire family , but you don't have to を取り引きする the usual 1-Wire programming things. You DON'T need the general Arduino 1-Wire library... or, for that 事柄, any extra libraries. (For using your 保護物,者 to read 気温 sensors.)
公式文書,認める that all the 保護物,者 is doing here is 供給するing a convenient mechanical "interface" between the sensor and the Arduino. What follows could be used even if you didn't have the 保護物,者.
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 可能性のある for 混乱させるing "one wire" and "1-Wire", if you are still nervous.)
Another 詳細(に述べる): This will work 正確に/まさに as written to read 気温s with one or more DS18B20s. If you have DS1820s (no "B" in 指名する), they connect to the 保護物,者 正確に/まさに as DS18B20s do, but you have to 修正する the code わずかに.
The DS18B20 is a member of Dallas's "1-Wire" family. That family is 有能な of clever things... like having 多重の sensors on a 選び出す/独身 pair of wires.
Doing clever things takes clever ソフトウェア. We, here, are going to use the 半導体素子 "crudely". But we won't be giving up the advantages it has which lead to 正確な 気温 readings. One "price" of our shortcut: we'll only be able to connect one 気温 sensor to each of the sockets of the nuelectronics datalogging 保護物,者 for the Arduino.
This shortcut doesn't change the fact that the DS18B20 (and DS1820) return the 気温 it is sensing in a 数字表示式の form. The DS18B20 datasheet says...
(I 港/避難所't looked into what 決意/決議 we are working at.)
Don't be downhearted by the "+/- 0.5°C 正確". I think the sensors are better than that might make you believe. Either skip the 残り/休憩(する) of this paragraph, or 圧力(をかける) on 用意が出来ている to not worry too much.... I believe that Dallas are 説 that if the sensor says, say, 15.0°, then it is in the 範囲 14.5° to 15.5°... but I also believe that any "error" will be 一貫した to a much tighter 基準. If the sensor 報告(する)/憶測s that the 気温 is now 15.2°, I believe you can 信用 the message that the 気温 has risen by 0.2°.... you just can't be sure 正確に/まさに what the 気温 is in 絶対の 条件.
The に引き続いて is the pinout for both the DS1820 and the DS18B20...
The nuelectronics datalogging 保護物,者 has a number of sockets around its 辛勝する/優位. In every 事例/患者, one of the outside pins carries 5v and the other outside pin carries 0v, or "ground". The middle pin or pins connect to one of the Arduino's analog pins. (Which can also be used for 数字表示式の i/o... a story for another day.)
Plug your DS18B20 sensor into P4 for the 目的s of this tutorial. P4 brings ADC0 to the 辛勝する/優位 of the 保護物,者. (Of course, you can plug your DS18B20 in どこかよそで, but that 要求するs a tiny modification of the code. When you are ready to consider using a different connector, you can find the (警察などへの)密告,告訴(状) you need on my "指名するing of parts" page.)
If you bought a DS18B20 module from nuelectronics, you just plug it in. If you have a connector for the sort of socket used, with a その上の 3 way socket on the far end of the connector, and a loose DS18B20, you can just "plug it in" to the socket on the end of the connector.... but you must get it the 権利 way up. (That's the bad news. The good news is that the order of the pins and the order of the signals on the connector make "plugging in" 平易な.)
IN THE ILLUSTRATION... to the 権利: From left to 権利, the wires are 黒人/ボイコット, white, red. Ground, data, 5v. 公式文書,認める which 味方する of the DS1820 is up.
BE CAREFUL: do not plug the 半導体素子 in backwards, "upside 負かす/撃墜する". (言及する to diagram) The "1-Wire 0v" pin (left 手渡す.. as drawn..) goes to the Arduino ground. The middle pin goes to the Arduino data pin. The (権利 手渡す)"See Text" pin goes to the 5v 供給(する)d by the Arduino. (We are not using the 半導体素子 in "parasitic 方式".
Bad news! You must ALSO connect a 4k7 ohm resistor (4700 ohms) between the middle pin of the sensor and the 5v line. Don't you wish you'd just bought the one made for you by nuelectronics? That has the resistor already in place!
Good news: In a fit of "poke and hope", when I couldn't find a 4k7 resistor, I tried a 10k resistor. It "worked". Reliably? I don't know. I will order some 4k7s, if need be!
More good news... I was even able to "attach" the resistor by 押すing it's leads 負かす/撃墜する the connector, と一緒に the DS18B20's leads. Not perfect. Not the "finished 製品"... but enough to 満足させる me that the thing 作品!!
(警察などへの)密告,告訴(状): If your sensor returns "85" (degrees C), it is "説" "Something is wrong." (85 is a rogue value
That's it! Your sensor is connected!
As I think I said どこかよそで, you do not need the Arduino OneWire libraries to read the sensor, or any other extra libraries for what is 現在のd in this tutorial.
The に引き続いて code reads the sensor once every 10 seconds, and 報告(する)/憶測s the 気温 sensed to the serial 監視する. 明白に, in a "serious" 使用/適用, you would be ありそうもない to tie up your big computer to make a "審査する" for the Arduino's 生産(高)... this program is just to show you how to read from the sensor. Once you've mastered that, what you do with the 気温 you are given is up to you!
公式文書,認める 1: If you change the "14" in the line "#define TEMP_PIN 14", you can change where the program looks for the 気温 sensor. In other words, the 気温 sensor(s) can be connected to the 保護物,者 wherever you want, as long as you 修正する the program to 許す for where you are connecting them.
追加するing a second, third, etc, sensor doesn't take much more than 追加するing a "#define TEMP_PIN2 15", "#define TEMP_PIN3 16", etc, and 追加するing an extra "read it" line and an extra "報告(する)/憶測 answer" line.
公式文書,認める 2: The three lines at and に引き続いて "See 公式文書,認める 2" are just "setting the 行う/開催する/段階" for the 宣言 of some subroutines later in the code. In another language, I would call these "今後 宣言s". Maybe that's the 権利 称する,呼ぶ/期間/用語 in C, too. ("Arduino-Speak" is a dialect of C).
/*ReadDS18B20
ver: 6 Jly 2010
THIS IS A FIRST DRAFT.... WORKS, but scheduled for 精密検査する.
Simple, simple 実験(する) of reading DS18B20
connected to nuelectronics.com datalogging 保護物,者.
See...
http://sheepdogguides.com/arduino/ar3ne1tt.htm
... for explanation of this code.
Code lightly adapted from code from nuelectronics.com*/
#define TEMP_PIN 14 //See 公式文書,認める 1, sheepdogguides..ar3ne1tt.htm
無効の OneWireReset(int Pin);//See 公式文書,認める 2
無効の OneWireOutByte(int Pin, byte d);
byte OneWireInByte(int Pin);
無効の 体制/機構() {
digitalWrite(TEMP_PIN, LOW);
pinMode(TEMP_PIN, INPUT); // 始める,決めるs the 数字表示式の pin as input (logic 1)
Serial.begin(9600);
//9600 to match the data 率 存在 used by the
//serial 監視する on my system, which is 始める,決める to
//the Arduino default. (見本 code published
//by nuelectronics used a faster baud 率.)
延期する(100);
Serial.print("気温 測定:\n");
}
無効の 宙返り飛行(){
int HighByte, LowByte, TReading, SignBit, Tc_100, Whole, Fract;
OneWireReset(TEMP_PIN);
OneWireOutByte(TEMP_PIN, 0xcc);
OneWireOutByte(TEMP_PIN, 0x44); // 成し遂げる 気温 転換, strong pullup for one sec
OneWireReset(TEMP_PIN);
OneWireOutByte(TEMP_PIN, 0xcc);
OneWireOutByte(TEMP_PIN, 0xbe);
LowByte = OneWireInByte(TEMP_PIN);
HighByte = OneWireInByte(TEMP_PIN);
TReading = (HighByte << 8) + LowByte;
SignBit = TReading & 0x8000; // 実験(する) most sig bit
if (SignBit) // 消極的な
{
TReading = (TReading ^ 0xffff) + 1; // 2's comp
}
Tc_100 = (6 * TReading) + TReading / 4; // multiply by (100 * 0.0625) or 6.25
Whole = Tc_100 / 100; // separate off the whole and わずかの 部分s
Fract = Tc_100 % 100;
if (SignBit) // If its 消極的な
{
Serial.print("-");
}
Serial.print(Whole);
Serial.print(".");
if (Fract < 10)
{
Serial.print("0");
}
Serial.print(Fract);
Serial.print("\n");
延期する(5000); // 5 second 延期する. Adjust as necessary
}
無効の OneWireReset(int Pin) // reset. Should 改善する to 行為/法令/行動する as a presence pulse
{
digitalWrite(Pin, LOW);
pinMode(Pin, OUTPUT); // bring low for 500 us
delayMicroseconds(500);
pinMode(Pin, INPUT);
delayMicroseconds(500);
}
無効の OneWireOutByte(int Pin, byte d) // 生産(高) byte d (least sig bit first).
{
byte n;
for(n=8; n!=0; n--)
{
if ((d & 0x01) == 1) // 実験(する) least sig bit
{
digitalWrite(Pin, LOW);
pinMode(Pin, OUTPUT);
delayMicroseconds(5);
pinMode(Pin, INPUT);
delayMicroseconds(60);
}
else
{
digitalWrite(Pin, LOW);
pinMode(Pin, OUTPUT);
delayMicroseconds(60);
pinMode(Pin, INPUT);
}
d=d>>1; // now the next bit is in the least sig bit position.
}
}
byte OneWireInByte(int Pin) // read byte, least sig byte first
{
byte d, n, b;
d=0;//This 批判的な line 追加するd 04 Oct 16
//I hate to think how many derivatives of
//this code 存在する どこかよそで on my web pages
//which have NOT HAD this. You may "get away"
//with not setting d to 無 here... but it
//is A Very Bad Idea to 信用 to "hidden"
//initializations!
//The 事柄 was brought to my attention by
//a 肉親,親類d reader who was THINKING OF YOU!!!
//If YOU 位置/汚点/見つけ出す an error, please 令状 in, bring
//it to my attention, to save the next person
//grief.
for (n=0; n<8; n++)
{
digitalWrite(Pin, LOW);
pinMode(Pin, OUTPUT);
delayMicroseconds(5);
pinMode(Pin, INPUT);
delayMicroseconds(5);
b = digitalRead(Pin);
delayMicroseconds(50);
d = (d >> 1) | (b<<7); // 転換 d to 権利 and 挿入する b in most sig bit position
}
return(d);
}So! There you have it. Delightfully simple. I was using 1-Wire 気温 sensors LONG before I started using the Arduino, and I can 保証する you that it is not always this 平易な!
The ideas above are taken just a little その上の in my next "How To" essay, in which I explain how to connect two (or more) DS18B20s to a microprocessor, e.g. Arduino.
I have a "FarWatch" 測候所 online which reads many things with 1-Wire 半導体素子s. I also have a page explaining how that 測候所 was 始める,決める up.
その上の 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.
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.
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.
Click here to visit editor's Sheepdog ソフトウェア (tm) freeware, shareware pages.
Click here to visit the homepage of my biggest 場所/位置.
Click here to visit the homepage of Sheepdogsoftware.co.uk. 陳謝s if the "?Frmar3ne1tt" I 追加するd to that link 原因(となる)s your browser problems. Please let me know, if so?
Page has been 実験(する)d for 同意/服従 with INDUSTRY (not MS-only) 基準s, using the 解放する/自由な, 公然と accessible validator at validator.w3.org. Mostly passes.
....... P a g e . . . E n d s .....