Tiny Sorter on Arduino Uno R4 Minima...or not?

Hi,

I tried to make this project:

I had to buy a new board, and choose to buy the more recent Arduino Uno R4 Minima instead of the Arduino Leonardo, expecthing that both boards ability to act as mouse/keyboard was what was needed. But I'm now really struggling to make it work ;(

When trying to verify this code:

#include <WebUSB.h>

/**
 * Creating an instance of WebUSBSerial will add an additional USB interface to
 * the device that is marked as vendor-specific (rather than USB CDC-ACM) and
 * is therefore accessible to the browser.
 *
 * The URL here provides a hint to the browser about what page the user should
 * navigate to to interact with the device.
 */
WebUSB WebUSBSerial(1 /* https:// */, "webusb.github.io/arduino/demos/rgb");

#define Serial WebUSBSerial

const int redPin = 9;
const int greenPin = 10;
const int bluePin = 11;
int color[3];
int colorIndex;

void setup() {
  while (!Serial) {
    ;
  }
  Serial.begin(9600);
  Serial.write("Sketch begins.\r\n");
  Serial.flush();
  colorIndex = 0;
}

void loop() {
  if (Serial && Serial.available()) {
    color[colorIndex++] = Serial.read();
    if (colorIndex == 3) {
      analogWrite(redPin, color[0]);
      analogWrite(greenPin, color[1]);
      analogWrite(bluePin, color[2]);
      Serial.print("Set LED to ");
      Serial.print(color[0]);
      Serial.print(", ");
      Serial.print(color[1]);
      Serial.print(", ");
      Serial.print(color[2]);
      Serial.print(".\r\n");
      Serial.flush();
      colorIndex = 0;
    }
  }
}

but I get this error:

In file included from C:\Users\[user]\Downloads\arduino-gh-pages\arduino-gh-pages\demos\rgb\sketch\sketch.ino:1:0:
C:\Users\[user]\AppData\Local\Arduino15\libraries\WebUSB/WebUSB.h:31:10: fatal error: PluggableUSB.h: No such file or directory
 #include "PluggableUSB.h"
          ^~~~~~~~~~~~~~~~
compilation terminated.
exit status 1

Compilation error: exit status 1

Without the complete error message I can only take a SWAG. It cannot find one of the files"
#include "PluggableUSB.h". That include could be in one of the libraries, not sure. Also the " tells me it needs to be in the same directory as the sketch. Again just a SWAG.

It is typically provided as part of the core. For example, you can see it here in the core of the "Arduino AVR Boards" platform:

https://github.com/arduino/ArduinoCore-avr/blob/master/cores/arduino/PluggableUSB.h

The system is documented here:

Unfortunately this was not implemented in the core of the "Arduino UNO R4 Boards" platform, so any library that depends on PluggableUSB can't be used with the UNO R4 Minima board.

The "Arduino UNO R4 Boards" platform uses the TinyUSB stack, and TinyUSB does implement WebUSB:

https://github.com/arduino/tinyusb/tree/c796dcfe0bee337547437632dc16829038ef0f3d/examples/device/webusb_serial

But I'm doubtful about how easy this would be to get working in an Arduino sketch for the UNO R4 Minima in the absence of a nice wrapper library.

1 Like