# 3.Analog-digital converter

คำสั่งแนะนำของ ADC บน BiBoard&#x20;

พิน 34, 35, 36 และ 39 ของโมดูล ESP32 รองรับอินพุตเท่านั้น เรากำหนดค่าให้เป็นพอร์ตอินพุตแบบอะนาล็อกบน BiBoard ซึ่งทำให้สะดวกสำหรับนักพัฒนาในการเชื่อมต่อเซ็นเซอร์เท้า 4 ตัว

การใช้งานตัวแปลงสัญญาณอนาล็อกเป็นดิจิตอล (ADC) บน BiBoard นั้นเหมือนกับ Arduino UNO พื้นฐาน แต่ความแม่นยำนั้นสูงกว่า (12 บิต UNO คือ 10 บิต) และมีการเพิ่มตัวขยายสัญญาณที่ตั้งโปรแกรมได้เพื่อให้ ADC ทำงานในช่วงที่ดีที่สุด

เมื่อป้อนสัญญาณแรงดันไฟฟ้า 1V หากใช้การเข้าถึง 12 บิตตามการกำหนดค่าปกติ แรงดันอ้างอิงจะเท่ากับแรงดันแหล่งจ่ายไฟ (3.3V): เอาต์พุตที่สอดคล้องกันคือ 0\~1241 ส่วนใหญ่ของช่วง ADC จะเสียเปล่า ทำให้ได้ข้อมูลที่ไม่ถูกต้อง เมื่อเรากำหนดค่าอัตราขยายที่ตั้งโปรแกรมได้ เราสามารถทำให้สัญญาณอินพุต 1V เติมเต็มช่วง ADC เกือบทั้งหมด และความแม่นยำและความละเอียดจะดีขึ้นอย่างมาก

การสาธิตนี้ใช้ 4 อินพุต กำหนดค่าตามลำดับเป็น: อัตราขยายเดซิเบล 0/2.5/6/11 ควรสังเกตว่าการกำหนดค่าเริ่มต้นของ ESP32 Arduino คืออัตราขยาย 11 เดซิเบล

เราใช้ "analogSetPinAttenuation(PIN\_NAME, attenuation)" เพื่อกำหนดค่าอัตราขยายของพินอินพุตเดี่ยว หรือใช้ "analogSetAttenuation(attenuation)" เพื่อกำหนดค่าอัตราขยายของพินอินพุตแบบอะนาล็อกทั้งหมด

```c
// Ain 34 - 0dB Gain - ADC_0db
analogSetPinAttenuation(34, ADC_0db);

// Ain 35 - 2.5dB Gain - ADC_2_5db
analogSetPinAttenuation(35, ADC_2_5db);

// Ain 36 - 6dB Gain - ADC_6db
analogSetPinAttenuation(36, ADC_6db);

// Ain 39 - 11dB Gain - ADC_11db    (default)
analogSetPinAttenuation(39, ADC_11db);
```

ในการทดสอบจริง เมื่อป้อนแรงดันไฟฟ้ามาตรฐาน 1V ค่า ADC จะเป็น: 3850/2890/2025/1050 ในการผลิตในอนาคต ช่วง ADC สามารถเปลี่ยนแปลงได้โดยการเปลี่ยนอัตราขยายของ ADC โดยไม่ต้องเปลี่ยนแหล่งจ่ายแรงดันอ้างอิง


---

# 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.petoi.com/thai/biboard/demo-applications/3.analog-digital-converter.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.
