Cheaper than Teensy

General GBZ-related chat goes here. Share ideas, tips and tricks, or ask questions that don't fit into the hardware/software help forums.
Post Reply
User avatar
Oxodao
Posts: 131
Joined: Wed Jun 01, 2016 11:35 am
Location: 127.0.0.1
Has thanked: 4 times
Been thanked: 30 times
Contact:

Cheaper than Teensy

Post by Oxodao » Wed Jun 01, 2016 2:42 pm

[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 :)
Last edited by Oxodao on Sat Jul 16, 2016 10:55 am, edited 8 times in total.
Arduino sketch for the gamepad (Teensy replacement): http://github.com/oxodao/GBZGamepad

User avatar
wermy
Site Admin
Posts: 1346
Joined: Tue May 03, 2016 8:51 pm
Has thanked: 620 times
Been thanked: 1322 times
Contact:

Re: Cheaper than Teensy

Post by wermy » Wed Jun 01, 2016 2:53 pm

This would be awesome. :) Looking forward to updates on this.
ImageImageImageImage

GnobarEl
Posts: 42
Joined: Mon May 23, 2016 4:10 am
Has thanked: 17 times

Re: Cheaper than Teensy

Post by GnobarEl » Wed Jun 01, 2016 3:06 pm

I'm here to follow this topic as well! :)

User avatar
Helder
Trailblazer
Trailblazer
Posts: 2985
Joined: Thu May 05, 2016 8:33 am
Location: Rogers, AR
Has thanked: 1459 times
Been thanked: 3114 times

Re: Cheaper than Teensy

Post by Helder » Wed Jun 01, 2016 3:36 pm

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
Last edited by Helder on Wed Jun 01, 2016 3:43 pm, edited 1 time in total.
Chat with me and other members On Discord

Don't contact me about obtaining my board files (as you will not get them). If my Boards or PCB Kits are sold out, they will be restocked as soon as I can get them and there is demand for them. You can join the mailing list on my Website to be notified when they are available.


Helder's Game Tech Website

We will not support any cloned work so don't come to us with technical issues to resolve, go talk to the cloner for help.

User avatar
wermy
Site Admin
Posts: 1346
Joined: Tue May 03, 2016 8:51 pm
Has thanked: 620 times
Been thanked: 1322 times
Contact:

Re: Cheaper than Teensy

Post by wermy » Wed Jun 01, 2016 3:41 pm

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.
ImageImageImageImage

User avatar
Helder
Trailblazer
Trailblazer
Posts: 2985
Joined: Thu May 05, 2016 8:33 am
Location: Rogers, AR
Has thanked: 1459 times
Been thanked: 3114 times

Re: Cheaper than Teensy

Post by Helder » Wed Jun 01, 2016 3:47 pm

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.
Chat with me and other members On Discord

Don't contact me about obtaining my board files (as you will not get them). If my Boards or PCB Kits are sold out, they will be restocked as soon as I can get them and there is demand for them. You can join the mailing list on my Website to be notified when they are available.


Helder's Game Tech Website

We will not support any cloned work so don't come to us with technical issues to resolve, go talk to the cloner for help.

User avatar
Oxodao
Posts: 131
Joined: Wed Jun 01, 2016 11:35 am
Location: 127.0.0.1
Has thanked: 4 times
Been thanked: 30 times
Contact:

Re: Cheaper than Teensy

Post by Oxodao » Wed Jun 01, 2016 3:51 pm

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.
Arduino sketch for the gamepad (Teensy replacement): http://github.com/oxodao/GBZGamepad

User avatar
Oxodao
Posts: 131
Joined: Wed Jun 01, 2016 11:35 am
Location: 127.0.0.1
Has thanked: 4 times
Been thanked: 30 times
Contact:

Re: Cheaper than Teensy

Post by Oxodao » Wed Jun 01, 2016 3:53 pm

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
Arduino sketch for the gamepad (Teensy replacement): http://github.com/oxodao/GBZGamepad

User avatar
Helder
Trailblazer
Trailblazer
Posts: 2985
Joined: Thu May 05, 2016 8:33 am
Location: Rogers, AR
Has thanked: 1459 times
Been thanked: 3114 times

Re: Cheaper than Teensy

Post by Helder » Wed Jun 01, 2016 4:31 pm

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?
Chat with me and other members On Discord

Don't contact me about obtaining my board files (as you will not get them). If my Boards or PCB Kits are sold out, they will be restocked as soon as I can get them and there is demand for them. You can join the mailing list on my Website to be notified when they are available.


Helder's Game Tech Website

We will not support any cloned work so don't come to us with technical issues to resolve, go talk to the cloner for help.

User avatar
Fleder
Posts: 849
Joined: Thu May 05, 2016 9:04 am
Location: Germany
Has thanked: 183 times
Been thanked: 258 times

Re: Cheaper than Teensy

Post by Fleder » Thu Jun 02, 2016 12:13 am

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.

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest