Arduino + MCP4725 Breakout Board

February 24, 2011 | Amateur Radio, Arduino, electronics, My Projects | By: Mark VandeWettering

Well, the other I2C based breakout board I got from Sparkfun was for a Microchip MCP4725 DAC. It’s a 12 bit device, and will eventually do duty controlling the voltage controlled oscillator in my beacon transmitter. For tonight though, I just wanted to make sure I could program it, so I soldered on some header pins, plugged it into a breadboard, and coded up a small, simple program to simply send values from a table holding appropriately scaled sine values as quickly as possible. Here’s the code:


#include <Wire.h>

void
setup()
{
  Wire.begin() ;
}

#define MCP4725_DEVICE 96

int sintab[64] = {2147, 2347, 2545, 2737, 2922, 3100, 3267, 3422, 3564, 3692, 3803,
3898, 3975, 4033, 4072, 4092, 4092, 4072, 4033, 3975, 3898, 3803,
3692, 3564, 3422, 3267, 3100, 2922, 2737, 2545, 2347, 2147, 1947,
1747, 1549, 1357, 1172, 994, 827, 672, 530, 402, 291, 196, 119, 61,
22, 2, 2, 22, 61, 119, 196, 291, 402, 530, 672, 827, 994, 1172,
1357, 1549, 1747, 1947} ;

int sp = 0 ;

void
loop()
{
  Wire.beginTransmission(MCP4725_DEVICE);
  Wire.send(64);                     // cmd to update the DAC
  Wire.send(sintab[sp] >> 4);        // the 8 most significant bits...
  Wire.send((sintab[sp] & 15) << 4); // the 4 least significant bits...
  Wire.endTransmission();
  sp = (sp + 1) & 63 ;
}

And here’s the brief YouTube video showing it in operation:



Share Button
Be Sociable, Share!

Write a comment