Skip to content

Instantly share code, notes, and snippets.

Last active January 7, 2024 14:15
Show Gist options
  • Save chrismeyersfsu/3270419 to your computer and use it in GitHub Desktop.
Save chrismeyersfsu/3270419 to your computer and use it in GitHub Desktop.
Arduino Poor man's oscilloscope processing code
* Oscilloscope
* Gives a visual rendering of analog pin 0 in realtime.
* This project is part of Accrochages
* See
* (c) 2008 Sofian Audry (
* 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 <>.
import processing.serial.*;
Serial port; // Create object from Serial class
int val; // Data received from the serial port
int[] values;
float zoom;
void setup()
size(1280, 480);
// 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];
zoom = 1.0f;
int getY(int val) {
return (int)(height - val / 1023.0f * (height - 1));
int getValue() {
int value = -1;
while (port.available() >= 3) {
if ( == 0xff) {
value = ( << 8) | (;
return value;
void pushValue(int value) {
for (int i=0; i<width-1; i++)
values[i] = values[i+1];
values[width-1] = value;
void drawLines() {
int displayWidth = (int) (width / zoom);
int k = values.length - displayWidth;
int x0 = 0;
int y0 = getY(values[k]);
for (int i=1; i<displayWidth; i++) {
int x1 = (int) (i * (width-1) / (displayWidth-1));
int y1 = getY(values[k]);
line(x0, y0, x1, y1);
x0 = x1;
y0 = y1;
void drawGrid() {
stroke(255, 0, 0);
line(0, height/2, width, height/2);
void keyReleased() {
switch (key) {
case '+':
zoom *= 2.0f;
if ( (int) (width / zoom) <= 1 )
zoom /= 2.0f;
case '-':
zoom /= 2.0f;
if (zoom < 1.0f)
zoom *= 2.0f;
void draw()
val = getValue();
if (val != -1) {
Copy link

Hey there! I found your oscillosope very interesting and tweaked UI a bit to support vertical panning and scaling (numpad *,/,8,2) Please take a look:

Copy link

DemiM23 commented Sep 25, 2018

Hi! Is there any way to add labelled axes to the graph? I'm new to coding; just wanted to check!

Copy link

Hi. I don't know how I can suggest changes or make pull requests towards a gist.
Here is a version which:
Adds a pause button (p),
Switches to a speed of 2.000.000 (because why not)
Goes to the second serial port, as the first is used by BT on mac.

Copy link

What could I modify to add a second analog reading? I have been using this code to diagnose engine signals, but having the ability to compare two waveforms at once would be really cool! I have some light arduino/processing experience, but I can't see where to begin to add, say, reading and displaying A0 and A1

Thank you!

Copy link

hadoopmarc commented Jan 7, 2024

Inspirational and practical! See my personal gist with increased time resolution to 8000 samples per second, building on the Pause feature of zsolt-szilagyi. The images below show a 16 Hz blockwave in the original and the new version. Now it is no longer a poor man's oscilloscope but a usable scope for speech signals (3.1 kHz).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment