Maker Pi Pico with ESP01S Module

It has been a while since my last post, most of which has been spent dealing with other things, as well as waiting for electronics modules to arrive from overseas. A lot of my time has also been spent on getting to grips with the Raspberry Pi Pico, and in particular, the Maker Pi Pico, from Cytron Technologies. This has been an experience with quite a lot of mixed feelings… As Usual, Cytron has done an excellent job with the development board, which, while apparently still in Beta, seems to be rock solid. Most of my frustration came from the “patchy” C/C++ support for the Pi Pico (Yes, I know there are great support, BUT it is not exactly user friendly 🙂 ). That left me with MicroPython, which although I am fluent, are not my goto language…

Lets get back on track though… The Maker Pi Pico has built in support for an ESP01/ESP01S Module. Lets look at the schematic….

Maker Pi Pico Schematic

As we can see, Cytron has provided us with access to Tx (GP17) and Rx(GP16) directly on the Pi Pico. Power (+3.3v) and Ground are connected as well… On this version of the board, no access to IO0,IO2 and the Reset Pin for the ESP01/ESP01S was provided… Maybe this will change in future…?

I have used the standard AT command firmware that comes pre-loaded onto the ESP01/S module. This allows you to send AT commands to the ESP01 Module to control it. It is also possible to setup a transparent WiFi “channel” to communicate between Pico and a remote application , making it possible to control Pico remotely. I have however not prepared and example of that for release yet….

MicroPython Code to communicate with ESP01 from Maker Pi Pico

import uos
from machine import UART, Pin
import utime

"""
ESPRESSIF AT Command Set
https://docs.espressif.com/projects/esp-at/en/latest/AT_Command_Set/
"""

print()
print("Machine: \t" + uos.uname()[4])
print("MicroPython: \t" + uos.uname()[3])

#indicate program started visually
led_onboard = machine.Pin(25, machine.Pin.OUT)
led_onboard.value(0)     # onboard LED OFF/ON for 0.5/1.0 sec
utime.sleep(0.5)
led_onboard.value(1)
utime.sleep(1.0)
led_onboard.value(0)

uart0 = UART(0, rx=Pin(17), tx=Pin(16), baudrate=115200)
# NOTE that we explicitly set the Tx and Rx pins for use with the UART
# If we do not do this, they WILL default to Pin 0 and Pin 1
# Also note that Rx and Tx are swapped, meaning Pico Tx goes to ESP01 Rx 
# and vice versa.
print(uart0)

def sendCMD_waitResp(cmd, uart=uart0, timeout=2000):
    print("CMD: " + cmd)
    uart.write(cmd)
    waitResp(uart, timeout)
    print()
    
def waitResp(uart=uart0, timeout=2000):
    prvMills = utime.ticks_ms()
    resp = b""
    while (utime.ticks_ms()-prvMills)<timeout:
        if uart.any():
            resp = b"".join([resp, uart.read(1)])
    print("resp:")
    try:
        print(resp.decode())
    except UnicodeError:
        print(resp)
    
sendCMD_waitResp('AT\r\n')          #Test AT startup
sendCMD_waitResp('AT+GMR\r\n')      #Check version information
#sendCMD_waitResp('AT+RESTORE\r\n')  #Restore Factory Default Settings
sendCMD_waitResp('AT+CWMODE?\r\n')  #Query the Wi-Fi mode
sendCMD_waitResp('AT+CWMODE=1\r\n') #Set the Wi-Fi mode = Station mode
sendCMD_waitResp('AT+CWMODE?\r\n')  #Query the Wi-Fi mode again
#sendCMD_waitResp('AT+CWLAP\r\n', timeout=10000) #List available APs
sendCMD_waitResp('AT+CWJAP="jean_iot","master123abc"\r\n', timeout=5000) #Connect to AP
utime.sleep(1)
sendCMD_waitResp('AT+CIFSR\r\n')    #Obtain the Local IP Address

You can now extend and adapt this code to suit your purposes…

The ESP01/ESP01S AT Command Datasheet is available for download here

Thank you

8 thoughts on “Maker Pi Pico with ESP01S Module”

  1. Gregory Walters

    Thank you for this post.
    I received my Maker board and ESP-01 yesterday and I must say that I am impressed.

    I was struggling to get connected to my network but with your example code I was able to connect.

    However, once I am connected, nothing else seems to work. I have tried to connect to a local MQTT server as shown in the AT Command Datasheet you point to and am getting an error.
    I have also tried (using the same datasheet information) to connect to the NTP server and get the “network” time, but still receive an error.
    The code is:
    sendCMD_waitResp(‘AT+CIPSNTPCFG=1,-6,”0.pool.ntp.org”,”time.google.com”\r\n’)
    sendCMD_waitResp(‘AT+CIPSNTPTIME?\r\n’)
    and the responses are:
    CMD: AT+CIPSNTPCFG=1,-6,”0.pool.ntp.org”,”time.google.com”
    resp:
    AT+CIPSNTPCFG=1,-6,”0.pool.ntp.org”,”time.google.com”
    ERROR
    CMD: AT+CIPSNTPTIME?
    resp:
    AT+CIPSNTPTIME?
    ERROR

    Can you provide any words of wisdom?
    Thank you in advance,
    Greg

    1. Hi Greg,
      I am also still battling with similar issues. Micro-python is definitely not my favorite language to use.
      The code that I posted, took me quite a few hours to translate from other examples, for other chips…

      From the responces you get back, it seems like the ESP01 is not happy with that ntp server…

      I suggest you do what I did, get a serial to usb device connected directly to that ESP01, keeping in mind that it MUST
      be powered with ONLY 3.3v. Also connect that 3.3v to the EN pin…

      Then connect that straight to the Arduino Serial monitor, and try out those commands. also ensuring that you can actually ping those servers from the ESP01 when connected to wifi…

      then try those in the Micropython Code…

      I also suggest that you place some sort of delay between the commands…
      I found out the hard way, that simply getting an IP address, right after connecting, fails, unless I add about 1 sec delay …

      Seems all is definitely not there yet, and for some reason, USING the ESP01 as a wifi Modem, from Micropython, is not documented …

      Everybody seem to flash it with micropython, which completely defies the object of us trying to use the Pico with the ESP01…

      Hopefully, C/C++ support will get better, and then things will get easier. Feel free to contact me directly on email if you need more help…

      I would love to help, as I am just as frustrated with this issue…

      Regards

      Jean

      1. Gregory Walters

        Thank you for your thoughts.

        I will try the serial direct from PC to ESP-01 to get see if I can get things to work.

        I agree with you that flashing the ESP-01 with MicroPython is the wrong way to go for this project. The idea is giving the Pico a “voice on the network” at least until there is more support for networking on the Pico, like the upcoming Arduino RP2040 board.

        I don’t think that anyone including the Raspberry Pi Foundation realized just how popular the Pico would be when it was introduced. The fact that the MicroPython port for the Pico is being updated everyday just goes to show how much effort is being put into getting it up to speed.

        I will update you if I find anything helpful.

        Greg

        1. Thank you. Yes I agree, It is quite popular. I also believe the Arduino RP2040 will be quite a hit, If not only for the support that the Arduino ecosystem will bring to the party. Good Luck with the project.. I will also post here if I manage to find something else that is useful to everyone else out there 🙂

          1. This morning, I was able to connect the ESP-01 to an Arduino Uno and do direct serial commands via the Serial Monitor.
            I was able to get connected to my network and then using the AT+CIPSTART=4,”TCP”,”api.weatherapi.com/V1″,80
            to get a connection to an outside server, but was unable to create a packet formatted correctly the server.

            I’m afraid that the software inside the ESP-01 is too old to support all of the “advanced” AT commands. I don’t have the ability to flash a newer version of the firmware and it seems there are questions about which version should be used (from what I’ve seen on the Web searches that I did).

            Just between us (and who ever reads this), Cytron support couldn’t get it to work correctly either and they pointed me to your site.

            I agree that if anything needs to be done via network like MQTT, we’ll have to …
            a) wait for the Arduino RP2040 and…
            b) wait for the MicroPython port to the Pico to become more mature.

            This is the unfortunate side of working on the “bleeding” edge of technology. You have to be prepared to bleed a bit yourself :o}

            Thanks for you help and if I get any further, I’ll post it here.

            Greg

          2. Hi Greg,

            Yes, I have also found that the AT Command Set of the ESP01 seems quite old…
            You can try to download an update from the espressive site ( the ESP manufacturer)

            I can however not say if it will be any better, as it seems like they focus more on the bigger chip modules…

            Waiting for the Micropython port to become more mature is definitely an option,
            and the same with the Arduino Port ….

            I agree, bleeding edge stuff is quite painful, as answers are few and far between 🙂
            I will also keep trying and give update here when i get to it …

            What I did see in my own experiments is that, although I can get the ESP01 to connect to WiFI, as well as host a transparent “server” on it, I can not seem to connect to it from outside ( This works well with Arduino however, making int possible to host a webserver on an Arduino UNO, with the ESP01 as a WiFi Modem … )

            The Micropython port is definitely not very mature at this stage … Circuit Python seems attractive option, But as it is still in Beta status, could not really get it to work on the pico at all ….

            Regards

            Jean

  2. I was trying to get the ESP-01 to connect to a “quote of the day” and display the quote in the Thonny serial screen.

    It works fine if I connect it to an RPi4 using a CH340 serial to ttl adapter. I can see that it is connected to the router and I can see the quotes in the Arduino serial screen.

    If I connect the same ESP-01 to the Maker Pi Pico it doesn’t work. I have never seen it connect to the router.

    I have heard that the Maker Pi Pico doesn’t have enough umph to power the transmit function of the ESP-01. So I tried plugging the CH340 into the Pi and connecting the ground and VCC from the CH340 to the ESP-01 and. The Tx & Rex pins to the Maker Pi Pico via jumper leads. It seemed to try and reported that it couldn’t connect to the website. Daft as it seems that is progress 😂😂

    I checked the voltage and current from the CH340 and the Maker Pi Pico.
    The CH340 supplies 3.33 v at a max current of 1.45ma
    The Maker Pi Pico supplies 3.25v at a max current of 1.41 Ma

    The current from the CH340 varied all the time. I think the lowest I saw was 1.25 with 1.45 as the maximum. The Maker Pi Pico seemed vary stable at 1.41ma. It doesn’t seem areas difference but it could be the straw etc.

    Let me know your thoughts please.

    P.S. it may not be nice for you but it makes me feel better that more experienced programmers are struggling 😂😂

    1. Hi, I have recently tried to do just the same thing, and actually got it working, with a workaround though…

      Basically, you have to load the Time Of Day sketch onto the ESP01s using Arduino IDE.
      And then use MicroPyton or CircuitPython to receive the data on the Pico Serial Port…

      This can then be extended where you can set the pico to pass a url to the ESP01, which will then connect and retrieve it,
      and send it back to the Pico.

      Sort of very backwards, I know, Not quite ideal. But more than that, with current support, seems not doable…
      Hopefully, in future, the drivers for the Pico will improve, and more can be done…

      You can also try to use the Pico with Arduino IDE, as they have just release a sort of official core for it, based on MBED OS.
      It is however also still very “bleeding edge” and as such, I have not quite had the time to test it…

      That way, it would in theory be possible to use the native AT command software on the ESP01 and communicate with it via the Pico…

      Let me know how it goes, and good luck

Leave a Reply

Your email address will not be published. Required fields are marked *