Projects / Pico DAC waveform maker

Pico DAC waveform maker

Intermediate2.5 hGuided buildReviewed

Build it step by step

0 of 7 done
  1. PICOMCP4725

    Wire the DAC

    VCC to 3V3(OUT), GND, SDA to GP0, SCL to GP1.

  2. PICO

    Wire the button

    GP14 to GND.

  3. PICO

    Check the address

    The program prints the I2C devices.

  4. PICO

    Save the program as main.py

    On the Pico.

  5. PICO

    Run it

    A sine wave appears on the scope.

  6. PICO

    Press the button

    Triangle, then saw.

  7. PICO

    Add a resistor and capacitor

    See the steps smooth out.

In short

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

FromToWhy
MCP4725 VCCPico 3V3(OUT) pin 36Power at 3.3 V, so the output swings 0 to 3.3 V
MCP4725 GNDPico GNDGround
MCP4725 SDA and SCLPico GP0 pin 1 and GP1 pin 2I2C data and clock
MCP4725 OUTOscilloscope or multimeter probeAnalog output (keep the load light)
Shape buttonPico GP14 pin 19 and GNDChanges 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.

CheckExpected
Sine selectedSmooth rounded wave with visible steps
Triangle selectedStraight rising and falling edges
Saw selectedSlow rise and sharp drop
Peak voltageClose to the 3.3 V supply
FrequencyRoughly 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 →

Ask Lark AI

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.