Using Nicla vision to play wav files using mcp4728, troubles with i2c

I am trying to play a wav file from Nicla Vision flash memory, and I have troubles getting i2c to work. Arduino C++ code to test i2c connection works fine so its a software issue. I tried using this (GitHub - openfablab/mcp4728: Helpful libraries and other stuff for micropython) custom library but so far nothing has worked.

Any tips on how to get i2c communication with mcp4728 DAC to work?

Hi, it would be helpful if you described the particular errors you are having? Like, what is not working? The I2C connection? Any STM32 boards have the best MicroPython support. So, any driver issues should easily be fixed.

Thanks for the quick answer! Yes, the i2c connection is not working although i checked it with Arduino IDE and there it works fine.

For the record:

The boards are connected as follows

MCP4728 Breakout Board Nicla Vision

Nicla is connected to the pc through usb.
MCP4728 has two 10k pull-up resistors available for i2c.

I am trying to use this code to test i2c communication using openMV micropython environment.

First I wanted to scan for available devices, but the mcp4728 is not listed in the feed.

import pyb

# Initialize I2C bus
i2c = pyb.I2C(2, pyb.I2C.MASTER, baudrate=400000)

def scan_i2c():
    devices = i2c.scan()
    if not devices:
        print("No I2C devices found.")
        print("I2C devices found:", [hex(device) for device in devices])

# Scan for I2C devices

Returns: >>> I2C devices found: ['0x8', '0x29', '0x36']
Then I thought that maybe the address is different by a chance and tested it when the mcp4728 board were unplugged, still the same devices were found.

Then I wanted to specify the device, by default the mcp4728 address is 0x60, with this code:

import pyb
import time

# MCP4728 I2C address
MCP4728_ADDR = 0x60

# Initialize I2C bus
i2c = pyb.I2C(2, pyb.I2C.MASTER, baudrate=400000)

def test_i2c_connection():
    return MCP4728_ADDR in i2c.scan()

def main():
    if test_i2c_connection():
            i2c.send(bytes([0x58, 0x00, 0x00]), MCP4728_ADDR)  # Example write
            data = i2c.recv(12, MCP4728_ADDR)  # Example read
            print("Data received:", data)
        except OSError as e:
            print("I2C communication error:", e)
        print("MCP4728 not found on I2C bus.")


It returns: >>> MCP4728 not found on I2C bus.

Any ideas?

I think you may be on the wrong I2C bus. Try bus 1.

The Nicla has a different I2C bus layout than the regular OpenMV Cam.

I2C2 is the internal bus.

Worked like a charm. Thanks kwagyeman!