space
space
space
 
พฤษภาคม 2562
 
 1234
567891011
12131415161718
19202122232425
262728293031 
space
space
5 พฤษภาคม 2562
space
space
space

Code หา Address I2C

วิธีหา Address I2C สำหรับโมดูลที่อาจจะไม่มีการแสดง Adress ที่ชัดเจน เรามีผู้เขียน Sketch ชื่อคุณ Nick Gammon เพื่อทดสอบหา Address ดังนี้ครับ

// I2C Scanner
// Written by Nick Gammon
// Date: 20th April 2011

#include

void setup() {
Serial.begin (115200);

// Leonardo: wait for serial port to connect
while (!Serial)
{
}

Serial.println ();
Serial.println ("I2C scanner. Scanning ...");
byte count = 0;

Wire.begin();
for (byte i = 8; i < 120; i++)
{
Wire.beginTransmission (i);
if (Wire.endTransmission () == 0)
{
Serial.print ("Found address: ");
Serial.print (i, DEC);
Serial.print (" (0x");
Serial.print (i, HEX);
Serial.println (")");
count++;
delay (1); // maybe unneeded?
} // end of good response
} // end of for loop
Serial.println ("Done.");
Serial.print ("Found ");
Serial.print (count, DEC);
Serial.println (" device(s).");
} // end of setup

void loop() {}

โดยการ copy Sketch นี้อัพโหลดไปที่ Board Arduino

ต่อสายอุปกรณ์ตามนี้
A4 = SDA
A5 = SCL




 

Create Date : 05 พฤษภาคม 2562
0 comments
Last Update : 5 พฤษภาคม 2562 14:48:06 น.
Counter : 388 Pageviews.

ชื่อ :
Comment :
  *ใช้ code html ตกแต่งข้อความได้เฉพาะสมาชิก
 

space

Microtonic
Location :


[ดู Profile ทั้งหมด]

ฝากข้อความหลังไมค์
Rss Feed
ผู้ติดตามบล็อก : 1 คน [?]






space
space
[Add Microtonic's blog to your web]
space
space
space
space
space