Newbie needs help getting started - connecting DAC breakout board to Arduino
Bought Arduino Uno, got the simple examples progs to work. Bought a Sparkfun DAC breakout board, Connections between boards are straightforward but struggling to know how to write the code for the I2C for getting an analog voltage sent to the breakout board.
Just need advice on simple code to send say a value of 2048 from Arduino to DAC so I can see a 2.5v output on voltmeter. If I have that I can build the rest of the project.
By looking at examples on the net - prepare a simple test program to output analog volts - cannot get it to work - here is the code. The LED goes on/off - but no alaog output. Also really need to get output up to 5 v (val = 4095). All help appreciated
/* Test Program for Sparkfun DAC Breakout Board connected to Arduino Uno R3
Right now the ANALOG OUTPUT IS NOT WORKING??
connections as follows
DAC Breakout Arduino
VCC ------------ 5v pin
SDA ------------ Pin 4
SCL ------------ Pin 5
GND ------------ GND pin
Analog out and ground from DAC connected to digital voltmeter
LED connected to Pin 13
Program loops with lED on/off every 2 seconds and analog volts high (0.31 volts)
every 5 seconds - but no voltage detected on the output from DAC board
*/
#include <Wire.h>
int led = 13; // the number of the LED pin;
void setup()
{
Wire.begin(); // join i2c bus (address optional for master)
pinMode(led, OUTPUT); // set LED as output
}
byte val = 0;
void loop()
{
Wire.beginTransmission(96); // transmit to device
// device address is specified in datasheet
//Wire.write(byte(0x00)); // sends instruction byte
val = 0;
Wire.write(val); // sends DAC value byte = 0 -i.e. 0 volts
digitalWrite(led, HIGH); // turn the LED on (HIGH is the voltage level)
delay(2000); // wait for a second
val = 255;
Wire.write(val); // sends DAC value byte = 255 -i.e. 0.31 volts
digitalWrite(led, LOW); // turn the LED off by making the voltage LOW
delay(2000); // wait for a second
Wire.endTransmission(); // stop transmitting
val++; // increment value
if(val == 255) // if reached 255 - set as max for this test
{
val = 0; // start over from lowest value
}
delay(500);
}
SDA/SCL indicates an I2C bus. The Arduino is 5V0 is the ADC boards as well?
I2C requires a pullup on the clock and data line at one location on the bus. Do you have physical pullups someplace or have you enabled internal pullups on those lines?
Can you read any of the registers on the ADC. There is often a “WhoAmI” register that returns a unique ID number for the chip. Chan you read this properly?
Well I was going to give you a hex register for the whoami and what to expect. But I cannot find a register map. I like Microchip but I am quite disappointed… But now looking again I find that this device is too dumb to have a true register map. It simply has a read and write command with 3 bits of specific commands. I would suggest if you have not already done so, read section six of the manual. After you completely understand and implement all that is in that section, preform a read and see if it contains anything other than 0xFF. If it does, good news! Your chip is operational from a bus standpoint.
Still struggling to get the Sparkfun DAC BOB to work from Arduino. Have rewritten my program , found Square Wave example on net - revised this to attempt volts output on/off every 2 secs - but all I get is 2.51 volts constant - measured with voltmeter and scope a friend loaned to me. Just wondered if the DAC board is defective, or have I used the wrong address and write codes. Full code os my second attempt below. Never tried any I2C stuff before so big learning curve?
/* Test Program for Sparkfun DAC Breakout Board connected to Arduino Uno R3
This program is based on an example from the net - of a square wave program
My second attempt to get an analogue output still the ANALOG OUTPUT IS NOT WORKING??
connections as follows
DAC Breakout Arduino
VCC ------------ 5v pin
SDA ------------ Pin 4
SCL ------------ Pin 5
GND ------------ GND pin
Analog out and ground from DAC connected to digital voltmeter
LED connected to Pin 13
Program should loops with lED on/off every 2 seconds
and analog volts high (5 volts)every 2 seconds
- but voltage detected on the output from DAC board constant 2.51 voles
scope also shows constant volts - not a swquare wave
not a sine wave, but to LED does goes go on/off every 2 secs
Have I got a defective DAC board?
Should the DAC Register be 64 and the write register 96 ??
(as in the square wave example program)
*/
#include <Wire.h>
int led = 13; // the number of the LED pin;
void setup()
{
Wire.begin();
pinMode(led, OUTPUT); // set LED as output
}
byte ON = 255; // All bits high will give maximum output, Vcc, which is 5V.
byte OFF = 0; // All bits low will give minimum output, GND, which is 0V.
byte Program = 64; // See below for more details, but this sets the DAC register to receive new data
byte Device = 96; // This hardwired into the IC and the BoB, in other words, it is a given.
void loop()
{
digitalWrite(led, HIGH); // turn the LED on (HIGH is the voltage level)
Wire.beginTransmission(Device);
Wire.write(Program);
Wire.write(ON);
Wire.write(ON); // Needed twice, since the 4 lowest bits (of 12) are in the fourth byte
Wire.endTransmission();
delay(2000);
digitalWrite(led, LOW); // turn the LED off (LOW is the voltage level)
Wire.beginTransmission(Device);
Wire.write(Program);
Wire.write(OFF);
Wire.write(OFF); // Needed twice, since the 4 lowest bits (of 12) are in the fourth byte
Wire.endTransmission();
delay(2000);
}
Yes - looks like I need to read the address from the DAC board, if I knew how? I have ordered an LCD shield accessory for the Arduino, so maybe I can use that and program to try and read the address and dislay on the LCD?
All attempts to get this to work have failed, advice from Sparkfun Technical support is that the DAC board might be defective, so waiting for replacement and will start again when it arrives