How i can connect the joystick to picade pcb?

Hi, I have the “mini mountable analog joystick (com-b003)” I bought in Pimoroni and i don’t know to connect this to picade module pcb.
Thanks…

That joystick is (I believe) not of the same kind as is designed to be used with the picade PCB.

The Picade board has inputs for up/down/left/right - which are designed to be connected to a joystick which essentially has 4 switches (one for each direction) inside. So, a connection between up/down/left/right and ground is made depending on which way the joystick’s been pushed.

The joystick you linked is analogue, and is designed so that you can find out how much it’s being pushed in either direction rather than just whether it is being pushed in the direction or not.

All, however, is not lost. These suggestions may or may not work (I have neither product myself and I don’t work for Pimoroni):

Luckily, the joystick buttons are hooked up to analogue inputs on the microcontroller on the board, as shown here:

#define LEFT       A10 // PB6  ADC13 - 
#define RIGHT      A9  // PB5  ADC12
#define UP         A7  // PD7  ADC10
#define DOWN       A8  // PB4  ADC11

Pin numbers starting with an A are analogue.

It looks to me like the support for an analog joystick is embedded in the code as follows:

  uint8_t state;
// test for current state of this input
// read an analog value instead of digital for our magical analog bindings
if ( default_config.buttons[i].key == JOY1_X
     || default_config.buttons[i].key == JOY1_Y
     || default_config.buttons[i].key == JOY2_X
     || default_config.buttons[i].key == JOY2_Y ) {
  state = map(analogRead(picade_pins[i]), 0, 1023, 0, 254);
}
else
{
  state = !digitalRead(picade_pins[i]);

If my dodgy arduino skills don’t deceive me, it looks like the line state = map(analogRead(picade_pins[i]), 0, 1023, 0, 254); is just taking an analog reading and mapping it to a set scale which the software then uses to determine whether it’s a press or not. If this is truly the case, just connecting the left and right contacts on each side of the joystick to 5v and gnd, and the middle one to the appropriate pin on the picade PCB would yield some results. Tweaking the code to get the sensitivity you want is easy too.

If I’m wrong about the code reading analog values, you could use an ADC (analog-digital converter) or possibly some analog components to it up so that it read on if it was above a certain value, or off if it was below. Or, you could write your own code to deal with this.

Have fun :)

1 Like

The joystick pins are hooked up to analog inputs, and I added support for analog joysticks- which map onto the emulated “gamepad” in the Picade firmware- giving proper analog joystick support.

The line state = map(analogRead(picade_pins[i]), 0, 1023, 0, 254); is mapping the range 0 to 1023 to the range 0 to 254 so it fits into a single byte for the joystick HID report :D

Great sleuthing though! And I totally realise I need to put together a proper guide for using these joysticks with the Picade PCB- you can use two of them for dual analog in theory. I’ve had one up and running recently.

I don’t think I’d considered wanting to map an analog joystick to digital values, though, I don’t believe it’s currently possible to map analog U/D/L/R to individual keyboard keys, which in retrospect might be something people want! It depends how well RetroPie handles it!

At the moment, sending the char ‘n’ over serial to the Picade PCB will load the ‘quickbind dual analog’ profile which will make the Picade work like a gamepad with two analog sticks.