Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 6 of 6

Thread: Teensy 4.1 WiFi (Howto)

  1. #1
    Member
    Join Date
    Apr 2020
    Location
    Germany, NRW
    Posts
    86

    Teensy 4.1 WiFi (Howto)

    Hi all,

    today my new parts arrived including an Adafruit Airlift Feather so i decided to connect the Teensy 4.1 to my WLAN.

    (I think this would also work with Teensy 4.0)

    Here is a bit of an advanced howto, proceed at your own risk, soldering skills are required!

    Hardware needed:

    AirLift FeatherWing ESP32

    https://www.adafruit.com/product/4264

    Teensy Feather Adapter

    https://www.adafruit.com/product/3200

    Stacking Headers for the Teensy/Airlift, or what i used:

    FeatherWing Doubler - Prototyping Add-on For All Feather Boards

    https://www.adafruit.com/product/2890

    (Also available from other suppliers)

    The prepared parts will look like this:







    Note: On the AirLift you might need to solder the pads near ESPGPIO0.
    I did not get it working without soldering the pads but it might be worthwhile to try without first.

    You need this Library:

    https://github.com/adafruit/WiFiNINA

    I used version 1.3.0 of this library.

    If you use Teensyduino i think following the instructions on

    https://learn.adafruit.com/adafruit-...or-featherwing

    should be helpful. I used PlatformIO, where you have to add this line to the file platformio.ini in your project dir:

    Code:
    lib_deps = https://github.com/adafruit/WiFiNINA/#1.3.0
    You need to apply this patch to the Adafruit WiFiNINA library to make it work with Teensy4:

    Code:
    diff --git a/src/utility/spi_drv.cpp b/src/utility/spi_drv.cpp
    index ff89d41..3884f30 100644
    --- a/src/utility/spi_drv.cpp
    +++ b/src/utility/spi_drv.cpp
    @@ -81,6 +81,14 @@ void SpiDrv::begin()
           SLAVERESET = (uint8_t)SPIWIFI_RESET;
     #endif
    
    +#ifdef ARDUINO_TEENSY41
    +#define SLAVESELECT  5
    +#define SLAVERESET   6
    +#define SLAVEREADY   9
    +#define NINA_GPIO0  10
    +#endif
    +
    +#ifndef ARDUINO_TEENSY41
     #ifdef ARDUINO_SAMD_MKRVIDOR4000
           inverted_reset = false;
     #else
    @@ -88,6 +96,7 @@ void SpiDrv::begin()
             inverted_reset = true;
             SLAVERESET = ~SLAVERESET;
           }
    +#endif
     #endif
    Then you should be able to compile and upload this sketch:

    Code:
    #define SPIWIFI        SPI  // The SPI port
    
    #include <Arduino.h>
    #include <SPI.h>
    #include <WiFiNINA.h>
    
    const char *ssid = "YOUR_SSID_HERE";
    const char *pass= "YOUR_PASSWORD";
    int status = WL_IDLE_STATUS;     // the Wifi radio's status
    
    void printMacAddress(byte mac[]) {
      for (int i = 5; i >= 0; i--) {
        if (mac[i] < 16) {
          Serial.print("0");
        }
        Serial.print(mac[i], HEX);
        if (i > 0) {
          Serial.print(":");
        }
      }
      Serial.println();
    }
    
    void printWifiData() {
      // print your board's IP address:
      IPAddress ip = WiFi.localIP();
      Serial.print("IP Address: ");
      Serial.println(ip);
      Serial.println(ip);
    
      // print your MAC address:
      byte mac[6];
      WiFi.macAddress(mac);
      Serial.print("MAC address: ");
      printMacAddress(mac);
    }
    
    
    void printCurrentNet() {
      // print the SSID of the network you're attached to:
      Serial.print("SSID: ");
      Serial.println(WiFi.SSID());
    
      // print the MAC address of the router you're attached to:
      byte bssid[6];
      WiFi.BSSID(bssid);
      Serial.print("BSSID: ");
      printMacAddress(bssid);
    
      // print the received signal strength:
      long rssi = WiFi.RSSI();
      Serial.print("signal strength (RSSI):");
      Serial.println(rssi);
    
      // print the encryption type:
      byte encryption = WiFi.encryptionType();
      Serial.print("Encryption Type:");
      Serial.println(encryption, HEX);
      Serial.println();
    }
    
    void setup() {
      //Initialize serial and wait for port to open:
      Serial.begin(115200);
      while (!Serial) {
        ; // wait for serial port to connect. Needed for native USB port only
      }
      SPI.begin();
      // check for the WiFi module:
      if (WiFi.status() == WL_NO_MODULE) {
        Serial.println("Communication with WiFi module failed!");
        // don't continue
        while (true);
      }
    
      String fv = WiFi.firmwareVersion();
      if (fv < WIFI_FIRMWARE_LATEST_VERSION) {
        Serial.println("Please upgrade the firmware!");
      }
    
      // attempt to connect to Wifi network:
      while (status != WL_CONNECTED) {
        Serial.print("Attempting to connect to WPA SSID: ");
        Serial.println(ssid);
        // Connect to WPA/WPA2 network:
        status = WiFi.begin(ssid, pass);
    
        // wait 5 seconds for connection:
        delay(5000);
      }
    
      // you're connected now, so print out the data:
      Serial.print("You're connected to the network.");
      printCurrentNet();
      printWifiData();
    }
    
    void loop() {
      // check the network connection once every 10 seconds:
      delay(10000);
      printCurrentNet();
    }
    If it works it should look like this in the serial monitor:

    Code:
    Attempting to connect to WPA SSID: bs_XXXXX
    You're connected to the network.SSID: bs_XXXXX
    BSSID: D0:03:4B:XX:XX:XX
    signal strength (RSSI):-62
    Encryption Type:4
    
    IP Address: 192.168.178.40
    192.168.178.40
    MAC address: A4:CF:12:XX:XX:XX
    SSID: bs_XXXXX
    BSSID: D0:03:4B:XX:XX:XX
    signal strength (RSSI):-62
    Encryption Type:4
    In the terminal window:

    Code:
    ms@braeburn:WiFiNINA #5009 22:28 :) ping 192.168.178.40
    PING 192.168.178.40 (192.168.178.40): 56 data bytes
    64 bytes from 192.168.178.40: icmp_seq=0 ttl=255 time=188.952 ms
    64 bytes from 192.168.178.40: icmp_seq=1 ttl=255 time=121.472 ms
    64 bytes from 192.168.178.40: icmp_seq=2 ttl=255 time=38.590 ms
    64 bytes from 192.168.178.40: icmp_seq=3 ttl=255 time=250.641 ms
    64 bytes from 192.168.178.40: icmp_seq=4 ttl=255 time=167.443 ms
    Caveat: Sometime it does not find the ESP32, i think it could benefit from some SPI pullup resistors, but i am not sure
    which values to use and where exactly. Did not look at Paul's SPI recommendation page today.
    Last edited by mstiller; 06-09-2020 at 09:43 PM. Reason: Typo

  2. #2
    Member
    Join Date
    Apr 2020
    Location
    Germany, NRW
    Posts
    86
    PS:

    I think that issue with the SPI pullups might actually be true. I remembered that the FeatherWing Logger has pull-ups, so i stacked another module. It looks gross now but worked at the first try.

  3. #3
    Member
    Join Date
    Apr 2020
    Location
    Germany, NRW
    Posts
    86
    I forked the lib fresh from master which looks better than the 1.3.0 version and applied a new patch to make it work out of the box.

    https://github.com/gounselor/WiFiNINA

    So please replace the github.com url in the first posting an report if it works for you.

  4. #4
    Member
    Join Date
    Apr 2020
    Location
    Germany, NRW
    Posts
    86
    More investigation reveals, that you can in fact use the Adafruit library https://github.com/adafruit/WiFiNINA
    but you should use master and add this on top of the sketch:

    Code:
    #if defined(TEENSYDUINO)
      #define SPIWIFI       SPI  // The SPI port
      #define SPIWIFI_SS     5   // Chip select pin
      #define ESP32_RESETN   6   // Reset pin
      #define SPIWIFI_ACK    9   // a.k.a BUSY or READY pin
      #define ESP32_GPIO0   -1
    #endif
    And this in setup():

    Code:
    WiFi.setPins(SPIWIFI_SS, SPIWIFI_ACK, ESP32_RESETN, ESP32_GPIO0, &SPIWIFI);
    Besides i still have the issue that it works only with the added AdaLogger feather even after adding two 10k pull-ups on CS and MOSI.

    Any clues?

  5. #5
    Junior Member
    Join Date
    Jan 2021
    Posts
    2
    Hiya, I wondered if anyone has had any more progress I this? I've run through all the steps and not having any joy (am currently waiting on delivery of an Adalogger) Can anyone give guidance on an alternative to using the logger?

  6. #6
    Junior Member
    Join Date
    Jan 2021
    Posts
    2

    Laptop USB power sufficient for this setup?

    Quote Originally Posted by Asteroider View Post
    Hiya, I wondered if anyone has had any more progress I this? I've run through all the steps and not having any joy (am currently waiting on delivery of an Adalogger) Can anyone give guidance on an alternative to using the logger?
    Also I was wondering if the USB port on my laptop would provide sufficient power to run this setup? (given that the instructions here rely on response via the serial monitor)

    Or would it be prudent to add an aditional power supply?

    I'm a bit of a NOOB with this stuff. I've been tinkering with Arduino for 10 or 15 years with reasonabel success but this is a bit of stretch for me :-) so I'm grateful for any assistance

    Cheers

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •