Showing posts with label MCP4726. Show all posts
Showing posts with label MCP4726. Show all posts

Friday, April 24, 2015

ESP8266 Ultimate DevBoard - Finally Arrived!!




   What do you really expect from a IOT Development board?

   I'm sure most of you will say easy configurable Internet access. Direct Wifi if possible.

   And after that?

   What do you think do you need mostly for your IOT Projects?

   Maybe some sort of easy interaction and data exchange with the real world environment?


  Sounds intriguing to start with so many questions but they are more than legitimate:

  When removing all the bells and whistles, what do we REALLY need to develop the next level of IOT devices?


    If you asked yourself already all these questions, and I'm sure a lot of you has done it already, thinking on your own future projects, what do you think about a IOT Development Board that can offer you at least:



   Sounds good? sounds impossible? Well...I hope that I have, at least for a part of you, one of the right answers below:

CBDB v2 Schematic


  A DevBoard full of functions in a 5x5 size PCB, small enough to easy integrate in your hobbyist workplace ecosystem :)


CBDB V2 DevBoard PCB - TOP


   Latest design review PCBs of the fresh new ESP8266 Dev Board v.2 just landed on my desk and is definitely a next step in Experimenting in the IOT world. Designed with ease of use and flexibility in mind it will offer you endless hours of Experimenting, Programming and Developing your own projects.



     For any new requests please feel free to use as usual: tech at esp8266-projects.com.
     If you want for your own experiments to order CBD v2 EVO bare PCBs only, you can also do it directly at Dirty PCBs, our preferred PCB House:
  http://dirtypcbs.com/view.php?share=5876&accesskey=3d0fd70d53d6dc20c0bf0255f67cde65

     Please keep in mind this is a experimental board, not a commercial product and is offered as it is. If it will burn your house, help the Aliens to abduct you or even eat your cat it's your problem not mine. The old enough ones to remember ALF will understand even deeper the disclaimer :)


  On the TOP side, you can easily directly integrate your LCD or if you want it separate just run it thru a usual cable:
 
CBDB v2 - TOP


     After finished soldering, cleaning and cooling down, this is how is looking the ESP8266 CBDBv2 DevBoard ready for testing  the onboard regulator :



Testing was done with power supplied from a Li-Ion Battery pack and also from a standard 5V SMPS unit under a decent 500mA load. No overheating or nasty oscillations, looks good up to 800mA. Are 800mA warm but the proper calculated double side heatsink area is doing the job right :).


Onboard regulator test - 5V  SMPS Supply


    I know it's a big debate this days about 1A requirement for ESP8266 Modules, but from all my experience and informations, at least with the ESP-07/12 Modules I had in my hands in the latest months, they were never exceed the 250mA margin. In fact, I have one module running for months now as a temperature logger/webserver and the power consumption looks constantly as in the pictures below:

Full drain test with thinkspeak data upload and 1/s direct web access reload



Temperature  Logger supply line monitoring


   I must also admit that I have also some old ESP-01 Modules, never used them, they are indeed looking very power hungry but never had the time to check them how much power they require to properly operate. Or if they are just faulty.

   I have seen before entire batches of faulty ESP8266 modules. Even ESP-07 ones if you remember the story. What I can confirm about these ESP-01 modules is that they cannot be programmed using power directly from my CP2102 USB Adapter, as ESP-07/12. Not enough juice for them. Why? If I will find some time will take a look at them. If is anybody out there that has the answer, please share it with us.


And finally, this is how is looking, ready for firmware upload and first tests:
 ESP8266 DevBoard

Stay tuned for what will follow soon:  firmware uploading and the infamous Blinky test:)



Saturday, March 7, 2015

Part 2 - MCP4726 - 12 Bit I2C DAC Driver for ESP8266 CBDB Board


   Now, with a nice and powerful 12 bit DAC working on our ESP8266 CBDB Board ( see Part 1 ) let's test it to the limit a little bit. As you will see from the Oscilloscope and DMM images below, MCP4726 DAC Output it's nice, smooth and stable. Not bad at all for a 1$ range DAC!

 First step: DAC Output voltage programmed at 0.5V


Oscilloscope - 0.5V DAC Output

DMM - 0.5V DAC Output

What do you think about generating some standard waveforms with ESP8266 CBDB Board ? :)

1. Square Wave

function squareWave(nrit)
 local t=0
 while t<nrit do
       mcp4726:write_dac(2.5)
       tmr.delay(500000)
       tmr.wdclr()
       mcp4726:write_dac(0)
       tmr.delay(500000)
       tmr.wdclr()
    t=t+1
 end
end


Oscilloscope - Square Wave DAC Output
DMM - Square Wave DAC Output


2. Sawtooth Wave

function sawtoothWave(nrit)
 local t=0
 while t<nrit do
    for i=0,3,0.01 do
       mcp4726:write_dac(i)
       --tmr.delay(100)
       tmr.wdclr()
    end
    t=t+1
 end
 mcp4726:write_dac(0)
end


Oscilloscope - Sawtooth Wave DAC Output


DMM - Sawtooth Wave DAC Output

3. Triagle Wave

function triangleWave(nrit)
 local t=0
 while t<nrit do
    for i=0,3,0.01 do
       mcp4726:write_dac(i)
       --tmr.delay(100)
       tmr.wdclr()
    end
    for i=3,0,-0.01 do
       mcp4726:write_dac(i)
       --tmr.delay(100)
       tmr.wdclr()
    end
    t=t+1
 end
end


Oscilloscope - Triangle Wave DAC Output
DMM - Triangle Wave DAC Output

4. SIN Wave

   For this one we will use a predefined table with calculated SIN points values:

s1={1.27,1.30,1.33,1.36,1.39,1.43,1.46,1.49,1.52,1.55,1.58,1.61,1.64,1.67,1.70,1.73,
  1.76,1.79,1.82,1.84,1.87,1.90,1.93,1.95,1.98,2.00,2.03,2.05,2.08,2.10,2.13,2.15,
  2.17,2.19,2.21,2.24,2.26,2.28,2.29,2.31,2.33,2.35,2.36,2.38,2.39,2.41,2.42,2.44,
  2.45,2.46,2.47,2.48,2.49,2.50,2.51,2.51,2.52,2.53,2.53,2.54,2.54,2.54,2.54,2.54,
  2.55,2.54,2.54,2.54,2.54,2.54,2.53,2.53,2.52,2.51,2.51,2.50,2.49,2.48,2.47,2.46,
  2.45,2.44,2.42,2.41,2.39,2.38,2.36,2.35,2.33,2.31,2.29,2.28,2.26,2.24,2.21,2.19,
  2.17,2.15,2.13,2.10,2.08,2.05,2.03,2.00,1.98,1.95,1.93,1.90,1.87,1.84,1.82,1.79,
  1.76,1.73,1.70,1.67,1.64,1.61,1.58,1.55,1.52,1.49,1.46,1.43,1.39,1.36,1.33,1.30,
  1.27,1.24,1.21,1.18,1.15,1.11,1.08,1.05,1.02,0.99,0.96,0.93,0.90,0.87,0.84,0.81,
  0.78,0.75,0.72,0.70,0.67,0.64,0.61,0.59,0.56,0.54,0.51,0.49,0.46,0.44,0.41,0.39,
  0.37,0.35,0.33,0.30,0.28,0.26,0.25,0.23,0.21,0.19,0.18,0.16,0.15,0.13,0.12,0.10,
  0.09,0.08,0.07,0.06,0.05,0.04,0.03,0.03,0.02,0.01,0.01,0,0,0,0,0,
  0,0,0,0,0,0,0.01,0.01,0.02,0.03,0.03,0.04,0.05,0.06,0.07,0.08,
  0.09,0.10,0.12,0.13,0.15,0.16,0.18,0.19,0.21,0.23,0.25,0.26,0.28,0.30,0.33,0.35,
  0.37,0.39,0.41,0.44,0.46,0.49,0.51,0.54,0.56,0.59,0.61,0.64,0.67,0.70,0.72,0.75,
  0.78,0.81,0.84,0.87,0.90,0.93,0.96,0.99,1.02,1.05,1.08,1.11,1.15,1.18,1.21,1.24}


function sinWave(nrit)
  local sn=0
  while sn<nrit do
    for f = 1, #s1 do
      v = string.format("%f",s1[f])
      --print(v)
       mcp4726:write_dac(v)
       --tmr.delay(1)
      tmr.wdclr()
    end
  sn=sn+1
  end
end



Oscilloscope - SIN Wave DAC Output
DMM - SIN Wave DAC Output


For programming and uploading the software we will continue to use the LuaUploader as before.

To run the test, just save the code on ESP as 'func_gen.lua', restart ESP and run:

           require('mcp4726')
           sda=2 --GPIO4
           scl=1 --GPIO5
           mcp4726:init(sda, scl)
           mcp4726:write_dac(0.5)  -- 0.5 steady DAC output

          require('func_gen')
          squareWave(10)
          sawtoothWave(10)
          triangleWave(10)
          sinWave(10)


If you run in problems regarding available memory (should not if running after proper ESP Module restart) or want to optimise the memory usage just compile the program and driver before execution:

         node.compile('mcp4726.lua')
         node.compile('func_gen.lua')



Uploading and running the function generator test


And the "LIVE" action :




Friday, March 6, 2015

MCP4726 - 12 Bit I2C DAC Driver for ESP8266 CBDB Board - Part 1

    At least from the zillions of request for a DAC Driver implementation example that I received in the latest weeks, this is the long awaited topic: ESP8266 Modules and Voltage Output Digital-to-Analog Converter control!

    For our project we will use Microchip MCP4726, a Voltage Output Digital-to-Analog Converter (DAC) with EEPROM and I2C™ Interface.

    As you will see, despite the fact that is a tiny one, it's a very versatile chip with a great price/capabilities ratio. If you take a look on Digikey for example it can be found at around 1.15$!

Features:

• Output Voltage Resolutions:
 - 12-bit: MCP4726
 - 10-bit: MCP4716
 - 8-bit: MCP4706

• Rail-to-Rail Output


• Fast Settling Time of 6 μs (typical)

• DAC Voltage Reference Options:
- VDD
- VREF Pin

   The VREF pin or the device VDD can be selected as the DAC’s reference voltage. When VDD is selected, VDD is connected internally to the DAC reference circuit.  When the VREF pin is used, the user can select the output buffer’s gain to 1 or 2. When the gain is 2, the VREF pin voltage should be limited to a maximum of VDD/2.

  That means that it has also an internal reference and if you don't need very high accuracy or you have a very stable power supply for MCP4726 DAC, you don't need to use an external expensive Voltage Reference to make it working decent! If you are looking in the basement after boson Higgs cousin then this 1.15$ DAC is not what are you looking for :)

• Output Gain Options:
- Unity (1x)
- 2x, only when VREF pin is used as voltage
source

• Nonvolatile Memory (EEPROM):
- Auto Recall of Saved DAC register setting
- Auto Recall of Saved Device Configuration
(Voltage Reference, Gain, Power-Down)

• Power-Down modes:
- Disconnects output buffer
- Selection of VOUT pull-down resistors
(640 kΩ, 125 kΩ, or 1 kΩ)

• Low-Power Consumption:

- Normal Operation: 210 μA typical
- Power-Down Operation: 60 nA typical
(PD1:PD0 = 11)

• Single-Supply Operation: 2.7V to 5.5V

• I2C™ Interface:
- Eight Available Addresses - Factory hardcoded !! - if you need more than one to run in your project be carefully when ordering!!
- Standard (100 kbps), Fast (400 kbps), and
High-Speed (3.4 Mbps) modes

• Small 6-lead SOT-23 and DFN (2x2) Packages
• Extended Temperature Range: -40°C to +125°C

For more details, please see MCP4726 Datasheet

   Don't be scared by the SOT-23 package used, with a small SOT-23 to DIP adapter will fit great in our CBDB extension slots so it will not matter at all. Actually is even more manageable than the MCP9808 Temperature sensor MSOP-8 package used before


What we will need:
  • CBDB Board
  • USB adapter (take a look on Part 1 for details how to connect them together)
  • MCP4726 Module from above
  • LED module (if you want maybe a LED ticker)
CBDB with MCP4726 DAC and MCP9808 Temperature Modules

    Connection between the modules is pretty simple as both are I2C chip modules. Each of them is connected at +3V, GND and toghether on I2C bus using SDA and SCL lines. I will suggest also to do proper decoupling for MCP4726 Power and Vout pins (see picture above).

MCP4726 DAC Module connections



    Please remember that all released software examples are provided under MIT Licence, if no other specific options stated. I was asked about, so this is the reason of this declaration. Some people looks more interested in legal stuff than wide access to information. So, if you find on this website anything useful and you want to contribute, please send your comments or even a  donation. OR virtual beer. OR whaterver. OR nothing. Your choice.
----------------------------------------------------------------------------------------------------------------------------
The MIT License (MIT)
 

Copyright (c) 2015       
esp8266-projects.com
 

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
 

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
----------------------------------------------------------------------------------------------------------------------------

  For programming and uploading the driver and the software we will continue to use the LuaUploader as before.

Driver implementation.
 
As MCP4726 has a I2C compatible compatible interface, building a driver for it it's a pretty straigh forward process:
1. Init I2C bus/interface
     
          dev_addr = 0x60,
          init = function (self, sda, scl)
                   self.id = 0
           i2c.setup(self.id, sda, scl, i2c.SLOW)
          end

 

  2. Write Volatile DAC Register Function.

          write_dac = function (self, voltage) 
               self.dev_addr = 0x60
               self.reg_addr = 0x40

               volt=(4096*voltage)/3.27 -- tweak the value for your VREF value
               print("Voltage Steps:" .. string.format("%d",volt))  --debug

               msb = bit.rshift(volt, 8)
               print("MSB:" .. string.format("%d",msb))              --debug

               lsb = volt-bit.lshift(msb,8)
               print("LSB:" .. string.format("%d",lsb))              --debug

               i2c.start(self.id)
               i2c.address(self.id, self.dev_addr ,i2c.TRANSMITTER)
               --i2c.write(self.id,self.reg_addr)
               i2c.write(self.id,msb)
               i2c.write(self.id,lsb)
               i2c.stop(self.id)
          end



For testing, just save the code on ESP as 'mcp4726.lua', restart ESP and run:


          require('mcp4726')
          sda=2 --GPIO4
          scl=1 --GPIO5
          mcp4726:init(sda, scl)
          mcp4726:write_dac(1.5)


Uploading Driver on ESP module
  If all OK, if you measure the DAC output (see picture above for connections) you will find the programmed voltage. 

MCP4726 DAC output voltage set
   
Youtube MCP4726 DAC Driver Test Video :





That's all for today, thank you for your great feedback and looking forward for your suggestions!