Adafruit AirLift FeatherWing - ESP32 WiFi Co-Processor Created by Brent Rubell Last updated on 2019-07-29 04:56:09 PM UTC
Overview Give your Feather project a lift with the Adafruit AirLift FeatherWing - a FeatherWing that lets you use the powerful ESP32 as a WiFi co-processor. You probably have your favorite Feather (like the Feather M4 (https://adafru.it/Cmy)) that comes with its own set of 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 FeatherWing with a separate 3.3V regulator, and a tri-state chip for MOSI so you can share the SPI bus with other 'Wing. Comes fully assembled and tested, pre-programmed with ESP32 SPI WiFi coprocessor firmware that you can use in CircuitPython to use this into WiFi co-processsor over SPI + 2 pins (https://adafru.it/Evl).
© Adafruit Industries https://learn.adafruit.
Pinouts Power Pins GND - Common power/logic ground. BAT - Positive voltage from JST on Feather for an optional LiPo battery. USB - Positive voltage to/from the Micro USB jack if connected. EN - 3.3V regulator's enable pin. It's pulled up, so connect to ground to disable the 3.3V regulator 3V - this is the output from the 3.3V regulator. The regulator can supply 500mA peak but half of that is drawn by the ESP32, and it's a fairly power-hungry chip.
Classic SPI Pins: SCK - SPI Clock from your microcontroller, level shifted so can be 3-5V logic MISO - SPI Data from the AirLift to the microcontroller, this is 3.3V logic out, can be read by 3-5V logic. This is tristated when not selected, so you can share the SPI bus with other devices.
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 FeatherWing: Place the FeatherWing over the pins so that the short pins poke through the two rows of breakout pads And Solder! Be sure to solder all pins for reliable electrical contact. (For tips on soldering, be sure to check out ourGuide to Excellent Soldering (https://adafru.it/aTk)). Start by soldering the first row of headers © Adafruit Industries https://learn.adafruit.
Now flip around and solder the other row completely © Adafruit Industries https://learn.adafruit.
© Adafruit Industries https://learn.adafruit.
You're done! © 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 Pinout Since all CircuitPython-running Feathers follow the same pinout, you do not need to change any of the pins listed below.
First make sure you are running the latest version of Adafruit CircuitPython (https://adafru.it/Amd) for your board. Next you'll need to install the necessary libraries to use the hardware--carefully follow the steps to find and install these libraries from Adafruit's CircuitPython library bundle (https://adafru.it/uap). Our CircuitPython starter guide has a great page on how to install the library bundle (https://adafru.it/ABU).
Make sure you see the same output! If you don't, check your wiring. Note that we've changed the pinout in the code example above to reflect the CircuitPython Microcontroller Pinout at the top of this page. Once you've succeeded, continue onto the next page! If you can read the Firmware and MAC address but fails on scanning SSIDs, check your power supply, you may be running out of juice to the ESP32 and it's resetting © 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.ESP_SPIcontrol(spi, esp32_cs, esp32_ready, esp32_reset) To use the AirLift FeatherWing's pins, replace the following lines into your code: esp32_cs = DigitalInOut(board.D13) esp32_ready = DigitalInOut(board.
Verifies an ESP32 is found, checks the firmware and MAC address if esp.status == adafruit_esp32spi.WL_IDLE_STATUS: print("ESP32 found and in idle mode") print("Firmware vers.", esp.firmware_version) print("MAC addr:", [hex(i) for i in esp.MAC_address]) 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 I
We've written a requests-like (https://adafru.it/FpT) library for web interfacing named Adafruit_CircuitPython_Requests (https://adafru.it/FpW). This library allows you to send HTTP/1.1 requests without "crafting" them and provides helpful methods for parsing the response from the server. Here's an example of using Requests to perform GET and POST requests to a server. # adafruit_requests usage with an esp32spi_socket import board import busio from digitalio import DigitalInOut import adafruit_esp32spi.
response.close() data = '31F' print("POSTing data to {0}: {1}".format(JSON_POST_URL, data)) response = requests.post(JSON_POST_URL, data=data) print('-'*40) json_resp = response.json() # Parse out the 'data' key from json_resp dict. print("Data received from server:", json_resp['data']) print('-'*40) response.close() json_data = {"Date" : "July 25, 2019"} print("POSTing data to {0}: {1}".format(JSON_POST_URL, json_data)) response = requests.
esp32_cs = DigitalInOut(board.D9) esp32_ready = DigitalInOut(board.D10) esp32_reset = DigitalInOut(board.D5) HTTP GET with Requests The code makes a HTTP GET request to Adafruit's WiFi testing website - http://wifitest.adafruit.com/testwifi/index.html (https://adafru.it/FpZ). 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.
data = '31F' print("POSTing data to {0}: {1}".format(JSON_POST_URL, data)) response = requests.post(JSON_POST_URL, data=data) print('-'*40) json_resp = response.json() # Parse out the 'data' key from json_resp dict. print("Data received from server:", json_resp['data']) print('-'*40) 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}".
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) Next, set up an Adafruit IO feed named test If you do not know how to set up a feed, follow this page and come back when you've set up a feed named test .
We can then have a simple loop for posting data to Adafruit IO without having to deal with connecting or initializing the hardware! Take a look at your test feed on Adafruit.io and you'll see the value increase each time the CircuitPython board posts data to it! © 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.
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 (https://adafru.it/EVu) At the top you'll see a section where the GPIO pins are defined © Adafruit Industries https://learn.adafruit.
(https://adafru.it/EVv) If you don't see this, you may have the wrong WiFiNINA library installed. Uninstall it and re-install the Adafruit one as above. Compile and upload to your board wired up to the AirLift (https://adafru.it/EVw) 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.
(https://adafru.it/EVx) Open up the secondary tab, arduino_secrets.h. This is where you will store private data like the SSID/password to your network. (https://adafru.it/EVy) 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 © Adafruit Industries https://learn.adafruit.
(https://adafru.it/EVz) 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: (https://adafru.it/EVA) © Adafruit Industries https://learn.adafruit.
Note we use WiFiSSLClient client; instead of WiFiClient client; to require an SSL connection! (https://adafru.it/EVB) 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).
Then load the example JSONdemo (https://adafru.it/EVC) By default it will connect to to the Twitter banner image API, parse the username and followers and display them. (https://adafru.it/EVD) Adapting Other Examples Once you've got it connecting to the Internet you can check out the other examples. The only change you'll want to make is at the top of the sketches, add: © Adafruit Industries https://learn.adafruit.
// Configure the pins used for the ESP32 connection #if defined(ADAFRUIT_FEATHER_M4_EXPRESS) || \ defined(ADAFRUIT_FEATHER_M0_EXPRESS) || \ defined(ARDUINO_AVR_FEATHER32U4) || \ defined(ARDUINO_NRF52840_FEATHER) #define SPIWIFI SPI // The SPI port #define SPIWIFI_SS 13 // Chip select pin #define ESP32_RESETN 12 // Reset pin #define SPIWIFI_ACK 11 // a.k.
Downloads Files ESP32 WROOM32 Datasheet (https://adafru.it/EVE) EagleCAD files on GitHub (https://adafru.it/EVF) Fritzing object in Adafruit Fritzing Library (https://adafru.it/EVG) 3D Models on GitHub (https://adafru.it/FcS) Schematic Fab Print © Adafruit Industries https://learn.adafruit.
© Adafruit Industries https://learn.adafruit.
© Adafruit Industries Last Updated: 2019-07-29 04:56:09 PM UTC Page 39 of 39