Arduino_USBHostMbed5 + Wifi Conflict?

Hello. I'm trying to use the Wifi and Arduino_USBHostMbed5 libraries together. I have a working Wifi example, and have successfully transferred data between two R1s using UDP packets just fine.

I have also used Arduino_USBHostMbed5 to read files from my USB device.

But, when I simply #include the Arduino_USBHostMbed5 header into my Wifi sketch, it causes the call to WiFi.beginAP() to fail.

I'm new to the Arduino world, so I don't really know a lot about debugging in this environment. I can say that calling WiFi.beginAP() causes the red light on the Giga to start flashing, and that's about it, lol.

I'm digging through the library source right now to see if I can spot anything. Clearly some globals must are being included that are causing some sort of conflict.

Any help would be much appreciated!

I hate to do this, but I'm a new user and cannot upload attachments, so here's the code inline:

#include <SPI.h>
#include <WiFi.h>
#include <WiFiUdp.h>

// Simply including this header causes the sketch to fail
// #include <Arduino_USBHostMbed5.h>

#include "arduino_secrets.h" 
///////please enter your sensitive data in the Secret tab/arduino_secrets.h
char ssid[] = SECRET_SSID;        // your AP SSID (name)
char pass[] = SECRET_PASS;    // your AP password

unsigned int localPort = 2390;      // local port to listen on
char packetBuffer[256];             // buffer to hold incoming packet
char  ReplyBuffer[] = "acknowledged";       // a string to send back

WiFiUDP Udp;

void setup() {
  // Initialize serial and wait for port to open:
  Serial.begin(9600);
  // while (!Serial) {
  //   ; // wait for serial port to connect. Needed for native USB port only
  // }

  Serial.println("Access Point UDP Server");

  // check for the WiFi module:
  if (WiFi.status() == WL_NO_MODULE) {
    Serial.println("Communication with WiFi module failed!");
    // don't continue
    while (true);
  }

  // print the network name (SSID);
  Serial.print("Creating access point named: ");
  Serial.println(ssid);

  // Create open network. Change this line if you want to create an WEP network:
  int status = WiFi.beginAP(ssid, pass);
  if (status != WL_AP_LISTENING) {
    Serial.println("Creating access point failed");
    // don't continue
    while (true);
  }

  // wait 10 seconds for connection:
  delay(10000);

  // start UDP
  Udp.begin(localPort);
  
  // print the WiFi status
  printWiFiStatus();
}

void loop() {
  // if there's data available, read a packet
  int packetSize = Udp.parsePacket();
  if (packetSize) {
    Serial.print("Received packet of size ");
    Serial.println(packetSize);
    Serial.print("From ");
    IPAddress remoteIp = Udp.remoteIP();
    Serial.print(remoteIp);
    Serial.print(", port ");
    Serial.println(Udp.remotePort());

    // read the packet into packetBufffer
    int len = Udp.read(packetBuffer, 255);
    if (len > 0) {
      packetBuffer[len] = 0;
    }
    Serial.println("Contents:");
    Serial.println(packetBuffer);

    // send a reply, to the IP address and port that sent us the packet we received
    Udp.beginPacket(Udp.remoteIP(), Udp.remotePort());
    Udp.write(ReplyBuffer);
    Udp.endPacket();
  }
}

void printWiFiStatus() {
  // print the SSID of the network you're attached to:
  Serial.print("SSID: ");
  Serial.println(WiFi.SSID());

  // print your board's IP address:
  IPAddress ip = WiFi.localIP();
  Serial.print("IP Address: ");
  Serial.println(ip);

  // print the received signal strength:
  long rssi = WiFi.RSSI();
  Serial.print("signal strength (RSSI):");
  Serial.print(rssi);
  Serial.println(" dBm");
}

I just tested your code with #include <Arduino_USBHostMbed5.h> and I still got my Access Point configured without error and I got no flashing red LED either.

Maybe check that you have the latest library versions. I know the Arduino_USBHostMbed5 library was recently updated.

Interesting. The library manager said that I had the latest version installed (0.1.1). I even removed it and installed it from a zip from the github repo. I still see the same issue :(.

I have two Giga R1s, so I tried the second board this morning and still get the flashing red light.

I also created a brand new sketch and copied my code into it. Still, flashing red light.

Thanks for your help. Any other suggestions would be appreciated.

Also check that your Board Manager files are up to date. MbedOS Giga is version 4.0.4.

Yep, it's up to date as well.

I'm at a loss. If I can't use USB and Wifi at the same time, then this isn't going to work for my project.

I'll keep digging!

Well, this is interesting. I have been using the Arduino IDE this whole time. I uploaded everything to the cloud IDE, and magically everything just worked.

Just for reference to others like me who may have the same issue in the future, what could have caused this? I made sure everything was up to date?

Anyway, using the cloud IDE solved this issue.

You might compare the output from a compilation of the sketch with the verbose output preference enabled between Arduino IDE and Arduino Web Editor to see what differences there are between the two.

One potentially significant difference is that you said you are using version 4.0.4 of the "Arduino Mbed OS Giga Boards" platform with Arduino IDE, but Arduino Cloud is still using 4.0.2. You could test to see whether this is the relevant difference by using the Arduino IDE Boards Manager to install version 4.0.2 and then check whether the problem still occurs when you upload the sketch to the board using Arduino IDE.

Another potential difference is the "custom board options" menus, which you might have set different in Arduino IDE vs Arduino Web Editor:

  • Flash split
  • Target core