Page 1 of 1

Controller PCB

Posted: Wed Oct 05, 2016 5:38 am
by OrbitalPi
Hi Guys,

I'm just kinda dipping my toe into the Gameboy Zero project and I need a bit of advice when it comes the button PCB. I unfortunately missed out on Helder's All in One PCB so I'm looking at other ideas.

The one that Kitsch Bent does (Link Below)
http://store.kitsch-bent.com/product/ex ... 2c-version

Would I still need the teensy controller with this or not? As Kitsch Bent do really put alot of info on there for people who are new to it.

Any help is much appreciated :)

Re: Controller PCB

Posted: Wed Oct 05, 2016 9:02 am
by chaosratt
That is an I2C board. If you do not know what I2C is or how to use it, do not get that board, as to my knowledge there are no tutorials available on it.

What you need is one of the many "common ground" boards available here and on ebay. Kitch has one too: http://store.kitsch-bent.com/product/co ... button-pcb

These can be wired directly to the pi, adafruit has a guide for it for one of her retropie kits (this one I think), or you can use either a teensy or arduino (Leonardo clone) to 'fake' the keyboard/gamepad imputs.

Re: Controller PCB

Posted: Wed Oct 05, 2016 11:13 am
by Ganreizu
I would just wait for a second round of helder's AIO version 2.0. Cuts so much time and space in the case that by the time you finish it normally you'd have it received and assembled anyway and you can get a bigger battery.

Re: Controller PCB

Posted: Wed Oct 05, 2016 2:31 pm
by OrbitalPi
Thanks guys. I think I'll just wait for Helder's next board. Too much faffing about otherwise and it gives me time to get the rest of the parts all together :)

Re: Controller PCB

Posted: Fri Dec 09, 2016 7:55 pm
by Tango
If you are looking for some code for the i2c controller PCB... I wrote a program for a Teensy 3.2 that takes the i2c input and generates a keyboard HID output via the teensy usb port. It's a work in progress so I have to tweak some things... I have put it out here to help anyone else who is trying to interface to this board.

Dale

Code: Select all

#include "Arduino.h"
#include <i2c_t3.h>
#include <usb_keyboard.h>

byte port_a;
byte port_b;

//The setup function is called once at startup of the sketch
void setup()
{
// Add your initialization code here

	  Wire.begin(I2C_MASTER,0x20,I2C_PINS_18_19,I2C_PULLUP_INT,I2C_RATE_100); // wake up I2C bus
	  Wire.beginTransmission(0x20);
	  Wire.write(0x0c);
	  Wire.write(0xFF);
	  Wire.endTransmission();
	  //Wire.endTransmission(0x20);

	  Wire.beginTransmission(0x20);
	  Wire.write(0x0d);
	  Wire.write(0xFF);
	  Wire.endTransmission();

	  pinMode(13, OUTPUT);
	  //digitalWrite(13, HIGH);
	  //Serial.begin(9600);

}

// The loop function is called in an endless loop
void loop()
{
//Add your repeated code here

	  Wire.beginTransmission(0x20);
	  Wire.write(0x12);
	  Wire.endTransmission();
	  Wire.requestFrom(0x20, 1);

	  port_a = Wire.read();

	  Wire.beginTransmission(0x20);
	  Wire.write(0x13);
	  Wire.endTransmission();
	  Wire.requestFrom(0x20, 1);

	  port_b = Wire.read();

	  if (!((1 << 2) & port_a)) //B
		  usb_keyboard_press(KEY_L,0);

	  if (!((1 << 3) & port_a)) //A
		  usb_keyboard_press(KEY_P,0);

	  //if (!((1 << 4) & port_a)) //R2

	  if (!((1 << 5) & port_a)) //R1
		  usb_keyboard_press(KEY_E,0);

	  if (!((1 << 6) & port_a)) //X
		  usb_keyboard_press(KEY_K,0);

	  if (!((1 << 7) & port_a)) //Y
		  usb_keyboard_press(KEY_O,0);

	  if (!((1 << 0) & port_b)) //UP
		  usb_keyboard_press(KEY_W,0);

	  if (!((1 << 1) & port_b)) //L1
		  usb_keyboard_press(KEY_Q,0);

	  //if (!((1 << 2) & port_b)) //L2

	  if (!((1 << 3) & port_b)) //LEFT
		  usb_keyboard_press(KEY_A,0);

	  if (!((1 << 4) & port_b)) //RIGHT
		  usb_keyboard_press(KEY_D,0);

	  if (!((1 << 5) & port_b)) //DOWN
		  usb_keyboard_press(KEY_S,0);

	  if (!((1 << 6) & port_b)) //SELECT
		  usb_keyboard_press(KEY_Z,0);

	  if (!((1 << 7) & port_b)) //START
		  usb_keyboard_press(KEY_X,0);

	  delay(200);
}


Re: Controller PCB

Posted: Sat Dec 10, 2016 11:26 am
by Helder
Tango wrote:If you are looking for some code for the i2c controller PCB... I wrote a program for a Teensy 3.2 that takes the i2c input and generates a keyboard HID output via the teensy usb port. It's a work in progress so I have to tweak some things... I have put it out here to help anyone else who is trying to interface to this board.

Dale

Code: Select all

#include "Arduino.h"
#include <i2c_t3.h>
#include <usb_keyboard.h>

byte port_a;
byte port_b;

//The setup function is called once at startup of the sketch
void setup()
{
// Add your initialization code here

	  Wire.begin(I2C_MASTER,0x20,I2C_PINS_18_19,I2C_PULLUP_INT,I2C_RATE_100); // wake up I2C bus
	  Wire.beginTransmission(0x20);
	  Wire.write(0x0c);
	  Wire.write(0xFF);
	  Wire.endTransmission();
	  //Wire.endTransmission(0x20);

	  Wire.beginTransmission(0x20);
	  Wire.write(0x0d);
	  Wire.write(0xFF);
	  Wire.endTransmission();

	  pinMode(13, OUTPUT);
	  //digitalWrite(13, HIGH);
	  //Serial.begin(9600);

}

// The loop function is called in an endless loop
void loop()
{
//Add your repeated code here

	  Wire.beginTransmission(0x20);
	  Wire.write(0x12);
	  Wire.endTransmission();
	  Wire.requestFrom(0x20, 1);

	  port_a = Wire.read();

	  Wire.beginTransmission(0x20);
	  Wire.write(0x13);
	  Wire.endTransmission();
	  Wire.requestFrom(0x20, 1);

	  port_b = Wire.read();

	  if (!((1 << 2) & port_a)) //B
		  usb_keyboard_press(KEY_L,0);

	  if (!((1 << 3) & port_a)) //A
		  usb_keyboard_press(KEY_P,0);

	  //if (!((1 << 4) & port_a)) //R2

	  if (!((1 << 5) & port_a)) //R1
		  usb_keyboard_press(KEY_E,0);

	  if (!((1 << 6) & port_a)) //X
		  usb_keyboard_press(KEY_K,0);

	  if (!((1 << 7) & port_a)) //Y
		  usb_keyboard_press(KEY_O,0);

	  if (!((1 << 0) & port_b)) //UP
		  usb_keyboard_press(KEY_W,0);

	  if (!((1 << 1) & port_b)) //L1
		  usb_keyboard_press(KEY_Q,0);

	  //if (!((1 << 2) & port_b)) //L2

	  if (!((1 << 3) & port_b)) //LEFT
		  usb_keyboard_press(KEY_A,0);

	  if (!((1 << 4) & port_b)) //RIGHT
		  usb_keyboard_press(KEY_D,0);

	  if (!((1 << 5) & port_b)) //DOWN
		  usb_keyboard_press(KEY_S,0);

	  if (!((1 << 6) & port_b)) //SELECT
		  usb_keyboard_press(KEY_Z,0);

	  if (!((1 << 7) & port_b)) //START
		  usb_keyboard_press(KEY_X,0);

	  delay(200);
}

So you still need a Teensy? And instead of using the USB on the Pi you use the I2C pins on the Pi? I guess it works out well if you need to have that free USB port and don't use a hub.

Re: Controller PCB

Posted: Mon Dec 12, 2016 12:12 pm
by Tango
The program above is for an Arduino (in my case a Teensy 3.2) where the pcb is connected via i2c (cuts down on the wiring).

I don't see why you couldn't use the Raspberry pi i2c bus also... you would have to write a daemon that ran on the pi to convert the i2c data into keyboard commands... it's certainly doable.

Updated Code... the old code above seemed to hang and not work very well... so tweaked a bit and seems to work a bit better.
The i2c_t3 library you can get from https://github.com/nox771/i2c_t3 as discussed here https://forum.pjrc.com/threads/21680-Ne ... or-Teensy3

Code: Select all

#include "Arduino.h"
#include <i2c_t3.h>

byte port_a;
byte port_b;

void setup()
{
	  Keyboard.begin();
	  Wire.begin(I2C_MASTER,0x20,I2C_PINS_18_19,I2C_PULLUP_INT,I2C_RATE_100); // wake up I2C bus
	  Wire.beginTransmission(0x20);
	  Wire.write(0x0c);
	  Wire.write(0xFF);
	  Wire.endTransmission();

	  Wire.beginTransmission(0x20);
	  Wire.write(0x0d);
	  Wire.write(0xFF);
	  Wire.endTransmission();

	  pinMode(13, OUTPUT);
	  digitalWrite(13, HIGH); //Comment out to reduce power consumption
}

void loop()
{
	  Wire.beginTransmission(0x20);
	  Wire.write(0x12);
	  Wire.endTransmission();
	  Wire.requestFrom(0x20, 1);

	  port_a = Wire.read();

	  Wire.beginTransmission(0x20);
	  Wire.write(0x13);
	  Wire.endTransmission();
	  Wire.requestFrom(0x20, 1);

	  port_b = Wire.read();

	  if (!((1 << 2) & port_a)) //B
		  Keyboard.press('l');

	  if (!((1 << 3) & port_a)) //A
		  Keyboard.press('p');

	  //if (!((1 << 4) & port_a)) //R2

	  if (!((1 << 5) & port_a)) //R1
		  Keyboard.press('e');

	  if (!((1 << 6) & port_a)) //X
		  Keyboard.press('k');

	  if (!((1 << 7) & port_a)) //Y
		  Keyboard.press('o');

	  if (!((1 << 0) & port_b)) //UP
		  Keyboard.press('w');

	  if (!((1 << 1) & port_b)) //L1
		  Keyboard.press('q');

	  //if (!((1 << 2) & port_b)) //L2

	  if (!((1 << 3) & port_b)) //LEFT
		  Keyboard.press('a');

	  if (!((1 << 4) & port_b)) //RIGHT
		  Keyboard.press('d');

	  if (!((1 << 5) & port_b)) //DOWN
		  Keyboard.press('s');

	  if (!((1 << 6) & port_b)) //SELECT
		  Keyboard.press('z');

	  if (!((1 << 7) & port_b)) //START
		  Keyboard.press('x');

	  delay(200);
	  Keyboard.releaseAll();
}
Dale

Re: Controller PCB

Posted: Tue Dec 13, 2016 9:25 am
by majestic
I bought this board thinking it would make a gbz build easier and its made it a nightmare. All hooked up to the pi and nothing. Ive looked for 3months and tried all i can. Gutted its come to a halt.

Re: Controller PCB

Posted: Sat Dec 17, 2016 4:10 am
by Tango
majestic wrote:I bought this board thinking it would make a gbz build easier and its made it a nightmare. All hooked up to the pi and nothing. Ive looked for 3months and tried all i can. Gutted its come to a halt.
You can certainly use the i2c bus on the Pi... but you will have to write some code on the pi to translate the i2c commands from the PCB. I elected to use a Teensy as I am also using it for shutdown and battery monitoring.Ma

@Majestic Take a look here http://www.sudomod.com/forum/viewtopic.php?f=8&t=1989 It's not an exact driver as it also uses the GPIO on the pi, but its a start. I chose the Teensy route as it was easier to interface to and I have some coding knowledge with the teensy.

Dale