Raspberry Pi Pico weather display (MicroPython)
Your first MicroPython project: temperature and humidity on an OLED.
Shop by category
Shop all componentsMost Arduinos can only fake analog output with PWM. The Arduino Due's SAM3X8E has two 12-bit DAC pins (DAC0 and DAC1) that output a real voltage, roughly between 0.55 V and 2.75 V. The sketch keeps a 100-point table for each wave and steps through it at a rate set by a potentiometer, giving test signals from a few hertz to about 1 kHz. Feed it to an oscilloscope, a small amplifier or an RC filter to see how filters change waves.
The Due is 3.3 V only; check every signal before connecting it.
Tick anything you already have and the total updates.
Follow the colours: red is power, dark grey is ground, blue is a signal.
USB on the programming port.
wavegen.inoVerify & upload in Electrolarkconst int N = 100;
uint16_t waves[3][N];
int shape = 0;
bool lastBtn = HIGH;
void setup() {
analogWriteResolution(12);
analogReadResolution(12);
pinMode(2, INPUT_PULLUP);
for (int i = 0; i < N; i++) {
waves[0][i] = 2047 + 2047 * sin(2 * PI * i / N); // sine
waves[1][i] = i < N / 2 ? i * 4095 / (N / 2) : (N - i) * 4095 / (N / 2); // triangle
waves[2][i] = i < N / 2 ? 4095 : 0; // square
}
}
void loop() {
int freq = map(analogRead(A0), 0, 4095, 5, 1000); // hertz
unsigned long stepUs = 1000000UL / (freq * (unsigned long)N);
for (int i = 0; i < N; i++) {
analogWrite(DAC0, waves[shape][i]);
delayMicroseconds(stepUs);
}
bool b = digitalRead(2);
if (b == LOW && lastBtn == HIGH) shape = (shape + 1) % 3;
lastBtn = b;
}
Check you picked the Due board, not another; DAC0 is labelled near A11.
The DAC swings only about 0.55-2.75 V; use an op-amp to shift and scale it.
The loop overhead adds time; use a timer interrupt for accurate high frequencies.
No, every pin is 3.3 V; 5 V on a pin can destroy the chip.
No, the DAC gives very little current; feed an amplifier input instead.
Use DAC1 for a second channel, for example a stereo test tone or an X-Y scope picture.
5 parts: Arduino Due AT91SAM3X8E ARM Cortex-M3 Dev Board w/ USB, Rotary Potentiometer Module 10k (3-Pin), Tactile Push Button Switch, Solderless Breadboard and Dupont Jumper Wires (40 pcs). On this page you can tick the parts you already have and add only the rest to your cart.
It is a intermediate project and takes about 2 hours. The build on this page has 5 steps.
No. This page has the complete, tested code (wavegen.ino).
About ₹1,468 for the parts at the prices on this page. Quantity price breaks lower the cost when you build several.
The difference between a DAC and PWM; Wave tables; The Due's 3.3 V limits.
The Due is 3.3 V only; check every signal before connecting it.
Your first MicroPython project: temperature and humidity on an OLED.
A web page with ON and OFF buttons that switches a relay over Wi-Fi.
A warm ring light that fades up at dusk and down at dawn.
Turn a Pi and a touchscreen into a home command centre with a clock and to-do list.
Lessons are free to read. Maker (₹499/month) and Pro add quizzes, worked problems and certificates, paid with your Geekobot account. See plans
Learning project. Check every circuit and the datasheet of each part before you power it up.