Hello
I am working on a button box using the Adafruit Feather nRF52840 Express. I have designed my wiring as follows:
And have (as many do) created my code through Youtube and good old faithful copy & paste. I am using the Arduino IDE. My code is currently as follows:
#include <Adafruit_TinyUSB.h>
#include "tusb.h" // For HID key definitions
// Row and column pin definitions
const uint8_t rowPins[4] = {2, 3, 4, 5};
const uint8_t colPins[4] = {8, 9, 10, 11};
// Map matrix positions to HID keycodes
const uint8_t keyMap[4][4] = {
{HID_KEY_A, HID_KEY_B, HID_KEY_C, HID_KEY_D},
{HID_KEY_E, HID_KEY_F, HID_KEY_G, HID_KEY_H},
{HID_KEY_I, HID_KEY_J, HID_KEY_K, HID_KEY_L},
{HID_KEY_M, HID_KEY_N, 0, 0 }
};
// LEDs for buttons 10β14 (indices 9β13)
const uint8_t ledPins[5] = {A1, A2, A3, A4, A5};
const uint8_t ledButtonIndices[5] = {9, 10, 11, 12, 13};
// Track debounce and state
bool buttonState[14] = {false};
bool lastButtonState[14] = {false};
uint32_t lastDebounceTime[14] = {0};
const uint32_t debounceDelay = 50;
Adafruit_USBD_HID usb_hid;
// HID report struct
typedef struct {
uint8_t modifier;
uint8_t reserved;
uint8_t keycode[6];
} keyboard_report_t;
keyboard_report_t report = { 0, 0, {0} };
void setup() {
for (uint8_t i = 0; i < 4; i++) {
pinMode(rowPins<em>, OUTPUT);
pinMode(colPins<em>, INPUT_PULLUP);
}
for (uint8_t i = 0; i < 5; i++) {
pinMode(ledPins<em>, OUTPUT);
digitalWrite(ledPins<em>, LOW);
}
usb_hid.begin();
delay(500); // Ensure USB ready
}
void loop() {
for (uint8_t row = 0; row < 4; row++) {
for (uint8_t r = 0; r < 4; r++) {
digitalWrite(rowPins[r], r == row ? LOW : HIGH);
}
delayMicroseconds(10);
for (uint8_t col = 0; col < 4; col++) {
uint8_t keycode = keyMap[row][col];
if (keycode == 0) continue;
uint8_t keyIndex = row * 4 + col;
bool reading = !digitalRead(colPins[col]);
if (reading != lastButtonState[keyIndex]) {
lastDebounceTime[keyIndex] = millis();
}
if ((millis() - lastDebounceTime[keyIndex]) > debounceDelay) {
if (reading != buttonState[keyIndex]) {
buttonState[keyIndex] = reading;
if (reading) {
sendKeyPress(keycode);
if (keyIndex == 0) {
delay(1000); // Hold key A for 1 second
}
// Turn on LED if applicable
for (uint8_t i = 0; i < 5; i++) {
if (keyIndex == ledButtonIndices<em>) {
digitalWrite(ledPins<em>, HIGH);
}
}
if (keyIndex != 0) sendKeyRelease(); // keyIndex 0 already released after delay
} else {
sendKeyRelease();
for (uint8_t i = 0; i < 5; i++) {
if (keyIndex == ledButtonIndices<em>) {
digitalWrite(ledPins<em>, LOW);
}
}
}
}
}
lastButtonState[keyIndex] = reading;
}
}
}
void sendKeyPress(uint8_t keycode) {
report.modifier = 0;
report.keycode[0] = keycode;
for (int i = 1; i < 6; i++) report.keycode <em>= 0;
usb_hid.sendReport(0, &report, sizeof(report));
}
void sendKeyRelease() {
for (int i = 0; i < 6; i++) report.keycode <em>= 0;
report.modifier = 0;
usb_hid.sendReport(0, &report, sizeof(report));
}
While my code still needs some refining for my use case, I believe it should compile.
The issue I have is that when I run the Verify command on my code (the board has not arrived yet), I get the following error message:
=====Error Message Start=====
Traceback (most recent call last):
File "main.py", line 317, in
File "click/core.py", line 1134, in call
File "click/core.py", line 1040, in main
File "click/_unicodefun.py", line 100, in _verify_python_env
RuntimeError: Click will abort further execution because Python was configured to use ASCII as encoding for the environment. Consult Unicode Support β Click Documentation (8.1.x) for mitigation steps.
This system lists some UTF-8 supporting locales that you can pick from. The following suitable locales were discovered: af_ZA.UTF-8, am_ET.UTF-8, be_BY.UTF-8, bg_BG.UTF-8, ca_ES.UTF-8, cs_CZ.UTF-8, da_DK.UTF-8, de_AT.UTF-8, de_CH.UTF-8, de_DE.UTF-8, el_GR.UTF-8, en_AU.UTF-8, en_CA.UTF-8, en_GB.UTF-8, en_IE.UTF-8, en_NZ.UTF-8, en_US.UTF-8, es_ES.UTF-8, et_EE.UTF-8, eu_ES.UTF-8, fi_FI.UTF-8, fr_BE.UTF-8, fr_CA.UTF-8, fr_CH.UTF-8, fr_FR.UTF-8, he_IL.UTF-8, hr_HR.UTF-8, hu_HU.UTF-8, hy_AM.UTF-8, is_IS.UTF-8, it_CH.UTF-8, it_IT.UTF-8, ja_JP.UTF-8, kk_KZ.UTF-8, ko_KR.UTF-8, lt_LT.UTF-8, nl_BE.UTF-8, nl_NL.UTF-8, no_NO.UTF-8, pl_PL.UTF-8, pt_BR.UTF-8, pt_PT.UTF-8, ro_RO.UTF-8, ru_RU.UTF-8, sk_SK.UTF-8, sl_SI.UTF-8, sr_YU.UTF-8, sv_SE.UTF-8, tr_TR.UTF-8, uk_UA.UTF-8, zh_CN.UTF-8, zh_HK.UTF-8, zh_TW.UTF-8
[83167] Failed to execute script main
exit status 1
Compilation error: exit status 1
=====Error Message Finish=====
I have researched the issue online and have in theory updated the locale settings as appears to be the issue. When I now run locale command in Terminal, I see the following which appear sto show several of the supported locales as per the error message.
=====locale command output Start=====
LANG="en_GB.UTF-8"
LC_COLLATE="en_GB.UTF-8"
LC_CTYPE="en_GB.UTF-8"
LC_MESSAGES="en_GB.UTF-8"
LC_MONETARY="en_GB.UTF-8"
LC_NUMERIC="en_GB.UTF-8"
LC_TIME="en_GBUTF-8"
LC_ALL="en_GB.UTF-8"
======locale command output Finish
Reading the error message, it appears to show an issue with a file called click.py which I assume is something to do with the Python environment on my computer.
As I have never installed Python, am I correct in thinking that it will have been installed when installing the Arduino IDE?
How do I fix the class.py?
I am lost... any suggestions on how to reoslve this issue would be much appreciated. According to ChatGPT, the issue is not my code and more likely an issue in my system's Python setup, but I have no idea!
UPDATE:
I connected an UNO board and it is seen and works as expected with the basic sketches. Compiles and uploads as it should.
M1 Mac Studio
macOS Sequoia 15.3.2