HID not sending anything - TinyUSB

Post here about your Arduino projects, get help - for Adafruit customers!

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
Knedl
 
Posts: 5
Joined: Sun Oct 16, 2022 4:04 am

HID not sending anything - TinyUSB

Post by Knedl »

Hi, I am trying to send potentiometer value through HID to python, but I don't recieve anything, just blank. What could be wrong?
This is arduino code:

Code: Select all

#include "Adafruit_TinyUSB.h"

#define REPORT_SIZE 16

uint8_t const desc_hid_report[] = {TUD_HID_REPORT_DESC_GENERIC_INOUT(REPORT_SIZE)};
Adafruit_USBD_HID usb_hid(desc_hid_report, sizeof(desc_hid_report), HID_ITF_PROTOCOL_NONE, 1, true);

char char_buf[REPORT_SIZE];


void setup()
{
pinMode(D8, INPUT_PULLDOWN);  
#if defined(ARDUINO_ARCH_MBED) && defined(ARDUINO_ARCH_RP2040)
  
  TinyUSB_Device_Init(0);
#endif

  usb_hid.enableOutEndpoint(true);
  usb_hid.setPollInterval(1);
  usb_hid.setReportDescriptor(desc_hid_report, sizeof(desc_hid_report));
  usb_hid.setStringDescriptor("Spotify Keyboard");

  usb_hid.setReportCallback(get_report, NULL);
  usb_hid.begin();

  Serial.begin(115200);


  while( !TinyUSBDevice.mounted() ) delay(1);

  Serial.println("Adafruit TinyUSB HID Generic In Out example");
}

int sense(void){
int volume =analogRead(A0);
return volume;


}


uint16_t get_report(uint8_t report_id, hid_report_type_t report_type,
                    uint8_t *buffer, uint16_t reqlen)
{
  uint16_t size = snprintf(char_buf, REPORT_SIZE, "%d", sense());
  for (int i = 0; i < size; i++)
    buffer[i] = (uint8_t)char_buf[i];
  return size;
}
void loop()
{
}
This is pyton:

Code: Select all

from re import S
import hid
import time

# default is TinyUSB (0xcafe), Adafruit (0x239a), RaspberryPi (0x2e8a), Espressif (0x303a) VID
USB_VID = (0xcafe, 0x239a, 0x2e8a, 0x303a)

print("VID list: " + ", ".join('%02x' % v for v in USB_VID))

for vid in  USB_VID:
    for dict in hid.enumerate(vid):
        print(dict)
        dev = hid.Device(dict['vendor_id'], dict['product_id'])
        if dev:
            while True:
                # Get input from console and encode to UTF8 for array of chars.
                # hid generic inout is single report therefore by HIDAPI requirement
                # it must be preceeded with 0x00 as dummy reportID
                # str_out = b'\x00'
                # str_out += input("Send text to HID Device : ").encode('utf-8')
                # dev.write(str_out)
                str_in = dev.read(0,16)
                print("Received from HID Device:", str_in, '\n')
                time.sleep(1)
           

User avatar
adafruit_support_mike
 
Posts: 67446
Joined: Thu Feb 11, 2010 2:51 pm

Re: HID not sending anything - TinyUSB

Post by adafruit_support_mike »

As a sanity check, is your Python code even finding the TinyUSB device? For that matter, does it show up in the Device Manager when you connect the microcontroller to the computer?

User avatar
Knedl
 
Posts: 5
Joined: Sun Oct 16, 2022 4:04 am

Re: HID not sending anything - TinyUSB

Post by Knedl »

Yes it finds it

User avatar
adafruit_support_mike
 
Posts: 67446
Joined: Thu Feb 11, 2010 2:51 pm

Re: HID not sending anything - TinyUSB

Post by adafruit_support_mike »

What microcontroller are you using?

User avatar
Knedl
 
Posts: 5
Joined: Sun Oct 16, 2022 4:04 am

Re: HID not sending anything - TinyUSB

Post by Knedl »

I am using Seeed XIAO RP2040

Locked
Please be positive and constructive with your questions and comments.

Return to “Arduino”