Can someone help me? I can’t manage to use the USB host function with the Arduino framework in PlatformIO for the Blues Swan v3. I’ve tried everything, from generating a library with STM32CubeMX to implementing other libraries. I just want to use the micro USB on the Blues Swan to connect a USB keyboard. Or any alternative on how to connect a computer keyboard. I’m programming via ST-Link.
Hi @pedrogmnz,
Are you wanting to use a USB keyboard as an input device? If so, I found this thread that may be helpful.
Rob
Hello, here again. My current setup with the Blues is using the Feather board, connected to a display over I2C with an Adafruit RA8875 controller and a PS2 adapter to test a PS2 keyboard. I’ve tried this code, but the character input isn’t working, and nothing appears on the screen. I’ve checked everything. I’m also attaching a rough sketch of the current connections. I’m programming with PlatformIO using the Arduino framework. I’m also attaching my configuration for the platformio.ini
file.
platformio.ini
:
; PlatformIO Project Configuration File
;
; Build options: build flags, source filter
; Upload options: custom upload port, speed and extra flags
; Library options: dependencies, extra library storages
; Advanced options: extra scripting
;
; Please visit documentation for the other options and examples
; https://docs.platformio.org/page/projectconf.html
[env:bw_swan_r5]
platform = ststm32
board = bw_swan_r5
framework = arduino
monitor_port = COM3
monitor_speed = 115200
upload_protocol = stlink
lib_extra_dirs =
lib_deps =
Wire
blues/Blues Wireless Notecard@^1.6.0
adafruit/Adafruit GFX Library@^1.11.11
adafruit/Adafruit RA8875@^1.4.4
adafruit/Adafruit BusIO
main.cpp:
#include <SPI.h>
#include <Adafruit_GFX.h>
#include <Adafruit_RA8875.h>
// Pines para RA8875
#define RA8875_CS D11 // Chip Select
#define RA8875_RST D2 // Reset
// Pines para el teclado PS/2
#define CLOCK_PIN D6 // Pin de reloj del teclado
#define DATA_PIN D7 // Pin de datos del teclado
// Configuración de la pantalla
Adafruit_RA8875 tft = Adafruit_RA8875(RA8875_CS, RA8875_RST);
// Mapa de teclas simplificado (para probar)
const char keymap[] = {
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, '`', 0,
'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p',
'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '1', '2', '3', '4', '5', '6',
'7', '8', '9', '0', '-', '=', '[', ']', ';', '\'', ',', '.', '/', '\\', ' ', '\n'};
volatile uint8_t lastScanCode = 0;
volatile bool newKeyAvailable = false;
uint8_t line = 0, col = 0; // Posición en pantalla
// Prototipos de funciones
void handleClockInterrupt();
void drawCursor(bool erase = false);
void setup()
{
Serial.begin(115200);
delay(2000);
Serial.println("Iniciando...");
// Inicialización de la pantalla RA8875
if (!tft.begin(RA8875_800x480))
{
Serial.println("Error en RA8875.");
while (1)
;
}
tft.displayOn(true);
tft.GPIOX(true);
tft.PWM1config(true, RA8875_PWM_CLK_DIV1024);
tft.PWM1out(255);
tft.fillScreen(RA8875_BLACK);
tft.setTextColor(RA8875_WHITE);
tft.setTextSize(2);
Serial.println("Pantalla inicializada.");
// Configuración del teclado PS/2
pinMode(CLOCK_PIN, INPUT_PULLUP);
pinMode(DATA_PIN, INPUT_PULLUP);
attachInterrupt(digitalPinToInterrupt(CLOCK_PIN), handleClockInterrupt, FALLING);
Serial.println("Esperando entrada del teclado...");
drawCursor(); // Dibuja el cursor inicial
}
// Función de interrupción para leer datos del teclado
void handleClockInterrupt()
{
static uint8_t bitCount = 0;
static uint8_t scanCode = 0;
bool dataBit = digitalRead(DATA_PIN);
scanCode |= dataBit << bitCount;
bitCount++;
if (bitCount == 8)
{
lastScanCode = scanCode;
newKeyAvailable = true;
bitCount = 0;
scanCode = 0;
}
}
// Dibuja el cursor en pantalla
void drawCursor(bool erase)
{
tft.textSetCursor(col * 12, line * 24);
if (erase)
{
tft.textWrite(" "); // Borra el cursor
}
else
{
tft.textWrite("_"); // Dibuja el cursor
}
}
void loop()
{
if (newKeyAvailable)
{
newKeyAvailable = false;
char key = keymap[lastScanCode];
// Borra el cursor antes de mostrar el nuevo carácter
drawCursor(true);
if (lastScanCode == 0x5A)
{ // Enter
col = 0;
line = (line + 1) % 4;
}
else if (lastScanCode == 0x66)
{ // Backspace
if (col > 0)
col--;
tft.textSetCursor(col * 12, line * 24);
tft.textWrite(" ");
}
else if (key != 0)
{
tft.textSetCursor(col * 12, line * 24);
tft.textWrite(String(key).c_str());
col++;
if (col > 19)
{
col = 0;
line = (line + 1) % 4;
}
}
drawCursor(); // Redibuja el cursor
Serial.print("Tecla presionada: ");
Serial.println(key);
}
}
I’m not sure if this will help, but I did some work with a FeatherWing keyboard in this project on Hackster: Two-Way Satellite Messaging with Blues Starnote - Hackster.io
There may be some keyboard-related tidbits in here that can help?