"""P9-4 Generate a sine wave using MCP4725 on I2C Bus""" from machine import Pin, I2C i2c = I2C(1, scl = Pin(27), sda = Pin(26), freq = 400_000) DEV_ADDR = 0x60 sinewave = (2048, 3071, 3821, 4095, 3821, 3071, 2048, 1024, 274, 0, 274, 1024, 2048) while True: for d in sinewave: # Create a bytearray of DAC command, high byte (D11-D4), low byte (D3-D0) ba = bytearray([0x40, (d >> 4) & 0xFF, (d << 4) & 0xF0]) # Write the bytearray to MCP4725 DAC through I2C i2c.writeto(DEV_ADDR, ba)