Conection from Arduino to Gdevelop?

Hey everyone, today, for some reason, my brain decided to make an arduino controller type thing. For this, the only thing I could think of was arduino. After some researching, I found out that one way to do this would be for arduino to send a message to a serial port, and the game engine reading it. Is something like this possible using GDevelop? Or is there another way to create a connection between arduino and gdevleop.
Thank you everyone in advance for your answer

2 Likes

Hi,
We have done loads of projects using Arduino to send input to GDevelop. We have used the (now discontinued) text input object in GDevelop and on the Arduino side we have sent numbers or characters followed by return via usb and some keyboard simulation library on the Arduino. It works great. But now GDevelop has a new text input that works differently and I not sure how to solve it. I will ask about it here on the forum. I’ll get back to you when I know how it works.

//Farid

1 Like

You can use one of the web’s different standards to interact with USB devices: WebUSB, WebHID, or WebSerial.

I don’t think WebHID is a good fit here, WebUSB would be the safer and more widespread solution, whereas WebSerial would be the simpler solution.

I might develop an extension for this later. In the meantime, here are introduction posts for WebSerial and WebUSB.

If you have a bluetooth capable device, such as an ESP32, you could also use the WebBluetooth API.

2 Likes

From Arduino to the game should be the easiest if it’s a board with a 32u4 chip (Leonardo, Micro) or SAMD (Due, Zero) because they can behave as a keyboard.

I tested the other direction with WebSerial a year ago, but it had a delay of 1-2 seconds.

1 Like

Hello.

If you need to have a connection between a pc/laptop and Arduino I would suggest to use the WebSerial API. I have a small, not complete yet, extension for WebSerial that I currently use for a project. It’s only able to receive data at this point since I only wanted a one-way communication (microcontroller → pc/laptop). I send byte size data from the microcontroller to the OC and the latency it’s pretty small (20-30ms). I have attached the WebSerial extension file in case anyone wants to have a go with it.

If you need to communicate between a tablet/phone (android) and Arduino you will need to use the WebUSB API since the WebSerial API is not supported on Android platform. Using WebUSB means that you also need to provide a pretty basic “usb driver” for the serial/ttl chip used with Arduino. Not an easy task. I used WebUSB in the past and as soon as you manage to get the driver working it’s just like using a plain serial port.

Update: I can’t attach the file, you can get it from here: https://steliosm.net/WebSerial.json

2 Likes

That is exactly what we have done before, but that doesn’t seem to work with the new Text input. The old Text entry could do this.

1 Like

Do you know if there is a guide on how to implement different JS libraries or APIs in GDevelop? We have been trying to get AR.js into GDevelop but we got stuck pretty soon. It would also be great to learn how to use WebUSB that you linked to.

Cheers

Farid

1 Like

There is no guide for that, no. Anyone with good experience in JS should be able to help you with that. I already linked a tutorial to webusb in my last post.

1 Like

Hello everyone, sorry my english :frowning:
I would like to know how I can join several proximity sensors to use them in my game but I don’t have much knowledge of how to implement what they mention, I would like to know where I should start or how I can use the code provided by steliosm, or if Farre has any other way to connect them, I am very awaiting your response and thank you very much in advance :slight_smile:

1 Like

Hi Playoff2,
I’m not sure exactly how we fixed this in detail but as I remember we did something like this:
We installed a local webserver (Apache?) on the computer running the GDevelop app. On that web server we put a json file that one could access via the computers IP. GDevelop could read and write to that json. The sensor was connected to a Raspberry Pi that wrote data to the json file on the webserver. Something like that. There might have been some Python script involved but I don’t know because I didn’t do that part, I just created the GDevelop app and the json file.

For one way communication from the sensor to GDevelop it’s much easier. Just connect the sensor to an Arduino and let the Arduino emulate a keyboard to send data via usb to GDevelop.

Good luck

/Farre

1 Like