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.

  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)

 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

  •  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.address(bus, dev_addr, i2c.TRANSMITTER)
  i2c.write(bus, reg)
  i2c.address(bus, dev_addr, i2c.RECEIVER), 1)
  --print(string.byte(c, 1))
  return c

3. WRITE MPU6050 Register

  • 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.address(bus, dev_addr, i2c.TRANSMITTER)
  i2c.write(bus, reg)
  i2c.write(bus, val)

4. INIT MPU6050

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

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

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

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

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

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)
   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!")
   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 !")


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

  •  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.address(bus, dev_addr, i2c.TRANSMITTER)
  i2c.write(bus, 59)
  i2c.address(bus, dev_addr, i2c.RECEIVER), 14)
  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

8. Main program

  • 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

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

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 nEXT Evo bare PCB has also been made available directly at Dirty PCBs, our preferred PCB House for experimenting (**):

(**) - 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)
     c=i2c.address(i2c_id, dev_addr ,i2c.TRANSMITTER)
     return c

2. Scan Bus for devices function

 function scanbus()
    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)
            if i==72 then
            print("- LM75 Temperature sensor         - found at address 0x"..string.format("%02X",i).." -> "..i)
            if i==96 then
            print("- MCP4728 - 4x12Bit DAC           - found at address 0x"..string.format("%02X",i).." -> "..i)
            if i==104 then
            print("- MCP3421 - 18Bit ADC             - found at address 0x"..string.format("%02X",i).." -> "..i)
            if i==60 then
            print("- SSD1306 OLED Display            - found at address 0x"..string.format("%02X",i).." -> "..i)
            print("- NEW UNREGISTERED DEVICE         - found at address 0x"..string.format("%02X",i).." -> "..i)

 3. MAIN Scanbus Program


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.


  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)
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:setRot180()           -- use it for rotate display

2. Print Text routine
str2="Hello World!!"

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

3. Print on Display function
function print_OLED()
     disp:drawCircle(64, 47, 14)
   until disp:nextPage() == false

4. Main program
str2="Hello World!!"


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

 for r=30, 1, -1 do
     disp:drawCircle(64, 32, r)
   until disp:nextPage() == false

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

CBDB nEXT Evo bare PCB has also been made available directly at Dirty PCBs, our preferred PCB House for experimenting (**):

(**) - 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: 

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

  • 4x12 BIT DAC

  • 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:


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

Tuesday, November 24, 2015

P2 - ESP8266 DevBoard - CBDB nEXT EVO - Firmware

  Part 2 of the the new ESP8266 nEXT Evolution Board Series

For any new CBDB orders/requests please feel free to use as usual:
     tech at

CBDB nEXT Evo bare PCB has also been made available directly at Dirty PCBs, our preferred PCB House for experimenting (**):

(**) - 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. But more about this one in the next articles.  -------------------------------------------------------------------------------------------------------------------------

First thing to see is how easy is the process to configure and start using CBCB nEXT EVO Board. It will come preconfigured with NodeMCU, so, if LUA is your desired programming language you can just start using it.

   In case of firmware update needed or if you want to change the environment, it is a very easy process, almost similar with the one used for MPSM Board for example.

What we will need:

Uploading  new firmware:

  • connect CBDB nEXT EVO Board with the USB Cable.
  •  Press PROG + RESET Buttons and power up (plug it into PC USB port)
  • Start NodeMCU Flasher. Choose you USB adapter corresponding port
  • Add from Config Menu latest previously downloaded firmware. It must start from 0x0000. Disable anything else. 
  • Go back on Operation tab. Power off your CBDB Module. Press FLASH Button. power ON quick CBDB module. It will be recognised and will start flashing. Give it a second try if necessary.
  •  When finished succesfully A green OK checkmark will appear
  •  Power Off CBDB Module, Remove yellow jumper. Power back ON. Your nEXT EVO Board should be now programmed with the new NodeMCU Firmware.

If you have trouble to keep pressed both PROG and RESET buttons ,you can use a jumper from GPIO to GND as a replacement for PROG button and press just RESET when necessary:

For further programming in LUA, it might be possible to do it directly in your Serial Terminal Program but I will recomend you to use a more dedicated program for that, like ESPlorer or LuaUploader. I will stay with the latest one, for it's great flexibility and simplicity.

   To run a quick test, you can just use the code snippets provided by LuaUploader at start-up. Select the piece of code that you want to run and press "Execute Selection" button.

  • To quick setup your WIFI network :
        -- One time ESP Setup --
         wifi.sta.config ( "YOUR_WIFI_SSID" , "PASSWORD" ) 

  • For the Blinky test we will use the onboard LED connected to GPIO2 and run the code from below

                -- Blink using timer alarm --
                timerId = 0 -- we have seven timers! 0..6
                dly = 500 -- milliseconds
                ledPin = 4 -- 4=GPIO2
               ledState = 0
               tmr.alarm( timerId, dly, 1, function()
                  ledState = 1 - ledState;
                  gpio.write(ledPin, ledState)

 For all the Arduino IDE lovers:

Arduino IDE first test for direct programming and firmware uploading on the new ESP8266 CBDB nEXT EVO DevBoard.

 Running Blinky LED program on GPIO2:

// the setup function runs once when you press reset or power the board
void setup() {
     // initialize digital pin 2 as an output - GPIO2
     pinMode(4, OUTPUT);

// the loop function runs over and over again forever
void loop() {
     digitalWrite(2, HIGH);   // turn the LED on (HIGH is the voltage level)
     delay(500);              // wait for a second
     digitalWrite(2, LOW);    // turn the LED off by making the voltage LOW
     delay(500);              // wait for a second

If you want to use it without RESET + PROG buttons control, then just solder the back jumpers as in the picture below and No manual reset needed , no buttons to press, just press Upload in Arduino IDE and that's it!

Tuesday, November 17, 2015

New ESP8266 DevBoard - CBDB nEXT EVO!

For any new CBDB orders/requests please feel free to use as usual:
     tech at

CBDB nEXT Evo bare PCB has also been made available directly at Dirty PCBs, our preferred PCB House for experimenting (**):

(**) - 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. But more about this one in the next articles. 

   This simple ESP8266 Board is the result of searching for a smaller and somehow a  more flexibile hardware configuration than the previous CBDB Evolution DevBoard
CBDB v2 Evo is perfect for it's Development (like the Battery Monitor System for example) and Educational purposes, you have there all-in-one-board, ADC, DAC, Voltage, Temperature and Current measurement, RTC, LCD Display, buttons, everything. 
   BUT sometime you want to keep is as simple as possible. Just a core. A small one. And you don't want a external/separate USB adapter. And you want to be able to extend the Board capabilities easy with other functions, as you wish and when you wish.

If this is the case then maybe the answer can be found below.

Let's see what we need for a simple ESP8266 Board:
- ESP8266 Module 
- USB adapter
- Voltage regulator
- Extension interface

ESP8266 Module 

   Just pick one from your preffered Shop, Ebay, Banggood,Amazon, etc. Ones of the best offers that I find so far (and with modules that were working OK):

 - 5pcs x ESP07 - 14.30
 - 10pcs x ESP12 - 26.99USD

ESP8266 - CBDB nEXT EVO Core

USB adapter

  For USB adapter we will use a CH340G chip. As been in a SOP16 package it is also very easy to solderat home.

CBDB nEXT EVO - USB adapter schematic

Voltage Regulator

Because I want to be able to run the board also from a Li-Ion or Li-Po Battery, for the voltage regulator decided to use something with better specifications than the usual LD1117. 

The choosen one was MCP1825S . I've use it before in many other projects and it's very good LDO: 
-  Input Operating Voltage Range: 2.1V to 6.0V
- 500 mA Output Current Capability
-  Low Dropout Voltage: 210 mV Typical at 500 mA ! - > you have about 1V for LD1117 !
- Low Supply Current: 120 μA

CBDB nEXT EVO - Voltage Regulator

 Extension interface

     The choosen nExtensions Bus Interface that will be used for connecting the ESP8266 Main Board with the other compabile available modules is very simple one, based on the I2C standard interface.  

    In the same time, you have full access to all the pins thru JP1 and JP2 pin headers. You can even use this headers to directly connect the CBDB nEXT Board to a Breadboard as they are at a breadboard friendly distance!

Putting together all the bits and pieces, this is the final result: 

CBDB nEXT EVO 3.4d Schematic

the PCB for it: 
CBDB nEXT Evo v3.4d PCB

  and the final result: 

CBDB nEXT Evo v3.4d Board
  Next we will continue with Firmware upload and some basic tests. 

Wednesday, November 4, 2015

Raspberry PI2 + Thingspeak on JESSIE

   This is a follow-up for the previous Raspberry PI2 - Standalone Thingspeak server installation

   Because many people have encountered lots of issues with the installation, mainly r8188eu WIFI chipset driver issues or strange compile problems, I was thinking to give a chance also to the new RASPBIAN Jessie, maybe it might be possible to make life easier for many of us.

   The setup environment remain the same, same remain the SD Card flashing process, so please take a look first at : Raspberry PI2 - Standalone Thingspeak server installation

   First thing: because I use RPI2 board headless, I have disabled the new default boot to graphical interface that Jessie has, CLI is more than enough for me.

   GOOD NEWS!! The issue with the r8188eu WIFI seems to be solved. At least my dongle worked this time out of the box, nothing fancy to be done anymore.

   Below is the full transcript of a Thingspeak Server installation process finished about 30 min ago, using a fresh new RASPBIAN Jessie image:

System Update & required packages install

  • Switched over to SSH remote access with Putty - accept new key
  • Change "pi" account password:
  • Set ROOT password, so you can then use root (just for very, very special things!)
              pi@RPIMON1~$sudo passwd root
  • System Update & upgrade  :
              pi@RPIMON1~$sudo apt-get update            
              pi@RPIMON1~$sudo apt-get upgrade          
              pi@RPIMON1~$sudo apt-get dist-upgrade   
              pi@RPIMON1~$sudo sync

  • Reboot:
            pi@RPIMON1~$ sudo reboot
  • INSTALL Required packages:
           pi@RPIMON1~$sudo apt-get -y install build-essential git mysql-server mysql-client 
                                       libmysqlclient-dev libxml2-dev libxslt-dev libssl-dev libsqlite3-dev  

 MySQL Database configuration

    pi@RPIMON1~$mysql --user=root mysql -p useyourpasswd here
    pi@RPIMON1~$mysql> CREATE USER 'thing'@'localhost' IDENTIFIED BY 'speak’;
    pi@RPIMON1~$mysql> GRANT ALL PRIVILEGES ON *.* TO 'thing'@'localhost' WITH GRANT OPTION;
    pi@RPIMON1~$mysql> commit;
    pi@RPIMON1~$mysql> exit;

Ruby / Rails install

          pi@RPIMON1~$tar xvzf ruby-2.1.5.tar.gz
          pi@RPIMON1~$cd ruby-2.1.5


  Files:        962
  Classes:     1414 ( 566 undocumented)
  Modules:      268 (  87 undocumented)
  Constants:   2098 ( 624 undocumented)
  Attributes:  1146 ( 272 undocumented)
  Methods:    10651 (2228 undocumented)

  Total:      15577 (3777 undocumented)
   75.75% documented

  Elapsed: 812.6s

(That means you need to be VERY patient thru the entire process ! :) )

          pi@RPIMON1~$sudo make install
          pi@RPIMON1~$cd ..
          pi@RPIMON1~$echo "gem: --no-rdoc --no-ri" >> ${HOME}/.gemrc
          pi@RPIMON1~$sudo gem install rails


    pi@RPIMON1~$git clone
    pi@RPIMON1~$cp thingspeak/config/database.yml.example thingspeak/config/database.yml
    pi@RPIMON1~$cd thingspeak
    pi@RPIMON1~$bundle install
    pi@RPIMON1~$bundle exec rake db:create


    pi@RPIMON1~$mysql --user=root mysql -p
    pi@RPIMON1~$mysql> show databases;

#+----------------------------  +
#| Database                        |
#+----------------------------  +
#| information_schema        |
#| mysql                              |
#| performance_schema      |
#| thingspeak_development |
#| thingspeak_test               |

     pi@RPIMON1~$mysql> exit; 

IF MYSQL DB OK  then :

     pi@RPIMON1~$bundle exec rake db:schema:load


    pi@RPIMON1 ~/yourthingspeak $ rails server webrick.

 That's it! Prepare yourself for about 4 hours of patience :)

 Waiting your feedback about!