Skip to content

ADC ​

analog_read ​

analog_read读取引脚电平模拟量。引脚须由config指令启用 analog 模拟输入功能,参考 ADC配置。

参数说明 ​

  • io_num [array] (!) 要读取的GPIO序号数组。

样例 ​

json
{
  "action": "analog_read",
  "io_num": [4, 5]
}

应答 ​

type-analog 返回读取的引脚电平模拟量。该消息类型与模拟量监视器消息一样,监视器消息只包含单一引脚数据,而analog_read可以一次读取多个引脚数据。

json
{
  "type": "analog",
  "data": [
    {
      "io_num": 4,
      "raw": 617,
      "voltage_mv": 529
    },
    {
      "io_num": 5,
      "raw": 1965,
      "voltage_mv": 1632
    }
  ]
}
  • type - 数据类型 analog(引脚电平模拟量)。
  • data - 数据对象数组。
    • io_num - 引脚的GPIO序号。
    • raw - 12-bit ADC原始采样值(0~4095)。
    • voltage_mv - 经过校准转换的mV单位电压值。