Go Down

Topic: Library for MCP4275 - AD convertor (Read 4425 times) previous topic - next topic

robtillaart


Recently I needed a DAC and I choose the MCP4725 as it had 12 bit (4096 steps 0..5V). It is an I2C device with one configurable address pin so one Arduino can handle two of them. One of the nice features is it has an EEPROM on board that allows to set the start/boot value of the ADC to the value you want.
datasheet:  - https://www.sparkfun.com/datasheets/BreakoutBoards/MCP4725.pdf -

To make using the MCP4725 easier I created a class to encapsulate its functionality. Although not complete It is stable enough to be useful and to be shared. Still to do are the EEPROM and the powerDownMode. Furthermore the registerWriteMode() might change its internal behaviour (relates to EEPROM). Hope to add these soon.

As always comments and remarks are welcome.

Code including a test sketch can be found on github: - https://github.com/RobTillaart/Arduino/tree/master/libraries/MCP4725 -
Rob Tillaart

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

robtillaart

update:
EEPROM seems to work now (code still in beta) 
- need additional testing as EEPROM write latency (~30 milliseconds) affects behaviour quite a bit, especially write is blocked.
- clean up the code.
Rob Tillaart

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

terryking228

Hi Rob,

Nice Library for Nice DAC.  I'll get a couple of those for when Real DC output is needed..

I pointed to your collection of great libraries on ArduinoInfo.Info hoping more people will know about them.
Regards, Terry King terry@yourduino.com  - Check great prices, devices and Arduino-related boards at http://YourDuino.com
HOW-TO: http://ArduinoInfo.Info

robtillaart

Thanks for the compliment Terry,

I've seen several pieces of code for this DAC but none of them check the RDY flag when writing. Not even the AdaFruit lib, and these are normally very good.
The only drawback so far is that one cannot set the EEPROM value without setting the DAC value, the datasheet gives no clue.
(I still have some ideas to try things outside the datasheet but that breaks the guarantee ;)

I hope to push a new beta (0.1.02) this evening that keeps track of the RDY flag when writing.

If you have time, please test the lib and let me hear your remarks,
Rob Tillaart

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

robtillaart

@Terry,
in your opinion, should libraries like this still be made backwards (pre Arduino 1.00) compatible ? (maybe better ask on a separate thread)
Rob Tillaart

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

robtillaart

updated the version on gitHub.
+ EEPROM code works fine now (as far as tested)
Todo:
- powerDownModes, reset, wakeup
- more sample sketches how to use it
- remove smooth2Value() function as it should not be in the lib => example sketch
- refactor a bit more, rename RDY? make it private?
Rob Tillaart

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

robtillaart

updated the version on gitHub to 0.1.03
+ tested EEPROM some more
+ removed smooth2Value
+ added experimental powerDownMode code, however the interface is not great

As always comments and remarks are welcome.
(next update next weekend)
Rob Tillaart

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

terryking228

Hi Rob,
Quote
should libraries like this still be made backwards (pre Arduino 1.00) compatible ?


Hmm... I would say IF all it takes is the #if stuff to get the right Arduino header files, you may as well (That's easy).. But if it's complex to make it work, or needs other libraries that are not pre-1.0 compatible I don't think it's worth it.

I JUST realized that Arduino 1.5.5 is not only required for DUE etc. but is now (+- BETA label) best to be used for regular Arduino development. Somehow I missed that... I guess 1.0.5 is the last of the 1.0.x family. 1.5.5 DOES fix the lack of scrolling on Libraries and Sketchbook in 1.0.5.

Those of us who have lots of libraries (plus all of Yours!) need a scrollable list of libraries!

Other: I think EVERY Library should put detailed information in it's .h file that documents what Timers and Pins and other resources it consumes, to help in handling conflicts.
Regards, Terry King terry@yourduino.com  - Check great prices, devices and Arduino-related boards at http://YourDuino.com
HOW-TO: http://ArduinoInfo.Info

robtillaart

updated the version on gitHub to 0.1.04
- https://github.com/RobTillaart/Arduino/tree/master/libraries/MCP4725 -

+ fixed powerDownMode (still experimental, use with care)
+ fixed powerOnReset()
+ fixed powerOnWakeUp()
+ changed interface + behavior of writePowerDownMode()
+ added some missing conditional #ifdef's
+ added testcode for powerDownMode()

as always comments and remarks are welcome
Rob Tillaart

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

Go Up