Hey all! I'm using serial communication with two analog inputs , voltage & current from the arduino to labview. When I run the program, the voltage & current signals show a smooth sine wave. But after around 30secs -1 minute, it will start to show spikes and as time passes, the spikes become more regular affecting the reading by a lot.
How can I make the signal more stable? How can I remove the spike? I don't see a problem with the hardware and I'm just serial printing the two values into labview. What is causing the spike?
I've attached the picture of the spikes. What can I do to solve this problem?
Here is my code:
const int analogIn0 = A0;
const int analogIn1 = A1;
float Voltage0 = 0;
float Voltage1 = 0;
int mVperAmp = 185;
float Amps = 0;
int ACSoffset = 2500;
int RawCurrentValue[250] ;
int RawVoltageValue[250] ;
void setup(){
Serial.begin(9600);
}
void loop(){
for (int k=0 ; k < 250 ; k += 1)
{
RawCurrentValue[k] = analogRead(analogIn0);
RawVoltageValue[k] = analogRead(analogIn1);
delay(2) ;
}
If you reset the Arduino shortly after the spikes start to appear do you immediately get another 30 secs of clean readings.
Have you a separate oscilloscope to view the signal that is going into the analog pins - in other words to verify that the spikes are happening outside the Arduino?
You mean the reset by pressing the button? If I stop then run the program, it will reset and the signal will spike again after 20+ secs.
Yeap! I tried the oscilloscope but I don't think there is spike?
Please help! My project deadline is this friday
Why would there be spikes specifically appearing after running the program for about 20secs?
Or is there a way or code to reset every time the samples are collected at 15secs?
Sounds like a buffer is overflowing inside LabView. You could put a small delay in the Arduino code to slow down the data rate and see if that improves things.
lamela:
Please help! My project deadline is this friday
Then you should have started earlier ...
You seem to be saying that for 20 secs the Arduino is reporting the correct values (the same as the oscilloscope) and after that it starts reporting incorrect values (i.e. different from the oscilloscope) ?
You need to post a schematic of your setup.
Have you read the Atmel datasheet to ensure that your circuit meets its requirements?
How many samples per second are you taking ?
What happens if you only read one channel?
Maybe it is switching between channels that is causing the problem - the Arduino has only one ADC.
...R
And what @Grumpy_Mike is saying should be the first thing to check.
Yes, it meets the requirement. I tried increasing & decreasing the delay but it won't work. The code is sampling 250-500 per sec for voltage & current.
Do you mean I just try reading one input at a time? What should I do?
Grumpy_Mike:
Please make sensible replies, you have addressed none of the questions you were asked.
What won't work?
What happened?
Did you write that code or did you take it from somewhere else?
I increased & decreased the delay using the arduino code but it still won't work..
Partially I wrote it but with reference I found online(similar threads & topics)
What do you think I should do?
When you say it will not work, do you actually mean it made no difference to the results you observed?
That code as you wrote it will not generate spikes, assuming you mean a spike is a sudden increase in voltage followed by normal operation. So your problem is outside your code.
We need more information about the nature of these spikes, can you post a picture?
If I were faced with this problem I would write it so that the Arduino produced a ramp up and down in place of reading anything. If that worked then your problem is with the input system and hardware. If that continued to produce spikes then your problem is with the LabView code.
Ok, I have attached the signal picture. I will see the readings on the arduino serial monitor first to see if there is any sudden change in value. If there is no issue, the problem is likely the LabView code, right? Because I'm certain the hardware is connected properly.
I will see how is it when I get back to my school's lab tomorrow! Thanks again!