Introduction: Connect an ESP8266 to Your RaspberryPi
ESP8266 boards are pretty neat, but if you just bought one (And why wouldn't you for only $5?) and have realized that you don't have any obvious means (3.3V TTL USB serial device) to communicate with it, you can talk to it directly with a Raspberry Pi. Both use 3.3V signaling, so no level converting is required.
You will need:
Raspberry Pi desktop setup (just about any Pi should do, but with power, keyboard, screen, etc. network access is a plus)
ESP8266-01 (or equivalent)
Some jumper wire and nipper/strippers
Solderless Breadboard (or You can solder this instead)
2x Pull-up/down resistors
(optional) push-button switch
The process is roughly two steps,
1) Wire them together
2) Configure Raspbian
3) Start talking to your ESP8266
Step 1: Wire Them Together
With the power off, connect the 3.3V and ground pins to one another. Similarly connect the RX to TX and vice versa. You will also want some pull down resistors and optionally a reset button. I've included a Fritzing diagram (above).
Step 2: Configure Raspbian Linux
Boot up the Pi and with super user privs make some edits (e.g. “sudo nano”).
Disable the Kernel serial console
Edit /boot/cmdline.txt to remove the underlined text:
dwc_otg.lpm_enable=0 rpitestmode=1 console=ttyAMA0,115200 kgdboc=ttyAMA0,115200 console=tty1 root=/dev/mmcblk0p2 rootfstype=ext4 rootwait
Disable serial logins
Edit /etc/inittab and remove the (usually) last line:
2:23:respawn:/sbin/getty -L ttyAMA0 115200 vt100
Reboot
sudo shutdown -r now
Step 3: Start Talking to Your ESP8266
Connect to the serial port
You should now be able to interact with the ESP8266 via a terminal emulator program. I suggest GNU Screen for this (“sudo apt-get install screen”). Screen passes through your keystrokes unless you start with “CTRL-A” in which case you can then make screen do things. For example “CTRL-A” then “k” will close (kill) the session. screen /dev/ttyAMA0 115200 (the speed may vary depending on your ESP8266 board) (you may need to sudo this too, depending permissions) You can now send your ESP8266 “AT” commands. You’ll still need “return” and “CTRL-J” after each one, though.
Notes/Caveats
The Pi does not seem to recover well if you try to use the reset button. Best to shutdown the pi, then remove power, then power/boot back up rather than try the reset button.
Don’t mess with the wires while power is on. Shutdown the Pi ("sudo shutdown -h now") and wait for any blinking LEDs to stop and disconnect power before trying to connect/disconnect wires.
This linking won’t by itself give your Pi internet access via the ESP8266. But it does at least let you try out, configure, maybe even reprogram it.
Screen won’t relinquish the serial port if you just close a window or disconnect. This is on purpose, but can take some getting used to. If you think you disconnected from Screen but it is still running try “screen -ddR” to reconnect, and then you can to the kill as above. [Or reboot.]
The Pi and the ESP8266 can use a lot of power. This setup relies on the Pi’s 3.3V supply alone, which may not be up to the task if both devices are going to be going full blast. A more reliable/permanent solution would be to rig up separate power for the ESP8266.
11 Comments
Question 3 years ago on Introduction
How to connect this esp8266 which has a usb port instead
5 years ago
This gets you connected to it, but then what? i.e. can you/how-can-you used the wifi on it?
6 years ago
couln't find the line to edit in "/boot/cmdline.txt" and "/etc/inittab".
pls help if anyone else had same issues.
thanks
Reply 6 years ago
i am using a rpi3 fyi
7 years ago
After Disable the Kernel serial console and Disable serial logins i reboot and installed screen. And then i don't understand what i am supposed to do. I need to flash ESP8266 and then upload the code to it. Is this not possible with this tutorial ?
Reply 6 years ago
The rx/tx is how you communicate with it.
rx pi -> tx esp ; tx pi -> rx esp
Sometimes they need reversal, sometimes not. Like anything from China, sometimes things get reversed.
I don't remember needing to flash new firmware on the ESP when I used an Arduino, just had to flash my Arduino.
Assuming similar thing with pi.
Reply 6 years ago
http://www.espressif.com/sites/default/files/4a-esp8266_at_instruction_set_en_v1.5.4_0.pdf
AT Commands are what the Esp is flashed with.
Reply 6 years ago
Arduino branch, but useful with info and hookup.
https://github.com/esp8266/Arduino/blob/master/doc...
7 years ago
Just out of curiosity how do yo determine what resistors to use? I see that you have red, red, red, gold. Are these the type of resistors needed? Thanks for putting this together.
Reply 7 years ago
Resistors are selected as per the current (and sometimes power) requirements. Here he uses them as pull-up/pull-downs which is just to "hold" the pins at a particular voltage, so high value of resistance is preferred. Most common is 10k, but you can make it work with 1k and higher. Red, Red, Red, Gold is 2.2k, so yes they will work too! Here is a calculator you can use: http://www.digikey.com/en/resources/conversion-cal...
More on pull up resistors: https://learn.sparkfun.com/tutorials/pull-up-resistors
8 years ago on Introduction
Nice tutorial. Thank for sharing.