Coder Social home page Coder Social logo

usb_host_library_samd's Introduction

USB Host Library SAMD

USB Host Library for Arduino SAMD boards

This library is based on the USB Host Shield Library 2.0 with modifications to work on Arduino and Arduino compatible SAMD boards. Be sure to see the README for details on Bluetooth pairing, etc. because the information is not repeated here.

This library would not be possible without the work of the USB Host Shield Library developers. Thank you!

The example programs should work on Zero, M0, and MKR family on the native USB port in USB host mode. The USB host shield with MAX3421E is not supported by this library.

Early versions of this library required some changes to the SAMD board package. The current version does not, so it works like a regular Arduino library.

Image of MKR Zero connected to Xbox One controller

USB Host Co-Processor

The related USB Host Co-Processor project encapsulates some of the USB host drivers of this project (MIDI and keyboard so far) in an Adafruit Trinket M0. This allows boards without USB hardware or without USB host software support to use USB host mode by connecting via UART to a Trinket M0.

To make using the firmware even easier, the repo includes UF2 binary releases that can be burned into a Trinket M0 by dragging and dropping the UF2 file on the TRINKETBOOT USB drive. It is not necessary to install the Arduino IDE, libraries, or USB serial driver.

Xbox and MKR board example

Components from left to right:

  • USB phone/tablet charger, 5V
  • Arduino MKR Zero (but any MKR board should work)
  • Adafruit CP2104 USB to UART (but any USB 3.3V serial should work)
  • Xbox One controller with batteries

USB OTG to host cable and 2 X USB micro cables are also shown. Search any shopping website for "usb otg to usb host".

The Xbox controller must have working batteries to ensure the controller works when both rumble motors are turned on.

When using a MKR board, in the XBOXONE.ino example program, change "Serial." to "Serial1." to get serial console on the TX/RX pins.

When using USB host mode on MKR boards, the IDE automatic upload does not work. When the IDE says "Uploading", double click on the MKR board reset button.

Be sure the USB serial board uses 3.3V logic levels on Tx and Rx and 5V on the power pin.

CP2104 MKR board
5V VIN
GND GND
RXD 14<-TX (Serial1)
TXD 13->RX (Serial1)

The CP2104 board passes through the USB 5V to the MKR VIN power input pin. The MKR board powers the Xbox controller via its USB port.

Arduino MKR Boards

The Zero and M0 boards have two USB ports. The programming port is used for sketch uploads and serial console. The native USB port with a USB OTG to host cable/adapter is used for the USB device (for example, Xbox controller). When using a MKR board, the native USB port is used for both functions.

The IDE automatic upload does not work on MKR boards when using USB host. The solution is simple. Unplug the USB OTG to host cable/adaper, plug in the MKR board to computer running the IDE as usual. Press the IDE Upload icon. When the IDE status shows "Uploading", double click the MKR board reset button.

Adafruit M0 and M4 Boards

The Adafruit Metro M4 (SAMD51) and Trinket M0 (SAMD21) work with this library. Follow Adafruit's tutorial to install the Adafruit SAMD board package. Other Arduino compatible (for example Adafruit, SparkFun, etc.) SAMD boards might work.

Image of Metro M4 connected to PS3 controller clone via Bluetooth

Components starting from the Metro M4 board then moving clockwise.

  • Adafruit Metro M4 with USB OTG to host adapter and USB Bluetooth plug
  • USB FTDI serial board for serial console and power
  • USB phone/tablet charger, 5V
  • Playstation 3 controller (clone) with Bluetooth
FTDI Metro M4 board
5V VIN
GND GND
RXD TX-1 (Serial1)
TXD RX-0 (Serial1)

Related projects

Testing

This is unstable and may break at any time. It works for me but may not work you. Use At Your Own Risk. Your Mileage May Vary. Batteries Not Included.

I do not have the hardware to test all the drivers. Also I do not have time to do extensive testing. Hardware I have connected and tested minimally:

  • USB keyboard and mouse
  • Xbox One USB (genuine)
  • Xbox 360 USB (clone)
  • PS3 USB (cheap clone)
  • PS4 USB (genuine)
  • ftdi serial
  • pl2303 serial
  • CDC ACM serial (Uno, Leonardo, Zero, MKR, CircuitPlayground Express)
  • MIDI USB Korg NanoKontrol2
  • Bluetooth SPP, BTHID (BT keyboard), and PS3BT (Playstation 3 controller)
  • ADK ArduinoBlinkLED
  • USB hubs work but not reliable yet
  • Logitech Extreme 3D Pro joystick
  • Thrustmaster T.16000M FCS joystick
  • Dymo M10 postage scale using the scaleEasy example
  • USB ESC POS receipt printer (https://github.com/gdsports/USBPrinter_uhls)

Building the development environment

Early versions of this library required patches to the SAMD board package. The current version does not, so it works like a regular Arduino library.

The following script works for a Linux system. The enviroment uses the Arduino IDE portable feature to insulate this project from the standard Arduino directories. This is no longer needed since it no longer patches the SAMD board package.

The script use the IDE command line interface (CLI) which is documented here.

IDEVER="1.8.7"
# Change to home directory
cd
# Create work directory
mkdir arduino_samd_usb_host
cd arduino_samd_usb_host
WORKDIR=`pwd`
# Install Ardino IDE in work directory
wget -O arduino.tar.xz https://downloads.arduino.cc/arduino-${IDEVER}-linux64.tar.xz
tar xf arduino.tar.xz -C ${WORKDIR}
rm arduino.tar.xz
# Create portable sketchbook and library directories
# Using portable prevents these changes from affecting other Arduino projects.
IDEDIR="${WORKDIR}/arduino-${IDEVER}"
LIBDIR="${IDEDIR}/portable/sketchbook/libraries"
mkdir -p "${LIBDIR}"
cd ${IDEDIR}
# Install board package
./arduino --pref "compiler.warning_level=default" --save-prefs
./arduino --install-boards "arduino:samd"
BOARD="arduino:samd:arduino_zero_edbg"
./arduino --board "${BOARD}" --save-prefs
# Install MIDI library for USBH_MIDI examples
./arduino --install-library "MIDI Library"
cd ${LIBDIR}
# Install TinyGPS for pl2303 example
git clone https://github.com/mikalhart/TinyGPS.git
# Install USB host library for SAMD
git clone https://github.com/gdsports/USB_Host_Library_SAMD
cd ${IDEDIR}
./arduino &

usb_host_library_samd's People

Contributors

gdsports avatar per1234 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

usb_host_library_samd's Issues

delay.h not found

using on Arduino Nano IOT board

libraries/USB_Host_Library_SAMD-master/src/usbhub.cpp:18:10: fatal error: delay.h: No such file or directory
#include "delay.h"

include from sketch

#include <cdcacm.h>
#include <usbhub.h>

or just

#include <usbhub.h>

if I comment it out , no errors

Works on Nano 33 iOT but cannot compile for RP2040 connect

I was using a Trinket M0. That worked so I moved to a Nano 33 iOT and that worked... but going to the RP2040 Connect with Cortex M0+, I am getting errors mentioning the variant. Is there something I can change to allow it to work with the M0+ (133Mhz) or is it a whole different animal?

KeyboardController

Hello, I am trying to connect a USB keyboard -> SAMD21 (Itsy Bitsy M0 Express) -> OLED.
I want to send ASCII from the USB keyboard to the M0 so I can output characters on the OLED.

I'm not sure how to use this library. I have installed it into Arduino IDE, used your KeyboardController.ino example code but I'm not sure how to read the serial output to test it.

I've connected a Prolific USB-to-Serial cable to the M0 (tx/Rx) and my computer (shows up as COM14) and opened the port via PuTTY to read the output and this is what I get in the console upon booting up the M0: " ▒▒▒▒▒▒ "

I am new to programming and working with microcontrollers, so if you could offer any help as to how to use this library that would be greatly appreciated!

(P.S. I found your Trinket M0 firmware UF2 stuff and tried that but I also couldn't get it to work on my Itsy Bitsy M0)

Disable USB Host mode

Hello,

I am trying to figure out a way to disable USB host or be able to switch from USB host USB device mode. Does this library offer this functionality?

Recvbuf needs to be aligned

Hi the datasheet for the SAMD21 here https://cdn.sparkfun.com/datasheets/Dev/Arduino/Boards/Atmel-42181-SAM-D21_Datasheet.pdf page 836, says that the ADDR value must be aligned with the two least significant bits zero.

So in USBH_MIDI_dump.ino the bufMidi declaration should be
uint8_t bufMidi[64] __attribute__ ((aligned (4)));

Similarly, looking at USB_MIDI_converter_multi.ino, this leads to the declaration in usbh_midi.h
uint8_t recvBuf[MIDI_EVENT_PACKET_SIZE];
This also needs to be aligned per the datasheet.

I am not sure the implications of this. I am doing a deep dive on this code to sort out the dropped MIDI message problem, and just stumbled on it.

incompatibility with Adafruit_SSD1306.h?

Can anyone think of a reason why introducing
#include <usbh_midi.h>
#include <usbhub.h>
in a sketch with an OLED display produces garbled images on the display?
the oled runs on I2C on the standard XIAO/QT Py pins of the SAMD21.

Seeeduino Xiao

hi sir, I use this librarry with my seeeduino xiao to controlling my MIDI device. I have tested on several MIDI Device and It's work og my BOSS ME 80, Zoom MS60B, Behringer BCF2000. but when I try on Korg PA300 still detected and sketch running normally but no MIDI messages sent to KORG PA300. how I can fix it? thanks

USB Not starting on Adafruit QTPy w/USB-C->USB-A (3.0) Adapter

Hi folks,

I made an adapter PCB that puts two Adafruit QTPy boards back-to back and connects the UART, SPI and I2C lines (plus power and ground). Happy to share the Eagle files when it's working (or before privately).

However, when I run the MouseController example it only gets "Detached, waiting for Device" and never enumerates. The USB_desc example also just waits with no state changes.

Because the QTPy has only a USB-C connector, I am using a USB-C OTG connector (this one: https://tinyurl.com/y6rd252y )

Is there any chance that the USBHost code won't work w/a USB-C or a USB 3.0 connection?

This same code worked with the Trinket M0, so I'm a bit lost.

Thanks

The data received with Arduino MKR 1010 is missing

I connect MKR 1010 to a Lidar with a OTG cable .MKR 1010 is USBHost , it can send command to Lidar and receive data from Lidar.
But the problem I meet is the data I receive is loss some bytes. The bellow is my code.
`#include <cdcacm.h>
#include <SPI.h>
#include <WiFiNINA.h>
#include <usbhub.h>
#include "pgmstrings.h"

// On SAMD boards where the native USB port is also the serial console, use
// Serial1 for the serial console. This applies to all SAMD boards except for
// Arduino Zero and M0 boards.
#if (USB_VID==0x2341 && defined(ARDUINO_SAMD_ZERO)) || (USB_VID==0x2a03 && defined(ARDUINO_SAM_ZERO))
#define SerialDebug SERIAL_PORT_MONITOR
#else
#define SerialDebug Serial1
#endif

class ACMAsyncOper : public CDCAsyncOper
{
public:
uint8_t OnInit(ACM *pacm);
};

uint8_t ACMAsyncOper::OnInit(ACM *pacm)
{
uint8_t rcode;
// Set DTR = 1 RTS=1
rcode = pacm->SetControlLineState(3);

if (rcode)
{
ErrorMessage<uint8_t>(PSTR("SetControlLineState"), rcode);
return rcode;
}

LINE_CODING lc;
lc.dwDTERate = 115200;
lc.bCharFormat = 0;
lc.bParityType = 0;
lc.bDataBits = 8;

rcode = pacm->SetLineCoding(&lc);

if (rcode)
ErrorMessage<uint8_t>(PSTR("SetLineCoding"), rcode);

return rcode;
}

uint8_t* hokuyo_data= (uint8_t*) malloc(128);

char ssid[] = "passssss";
char pass[] = "12345678";
int keIndex = 0;
int status = WL_IDLE_STATUS;

const IPAddress serverIP(192, 168, 137, 1);
uint16_t serverPort = 54768;

WiFiClient client;

USBHost UsbH;
USBHub Hub(&UsbH);
ACMAsyncOper AsyncOper;
ACM Acm(&UsbH, &AsyncOper);

void setup()
{
// SerialDebug.begin(19200);
// SerialDebug.println("Start");

if (UsbH.Init())
//SerialDebug.println("USB host failed to initialize");

delay( 200 );

//SerialDebug.println("USB Host init OK");
WiFi.begin(ssid, pass);
while (WiFi.status() != WL_CONNECTED)
{
delay(500);
//Serial.print(".");
}

if (client.connect(serverIP, serverPort))
{
client.print("Hello world!");
}

else

{
client.stop();
}

//client.connect(serverIP, serverPort);
//client.print("Hello world!");

}

void loop()
{

UsbH.Task();
if (Acm.isReady()) {
  uint8_t rcode;

  if (client.available()) {
    String line = client.readString();
    //client.write(line.c_str());
    /* sending to the phone */
    rcode = Acm.SndData(line.length(), (uint8_t*) line.c_str());
    if (rcode)
      ErrorMessage<uint8_t>(PSTR("SndData"), rcode);
  } //if(Serial.available()...

  //delay(50);
  uint32_t epAddr = Acm.GetEpAddress();
  static uint8_t buf[1024];
  uint16_t rcvd = 1024;
  rcode = Acm.RcvData(&rcvd, buf);
  if (rcode && rcode != USB_ERRORFLOW)
    ErrorMessage<uint8_t>(PSTR("Ret"), rcode);

  if (rcvd) { //more than zero bytes received
    for (uint16_t i = 0; i < rcvd; i++) {
      client.write((char) buf[i]); //printing on the screen
      
    }
    
  }
  
}

}`

delay.h issue

cannot compile this library anymore on MKRzero, stops at "Arduino/Sketches/libraries/USB_Host_Library_SAMD/src/usbhub.cpp:18:10: fatal error: delay.h: No such file or directory".

USB Host with a SAMD21: receiving and sending data issues

I am using an Seeed Xiao SAMD21 controller as an USB Host.

The USB counter part I would like to read and write to is a custom Controller from a 3rd-party company that normally connects via USB-FTDI COM port to a computer.

I would like to directly connect this 3rd-party Controller to my Xiao SAMD21 USB-Host.

By the below code example1, I achieved to read from the 3rd-party controller !!
I used the existing example for a PL2303 from the given USB_Host_Library_SAMD library. And this PL2303 example seemed to work best to interact with my 3rd-party Controller.

However, there are still two problems:

  1. about every 10th reading is only partially received (i.e. letters in receiving-string are missing)
  2. I cannot send yet (I can only receive)

As for the first problem: erroneous readings:
Some readings are cut-off parts of the receiving string. Most receiving-communication works. There is just about every 10th cmd from the 3rd-party controller that is only partially transmitted (i.e. partially received). I tried to change the delay in the receiving routine as can be seen in example1 below. But without success.

Do you have any idea what I could do in order to get 100% successful data readings ?

Example1: Receiving data from the 3rd-party Controller to a SAMD21 USB-Host:

#include <usbhub.h>
#include <cdcacm.h>
#include <cdcprolific.h>

class PLAsyncOper : public CDCAsyncOper {
    public:
        uint8_t OnInit(ACM *pacm);
};

uint8_t PLAsyncOper::OnInit(ACM *pacm) {
    
    uint8_t rcode;

    // Set DTR = 1
    rcode = pacm->SetControlLineState(1);

    if (rcode) {
        ErrorMessage<uint8_t>(PSTR("SetControlLineState"), rcode);
        return rcode;
    }

    LINE_CODING	lc;
    lc.dwDTERate = 115200;
    lc.bCharFormat	= 0;
    lc.bParityType	= 0;
    lc.bDataBits	= 8;

    rcode = pacm->SetLineCoding(&lc);

    if (rcode) {
        ErrorMessage<uint8_t>(PSTR("SetLineCoding"), rcode);
    }

    return rcode;
}

USBHost         UsbH;
PLAsyncOper     AsyncOper;
PL2303          Pl(&UsbH, &AsyncOper);

void setup() {
    
  Serial1.begin(115200); // receiving from 3rd-party controller and sending to Serial1
  delay(2000);

  if (UsbH.Init()) {
      Serial1.println("USB host did not start");
  }

  delay( 200 );
}

void loop() {
    
    UsbH.Task();

    if( UsbH.getUsbTaskState() == USB_STATE_RUNNING ) {
        
        uint8_t rcode;
        
        uint8_t  buf[32];
        uint16_t rcvd = 32;
        rcode = Pl.RcvData(&rcvd, buf);
        if (rcvd) { // more than zero bytes received
            String receivedStr = "";
            for (uint16_t i=0; i < rcvd; i++ ) {
                receivedStr += (char)buf[i];
                delay(3);
                // delay(5);       // ...other delays did not have an effect, unfortunately
                // delay(10);    // ... but without any delay, every cmd is only received partailly. So I think there must be a delay even tough it makes the entire reading slower....
                // delay(20);
                // delay(100);
            }
            Serial1.write(receivedStr.c_str());
        }
    }
}

Also, I tried to write to the 3rd-party Controller - but this did not work at all. See code-example 2

Example2: Sending data to the 3rd-party Controller from a SAMD21 USB-Host:

#include <usbhub.h>
#include <cdcacm.h>
#include <cdcprolific.h>

class PLAsyncOper : public CDCAsyncOper {
    public:
        uint8_t OnInit(ACM *pacm);
};

uint8_t PLAsyncOper::OnInit(ACM *pacm) {
    
    uint8_t rcode;

    // Set DTR = 1
    rcode = pacm->SetControlLineState(1);

    if (rcode) {
        ErrorMessage<uint8_t>(PSTR("SetControlLineState"), rcode);
        return rcode;
    }

    LINE_CODING	lc;
    lc.dwDTERate = 115200;
    lc.bCharFormat	= 0;
    lc.bParityType	= 0;
    lc.bDataBits	= 8;

    rcode = pacm->SetLineCoding(&lc);

    if (rcode) {
        ErrorMessage<uint8_t>(PSTR("SetLineCoding"), rcode);
    }

    return rcode;
}

USBHost         UsbH;
PLAsyncOper     AsyncOper;
PL2303          Pl(&UsbH, &AsyncOper);

void setup() {
    
  Serial1.begin(115200); // receiving from 3rd-party controller and sending to Serial1
  delay(2000);

  if (UsbH.Init()) {
      Serial1.println("USB host did not start");
  }

  delay( 200 );
}

void loop() {
    
    UsbH.Task();

    if( UsbH.getUsbTaskState() == USB_STATE_RUNNING ) {
        
        uint8_t rcode;
        
        // sending to the 3rd-party controller
        if (Serial1.available()) {                    
            uint8_t data= Serial1.read();
            rcode = Pl.SndData(1, &data);
        }
    }
}

There was no data transmission at all. What could be improved ??

Questions:

  1. What can I do to improve the data-receiving ? (i.e. how to get rid of missing receive-strings ?)
  2. What can I do to get data-sending working at all ?
  3. Which example-library do you suggest to work best for my USB-FTDI counter-part (see USB-specs below) ?

Here is a complete printout of the 3rd-party USB chip that my 3rd-party Controller contains:

String Descriptors:
Manufacturer:           Prolific Technology Inc. 
Product:                USB-Serial Controller D

Device descriptor: 
Descriptor Length:      12
Descriptor type:        01
USB version:            0110
Device class:           00
Device Subclass:        00
Device Protocol:        00
Max.packet size:        40
Vendor  ID:             067B
Product ID:             2303
Revision ID:            0400
Mfg.string index:       01
Prod.string index:      02
Serial number index:    00
Number of conf.:        01

Configuration descriptor:
Total length:           0027
Num.intf:               01
Conf.value:             01
Conf.string:            00
Attr.:                  80
Max.pwr:                32

Interface descriptor:
Intf.number:            00
Alt.:                   00
Endpoints:              03
Intf. Class:            FF
Intf. Subclass:         00
Intf. Protocol:         00
Intf.string:            00

Endpoint descriptor:
Atr:oint address03      81
                  axpktsie              00
olin iteva:     0

ndpin dsrito:
npontaddes:02
             At.:               0
Polig ntrvl     000
Enpintdecrpor
Atr.t ddes:     0
Polig ntrvl:0   000
Adr1(.01)

feather m0 bluetooth le + 3.7v lipo run 3.3v mcu keeb?

Question/test request
Could this work:

  1. Install your usb host samd library on a feather m0 bluetooth le
  2. Connect 3.7v lipo to feather
  3. Connect a keyboard by a 3.3v pro micro (with no leds/neopixels on the keeb) to the feather's micro usb via otg cable
  4. Have the feather power this not thirsty keeb
    running its firmware on a 3.3v mcu (and no leds in use), capture its keycode outputs over HID and forward them over ble hid to a laptop or ipad?
  5. Have the feather charge lipo as usual when connected to a usb port/charger instead of the keeb?

USBH_MIDI : Failing to get device descriptor with some devices.

USBH_MIDI : Failing to get device descriptor with some devices.
The problem is at line 163 from USBH_MIDI.cpp: (Init)
rcode = pUsb->getDevDescr( 0, 0, sizeof(USB_DEVICE_DESCRIPTOR), (uint8_t*)buf );

With some devices work fine, and with others doesn't.
(return 0 when successful ; 8 when error )

Looking deep, the problem come from:
Line 206 from USB.cpp
rcode = dispatchPkt(tokSETUP, ep, nak_limit); // Dispatch packet

Any tips?

I can get device descriptor of any devices without using USBH_MIDI (without creating USBH_MIDI class)
I can get device descriptor from my PenDrive, and return that isn't a MIDI Device.
I can't get device descriptor from my Mouse by example, returning the RCODE equal 8.
My Zoom G3 works fine. My Nux MG300 doesn't.

Capturing and transmitting arrow key presses (directional keys: up down left right) for Arduino USB Host

The directional keys are not captured in the ASCII codes and are not returned by the Arduino KeyboardController getKey() function. However, for the KeyboardController library there is a function getOemKey() that can be used to capture presses of the directional arrow keys (up down left right). This function returns 79-81 for the arrow keys and then can be translated into the appropriate escape codes in a printKey() function as below.

I simplified the KeyboardController.ino sample file by deleting all the extra serial write outputs and left only the output for the printKey() statement as below.

Hardware setup: I ran this on an Adafruit ItsyBitsy M4 with serial output via UART. The UART was setup using #define SerialDebug Serial1

Below is the printkey() function that translates the getOemKey() codes into arrow key escape codes for my application.

void printKey() {
  switch (keyboard.getOemKey()) { // Trial on 5/4/2020 to see if it will fix arrow keys

    case 80:
      SerialDebug.write(27); // left
      SerialDebug.write(91);
      SerialDebug.write(68);
      break;

    case 79:
      SerialDebug.write(27); // Right
      SerialDebug.write(91);
      SerialDebug.write(67);
      break;

    case 81:
      SerialDebug.write(27); // down
      SerialDebug.write(91);
      SerialDebug.write(66);
      break;

    case 82:
      SerialDebug.write(27); // up
      SerialDebug.write(91);
      SerialDebug.write(65);
      break;

    default:
      SerialDebug.write(keyboard.getKey());
      break;
  }
}

Does this work with USBC boards?

I'm curious whether this works with USBC boards. In theory the CC lines need to have a different configuration for host vs. device. Does that mean some hardware modifications would be necessary?

Problem with USBH_MIDI with Zoom G3.

I can make USB_STATE_RUNNING with my Zoom G3 without de USBH_MIDI library.
But when I add the:
USBH_MIDI midiUsb(&usb);
I get problems.
Stuck a while with USB_STATE_CONFIGURING and then USB_STATE_ERROR.
Any Idea of what is happening or what I need to look for?

I just need to send data. Another library that I can use to send data?
outTransfer(bAddress, epInfo[epDataOutIndex].epAddr, bytes_send, dataptr);
How I get the "bAdress" and "epInfo[epDataOutIndex].epAddr" without USBH_MIDI library?

MKR WiFi 1010 pairing issues

First off, thanks for making the port! I'm trying to connect my PS3 nav controller to an MKR 1010 but I'm having some trouble. To pair the controller do we still have to find a way to plug it into the MKR board?

Also is there any way to access the serial port once it's programmed?

Thanks!

Using PTP to control camera never retrieves any data

I am trying to use this library to implement a simple PTP (picture transfer protocol) to be able to control my DLSR using Trinket M0.
But no matter what, I never get any data from the camera when using the actual PTP.
I can get all the descriptors just fine, as that's done by the library itself. Using them I set up the device to use correct endpoints and config. But then, no matter what, when I tried to get "GetDeviceInfo" from the camera, both outTransfer and inTransfer return 0, but there are never any data coming from inTransfer.
Here is the function that I call when I press a button connected to pin 1 on my trinket.

void camPoll() {
    int rcode;
    uint16_t length = (sizeof(uint16_t)*2 + sizeof(uint32_t)*2); //dont care about the rest of the container
    uint8_t data[length];
    memset(data, 0, length);
    //little endian
    data[0] = 0x0C;   //len 0
    data[4] = 0x01;   //type 0
    data[6] = 0x01;   //code 1
    data[7] = 0x10;   //code 0

    //send command container
    rcode = UsbH.outTransfer(1, ep_info[BULK_OUT].epAddr, length, data);
    u8x8log.printf("RC: %d\n", rcode);
    uint16_t read = 64;
    uint8_t in_data[64];
    memset(in_data, 0, 64);

    //receive data
    rcode = UsbH.inTransfer(1, ep_info[BULK_IN].epAddr, &read, in_data);
    u8x8log.printf("RC: %d\n", rcode);

    //print data
    for (int i = 0; i < 64; i++) {
        u8x8log.printf("%02x", in_data[i]);
        if ((i + 1) % 8 == 0) u8x8log.printf("\n");
    }
}

And every time, I get return code 0, but no data in "in_data".
Also, after 2 tries, I start to get return code 2 on outTransfer.
I have tried literally everything I could think of (different packet sizes, endians, endpoints), but nothing works.
Does anyone have any idea how to actually use this for PTP?

P.S.: I looked into some PTP libraries (libgphoto2, PTP2.0). I followed them as close as I could, but I never get anything from the camera.

USB MIDI message loss, tips on how to diagnose?

Hi,
This library is perfect for my needs, but I'm finding it is losing MIDI messages. Has anyone else seen this?

To demonstrate the issue, I've create a lightly modified version of the USBH_MIDI_dump.ino file at:
https://gist.github.com/todbot/7f05268ed3c5201c163a3e269d2c2d64
It parses out the received buffer into a collection of 4-byte USB-MIDI messages and logs the number of Note-On vs Note-Off messages.

If hooking up a USB MIDI keyboard (I've tried several) and mashing on the keys, you'll notice a mismatch between Note-On and Note-Off messages. You an also hear this if hooking up a serial MIDI synth to USB_MIDI_converter.ino.

I have enabled DEBUG_USB_HOST and can see the startup messages but no errors. I've tested this on a Trinket M0, ItsyBitsy M0 and ItsyBitsy M4, all with the same result.

I'd like to diagnose this issue. I have some experience with USB but not host stacks. Any tips on where to start?

OutTransfer not handling >64bytes

I am running some tests here with a FTDI device and I just can't send more than 64 bytes.
Checking the Ftdi.SndData, I saw it calls the OutTransfer which is suppose to deal with the maxpktsize (64 byte) limit.
I didn't test a solution yet, but looks like this is wrong:

uint8_t buf[64];

for( i=0; i<nbytes; i++) {
	buf[i] = data[i];
}

nbytes is the number of bytes (total) to be sent, a uint32. But this implementation takes only the fist 64bytes, since buf is 64 bytes long.

This for loop, copying the data to the buffer that will be writen should be done insisde the while (bytes_left) loop. This while loop seems to be OK, treating the message in chunks of 64 bytes and updating bytes_left every iteration.

I will test the solution tomorrow.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.