Build it step by step
0 of 7 doneWire the DAC
VCC to 3V3(OUT), GND, SDA to GP0, SCL to GP1.
Wire the button
GP14 to GND.
Check the address
The program prints the I2C devices.
Save the program as main.py
On the Pico.
Run it
A sine wave appears on the scope.
Press the button
Triangle, then saw.
Add a resistor and capacitor
See the steps smooth out.
How do you build a pico DAC waveform maker?
A Pico sends numbers to an MCP4725 DAC over I2C to make sine, triangle and saw waves of about 100 hertz, chosen with a button. You need Raspberry Pi Pico H, MCP4725 12-bit DAC module, Tactile push button 6 mm and Breadboard 830 Tie Points. It takes 7 steps and about 150 minutes.
- Level
- Intermediate
- Time
- About 150 min
- Parts
- 4
Parts list
Tick what you already own. It saves to My Garage, so “Build with what I have” knows.
Wiring
| From | To | Why |
|---|---|---|
| MCP4725 VCC | Pico 3V3(OUT) pin 36 | Power at 3.3 V, so the output swings 0 to 3.3 V |
| MCP4725 GND | Pico GND | Ground |
| MCP4725 SDA and SCL | Pico GP0 pin 1 and GP1 pin 2 | I2C data and clock |
| MCP4725 OUT | Oscilloscope or multimeter probe | Analog output (keep the load light) |
| Shape button | Pico GP14 pin 19 and GND | Changes the waveform |
Code
A digital-to-analog converter turns a number into a voltage, the opposite of an ADC. The MCP4725 takes a 12-bit number from 0 to 4095 and outputs a voltage from zero up to its supply, so with a 3.3 V supply each step is about 0.8 millivolt. The program builds a table of 64 values for one cycle of a sine, a triangle and a saw wave, then writes the values to the chip one after another in a loop, which draws the waveform in voltage. Each write is a short I2C message, and at 400 kilohertz the loop gives a wave of roughly a hundred hertz, with steps that show on an oscilloscope as a staircase. A faster wave needs fewer points per cycle. The output can supply only a little current, so connect it to a high impedance input such as a scope probe or a meter, and never use it to drive a speaker or motor directly. A low pass filter of a resistor and a capacitor smooths the steps.
import math, time
from machine import Pin, I2C
i2c = I2C(0, sda=Pin(0), scl=Pin(1), freq=400000)
addrs = i2c.scan()
print("I2C devices:", [hex(a) for a in addrs])
ADDR = addrs[0] if addrs else 0x60 # the DAC is usually 0x60, 0x61 or 0x62
button = Pin(14, Pin.IN, Pin.PULL_UP)
N = 64
sine = [int(2047.5 + 2047.5 * math.sin(2 * math.pi * i / N)) for i in range(N)]
tri = [int(i * 4095 / (N // 2)) if i < N // 2 else int((N - i) * 4095 / (N // 2)) for i in range(N)]
saw = [int(i * 4095 / (N - 1)) for i in range(N)]
shapes = [("sine", sine), ("triangle", tri), ("saw", saw)]
def write(v):
i2c.writeto(ADDR, bytes([(v >> 8) & 0x0F, v & 0xFF])) # fast mode write of a 12-bit value
idx = 0
prev = 1
print("Shape:", shapes[idx][0])
while True:
b = button.value()
if prev == 1 and b == 0:
idx = (idx + 1) % len(shapes)
print("Shape:", shapes[idx][0])
time.sleep_ms(40)
prev = b
table = shapes[idx][1]
for v in table:
write(v)Test checklist
What you should see at each check. If a reading is far off, stop and use the troubleshooting list.
| Check | Expected |
|---|---|
| Sine selected | Smooth rounded wave with visible steps |
| Triangle selected | Straight rising and falling edges |
| Saw selected | Slow rise and sharp drop |
| Peak voltage | Close to the 3.3 V supply |
| Frequency | Roughly 100 hertz |
If it does not work
No output
Check the printed address and the wiring.
Wave looks coarse
That is the 64 steps, filter it with a resistor and capacitor.
Peak below 3.3 V
The module load or supply is dragging it down.
Button does nothing
Check GP14 to GND.
Program does not start on power-up
Save it on the Pico as main.py.
Still stuck? Find the fault step by step with your multimeter →
Common questions
What parts do I need for the pico DAC waveform maker?
Raspberry Pi Pico H, MCP4725 12-bit DAC module, Tactile push button 6 mm and Breadboard 830 Tie Points.
How long does the pico DAC waveform maker take to build?
About 150 minutes for a intermediate maker, in 7 steps.
How do I know the pico DAC waveform maker works?
Sine selected: Smooth rounded wave with visible steps. Triangle selected: Straight rising and falling edges. Saw selected: Slow rise and sharp drop.
No output: what should I check?
Check the printed address and the wiring.
Wave looks coarse: what should I check?
That is the 64 steps, filter it with a resistor and capacitor.
Peak below 3.3 V: what should I check?
The module load or supply is dragging it down.
Button does nothing: what should I check?
Check GP14 to GND.
