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

Thread: I'm trying to do a RAWHID test program for TeensyLC

  1. #1

    I'm trying to do a RAWHID test program for TeensyLC

    I'm trying to write a RAWHID program to connect a Windows10 tablet to a TeensyLC.
    I've done it successfully for both a Teensy 2.0 and Teensy 2.0+.

    But the TeensyLC doesn't work.

    There is an old RAWHID example under the Teensy->Code Library tab.
    It lists the "Teensy Side Functions" as:
    void usb_init(void);
    uint8_t usb_configured(void);
    int8_t usb_rawhid_recv(uint8_t *buffer, uint8_t timeout);
    int8_t usb_rawhid_send(const uint8_t *buffer, uint8_t timeout);

    Before getting fancy...I'm just trying to get a simple "send" and "receive" program to work.
    The TensyLC will sit in a "while loop"...waiting to receive a packet from the tablet.
    The Tablet will sent the first packet.
    The TeensyLC will receive it and immediately send it back.
    The Tablet will receive it and immediately send it back.
    Each USB packet the tablet sees will print out on a log file.
    No lines are printing.
    We should see approximately 500 packets going to the TeensyLC and 500 packets going to the Tablet per second.

    Here's the source:
    I'm getting errors in compiling...
    The compiler doesn't recognize usb_init() and usb_configured()....they are undefined.
    But, the compiler does recognize usb_rawhid_recv() and usb_rawhid_send().

    Code:
    byte buffer[64];
    int count = 0x00;
    byte ping = 1;
    
    void setup()
    {
    	usb_init();                     //THIS FUNCTION THROWS AND UNDEFINED COMPILER ERROR
    	pinMode(LED_BUILTIN, OUTPUT);
    	for (int i = 0; i < 64; i++)
    	{
    		buffer[i] = count;
    		count++;
    	}
    	while (usb_configured() != 1);      //THIS FUNCTION THROWS AND UNDEFINED COMPILER ERROR
    	digitalWrite(LED_BUILTIN, HIGH);
    }
    	
    void loop()
    {
    	while(usb_rawhid_recv(buffer, 100) == 0);
    	usb_rawhid_send(buffer, 100);
    }
    I'm using Visual Micro to compile and am using the "USB HID" USB Type.
    When the board gets plugged in it already has a RAWHID Session...so I guess usb_init() might not be necessary.
    If I comment out the two lines with errors, the code itself still doesn't work

    Any help would be appreciated...

    Jim K.

    PS.
    I'm pretty sure it has to do with USB Enumeration.
    Looks like the RAWHID USB type has more than HID.
    I have a program the lists all the USB devices.
    I see something pointing to the usbccgp.sys....and two things pointing to hidusub.sys.
    These are all coming from the TeensyLC with the VendorID of 16c0....and the ProductID of 0486.
    Last edited by Burly; 11-14-2016 at 01:57 AM.

  2. #2
    Senior Member+ defragster's Avatar
    Join Date
    Feb 2015
    Posts
    9,675
    usb_init is called before setup() is called? What do you expect usb_configured to do?

    There is a variable "volatile uint8_t usb_configuration = 0;" - but that is used internally for tracking it seems?

  3. #3
    OK...I've got it fixed...

    There is a sample program where Arduino is installed on your C: drive.
    Program Files (x86)\arduino\examples\teensy\USB_RawHID\Basic\Bas ic.pde

    I shortened the sample to be minimal code.
    I get a little under 1000 packets sent per second...500 in each direction.

    Code:
    void setup()
    {
        pinMode(LED_BUILTIN, OUTPUT);
        digitalWrite(LED_BUILTIN, HIGH);
    }
    
    byte buffer[64];
    int count = 0;
    
    void loop()
    {
        while (RawHID.recv(buffer, 100) == 0);
        RawHID.send(buffer, 100);	
        
        count++;
        if (count > 100 )
        {
            count = 0;
        }
        if (count > 50)
            digitalWrite(LED_BUILTIN, HIGH);
        else
            digitalWrite(LED_BUILTIN, LOW);
     
    }
    So the RawHID object is already instantiated and ready to use.
    Last edited by Burly; 11-14-2016 at 05:12 AM.

  4. #4
    Senior Member+ defragster's Avatar
    Join Date
    Feb 2015
    Posts
    9,675
    Quote Originally Posted by Burly View Post
    OK...I've got it fixed...

    There is a sample program where Arduino is installed on your C: drive.
    Program Files (x86)\arduino\examples\teensy\USB_RawHID\Basic\Bas ic.pde
    ...

    So the RawHID object is already instantiated and ready to use.
    Yep, Paul sells rather small but moderately priced ( by Arduino Standards ) and very capable hardware as the come on - then supplies working software in a ready to run environment that lets it do a great deal - at no charge, a very user friendly business model.

  5. #5
    Yep...I'm very pleased with my TeensyLC's.

Posting Permissions

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