В какой-то момент у меня возникло желание поэксперементировать с платой Ruspberry pi pico 2040, ревизии YD-RP2040.
Спустя некоторое количество почёсываний головы, решил, что хочу сделать автоматический ввод нескольких горячих клавишь и начал искать как это сделать. Оказалось, что стандартная библиотека Keyboard, на малинке не работает. Спустя некоторое время, было найдено другое решение:
https://github.com/arduino/ArduinoCore-mbed/issues/252
Спустя пару штрихов, получился нормальный, рабочий код:
#include "PluggableUSBHID.h"
#include "USBKeyboard.h"
USBKeyboard Keyboard;
void setup() {
pinMode(24, INPUT_PULLUP);
Keyboard.rewind();
}
void loop() {
if (digitalRead(24) == LOW) {
//Send the message
Keyboard.printf("Hello!");
delay(1000);
}
}
Появилась надежда сделать задуманное, но она оборвалась, после нескольких попыток и непонимания, что делать:
#include "PluggableUSBHID.h"
#include "USBKeyboard.h"
USBKeyboard Keyboard;
void setup() {
// put your setup code here, to run once:
pinMode(24, INPUT_PULLUP);
// initialize control over the keyboard:
Keyboard.rewind();
}
void loop() {
// put your main code here, to run repeatedly:
while (digitalRead(24) == HIGH) {
// do nothing until pin 24 goes low
delay(500);
}
delay(1000);
// new document:
Keyboard.press(KEY_LEFT_CTRL);
Keyboard.press('n');
delay(100);
Keyboard.releaseAll();
// wait for new window to open:
delay(1000);
}
Вывод командной строки:
Detecting libraries used...
"...\hardware\mbed_rp2040\4.1.5\variants\RASPBERRY_PI_PICO/defines.txt" "@...\hardware\mbed_rp2040\4.1.5\variants\RASPBERRY_PI_PICO/cxxflags.txt" -DARDUINO_ARCH_RP2040 -mcpu=cortex-m0plus -w -x c++ -E -CC -DARDUINO=10819 -DARDUINO_RASPBERRY_PI_PICO -DARDUINO_ARCH_MBED_RP2040 -DARDUINO_ARCH_MBED -DARDUINO_LIBRARY_DISCOVERY_PHASE=1 "-I...\hardware\mbed_rp2040\4.1.5\cores\arduino" "-I...\hardware\mbed_rp2040\4.1.5\variants\RASPBERRY_PI_PICO" "-I...\hardware\mbed_rp2040\4.1.5\cores\arduino/api/deprecated" "-I...\hardware\mbed_rp2040\4.1.5\cores\arduino/api/deprecated-avr-comp" "-iprefix...\hardware\mbed_rp2040\4.1.5\cores\arduino" "@...\hardware\mbed_rp2040\4.1.5\variants\RASPBERRY_PI_PICO/includes.txt" "C:\Users\User_123\AppData\Local\Temp\arduino_build_151887\sketch\sketch_sep15b.ino.cpp" -o nul
Alternatives for PluggableUSBHID.h: [USBHID@1.0]
ResolveLibrary(PluggableUSBHID.h)
-> candidates: [USBHID@1.0]
"...\hardware\mbed_rp2040\4.1.5\variants\RASPBERRY_PI_PICO/defines.txt" "@...\hardware\mbed_rp2040\4.1.5\variants\RASPBERRY_PI_PICO/cxxflags.txt" -DARDUINO_ARCH_RP2040 -mcpu=cortex-m0plus -w -x c++ -E -CC -DARDUINO=10819 -DARDUINO_RASPBERRY_PI_PICO -DARDUINO_ARCH_MBED_RP2040 -DARDUINO_ARCH_MBED -DARDUINO_LIBRARY_DISCOVERY_PHASE=1 "-I...\hardware\mbed_rp2040\4.1.5\cores\arduino" "-I...\hardware\mbed_rp2040\4.1.5\variants\RASPBERRY_PI_PICO" "-I...\hardware\mbed_rp2040\4.1.5\libraries\USBHID\src" "-I...\hardware\mbed_rp2040\4.1.5\cores\arduino/api/deprecated" "-I...\hardware\mbed_rp2040\4.1.5\cores\arduino/api/deprecated-avr-comp" "-iprefix...\hardware\mbed_rp2040\4.1.5\cores\arduino" "@...\hardware\mbed_rp2040\4.1.5\variants\RASPBERRY_PI_PICO/includes.txt" "C:\Users\User_123\AppData\Local\Temp\arduino_build_151887\sketch\sketch_sep15b.ino.cpp" -o nul
"...\hardware\mbed_rp2040\4.1.5\variants\RASPBERRY_PI_PICO/defines.txt" "@...\hardware\mbed_rp2040\4.1.5\variants\RASPBERRY_PI_PICO/cxxflags.txt" -DARDUINO_ARCH_RP2040 -mcpu=cortex-m0plus -w -x c++ -E -CC -DARDUINO=10819 -DARDUINO_RASPBERRY_PI_PICO -DARDUINO_ARCH_MBED_RP2040 -DARDUINO_ARCH_MBED -DARDUINO_LIBRARY_DISCOVERY_PHASE=1 "-I...\hardware\mbed_rp2040\4.1.5\cores\arduino" "-I...\hardware\mbed_rp2040\4.1.5\variants\RASPBERRY_PI_PICO" "-I...\hardware\mbed_rp2040\4.1.5\libraries\USBHID\src" "-I...\hardware\mbed_rp2040\4.1.5\cores\arduino/api/deprecated" "-I...\hardware\mbed_rp2040\4.1.5\cores\arduino/api/deprecated-avr-comp" "-iprefix...\hardware\mbed_rp2040\4.1.5\cores\arduino" "@...\hardware\mbed_rp2040\4.1.5\variants\RASPBERRY_PI_PICO/includes.txt" "...\hardware\mbed_rp2040\4.1.5\libraries\USBHID\src\USBHID.cpp" -o nul
"...\hardware\mbed_rp2040\4.1.5\variants\RASPBERRY_PI_PICO/defines.txt" "@...\hardware\mbed_rp2040\4.1.5\variants\RASPBERRY_PI_PICO/cxxflags.txt" -DARDUINO_ARCH_RP2040 -mcpu=cortex-m0plus -w -x c++ -E -CC -DARDUINO=10819 -DARDUINO_RASPBERRY_PI_PICO -DARDUINO_ARCH_MBED_RP2040 -DARDUINO_ARCH_MBED -DARDUINO_LIBRARY_DISCOVERY_PHASE=1 "-I...\hardware\mbed_rp2040\4.1.5\cores\arduino" "-I...\hardware\mbed_rp2040\4.1.5\variants\RASPBERRY_PI_PICO" "-I...\hardware\mbed_rp2040\4.1.5\libraries\USBHID\src" "-I...\hardware\mbed_rp2040\4.1.5\cores\arduino/api/deprecated" "-I...\hardware\mbed_rp2040\4.1.5\cores\arduino/api/deprecated-avr-comp" "-iprefix...\hardware\mbed_rp2040\4.1.5\cores\arduino" "@...\hardware\mbed_rp2040\4.1.5\variants\RASPBERRY_PI_PICO/includes.txt" "...\hardware\mbed_rp2040\4.1.5\libraries\USBHID\src\USBKeyboard.cpp" -o nul
"...\hardware\mbed_rp2040\4.1.5\variants\RASPBERRY_PI_PICO/defines.txt" "@...\hardware\mbed_rp2040\4.1.5\variants\RASPBERRY_PI_PICO/cxxflags.txt" -DARDUINO_ARCH_RP2040 -mcpu=cortex-m0plus -w -x c++ -E -CC -DARDUINO=10819 -DARDUINO_RASPBERRY_PI_PICO -DARDUINO_ARCH_MBED_RP2040 -DARDUINO_ARCH_MBED -DARDUINO_LIBRARY_DISCOVERY_PHASE=1 "-I...\hardware\mbed_rp2040\4.1.5\cores\arduino" "-I...\hardware\mbed_rp2040\4.1.5\variants\RASPBERRY_PI_PICO" "-I...\hardware\mbed_rp2040\4.1.5\libraries\USBHID\src" "-I...\hardware\mbed_rp2040\4.1.5\cores\arduino/api/deprecated" "-I...\hardware\mbed_rp2040\4.1.5\cores\arduino/api/deprecated-avr-comp" "-iprefix...\hardware\mbed_rp2040\4.1.5\cores\arduino" "@...\hardware\mbed_rp2040\4.1.5\variants\RASPBERRY_PI_PICO/includes.txt" "...\hardware\mbed_rp2040\4.1.5\libraries\USBHID\src\USBMouse.cpp" -o nul
"...\hardware\mbed_rp2040\4.1.5\variants\RASPBERRY_PI_PICO/defines.txt" "@...\hardware\mbed_rp2040\4.1.5\variants\RASPBERRY_PI_PICO/cxxflags.txt" -DARDUINO_ARCH_RP2040 -mcpu=cortex-m0plus -w -x c++ -E -CC -DARDUINO=10819 -DARDUINO_RASPBERRY_PI_PICO -DARDUINO_ARCH_MBED_RP2040 -DARDUINO_ARCH_MBED -DARDUINO_LIBRARY_DISCOVERY_PHASE=1 "-I...\hardware\mbed_rp2040\4.1.5\cores\arduino" "-I...\hardware\mbed_rp2040\4.1.5\variants\RASPBERRY_PI_PICO" "-I...\hardware\mbed_rp2040\4.1.5\libraries\USBHID\src" "-I...\hardware\mbed_rp2040\4.1.5\cores\arduino/api/deprecated" "-I...\hardware\mbed_rp2040\4.1.5\cores\arduino/api/deprecated-avr-comp" "-iprefix...\hardware\mbed_rp2040\4.1.5\cores\arduino" "@...\hardware\mbed_rp2040\4.1.5\variants\RASPBERRY_PI_PICO/includes.txt" "...\hardware\mbed_rp2040\4.1.5\libraries\USBHID\src\USBMouseKeyboard.cpp" -o nul
Generating function prototypes...
"...\hardware\mbed_rp2040\4.1.5\variants\RASPBERRY_PI_PICO/defines.txt" "@...\hardware\mbed_rp2040\4.1.5\variants\RASPBERRY_PI_PICO/cxxflags.txt" -DARDUINO_ARCH_RP2040 -mcpu=cortex-m0plus -w -x c++ -E -CC -DARDUINO=10819 -DARDUINO_RASPBERRY_PI_PICO -DARDUINO_ARCH_MBED_RP2040 -DARDUINO_ARCH_MBED -DARDUINO_LIBRARY_DISCOVERY_PHASE=1 "-I...\hardware\mbed_rp2040\4.1.5\cores\arduino" "-I...\hardware\mbed_rp2040\4.1.5\variants\RASPBERRY_PI_PICO" "-I...\hardware\mbed_rp2040\4.1.5\libraries\USBHID\src" "-I...\hardware\mbed_rp2040\4.1.5\cores\arduino/api/deprecated" "-I...\hardware\mbed_rp2040\4.1.5\cores\arduino/api/deprecated-avr-comp" "-iprefix...\hardware\mbed_rp2040\4.1.5\cores\arduino" "@...\hardware\mbed_rp2040\4.1.5\variants\RASPBERRY_PI_PICO/includes.txt" "C:\Users\User_123\AppData\Local\Temp\arduino_build_151887\sketch\sketch_sep15b.ino.cpp" -o "C:\Users\User_123\AppData\Local\Temp\arduino_build_151887\preproc\ctags_target_for_gcc_minus_e.cpp"
"C:\Program Files\WindowsApps\ArduinoLLC.ArduinoIDE_1.8.57.0_x86__mdqgnx93n4wtt\tools-builder\ctags\5.8-arduino11/ctags" -u --language-force=c++ -f - --c++-kinds=svpf --fields=KSTtzns --line-directives "C:\Users\User_123\AppData\Local\Temp\arduino_build_151887\preproc\ctags_target_for_gcc_minus_e.cpp"
Компиляция скетча...
"...\hardware\mbed_rp2040\4.1.5\variants\RASPBERRY_PI_PICO/defines.txt" "@...\hardware\mbed_rp2040\4.1.5\variants\RASPBERRY_PI_PICO/cxxflags.txt" -DARDUINO_ARCH_RP2040 -MMD -mcpu=cortex-m0plus -DARDUINO=10819 -DARDUINO_RASPBERRY_PI_PICO -DARDUINO_ARCH_MBED_RP2040 -DARDUINO_ARCH_MBED -DARDUINO_LIBRARY_DISCOVERY_PHASE=0 "-I...\hardware\mbed_rp2040\4.1.5\cores\arduino" "-I...\hardware\mbed_rp2040\4.1.5\variants\RASPBERRY_PI_PICO" "-I...\hardware\mbed_rp2040\4.1.5\libraries\USBHID\src" "-I...\hardware\mbed_rp2040\4.1.5\cores\arduino/api/deprecated" "-I...\hardware\mbed_rp2040\4.1.5\cores\arduino/api/deprecated-avr-comp" "-iprefix...\hardware\mbed_rp2040\4.1.5\cores\arduino" "@...\hardware\mbed_rp2040\4.1.5\variants\RASPBERRY_PI_PICO/includes.txt" "C:\Users\User_123\AppData\Local\Temp\arduino_build_151887\sketch\sketch_sep15b.ino.cpp" -o "C:\Users\User_123\AppData\Local\Temp\arduino_build_151887\sketch\sketch_sep15b.ino.cpp.o"
C:\Users\User_123\Documents\sketch_sep15b\sketch_sep15b.ino: In function 'void loop()':
sketch_sep15b:21:12: error: 'class arduino::USBKeyboard' has no member named 'press'
Keyboard.press(KEY_LEFT_CTRL);
^~~~~
sketch_sep15b:21:18: error: 'KEY_LEFT_CTRL' was not declared in this scope
Keyboard.press(KEY_LEFT_CTRL);
^~~~~~~~~~~~~
sketch_sep15b:22:12: error: 'class arduino::USBKeyboard' has no member named 'press'
Keyboard.press('n');
^~~~~
sketch_sep15b:24:12: error: 'class arduino::USBKeyboard' has no member named 'releaseAll'
Keyboard.releaseAll();
^~~~~~~~~~
Используем библиотеку USBHID версии 1.0 из папки: ...\hardware\mbed_rp2040\4.1.5\libraries\USBHID
exit status 1
'class arduino::USBKeyboard' has no member named 'press'
Можете подсказать, какие команды может выполнять класс USBKeyboard?