Page 1 of 15

Cheaper than Teensy

Posted: Wed Jun 01, 2016 2:42 pm
by Oxodao
[spoiler="This post in a nutshell"]So,
Arduino pro micro are way cheaper than Teensy, so I used them.
Demo here: https://www.youtube.com/watch?v=KqMsXyjs0Yo
In order to do the same, download this library and open the Gamepad.cpp in Notepad++, then remove every "sendUpdate();" lines (Except the function sendUpdate) then create a new sketch with this code, and upload it. Arduino pro micro needs to be set as an Arduino Leonardo in order to be able to put the code on the chip.

Code: Select all

#include <Gamepad.h>
Gamepad gb;

#define BTN_DOWN 0
#define BTN_UP 1
#define BTN_LEFT 2
#define BTN_RIGHT 3
#define BTN_A 4
#define BTN_START 5
#define BTN_Y 6
#define BTN_L1 7
#define BTN_X 8
#define BTN_R1 9
#define BTN_R2 10
#define BTN_L2 11
#define BTN_B 12
#define BTN_SELECT 13

void setup() {
  for (int x = 0; x<13; x++){
      pinMode(x, INPUT_PULLUP);
  }
}

void loop() {

  bool downSet  = digitalRead(BTN_DOWN);
  bool upSet    = digitalRead(BTN_UP); // No pun intended
  bool leftSet  = digitalRead(BTN_LEFT);
  bool rightSet = digitalRead(BTN_RIGHT);
 
  gb.setLeftXaxis(!leftSet ? -127 : !rightSet ? 127 : 0);
  gb.setLeftYaxis(!downSet ? 127 : !upSet ? -127 : 0);

  gb.setButtonState(1, !digitalRead(BTN_A));
  gb.setButtonState(2, !digitalRead(BTN_B));
  gb.setButtonState(3, !digitalRead(BTN_X));
  gb.setButtonState(4, !digitalRead(BTN_Y));
  gb.setButtonState(5, !digitalRead(BTN_SELECT));
  gb.setButtonState(6, !digitalRead(BTN_START));
  gb.setButtonState(7, !digitalRead(BTN_L1));
  gb.setButtonState(8, !digitalRead(BTN_R1));
  gb.setButtonState(9, !digitalRead(BTN_L2));
  gb.setButtonState(10, !digitalRead(BTN_R2));

  gb.sendUpdate();
}
Beyond that, Helder is working on a fully arduino integrated pcb for the controller, replacing the "Common ground pcb" and saving a lot of space in cables. He has done insane amount of stuff, giving us a fully populated board including: Gamepad, PWM audio, USB Hub and Amplifier.[/spoiler]
Hi,

I don't think that i'm the first one to propose this, but replacing the Teensy which costs 20$ with an Arduino pro micro which is way cheaper (4$ on ebay) looks like working correctly, I've done it. The only problem is that there is not enough digital ports so we need to use some analog too, and the Pro Micro has a ATMEGA32u4 instead of a 328, this allows him to be used as a keyboard.

I made this to try on mine and it works nicely:

Code: Select all

#include "Keyboard.h"

void setup() {
  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);
  Keyboard.begin();
  Serial.begin(9600);
}

void loop() {
  if(digitalRead(2) == LOW) {
    Serial.println("Up");
    Keyboard.press(KEY_UP_ARROW);
  }
  
  if(digitalRead(3) == LOW) {
    Serial.println("Left");
    Keyboard.press(KEY_LEFT_ARROW);
  }
  
  if(digitalRead(4) == LOW) {
    Serial.println("Down");
    Keyboard.press(KEY_DOWN_ARROW);
  }
  
  if(digitalRead(5) == LOW) {
    Serial.println("Right");
    Keyboard.press(KEY_RIGHT_ARROW);
  }
  
  if(digitalRead(6) == LOW) {
    Serial.println("A");
    Keyboard.press(KEY_BACKSPACE);
  }
  if(digitalRead(7) == LOW) {
    Serial.println("B");
    Keyboard.press(KEY_END);
  }

  
  if(digitalRead(8) == LOW) {
    Serial.println("Select");
    Keyboard.press(KEY_PAGE_UP);
  }
  
  if(digitalRead(9) == LOW) {
    Serial.println("Start");
    Keyboard.press(KEY_PAGE_DOWN);
  }
  delay(100);
  Keyboard.releaseAll();
}
My goal is to implement a Atmega32u4 on the design of the common ground pcb, it would save a lot of space in the case, no need for the wires to the teensy + no external board.

I'm working on that, probably post untested schematics in the beggining of the next week.

See you :)

Re: Cheaper than Teensy

Posted: Wed Jun 01, 2016 2:53 pm
by wermy
This would be awesome. :) Looking forward to updates on this.

Re: Cheaper than Teensy

Posted: Wed Jun 01, 2016 3:06 pm
by GnobarEl
I'm here to follow this topic as well! :)

Re: Cheaper than Teensy

Posted: Wed Jun 01, 2016 3:36 pm
by Helder
Oxodao wrote: My goal is to implement a Atmega32u4 on the design of the common ground pcb, it would save a lot of space in the case, no need for the wires to the teensy + no external board.

I'm working on that, probably post untested schematics in the beggining of the next week.

See you :)
I'm working on the same thing and just needed the code to be working before I wasted time with a schematic. What else is missing if anything from the code? also do you have the pinout on the Atmega32u4 to the actual buttons? (I haven't looked at the code which probably has this)


Edit: I found a super simple version of the schematic:
Image

Re: Cheaper than Teensy

Posted: Wed Jun 01, 2016 3:41 pm
by wermy
This would be really awesome if you guys get it going. Then we'd just have 4 wires coming off of the controller board for USB, and that's it.

Do you guys know offhand if it would still be reprogrammable easily? Say if someone wanted to use joypad input in stead of keyboard.

Re: Cheaper than Teensy

Posted: Wed Jun 01, 2016 3:47 pm
by Helder
If once it's programmed using USB and if it can be reprogrammed using USB it will be a piece of cake but if not we will have to use the ISP pins and an external programmer.

Re: Cheaper than Teensy

Posted: Wed Jun 01, 2016 3:51 pm
by Oxodao
Thanks :)

Actually, the 32u4 is capable of simulating joystick too I guess, even MIDI thingy things if I'm not mistaken. I used keyboard because that's how I usually use it...
I'm working on the same thing and just needed the code to be working before I wasted time with a schematic. What else is missing if anything from the code? also do you have the pinout on the Atmega32u4 to the actual buttons? (I haven't looked at the code which probably has this)
I'll let you do the schematic so, I'm pretty new to electronic community so I would take ages to do simple things..

The pinouts are available here:
Image

We should probably use the TQFP ML 44 package one, it is tiny but still solderable with an soldering iron.

Re: Cheaper than Teensy

Posted: Wed Jun 01, 2016 3:53 pm
by Oxodao
Our best bet I think would be to have solder points for UART, then after have soldered an arduino-bootloader-atmega we can just connect an FTDI usb key to theses in order to reupload sketches.
Also if you are doing the scheme/pcb, we should add a small tactile push button in order to reset the atmega. That's needed when you flash a sketch

Re: Cheaper than Teensy

Posted: Wed Jun 01, 2016 4:31 pm
by Helder
Cool I'll handle the schematic and maybe you can edit the code. I was wondering how many more pins are available for buttons? Maybe add another 6 like X,Y,L1,L2,R1,R2 or will that exceed the available pins?

Re: Cheaper than Teensy

Posted: Thu Jun 02, 2016 12:13 am
by Fleder
Helder wrote:If once it's programmed using USB and if it can be reprogrammed using USB it will be a piece of cake but if not we will have to use the ISP pins and an external programmer.
As i am working on getting the micro to act as a keyboard, too, i already tried this.
The problem is, if your code is not good, it sends releases or other commands constantly, which makes reprogramming it very hard.
So, it is not a problem, if you only send inputs on button presses and the micro/leonardo is silent the rest of the time.

My only problem is the code and how to get it to accept my keys, as i am new to C and does not really have the time to read a lot of tutorials right now.

I am even considering getting someone else to do the code for me for money on fiverr.