Pro micro not recognized after upload

Hey everyone. I know newbies are super annoying so I will do my best to get right to it and provide as much info as I can. The short version is, that I have built a small keyboard using a tutorial and since I like understanding all the elements of a build, I want to understand why this last step fails.

Board: SparkFun Pro Micro (ATMega 32U4) 3.3v
Software: Arduino IDE
OS: Windows 10

Code is at the end of this post.

My workflow:
I've added SparkFun to my IDE and I select SparkFun Pro Micro as my board and 3.3v as the processor. When connecting to Windows, it recognizes the board as arduino and I am able to upload to it. When I upload the code in the end of this post, the device disconnects and then reconnects but when it reconnects, windows does not recognize it as anything and tells me that it has no idea what the thing is. Now, the code is not mine but I see that other people have made it work so that leads me to think, that there's something I'm not doing right. Am I missing a step? I read the forum about resetting and besides from getting the timing right on the gnd+rst and uploading, I think I am doing that right. No matter how I try to upload, windows fails to recognize it as a keyboard after.

One thing I have thought about that it might be is that I have not wired anything to the board yet. It is completly empty. Could that cause the problem? If not - are there anything I'm missing?

Thank you for your help in advance!

#define BUTTON_KEY1 KEY_F13
#define BUTTON_KEY2 KEY_F14
#define BUTTON_KEY3 KEY_F15
#define BUTTON_KEY4 KEY_F16
#define BUTTON_KEY5 KEY_F17
#define BUTTON_KEY6 KEY_F18
#define BUTTON_KEY7 KEY_F19
#define BUTTON_KEY8 KEY_F20
#define BUTTON_KEY9 KEY_F21
#define BUTTON_KEY10 KEY_F22
#define BUTTON_KEY11 KEY_F23
#define BUTTON_KEY12 KEY_F24
 
#define BUTTON_PIN1 2
#define BUTTON_PIN2 3
#define BUTTON_PIN3 4
#define BUTTON_PIN4 5
#define BUTTON_PIN5 6
#define BUTTON_PIN6 7
#define BUTTON_PIN7 8
#define BUTTON_PIN8 9
#define BUTTON_PIN9 10
#define BUTTON_PIN10 16
#define BUTTON_PIN11 14
#define BUTTON_PIN12 15
// ---------------------------------
 
#include "Keyboard.h"
 


class button {
  public:
  const char key;
  const uint8_t pin;
 
  button(uint8_t k, uint8_t p) : key(k), pin(p){}
 
  void press(boolean state){
    if(state == pressed || (millis() - lastPressed  <= debounceTime)){
      return; // Nothing to see here, folks
    }
 
    lastPressed = millis();
 
    state ? Keyboard.press(key) : Keyboard.release(key);    
    pressed = state;
  }
 
  void update(){
    press(!digitalRead(pin));
  }
 
  private:
  const long debounceTime = 30;
  unsigned long lastPressed;
  boolean pressed = 0;
} ;
 
button buttons[] = {
  {BUTTON_KEY1, BUTTON_PIN1},
  {BUTTON_KEY2, BUTTON_PIN2},
  {BUTTON_KEY3, BUTTON_PIN3},
  {BUTTON_KEY4, BUTTON_PIN4},
  {BUTTON_KEY5, BUTTON_PIN5},
  {BUTTON_KEY6, BUTTON_PIN6},
  {BUTTON_KEY7, BUTTON_PIN7},
  {BUTTON_KEY8, BUTTON_PIN8},
  {BUTTON_KEY9, BUTTON_PIN9},
  {BUTTON_KEY10, BUTTON_PIN10},
  {BUTTON_KEY11, BUTTON_PIN11},
  {BUTTON_KEY12, BUTTON_PIN12},
};
 
const uint8_t NumButtons = sizeof(buttons) / sizeof(button);
const uint8_t ledPin = 17;
 
void setup() { 
  pinMode(1, INPUT_PULLUP);
  if(!digitalRead(1)){
    failsafe();
  }
 
  pinMode(ledPin, OUTPUT);
  digitalWrite(ledPin, HIGH);
  TXLED0;
 
  for(int i = 0; i < NumButtons; i++){
    pinMode(buttons[i].pin, INPUT_PULLUP);
  }
}
 
void loop() {
  for(int i = 0; i < NumButtons; i++){
    buttons[i].update();
  }
}
 
void failsafe(){
  for(;;){} 
}

If I understand you correctly, you can recover the board every time; that's great.

Have you tried an empty sketch that only includes Keyboard.h; below should show your ProMicro as a HID.

#include "Keyboard.h"

const uint8_t ledPin = 17;

void setup() {
}

void loop() {
}

My experience with using either TXled or RXled (can't remember) is that it interferes with uploads; I have no idea why and have not had time yet to analyse.

Thank you for replying! I have solved it but I decided to post what my problem was so that others in my shoes could perhaps learn from it :slight_smile:

After uploading the suggested script, the Arduino didn't work again so I decided to read some more. It took ages but I suddenly realized that my problem was even more basic; I had ordered the 3.3v version but this one came with a 16MHz processor and not an 8MHz as I was expecting. Thus, the only thing I had to do was to switch the processor in the Arduino software before upload and then everything worked perfectly.

Again, thank you sterretje for your suggestion!

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