- Back to Home »
- อาดุยโน่ , อาดุยโน่ วัดอุณหภูมิ , Arduinoไทย , Arduino ไทย , Arduino Thai , DS18B20 , One wire DS18B20 »
- Arduino UNO R3 Clone with One wire , DS18B20 Sketch to read address
Posted by : Unknown
วันอาทิตย์ที่ 10 สิงหาคม พ.ศ. 2557
DS18B20 เป็นหนึ่งในตระกูล DS18XXX ที่ปัจจุบัน เปลี่ยนเจ้าของจาก Dallas ไปสู่ MAXIM เรียบร้อยแล้วดาต้าชีต อยู่ที่นี่ DS18B20 data sheet by MAXIM ความพิเศษของชิบตระกูลนี้คือ มันมีตำแหน่งจำเพาะในตัวมันเองที่ไม่ซ้ำกัน เหมือน IP ของระบบอินเตอร์เน็ต ทำให้เวลาอ้างอิงตำแหน่ง สามารถอ้างอิงด้วยรหัสในตัวของมันเองได้เลย ซึ่งอะเมซิ่งมาก... 5555
![]() |
ต่อไว้ 3 ตัว แต่ละตัวมีรหัสที่แตกต่างกัน |
เว็บอ้างอิงสำหรับตอนนี้คือ
arduino.cc/Learning/OneWire โหลดไลบราลี่ล่าสุดจากที่นี่ได้เลย
วิธีการนำไปใช้มีหลายเว็บ ลองค้นๆ ดู ผมเก็บมาเป็นตัวอย่างบางเว็บ เช่น
arduino-1-wire-tutorial ,
เว็บนี้รวมทุกอย่างเกี่ยวกับ One wire กับชิบ DS18B20 (ผมใช้เว็บนี้เป็นแนวทาง) มีทั้งต่อตัวเดียว , ต่อหลายตัวแต่ใช้ PIN เดียว , ต่อหลายตัวๆ ละ PIN ถ้าขี้เกียจเปิดเยอะก็เว็บนี้แหละ ที่เดียวจบ Brick-Temperature-DS18B20
CODE สำหรับค้นหาว่าชิบแต่ละตัวรหัสคืออะไร ในรูปผมต่อไว้ 3 ตัว ก็จะแสดงผล 3 ตัว ทั้งๆ ที่ผมอ้างอิงตำแหน่ง PIN แค่อันเดียว ซึ่งในตัวอย่างคือ PIN 6 แต่จริงๆ ผมต่อแยกกัน คือ PIN 6,7,8 ซึ่งในโค้ดผมแจ้งแค่ว่าต่อกับ PIN 6 แต่มันดึงออกมาได้ครบทั้ง 3 ตัว....หุหุ นายแน่มาก
![]() | |||
ผมต่อ DS18B20 ไว้ 3 ตัว และแยกเข้าที่ PIN 6,7,8 แต่ในโค้ดแจ้งไว้แค่ PIN 6 |
โค้ดสำหรับดูรหัสของ CHIP
Test Sketch to read DS18B20 addresses
#include <OneWire.h>
/*-----( Declare Constants and Pin Numbers )-----*/
#define SENSOR_PIN 6 // Any pin 2 to 12 (not 13) and A0 to A5
/*-----( Declare objects )-----*/
OneWire ourBus(SENSOR_PIN); // Create a 1-wire object
void setup() /****** SETUP: RUNS ONCE ******/
{
Serial.begin(9600);
discoverOneWireDevices(); // Everything happens here!
}//--(end setup )---
void loop() /****** LOOP: RUNS CONSTANTLY ******/
{
// Nothing happening here
}
/*-----( Declare User-written Functions )-----*/
void discoverOneWireDevices(void) {
byte i;
byte present = 0;
byte data[12];
byte addr[8];
Serial.print("Looking for 1-Wire devices...\n\r");// "\n\r" is NewLine
while(ourBus.search(addr)) {
Serial.print("\n\r\n\rFound \'1-Wire\' device with address:\n\r");
for( i = 0; i < 8; i++) {
Serial.print("0x");
if (addr[i] < 16) {
Serial.print('0');
}
Serial.print(addr[i], HEX);
if (i < 7) {
Serial.print(", ");
}
}
if ( OneWire::crc8( addr, 7) != addr[7]) {
Serial.print("CRC is not valid!\n\r");
return;
}
}
Serial.println();
Serial.print("Done");
ourBus.reset_search();
return;
}
What are the best casinos to play in 2021?
ตอบลบWhich casinos offer slots? — Casino Sites. Best casino sites are those ventureberg.com/ that casinosites.one allow players to try a worrione.com game from septcasino anywhere. The most common https://septcasino.com/review/merit-casino/ online slots