Menu

ESP8266

BadBeef67
Attachments
AA.png (342485 bytes)
CP2102.png (186296 bytes)
ESP8266.png (193558 bytes)

The ESP8266 is a Wi-Fi enabled microprocessor that can be had for under $10 from major online retailors (think, really big company that ships in two days)... Ebay has them for as low as $3 each. specificly "ESP8266 Serial Esp-01 WIFI Wireless Transceiver Module Send Receive LWIP AP+STA"

Anyway, LapTrackerTK isn't much good unless you send data to it somehow. Here be the ESP8266 to the rescue.

Step 1:
Purchase the ESP8266 from online retailers.
ESP8266

Step 2:
To program and interact with the ESP8266 you need a USB to Serial adapter. I'm no expert in this department and I wouldn't necessary suggest getting the adapter I did, but it worked anyway after some tinkering... I purchased the CP2102 adapter which came with some header pin cables. Caution: See step 5 before considering this serial adapter! I have no other suggestions on another adapter however...
CP2102

Step 3:
The ESP8266 has a CH_PHD pin that needs input power. Don't ask me why, but it does. I soldered a wire from the power pin to the CH_PHD pin.

Step 4:
Before interacting with your ESP8266 you'll need a few pieces of software. I can't credit these guys enough! Awesome developers and so glad they made the ESP8266 so easy to work with.

Peter Jennings: This guy is amazing. He has a FANTASTIC quickstart write up on how to get the ESP flashed, and loaded with LUA scripting language. LUA is much easier to work with than the firmware shipped on the ESP. Link to the quickstart below. You can pretty much follow the quick start to get everything loaded but I ran into a few snags to start off. You'll need LuaLoader from his website.

Referenced in the QuickStart for the ESP8266 is nodemcu. Again, can't credit these guys enough for all they contribute! You'll need the latest firmware and flasher.exe on nodemcu's github page.

http://benlo.com/esp8266/esp8266QuickStart.html

https://github.com/nodemcu/nodemcu-firmware

https://github.com/nodemcu/nodemcu-flasher

Step 5:
Ok, now that you have the software and the hardware we are ready for the fun part. The ESP8266 is 3.3volts, not 5v! This isn't a problem if you have the correct serial adapter that can provide that power. The CP2102 advertised 3.3vots, and indeed had it on the adapter, but you had to make a solder bridge to chose between 5volts or 3.3volts. If you know this, no problem, but the adapter came with zero instructions. Lucky I read a ton on this device and felt confident that I could make it work.

I unpackaged the adapter and plugged it into my windows 7 64bit PC. The PC immediately recognized the device. GOOD, Check...

I put my Voltmeter across V+ and GND, expecting zero volts as I had not yet made the solder bridge. To my surprise, I received 5volts. After some tinkering, I gave up and pulled the header pin from the V+ and soldered to the 3.3 volt breakout on the board.

Now, armed with 3.3 volts, I attached my ESP8266 to the 3.3volt input power and the GND pin. The ESP lit up and booted, however my PC lost the serial adapter! After a few ties to get the 3.3volt output pin to power the ESP and stay connected to my PC, I gave up... My work around was two AA batteries in series connected to the power and GND pin of the ESP for an external power source. This in the end, worked very well. Go ahead - JUDGE ME - I regret nothing!
AA

Attach the RX, TX , and the GND from the serial adapter to the ESP8266 next. I tried only the RX, TX pins and found that the GND was needed to be attached to the Negative side of the AA batteries to get the ESP to echo my requests. I suspect it needed the same GND for reference voltage or something.

Cross your fingers, Attach the Serial adapter to PC, and launch LuaLoader and set the baud rate. With any luck you can send an AT command and receive an OK... If so, congratulations! The ESP is up and running with its default firmware and now thinks you're its mother.

Step 6:
Ok, now that the hardware is working with the software its time to build our Frankenstein. The default firmware isn't suitable to our needs as a transponder and needs some smarts... <-- I will not be offended of someone proves me wrong...

Close LuaLoader. Remove power from the ESP and connect the GPIO to GND to enter flash mode. This is required to get the new firmware on the ESP. Power back on, launch nodemcu-flasher and choose the correct COM port, baud rate and latest firmware you've already downloaded See Step 4. If all goes well, the firmware will start loading. When done flashing remove GPIO from GND and power off the ESP.

Launch LuaLoader, and power the ESP back on. Select the correct COM port, baud rate and hit enter a few times and then hit the Heap button on the right. The ESP should echo back some info. If all is well you are ready to load the script file that will be used to sense GPIO high or low, and send the ESP's ChipID to the server where LapTrackerTK is listening.

Step 7:
The ESP uses 802.11 Wi-Fi for connectivity. You'll need a wireless router or access-point, broadcasting a network for the ESP to connect to. The nice thing that the ESP does is remember the settings you configure and is persistent through reboots. I happened to have a WRT54G router laying around that I setup with a dedicated SSID called ... you guessed it ... LapTracker.

LuaLoader has buttons on the right to set your SSID, and PSK password. I don't recall all the specs on the ESP for what encryption levels it supports. I think my access-point is configured for WPA2 PSK. Set the SSID, and PW for your setup. You'll also need DHCP on the network your connecting to so that the ESP can be assigned an IP.

Once you have your ESP connected to your SSID, press the GetIP button on the right to pull an IP from DHCP and be displayed on the screen. At this point, if your PC is connected to the same network, you should be able to ping the ESP.

Step 8:
The ESP running LUA firmware tries to run init.lua at startup. There are some features that persist outside of init.lua (like Wi-Fi SSID), but I simply didn't dive deep enough to find any of that, we need to stay focused here to get what we want done!

LuaLoader allows you to upload files from your PC, to the ESP. Knowing that the ESP will fire off init.lua at boot, we can upload a new init.lua and have it do our bidding. Upload two files with the context below. init.lua and sendid.lua

https://sourceforge.net/projects/laptrackertk/files/ESP8266-LUA/

!!Update!!- New files are posted for completed transponder, the files below have been renamed with '3SecDelay'. Be careful which ones you use for your initial setup...

init.lua:

tmr.alarm(0,3000,1,function() dofile('sendid.lua') end) 

sendid.lua:

function check_pin(pin)
    pinValue = gpio.read(pin);
    id = node.chipid()
    if pinValue == 1 then
        conn=net.createConnection(net.TCP, 0);
        conn:on("receive", function(conn, payload) print(payload) end);
        conn:connect(65000,'192.168.1.254');
        conn:send(id);
        conn:send("\r");
    else
    end;
end;
gpio.mode(3, gpio.INPUT);
check_pin(3);

Couple of things to note here... These are test scripts, as I'm currently proveing this concept... <you fools!=""> . This init.lua waits 3 seconds, then runs the sendid.lua file. In reality, we want the script to be running way more often than that, as the RC car will be running at 20-30MPH down the track. The GPIO pin will be triggered by a magnetic switch which pulls GPIO to low when the car runs over an embedded magnetic field across the start finish line. <thats the="" idea="" anyway=""> . So 3 seconds is no good in reality, but I strongly suggest leaving the 3 seconds there until you have a good working ESP, calling out to the LapTrackerTK server sitting on the same network, then dial it down from there.. !Update! See [ESP8266 Part2]</thats></you>

Also, the sendid.lua script is sending to a IP Address of 192.168.1.254. I simply setup my LapTrackerTK server on the same network with a static IP of 192.168.1.254. I suppose you could use DNS or something different if you want ~ I simply don't care how you live your life ~.

The script above is set to read GPIO pin and if its read as High, the ChipID will be sent to the server. Again, in reality, we should be doing so if GPIO is low. !Update! See [ESP8266 Part2]

Step 9:
Now you should have the following: Scripts are loaded on ESP, Your Wi-Fi is working, You have a PC connected to that network running LapTrackerTK with the correct serverside IP configured. With all that in place reboot the ESP. Every 3 seconds the ChipID will be sent to LapTrackerTK and all is right in the world.

If something goes wrong with the scripts on the ESP, you can interrupt the script by hitting the tmr.stop button on the right pane in LuaLoader. This will stop the 3 second delay (or whatever the delay is you have set) and allow you to adjust the files on the ESP.

FUTURE:
In the near future I hope to have my reed switch sensors soldered to a board and ready to be connected to the ESP. For in RC car power I'm not going to get cute and try to step down from the 7.2 volts to 3.3, just going to stick with a couple of AA's for now. There are other options I'm exploring... Once I have the reed sensors connected I'll modify the scripts and update.

THE FUTURE IS NOW!!: Continued here ---> [ESP8266 Part2]

Enjoy!


Related

Wiki: ESP8266 Part2
Wiki: Home
Wiki: LapTrackerTK