Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/arduino/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/kubernetes/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Arduino 即使引脚接地,analogRead()输出也会振荡_Arduino_Adc - Fatal编程技术网

Arduino 即使引脚接地,analogRead()输出也会振荡

Arduino 即使引脚接地,analogRead()输出也会振荡,arduino,adc,Arduino,Adc,我使用Arduino Micro读取5个flex传感器,并向串行监视器显示相应的角度。目前,我从analogRead()获得的振荡值存在一些问题。引脚是否连接到flex传感器或只是接地似乎无关紧要——输出振荡很大 最初,所有的数据都被读取和输出得很好,但我想要一个精确的100Hz采样频率,并尝试播放一些定时器中断。这就是这种振荡行为开始的时候。我回到了我的原始代码,它只使用了一些delay(),并简化为仅从两个管脚读取,但似乎无法摆脱振荡 我想我可能在尝试实现中断时弄乱了ADC的一些东西,但我不

我使用Arduino Micro读取5个flex传感器,并向串行监视器显示相应的角度。目前,我从analogRead()获得的振荡值存在一些问题。引脚是否连接到flex传感器或只是接地似乎无关紧要——输出振荡很大

最初,所有的数据都被读取和输出得很好,但我想要一个精确的100Hz采样频率,并尝试播放一些定时器中断。这就是这种振荡行为开始的时候。我回到了我的原始代码,它只使用了一些delay(),并简化为仅从两个管脚读取,但似乎无法摆脱振荡

我想我可能在尝试实现中断时弄乱了ADC的一些东西,但我不知道如何检查或修复它。请帮我想办法解决这个问题

下面是我的代码示例:


int fin;
const int input[5] = {A0,A1,A2,A3,A4}; // the analog pins

int flex[5]; // analog signal read
float flexV; 
float flexR[5]; // resistance on the 47k resistor
int angle[5]; // joint angles

const float VCC = 4.98; // Measured voltage of Arduino 5V line
// Measured resistance of the 47k resistors R1-R5
const float R[5] = {45900.0,45900.0,45900.0,45900.0,45900.0}; 

// Calibration values of resistance measured during straight phase and 90 deg bend phase
const float R_STRAIGHT[5] = {37651.0,37651.0,37651.0,37651.0,37651.0};
const float R_BEND[5] = {71783.0,71783.0,71783.0,71783.0,71783.0};

void setup() {

}

void loop() {

  for(fin = 0; fin <= 4; fin++) {
   flex[fin] = analogRead(input[fin]);
   flexV = flex[fin]*VCC/1023.0;
   flexR[fin] = R[fin] * (VCC/flexV - 1.0);
   angle[fin] = map(flexR[fin],R_STRAIGHT[fin],R_BEND[fin],0,90.0);
   delay(1);   
    }
    Serial.print(angle[0]);
    Serial.print(" ");
    Serial.print(angle[1]);
    Serial.print(" ");
    Serial.print(angle[2]);
    Serial.print(" ");
    Serial.print(angle[3]);
    Serial.print(" ");
    Serial.print(angle[4]);
    Serial.print(" ");
    Serial.println(millis());
    delay(6);   
}


内鳍;
常量int输入[5]={A0,A1,A2,A3,A4};//模拟引脚
int flex[5];//模拟信号读取
浮动柔性传动;
浮动挠曲器[5];//47k电阻器上的电阻
内角[5];//关节角
常数浮点VCC=4.98;//Arduino 5V线路的测量电压
//47k电阻器R1-R5的测量电阻
常量浮点R[5]={45900.045900.045900.045900.045900.045900.0};
//直线阶段和90度弯曲阶段测得的电阻校准值
常量浮点R_直[5]={37651.037651.037651.037651.037651.037651.0};
const float R_BEND[5]={71783.071783.071783.071783.071783.071783.0};
无效设置(){
}
void循环(){

对于(fin=0;finok,模拟读数通常会有一点振荡,这很正常!它们测量电压值,并且根据您使用的传感器,它们会振荡,这与使用万用表测量电压的想法相同。如果您想进一步了解这一点,ADC的conversor是一个很好的开始方式

为了防止这些振荡,你需要做的是开发一个滤波器。这可以在硬件或软件上完成。显然,软件是最简单的方法

我给你们的建议是使用一个平均值过滤器!这是一个简单的概念,你将在传感器的同时获得X个读数(数值会随着变化而上下变化),你将从中获得平均值

下面是一个使用您的代码的简单示例:

int fin;
const int input[5] = {A0,A1,A2,A3,A4}; // the analog pins

int flex[5]; // analog signal read
float flexV; 
float flexR[5]; // resistance on the 47k resistor
float average; //Variable to store the sum of measurements
int nSamples = 4;  //Number of reading you are going to use
int angle[5]; // joint angles

const float VCC = 4.98; // Measured voltage of Arduino 5V line
// Measured resistance of the 47k resistors R1-R5
const float R[5] = {45900.0,45900.0,45900.0,45900.0,45900.0}; 

// Calibration values of resistance measured during straight phase and 90 deg bend phase
const float R_STRAIGHT[5] = {37651.0,37651.0,37651.0,37651.0,37651.0};
const float R_BEND[5] = {71783.0,71783.0,71783.0,71783.0,71783.0};

void setup() {

}

void loop() {

  for(fin = 0; fin <= 4; fin++) {
   /* A new for here to make readings and store them on the average variable */
   for(int x = 0; x <= nSamples; x++){
    flex[fin] = analogRead(input[fin]);
    average = average + flex[fin];
   }
   /*Do de avarage and clear the value on this variable*/
   flex[fin] = average/nSamples;
   avarage = 0;
   flexV = flex[fin]*VCC/1023.0;
   flexR[fin] = R[fin] * (VCC/flexV - 1.0);
   angle[fin] = map(flexR[fin],R_STRAIGHT[fin],R_BEND[fin],0,90.0);
   delay(1);   
    }
    Serial.print(angle[0]);
    Serial.print(" ");
    Serial.print(angle[1]);
    Serial.print(" ");
    Serial.print(angle[2]);
    Serial.print(" ");
    Serial.print(angle[3]);
    Serial.print(" ");
    Serial.print(angle[4]);
    Serial.print(" ");
    Serial.println(millis());
    delay(6);   
}
int-fin;
const int input[5]={A0,A1,A2,A3,A4};//模拟管脚
int flex[5];//模拟信号读取
浮动柔性传动;
float flexR[5];//47k电阻器上的电阻
float average;//用于存储测量值总和的变量
int nSamples=4;//要使用的读取次数
int角度[5];//关节角度
const float VCC=4.98;//测得的Arduino 5V线路电压
//47k电阻器R1-R5的测量电阻
常量浮点R[5]={45900.045900.045900.045900.045900.045900.0};
//直线阶段和90度弯曲阶段测得的电阻校准值
常量浮点R_直[5]={37651.037651.037651.037651.037651.037651.0};
const float R_BEND[5]={71783.071783.071783.071783.071783.071783.0};
无效设置(){
}
void循环(){

对于(fin=0;fin从它的声音来看,我认为这与您的代码没有什么关系。您可能想尝试和。
显然,软件是最简单的方法。
简单的RC过滤器需要更少的努力,但由于这是如此,而不是Arduino堆栈交换或EE堆栈交换,它仍然是正确的答案。谢谢Nathan,我同意,我期待bi振荡的t。但这里我认为太多了-我的意思是,虽然我保持传感器弯曲,但输出在1023和我假设的正确值之间以某种周期性的方式波动。比如,如果每个第n个样本都是正确的,而其他样本只是读取1023。我理解平均滤波器的概念,并且我已经尝试了exa您建议的示例脚本。但是,这没有帮助。使用过滤器后,角度输出是一条平线,无论传感器是否弯曲。以及原始(柔性)输出仍然波动。老实说,我认为在尝试中断时,我把ADC搞砸了,但我不知道如何检查或修复它……好吧,@ForestApple,如果你不记得在哪里弄乱了中断,也许可以尝试新的安装。我可以重新安装吗?