Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

PIC to ESP12E wifi IoT module

Status
Not open for further replies.

Mosaic

Well-Known Member
Hi
Has anyone got any advice on using a PIC front end to gather data/multiple ADC samples and get this ESP 8266 -12E to format a web page for browsing?
How is the ESP8266 programmed or is it just AT commands to do it and these can be sent via PIC RX/TX?
How about I2c....or possible bitbang?

thx
Ancel
 
Good luck with that most of the stuff you find is so dated it don't work with your esp LOL.
The ESP 8266 -12E comes with nodemcu LUA on it and will have a web sever running on it the problem is most miss it because they think the dang thing has to use AT commands and then flash it wrong. Because they don't know how to find the right firmware or they load it to the wrong place.
The best way to start is to use this tool and find out for sure what you have. https://benlo.com/esp8266/index.html#LuaLoader
Don't believe me try the the loader it's by far the best way to get to know the hardware and has tons of help files to links that get you going in the right way.
I have made about five of these work stand a long to turn on lights over the wifi with my phone
I have a sch for them I made thats great
esp.jpg

I can't remember what computer I made that on I'm looking for the SCH I made in eagle
 
I agree with Burt. NodeMCU is by far the simplest and best way to start. I have a little weather station im working on and while im no where near complete (waiting on PCBs) the code seems pretty simple.
 
It's not that hard
just change the XXXX to your wifi Name and password save as init.lua and load with the lualoader It has ADC and can do PWM too the thing about ADC is the max voltage is 1.8 volts so be sure to use a divider to scale to 1.8 volts on the ADC input pin
wifi.sta.config("xxxxxxxxxx","xxxxxxxxx")
Code:
wifi.setmode(wifi.STATION)
wifi.sta.config("xxxxxxxxxx","xxxxxxxxx")
print(wifi.sta.getip())
led1 = 7
led2 = 4
gpio.mode(led1, gpio.OUTPUT)
gpio.mode(led2, gpio.OUTPUT)
srv=net.createServer(net.TCP)
srv:listen(80,function(conn)
    conn:on("receive", function(client,request)
        local buf = "";
        local _, _, method, path, vars = string.find(request, "([A-Z]+) (.+)?(.+) HTTP");
        if(method == nil)then
            _, _, method, path = string.find(request, "([A-Z]+) (.+) HTTP");
        end
        local _GET = {}
        if (vars ~= nil)then
            for k, v in string.gmatch(vars, "(%w+)=(%w+)&*") do
                _GET[k] = v
            end
        end
        buf = buf.."<h1> ESP8266 Web Server</h1>";
        buf = buf.."<p>GPIO13 <a href=\"?pin=ON1\"><button>ON</button></a>&nbsp;<a href=\"?pin=OFF1\"><button>OFF</button></a></p>";
        buf = buf.."<p>GPIO2 <a href=\"?pin=ON2\"><button>ON</button></a>&nbsp;<a href=\"?pin=OFF2\"><button>OFF</button></a></p>";
        local _on,_off = "",""
        if(_GET.pin == "ON1")then
              gpio.write(led1, gpio.HIGH);
        elseif(_GET.pin == "OFF1")then
              gpio.write(led1, gpio.LOW);
        elseif(_GET.pin == "ON2")then
              gpio.write(led2, gpio.HIGH);
        elseif(_GET.pin == "OFF2")then
              gpio.write(led2, gpio.LOW);
        end
        client:send(buf);
        client:close();
        collectgarbage();
    end)
end)
[code/]
 
Last edited:
Hi
Has anyone got any advice on using a PIC front end to gather data/multiple ADC samples and get this ESP 8266 -12E to format a web page for browsing?
How is the ESP8266 programmed or is it just AT commands to do it and these can be sent via PIC RX/TX?
How about I2c....or possible bitbang?

thx
Ancel

The ESP8266 is a full microcontroller. It has its own ADC, you will just need a multiplexer that the ESP8266 can control.

the easiest way to write code is to use the Arduino IDE from Arduino.cc
Then, under preferences, add the following line to "additional boards" and the ESP8266 libraries and board capabilities will be added to your IDE

https://arduino.esp8266.com/stable/package_esp8266com_index.json

Then go to this website to see the library of commands that are available.

**broken link removed**



And be sure to set the correct COM port before downloading. and Select the board (Generic ESP8266, or if you are using NodeMCU boards with USB connection to the ESP8266, there are specific sub-board options as well.

Here is a first sketch for you, no libraries needed...
Just connect the anode of an LED to GPIO05 and cathode to a 220 to 1k resistor to ground.
Code:
void setup() {
  pinMode(5, OUTPUT);
}
void loop() {
  digitalWrite(5, HIGH);
  delay(100);
  digitalWrite(5, LOW);
  delay(100);
}
 
The arduino add-on for the esp is not the best way to go at all. Lua lets you do the same stuff just as easy but with a major plus that little program you posted reflash the whole frimware each time you load it and wears the ram out. Lua only writes to longer lasting memory.
Oh and I forgot what happens when you have a failed flash you esp doesn't work again and then your lost as to how to fix it without a ton of reading.
 
Not difficult at all. Just hold the flash, then push the reset button and select Upload again. If you feel more comfortable with Lua, that is fine. Note that I tried AT commands, Lua and the arduino IDE. I stick with my comment, Arduino is the EASIEST way to get something of significant complexity up and running.

If you want to debate BEST, I'll let you run with that word on your own.
 
Last edited:
I'm just saying the facts the arduino add-on is easy but its not a simple press a button and fix a failed flash some can't be fixed easy at all. And it happens and I wasn't impressed with it at all I'm not a fan of lua but it is easy to start with and use. After that move on to something better. I've tried about everything out there. Plus helped a lot of people fix there esp do to not understanding how the chip is programmed. The arduino way flashes the whole frimware. Lua doesn't your chip will last a lot longer and the code is not as big in lua you just don't have librarys but ever arduino library I wanted to use didn't work at all so in the end I had to make my own code anyways so no savings in time for me just got to learn something new.
 
I'm just starting out with the ESPs. I haven't had any bad flashes yet, I am not sure what is causing my luck but it is what it is. Also, I think I can write my base program on arduino and still move files in/out with Lua. I just have to be careful with file names or use a display.

So far so good with Arduino. I think capabilities of the chip are way more than what I planned to use it for so I will not be pushing any limits.

I bought a bag full so I have some projects in my near future.
 
Most flashing problems come from not setting it to flash right and the fact that there's been tons of hardware changes from the esp - 1 to the 12
 
The most i was able to do is blink an led. No documentation on json parsing or anything like that. Lua i can do it all. I will be posting code today. When i get back home ill post it.
 
Funny I kind of said that I bet I've walk 10 people threw how to fix a bricked esp that they messed up with arduino and then you have people thinking that all esp can do at commands they didn't read where the AT CODE belonged to MIT and had to be removed till they came up with a replacement the esp 12 come with four or more ram chips that each load differently so you have some lucky ones and some unlucky esp campers lol.
 
Remember this isnt complete but fun. Pulls weather data from site, does not use JSON parser but can read JSON variables :)
 

Attachments

  • WeatherESP_Atom.zip
    1.4 KB · Views: 227
Looks good Atom I havn't had much time to mess with these in a bit but hopefully get back at it.
 
Remember this isnt complete but fun. Pulls weather data from site, does not use JSON parser but can read JSON variables :)
How abt a tut Atom? I have some 12's coming in to play with.

I do want to hook it to a PIC after config/prg via PC IDE though.....RX/TX comms.
I need it to take PIC data (read from an i2c eprom) and put it up as a downloadable file or something. Even streamingit is ok. Not a terrible lot, 64K max.

i'd also like it to be able to feed RTC data to the PIC.
thx
Ancel
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top