Go Down

Topic: Digital to analogue (DAC) - mcp4728 library - not working? (Read 147 times) previous topic - next topic

NickH

Dear List,
There was a useful looking thread from a few years ago on a library developed for the mcp4728 Quad output DAC chip. I was going to reply on the thread but it has been dead for a while so I was advised to start a new thread. The link is here:

http://forum.arduino.cc/index.php?topic=51842.0

I have tried this library using an arduino Uno but it doesn't seem to work. At least I can't get it to work. I wonder if this is because it is no longer compatible with Arduino versions > 1.0

Is there any interest in this any more? i think this is a great idea for analogue outputs but I can't get the library to work. Is there anyone out there who is using this resource who can offer some advice? As far as I can tell, i have wired it up correctly.

THanks,
NickH

robtillaart

might be relative easy to fix


#if defined(ARDUINO) && ARDUINO >= 100
    #define WIRE_WRITE Wire.write
    #define WIRE_READ  Wire.read
#else
    #define WIRE_WRITE Wire.send
    #define WIRE_READ  Wire.receive
#endif


and replace the Wire.send calls with WIRE_WRITE
Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

NickH

Thanks Rob.. but where should this be?
In the library (.cpp or .h) or is this in the sketch?
NickH

NickH


Quote
might be relative easy to fix


#if defined(ARDUINO) && ARDUINO >= 100
    #define WIRE_WRITE Wire.write
    #define WIRE_READ  Wire.read
#else
    #define WIRE_WRITE Wire.send
    #define WIRE_READ  Wire.receive
#endif


and replace the Wire.send calls with WIRE_WRITE
Answering my own reply, I guess this would be in the library with the definitition in .h and the new definition used in .cpp

It seems that from Arduino version 1.0 onwards, then the commands wire.send should be wire.write and wire.receive should be wire.read and this is a nice way of making the library compatible with older versions of the arduino software.

However, the library has already been updated to a 1.0 compatible version and from what I can see, this represents changes along the line that Rob has recommended.

so this seems not to be the problem.

I am now not sure if this is a hardware or software problem.

I have tried using pull up resistors to SCL and SDA inputs (A4 and A5) and tried removing them as a post elsewhere seemed to suggest these pins already had pull up resistors.

Any other suggestions?


Hopefully,
NickH

NickH

Ok, well I will post the answer in case anyone else is struggling. Rather obvious when you know how!!!


The library is fine but it will only work if it uses the correct address for the I2C device. The code seemingly is wired to what is supposed to be the default address for the chip (0). However, I needed to find an I2C scanning bit of code:

http://playground.arduino.cc/Main/I2cScanner

With this, it told me the address of my I2C device was 0x61. By letting the sketch know that this was the correct address, everything started to work.

I am not currently using pull up resistors. Not sure how important this is so if anyone can advise, please let me know.

THanks,
NickH

robtillaart

Read all about I2C here - http://www.gammon.com.au/forum/?id=10896 -

in the 2nd part the reasons for pull up s are explained.
Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

rmay_pci

Saw this thread and wanted to add an example for other potential Arduino noobs.  I recently purchased a Due and the Microchip MCP4728 evaluation board (eg. available from Digikey as part number MCP4728EV-ND, $15).  I got this working realtively easily using the library referenced at the start of this theaad, with only some minor edits to the .cpp and .h files (changed wire.send() to wire.write(),  wire.receive() to wire.read(), and WProgram.h to Arduino.h).  I also added some comments to the original example sketch "BasicUse" and renamed that to MCP4728B_web.ino which is posted here.  I have the mcp4728 library files in the usual Arduino install folder location (/libraries folder).

I'll try to attach the sketch and .cpp and .h files here (first post so I may botch this part). The MCP4728 eval board has 5K pullups on the SDA and SCL lines, so those were in parallel with the 1.5K pullups on the Due board (or, some forum comments indicate these may be 1K pullups instead, despite the schematic notation).  Things worked despite the relatively low value of the parallel combination of pullups (either 833 ohm or 1154 ohm depending on the value of the Due pullups).  The 5K pullups on the eval board are easily removed but things worked with them in place.

Lastly, I used the default MCP4728 I2C address, but the original library contains another example called changeDeviceID which can be used to change the I2C address.  The file TwoWireBase.h in the SoftI2CMaster folder also must have WProgram.h changed to Arduino.h.  Use that example to change the MCP4728 I2C address if necessary (I have not tried this yet but plan to shortly).

Overall, very easy to use this DAC with the Due and get four honest 0V to Vdd 12-bit outputs (or if using the internal reference 0 - 2.048V or 0- 4.096V output ranges).  The Due DACs seem to operate only over part of the range (0.55V to 2.75V according to other forum posts).

Go Up