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

Thread: Basic:29: error: 'RawHID' was not declared in this scope

  1. #1
    Junior Member
    Join Date
    Mar 2022
    Posts
    6

    Basic:29: error: 'RawHID' was not declared in this scope

    I'm trying to use the Teensy example sketch 'Basic Raw HID Example', but I'm getting the error

    Code:
    Basic: In function 'void loop()':
    Basic:29: error: 'RawHID' was not declared in this scope
    To make a USB RawHID device, use the Tools > USB Type menu
       n = RawHID.recv(buffer, 0); // 0 timeout = do not wait
           ^
    'RawHID' was not declared in this scope
    The code from the example sketch, un altered.
    Code:
     /* Basic Raw HID Example
       Teensy can send/receive 64 byte packets with a
       dedicated program running on a PC or Mac.
    
       You must select Raw HID from the "Tools > USB Type" menu
    
       Optional: LEDs should be connected to pins 0-7,
       and analog signals to the analog inputs.
    
       This example code is in the public domain.
    */
    
    
    void setup() {
      Serial.begin(9600);
      Serial.println(F("RawHID Example"));
      for (int i=0; i<7; i++) {
        pinMode(i, OUTPUT);
      }
    }
    
    // RawHID packets are always 64 bytes
    byte buffer[64];
    elapsedMillis msUntilNextSend;
    unsigned int packetCount = 0;
    
    void loop() {
      int n;
      n = RawHID.recv(buffer, 0); // 0 timeout = do not wait
      if (n > 0) {
        // the computer sent a message.  Display the bits
        // of the first byte on pin 0 to 7.  Ignore the
        // other 63 bytes!
        Serial.print(F("Received packet, first byte: "));
        Serial.println((int)buffer[0]);
        for (int i=0; i<8; i++) {
          int b = buffer[0] & (1 << i);
          digitalWrite(i, b);
        }
      }
      // every 2 seconds, send a packet to the computer
      if (msUntilNextSend > 2000) {
        msUntilNextSend = msUntilNextSend - 2000;
        // first 2 bytes are a signature
        buffer[0] = 0xAB;
        buffer[1] = 0xCD;
        // next 24 bytes are analog measurements
        for (int i=0; i<12; i++) {
          int val = analogRead(i);
          buffer[i * 2 + 2] = highByte(val);
          buffer[i * 2 + 3] = lowByte(val);
        }
        // fill the rest with zeros
        for (int i=26; i<62; i++) {
          buffer[i] = 0;
        }
        // and put a count of packets sent at the end
        buffer[62] = highByte(packetCount);
        buffer[63] = lowByte(packetCount);
        // actually send the packet
        n = RawHID.send(buffer, 100);
        if (n > 0) {
          Serial.print(F("Transmit packet "));
          Serial.println(packetCount);
          packetCount = packetCount + 1;
        } else {
          Serial.println(F("Unable to transmit packet"));
        }
      }
    }

    Board is set to Teensy 4.0.
    I tried adding #include <usb_rawhid.h> to the sketch, but it didn't help.
    Last edited by slade; 03-24-2022 at 04:33 AM.

  2. #2
    Junior Member
    Join Date
    Mar 2022
    Posts
    6
    I had to set USB Type to "RAW HID".

  3. #3
    Senior Member+ defragster's Avatar
    Join Date
    Feb 2015
    Posts
    16,245
    Works here in the IDE 1.8.19 with TeensyDuino 1.56

    Board Selected Teensy 4.0
    USB: Raw HID

    Did a Verify Build - then rebuild for shorter console output that looks like the following - scrolling show RED notes confirming the options that should show there in Verbose Console output:
    Code:
    C:\T_Drive\arduino-1.8.19\arduino-builder -dump-prefs -logger=machine -hardware C:\T_Drive\arduino-1.8.19\hardware -hardware C:\Users\Tim\AppData\Local\Arduino15\packages -tools C:\T_Drive\arduino-1.8.19\tools-builder -tools C:\T_Drive\arduino-1.8.19\hardware\tools\avr -tools C:\Users\Tim\AppData\Local\Arduino15\packages -built-in-libraries C:\T_Drive\arduino-1.8.19\libraries -libraries C:\T_Drive\tCode\libraries -fqbn=teensy:avr:teensy40:usb=rawhid,speed=600,opt=o2std,keys=en-us -vid-pid=10C4_EA60 -ide-version=10819 -build-path R:\Temp\arduino_build_409939 -warnings=none -build-cache R:\Temp\arduino_cache_46238 -prefs=runtime.tools.teensy-compile.path=C:\Users\Tim\AppData\Local\Arduino15\packages\teensy\tools\teensy-compile\1.56.1 -prefs=runtime.tools.teensy-compile-1.56.1.path=C:\Users\Tim\AppData\Local\Arduino15\packages\teensy\tools\teensy-compile\1.56.1 -prefs=runtime.tools.teensy-monitor.path=C:\Users\Tim\AppData\Local\Arduino15\packages\teensy\tools\teensy-monitor\1.56.1 -prefs=runtime.tools.teensy-monitor-1.56.1.path=C:\Users\Tim\AppData\Local\Arduino15\packages\teensy\tools\teensy-monitor\1.56.1 -prefs=runtime.tools.teensy-tools.path=C:\Users\Tim\AppData\Local\Arduino15\packages\teensy\tools\teensy-tools\1.56.1 -prefs=runtime.tools.teensy-tools-1.56.1.path=C:\Users\Tim\AppData\Local\Arduino15\packages\teensy\tools\teensy-tools\1.56.1 -verbose C:\T_Drive\arduino-1.8.19\examples\Teensy\USB_RawHID\Basic\Basic.pde
    C:\T_Drive\arduino-1.8.19\arduino-builder -compile -logger=machine -hardware C:\T_Drive\arduino-1.8.19\hardware -hardware C:\Users\Tim\AppData\Local\Arduino15\packages -tools C:\T_Drive\arduino-1.8.19\tools-builder -tools C:\T_Drive\arduino-1.8.19\hardware\tools\avr -tools C:\Users\Tim\AppData\Local\Arduino15\packages -built-in-libraries C:\T_Drive\arduino-1.8.19\libraries -libraries C:\T_Drive\tCode\libraries -fqbn=teensy:avr:teensy40:usb=rawhid,speed=600,opt=o2std,keys=en-us -vid-pid=10C4_EA60 -ide-version=10819 -build-path R:\Temp\arduino_build_409939 -warnings=none -build-cache R:\Temp\arduino_cache_46238 -prefs=runtime.tools.teensy-compile.path=C:\Users\Tim\AppData\Local\Arduino15\packages\teensy\tools\teensy-compile\1.56.1 -prefs=runtime.tools.teensy-compile-1.56.1.path=C:\Users\Tim\AppData\Local\Arduino15\packages\teensy\tools\teensy-compile\1.56.1 -prefs=runtime.tools.teensy-monitor.path=C:\Users\Tim\AppData\Local\Arduino15\packages\teensy\tools\teensy-monitor\1.56.1 -prefs=runtime.tools.teensy-monitor-1.56.1.path=C:\Users\Tim\AppData\Local\Arduino15\packages\teensy\tools\teensy-monitor\1.56.1 -prefs=runtime.tools.teensy-tools.path=C:\Users\Tim\AppData\Local\Arduino15\packages\teensy\tools\teensy-tools\1.56.1 -prefs=runtime.tools.teensy-tools-1.56.1.path=C:\Users\Tim\AppData\Local\Arduino15\packages\teensy\tools\teensy-tools\1.56.1 -verbose C:\T_Drive\arduino-1.8.19\examples\Teensy\USB_RawHID\Basic\Basic.pde
    Using board 'teensy40' from platform in folder: C:\Users\Tim\AppData\Local\Arduino15\packages\teensy\hardware\avr\1.56.1
    Using core 'teensy4' from platform in folder: C:\Users\Tim\AppData\Local\Arduino15\packages\teensy\hardware\avr\1.56.1
    Detecting libraries used...
    "C:\\Users\\Tim\\AppData\\Local\\Arduino15\\packages\\teensy\\tools\\teensy-compile\\1.56.1/arm/bin/arm-none-eabi-g++" -E -CC -x c++ -w -g -Wall -ffunction-sections -fdata-sections -nostdlib -std=gnu++14 -fno-exceptions -fpermissive -fno-rtti -fno-threadsafe-statics -felide-constructors -Wno-error=narrowing -mthumb -mcpu=cortex-m7 -mfloat-abi=hard -mfpu=fpv5-d16 -D__IMXRT1062__ -DTEENSYDUINO=157 -DARDUINO=10819 -DARDUINO_TEENSY40 -DF_CPU=600000000 -DUSB_RAWHID -DLAYOUT_US_ENGLISH "-IC:\\Users\\Tim\\AppData\\Local\\Arduino15\\packages\\teensy\\hardware\\avr\\1.56.1\\cores\\teensy4" "R:\\Temp\\arduino_build_409939\\sketch\\Basic.pde.cpp" -o nul
    Generating function prototypes...
    "C:\\Users\\Tim\\AppData\\Local\\Arduino15\\packages\\teensy\\tools\\teensy-compile\\1.56.1/arm/bin/arm-none-eabi-g++" -E -CC -x c++ -w -g -Wall -ffunction-sections -fdata-sections -nostdlib -std=gnu++14 -fno-exceptions -fpermissive -fno-rtti -fno-threadsafe-statics -felide-constructors -Wno-error=narrowing -mthumb -mcpu=cortex-m7 -mfloat-abi=hard -mfpu=fpv5-d16 -D__IMXRT1062__ -DTEENSYDUINO=157 -DARDUINO=10819 -DARDUINO_TEENSY40 -DF_CPU=600000000 -DUSB_RAWHID -DLAYOUT_US_ENGLISH "-IC:\\Users\\Tim\\AppData\\Local\\Arduino15\\packages\\teensy\\hardware\\avr\\1.56.1\\cores\\teensy4" "R:\\Temp\\arduino_build_409939\\sketch\\Basic.pde.cpp" -o "R:\\Temp\\arduino_build_409939\\preproc\\ctags_target_for_gcc_minus_e.cpp"
    "C:\\T_Drive\\arduino-1.8.19\\tools-builder\\ctags\\5.8-arduino11/ctags" -u --language-force=c++ -f - --c++-kinds=svpf --fields=KSTtzns --line-directives "R:\\Temp\\arduino_build_409939\\preproc\\ctags_target_for_gcc_minus_e.cpp"
    Compiling sketch...
    "C:\\Users\\Tim\\AppData\\Local\\Arduino15\\packages\\teensy\\tools\\teensy-tools\\1.56.1/precompile_helper" "C:\\Users\\Tim\\AppData\\Local\\Arduino15\\packages\\teensy\\hardware\\avr\\1.56.1/cores/teensy4" "R:\\Temp\\arduino_build_409939" "C:\\Users\\Tim\\AppData\\Local\\Arduino15\\packages\\teensy\\tools\\teensy-compile\\1.56.1/arm/bin/arm-none-eabi-g++" -x c++-header -O2 -g -Wall -ffunction-sections -fdata-sections -nostdlib -MMD -std=gnu++14 -fno-exceptions -fpermissive -fno-rtti -fno-threadsafe-statics -felide-constructors -Wno-error=narrowing -mthumb -mcpu=cortex-m7 -mfloat-abi=hard -mfpu=fpv5-d16 -D__IMXRT1062__ -DTEENSYDUINO=157 -DARDUINO=10819 -DARDUINO_TEENSY40 -DF_CPU=600000000 -DUSB_RAWHID -DLAYOUT_US_ENGLISH "-IC:\\Users\\Tim\\AppData\\Local\\Arduino15\\packages\\teensy\\hardware\\avr\\1.56.1/cores/teensy4" "R:\\Temp\\arduino_build_409939/pch/Arduino.h" -o "R:\\Temp\\arduino_build_409939/pch/Arduino.h.gch"
    Using previously compiled file: R:\Temp\arduino_build_409939\pch\Arduino.h.gch
    "C:\\Users\\Tim\\AppData\\Local\\Arduino15\\packages\\teensy\\tools\\teensy-compile\\1.56.1/arm/bin/arm-none-eabi-g++" -c -O2 -g -Wall -ffunction-sections -fdata-sections -nostdlib -MMD -std=gnu++14 -fno-exceptions -fpermissive -fno-rtti -fno-threadsafe-statics -felide-constructors -Wno-error=narrowing -mthumb -mcpu=cortex-m7 -mfloat-abi=hard -mfpu=fpv5-d16 -D__IMXRT1062__ -DTEENSYDUINO=157 -DARDUINO=10819 -DARDUINO_TEENSY40 -DF_CPU=600000000 -DUSB_RAWHID -DLAYOUT_US_ENGLISH "-IR:\\Temp\\arduino_build_409939/pch" "-IC:\\Users\\Tim\\AppData\\Local\\Arduino15\\packages\\teensy\\hardware\\avr\\1.56.1\\cores\\teensy4" "R:\\Temp\\arduino_build_409939\\sketch\\Basic.pde.cpp" -o "R:\\Temp\\arduino_build_409939\\sketch\\Basic.pde.cpp.o"
    Compiling libraries...
    Compiling core...
    Using precompiled core: R:\Temp\arduino_cache_46238\core\core_71bdbba68a9a844d4d641f4fd86a3720.a
    Linking everything together...
    "C:\\Users\\Tim\\AppData\\Local\\Arduino15\\packages\\teensy\\tools\\teensy-compile\\1.56.1/arm/bin/arm-none-eabi-gcc" -O2 -Wl,--gc-sections,--relax "-TC:\\Users\\Tim\\AppData\\Local\\Arduino15\\packages\\teensy\\hardware\\avr\\1.56.1\\cores\\teensy4/imxrt1062.ld" -mthumb -mcpu=cortex-m7 -mfloat-abi=hard -mfpu=fpv5-d16 -o "R:\\Temp\\arduino_build_409939/Basic.pde.elf" "R:\\Temp\\arduino_build_409939\\sketch\\Basic.pde.cpp.o" "R:\\Temp\\arduino_build_409939/..\\arduino_cache_46238\\core\\core_71bdbba68a9a844d4d641f4fd86a3720.a" "-LR:\\Temp\\arduino_build_409939" -larm_cortexM7lfsp_math -lm -lstdc++
    "C:\\Users\\Tim\\AppData\\Local\\Arduino15\\packages\\teensy\\tools\\teensy-compile\\1.56.1/arm/bin/arm-none-eabi-objcopy" -O ihex -j .eeprom --set-section-flags=.eeprom=alloc,load --no-change-warnings --change-section-lma .eeprom=0 "R:\\Temp\\arduino_build_409939/Basic.pde.elf" "R:\\Temp\\arduino_build_409939/Basic.pde.eep"
    "C:\\Users\\Tim\\AppData\\Local\\Arduino15\\packages\\teensy\\tools\\teensy-compile\\1.56.1/arm/bin/arm-none-eabi-objcopy" -O ihex -R .eeprom "R:\\Temp\\arduino_build_409939/Basic.pde.elf" "R:\\Temp\\arduino_build_409939/Basic.pde.hex"
    "C:\\Users\\Tim\\AppData\\Local\\Arduino15\\packages\\teensy\\tools\\teensy-tools\\1.56.1/teensy_secure" encrypthex TEENSY40 "R:\\Temp\\arduino_build_409939/Basic.pde.hex"
    encrypting 13312 bytes to R:\Temp\arduino_build_409939/Basic.pde.ehex
    "C:\\Users\\Tim\\AppData\\Local\\Arduino15\\packages\\teensy\\tools\\teensy-tools\\1.56.1/teensy_post_compile" -file=Basic.pde "-path=R:\\Temp\\arduino_build_409939" "-tools=C:\\Users\\Tim\\AppData\\Local\\Arduino15\\packages\\teensy\\tools\\teensy-tools\\1.56.1/" -board=TEENSY40
    "C:\\Users\\Tim\\AppData\\Local\\Arduino15\\packages\\teensy\\tools\\teensy-tools\\1.56.1/stdout_redirect" "R:\\Temp\\arduino_build_409939/Basic.pde.sym" "C:\\Users\\Tim\\AppData\\Local\\Arduino15\\packages\\teensy\\tools\\teensy-compile\\1.56.1/arm/bin/arm-none-eabi-objdump" -t -C "R:\\Temp\\arduino_build_409939/Basic.pde.elf"
    "C:\\Users\\Tim\\AppData\\Local\\Arduino15\\packages\\teensy\\tools\\teensy-tools\\1.56.1/teensy_size" "R:\\Temp\\arduino_build_409939/Basic.pde.elf"
    Memory Usage on Teensy 4.0:
      FLASH: code:10152, data:2984, headers:8364   free for files:2010116
       RAM1: variables:4064, code:8448, padding:24320   free for local variables:487456
       RAM2: variables:1632  free for malloc/new:522656

  4. #4
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    26,573
    The message "To make a USB RawHID device, use the Tools > USB Type menu" means click this in Arduino.

    Click image for larger version. 

Name:	capture.png 
Views:	13 
Size:	136.9 KB 
ID:	27893

Posting Permissions

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