Showing posts with label tutorial. Show all posts
Showing posts with label tutorial. Show all posts

Wednesday, May 3, 2017

ESP8266 USB Programmer USBProg


USBPrg v8.4 -  a fully isolated SAFE USB to Serial adapter for communcation and programming devices protecting your USB ports and devices.


The perfect companion for a complete Development platform for your projects!

Now available on TINDIE Store: https://www.tindie.com/products/nEXT_EVO1/usbprgv84-isolated-usb-serial-programmer-adapter/

You can buy it a special price in the MPRSx8 Home Automation Development pack - MPRSx8 Dev Board + USPPrgv8.4  programmer: https://www.tindie.com/products/nEXT_EVO1/wifi-8x-mains-relays-board-for-home-automation/


------------------------------------------------------------------------------------------------------------------

What is it?

 

  A fully isolated USB to Serial adapter for communication and also programming devices protecting your USB ports and connected devices.
  Integrated hardware Autoreset function makes it suitable for direct programming ESP8266, ESP32 and other MCU's that require it.
  If you use Arduino IDE/Platformio/etc for example with ESP8266, you will love it, as it doesn't need to press anymore RST/Prog buttons for new sketch upload! The autoreset function takes care of that, putting automatically the ESP8266 module in the right boot mode.


Youtube Video step-by-step Tutorial on how to use it to program a ESP8266 Module:



 In the case above ESP8266 is embedded on a MPRSx8 Home Automation board but in the same easy way can be used for programming standalone ESP8266 modules.


Pinout



      Capabilities

    • Fully isolated interface
    • High speed (can work OK also at 115200 and up - used it with Arduino IDE/Platfromio at 921600)
    • DTR/RTS/autoreset function
    • 2.5 kV RMS integrated digital isolator from Silicon Labs
    • High electromagnetic immunity
    • Ultra low power
    • Schmitt trigger inputs
    • Transient Immunity 50 kV/μs

     

    Schematics

    USB interface



    Digital isolator



    Auto-reset circuit


    Below you can find also the wiring for the MPRSx8 Home Automation Board Programming:







    Monday, April 24, 2017

    ESPBasic - Web Interface - CSS elements example

    A quick example on how to change your Web interface GUI objects properties without using a separate CSS file.

    Reading Himidity and Temperature from a DHT22 Sesor connected to the GPIO5 and also retrieving Date and Time from NTP Server:

    PinDHT = 5
    DHT.SETUP(22, PinDHT)

    cls

    timer 1000, [branch] ' ## Time for auto refresh variables ##

    wprint |<body style="background-color:powderblue;">|
    wprint |<H1><span style="color: red;">|
    wprint "Example for changing GUI object properties with CSS"
    wprint "</H1>"
    wprint "</span>"

    wprint "<table border='1'><tr><td>Date</td><td>"
    textbox Dtm
    cssid htmlid(), "background-color: yellow;display:block;width:160px"
    wprint "</td></tr><tr><td>Humidity </td><td>"
    textbox Hum
    cssid htmlid(), "background-color: grey;color:#F00;display:block;width:40px"
    wprint "</td></tr><tr><td>Temperature Deg C</td><td>"
    textbox Temp
    cssid htmlid(), "background-color: #ccaabb;display:block;width:40px"

    wprint "</td></tr></table><p>"

    wprint "<p> Click to Exit <br>"
    button "Exit", [TestExit]

    Wait


    [TestExit]
    timer 0
    end

    [branch]
    gosub [readdata]
    wait

    [readdata]
    Dtm = time() 'Current Date and Time
    Temp = DHT.TEMP() 'Current Temperature
    Hum = DHT.HUM() 'Current Humidity


    The result looks as below:






    Friday, April 14, 2017

    Part 2 - Raspberry Pi + Domoticz AC Dimmer


         ---------------------------------------------------------------------------------------------------------------------------

                           Special April Sale Discounts!!


    Special Spring Sale discounts for all the products available on Tindie Store:
    https://www.tindie.com/stores/nEXT_EVO1/

    Including the popular MPDMv4 Universal AC Mains Dimmer and the MPRSx8 Home Automation Board!

    Spread the word and use Coupon code: NDSCVO10

    Thank you all for your support!

     ---------------------------------------------------------------------------------------------------------------------------


    Part 2 of the tutorial: Raspberry Pi + Domoticz + MPDM v4 AC dimmer board.


    Part 2 topic: Domoticz setup & final testing :





    What we will need:

    - MPDMv4 Universal AC Dimmer - available also on Tindie Store !
    - Raspberry PI 2 Board

    - PIGPIO library for Raspberry PI  - take a look at Part 1 how to install and test
    - Domoticz
       Latest available, on a Raspberry PI 2 Board install :  
         sudo curl -L install.domoticz.com | bash



    Software 

    Domoticz LUA script for RPi Dimmer:

    commandArray = {}
    DomDevice = 'RPi_Dimmer';
    if devicechanged[DomDevice] then
       if(devicechanged[DomDevice]=='Off') then
         print ("OFF dimm = "..uservariables['dimm']);
         CalcValue = 860*1000;
       else if(devicechanged[DomDevice]=='On') then
            DomValue = uservariables['dimm'];
            print ("ON dimm = "..uservariables['dimm']);
            CalcValue = DomValue;
          else
             print("Other");
             DomValue = otherdevices_svalues[DomDevice];
             CalcValue = (900-(DomValue*9))*1000;
             commandArray['Variable:dimm'] = tostring(CalcValue);
    --         commandArray['Variable:dimm'] = CalcValue;
             print ("dimm Level = "..uservariables['dimm']);
       end
       end
       runcommand = "pigs hp 18 400 " ..tonumber(CalcValue);
       print("PWM calculated value= "..CalcValue);
       print("Run command: " ..runcommand);
       os.execute(runcommand);
    end
    return commandArray

     Save it as "script_device_RPi_Dimmer.lua" in the "domoticz/scripts/lua" folder !









    --------------------------------------------------- DISCLAIMER --------------------------------------------------
    WARNING!! You will play with LIVE MAINS!! Deadly zone!! 
          If you don't have any experience and are not qualified for working with MAINS power I will not encourage you to play arround!. The author take no responsibility for any injury or death resulting, directly or indirectly, from your inability to appreciate the hazards of household mains voltages.
       The circuit diagrams are as accurately as possible, but are offered with no guarantees whatsoever. 
        There is no guarantee that this design meets any Rules which may be in force in your country so please check before your local rules/regulations.
    ----------------------------------------------------------------------------------------------------------------------------
     
                                                                 Creative Commons License

    All materials and boards released under ESP8266-Projects.com are licensed under a Creative Commons Attribution-NonCommercial 4.0 International License.   





    Wednesday, April 5, 2017

    Raspberry Pi + Domoticz AC Dimmer - Part 1


         ---------------------------------------------------------------------------------------------------------------------------

                           Special April Sale Discounts!!


    Special Spring Sale discounts for all the products available on Tindie Store:
    https://www.tindie.com/stores/nEXT_EVO1/

    Including the popular MPDMv4 Universal AC Mains Dimmer and the MPRSx8 Home Automation Board!

    Spread the word and use Coupon code: NDSCVO10

    Thank you all for your support!

     ---------------------------------------------------------------------------------------------------------------------------



    New Tutorial related with direct connection setup between Raspberry Pi board and MPDM v4 AC dimmer board.

    Part 1: General view, wiring and hardware setup :



    What we will need:

    - MPDMv4 Universal AC Dimmer - available also on Tindie Store !
    - Raspberry PI 2 Board
    - Domoticz
       Latest available, on a Raspberry PI 2 Board install :  
         sudo curl -L install.domoticz.com | bash


     

    Software 

    1. PIGPIO library for Raspberry PI install script:
    rm pigpio.zip
    sudo rm -rf PIGPIO
    wget abyz.co.uk/rpi/pigpio/pigpio.zip
    unzip pigpio.zip
    cd PIGPIO
    make -j4
    sudo make install
    save it in the choosen directory for your PIGPIO library as "install.sh" and run also command:
    chmod 775 install.sh

    2. Testing script:
    #!/usr/bin/env python

    #*** MPDMv4 Universal AC Dimmer PWM Example  ****************
    #*                                                          *
    #* This demo is using RPi2 GPIO18 (header pin 12)!!         *
    #*                                                          *
    #* Wiring table:                                            *
    #* MPDMv4      Raspberry PI 2                               *
    #*   VCNT  ->  GPIO18      - header pin 12                  *
    #*    GND  ->  GND         - header pin 6                   *
    #*    VCC  ->  VCC (+3,3V) - header pin 1                   *
    #*                                                          *
    #* tech@esp8266-projects.com                                *
    #*                                                          *
    #************************************************************
     
    import pigpio

    GPIO=18

    pi = pigpio.pi()

    if pi.connected:
       print("Connected to pigpio daemon !\n")

    dm = 0
    while dm < 860:
        dm = input("Enter Dimmer Value: ")
        dm = int(dm)
        pi.hardware_PWM(GPIO, 5000, dm*1000) # 5000Hz dm*1000% dutycycle

    print("\nOut of range. Exiting...")
    pi.hardware_PWM(GPIO, 5000, 860000) # 5000Hz 95% dutycycle
    pi.stop()


    save it as "test.py" in the PIGPIO folder generated after the full install is done.


    Next time: Domoticz setup & configuration and Dimmer testing.



    --------------------------------------------------- DISCLAIMER --------------------------------------------------
    WARNING!! You will play with LIVE MAINS!! Deadly zone!! 
          If you don't have any experience and are not qualified for working with MAINS power I will not encourage you to play arround!. The author take no responsibility for any injury or death resulting, directly or indirectly, from your inability to appreciate the hazards of household mains voltages.
       The circuit diagrams are as accurately as possible, but are offered with no guarantees whatsoever. 
        There is no guarantee that this design meets any Rules which may be in force in your country so please check before your local rules/regulations.
    ----------------------------------------------------------------------------------------------------------------------------
     
                                                                 Creative Commons License

    All materials and boards released under ESP8266-Projects.com are licensed under a Creative Commons Attribution-NonCommercial 4.0 International License.   




    Friday, February 24, 2017

    ESPBasic Series : Decimal-to-Binary conversion


       I was looking a while ago to implement some Decimal-to-Binary conversion subroutine to be used for easy visualisation of the Registry content. Been able to see the values directly binary can help a lot when developping a driver for a IC or any piece of related software:


    1. Decimal-to-Binary subroutine:
     [decbin]
      i = 1
      r = 0
      binval = 0
      nr = decval
     Do
       r = nr % 2
       nr = int(nr/2)
       binval = binval + r*i
       i = i*10
     Loop while nr > 0
    wait

      2. Test Program:
    decval = 0
    binval = 0
    wprint "<br><br>Decimal value "

    textbox decval
    button " Convert ", [decbin]

    wprint "<br><br> Binary value "
    textbox binval
    wprint "<br><br>"
    button " Exit ", [TestExit] 
    Wait

    [TestExit]
     Looking forward to see your own ideas about!

    Happy breadboarding,
    TJ.

    Thursday, February 16, 2017

    ESPBasic Series - DEC to BCD and BCD to DEC conversions


    In the process of working on a new Driver Tutorial for the ESPBasic Series I am looking today to implement some Decimal-to-BCD and BCD-to-Decimal subroutines.

    What I have done so far:

    1. BCD-to-Decimal subroutine:
    [DEC]
    hv = val >> 4
    hl = val and 15
    val = hv*10 + hl
    wait 
     2. Decimal-to-BCD subroutine:
    [BCD]
    d = int( val / 10 )
    d1 = d * 10
    d2 = val - d1
    val = d*16 + d2
    wait

     3. Test Program
    let val = 96
    textbox val
    button "To DEC", [DEC]
    button "To BCD", [BCD]
    wprint "<br><br>"
    button " Exit ", [TestExit]
    wait

    [TestExit]
    end


    If you have any other idea please feel free to share it, looking forward to see smarter solutions that that. I'm sure they are!

    Happy breadboarding,
    TJ.

    Monday, November 14, 2016

    Mailbag - PCF8591 I2C 8 bit ADC/DAC Driver - Part 2








    ESP Basic series -  I2C driver example for the PCF8591 I2C 8-bit A/D and D/A converter - PART2

    For a deeper description of the PCF8591 and simple DAC driver example please go to PART 1



     What we will need:


        Connection with the ESP8266 nEXT EVO Board is very easy, as PCF8591 Module connector is fully compatible with the nEXT Bus connector.


    Driver implementation
    As been a I2C compatible device you need to have a standard I2C Bus Initialisation function as usual and also to know the I2C address of the device.  
    For a detailed PCF 8591 Control Byte description go to PART1.


    Software: 

    1. Main program: 
     
    let address = 72   'PCF8591 I2C Address
    i2c.setup(4,5)       'choose your I2C bus pins

    cls
    let dac = 0
    let dac_v = 0
    let adc0_1 = 0
    let adc0_v = 0
    let v_cal = 0.0128

    adc0_1 = "ADC stopped"

    wprint " <b>PCF8591 8-bit A/D and D/A converter driver demo</b><br><i>by tech@esp8266-projects.com</i><br><br> "

    wprint " Input DAC value"
    textbox dac

    button " Set Value ",[SetDAC]

    wprint " <br>DAC Output (V)"
    textbox dac_v

    wprint "<br>"

    wprint "<br><br>ADC0 Read Value:"
    textbox adc0_1

    wprint "<br>ADC0 Read (Volt):"
    textbox adc0_v
    wprint "<br><br>"
     
    button " Start ADC_0 ",[ADC0]
    button " Stop ADC", [Exit ADC]

    wprint "<br><br>"
    button " Stop Program", [Exit]

    wait


    2. Set DAC subroutine: 

     [SetDAC]
    dac_v = dac * v_cal

    i2c.begin(address)
    i2c.write(64)  'DAC Enable
    delay 5
    i2c.write(dac)
    i2c.end()
    wait


    3. Enable ADC subroutine:

    [ADC0]
    timer 1000, [readADC]
    wait

     

    4. Read ADC subroutine:
     
    [readADC]
    ch = 64
    i2c.begin(address)               'start another transaction
    i2c.write(ch)                         'point to the ADC_0 - keep DAC ON
    delay 5
    i2c.end()                                'end write transaction

    i2c.begin(address)                 'start another transaction
    i2c.requestfrom(address,2)    'start a transaction to read 2 bytes
    delay 5
    adc0_0 = i2c.read()              'read the 1st byte
    adc0_1 = i2c.read()              'read the 2nd byte
    i2c.end()                                'end read transaction
    adc0_v = v_cal + adc0_1 * v_cal
    wait

     

    5. EXIT ADC subroutine:
     
    [Exit ADC]
    timer 0
    adc0_1 = "ADC stopped"
    wait



     

    6. Exit Program button subroutine:
     
    [Exit]
    timer 0
    end

     

    In the ESP Basic Web editor interface Type & Save your program as "PCF8591.bas" and Run it.  

    If all OK the result should look as below:



    Friday, November 11, 2016

    Mailbag - PCF8591 I2C 8 bit ADC/DAC Driver - Part 1








    ESP Basic series -  I2C driver example for the PCF8591 I2C 8-bit A/D and D/A converter.


    General view:



       The PCF8591 is a single-chip, single-supply low-power 8-bit CMOS data acquisition
    device with four analog inputs, one analog output and a serial I2C-bus interface. Three
    address pins A0, A1 and A2 are used for programming the hardware address, allowing
    the use of up to eight devices connected to the I2C-bus without additional hardware.
    Address, control and data to and from the device are transferred serially via the two-line
    bidirectional I2C-bus.
     

      The functions of the device include analog input multiplexing, on-chip track and hold
    function, 8-bit analog-to-digital conversion and an 8-bit digital-to-analog conversion. The
    maximum conversion rate is given by the maximum speed of the I2C-bus.



    Features:

    • Single power supply
    • Operating supply voltage 2.5 V to 6.0 V
    • Low standby current
    • Serial input and output via I2C-bus
    • I2C address selection by 3 hardware address pins
    • Max sampling rate given by I2C-bus speed
    • 4 analog inputs configurable as single ended or differential inputs
    • Auto-incremented channel selection
    • Analog voltage range from VSS to VDD
    • On-chip track and hold circuit
    • 8-bit successive approximation A/D conversion
    • Multiplying DAC with one analog output.

    For more details please take a look at the PCF8591 Datasheet


    What we will need:

        Connection with the ESP8266 nEXT EVO Board is very easy, as PCF8591 Module connector is fully compatible with the nEXT Bus connector.



    Driver implementation

    As been a I2C compatible device you need to have a standard I2C Bus Initialisation function as usual and also to know the I2C address of the device.

    Control Byte is the second byte sent to a PCF8591 device and is stored in its control register and is required to control the device function :


     Things to take care about: 

     The upper nibble of the control register is used for enabling the analog output, and for programming the analog inputs as single-ended or differential inputs. 
      The lower nibble selects one of the analog input channels defined by the upper nibble .

      If the auto-increment flag is set, the channel number is incremented automatically after each A/D conversion. If the auto-increment mode is desired in applications where the internal oscillator is used,
    the analog output enable flag must be set in the control byte (bit 6). This allows the
    internal oscillator to run continuously, by this means preventing conversion errors
    resulting from oscillator start-up delay. 


      The analog output enable flag can be reset at other times to reduce quiescent power consumption.
     

       The selection of a non-existing input channel results in the highest available channel number being allocated. Therefore, if the auto-increment flag is set, the next selected channel is always channel 0. 

       The most significant bits of both nibbles are reserved for possible future functions and must be set to logic 0. After a Power-On Reset (POR) condition, all bits of the control register are reset to logic 0. 
       The D/A converter and the oscillator are disabled for power saving. 
       
      The analog output is switched to a high-impedance state.
     

    Software: 

    1. Main program: 
     
    let address = 72 'PCF8591 I2C Address
    i2c.setup(4,5) 'choose your I2C bus pins

    cls
    let dac = 0
    let dac_v = 0
    let v_cal = 0.0128

    wprint " <b>PCF8591 - 8-bit A/D and D/A converter driver <br>DAC demo</b><br><i>by tech@esp8266-projects.com</i><br><br> "

    wprint " Input DAC value"
    textbox dac

    button " Set Value ",[SetDAC]

    wprint " <br>DAC Output (V)"
    textbox dac_v

    wprint "<br><br>"
    button " Stop Program", [Exit]

    wait




    2. Set DAC subroutine: 

     
    [SetDAC]
    dac_v = dac * v_cal
    i2c.begin(address)
    i2c.write(64) 'Enable DAC
    delay 5
    i2c.write(dac)
    i2c.end()
    wait


    3. EXIT program button:

    [Exit]
    timer 0
    end


    In the ESP Basic Web editor interface Type & Save your program as "PCF8591.bas" and Run it.  

     
    If all OK the result should look as below:




    If you want your program to start automatically at reboot/power ON then just Save it as "default.bas" and also from Settings Tab enable the "Run default.bas at startup".
      



    Be aware that at start-up/reboot, it is a delay before your program will start automatically.



    In  the next part about PCF8591 we will talk about the ADC Driver implementation.





    Thursday, October 27, 2016

    ESP Basic Tutorial - Beep Button


    ESP Basic tutorial: How to "beep" your Button in the Web interface using a bit of Javascript :)

    Take the code from below and save it in "beep.js" file on your PC

    <code>
    function beep() {
      (new
        Audio(
        "data:audio/wav;base64,//uQRAAAAWMSLwUIYAAsYkXgoQwAEaYLWfkWgAI0wWs/ItAAAGDgYtAgAyN+QWaAAihwMWm4G8QQRDiMcCBcH3Cc+CDv/7xA4Tvh9Rz/y8QADBwMWgQAZG/ILNAARQ4GLTcDeIIIhxGOBAuD7hOfBB3/94gcJ3w+o5/5eIAIAAAVwWgQAVQ2ORaIQwEMAJiDg95G4nQL7mQVWI6GwRcfsZAcsKkJvxgxEjzFUgfHo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////// /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////VEFHAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAU291bmRib3kuZGUAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAMjAwNGh0dHA6Ly93d3cuc291bmRib3kuZGUAAAAAAAAAACU="
        )).play();
    }
    </code>

    Upload "beep.js" file on your ESP8266

    Type,  Save as "sound.bas" & RUN the code from below on your ESP8266 :

    <code>
     cls
    javascript beep.js
    wprint |<BUTTON onClick="beep();">Beep!</BUTTON>|
    wait
    </code>

    Press the Beep! button. Does it beep or not? :)

    --------------------------------------------------------------------------------------------------------------------------

    !! Update !!

    SECOND OPTION

    If you don't want to embed also the sound data and maybe want to load it from an external server then this can be done as below:

    Code to be typed saved on your PC as "playsound.js":

    <code>
    function PlaySound() {
      var sound = document.getElementById("audio");
      sound.play()
    }
    </code>

    Upload "playsound.js" file on your ESP8266.


    Type,  Save as "sound2.bas" & RUN the code from below on your ESP8266 :

     <code>
     cls
    wprint "Let's try a Beep!<br><br>"
    wprint |<audio id="audio" src="http://www.soundjay.com/button/beep-06.wav" autostart="false" ></audio>|
    javascript playsound.js
    wprint |<a onclick="PlaySound()"> Play</a>|
    wait
    </code>

    Click on play "Play". Does it beep or not? :)

    Thursday, August 4, 2016

    ESP Basic -3 - PCF8574 I2C I/O 8 x independent switches example



    8 x Independent switches driver Example :






      
       After doing last time the Mutually exclusive 8x Switch driver example, now is time for a 8 x independent switches implementation .


    What we will need: 


          This is how is looking the setup on a breadboard, for a better visibility:





    Software implementation:

    Something to remember: 

    • PCF8574 can SINK but NOT SOURCE much current - 100uA only (it cannot output high, if you want). Look at the above example how is connected the LED for SINKING current.
    • Each of the 8 GPIOs have a minimum guaranteed sinking current of 10 mA per bit at 5 V.
    • Each pin needs its own limiting resistor to prevent damage to the device!! keep under 25mA/pin.
    • Maximum device limit sink current in about 80mA. If you need more, look after PCA8574 (200mA max sink current!)

    For more details please take a look at the PCF8574 Datasheet


    ESP8266 Basic code: 
    let address = 32 'PCF8574 I2C Address

    i2c.begin(address)
    ss = 0 xor 255 'XOR - Bit masking for the desired I/O pins
    i2c.write(ss)
    i2c.end()
    button "1", [1]
    button "2", [2]
    button "3", [3]
    button "4", [4]
    button "5", [5]
    button "6", [6]
    button "7", [7]
    button "8", [8]
    button "OFF", [9]
    wait

    [9]
    i2c.begin(address)
    ss = 0 xor 255 'XOR - Bit masking for the desired I/O pins
    i2c.write(ss)
    i2c.end()
    wait

    [1]
    i2c.begin(address)
    ss = ss xor 1   'XOR - Bit masking for the desired I/O pins
    i2c.write(ss)
    i2c.end()
    wait

    [2]
    i2c.begin(address)
    ss = ss xor 2
    i2c.write(ss)
    i2c.end()
    wait

    [3]
    i2c.begin(address)
    ss = ss xor 4
    i2c.write(ss)
    i2c.end()
    wait

    [4]
    i2c.begin(address)
    ss = ss xor 8
    i2c.write(ss)
    i2c.end()
    wait

    [5]
    i2c.begin(address)
    ss = ss xor 16
    i2c.write(ss)
    i2c.end()
    wait

    [6]
    i2c.begin(address)
    ss = ss xor 32
    i2c.write(ss)
    i2c.end()
    wait

    [7]
    i2c.begin(address)
    ss = ss xor 64
    i2c.write(ss)
    i2c.end()
    wait

    [8]
    i2c.begin(address)
    ss = ss xor 128
    i2c.write(ss)
    i2c.end()
    wait

    This is how is looking the interface in the Web Browser after running the above program:



    PS: credit for the XOR Bit masking goes this time to Forlotto from the esp8266.com forum who posted quicker than me this elegant solution :)

    ESP Basic -1 - PCF8574 I2C I/O Expander Driver example



    Mutually-exclusive switch driver Example :







         Now that we have the I2C scanner program  that can help us to detect our I2C devices is time to move to some driver examples

        I think everybody know already the famous PCF8574. I have also cover it extendely in the previous Articles about, here for I/O input and here for output I/O.

        Now is time to put it at work also in ESP8266 Basic and see how is working.

       The example for today is a implementation of a mutually-exclusive switch that can be handy for many, many things as for example for doing the selection of a source in a Audio mixer or a any other analog path. Or driving Power relays.

       Mutually exclusive switch means  that when the corresponding switch button is pressed ON must also automatically turn the other sources OFF.



    What we will need: 


          This is how is looking the setup on a breadboard, for a better visibility:





    Software implementation:

    Something to remember: 

    • PCF8574 can SINK but NOT SOURCE much current - 100uA only (it cannot output high, if you want). Look at the above example how is connected the LED for SINKING current.
    • Each of the 8 GPIOs have a minimum guaranteed sinking current of 10 mA per bit at 5 V.
    • Each pin needs its own limiting resistor to prevent damage to the device!! keep under 25mA/pin.
    • Maximum device limit sink current in about 80mA. If you need more, look after PCA8574 (200mA max sink current!)

    For more details please take a look at the PCF8574 Datasheet


    ESP8266 Basic code: 
    let address=32     'PCF8574 I2C Address

    button "1", [1]     'Define push buttons for each I/O pin
    button "2", [2]
    button "3", [3]
    button "4", [4]
    button "5", [5]
    button "6", [6]
    button "7", [7]
    button "8", [8]
    button "OFF", [9]  'Button for turning OFF all
    wait

    [9]
    i2c.begin(address)    'Start I2C communication with device at 'address'
    i2c.write(255)           'write the corresponding I/O pin value to register
    i2c.end()                   'end I2C communication
    wait

    [1]
    i2c.begin(address)
    i2c.write(254)
    i2c.end()
    wait

    [2]
    i2c.begin(address)
    i2c.write(253)
    i2c.end()
    wait

    [3]
    i2c.begin(address)
    i2c.write(251)
    i2c.end()
    wait

    [4]
    i2c.begin(address)
    i2c.write(247)
    i2c.end()
    wait

    [5]
    i2c.begin(address)
    i2c.write(239)
    i2c.end()
    wait

    [6]
    i2c.begin(address)
    i2c.write(223)
    i2c.end()
    wait

    [7]
    i2c.begin(address)
    i2c.write(191)
    i2c.end()
    wait

    [8]
    i2c.begin(address)
    i2c.write(127)
    i2c.end()
    wait

    This is how is looking the interface in the Web Browser after running the above program:



    Monday, August 1, 2016

    ESP Basic - I2C Bus scanner example

    UPDATE !! UPDATE !!UPDATE !!UPDATE !!
    From ESPBasic Version 3.0 Alpha 43 you have also the i2c.setup function available!!

    i2c.setup():

    Will change the default pins for the i2c interface.  
    i2c.setup({SDA}, {SCL})

    ----------------------------------------------------------------------------------------------------

    From today I will start a new Series related with ESP Basic (www.esp8266basic.com)


    When working with a lot of I2C devices one of the first thing that you need is a simple I2C scanner that can help you to identify the IC's and do some very basic troubleshooting.








    What we will need: 
    • ESP8266 nEXT EVO Board
    • ESP8266 nEXT EVO - Analog Extension Board - AN1 (I2C devices onboard to test our scanner )
    • For programming and uploading the driver and the software we will use ESP8266 Basic .  


      nEXT EVO + AN-1 extension board



      I2C Scanner Software:

      UPDATE !! UPDATE !!UPDATE !!UPDATE !!
      From ESPBasic Version 3.0 Alpha 43 you have also the i2c.setup function available!!

      i2c.setup():

      Will change the default pins for the i2c interface.  
      i2c.setup({SDA}, {SCL})



                i2c.setup(4,5)
      for address = 1 to 127
         i2c.begin(address)
         stat = i2c.end()

         if stat < 1 then
           ' print stat
            wprint "Found I2C device at address: 0x" & hex(address)
            wprint " - > " & address
            wprint " <br>"
       endif
      next
      wait
       And the scanning result in browser :



      As you can see, has properly detected the I2C devices that are on the AN-1 Extension board:

      - PCF8574      - 8Bit I/O EXT port      - found at address 0x20 -> 32
      -
      LM75           - Temperature sensor    - found at address 0x48 -> 72
      -
      MCP4728    - 4x12Bit DAC              - found at address 0x60 -> 96
      -
      MCP3421    - 18Bit ADC                  - found at address 0x68 -> 10

    Please keep in mind that in ESP Basic you have hardcoded I2C pins yet, SDA -> GPIO0 and SCL -> GPIO2.

    Don't forget to add if needed pullup resistors on both lines, 4K7 should be OK. In case of AN-1 they are NOT needed.