arduino esp32 adc 驱动

    //读取并返回GPIO2的模拟电压,单位,毫伏
//analogReadMilliVolts(2)
#define v_out_adc 2
#define i_in_adc  4


void setup() {
  // 初始化波特率
  Serial.begin(115200);
  analogReadResolution(12);            //一般设置值在1-16之间  
  analogSetAttenuation(ADC_11db);
  
  /*
衰减倍数
0dB衰减(ADC_ATTEN_0db)表示参考电压为1.1V
2.5dB衰减(ADC_ATTEN_2_5db)表示参考电压为1.5V
6dB衰减(ADC_ATTEN_6db)表示参考电压为2.2V
11dB衰减(ADC_ATTEN_11db)表示参考电压为3.9V
*/
 
}
 
void loop() {
  
  int analogValue_V_OUT = analogRead(2);
  int analogValue_I_OUT = analogRead(4);
  
  float out_v_vlot = (float(analogValue_V_OUT)/4096.0)*3.9;
  float out_i_volt = (float(analogValue_I_OUT)/4096.0)*3.9;
  
  float out_i_amp = (out_i_volt - 2.930 )*10;

  Serial.printf("\r\n");
  Serial.printf("out_v value is %d \r\n",analogValue_V_OUT);
  Serial.printf("out_v volt  is %f \r\n",out_v_vlot);            //需要校准 2.906v,显示3.502v   3.3---3.899048   1.0--1.09

  Serial.printf("\r\n");
  Serial.printf("out_i_volt is %f \r\n",out_i_volt);
  Serial.printf("out_i_amp  is %f \r\n",out_i_amp);          //中点电压为2.930v左右  100mv/a  20a 量程  电阻分压 920k-120k

  delay(500);
}

 

posted @ 2023-05-26 14:39  为鲸  阅读(133)  评论(0编辑  收藏  举报