Problem with controler arcade

Hi everyone, :grinning:
I work for create my own controller.

I tested with an test controller and it works.

My test :

I added all the keys on input_binding and did the script.

function init(self)
	msg.post(".", "acquire_input_focus")
end

function on_input(self, action_id, action)
	if action.pressed then
		if action_id == hash("X") then
			print("X")
		elseif action_id == hash("Y") then
			print("Y")
		elseif action_id == hash("A") then
			print("A")
		elseif action_id == hash("B") then
			print("B")
		end
	end
end

But it does’nt work on Defold :frowning:

I use it as a controller.

Do you have any idea of the problem ?

Thanks for advance !!!

1 Like

Have you generated gamepad bindings for your custom controller?

2 Likes

Lecric!!! Firstly, I must say it’s fantastic to see someone else creating their own controller for Defold! Here’s my own mighty beast. It’s connected to a raspberry pi that I use to trigger animations on a screen behind me when I DJ.

In terms of your controller issue, you will need to do as britzl says. Create a new *.gamepads file and add it there. That’s what I did.

However, I quickly ran into some problems with the android OS I was running my app on, which wouldn’t recognise the gamepad. The solution? Get a rasperry pico (5€) and set it up as a macropad. It’s automatically recognised as a keyboard (rather than a gamepad, which face compatibility issues on different devices), it’s 0 latency, and you can connect it to anything. If you don’t mind soldering the buttons (they are the easiest thing to solder, I promise) it’s much cheaper and much more compatible, with no disadvantages over a gamepad device. I can even share the code for a simple macropad. it’s here. There’s also a youtube video, although, it comes with a few gotchas which are solved in my repo.

Please, share some information about your project!! And although I am sure you can get your gamepad working, please ask me any questions if you take the macro keyboard route.

4 Likes

Hey Josh,
It’s cool to know that I’m not the only one who had the idea.
I’m going to put it in the bookstores to play my game Drop In Music.
The buttons in the game will have the same position in the game and it will allow for some physical things to push :slight_smile:

I didn’t know I had to use gamepad input, but I still don’t understand how to use it.
I have created a new file, added a new gamepad, but when I test it doesn’t show. (i test with gamepad tester)


1 Like

Here’s my thread looking into the same thing. You have screenshots of the input and gamepad files, as well as the code you need to print what the gamepad gives you. Try setting it up exactly like that and seeing if it works.

The other option (which I think might actually be better) is to try the following in your on_input function and seeing if you are getting raw data.

if action_id == hash("raw") then
    pprint(action.gamepad_buttons)
    pprint(action.gamepad_axis)
    pprint(action.gamepad_hats)
end
1 Like

The simplest way to generate correct bindings is to use the gdc tool which we have linked in the gamepad manual:

Run the tool and follow the instructions in the terminal.

1 Like

Real good tool gdc.


But it doesn’t appears with that. :frowning:

Also with this, nothing.

If you are on windows could you try running with this tool? http://ds4-windows.com/

Defold doesn’t support non-xinput devices out of the box yet.

1 Like

If you can’t get this to work, and you don’t want to solder, you could get a raspberry Pico with pre-soldered header pins and buttons with screw terminals. The Pico even has a 5v output so you could still light your buttons up.

I swear, I don’t work for the pi foundation…

1 Like

It doesn’t work. :sob:

Is there really no other way?

Mmmmhhh, I just want a controller, not a second laptop.

The Pico costs less than €5! It’s a USB peripheral!!

2 Likes

Ok ok,
if it works with defold you convince me.
We can use 5v for led and 20 entries for the buttons.

Excellent!

In my code, you will need to make a few changes:

keycodetable = [Keycode.SPACE, Keycode.W, Keycode.A, Keycode.S, Keycode.D,  Keycode.UP_ARROW, Keycode.DOWN_ARROW, Keycode.LEFT_ARROW, Keycode.RIGHT_ARROW]
GPs = [board.GP0,board.GP1,board.GP2,board.GP3,board.GP4, board.GP5,board.GP6,board.GP7,board.GP8]

The keycodetable says what key code is activated by each IO connector. You’ll need to customise that.
You’ll also need to customise the GPs table to go from 0 to 20 (it currently goes from 0 to 8).

You’ll also have to change the for i in range(9): both times that it appears. Change the 9 to 20.

Let me know if you have trouble with it!

1 Like

Ok interesting.
I have several questions:

  • Is it compulsory to turn on the Pico each time to use it? How did you do it?
  • What language are you using? I have the impression that it’s MicroPython.
  • Is there anything to implement in defold to make the controller playable.
  • Is it possible to send messages to the Pico from Defold and how?
    To change the leds for example.

A lot of questions, but it’s a project I have to finish before February, because after that I’m going on a 6 month trip. :sweat:

  • Is it compulsory to turn on the Pico each time to use it? How did you do it?
    No, you don’t have to turn it on. You plug it into the USB, and start pressing buttons.

  • What language are you using? I have the impression that it’s MicroPython.
    It’s either python or micropython. Sorry I cannot help you more than that. I know just the basics. But it’s a very basic project.

  • Is there anything to implement in defold to make the controller playable.
    No. If you use my code, it’s the same as pressing a key on a USB keyboard. It works on anything you can plug a USB keyboard into (I would guess…).

  • Is it possible to send messages to the Pico from Defold and how? To change the leds for example.

You have two options for the LEDs:

  1. You can get 5v from Pin40 (labelled VBUS) of the pico [assuming your USB connection provides 5v]. That means the LEDs will turn on as soon as the pico is plugged in, and stay turned on.

  2. You can get messages from the buttons themselves to the pico (but you can’t send messages from defold to the Pico). So, you could program the pico so that LEDs turn on and off according to button presses (if your LEDs work with 3.3v, which is what the pico outputs from GP). It would involve putting these lines of code in somewhere:

from machine import Pin -- this fetches the library.

pin_led = Pin(26, mode=Pin.OUT) -- defines GP26 as controlling an LED
pin_led.on() -- sends 3.3v to GP26
pin_led.off()  -- sends 0v to GP26

Read more about controlling LEDs with a pico here.

1 Like

Ok, Thank you for all your answers.

It’s obligatory to push start buttons for start controller ?
If yes, How do you get it started since it’s in your box?

Is there really no way to communicate with Pico via native or whatever?
I don’t know much about it, but I’d be willing to give it a go. (like electronics :grinning:)

Sorry, I wasn’t clear. The pico starts automatically once it gets USB power.

There probably is, but I wouldn’t know where to start.

1 Like

I believe the question “how to communicate to Pico from Defold” better to split into a few smaller questions:

  1. how to send a data/signal to Pico? It’s a microcontroller probably similar to Arduino, so it should be able to send and receive data via USB. Just a first article after quick search. How to send data to a Raspberry Pi Pico via USB | smittytone messes with micros
    There might be YouTube videos about it.
  2. How to run C++ (or other) code inside Defold? I assume that there are examples in C++ how to communicate with Pico.
  3. How to call my native C++ code from Lua.
1 Like