Saturday, December 19, 2015

Mailbag !! MPU6050 Module I2C Driver, Init and config




   As been requested by many people that have difficulties to use the MPU6050 Modules, I've done a more detailed ESP8266 Video Tutorial related with the MPU6050 GY-521 Module initialisation and basic usage.

   It is a detailed, step-by-step tutorial, showing all the needed init stages and tests for a proper and smooth usage of the MPU6050 GY-521 module.

https://www.youtube.com/watch?v=DDzIQ_6IQBY






  This is how are looking the received modules:

MPU6050 - GY-521 Module - top

MPU6050 - GY-521 Module - bottom


  These ones seems to  work OK connected directly to the 3.3V power on the ESP8266 nEXT  EVO board Bus and looks to have some very low dropout voltage regulator. This are the good news about.
Now some bad news: it seems to be sold different types/flavours of modules (maybe old/new batches with various BOM) under the same name code so your experience may vary and might be necessary to use 5V power input for the GY-521. Or just bypass the Voltage Regulator to avoid any wiring around :).



MPU-60X0 Overview

      The MPU-60X0 is the world’s first integrated 6-axis MotionTracking device that combines a 3-axis gyroscope, 3-axis accelerometer, and a Digital Motion Processor™ (DMP) all in a small 4x4x0.9mm package.
     With its dedicated I2C sensor bus, it directly accepts inputs from an external 3-axis compass to provide a complete 9-axis MotionFusion™ output. It is also designed to interface with multiple non-inertial digital sensors, such as pressure sensors, on its auxiliary I2C port.

  So, it can act as a I2C master for other I2C devices.  That's cool!

   For power supply flexibility, the MPU-60X0 operates from VDD power supply voltage range of 2.375V-3.46V. Additionally, the MPU-6050 provides a VLOGIC reference pin (in addition to its analog supply pin: VDD), which sets the logic levels of its I2C interface. The VLOGIC voltage may be 1.8V±5% or VDD.

   The MPU-6000 and MPU-6050 are identical, except that the MPU-6050 supports the I2C serial interface only, and has a separate VLOGIC reference pin. The MPU-6000 supports both I2C and SPI interfaces and has a single supply pin, VDD, which is both the device’s logic reference supply and the analog supply for the part.



MPU-60X0 Features


1. Gyroscope Features
  • The triple-axis MEMS gyroscope in the MPU-60X0 includes a wide range of features:
  •  Digital-output X-, Y-, and Z-Axis angular rate sensors (gyroscopes) with a user-programmable full-scale range of ±250, ±500, ±1000, and ±2000°/sec
  •  External sync signal connected to the FSYNC pin supports image, video and GPS synchronization
  •  Integrated 16-bit ADCs enable simultaneous sampling of gyros
  •  Enhanced bias and sensitivity temperature stability reduces the need for user calibration
  •  Improved low-frequency noise performance
  •  Digitally-programmable low-pass filter
  •  Gyroscope operating current: 3.6mA
  •  Standby current: 5μA
  •  Factory calibrated sensitivity scale factor
  •  User self-test 


2. Accelerometer Features
  • The triple-axis MEMS accelerometer in MPU-60X0 includes a wide range of features:
  •  Digital-output triple-axis accelerometer with a programmable full scale range of ±2g, ±4g, ±8g and ±16g
  •  Integrated 16-bit ADCs enable simultaneous sampling of accelerometers while requiring no external multiplexer
  •  Accelerometer normal operating current: 500μA
  •  Low power accelerometer mode current: 10μA at 1.25Hz, 20μA at 5Hz, 60μA at 20Hz, 110μA at 40Hz
  •  Orientation detection and signaling
  •  Tap detection
  •  User-programmable interrupts
  •  High-G interrupt
  •  User self-test



3. Additional Features
  • The MPU-60X0 includes the following additional features:
  •  9-Axis MotionFusion by the on-chip Digital Motion Processor (DMP)
  •  Auxiliary master I2C bus for reading data from external sensors (e.g., magnetometer)
  •  3.9mA operating current when all 6 motion sensing axes and the DMP are enabled
  •  VDD supply voltage range of 2.375V-3.46V
  •  Flexible VLOGIC reference voltage supports multiple I2C interface voltages (MPU-6050 only)
  •  Smallest and thinnest QFN package for portable devices: 4x4x0.9mm
  •  Minimal cross-axis sensitivity between the accelerometer and gyroscope axes
  •  1024 byte FIFO buffer reduces power consumption by allowing host processor to read the data in bursts and then go into a low-power mode as the MPU collects more data
  •  Digital-output temperature sensor
  •  User-programmable digital filters for gyroscope, accelerometer, and temp sensor
  •  10,000 g shock tolerant
  •  400kHz Fast Mode I2C for communicating with all registers
  •  1MHz SPI serial interface for communicating with all registers (MPU-6000 only)
  •  20MHz SPI serial interface for reading sensor and interrupt registers (MPU-6000 only)
  •  MEMS structure hermetically sealed and bonded at wafer level
  •  RoHS and Green compliant


4. MotionProcessing
  •  Internal Digital Motion Processing™ (DMP™) engine supports 3D MotionProcessing and gesture recognition algorithms
  •  The MPU-60X0 collects gyroscope and accelerometer data while synchronizing data sampling at a user defined rate. The total dataset obtained by the MPU-60X0 includes 3-Axis gyroscope data, 3-Axis accelerometer data, and temperature data. The MPU’s calculated output to the system processor can also include heading data from a digital 3-axis third party magnetometer.
  •  The FIFO buffers the complete data set, reducing timing requirements on the system processor by allowing the processor burst read the FIFO data. After burst reading the FIFO data, the system processor can save power by entering a low-power sleep mode while the MPU collects more data.
  •  Programmable interrupt supports features such as gesture recognition, panning, zooming, scrolling, tap detection, and shake detection
  •  Digitally-programmable low-pass filters
  •  Low-power pedometer functionality allows the host processor to sleep while the DMP maintains the step count.
  • 5.5 Clocking
  •  On-chip timing generator ±1% frequency variation over full temperature range
  •  Optional external clock inputs of 32.768kHz or 19.2MHz


It is quite a beast in a tiny package, with Gyroscope, Accelerometer, DMP and all the other goodies inside. For more details please take a look at the MPU60x0 Datasheet




What we will need:





    Connection with the ESP8266 nEXT EVO Board is very easy, as MPU6050 GY-521 Module connector is fully compatible with the nEXT Bus connector. Depending on how to you choose you socket type, you can install it on TOP or Bottom of the ESP8266 nEXT EVO Board :

MPU6050 GY-521 Module on top of the ESP8266 nEXT Evo Board




Driver implementation


1. Init I2C bus/interface

 Standard I2C Bus Initialisation function:
function init_I2C()
    i2c.setup(bus, sda, scl, i2c.SLOW)
end


 2. READ MPU6050 Register

Before reading data from MPU6050, you must tell it which of its internal addresses you want to read
A read starts off by writing to the MPU6050






Procedure:
  •  Send a start sequence.
  •  Send I2C address of the device with the R/W bit low (i2c.TRANSMITTER)
  •  Send the Internal register address
  •  Stop sequence
  • Send a start sequence again (repeated start)
  • Send the I2C address of the device with the R/W bit high (i2c.RECEIVER) 
  • Read data byte from the register
  • Send the stop sequence. 


function read_reg_MPU(reg)
  i2c.start(bus)
  i2c.address(bus, dev_addr, i2c.TRANSMITTER)
  i2c.write(bus, reg)
  i2c.stop(bus)
  i2c.start(bus)
  i2c.address(bus, dev_addr, i2c.RECEIVER)
  c=i2c.read(bus, 1)
  i2c.stop(bus)
  --print(string.byte(c, 1))
  return c
end



3. WRITE MPU6050 Register






Procedure:
  • Send a start sequence
  • Send the I2C address of the MPU6050 with the R/W bit low (i2c.TRANSMITTER)
  • Send the internal register number you want to write to
  • Send the data byte
  • IF you want more data to be sent can be done here. MPU6050 will automatically increment the internal register address after each byte
  • Send the stop sequence.

function write_reg_MPU(reg,val)
  i2c.start(bus)
  i2c.address(bus, dev_addr, i2c.TRANSMITTER)
  i2c.write(bus, reg)
  i2c.write(bus, val)
  i2c.stop(bus)
end


4. INIT MPU6050

When power up, MPU6050 will start in SLEEP mode. To be able to use it you need to START the device.

Procedure: 
  • Set SLEEP bit = 0 in the Power Management Register (107) OR Clear the Register

function init_MPU(reg,val)  --(107) 0x6B / 0
   write_reg_MPU(reg,val)
end


5. MPU6050 connectivity
 
MPU6050 connectivity status only!
Be sure that you have properly initialised I2C Bus before!

function status_MPU(dev_addr)
     i2c.start(bus)
     c=i2c.address(bus, dev_addr ,i2c.TRANSMITTER)
     i2c.stop(bus)
     if c==true then
        print(" Device found at address : "..string.format("0x%X",dev_addr))
     else print("Device not found !!")
     end
end


6. Check MPU6050 Status

Using the status_MPU() function and the Who Am I register to check if the MPU6050 is available and alive before doing anything else.

function check_MPU(dev_addr)
   print("")
   status_MPU(0x68)
   read_reg_MPU(117) --Register 117 – Who Am I - 0x75
   if string.byte(c, 1)==104 then print(" MPU6050 Device answered OK!")
   else print("  Check Device - MPU6050 NOT available!")
        return
   end
   read_reg_MPU(107) --Register 107 – Power Management 1-0x6b
   if string.byte(c, 1)==64 then print(" MPU6050 in SLEEP Mode !")
   else print(" MPU6050 in ACTIVE Mode !")
   end
end



 7. READ MPU6050 RAW DATA

Reading RAW data from the MPU6050. No conversion or transformation si done.
Received Data is in 2 complement format.

Procedure:
  •  Send a start sequence.
  •  Send I2C address of the device with the R/W bit low (i2c.TRANSMITTER)
  •  Send the Internal register address
  •  Stop sequence
  • Send a start sequence again (repeated start)
  • Send the I2C address of the device with the R/W bit high (i2c.RECEIVER) 
  • Read the number of the requested data bytes from the registers
  • Send the stop sequence.

function read_MPU_raw()
  i2c.start(bus)
  i2c.address(bus, dev_addr, i2c.TRANSMITTER)
  i2c.write(bus, 59)
  i2c.stop(bus)
  i2c.start(bus)
  i2c.address(bus, dev_addr, i2c.RECEIVER)
  c=i2c.read(bus, 14)
  i2c.stop(bus)
 
  Ax=bit.lshift(string.byte(c, 1), 8) + string.byte(c, 2)
  Ay=bit.lshift(string.byte(c, 3), 8) + string.byte(c, 4)
  Az=bit.lshift(string.byte(c, 5), 8) + string.byte(c, 6)
  Gx=bit.lshift(string.byte(c, 9), 8) + string.byte(c, 10)
  Gy=bit.lshift(string.byte(c, 11), 8) + string.byte(c, 12)
  Gz=bit.lshift(string.byte(c, 13), 8) + string.byte(c, 14)

  print("Ax:"..Ax.."     Ay:"..Ay.."      Az:"..Az)
  print("Gx:"..Gx.."   Gy:"..Gy.."   Gz:"..Gz)
  print("\nTempH: "..string.byte(c, 7).." TempL: "..string.byte(c, 8).."\n")

  return c, Ax, Ay, Az, Gx, Gy, Gz
end



8. Main program

 Procedure: 
  • Initialise I2C Bus
  • Initialise MPU6050 and START device
  • Check device connectivity and status
  • Read data from device (RAW)

---test program
dev_addr = 0x68 --104
bus = 0
sda, scl = 2, 1
init_I2C()
init_MPU(0x6B,0)

check_MPU(0x68)
read_MPU_raw()  -- one shot
-- read data from MPU6050 every 1s
tmr.alarm(0, 1000, 1, function() read_MPU_raw() end)

--stop tmr when done
tmr.stop(0)


Related resources available on Github:

1. MPU6050 Driver Code :  MPU6050_driver_test_v2.lua
2. MPU6050 Datasheet
3. MPU6050 Register map and descriptions




Thursday, December 10, 2015

ESP8266 nEXT EVO - Analog extension Board - P2



     This is Part 2 of the ESP8266 nEXT EVO Analog Extension Board (AN1)


   In this part we will talk a bit about the nEXT Bus I²C protocol  and we will start also a longer, multi-part discussion about testing procedures and software programming for the AN1 Board devices and functions (I/O Expansion port, Temperature, ADC, DAC, Voltage measurements,etc.






Previous related Articles:



--------------------------------------------------------------------------------------------------------------------------
For any new CBDB orders/requests please feel free to use as usual:
     tech at esp8266-projects.com.


ESP8266 nEXT Evo bare PCB has also been made available directly at Dirty PCBs, our preferred PCB House for experimenting (**):
 http://dirtypcbs.com/view.php?share=9699&accesskey=91d782fd4a10943fd36ecc371c7ff2cd


(**) - Actually you have there 2 Boards for the price of one, a ESP8266 nEXT Evo together with a AN1 nEXT Analog Extension Board that brings you a 18Bit ADC (autoscale 0-40V input!), 4x12Bit DAC, Precison Temperature measurement, 8bit I/O port, etc.  
-------------------------------------------------------------------------------------------------------------------------






 Today topic

  First let's have a very quick look at the nEXT bus protocol: I²C
 
 What is I²C?

     I²C (Inter-Integrated Circuit), pronounced I-squared-C, is a multi-master, multi-slave, single-ended, two-wired serial bus - SDA (data line) and SCL (clock line) -  invented by Philips Semiconductor (now NXP Semiconductors). It is typically used for attaching lower-speed peripheral ICs to processors and microcontrollers.


Features of the I2C-bus:

  • Only two bus lines are required; a serial data line (SDA) and a serial clock line (SCL).
  • Each device connected to the bus is software addressable by a unique address and  simple master/slave relationships exist at all times; masters can operate as master-transmitters or as master-receivers.
  • It is a true multi-master bus including collision detection and arbitration to prevent data corruption if two or more masters simultaneously initiate data transfer.
  • Serial, 8-bit oriented, bidirectional data transfers can be made at up to 100 kbit/s in the Standard-mode, up to 400 kbit/s in the Fast-mode, up to 1 Mbit/s in Fast-mode Plus, or up to 3.4 Mbit/s in the High-speed mode.
  • Serial, 8-bit oriented, unidirectional data transfers up to 5 Mbit/s in Ultra Fast-mode
  • On-chip filtering rejects spikes on the bus data line to preserve data integrity.
  • The number of ICs that can be connected to the same bus is limited only by a maximum bus capacitance. More capacitance may be allowed under some conditions.

   SDA and SCL signals

    Both SDA and SCL are bidirectional lines, connected to a positive supply voltage via a current-source or pull-up resistor:






   When the bus is free, both lines are HIGH. The output stages of devices connected to the bus must have an open-drain or open-collector to perform the wired-AND function. Data on the I²C-bus can be transferred at rates of up to 100 kbit/s in the Standard-mode, up to 400 kbit/s in the Fast-mode, up to 1 Mbit/s in Fast-mode Plus, or up to 3.4 Mbit/s in the High-speed mode. The bus capacitance limits the number of interfaces connected to the bus.

For a single master application, the master’s SCL output can be a push-pull driver design if there are no devices on the bus which would stretch the clock.


   SDA and SCL logic levels

    Due to the variety of different technology devices (CMOS, NMOS, bipolar) that can be connected to the I²C-bus, the levels of the logical ‘0’ (LOW) and ‘1’ (HIGH) are not fixed and depend on the associated level of VDD.

Input reference levels are set as 30 % and 70 % of VDD; VIL is 0.3VDD and VIH is 0.7VDD.

Timing Diagram for F/S-mode devices on the I²C-bus


   Some legacy device input levels were fixed at VIL= 1.5 V and VIH= 3.0 V, but all new devices require this 30 %/70 % specification.


   For a more deep and extensive I²C protocol undestanding ( Data Validity, START and STOP conditions, Byte format, Acknowledge (ACK) and Not Acknowledge (NACK), Clock synchronisation, etc,etc please take a look at the official NXP I²C  Protocol datasheet.  I²C protocol it is quite a serious separate topic to discuss :).

   Before going further with our main topic I will insist only one one more thing, as it looks it creates a lot of confusion sometime:

     The slave address and R/W Bit (7 bit mode)


    Data transfers follow the format shown in the picture below:

A full data transfer


     After the START condition (S), a slave address is sent. This address is seven bits long followed by an eighth bit which is a data direction bit (R/W) — a ‘zero’ indicates a transmission (WRITE), a ‘one’ indicates a request for data (READ):

The first byte after the START procedure



      A data transfer is always terminated by a STOP condition (P) generated by the master.
However, if a master still wishes to communicate on the bus, it can generate a repeated START condition (Sr) and address another slave without first generating a STOP condition. Various combinations of read/write formats are then possible within such a transfer:

  • Master-transmitter transmits to slave-receiver. The transfer direction is not changed and the slave receiver acknowledges each byte:


  • Master reads slave immediately after first byte. At the moment of the first acknowledge, the master-transmitter becomes a master-receiver and the slave-receiver becomes a slave-transmitter. This first acknowledge is still generated by the slave. The master generates subsequent acknowledges. The STOP condition is generated by the master, which sends a not-acknowledge (A) just before the STOP condition:
 

  • Combined format. During a change of direction within a transfer, the START condition and the slave address are both repeated, but with the R/W bit reversed. If a master-receiver sends a repeated START condition, it sends a not-acknowledge (A) just before the repeated START condition:



  

         Now, after a very brief (very!) I²C protocol presentation, let's go back to our Analog Extension Board:

   
ESP8266 nEXT EVO + AN-1 Boards

 
  First thing that we want to do, after the AN-1 Board is properly soldered, cleaned, visual inspection OK, etc, will be to tests it and validate it as a proper working Board.


 What we will need:


    Connection with the ESP8266 nEXT EVO Board is very easy, as Analog Extension Board - AN1 connector is fully compatible with the nEXT connector. Depending on how to you choose you socket type, you can install it on TOP or Bottom of the ESP8266 nEXT EVO Board :

ESP8266 nEXT EVO Board + Analog Extension Board AN1


   And, if you want, you can continue stacking them on the nEXT Bus, with a SSD1306 OLED Display, for example:

ESP8266 nEXT EVO + AN1 + SSD1306 OLED Display




   Software implementation

    By default, on the AN-1 Board you should have the following available devices:
  • PCF8574 8Bit I/O Extension port  - at address 0x20
  • LM75 Temperature sensor             - at address 0x48
  • MCP4728 - 4x12Bit DAC             - at address 0x60
  • MCP3421 - 18Bit ADC                 - at address 0x68
   When also connected, the SSD1306 OLED Display will be available at 0x3C


   A fist step in testing the AN-1 available functions and devices will be to scan the nEXT I²C Bus and see if all the existing ones are alive and responding to the I²C Master requests. Also will list any new added devices, if alive.


1. Find device function

function find_dev(i2c_id, dev_addr)
     i2c.start(i2c_id)
     c=i2c.address(i2c_id, dev_addr ,i2c.TRANSMITTER)
     i2c.stop(i2c_id)
     return c
end

2. Scan Bus for devices function

 function scanbus()
    i2c.setup(id,sda,scl,i2c.SLOW)
    for i=1,127 do
       if find_dev(id, i)==true then
            if i==32 then
            print("- PCF8574 8Bit I/O Extension port - found at address 0x"..string.format("%02X",i).." -> "..i)
            else
            if i==72 then
            print("- LM75 Temperature sensor         - found at address 0x"..string.format("%02X",i).." -> "..i)
            else
            if i==96 then
            print("- MCP4728 - 4x12Bit DAC           - found at address 0x"..string.format("%02X",i).." -> "..i)
            else
            if i==104 then
            print("- MCP3421 - 18Bit ADC             - found at address 0x"..string.format("%02X",i).." -> "..i)
            else
            if i==60 then
            print("- SSD1306 OLED Display            - found at address 0x"..string.format("%02X",i).." -> "..i)
            else
            print("- NEW UNREGISTERED DEVICE         - found at address 0x"..string.format("%02X",i).." -> "..i)
            end
          end
        end
       end
       end
       end
       tmr.wdclr()
   end
end


 3. MAIN Scanbus Program

id=0
sda=2
scl=1
scanbus()


Next time we will continue with deeper testing and programming for each AN-1 available device/function.



Tuesday, December 8, 2015

Mailbag !! SSD1306 OLED Display for ESP8266 nEXT EVO Board





 


   I think everybody knows already the popular  SSD1306 0.96" OLED Display available all over the place for a very good price:

SSD1306 0.96" I2C OLED Display


  My first option for a Alphanumeric Display still remain the ST7032i LCD one, but as looking also for a Graphical Display option found this SSD1306 OLED as a easy to use one with the CBDB nEXT EVO Board.

It is a very good choice because:

 -  From the Hardware point of view, as been a Display with a native I2C interface, it is very easy to connect thru the CBDB EVO nEXT Bus (no extra wires, PSU, etc)

 -  From the Software point of view, even more good news:
  • if you want to use NodeMCU in your projects, a driver for SSD1306 is already there, based on the u8glib library.
  • if you want your Arduino IDE also the u8glib driver is there!
  • Full Datasheet available, so you can also implement your own driver very easy.



  The SSD1306 is a 128x64 Dot Matrix Driver/Controller manufactured by Solomon Systech.
Controller Power Supply for IC Logic is between 1.65V to 3.3V so we have here a 3.3V compatible device, no need for any kind of logical levels converter.

   I will not insist too much about the SSD1306 controller, just one thing that might worth to explain a bit, as it looks that it is creating a lot of confusion for many people:

If you look on the back of the module you can see a jumper option for the Display I2C address: 0x7A or 0x78, with default selected on 0x78:




   If you will try to use it like that, with the addresses from above, it will not work, as many people has already found it.

   Why?

  The I2C communication interface consists of slave address with set bit SA0, I2C-bus data signal SDA (SDAOUT/D2 for output and SDAIN/D1 for input) and I2C-bus clock signal SCL (D0). Both the data and clock signals must be connected to pull-up resistors. 

  SSD1306 has to recognize the slave address before transmitting or receiving any information by the
I2C-bus. The device will respond to the slave address following by the slave address bit (“SA0” bit)
and the read/write select bit (“R/W#” bit) with the following byte format:


b7 b6 b5 b4 b3 b2 b1     b0
 0   1  1   1   1   0   SA0  R/W#


 “SA0” bit provides an extension bit for the slave address.
Either “0111100” or “0111101”, can be selected as the slave address of SSD1306.
D/C# pin acts as SA0 for slave address selection, and actually this is a Address Select pin from the above.

So, if we take the 7 Bit I2C address representation from above we will have:

0 1 1 1 1 0 0  - > 0x3C (default)
OR
0 1 1 1 1 0 1   - > 0x3D (alternate)


The 8th bit is the “R/W#” bit and is used to determine the operation mode of the I2C-bus interface:

 - R/W#=1 - readmode.
 - R/W#=0 - write mode.

  For more details please take a look at the SSD1306 Datasheet




What we will need:


Connection with the nEXT EVO Board is very easy, as SSD1306 connector is fully compatible with the nEXT connector:

Connecting SSD1306 Display to the CBDB nEXT EVO Board


 No wires, no hasle, a nice and compact unit:






Software implementation

 As the driver is already available for this type of Display, for simple projects no driver implemetantion is needed, just few functions to make it running:

  1. Display initialisation
function init_OLED(sda,scl) --Set up the u8glib lib
     sla = 0x3C
     i2c.setup(0, sda, scl, i2c.SLOW)
     disp = u8g.ssd1306_128x64_i2c(sla)
     disp:setFont(u8g.font_6x10)
     disp:setFontRefHeightExtendedText()
     disp:setDefaultForegroundColor()
     disp:setFontPosTop()
     --disp:setRot180()           -- use it for rotate display
end

2. Print Text routine
str1="ESP8266-Projects.com"
str2="Hello World!!"

function PrintText()
  disp:drawStr(5, 10, str1)
  disp:drawStr(20, 20, str2)
end


3. Print on Display function
function print_OLED()
   disp:firstPage()
   repeat
     PrintText()
     disp:drawCircle(64, 47, 14)
     disp:drawFrame(2,2,126,62)
   until disp:nextPage() == false
end

4. Main program
str1="ESP8266-Projects.com"
str2="Hello World!!"

init_OLED(2,1)
print_OLED()

5. Drawing animation 
function draw_tst()
 for r=1, 31 do
   disp:firstPage()
   repeat
     disp:drawCircle(64, 32, r)
   until disp:nextPage() == false
   tmr.wdclr()
 end

 for r=30, 1, -1 do
   disp:firstPage()
   repeat
     disp:drawCircle(64, 32, r)
   until disp:nextPage() == false
   tmr.wdclr()
 end

print_OLED() end


Wednesday, December 2, 2015

P3 - ESP8266 nEXT EVO - Analog Extension Board - AN1



Part 3 of the ESP8266 nEXT Evolution Board Series

 
Analog Extension Board - AN1

 --------------------------------------------------------------------------------------------------------------------------
For any new CBDB orders/requests please feel free to use as usual:
     tech at esp8266-projects.com.

CBDB nEXT Evo bare PCB has also been made available directly at Dirty PCBs, our preferred PCB House for experimenting (**):
 http://dirtypcbs.com/view.php?share=9699&accesskey=91d782fd4a10943fd36ecc371c7ff2cd


(**) - Actually you have there 2 Boards for the price of one, a CBDB nEXT Evo together with a secondary nEXT Extesion Board that brings you a 18Bit ADC (autoscale 0-40V input!), 4x12Bit DAC, Precison Temperature measurement, 8bit I/O port, etc. 

More about this Extension Board in the article below -------------------------------------------------------------------------------------------------------------------------

CBDB nEXT A1 Extension Board - TOP


CBDB nEXT A1 Extension Board -Bottom



 Basic default functions of the CBDB nEXT A1 Extension Board: 


INPUT :
  • 0-40V Autorange Analog frontend
  • 18 Bit ADC 

OUTPUT :
  • 4x12 BIT DAC

TEMPERATURE :
  • I2C Temperature sensor, standard or high precision options

I/O :
  • 8 Bit I/O Port 





 
Analog frontend input



With the default resistor divider values you can have 4 different autoranging scales as below:
  • 0 - 20V
  • 0 - 10V 
  • 0 - 20 V
  • 0 - 40 V



Analog to digital conversion

For this board, the choosen ADC is the MCP3421 from Microchip.

The MCP3421 is a single channel, low-noise, high accuracy delta-sigma A/D converter with differential inputs and up to 18 bits of resolution in a small SOT-23-6 package. The on-board precision 2.048V reference voltage enables an input range of ±2.048V differentially. 

   The device uses a two-wire I2C compatible serial interface and operates from a single power supply ranging from 2.7V to 5.5V.  

    This device has an onboard programmable gain amplifier (PGA). User can select the PGA gain of x1, x2, x4, or x8 before the analog-to-digital conversion takes place.  This allows the MCP3421 device to convert a smaller input signal with high resolution.

For more details about MCP3421 please read the related article: MCP3421 - 18bit I2C ADC - Driver
You will find there driver details and detailed tests regarding MCP3421 ADC.




Digital to Analog conversion

  For the 4 DAC channels we will use the MCP4728 12 Bit  Quad Digital-to-Analog Converter with EEPROM Memory.




MAIN Features:

• 12-Bit Voltage Output DAC with Four Buffered Outputs
• On-Board Nonvolatile Memory (EEPROM) for DAC Codes and I2C™ Address Bits
• Internal or External Voltage Reference Selection
• Output Voltage Range:
   - Using Internal VREF (2.048V):
           0.000V to 2.048V with Gain Setting = 1
           0.000V to 4.096V with Gain Setting = 2
   - Using External VREF (VDD):  0.000V to VDD
• ±0.2 Least Significant Bit (LSB) Differential Nonlinearity (DNL) (typical)
• Fast Settling Time: 6 μs (typical)
• Normal or Power-Down Mode
• Low Power Consumption
• Single-Supply Operation: 2.7V to 5.5V
• I2C Interface:
    - Address bits: User Programmable to  EEPROM
    - Standard (100 kbps), Fast (400 kbps) and High Speed (HS) Mode (3.4 Mbps)
• 10-Lead MSOP Package
• Extended Temperature Range: -40°C to +125°C

Actually, from the DAC point of view you can see MCP4728 as the bigger brother of the MCP4726, Single 12 Bit DAC used before in examples below:



Temperature


For the remperature reading you can use the standard LM75 sensor OR if you want more precision the MCP9808 one.




Drivers and basic examples for both, below:



I/O Expander Port


The I/O expander port is based on the PCF8574, a 8-bit remote I/O port for the I2C-bus.



   The device consists of an 8-bit quasi-bidirectional port and an I2C-bus interface. The PCF8574 has a low current consumption and includes latched outputs with high current drive capability for directly driving LEDs.

   Another interting feature is the interrupt line (INT) which can be connected to the interrupt logic of the microcontroller. By sending an interrupt signal on this line, the remote I/O can inform the microcontroller if there is incoming data on its ports without having to communicate via the I2C-bus. This means that the PCF8574 can remain a simple slave device, even for data input, keyboard scanning, etc.


That's all for now, next times we will continue testing and exploring step-by-step each function of the ESP8266 nEXT Evo Extension Board