Skip to content

A plugin for serial data reading in Godot Engine 4.3, aimed at bridging communication between devices like Arduino and Godot to create dynamic interactions in games and applications.

Notifications You must be signed in to change notification settings

NicolasRaf/GDSerialRead

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

22 Commits
 
 
 
 
 
 

Repository files navigation

GDSerialRead

A plugin for serial data reading in Godot Engine 4.3, aimed at bridging communication between devices like Arduino and Godot to create dynamic interactions in games and applications.

Table of Contents

GDSerialRead offers a straightforward solution for reading serial data directly in Godot, making it ideal for integrating external devices like Arduino with the engine. This project was initially developed to simulate and capture data from an Arduino Esplora in a Linux environment, enabling real-world hardware and software interactions in a game environment.

1. In the project editor in godot initialize the environment for C# following the path below

Project --> Tools --> C# --> Creat C# solution 
Descrição da imagem

2. After initializing the environment, open a terminal with the path to the main folder of the Godot project

Descrição da imagem

3. Clone the main branch of the repository into the project folder

git clone https://github.com/NicolasRaf/GDSerialRead.git
Descrição da imagem

4. Still in the terminal, install the “System.IO.Ports” package in your project's main folder

dotnet add package System.IO.Ports

5. Now inside Godot open the scene called “DataReceiver.tscn” and assign the script “DataReceiver.gd” to the node

Descrição da imagem

6. Finally, set the “DataReceiver.tscn” node and the “SerialRead.cs” script to autoload (Global)

Descrição da imagem

7. After that, the program is up and running and you can receive and manipulate data from the “DataReciever.gd” node

Descrição da imagem

The node DataReceiver is responsible for receiving and processing the data sent from the SerialRead node. To utilize this functionality, ensure that both this scene (DataReceiver.gd) and the SerialRead.cs script are set as Global (Autoload) in your project.

To interact with the serial data

  • Call SerialRead.StartReading() to begin reading data from the serial port.
  • Call SerialRead._ExitTree() to stop reading data and properly close the connection.

Key Points

  • The script automatically starts reading data when the node is initialized.
  • If you stop the reading process, it will not resume until you explicitly call StartReading() again.
  • The code attempts to connect to a serial port only when data is being sent.
    • If access to the port is unavailable or if no data is received for 3 seconds, the script will attempt to connect to the next available port.
  1. This node serves as a manager for the incoming data, allowing you to process and store it as needed.
  2. You can create additional variables to hold the parsed or transformed data as necessary.

Note

This functionality only works if both this node and the SerialRead.cs script are configured as Autoloads in your project settings.

  • Switch to the example/TestSerialExample branch.

  • It has a project already installed for testing the reception of serial data.

This program was developed by Nícolas Rafael

About

A plugin for serial data reading in Godot Engine 4.3, aimed at bridging communication between devices like Arduino and Godot to create dynamic interactions in games and applications.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published