# LAB: Scan I2C bus via CLI

## **Usage I2C** via CLI

&#x20;   โดยปกติ Raspberry Pi  OS จะเปิด interface ของ I2C ไว้อยู่แล้ว แต่เพื่อความมั่นใจให้ทำการตั้งค่า enable interface I2C อีกครั้งโดยใช้ command config  ดังนี้

```typescript
sudo raspi-config 
```

&#x20;    ไปที่ Interface Options > กด Enter >I2C >กด Enter >Yes>OK >กดลูกศรเลื่อนลงไปยังคำว่า Finish แล้วกด Enter&#x20;

\
![](https://paper-attachments.dropbox.com/s_EEE636D9526C071EE54566BA4F9747132A170266CA6042B3ED8970E1C8CEED04_1660635885907_image.png)![](https://paper-attachments.dropbox.com/s_EEE636D9526C071EE54566BA4F9747132A170266CA6042B3ED8970E1C8CEED04_1660635998292_image.png)\
![](https://paper-attachments.dropbox.com/s_EEE636D9526C071EE54566BA4F9747132A170266CA6042B3ED8970E1C8CEED04_1660636058289_image.png)![](https://paper-attachments.dropbox.com/s_EEE636D9526C071EE54566BA4F9747132A170266CA6042B3ED8970E1C8CEED04_1660636082485_image.png)![](https://paper-attachments.dropbox.com/s_EEE636D9526C071EE54566BA4F9747132A170266CA6042B3ED8970E1C8CEED04_1660636141292_image.png)

**คำสั่ง:** หา I2C bus ที่มีทั้งหมด

```typescript
i2cdetect -l
```

![](https://paper-attachments.dropbox.com/s_EEE636D9526C071EE54566BA4F9747132A170266CA6042B3ED8970E1C8CEED04_1660637109157_image.png)

**คำสั่ง:** scan หา address ของอุปกรณ์ที่ต่ออยู่กับ I2C bus 1 &#x20;

```typescript
i2cdetect -y 1
```

![](https://paper-attachments.dropbox.com/s_EEE636D9526C071EE54566BA4F9747132A170266CA6042B3ED8970E1C8CEED04_1660637266999_image.png)

&#x20;    จากภาพสามารถ scan หา address ได้ 3 ตัว คือ 0x21, 0x5c และ 0x70 สามารถใช้คำสั่ง scan นี้ในการตรวจสอบการเชื่อมต่ออุปกรณ์ I2C bus เบื้องต้นได้

Date: May 2023

Author: Soontree Jaikhong (AIC-Researcher)

Author: Thanaluk Pranekunakol (AIC-Researcher)
