Adafruit AirLift - ESP32 WiFi Co-Processor Breakout Created by Kattni Rembor Last updated on 2019-07-29 04:59:42 PM UTC
Overview Give your plain ol' microcontroller project a lift with the Adafruit AirLift - a breakout board that lets you use the powerful ESP32 as a WiFi co-processor. You probably have your favorite microcontroller (like the ATmega328 or ATSAMD51), awesome peripherals and lots of libraries. But it doesn't have WiFi built in! So lets give that chip a best friend, the ESP32.
We placed an ESP32 module on a PCB with level shifting circuitry, a 3.3V regulator, and a tri-state chip for MOSI so you can share the SPI bus with other devices. Comes fully assembled and tested, pre-programmed with ESP32 SPI WiFi coprocessor firmware that you can use in CircuitPython to use this into a WiFi co-processsor over SPI + 2 pins (https://adafru.it/Evl). We also toss in some header so you can solder it in and plug into a solderless breadboard.
Pinouts Power Pins Starting from the left are the power in/out pins. The ESP32 chip can use a lot of power when transmitting. Make sure your power source can handle up to 250mA spikes of current during transmits! © Adafruit Industries https://learn.adafruit.
VIN - This is the power input. Can be 3.3-5VDC, USE A POWER SOURCE THAT CAN HAPPILY SUPPLY 250mA, we will regulate this down to 3.3V safely! This is probably a VBAT or USB pin not a 3.3V regulated output. 3vo - The output from the onboard 3.3V regulator, you can use up to ~50mA for other devices if you want to power them from the same chip GND - Power and logic ground. SPI & Control Pins To keep transfers speedy, we use SPI not UART Serial. Serial is too slow and hard to synchronize.
Assembly Prepare the header strip: Cut the strip to length if necessary. It will be easier to solder if you insert it into a breadboard - long pins down © Adafruit Industries https://learn.adafruit.
Add the breakout board: Place the breakout board over the pins so that the short pins poke through the breakout pads And Solder! Be sure to solder all 12 pins for reliable electrical contact. (For tips on soldering, be sure to check out our Guide to © Adafruit Industries https://learn.adafruit.
Excellent Soldering (https://adafru.it/aTk)). © Adafruit Industries https://learn.adafruit.
You're done! Check your solder joints visually and continue onto the next steps © Adafruit Industries https://learn.adafruit.
CircuitPython It's easy to use the Adafruit AirLift breakout with CircuitPython and the Adafruit CircuitPython ESP32SPI (https://adafru.it/DWV) module. This module allows you to easily add WiFi to your project. The ESP32SPI library requires an M4 or better microcontroller! The M0 will not work. CircuitPython Microcontroller Wiring First, wire up your AirLift as follows.
Copy the following code to your code.py file on your microcontroller: import board import busio from digitalio import DigitalInOut from adafruit_esp32spi import adafruit_esp32spi import adafruit_esp32spi.adafruit_esp32spi_requests as requests print("ESP32 SPI hardware test") esp32_cs = DigitalInOut(board.D10) esp32_ready = DigitalInOut(board.D9) esp32_reset = DigitalInOut(board.D7) spi = busio.SPI(board.SCK, board.MOSI, board.MISO) esp = adafruit_esp32spi.
© Adafruit Industries https://learn.adafruit.
Internet Connect! Once you have CircuitPython setup and libraries installed we can get your board connected to the Internet. To get connected, you will need to start by creating a secrets file . What's a secrets file? We expect people to share tons of projects as they build CircuitPython WiFi widgets. What we want to avoid is people accidentally sharing their passwords or secret tokens and API keys. So, we designed all our examples to use a secrets.
adafruit_bus_device adafruit_esp32_spi adafruit_requests neopixel Before continuing make sure your board's lib folder or root filesystem has the above files copied over. Next connect to the board's serial REPL (https://adafru.it/Awz) so you are at the CircuitPython >>> prompt. Into your lib folder. Once that's done, load up the following example using Mu or your favorite editor: import board import busio from digitalio import DigitalInOut import adafruit_esp32spi.
print("Ping google.com: %d ms" % esp.ping("google.com")) #esp._debug = True print("Fetching text from", TEXT_URL) r = requests.get(TEXT_URL) print('-'*40) print(r.text) print('-'*40) r.close() print() print("Fetching json from", JSON_URL) r = requests.get(JSON_URL) print('-'*40) print(r.json()) print('-'*40) r.close() print("Done!") And save it to your board, with the name code.py .
In order, the example code... Initializes the ESP32 over SPI using the SPI port and 3 control pins: esp32_cs = DigitalInOut(board.ESP_CS) esp32_ready = DigitalInOut(board.ESP_BUSY) esp32_reset = DigitalInOut(board.ESP_RESET) spi = busio.SPI(board.SCK, board.MOSI, board.MISO) esp = adafruit_esp32spi.
Performs a scan of all access points it can see and prints out the name and signal strength: for ap in esp.scan_networks(): print("\t%s\t\tRSSI: %d" % (str(ap['ssid'], 'utf-8'), ap['rssi'])) Connects to the AP we've defined here, then prints out the local IP address, attempts to do a domain name lookup and ping google.com to check network connectivity (note sometimes the ping fails or takes a while, this isn't a big deal) print("Connecting to AP...") esp.
import busio from digitalio import DigitalInOut import adafruit_esp32spi.adafruit_esp32spi_socket as socket from adafruit_esp32spi import adafruit_esp32spi import adafruit_requests as requests # If you are using a board with pre-defined ESP32 Pins: esp32_cs = DigitalInOut(board.ESP_CS) esp32_ready = DigitalInOut(board.ESP_BUSY) esp32_reset = DigitalInOut(board.ESP_RESET) # # # # If you have an externally connected ESP32: esp32_cs = DigitalInOut(board.D9) esp32_ready = DigitalInOut(board.
print('-'*40) response.close() json_data = {"Date" : "July 25, 2019"} print("POSTing data to {0}: {1}".format(JSON_POST_URL, json_data)) response = requests.post(JSON_POST_URL, json=json_data) print('-'*40) json_resp = response.json() # Parse out the 'json' key from json_resp dict. print("JSON Data received from server:", json_resp['json']) print('-'*40) response.close() The code first sets up the ESP32SPI interface. Then, it initializes a request object using an ESP32 socket and the esp object.
To do this, we'll pass the URL into requests.get() . We're also going to save the response from the server into a variable named response . While we requested data from the server, we'd what the server responded with. Since we already saved the server's response , we can read it back. Luckily for us, requests automatically decodes the server's response into human-readable text, you can read it back by calling response.text . Lastly, we'll perform a bit of cleanup by calling response.close() .
You can also post json-formatted data to a server by passing json data into the requests.post method. json_data = {"Date" : "July 25, 2019"} print("POSTing data to {0}: {1}".format(JSON_POST_URL, json_data)) response = requests.post(JSON_POST_URL, json=json_data) print('-'*40) json_resp = response.json() # Parse out the 'json' key from json_resp dict. print("JSON Data received from server:", json_resp['json']) print('-'*40) response.
import board import busio from digitalio import DigitalInOut import adafruit_esp32spi.adafruit_esp32spi_socket as socket from adafruit_esp32spi import adafruit_esp32spi import adafruit_requests as requests # If you are using a board with pre-defined ESP32 Pins: esp32_cs = DigitalInOut(board.ESP_CS) esp32_ready = DigitalInOut(board.ESP_BUSY) esp32_reset = DigitalInOut(board.ESP_RESET) # # # # If you have an externally connected ESP32: esp32_cs = DigitalInOut(board.D9) esp32_ready = DigitalInOut(board.
That simpletest example works but its a little finicky - you need to constantly check WiFi status and have many loops to manage connections and disconnections. For more advanced uses, we recommend using the WiFiManager object. It will wrap the connection/status/requests loop for you - reconnecting if WiFi drops, resetting the ESP32 if it gets into a bad state, etc.
"https://io.adafruit.com/api/v2/"+secrets['aio_username']+"/feeds/"+feed+"/data", json=payload, headers={"X-AIO-KEY":secrets['aio_key']}) print(response.json()) response.close() counter = counter + 1 print("OK") except (ValueError, RuntimeError) as e: print("Failed to get data, retrying\n", e) wifi.reset() continue response = None time.sleep(15) You'll note here we use a secrets.py file to manage our SSID info. The wifimanager is given the ESP32 object, secrets and a neopixel for status indication.
© Adafruit Industries https://learn.adafruit.
Arduino You can use the AirLift with Arduino. Unlike CircuitPython, it work work with just about any Arduino chip, even a classic Arduino UNO. However, if you want to use libraries like ArduinoJSON or add sensors and SD card, you'll really want an ATSAMD21 (Cortex M0) or ATSAMD51 (Cortex M4), both of which have plenty or RAM Arduino Wiring We'll show wiring to the hardware SPI pins, since the library does not support software SPI at all.
https://adafru.it/Evm Within the Arduino IDE, select Install library from ZIP... And select the zip you just downloaded. First Test OK now you have it wired and library installed, time to test it out! Lets start by scanning the local networks. Load up the ScanNetworks example At the top you'll see a section where the GPIO pins are defined If you don't see this, you may have the wrong WiFiNINA library installed. Uninstall it and re-install the Adafruit one as © Adafruit Industries https://learn.
above. Compile and upload to your board wired up to the AirLift If you don't even get the MAC address printed out, check your wiring. If you get the MAC address but cannot scan any networks, check your power supply. You need a solid 3-5VDC into Vin in order for the ESP32 not to brown out. WiFi Connection Test Now that you have your wiring checked, time to connect to the Internet! Open up the WiFiWebClient example Open up the secondary tab, arduino_secrets.h.
You must change these string values before updating to your board! After you've set it correctly, upload and check the serial monitor. You should see the following. If not, go back, check wiring, power and your SSID/password Secure Connection Example Many servers today do not allow non-SSL connectivity. Lucky for you the ESP32 has a great TLS/SSL stack so you can have that all taken care of for you. Here's an example of a secure WiFi connection: © Adafruit Industries https://learn.adafruit.
Note we use WiFiSSLClient client; instead of WiFiClient client; to require an SSL connection! © Adafruit Industries https://learn.adafruit.
JSON Parsing Demo This example is a little more advanced - many sites will have API's that give you JSON data. We'll use ArduinoJSON (https://adafru.it/Evn) to convert that to a format we can use and then display that data on the serial port (which can then be re-directed to a display of some sort) First up, use the Library manager to install ArduinoJSON (https://adafru.it/Evo).
// check for the WiFi module: WiFi.setPins(SPIWIFI_SS, SPIWIFI_ACK, ESP32_RESETN, ESP32_GPIO0, &SPIWIFI); while (WiFi.status() == WL_NO_MODULE) { Serial.println("Communication with WiFi module failed!"); // don't continue delay(1000); } Of course you can adjust the pins and SPI port if you like! © Adafruit Industries https://learn.adafruit.
Downloads Files EagleCAD PCB Files on GitHub (https://adafru.it/Evh) Fritzing Object in the Adafruit Fritzing Library (https://adafru.it/Evi) Schematic Fab Print © Adafruit Industries https://learn.adafruit.
© Adafruit Industries https://learn.adafruit.
© Adafruit Industries Last Updated: 2019-07-29 04:59:42 PM UTC Page 36 of 36