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 of RAM.
Arduino Wiring
We'll show wiring to the hardware SPI pins, since the library does not support software SPI at all. You will need female-to-male header wires to get to these pins
Connect:
- AirLift VIN to 5V power (even if you are on a 3V microcontroller, you'll need the current available from the 5V power pin
- AirLift GND to GND
- AirLift SCK to the 6-pin SPI header SPI SCK
-
AirLift MOSI to the 6-pin SPI header SPI MOSI
-
AirLift MISO to the 6-pin SPI header SPI MISO
- AirLift CS to digital 10 (you can change this later)
- AirLift Busy to digital 7 (you can change this later)
- AirLift Reset to digital 5 (you can change this later)
Library Install
We're using a variant of the Arduino WiFiNINA library, which is amazing and written by the Arduino team! The official WiFi101 library won't work because it doesn't support the ability to change the pins.
So! We made a fork that you can install.
Click here to download the library:
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 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. This is where you will store private data like the SSID/password to your network.
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:
Note we use WiFiSSLClient client;
instead of WiFiClient client;
to require an SSL connection!
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 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.
Then load the example JSONdemo
By default it will connect to to the Twitter banner image API, parse the username and followers and display them.
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:
// Configure the pins used for the ESP32 connection #if !defined(SPIWIFI_SS) // if the wifi definition isnt in the board variant // Don't change the names of these #define's! they match the variant ones #define SPIWIFI SPI #define SPIWIFI_SS 10 // Chip select pin #define SPIWIFI_ACK 7 // a.k.a BUSY or READY pin #define ESP32_RESETN 5 // Reset pin #define ESP32_GPIO0 -1 // Not connected #endif
And then before you check the status()
of the module, call the function WiFi.setPins(SPIWIFI_SS, SPIWIFI_ACK, ESP32_RESETN, ESP32_GPIO0, &SPIWIFI);
// 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!
Text editor powered by tinymce.