Posted on Leave a comment

How to unbrick / recover an ATTINY13a

I’ve been scratching my head all night trying to program a few ATTINY13a with Arduino. I just can’t upload code or burn bootloader. It used to work just fine but it seems when I tried burning the bootloader with a 128khz internal osc that’s when it stopped working. No matter what I do I just can’t get Arduino to do anything. I found out later the next day that you can actually reset it to its factory setting using a USBasp programmer.

Here’s how to unbrick or recover your ATTINY13a using USBasp

Step 1: Connect the USBasp programmer to the attiny13a.

Step 2: In Windows, open up cmd and use the following command:

avrdude -Cavrdude.conf -c USBasp -p t13 -e -Uhfuse:w:0xFF:m -Ulfuse:w:0x6A:m -B250

Now, you can use Arduino IDE again to upload code or burn bootloader again.

Posted on 21 Comments

How To Program The Pro Micro (atmega32u4) As A USB Gamepad Controller With Arduino

This tutorial should work on any Arduino Leonardo compatible board like the Sparkfun Pro Micro and the most popular Arduino Pro Micro compatible board. They’re all the same.

Let’s Get Started (Microsoft Windows):

    1. First, download and install the latest Arduino IDE at https://www.arduino.cc/en/Main/Software.
    2. Run the software, create a new file, copy and paste the code from https://www.tinkerboy.xyz/arduino-usb-gamepad/.
    3. Now let’s install the Arduino Joystick Library. Download the library. On Arduino IDE, click on Sketch > Include Library > Add .ZIP Library…, browse to the zip file you downloaded and click Open. A message should appear at the bottom telling you that “Library added to your libraries. Check “Include library” menu“.
    4. Plugin in the Pro Micro with a micro usb data cable and let Windows install the device. Take note of the COM port number used by the device (COM9 in this example).
    5. Now on Arduino IDE, click on Tools > Board > Arduino Leonardo.
    6. Click on Tools again, choose Port and the port used by your Pro Micro.
    7. Finally, click the Upload button or press CTR + U to flash/program the Pro Micro. You should see “Done uploading.” at the bottom if it’s successful.

Here’s how to enable Analog Stick support.

Comment below if this tutorial works for you or not.

Products you might be interested with:

Posted on 15 Comments

Arduino: USB Gamepad

/*
 * tinkerBOY's usb_gamepad v1.0
 * 
 */

#include <Joystick.h>

#define PINS 14
#define ENABLE_ANALOG1 false
int X1 = A0;
int Y1 = A1;

Joystick_ Joystick(JOYSTICK_DEFAULT_REPORT_ID, JOYSTICK_TYPE_GAMEPAD, PINS, 0, 
  true, true, false, false, false, false, false, false, false, false, false);

class CButton {
  public:
  int pin = NULL;
  int lastState = 0;
  
  CButton(int p) {
    pin = p;
  }
};

CButton Buttons[PINS] ={0,1,2,3,4,5,6,7,8,9,10,16,14,15};

void setup() {
  for(int i=0 ; i<PINS ;i++) {
    pinMode(Buttons[i].pin, INPUT_PULLUP);
  }

  Joystick.begin();
  if (ENABLE_ANALOG1) {
    Joystick.setXAxisRange(-512, 512);
    Joystick.setYAxisRange(-512, 512);
  }
}

void JButtonStates() {
  if (ENABLE_ANALOG1) {
    Joystick.setXAxis(analogRead(X1) - 512);
    Joystick.setYAxis(analogRead(Y1) - 512);
  }
  
  for (int i = 0; i < PINS; i++) {
    int currentState = !digitalRead(Buttons[i].pin);
    
    if (currentState != Buttons[i].lastState) {
      Joystick.setButton(i, currentState);
      Buttons[i].lastState = currentState;
    }
  }  
}

void loop() {
  JButtonStates();
  delay(50);
}

6-Button version:

/*
 * tinkerBOY's usb_gamepad v1.0 - 6-Button version
 * 
 */
 
#include <Joystick.h>

#define PINS 16
#define ENABLE_ANALOG1 false
int X1 = A0;
int Y1 = A1;

Joystick_ Joystick(JOYSTICK_DEFAULT_REPORT_ID, JOYSTICK_TYPE_GAMEPAD, PINS, 0, 
  true, true, false, false, false, false, false, false, false, false, false);

class CButton {
  public:
  int pin = NULL;
  int lastState = 0;
  
  CButton(int p) {
    pin = p;
  }
};

CButton Buttons[PINS] ={0,1,2,3,4,5,6,7,8,9,10,16,14,15,20,21};

void setup() {
  for(int i=0 ; i<PINS ;i++) {
    pinMode(Buttons[i].pin, INPUT_PULLUP);
  }

  Joystick.begin();
  if (ENABLE_ANALOG1) {
    Joystick.setXAxisRange(-512, 512);
    Joystick.setYAxisRange(-512, 512);
  }
}

void JButtonStates() {
  if (ENABLE_ANALOG1) {
    Joystick.setXAxis(analogRead(X1) - 512);
    Joystick.setYAxis(analogRead(Y1) - 512);
  }
  
  for (int i = 0; i < PINS; i++) {
    int currentState = !digitalRead(Buttons[i].pin);
    
    if (currentState != Buttons[i].lastState) {
      Joystick.setButton(i, currentState);
      Buttons[i].lastState = currentState;
    }
  }  
}

void loop() {
  JButtonStates();
  delay(50);
}