# 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)


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.aic-eec.com/general/development-on-crowpi/hardware-and-interfaces-usage-cli/lab-scan-i2c-bus-via-cli.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
