External DAC via I2C? MCP4725 question

146 views
Skip to first unread message

Bayonet

unread,
Jan 16, 2020, 3:23:04 PM1/16/20
to Mozzi-users
I am trying to figure out how to use I2C to send data to this external DAC, but all I'm seeing information is talking about SPI interface DACs. Should I just eat the cost of the DACs I have assembled and get an MCP49xx series DAC? or does anyone know how I can even start with this?

(driver/library link for example of relevant code)

Thanks much in advance! I don't mind just using the RC DAC, but it would be nice to have a more miniaturized solution for this project

Bayonet

unread,
Jan 17, 2020, 1:00:34 AM1/17/20
to Mozzi-users
Interesting, if I go into the driver .ccp and .h and find-and-replace "Wire.write" with "twowire_send" and "Wire." with "twowire_" the project compiles, and I can get some sound from the DAC, though it's clipping my recorder so possibly a bit loud and not particularly sine-like

Tim Barrass

unread,
Jan 17, 2020, 6:56:39 AM1/17/20
to 'Ian C.' via Mozzi-users
The I2C issue comes up regularly on the forum!  There are the twi_nonblock files in the "release" version of Mozzi (not the GitHub development code) which show one approach together with Examples>11.Communication>TwoWire_Read_ADXL345.  The technique is to split I2C requests so you don't block the processor while waiting for results.  However, different devices vary in how long they take to return, or may not even return a result, so non-blocking code isn't always necessary, while other devices can return large amounts of data that cause timing issues in other ways...  

My experience is that I2C is boring and fiddly with Mozzi, while usually possible to solve for most devices - though I have been stumped with one which returned unpredictable data lengths which were hard to handle without audio glitches.  If you feel like doing some programming then give it a go, but if I was faced with your choice I would probably opt for the SPI DAC someone else has already solved!

Tim

--
You received this message because you are subscribed to the Google Groups "Mozzi-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mozzi-users...@googlegroups.com.
To view this discussion on the web, visit https://groups.google.com/d/msgid/mozzi-users/c997c248-7fd3-4c58-ae58-7e9dc4e22d7d%40googlegroups.com.

Bayonet

unread,
Jan 17, 2020, 3:24:26 PM1/17/20
to Mozzi-users
Alright, I will definitely check out the DAC that has already been solved lol. I've so far gotten it to make loud sounds and that's about it so far. 
Tim

To unsubscribe from this group and stop receiving emails from it, send an email to mozzi...@googlegroups.com.

Tim Barrass

unread,
Jan 19, 2020, 7:01:14 AM1/19/20
to 'Ian C.' via Mozzi-users
One the other hand, I should have looked at your links before I posted.

It looks like the I2C calls to the DAC wouldn't use much processor time and you don't have to wait for anything to be returned. So maybe it's just a matter of making sure the audio data you're sending is in the right range, since you're getting sound. The Adafruit_MCP4725 examples on Github have data between 0-2048, while Mozzi has signed audio wavetables between -128 to 127, and standard audio output from updateAudio() is from -244 to 243 before being shifted into the range for pwm output. Are you converting the audio data to the positive range needed for the DAC?

I hope this isn't too vague and confusing.
> To unsubscribe from this group and stop receiving emails from it, send an email to mozzi-users...@googlegroups.com.
> To view this discussion on the web, visit https://groups.google.com/d/msgid/mozzi-users/31704cf7-a925-4761-840f-08a925a5dc9d%40googlegroups.com.

Bayonet

unread,
Jan 21, 2020, 2:56:47 PM1/21/20
to Mozzi-users
Vague and confusing? pshh all programming is pretty vague and confusing at the moment, but I'm pretty sure I can try. I already have a couple 4922 chips in the mail, but I can definitely continue to try to make this work, since I see no reason not to use a prepackaged product so widely available on the cheap!

Bayonet

unread,
Jan 22, 2020, 11:58:37 PM1/22/20
to Mozzi-users
Well, that didn't take long. I have attached my twi_nonblock modified MCP4725 I2C / IIC DAC library, a modified default sketch of how it is used in mozzi, and a video of how the DAC sounds on the AMsynth sketch.


I hope this helps other people in future, because it's actually not bad, especially for how easy it is to install given its almost obscene availability with resistors and caps already installed. lmk what y'all think!
Adafruit_MCP4725-Mozzi.zip
MCP4725-AMSynth-Demo.ino
Reply all
Reply to author
Forward
0 new messages