Ard_O_Scope: An Extremely Simple Voltage Visualizer (oscilloscope) for Arduino

12 07 2010


While I was investigating some noise-filtering and smoothing algorithms for analogRead in Arduino, I realized that I needed some way to test the influence of some parameters over a certain signal. I usually do this just by sending the reading of a potentiometer through the serial port of the Arduino and see how these number changed while sweeping my potentiometer.

But this is not a very graphical way to see a signal, so I wanted something similar to an oscilloscope, to to see the data I was pushing through the serial port in a comfortable way. So with only some lines of code I have created a nice arduino voltage visualizer, in the Old School way: It just prints to the Arduino serial console a real time bar chart with the readings of your input, with a refresh frequency of about 350 samples per second (When using 115200 bauds). No comparison with an oscilloscope, but useful when measuring inputs from potentiometers or LDRs…

Watch it in action after the break!

Here is an example of the output of the program:

--------------------------
Extremely Simple Voltage
visualizer for Arduino
-------------------------- 

Created by Sergio Vilches
vlxs.wordpress.com
--------o                 1.67 V
--------o                 1.50 V
-------o                  1.38 V
------o                   1.26 V
------o                   1.11 V
-----o                    0.92 V
----o                     0.72 V
---o                      0.55 V
--o                       0.42 V
--o                       0.37 V
-o                        0.37 V
-o                        0.39 V
-o                        0.73 V
--o                       1.46 V
-----o                    2.39 V
--------o                 3.06 V
-----------o              3.46 V
--------------o           3.68 V
----------------o         3.93 V
-----------------o        4.22 V
-------------------o      4.45 V
--------------------o     4.55 V
---------------------o    4.50 V
---------------------o    4.12 V
--------------------o     3.59 V
------------------o       2.94 V
----------------o         2.35 V
-------------o            1.70 V

And here is the sketch:

/*
                          Ard_o_Scope
                          
      Extremely Simple Voltage Visualizer (oscilloscope) for Arduino
  
  This program shows the (smoothed) reading of analog input (0) as an horizontal bar chart in the Serial Monitor of Arduino.

  The circuit:
  Analog sensor (potentiometer will do) attached to analog input 0

  Created 12 July 2010
  By Sergio Vilches  

  http://vlxs.wordpress.com
  
  This sketch is in the public domain. Feel free to modify or distribute it. Have fun!

*/

int val;
int ScreenWidth = 25;  // Use this parameter to choose the maximum number of characters that will be sent for each reading
                       // (the number of "-"). Please note that the sampling frequency will decrease when using a large value.

float smoothingFactor = 0.5; //Vary this value from 0 (no smoothing of the signal) to 0.99 (a lot of smoothing). 0.8 works well

void setup()
{
  Serial.begin(9600);
  val = analogRead(0) * ScreenWidth / 1024.0;

  //Let's print a heading
  delay(500);
  Serial.println("--------------------------");
  Serial.println("Extremely Simple Voltage");
  Serial.println("visualizer for Arduino");
  Serial.println("--------------------------");
  Serial.println();
  Serial.println("Created by Sergio Vilches");
  Serial.println("vlxs.wordpress.com");
  delay(1500);
}

void loop()
{
  val = (smoothingFactor * val + (1-smoothingFactor) * analogRead(0) * ScreenWidth / 1024.0) ;  //This line smooths the data

  for (int i = 0 ; i < val ; i++)    //We print as many "-" as val
    Serial.print("-");

  Serial.print("o");    //We print the marker

  for (int i = 0 ; i < ScreenWidth - val ; i++)
    Serial.print(" ");

  Serial.print(analogRead(0)*5/1024.0);  //And the voltage of the reading
  Serial.println(" V");
  }

Here is the result of measuring the voltage output from a slider, using a serial speed of 9600 bauds. You can improve the sampling speed by changing this value in void setup, setting Serial.begin(115200).

Advertisement

Acciones

Información

2 respuestas

13 07 2010
standardbalboa

Ehhh cuando tienes los campos? Cierra ya y bajate un dia :D

(el Click here if you want to see my blog in English! empieza a perder sentido XDDD)

14 07 2010
vilxes91

Que va!
Yo creo que google translate traduce mejor que yo al inglés!!
Y no te preocupes que bajo pronto!

Saludos!

Deja un comentario

Fill in your details below or click an icon to log in:

Logo de WordPress.com

You are commenting using your WordPress.com account. Log Out / Cambiar )

Twitter picture

You are commenting using your Twitter account. Log Out / Cambiar )

Facebook photo

You are commenting using your Facebook account. Log Out / Cambiar )

Connecting to %s




Seguir

Get every new post delivered to your Inbox.