Step 1. Add the JitPack repository to your build file
Add it in your root settings.gradle at the end of repositories:
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
mavenCentral()
maven { url 'https://jitpack.io' }
}
}
Add it in your settings.gradle.kts at the end of repositories:
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
mavenCentral()
maven { url = uri("https://jitpack.io") }
}
}
Add to pom.xml
<repositories>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
</repositories>
Add it in your build.sbt at the end of resolvers:
resolvers += "jitpack" at "https://jitpack.io"
Add it in your project.clj at the end of repositories:
:repositories [["jitpack" "https://jitpack.io"]]
Step 2. Add the dependency
dependencies {
implementation 'com.github.panamahitek:panamahitek_arduino:3.2.1'
}
dependencies {
implementation("com.github.panamahitek:panamahitek_arduino:3.2.1")
}
<dependency>
<groupId>com.github.panamahitek</groupId>
<artifactId>panamahitek_arduino</artifactId>
<version>3.2.1</version>
</dependency>
libraryDependencies += "com.github.panamahitek" % "panamahitek_arduino" % "3.2.1"
:dependencies [[com.github.panamahitek/panamahitek_arduino "3.2.1"]]
Electromechanical Engineer, Teacher, and Researcher at the Technological University of Panama. Founder of the Panama Hitek project along with the creative team of Panama Hitek Creative Team.
The PanamaHitek_Arduino library provides a simple framework for handling serial communication between Java applications and Arduino boards. It offers three main classes:
PanamaHitek_Arduino
- Handles the establishment and management of serial connections and communication with Arduino boards.PanamaHitek_MultiMessage
- Facilitates the reception and processing of multiple simultaneous messages from Arduino in Java.PanamaHitek_DataBuffer
- Manages data organization, supports table visualization, and enables export to MS Excel (.xlsx) files.The library also includes four specialized classes for real-time graphical representation using the JFreeCharts dependency:
PanamaHitek_DualDialChart
- Creates Swing-based analog clock-type charts with two hands using JFreeCharts.PanamaHitek_SingleDialChart
- Creates Swing-based analog clock-type charts with one hand using JFreeCharts.PanamaHitek_ThermometerChart
- Generates Swing-based thermometer-type charts using JFreeCharts.PanamaHitek_TimeLineChart
- Generates Swing-based multi-line charts based on time using JFreeCharts.Add the following lines to your pom.xml
file:
<dependencies>
<dependency>
<groupId>com.github.PanamaHitek</groupId>
<artifactId>PanamaHitek_Arduino</artifactId>
<version>3.2.1</version>
</dependency>
</dependencies>
<repositories>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
</repositories>
.jar
files to your Java project classpath.To use the library effectively, ensure that the Arduino board is connected to the computer via USB. Additionally, the Arduino board must have an appropriate sketch uploaded to facilitate serial communication. The setup involves running an Arduino sketch on the board while a corresponding Java program operates on the computer.
The documentation includes several paired Arduino sketches and Java programs that can be used to test the library's functionality. You can perform the following tests:
Sending data from Java to Arduino
tx_example.ino
txExample.java
Receiving data from Arduino to Java
single_data_send.ino
rxExample.java
Bidirectional communication between Java and Arduino
rxtx_example.ino
rxtxExample.java
Sending multiple data values from Arduino to Java
multiple_data_send.ino
rxMultiple.java
For detailed information on each example, please refer to the arduino_sketches folder in the repository.
Video tutorial (in Spanish): Tabulation and data export to Excel
rxtxSerial.dll
drivers installed in the JAVA_HOME
path.C:/JavaRXTX
path.NameSerialPortsAt()
is now getSerialPorts()
.SerialPortsAvailable()
is now getPortsAvailable()
.MessageAvailable()
is now isMessageAvailable()
.void ShowMessageDialogs(boolean input)
: Enables or disables pop-up windows when a runtime error occurs.void SendByte(int input)
: Sends bytes to Arduino through the serial port.The Arduino
class includes the following methods for serial communication between Arduino and Java:
void ArduinoTX(String PORT_NAME, int TIME_OUT, int DATA_RATE)
Establishes a serial connection to send data from Java to Arduino.
void ArduinoRX(String PORT_NAME, int TIME_OUT, int DATA_RATE, SerialPortEventListener event)
Sets up a connection to receive data from Arduino to Java using an event listener.
void ArduinoRXTX(String PORT_NAME, int TIME_OUT, int DATA_RATE, SerialPortEventListener event)
Enables bidirectional communication between Arduino and Java, allowing both sending and receiving data.
void SendData(String data)
Sends a string of text from Java to Arduino.
String ReceiveData()
Receives data directly from Arduino as a string of text.
boolean MessageAvailable()
Returns true
if a message has been received from Arduino, indicating data availability.
String PrintMessage()
Retrieves the message received from Arduino as a string of text.
int SerialPortsAvailable()
Returns the number of serial ports available on the system.
String NameSerialPortAt(int index)
Returns the name of the serial port corresponding to the specified index.
void KillArduinoConnection()
Terminates the established connection between Arduino and Java, releasing the resources used.
For complete documentation and usage examples, visit:
PanamaHitek Arduino Library