Go Down

### Topic: Regarding giving sine wave to analogRead and viewing it on the serial plotter. (Read 286 times)previous topic - next topic

#### sruthisindu

##### Jun 14, 2018, 09:33 amLast Edit: Jun 14, 2018, 09:39 am by sruthisindu
I was trying to get familiar with the serial plotter so that i can use it in future for debugging purpose. But when I give a sine wave of 1Volt amplitude and a DC offset of 500mV(to avoid negative voltage) and 50Hz. As a beginning i wrote the the following few lines as code.

void setup()
{
Serial.begin(115200);
}

void loop()
{

delay(100);

}
Result obtained on the serial plotter is a constant voltage of 19. same was obtained on monitor too. What should be done to vie the sine wave on the plotter?

#### AWOL

Sampling a 50Hz signal at somewhat less than 10 Hz?
"Pete, it's a fool (who) looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.
I speak for myself, not Arduino.

#### vffgaston

on the serial plotter is a constant voltage of 19. same was obtained on monitor too. What should be done to vie the sine wave on the plotter?

What is "serial plotter"?

#### sruthisindu

Sorry but did not get you. How do I change the sampling rate and how's it 10 Hz?

#### sruthisindu

Serial plotter is a feature on Arduino available from versions 1.6.6. Real time sensor data plotting and debugging is possible using the plotter which plots the data displayed on serial monitor.

#### ard_newbie

An example of Serial Plotter with an UNO (select 250000 bauds in Serial monitor):

Code: [Select]
`const uint8_t sinesize = 128;const uint8_t _sinesize = sinesize - 1;volatile float sine[sinesize];void setup() {  Serial.begin(250000);  for (uint8_t i = 0; i<sinesize; i++) {    sine[i] = 200 * (sinf(i * 2 * PI / sinesize));  }}void loop() {  uint8_t var;  static uint8_t i;  delay(5);  i = (i + 1 ) & _sinesize;       // Discard all bits above sinesize  Serial.print((int)sine[i]);       // Print waveform  Serial.print(" ");                // print a blanck  var = (i + 170) & _sinesize;  Serial.print((int)sine[var]);     // Print waveform  Serial.print(" ");                // print a blanck  var = (var + 170) & _sinesize;  Serial.println((int)sine[var]);   // Println waveform}`

#### vffgaston

Hi,

OK. I haven't used it ever.

What the other forer says is that, as you delay by 100 (0.1 s), you are sampling the sin signal at the same place all the times every 5 cycles ( 5 * (1/50) =  0.1) so having the same value every time.

Try with a value not multiple of 20 (ms by cycle); 101 has to do.

Regards.

#### sruthisindu

#7
##### Jun 14, 2018, 10:18 amLast Edit: Jun 14, 2018, 10:19 am by sruthisindu
@ard_newbie: I understand what you are trying to say. To save the samples as array and then use them. But as mentioned in your program, sinesize acts as sampling frequency. But how do i divide the real time sine wave's frequency as you have done for created sine wave?. I need to use the sine wave plotted for further processing.
@vffgaston: Thank you for the tip.

#### AWOL

Quote
how's it 10 Hz?
Code: [Select]
`Serial.println(analogRead(A5));delay(100);`
"Pete, it's a fool (who) looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.
I speak for myself, not Arduino.

Go Up