Introduction: MicroPython PCF8591 DACtest

About: I’m a retired Avionics repair technician ( depot level ) . I was also responsible for the quality control for the soldering shop . Sports to keep my old hardware in shape and Linux and embedded systems to keep…

I bought this book to improve my Micropython-skills : MicroPython for ESP8266 Development Workshop by Agus Kurniawan . This book is a very good start , the I2C project uses a PCF8591 module . But no DAC programming example so I had to figure that out by myself :-) .

Supplies

What do we need :

- Wemos D1R2 (or D1mini) ESP8266 flashed with the latest MicroPython found here

-PCF8591 module : found here

-DMM or oscilloscope ( better : this project generates a sawtooth waveform )

- Laptop or PC with Thonny IDE (or uPyCraft ) -USB cable to connect the D1R2 to the computer

Step 1: Preparing the PCF8591 Module , Flash WemosD1R2 With MicroPython

Before testing I inspected the module and found the A0 adress connection unwired and present on the input connector . My script uses adress 72(decimal) so this pin must be connected to GND.

See Datasheet for all info .The picture shows the purple wire connecting GND and A0 .

The Wemos D1R2 must be flashed with MicroPython . Ahmed Nouira did a fantastic job and explained everything here . Working with Micropython can be done via the REPL and a terminal emulator but it's easier with an IDE : I use Thonny IDE on Linux .

All info on Thonny IDE is found here . The RNT blog explains also how to use uPyCraft , another IDE for Windows users ( I tried but my old Linuxlaptop didn't buy uPyCraft ...) .

Step 2: Connecting the D1R2 to the PCF8591

I removed all jumpers from the PCF8591 module , they connect the pot , LDR , thermistor to the inputs and the analog output to a LED . If the DAC output is loaded with a 10k resistor it will make the output drop so why putting a LED there ?

Here's the Wiring list :

WemosD1R2 PCF8591

3V3 Vcc

GND GND

SCL(D1) SCL

SDA(D2) SDA

make sure the jumper wire is connected A0 to GND if you try my (silly) script :-)

Step 3: Load Script and Testing

If you're using Thonny IDE you can download DAC.py and DAC1.py , and load them into the D1R2

for testing . If You're using the REPL enter line by line , it's a very easy and short script .

DAC.py is a simple sawtooth generator ( verify by scope) while DAC1.py has a 1s delay built-in so you can use a DMM .

Have Fun !