Page 1 of 1

using a sparkfun pro mini

Posted: Sat Oct 22, 2016 1:34 pm
by winnetouch
Well this isn't exactly arduino but it's close enough I think since it's arduino based.

I'm using a sparkfun pro mini arduino clone. I programmed it to act like a keyboard (I need it to act like a keyboard not like a controller) but I noticed thare is one problem using it like this. If I press any button and keep it pressed it doesn't register it like a continously pressed button. It treats it like a button being pressed multiple times in succession.

I am not a programmer I learn as I go (or just use code from other people).

The code I used is a modified code from the sparkfun keayboard example page (I haven't tweaked the the delay yet):

Code: Select all

#include <Keyboard.h>

int up = 1;  // Set a button to any pin
int down = 0;
int left = 2;
int right = 3;
int select = 4;
int start = 5;
int buttonY = 6;
int buttonX = 7;
int buttonB = 8;
int buttonA = 9;
int L1 = 10;
int R1 = 16;

void setup()
{
  pinMode(up, INPUT);  // Set the button as an input
  digitalWrite(up, HIGH);  // Pull the button high
  
  pinMode(down, INPUT);  // Set the button as an input
  digitalWrite(down, HIGH);  // Pull the button high

    pinMode(left, INPUT);  // Set the button as an input
  digitalWrite(left, HIGH);  // Pull the button high

    pinMode(right, INPUT);  // Set the button as an input
  digitalWrite(right, HIGH);  // Pull the button high

    pinMode(select, INPUT);  // Set the button as an input
  digitalWrite(select, HIGH);  // Pull the button high

    pinMode(start, INPUT);  // Set the button as an input
  digitalWrite(start, HIGH);  // Pull the button high

    pinMode(buttonY, INPUT);  // Set the button as an input
  digitalWrite(buttonY, HIGH);  // Pull the button high

      pinMode(buttonX, INPUT);  // Set the button as an input
  digitalWrite(buttonX, HIGH);  // Pull the button high

      pinMode(buttonB, INPUT);  // Set the button as an input
  digitalWrite(buttonB, HIGH);  // Pull the button high

      pinMode(buttonA, INPUT);  // Set the button as an input
  digitalWrite(buttonA, HIGH);  // Pull the button high

      pinMode(L1, INPUT);  // Set the button as an input
  digitalWrite(L1, HIGH);  // Pull the button high

      pinMode(R1, INPUT);  // Set the button as an input
  digitalWrite(R1, HIGH);  // Pull the button high
}

void loop()
{
  if (digitalRead(up) == 0)  // if the button goes low
  {
    Keyboard.write('w');  // send a 'z' to the computer via Keyboard HID
    delay(100);  // delay so there aren't a kajillion z's
  }
    if (digitalRead(down) == 0)  // if the button goes low
  {
    Keyboard.write('s');  // send a 'z' to the computer via Keyboard HID
    delay(100);  // delay so there aren't a kajillion z's
  }

      if (digitalRead(left) == 0)  // if the button goes low
  {
    Keyboard.write('a');  // send a 'z' to the computer via Keyboard HID
    delay(100);  // delay so there aren't a kajillion z's
  }

      if (digitalRead(right) == 0)  // if the button goes low
  {
    Keyboard.write('d');  // send a 'z' to the computer via Keyboard HID
    delay(100);  // delay so there aren't a kajillion z's
  }

      if (digitalRead(select) == 0)  // if the button goes low
  {
    Keyboard.write('.');  // send a 'z' to the computer via Keyboard HID
    delay(100);  // delay so there aren't a kajillion z's
  }

      if (digitalRead(start) == 0)  // if the button goes low
  {
    Keyboard.write('\n');  // send a 'z' to the computer via Keyboard HID
    delay(100);  // delay so there aren't a kajillion z's
  }

        if (digitalRead(buttonY) == 0)  // if the button goes low
  {
    Keyboard.write('y');  // send a 'z' to the computer via Keyboard HID
    delay(100);  // delay so there aren't a kajillion z's
  }

        if (digitalRead(buttonX) == 0)  // if the button goes low
  {
    Keyboard.write('x');  // send a 'z' to the computer via Keyboard HID
    delay(100);  // delay so there aren't a kajillion z's
  }

        if (digitalRead(buttonB) == 0)  // if the button goes low
  {
    Keyboard.write('c');  // send a 'z' to the computer via Keyboard HID
    delay(100);  // delay so there aren't a kajillion z's
  }

        if (digitalRead(buttonA) == 0)  // if the button goes low
  {
    Keyboard.write('v');  // send a 'z' to the computer via Keyboard HID
    delay(100);  // delay so there aren't a kajillion z's
  }

        if (digitalRead(L1) == 0)  // if the button goes low
  {
    Keyboard.write('q');  // send a 'z' to the computer via Keyboard HID
    delay(100);  // delay so there aren't a kajillion z's
  }

        if (digitalRead(R1) == 0)  // if the button goes low
  {
    Keyboard.write('e');  // send a 'z' to the computer via Keyboard HID
    delay(100);  // delay so there aren't a kajillion z's
  }
}


Re: using a sparkfun pro mini

Posted: Sun Oct 23, 2016 1:11 am
by TimBer
The problem you have is with keyboard.write

You should be using keyboard.press() and keyboard.release()
It should be using a buffer, allowing for a number of buttons to be pressed and send at a single time.

But if I understand correctly, this sparkfun pro mini uses an ATmega328 chipset. Correct?

If so, I'm wondering what keyboard library you are using, because the default one is using HID support, that is not supported by the ATmega328.

Perhaps you can use my post concerning an arduino nano as some information:
http://www.sudomod.com/forum/viewtopic.php?f=18&t=1605

But you should be sure it has the ATmega328 and not the ATmega32u4 (which has HID support)

If it is an ATmega32u4, perhaps you can get some information from the support threads from helder:
http://sudomod.com/forum/viewtopic.php?f=25&t=1228

He uploaded the code as well, just make sure you are using the same inputs or change them accordingly.

Re: using a sparkfun pro mini

Posted: Sun Oct 23, 2016 4:17 am
by winnetouch
No. It uses a ATmega32u4 chip. It's not really a sparkfun chip but rather a knock off I had from a previous project that went nowhere.

It's like this one:

http://www.ebay.com/itm/140972980117?_t ... EBIDX%3AIT

Also... I am a mac user... Helders post doesn't help much, also I don't really understand much of it to be honest :P

Re: using a sparkfun pro mini

Posted: Sun Oct 23, 2016 4:27 am
by TimBer
Ah...yes....A pro micro is using a Atmega32u4

You can easily program it setting the arduino development tool to use an "arduino leonardo"

Keep in mind the pro micro does not have digital pins 11,12,13

E.g. you could use the software from helder (just make sure to put the correct libraries in you arduino libraries folder).

Change the port init to something like this:

Code: Select all

void setup() {
     pinMode(0, INPUT_PULLUP);
     pinMode(1, INPUT_PULLUP);
     pinMode(2, INPUT_PULLUP);
     pinMode(3, INPUT_PULLUP);
     pinMode(4, INPUT_PULLUP);
     pinMode(5, INPUT_PULLUP);
     pinMode(6, INPUT_PULLUP);
     pinMode(7, INPUT_PULLUP);
     pinMode(8, INPUT_PULLUP);
     pinMode(9, INPUT_PULLUP);
     pinMode(10, INPUT_PULLUP);
     pinMode(14, INPUT_PULLUP);
     pinMode(15, INPUT_PULLUP);
     pinMode(16, INPUT_PULLUP);
}
And define the ports accordingly

Re: using a sparkfun pro mini

Posted: Sun Oct 23, 2016 8:52 am
by winnetouch
But helder only posted hex files. How do I open the hex files in Arduino development tools? I googled and couldn't find any anwsers.

BTW. Thank you for your help and time. I really appreciate it :).

Re: using a sparkfun pro mini

Posted: Sun Oct 23, 2016 10:07 am
by winnetouch
winnetouch wrote:But helder only posted hex files. How do I open the hex files in Arduino development tools? I googled and couldn't find any anwsers.

BTW. Thank you for your help and time. I really appreciate it :).
EDIT: Also I tried using this bit of code but it still registered the button press as only one button. Basically it works just like before. I don't see any difference.

Code: Select all

while (digitalRead(up) == HIGH) {
    //do nothing until pin 2 goes high
    delay(500);
    }
    
    //new document:
    Keyboard.press('w');  // send a 'z' to the computer via Keyboard HID
  
  Keyboard.release('w');
  // wait for new window to open:
  delay(100);

Re: using a sparkfun pro mini

Posted: Sun Oct 23, 2016 10:43 am
by TimBer
That's because you now call release when you have still pressed the button. Next loop it will call press and release again. Giving you the same result.

I linked to wrong post from helder. It should be:
http://sudomod.com/forum/viewtopic.php?f=25&t=1176

But user myPiZero has made an example you can use without any external libraries.

Take a look at.
http://sudomod.com/forum/viewtopic.php? ... =10#p15571

Hope it helps.

Re: using a sparkfun pro mini

Posted: Sun Oct 23, 2016 2:26 pm
by winnetouch
Ok... I'll look in to the second link you posted but Helders solution is not really what I need. He set the program up to act like a gamepad. I kind of want it to work like a keyboard to play certain games.

EDIT: Also I can't seem to be able to compile heders code on OSX. Smeone posted a hint to change the progrramer to AVR ISP for mac users but that didn't work either :P.

Re: using a sparkfun pro mini

Posted: Thu May 25, 2017 1:01 pm
by Helder
Read through my whole thread and you'll see the necessary libraries you need to compile the sketch and the older files should have the keyboard sketch.

Re: using a sparkfun pro mini

Posted: Thu Oct 17, 2019 7:53 pm
by Helder
BarbaraBon wrote:
Thu Oct 17, 2019 1:22 pm
I finally got passed the authorization screen but all i get is sound i tried both players, is there any settings that will fix this?
What does this post have to do with the pro mini?