Hackster is hosting Hackster Holidays, Ep. 6: Livestream & Giveaway Drawing. Watch previous episodes or stream live on Monday!Stream Hackster Holidays, Ep. 6 on Monday!
Juan AlvarezTimster
Published © GPL3+

Draw Anything on Your Oscilloscope

Ever wanted to display any hand-drawn image on your fancy oscilloscope? Well, now you can!

IntermediateFull instructions provided2 hours9,185
Draw Anything on Your Oscilloscope

Things used in this project

Hardware components

Resistor 1k ohm
Resistor 1k ohm
Any resistor value is acceptable as long as you keep the ratios of the DAC correct. You don't need 50 if you have 2k resistors. Or two times the value of your chosen resistor.
×50
Arduino UNO
Arduino UNO
Or STM32 "blue pill" or "black pill".
×1

Software apps and online services

Arduino IDE
Arduino IDE

Story

Read more

Schematics

8 Bit R2R schematic with different values for R and 2R

8 bit R2R schematic with same resistor values for all

6 bit R2R schematic using the same value of resistors for all

6 bit R2R schematic using different values of resistors

Code

Arduino code

Arduino
Arduino sketch to use in an Arduino Uno or Nano board
const byte FIGURE_DELAY = 1; // trace delay in uS. adjust if needed
const int NUM_POINTS = 87;// number of XY points in figure

// x and y coordinates to plot 
byte x_points[NUM_POINTS] = {106,106,105,104,103,102,101,100,99,98,97,96,95,94,93,92,91,90,90,89,88,87,87,87,86,86,86,86,87,89,90,91,93,95,97,99,101,102,102,104,104,105,105,106,106,106,106,106,106,108,109,110,112,113,115,117,119,121,122,123,123,124,124,124,124,124,123,122,121,120,119,118,117,116,115,114,113,112,111,110,110,109,109,109,108,107,107};
byte y_points[NUM_POINTS] = {78,80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,96,98,99,100,101,103,105,106,108,110,112,113,113,114,115,115,115,115,115,115,114,112,112,110,109,107,106,106,108,110,112,114,114,115,116,116,117,117,117,117,117,116,115,113,112,110,108,106,104,103,102,100,99,98,97,96,95,94,93,92,91,90,89,87,86,84,82,81,80,78};


void setup(){
  // initialize port D and B for writing
  DDRD = B11111111; 
  DDRB = B00111111;
  byte t;
  for (t=0; t < NUM_POINTS; t++)
  {
    y_points[t] = map(y_points[t],0,255,0,63); // re-map Y points to 6 bits since port B is limited to 6 bits on Arduino
  }
}

void loop(){
    for (byte t=0; t < NUM_POINTS; t++)// run through points
    { 
      PORTD = x_points[t];
      PORTB = y_points[t];
      delayMicroseconds(FIGURE_DELAY);
    }
}

  

Plotting Tool

Python
Drawing tool to export points to plot
import tkinter as tk
X = []
Y = []
lastx, lasty = 0, 0

# xy and addLine are for graphical purposes only
# on_move_press is the one that logs the one to the list and fixes Y


def xy(event):
    # logs coordinates when mouse is clicked
    global lastx, lasty
    lastx, lasty = event.x, event.y

def addLine(event):
    # draws line from old point to new point
    global lastx, lasty
    canvas.create_line((lastx, lasty, event.x, event.y))
    # this makes the new starting point of the drawing
    lastx, lasty = event.x, event.y

# logs clicked coordinate on list
def on_move_press( event):
    curX, curY = (event.x, event.y)
    curY=255-curY # since tkinter uses different coordinates
    X.append(str(curX))
    Y.append(str(curY))

# set up needed for window
root = tk.Tk()
root.geometry("255x255")
root.columnconfigure(0, weight=1)
root.rowconfigure(0, weight=1)
canvas = tk.Canvas(root)
canvas.grid(column=0, row=0, sticky=(tk.N, tk.W, tk.E, tk.S))

# bind left click and drag to functions and start loop
canvas.bind("<Button-1>", xy)
canvas.bind("<B1-Motion>", addLine)
root.bind("<B1-Motion>",on_move_press)

root.mainloop()

# delete every 2nd entry to reduce points and increase trace refresh
for i in range(1,int(len(X)/2)):
    X.pop(i)
    Y.pop(i)

print("const int NUM_POINTS = %s;" % str(len(X)))
print("const unsigned long x_points[NUM_POINTS] = {%s};" % ','.join(X))
print("const unsigned long y_points[NUM_POINTS] = {%s};" % ','.join(Y))

#call python drawlog.py > arduino_list.txt

Credits

Juan Alvarez

Juan Alvarez

1 project β€’ 1 follower
just a maker
Timster

Timster

0 projects β€’ 1 follower
Thanks to Timster.

Comments