Trouble with pi pico hid keyboard

I don't know if this is the right place. If it's not feel free to mock me as long as you point me in the right direction lol.

I'm programming a raspberry pi pico with the Arduino ide. The project is supposed to get a voltage from a battery, type the value into the device it's connected to via otg, and press return. This all happens when the user presses a button connected to the pico.

And it works, mostly. It operates exactly as I expect when plugged into 2 different PCs, and a Google pixel. The problem is the galaxy note 20.

When I try it on the galaxy it only types the first digit then stops. Repeated button presses get no response and it won't do anything till I've unplugged it and plugged it back in.

The ultimate goal of this project is to get it to work on the galaxy. It's a work phone and I'm trying to input data to our databases faster. Any help or ideas you can provide is greatly appreciated.

Have you tried a normal keyboard on the Galaxy Note?

How does your code send the simulated keystrokes?
Maybe it's going too fast for the Galaxy?

What "stops" - the phone, or the Pico?

If the Pico, what do you mean by "stops"?

Please post your code: see 'How to get the best out of this forum' - in particular, ' Posting code and common code problems'

sounds like a terrible kludge - surely there must be a better way?

1 Like

I didn't even think to try a real keyboard. Good idea, but a real keyboard works just fine.

When i said it stops, it just types one character and does nothing after that.

#include <Keyboard.h>
bool button_pushed = false;
const int BUTTON_PIN = 7;
unsigned long lastButtonPressTime = 0;  // to store the last time the button was pressed
const unsigned long debounceTime = 50;  // debounce time in milliseconds

void setup() {

  
  Serial.begin(9600); // Initialize serial communication
  pinMode(BUTTON_PIN, INPUT);
}

void loop() {
 
 
  float Vin = ((float)analogRead(26)/1024) * 3.3;
  int buttonState = digitalRead(BUTTON_PIN);
  unsigned long currentTime = millis();  // current time

if (buttonState == LOW) {
  button_pushed = false;
 }
 if (Vin < 0.01)
 {Vin=0.0;}
  // Print the voltage value to the serial monitor
 
 // Check if enough time has passed since the last recognized button press
  if (currentTime - lastButtonPressTime > debounceTime) {
  if (buttonState == HIGH && button_pushed == false) {
    Serial.print("Voltage: ");
    Serial.print(Vin , 3);
    Serial.println(" V");
    Keyboard.print(Vin , 3);
    Keyboard.press(KEY_RETURN);
    Keyboard.releaseAll();
    button_pushed = true;
  }
  if (buttonState == LOW) {
    button_pushed = false;  // Reset flag when button is released
  }

  

 
}
}


I tried it on a coworkers s10 and got a notification that this is a high demand usb device that the phone can't power.  I guess its possible my phone is too stupid to know it doesn't have the power?

Still not sure what you're referring to as "it" - the phone or the Pico?

Is it?

Surely, a Pico just emulating a keyboard shouldn't require much power at all?

1 Like

Update. I added external power to the circuit. Now I get the entire value typed and the cursor moves to the next cell but when I pres ins the button again I usually get no response. Sometimes it will work 2 or three times in a row then arop working. Again this is only on my galaxy note 20.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.