Go Down

Topic: Oscilloscope Modification (Read 876 times) previous topic - next topic


I started by using the oscilloscope code for the Arduino and Processing from this website: http://accrochages.drone.ws/en/node/90 .  I then attached the voltage divider shown below.  Using it, the Arduino can measure approximately +-12V.  For a higher range, increase the value of the 3.9KOhm resistor.


That´s a fine rig! I just might try it out. Thanks for sharing!


Nov 25, 2008, 05:35 pm Last Edit: Nov 25, 2008, 05:39 pm by walterr Reason: 1
I finally had to try this one out. What fun! It was quick and easy to get going.

My first question was "Where is the scale?" I put a rechargeable battery across the input and wanted to know how close to charged it was, but without a scale I couldn't read the absolute voltage.

A few minutes later I had a version of the Processing code that draws a scale. (0-5) I also changed it so it doesn't erase the whole screen for every reading so I would not have to constantly redraw the scale. Now it only erases the line it is about to draw. I made the window much bigger too.

The code is pretty much off the cuff, could still use some polishing. See what you think:
Code: [Select]
* Oscilloscope
* Gives a visual rendering of analog pin 0 in realtime.
* This project is part of Accrochages
* See http://accrochages.drone.ws
* (c) 2008 Sofian Audry (info@sofianaudry.com)
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program.  If not, see <http://www.gnu.org/licenses/>.
import processing.serial.*;

Serial port;  // Create object from Serial class
int val;      // Data received from the serial port
int[] values;

void setup()
 size(1400, 700);
 // Open the port that the board is connected to and use the same speed (9600 bps)
 port = new Serial(this, Serial.list()[0], 9600);
 values = new int[width];

int getY(int val) {
 return (int)(val / 1023.0f * height) - 1;

void DrawScale()
 line(0, 0, 15, 0);
 line(0, (height/50), 5, (height/50));
 line(0, (height/50)*2, 5, (height/50)*2);
 line(0, (height/50)*3, 5, (height/50)*3);
 line(0, (height/50)*4, 5, (height/50)*4);
 line(0, (height/50)*5, 10, (height/50)*5);
 line(0, (height/50)*6, 5, (height/50)*6);
 line(0, (height/50)*7, 5, (height/50)*7);
 line(0, (height/50)*8, 5, (height/50)*8);
 line(0, (height/50)*9, 5, (height/50)*9);
 line(0, (height/5), 15, (height/5));
 line(0, (height/5)+(height/50), 5, (height/5)+(height/50));
 line(0, (height/5)+(height/50)*2, 5, (height/5)+(height/50)*2);
 line(0, (height/5)+(height/50)*3, 5, (height/5)+(height/50)*3);
 line(0, (height/5)+(height/50)*4, 5, (height/5)+(height/50)*4);
 line(0, (height/5)+(height/50)*5, 10, (height/5)+(height/50)*5);
 line(0, (height/5)+(height/50)*6, 5, (height/5)+(height/50)*6);
 line(0, (height/5)+(height/50)*7, 5, (height/5)+(height/50)*7);
 line(0, (height/5)+(height/50)*8, 5, (height/5)+(height/50)*8);
 line(0, (height/5)+(height/50)*9, 5, (height/5)+(height/50)*9);

 line(0, (height/5)*2, 15, (height/5)*2);
 line(0, (height/5)*2+(height/50), 5, (height/5)*2+(height/50));
 line(0, (height/5)*2+(height/50)*2, 5, (height/5)*2+(height/50)*2);
 line(0, (height/5)*2+(height/50)*3, 5, (height/5)*2+(height/50)*3);
 line(0, (height/5)*2+(height/50)*4, 5, (height/5)*2+(height/50)*4);
 line(0, (height/5)*2+(height/50)*5, 10, (height/5)*2+(height/50)*5);
 line(0, (height/5)*2+(height/50)*6, 5, (height/5)*2+(height/50)*6);
 line(0, (height/5)*2+(height/50)*7, 5, (height/5)*2+(height/50)*7);
 line(0, (height/5)*2+(height/50)*8, 5, (height/5)*2+(height/50)*8);
 line(0, (height/5)*2+(height/50)*9, 5, (height/5)*2+(height/50)*9);

 line(0, (height/5)*3, 15, (height/5)*3);
 line(0, (height/5)*3+(height/50), 5, (height/5)*3+(height/50));
 line(0, (height/5)*3+(height/50)*2, 5, (height/5)*3+(height/50)*2);
 line(0, (height/5)*3+(height/50)*3, 5, (height/5)*3+(height/50)*3);
 line(0, (height/5)*3+(height/50)*4, 5, (height/5)*3+(height/50)*4);
 line(0, (height/5)*3+(height/50)*5, 10, (height/5)*3+(height/50)*5);
 line(0, (height/5)*3+(height/50)*6, 5, (height/5)*3+(height/50)*6);
 line(0, (height/5)*3+(height/50)*7, 5, (height/5)*3+(height/50)*7);
 line(0, (height/5)*3+(height/50)*8, 5, (height/5)*3+(height/50)*8);
 line(0, (height/5)*3+(height/50)*9, 5, (height/5)*3+(height/50)*9);

 line(0, (height/5)*4, 15, (height/5)*4);
 line(0, (height/5)*4+(height/50), 5, (height/5)*4+(height/50));
 line(0, (height/5)*4+(height/50)*2, 5, (height/5)*4+(height/50)*2);
 line(0, (height/5)*4+(height/50)*3, 5, (height/5)*4+(height/50)*3);
 line(0, (height/5)*4+(height/50)*4, 5, (height/5)*4+(height/50)*4);
 line(0, (height/5)*4+(height/50)*5, 10, (height/5)*4+(height/50)*5);
 line(0, (height/5)*4+(height/50)*6, 5, (height/5)*4+(height/50)*6);
 line(0, (height/5)*4+(height/50)*7, 5, (height/5)*4+(height/50)*7);
 line(0, (height/5)*4+(height/50)*8, 5, (height/5)*4+(height/50)*8);
 line(0, (height/5)*4+(height/50)*9, 5, (height/5)*4+(height/50)*9);

void draw()
 while (port.available() >= 3)
   if (port.read() == 0xff)
     val = (port.read() << 8) | (port.read());
 for (int i=0; i<width-15-1; i++)
   values[i] = values[i+1];
 values[width-15-1] = val;
 for (int x=1; x<(width-15); x++)
   // Erase the line I'm about to draw
   line(width-1-x, 0, width-1-x, height);
   // Draw this reading
   line(width-x,   height-1-getY(values[x-1]),
        width-1-x, height-1-getY(values[x]));


The schematic for the voltage divider isn't clear enough for me to read it, is there a larger version?


Jan 02, 2009, 04:36 pm Last Edit: Jan 02, 2009, 04:51 pm by adclark Reason: 1
                         ------- (-  5V  +)---------
                         |                                 |
                         |                                /                            
                         |                                \                            
                          |                     10 M    /                            
                         |                                \                            
                         |                                /                            
            4 K        |            10 M              |
Input ---/\/\/\/--------------/\/\/\/--------------Output
                               \  1 K

Hope this helps


Jan 02, 2009, 05:02 pm Last Edit: Jan 02, 2009, 08:46 pm by AdderD Reason: 1
I'm curious... I recognize the normal voltage divider part of that circuit but why is there a 5v source and two 10M ohm resistors. What's that for? Seems like some sort of bias voltage.

It seems simpler to find the ratio between 12 and 5 and assume very low current draw. The ratio is 12/5. It might be safest, however, to go 12:4 in case of voltage spikes. In that case it's cutting the voltage to a third. That makes R2 twice the size of R1 which is easy enough to do. You can be pretty much assured of a low maximum current by using large resistors. Maybe 10k for R1 and 20K for R2?

Wait... I seem to recall that oscilliscopes need a really high resistance so that explains the 10M in line with the signal. Still confused about the 5V source...


I think there is a built in offset. The original post specified +-12V, so I think the offset makes -12v come in as 0, 0 come in as 2.5v and +12v come in as 5v.

Go Up