Hot!ESP8266 with PIC16F690

Author
Moni_a
New Member
  • Total Posts : 1
  • Reward points : 0
  • Joined: 2018/02/17 01:21:17
  • Location: 0
  • Status: offline
2018/02/22 07:55:11 (permalink)
0

ESP8266 with PIC16F690

Hey Guys,
I have downloaded the latest NodeMcu Lua firmware for ESP8266-01. I have no idea on how to integrate it with PIC as I am used to giving AT commands. All the online tutorials are only serve for Arduino. Please help with appropriate solutions:)
#1

17 Replies Related Threads

    katela
    Super Member
    • Total Posts : 954
    • Reward points : 0
    • Joined: 2013/06/11 05:25:18
    • Location: South Africa
    • Status: offline
    Re: ESP8266 with PIC16F690 2018/02/26 16:11:31 (permalink)
    +1 (1)
    What you want to do exactly with a PIC? You can use the ESP8266 as a standalone microcontroller, it has 16 GPIO pins, SPI, I²C , UART and ADC pins, Or you can send it standard AT command from the microcontroller via the UART module.
    You can't program it in the MPLAB environment. 

    Free online Microcontroller Tutorials and Projects for Hobbyists and students. From beginners to advanced. Website: www.studentcompanion.co.za
    YouTube Tutorials: https://www.youtube.com/user/StudentCompanionSA
    #2
    Lurch
    Super Member
    • Total Posts : 633
    • Reward points : 0
    • Joined: 2010/08/04 14:05:04
    • Location: 0
    • Status: offline
    Re: ESP8266 with PIC16F690 2018/02/27 01:12:38 (permalink)
    +1 (1)
    The ESP8266-01 only has a serial port and two GPIO lines. If you want to control the ESP from the PIC, then you can use the serial interface with AT commands. If you want to control the PIC from the ESP, then maybe using the two GPIO lines as I2C and the PIC as I2C-slave. The PIC16F690 might be small, as far as memory goes.
    If you just want ports, then you could use an mcp23s17 with I2C to get more ports?  
    #3
    Akshayy
    Super Member
    • Total Posts : 351
    • Reward points : 0
    • Joined: 2016/07/29 06:35:35
    • Location: 0
    • Status: offline
    Re: ESP8266 with PIC16F690 2018/02/28 05:43:37 (permalink)
    +1 (1)
    Connect
    PIC16F690 TX pin- ESP8266 RX pin
    PIC16F690 RX pin- ESP8266 TX pin.
     
    You will easily get UART drivers for PIC.
    Write application accordingly.
     

    Regards,
    Akshay.
    #4
    ArakelTheDragon
    New Member
    • Total Posts : 14
    • Reward points : 0
    • Joined: 2016/12/11 07:12:00
    • Location: 0
    • Status: offline
    Re: ESP8266 with PIC16F690 2018/08/04 08:47:22 (permalink)
    0
    Thanks. This is the hardware part. What about the software, any ideas? I need bidirectional communication so the serial pins should do.
     
    My idea is the nodeMCU to only send information to a web server and to a few PIC16F690s. That way I can control a few pics from the web server.
    post edited by ArakelTheDragon - 2018/08/04 08:48:53
    #5
    katela
    Super Member
    • Total Posts : 954
    • Reward points : 0
    • Joined: 2013/06/11 05:25:18
    • Location: South Africa
    • Status: offline
    Re: ESP8266 with PIC16F690 2018/08/04 09:18:12 (permalink)
    +1 (1)
    Maybe you can start by posting your code and explain what is not working. That way it's easy to get assistance.

    Free online Microcontroller Tutorials and Projects for Hobbyists and students. From beginners to advanced. Website: www.studentcompanion.co.za
    YouTube Tutorials: https://www.youtube.com/user/StudentCompanionSA
    #6
    Aussie Susan
    Super Member
    • Total Posts : 3333
    • Reward points : 0
    • Joined: 2008/08/18 22:20:40
    • Location: Melbourne, Australia
    • Status: offline
    Re: ESP8266 with PIC16F690 2018/08/05 19:18:55 (permalink)
    0
    I think you are now asking how to have the PIC interpret the strings that will be sent from the ESP2866?
    For that you will also need to tell us exactly what strings the PIC is expected to interpret so that we can suggest appropriate techniques that will fit into the 4K words of FLASH that you have available in that device - unless it is something very simple, you may need a bigger processor.
    Susan
    #7
    ArakelTheDragon
    New Member
    • Total Posts : 14
    • Reward points : 0
    • Joined: 2016/12/11 07:12:00
    • Location: 0
    • Status: offline
    Re: ESP8266 with PIC16F690 2018/08/06 10:15:52 (permalink)
    +1 (1)
    It is a simple board that controls 8 relays (5V input, 230VAC contacts).
     

    /**
    * reuseConnection.ino
    *
    * Created on: 22.11.2015
    *
    */

    #include <Arduino.h>
    #include <ESP8266WiFi.h>
    #include <ESP8266WiFiMulti.h>
    #include <ESP8266HTTPClient.h>
    const char* ssid = "PROTACK1";
    const char* password = "hostprotack";
    int WiFiCon() {
    // Check if we have a WiFi connection, if we don't, connect.
    int xCnt = 0;
    if (WiFi.status() != WL_CONNECTED){
    Serial.println();
    Serial.println();
    Serial.print("Connecting to ");
    Serial.println(ssid);
    WiFi.mode(WIFI_STA);

    WiFi.begin(ssid, password);

    while (WiFi.status() != WL_CONNECTED && xCnt < 50) {
    delay(500);
    Serial.print(".");
    xCnt ++;
    }
    if (WiFi.status() != WL_CONNECTED){
    Serial.println("WiFiCon=0");
    return 0; //never connected
    } else {
    Serial.println("WiFiCon=1");
    Serial.println("");
    Serial.println("WiFi connected");
    Serial.println("IP address: ");
    Serial.println(WiFi.localIP());
    return 1; //1 is initial connection
    }
    } else {
    Serial.println("WiFiCon=2");
    return 2; //2 is already connected

    }
    }
    //IP or name of address root: ie: google.com
    //NOT google.com/nothing/after/the/dotcom.html
    const char* hostGet = "cfcbazar.com";

    void postData() {
    WiFiClient clientGet;
    const int httpGetPort = 80;
    //the path and file to send the data to:
    String urlGet = "/data.esp8266.php";

    // We now create and add parameters:
    String src = "ESP";
    String typ = "flt";
    String nam = "temp";
    String vint = "92";
    urlGet += "?src=" + src + "&typ=" + typ + "&nam=" + nam + "&int=" + vint;

    Serial.print(">>> Connecting to host: ");
    Serial.println(hostGet);

    if (!clientGet.connect(hostGet, httpGetPort)) {
    Serial.print("Connection failed: ");
    Serial.print(hostGet);
    } else {
    clientGet.println("GET " + urlGet + " HTTP/1.1");
    clientGet.print("Host: ");
    clientGet.println(hostGet);
    clientGet.println("User-Agent: ESP8266/1.0");
    clientGet.println("Connection: close\r\n\r\n");

    unsigned long timeoutP = millis();
    while (clientGet.available() == 0) {

    if (millis() - timeoutP > 10000) {
    Serial.print(">>> Client Timeout: ");
    Serial.println(hostGet);
    clientGet.stop();
    return;
    }
    }
    //just checks the 1st line of the server response. Could be expanded if needed.
    while(clientGet.available()){
    String retLine = clientGet.readStringUntil('\r');
    Serial.println(retLine);
    break;
    }
    } //end client connection if else

    Serial.print(">>> Closing host: ");
    Serial.println(hostGet);

    clientGet.stop();
    }

    void setup() {

    Serial.begin(115200);
    WiFiCon();
    }
    void loop() {
    if (WiFiCon() > 0) {
    postData();
    }
    delay(1000);
    }
     

     
    This is the nodeMCU v1.0 code with 1kb flash. The PIC is PIC16F690.
    #8
    ArakelTheDragon
    New Member
    • Total Posts : 14
    • Reward points : 0
    • Joined: 2016/12/11 07:12:00
    • Location: 0
    • Status: offline
    Re: ESP8266 with PIC16F690 2018/08/06 10:23:59 (permalink)
    0
    Since I do not have access to the "microchip" site to edit my post, I post a second one.
     
    The idea is how to setup the nodeMCU to communicate with the PIC and how to make a web server with a ".php" file which when started in the browser will show the state of the 8 relays (as "ON" or "OFF") and the buttons will be able to change the state of the relays. I am guessing the PIC16F690 is programmed just for a normal RS232 communication without the MAX232 converter chip as we have communication between 2 MCUs. I will use a TTL to 3.3V converter instead.
    #9
    qɥb
    Monolothic Member
    • Total Posts : 3329
    • Reward points : 0
    • Joined: 2017/09/09 05:07:30
    • Location: Jupiter
    • Status: offline
    Re: ESP8266 with PIC16F690 2018/08/06 13:03:58 (permalink)
    +1 (1)
    Do you understand that PHP code runs on the server, not the client, so this is NOT a simple web server?
     

    This forum is mis-configured so it only works correctly if you access it via https protocol.
    The Microchip website links to it using http protocol. Will they ever catch on?
    PicForum "it just works"
    #10
    ArakelTheDragon
    New Member
    • Total Posts : 14
    • Reward points : 0
    • Joined: 2016/12/11 07:12:00
    • Location: 0
    • Status: offline
    Re: ESP8266 with PIC16F690 2018/08/06 13:05:53 (permalink)
    0
    qɥb
    Do you understand that PHP code runs on the server, not the client, so this is NOT a simple web server?
     


    Yes, I understand and I have a web server, but that does not mean that I can program the ".php" code. I also know about the PIC18 and so on series, on which you can run the server directly, but at the moment I have these boards and I want to use them.
     
    EDIT:
    I have already made the part, where the information is recorded to a ".txt" file. But I do not know how to make it with a button interface.
    post edited by ArakelTheDragon - 2018/08/06 13:07:05
    #11
    ArakelTheDragon
    New Member
    • Total Posts : 14
    • Reward points : 0
    • Joined: 2016/12/11 07:12:00
    • Location: 0
    • Status: offline
    Re: ESP8266 with PIC16F690 2018/10/10 03:49:55 (permalink)
    0
    It has been a long time, I hope someone is still active.
     
    I use the nodeMCU v1.0 (rev 2) to send a 16bit variable to the PIC. it seems to be working, however there are a some pins that are not active. I am guesiing that the analog modules need to be disabled and then the pins would work. I am using RS232 with receive and transmit pins (RA5, RA4). My ideas is to connect the 3 available RS232 interfaces to 3 PICs.
     
    The code is not with the "XC8" compiler, which is the reason why I have not posted it.
     
    On the "MPLAB X" simulator the registers "PORTA, PORTB PORTC" are set proper;y, but on the real PIC they are not. For some reason only the PORTC is set, PORTB and PORTC are not.
    post edited by ArakelTheDragon - 2018/10/10 03:51:45
    #12
    Aussie Susan
    Super Member
    • Total Posts : 3333
    • Reward points : 0
    • Joined: 2008/08/18 22:20:40
    • Location: Melbourne, Australia
    • Status: offline
    Re: ESP8266 with PIC16F690 2018/10/10 18:21:55 (permalink)
    0
    ArakelTheDragon
    On the "MPLAB X" simulator the registers "PORTA, PORTB PORTC" are set proper;y, but on the real PIC they are not. For some reason only the PORTC is set, PORTB and PORTC are not.

    This is an interesting statement but if you want someone to assist in in finding out why then we will need a lot more information; like the source code, how are you checking that the ports are not set correctly etc.
    Susan
    #13
    ArakelTheDragon
    New Member
    • Total Posts : 14
    • Reward points : 0
    • Joined: 2016/12/11 07:12:00
    • Location: 0
    • Status: offline
    Re: ESP8266 with PIC16F690 2018/10/10 18:33:15 (permalink)
    0
    I check the ports with a LED connected to groung and the port on the universal solderless development board.
     
    The source code:

     
     
     
    /************************************************************************
    * *
    * Filename: RS232-Proteus-CCS-PIC-C-PIC-16F690.txt *
    * File Version: 1.0 *
    * *
    * Author:  *
    * *
    *************************************************************************
    * *
    * Architecture: Mid-range PIC *
    * Processor: 16F690 *
    * Compiler: CCS PCB v5.061 *
    * *
    *************************************************************************
    * *
    * Files required: none *
    * *
    *************************************************************************
    * *
    * Description: RS232 communication *
    * Video-link: *
    * *
    * RS232 communications serial interface, voltage range from *
    * +-3 to +-25 by standard *
    * *
    * +-13 is commonly used *
    * *
    * +-3V is our commonly used dead zone used for noise absorbtion *
    * *
    * *
    *************************************************************************
    * *
    * Pin assignments: *
    * Transmit = PIN_A4 *
    * Receive = PIN_A5 *
    * *
    ************************************************************************/
     
     
     
    #include <16F690.h>
    /****CONFIGURATION******/
    #fuses NOMCLR, NOWDT, NOPROTECT, NOBROWNOUT, INTRC_IO /* Ext. reset, no watchdog, no code protect, no brownout reset, ext.
    oscilator */

    /****RS232 CONFIGURATION****/
    #use delay(clock=4M) /* We specify the clock frequency to use the "delay_()" function */
    #use rs232(baud=9600, xmit=PIN_A4, rcv=PIN_A5) /* RS232 parameters, baud rate = 9600, no parity bit */
     
     
     
    /* transmit pin = RC6, receive pin = RC7, 8 bits per transmitted data, hardware UART won't lockup with the "errors" setting or freeze when more than 2 characters come from the PC */
     
     
     
    void main(void)
    {
    unsigned int16 rx, ShadowRegisterA, ShadowRegisterB, ShadowRegisterC; /*****Initialization********/
    /******Analog inputs block******/
    /* By default, on power-on, reset, the analog modules of the MCU are enabled, we need to disable them in the initialization section to spare current, and use the pins as digital I/O */

    setup_comparator (NC_NC_NC_NC); /* Disable analog comparators, pins are available as digital */
    setup_vref (FALSE); /* Disable the programmable voltage reference, pin is available as digital */
    setup_adc (NO_ANALOGS); /* Disable the ADC module, AN pins are available as digital, the analog modules do not use current for lower power consumption */

    output_c(0);

    /******Main loop********/
    while (1)
    { /* Block processing */
    rx = getc (); /* All 16 bits of the variable that we receive can be "1" */
    ShadowRegisterA = (rx >> 8);
    ShadowRegisterB = (rx >> 8);
    ShadowRegisterC = (rx & 0b0000000011111111);
    /* Block ON */
    output_a (ShadowRegisterA);
    output_b (ShadowRegisterB);
    output_c (ShadowRegisterC);
    delay_ms (1000);
    /* Block OFF */
    output_a (0);
    output_b (0);
    output_c (0);
    delay_ms (1000);
    }
    }
     
     
     

    post edited by ArakelTheDragon - 2018/10/10 18:48:51
    #14
    qhb
    Superb Member
    • Total Posts : 7157
    • Reward points : 0
    • Joined: 2016/06/05 14:55:32
    • Location: One step ahead...
    • Status: online
    Re: ESP8266 with PIC16F690 2018/10/10 18:50:54 (permalink)
    +1 (1)
     rx = getc (); /* All 16 bits of the variable that we receive can be "1" */

    If getc() is a standard library function, not something you have written yourself, then it is almost certainly only returning 8 bits, so the upper 8 bits will ALWAYS be zero.
     
    Why are all your "ShadowRegister#" variables 16-bit when they are only used to hold the value of an 8-bit GPIO port?
     
     
     

    Worst forum problems are now fixed, but the damn firewall is still there.
    #15
    ArakelTheDragon
    New Member
    • Total Posts : 14
    • Reward points : 0
    • Joined: 2016/12/11 07:12:00
    • Location: 0
    • Status: offline
    Re: ESP8266 with PIC16F690 2018/10/10 19:23:27 (permalink)
    0
    qhb
     rx = getc (); /* All 16 bits of the variable that we receive can be "1" */

    If getc() is a standard library function, not something you have written yourself, then it is almost certainly only returning 8 bits, so the upper 8 bits will ALWAYS be zero.
     
    Why are all your "ShadowRegister#" variables 16-bit when they are only used to hold the value of an 8-bit GPIO port?

     
    Thanks for the fast reply!
     
    This is overlooked by me, I should make them 8bits. The function is a standard library function. What puzzles me is that on "MPLAB X" when I debug the program, the ports are set correctly. Is there any difference between the simulator and the real PIC(I know there should not be, however it seems possible, I am using MPLAB X, V5.0).
     
     
     




    #16
    qhb
    Superb Member
    • Total Posts : 7157
    • Reward points : 0
    • Joined: 2016/06/05 14:55:32
    • Location: One step ahead...
    • Status: online
    Re: ESP8266 with PIC16F690 2018/10/10 19:30:09 (permalink)
    0
    I never trust the simulator. Always test on real hardware.
     

    Worst forum problems are now fixed, but the damn firewall is still there.
    #17
    ArakelTheDragon
    New Member
    • Total Posts : 14
    • Reward points : 0
    • Joined: 2016/12/11 07:12:00
    • Location: 0
    • Status: offline
    Re: ESP8266 with PIC16F690 2018/10/10 19:57:52 (permalink)
    0
    It seems the problem really was this function. It send only 8bit I guess, when I sent 2 bytes with 2 functions it works.
    #18
    Jump to:
    © 2018 APG vNext Commercial Version 4.5