> For the complete documentation index, see [llms.txt](https://docs.petoi.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.petoi.com/thai/biboard/demo-applications/3.analog-digital-converter.md).

# 3.Analog-digital converter

Application of  ADC which is variable gain on BiBoard (ESP32)

คำสั่งแนะนำของ 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
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

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

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.petoi.com/thai/biboard/demo-applications/3.analog-digital-converter.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

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.
