> 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/chinese/biboard/li-cheng/mo-ni-shu-zi-zhuan-huan-qi.md).

# 3. 模拟-数字转换器

BiBoard（ESP32）可变增益ADC的应用

BiBoard ADC使用说明

ESP32模块34，35，36和39脚仅支持输入，在BiBoard上我们将其配置成模拟输入端口，方便开发者们连接4个足底传感器。

BiBoard模拟输入模-数转换器（ADC）的用法和基础的Arduino UNO相同，但是精度更高（12位，UNO为10位），同时增加了可编程增益放大器，可以让ADC工作在最佳的范围内。

当输入1V电压信号时，如果按照普通配置为12bit访问，参考电压等于电源电压（3.3V）：对应的输出为0～1241，ADC很大一部分量程会被浪费掉，造成数据不精确。当我们配置成可编程增益的时候，就可以让1V的输入信号填满几乎整个ADC量程，精度和分辨率大大提高。

我们的例程使用4个输入，分别配置成：0/2.5/6/11分贝的放大增益，需要注意的是ESP32 Arduino默认配置的是11分贝的放大增益。

我们使用“analogSetPinAttenuation(PIN\_NAME, attenuation)”来配置单个输入引脚的增益，也可以使用“analogSetAttenuation(attenuation)”来配置全部模拟输入引脚的增益。

```
// 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/chinese/biboard/li-cheng/mo-ni-shu-zi-zhuan-huan-qi.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.
