Pages: [1]   Go Down
Author Topic: Help with Serial Monitor Read-Outs  (Read 518 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 13
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I am working on a project to read ac voltages using the Arduino Uno R3.

I would like to increase the number of read-outs on the serial monitor as at the moment I get about five values in each cycle.

I have tried increasing the communication speed but that prints out gibberish
I have also tried changing the delay which doesnt affect the number of reading serial monitor prints out.

Below is my current code.

    const float analogInPin = A0; 
    //const float analogOutPin = A5;
    float sensorValue = 0;       
    float voltage = 0;       
    float sensor = 0;

    void setup()

 {
   Serial.begin(9600); // initialize serial communications at 9600 bps
 }

   void loop()

{
   sensor = analogRead(0);
   voltage = (sensor*5)/1024;// the sensor value divided by the voltage/sensor ratio
   //outputValue = map(voltage, 0, 1023);
  //analogWrite(analogOutPin, voltage);
   Serial.print("AC Voltage = " );                       
   Serial.println(voltage);   

   delay(3.125*0.000001);                   
}
Logged

East Anglia (UK)
Offline Offline
Faraday Member
**
Karma: 88
Posts: 3448
May all of your blinks be without delay()
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

The output to the serial monitor is relatively slow.  You can increase the speed of the serial link by changing the value in the Serial.begin function (up to 115200) but you must also change the speed to match in the serial monitor window itself - bottom right of the screen.  You could also speed up the repeat rate of printing by sending less characters each time.

Whether this will help you display more values I don't know.
Logged

Please do not send me PMs asking for help.  Post in the forum then everyone will benefit from seeing the questions and answers.

UK
Offline Offline
Shannon Member
****
Karma: 183
Posts: 11114
-
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

The delay calls are pointless - get rid of them. (delay() takes an integer value, not a float; when the float value is cast to an int it will be rounded to zero.)

What do you mean by 'cycle'? I don't suppose you mean a 50Hz AC cycle, since that would have resulted in far more output than you could fit down a 9600bps stream.
Logged

I only provide help via the forum - please do not contact me for private consultancy.

Offline Offline
Newbie
*
Karma: 0
Posts: 13
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thank you on the note on about the delay. When I say cycle I mean in a period the serial monitor reads out five values. I would like to see far more than 5.
Logged

Seattle, WA USA
Online Online
Brattain Member
*****
Karma: 547
Posts: 45952
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
When I say cycle I mean in a period the serial monitor reads out five values. I would like to see far more than 5.
In what period? A week? I'm sure the Arduino is capable of more than 5 readings a week.

If the period is 5 microseconds, you may well be SOL.

Code:
   voltage = (sensor*5)/1024;// the sensor value divided by the voltage/sensor ratio
Isn't integer math wonderful? It is, but it probably is not what you want. Using 5.0 and 1024.0 will produce results that are closer to what you expect, I'd guess.

Quote
I have tried increasing the communication speed but that prints out gibberish
Did you change the speed in the receiver, too?
Logged

UK
Offline Offline
Shannon Member
****
Karma: 183
Posts: 11114
-
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

When I say cycle I mean in a period the serial monitor reads out five values. I would like to see far more than 5.

That's no help at all. Let me ask it another way: How long is the 'cycle' or 'period' in milliseconds?
Logged

I only provide help via the forum - please do not contact me for private consultancy.

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 237
Posts: 24276
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Or, put it another way, at 9600 baud, it takes 1.04ms to transmit a character.
If you want to send ASCII decimal values, and analogRead gives a result with up to four decimal digits, so you need at least five characters (four digits plus separator) per readings.
Five readings per cycle gives 25 characters = 26ms, or a touch over 38Hz.
Logged

"Pete, it's a fool 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.

Offline Offline
Newbie
*
Karma: 0
Posts: 13
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

When I say cycle I mean in a period the serial monitor reads out five values. I would like to see far more than 5.

That's no help at all. Let me ask it another way: How long is the 'cycle' or 'period' in milliseconds?

I am working a frequency range of 0 to 60 Hz. at 10Hz for example the period is 0.1 second. Does that help ?

This is the type of data from the serial monitor. I would like to see more values in-between each period.
5
4.03
2.43
5
4.79
2.82
5
5
2.95
3.9
5
3.36
2.51
5
3.69
2.25
5
3.99
2.41
5
4.78
2.81
5
5
2.92
3.93
5
3.36
2.54
5
3.67
2.24
5
3.98
2.4
5
4.77

I have attached the input and output data.

* Sampling rate 041212.xlsx (98.49 KB - downloaded 2 times.)
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 13
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
When I say cycle I mean in a period the serial monitor reads out five values. I would like to see far more than 5.
In what period? A week? I'm sure the Arduino is capable of more than 5 readings a week.

If the period is 5 microseconds, you may well be SOL.

Code:
   voltage = (sensor*5)/1024;// the sensor value divided by the voltage/sensor ratio
Isn't integer math wonderful? It is, but it probably is not what you want. Using 5.0 and 1024.0 will produce results that are closer to what you expect, I'd guess.

Quote
I have tried increasing the communication speed but that prints out gibberish
Did you change the speed in the receiver, too?

Yes I have tried changing the communication speed at the reciever end, but this is in the serial monitor. I changed the communication speed in the code and in the serial monitor to match.
Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 237
Posts: 24276
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
3.69<cr><lf>
Six characters, 32Hz maximum at 9600.
Logged

"Pete, it's a fool 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.

Offline Offline
Newbie
*
Karma: 0
Posts: 13
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
3.69<cr><lf>
Six characters, 32Hz maximum at 9600.

Sorry but I dont understand what you mean. Is even possible to read/collect/record more that 5 data points when using the ADC ?
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 13
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

 I would like to collect at least 20 readingw in each cycle where my maximum frequency is 60Hz. Is that possible ?
Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 237
Posts: 24276
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
I would like to collect at least 20 readingw in each cycle where my maximum frequency is 60Hz. Is that possible ?
20 * 60 = 1200.
Sample rate using standard analogRead is around 9500 samples per second.
So, yes, you can collect that many samples, though you'd be hard-pressed to display them in real-time, and certainly not a 9600 baud.
Logged

"Pete, it's a fool 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.

UK
Offline Offline
Shannon Member
****
Karma: 183
Posts: 11114
-
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I would like to collect at least 20 readingw in each cycle where my maximum frequency is 60Hz. Is that possible ?

Yes, but you would need to collect and store them locally and then send them over the serial port later - the serial port is not fast enough to transfer the sample data in real time.
Logged

I only provide help via the forum - please do not contact me for private consultancy.

Pages: [1]   Go Up
Jump to: