Java library for serial communication between Java applications and Arduino boards with data visualization and export capabilities
The PanamaHitek_Arduino library provides comprehensive real-time visualization components using JFreeChart. It includes dial charts, thermometer displays, and time-series plots that can automatically follow Arduino data streams or be updated manually.
// Single dial chart types
public static final int ROUND_DIAL_CHART = 1;
public static final int HORIZONTAL_DIAL_CHART = 2;
public static final int VERTICAL_DIAL_CHART = 3;
// Dual dial positions
public static final int OUTER_DIAL = 1;
public static final int INNER_DIAL = 2;
public static final int LEFT_DIAL = 1;
public static final int RIGHT_DIAL = 2;
// Thermometer plot types
public static final int ROUND_DIAL_PLOT = 1;
public static final int HORIZONTAL_DIAL_PLOT = 2;
public static final int VERTICAL_DIAL_PLOT = 3;The PanamaHitek_SingleDialChart class provides single-dial gauge visualization with multiple display modes and color zones.
public class PanamaHitek_SingleDialChart {
public PanamaHitek_SingleDialChart(int chartType);
public PanamaHitek_SingleDialChart(int chartType, String chartTitle);
public PanamaHitek_SingleDialChart(int chartType, String chartTitle, String variableName);
}Parameters:
chartType - Type of dial chart (ROUND_DIAL_CHART, HORIZONTAL_DIAL_CHART, or VERTICAL_DIAL_CHART)chartTitle - Title displayed on the chartvariableName - Name of the variable being displayedpublic void setChartTitle(String title);
public void setChartVariableName(String variableName);
public void setChartLimitValues(int minValue, int maxValue);
public void setChartMajorDivisions(int majorDivisions);
public void setChartMinorDivisions(int minorDivisions);
public void setColorDistribuition(int firstArea, int secondArea, int thirdArea) throws Exception;Color Distribution:
firstArea - Percentage for first color zone (typically green/good)secondArea - Percentage for second color zone (typically yellow/warning)thirdArea - Percentage for third color zone (typically red/critical)public void setValue(double value);Updates the dial value in real-time.
public JPanel getChartPanel();
public void insertToPanel(JPanel panel);public void createArduinoFollowUp(String PORT_NAME, int DATA_RATE) throws ArduinoException, SerialPortException;
public void stopArduinoFollowUp() throws ArduinoException;Usage Example:
import com.panamahitek.liveinterfaces.PanamaHitek_SingleDialChart;
import javax.swing.*;
public class SingleDialExample extends JFrame {
private PanamaHitek_SingleDialChart speedDial;
public void setupSpeedometer() {
// Create round dial speedometer
speedDial = new PanamaHitek_SingleDialChart(
PanamaHitek_SingleDialChart.ROUND_DIAL_CHART,
"Vehicle Speed",
"Speed (km/h)"
);
try {
// Configure dial settings
speedDial.setChartLimitValues(0, 200);
speedDial.setChartMajorDivisions(10);
speedDial.setChartMinorDivisions(5);
// Set color zones: 60% green, 25% yellow, 15% red
speedDial.setColorDistribuition(60, 25, 15);
// Add to GUI
JPanel mainPanel = new JPanel();
speedDial.insertToPanel(mainPanel);
add(mainPanel);
// Start automatic Arduino following
speedDial.createArduinoFollowUp("COM3", 9600);
} catch (Exception ex) {
System.err.println("Speedometer setup error: " + ex.getMessage());
}
}
// Manual update example
public void updateSpeed(double newSpeed) {
speedDial.setValue(newSpeed);
}
}The PanamaHitek_DualDialChart class displays two gauge dials simultaneously, perfect for showing related measurements.
public class PanamaHitek_DualDialChart {
public PanamaHitek_DualDialChart();
public PanamaHitek_DualDialChart(String chartTitle);
public PanamaHitek_DualDialChart(String chartTitle, String variableName);
}public void setPlotTitle(String title);
public void setChartVariableName(String variableName);
public void setChartTopLimitValues(int topValue1, int topValue2);
public void setChartBottonLimitValues(int topValue1, int topValue2);
public void setChartMajorDivisions(int valueChart1, int valueChart2);
public void setChartMinorDivisions(int valueChart1, int valueChart2);public void setValue(double value1, double value2);Updates both dials simultaneously.
public JPanel getChartPanel();
public void insertToPanel(JPanel panel);
public void createArduinoFollowUp(String PORT_NAME, int DATA_RATE) throws ArduinoException, SerialPortException;
public void stopArduinoFollowUp() throws ArduinoException;Usage Example:
import com.panamahitek.liveinterfaces.PanamaHitek_DualDialChart;
public class DualDialExample {
public void setupTemperatureHumidity() {
PanamaHitek_DualDialChart climate = new PanamaHitek_DualDialChart(
"Climate Monitor", "Temperature & Humidity");
// Configure ranges for temperature (-10 to 50°C) and humidity (0 to 100%)
climate.setChartTopLimitValues(50, 100);
climate.setChartBottonLimitValues(-10, 0);
climate.setChartMajorDivisions(6, 10);
climate.setChartMinorDivisions(2, 2);
try {
// Start Arduino data following (expects 2 values per message)
climate.createArduinoFollowUp("COM3", 9600);
// Manual update example
climate.setValue(23.5, 65.2); // 23.5°C, 65.2% humidity
} catch (Exception ex) {
System.err.println("Climate monitor error: " + ex.getMessage());
}
}
}The PanamaHitek_ThermometerChart class provides thermometer-style visualization with temperature unit support.
public class PanamaHitek_ThermometerChart {
public PanamaHitek_ThermometerChart();
public PanamaHitek_ThermometerChart(String plotTitle);
}public void setChartLimitValues(int minValue, int maxValue);
public void setColorDistribuition(int firstArea, int secondArea, int thirdArea) throws Exception;
public void setThermometerUnit(int unit);Temperature Units:
public void setValue(double value);
public JPanel getPlotPanel();
public void insertToPanel(JPanel panel);
public void createArduinoFollowUp(String PORT_NAME, int DATA_RATE) throws ArduinoException, SerialPortException;
public void stopArduinoFollowUp() throws ArduinoException;Usage Example:
import com.panamahitek.liveinterfaces.PanamaHitek_ThermometerChart;
import org.jfree.chart.plot.ThermometerPlot;
public class ThermometerExample {
public void setupTemperatureMonitor() {
PanamaHitek_ThermometerChart tempChart = new PanamaHitek_ThermometerChart("Room Temperature");
try {
// Configure temperature range (0-50°C)
tempChart.setChartLimitValues(0, 50);
// Set color zones: 40% blue (cold), 40% green (normal), 20% red (hot)
tempChart.setColorDistribuition(40, 40, 20);
// Set temperature unit to Celsius
tempChart.setThermometerUnit(ThermometerPlot.UNITS_CELSIUS);
// Start automatic updates from Arduino
tempChart.createArduinoFollowUp("COM3", 9600);
} catch (Exception ex) {
System.err.println("Temperature monitor error: " + ex.getMessage());
}
}
}The PanamaHitek_TimeLineChart class creates time-series line plots that can display multiple data series from a data buffer.
public class PanamaHitek_TimeLineChart {
public PanamaHitek_TimeLineChart();
}public void setDataBuffer(PanamaHitek_DataBuffer buffer) throws Exception;
public void setDataBuffer(PanamaHitek_DataBuffer buffer, int index) throws Exception;
public void setDataBuffer(PanamaHitek_DataBuffer buffer, Integer[] bufferIndexes) throws Exception;Parameters:
buffer - Data buffer containing time-series dataindex - Single column index to plotbufferIndexes - Array of column indexes to plot multiple seriespublic void setChartTitle(String title);
public void setAxisTitle(String titleAxisX, String titleAxisY);
public void setTimeAxisFormat(SimpleDateFormat format);
public void setDateAxisVerticalLabel(boolean flag);
public void setMaximumItemCount(int itemCount) throws Exception;public void setLineColor(int serieIndex, Color color) throws Exception;
public void setLineThickness(int serieIndex, int thickness) throws Exception;
public void setLineStroke(int serieIndex, Stroke stroke) throws Exception;
public void setBackgroundColor(Color color);
public void setGridLinesColor(Color color);
public void setGridLinesVisible(boolean visible);
public void setLinesMarksVisible(boolean visible);public void setHorizontalAxisRange(double lower, double upper);
public void setVerticalAxisRange(double lower, double upper);
public JPanel getChartPanel();
public void insertToPanel(JPanel panel);
public JFreeChart getChartObject();
public void cleanDataSeries();Complete Usage Example:
import com.panamahitek.liveinterfaces.PanamaHitek_TimeLineChart;
import com.panamahitek.PanamaHitek_DataBuffer;
import java.awt.Color;
import java.text.SimpleDateFormat;
public class TimeLineExample extends JFrame {
private PanamaHitek_TimeLineChart timeChart;
private PanamaHitek_DataBuffer dataBuffer;
public void setupTimeSeriesChart() {
// Setup data buffer
dataBuffer = new PanamaHitek_DataBuffer();
dataBuffer.setDateFormat("HH:mm:ss");
try {
// Define data structure
dataBuffer.addTimeColumn(0, "Time");
dataBuffer.addColumn(1, "Temperature", Double.class);
dataBuffer.addColumn(2, "Pressure", Double.class);
dataBuffer.addColumn(3, "Humidity", Double.class);
// Create time-series chart
timeChart = new PanamaHitek_TimeLineChart();
// Configure chart appearance
timeChart.setChartTitle("Environmental Monitoring");
timeChart.setAxisTitle("Time", "Values");
timeChart.setTimeAxisFormat(new SimpleDateFormat("HH:mm:ss"));
// Set data buffer to plot columns 1, 2, 3 (temperature, pressure, humidity)
timeChart.setDataBuffer(dataBuffer, new Integer[]{1, 2, 3});
// Customize line appearance
timeChart.setLineColor(0, Color.RED); // Temperature - red
timeChart.setLineColor(1, Color.BLUE); // Pressure - blue
timeChart.setLineColor(2, Color.GREEN); // Humidity - green
timeChart.setLineThickness(0, 2);
timeChart.setLineThickness(1, 2);
timeChart.setLineThickness(2, 2);
// Configure display options
timeChart.setGridLinesVisible(true);
timeChart.setLinesMarksVisible(true);
timeChart.setMaximumItemCount(100); // Keep last 100 points
// Add to GUI
JPanel chartPanel = new JPanel();
timeChart.insertToPanel(chartPanel);
add(chartPanel);
// Start data collection simulation
startDataCollection();
} catch (Exception ex) {
System.err.println("Time chart setup error: " + ex.getMessage());
}
}
private void startDataCollection() {
// Simulate real-time data collection
new Thread(() -> {
try {
while (true) {
// Add simulated sensor data
double temp = 20 + Math.random() * 10; // 20-30°C
double pressure = 1000 + Math.random() * 50; // 1000-1050 hPa
double humidity = 50 + Math.random() * 30; // 50-80%
dataBuffer.addValue(1, temp);
dataBuffer.addValue(2, pressure);
dataBuffer.addValue(3, humidity);
dataBuffer.printRow();
Thread.sleep(1000); // Update every second
}
} catch (Exception ex) {
System.err.println("Data collection error: " + ex.getMessage());
}
}).start();
}
}import com.panamahitek.PanamaHitek_Arduino;
import com.panamahitek.liveinterfaces.*;
import jssc.*;
public class ComprehensiveVisualizationExample {
private PanamaHitek_Arduino arduino;
private PanamaHitek_SingleDialChart temperatureGauge;
private PanamaHitek_DualDialChart pressureHumidityDials;
private PanamaHitek_TimeLineChart trendChart;
public void setupCompleteVisualization() {
try {
// Setup Arduino connection
arduino = new PanamaHitek_Arduino();
arduino.arduinoRX("COM3", 9600, new SerialPortEventListener() {
@Override
public void serialEvent(SerialPortEvent event) {
processArduinoData();
}
});
// Setup temperature gauge
temperatureGauge = new PanamaHitek_SingleDialChart(
PanamaHitek_SingleDialChart.ROUND_DIAL_CHART,
"Temperature", "°C"
);
temperatureGauge.setChartLimitValues(-10, 50);
temperatureGauge.setColorDistribuition(60, 30, 10);
// Setup pressure/humidity dual dial
pressureHumidityDials = new PanamaHitek_DualDialChart(
"Pressure & Humidity", "Environmental"
);
pressureHumidityDials.setChartTopLimitValues(1100, 100);
pressureHumidityDials.setChartBottonLimitValues(900, 0);
// Setup trend chart with data buffer
setupTrendChart();
} catch (Exception ex) {
System.err.println("Visualization setup error: " + ex.getMessage());
}
}
private void processArduinoData() {
try {
if (arduino.isMessageAvailable()) {
String data = arduino.printMessage();
// Parse: "TEMP:25.3,PRESS:1013.2,HUM:65.4"
updateVisualizations(parseData(data));
}
} catch (Exception ex) {
System.err.println("Data processing error: " + ex.getMessage());
}
}
private void updateVisualizations(SensorData data) {
// Update individual gauges
temperatureGauge.setValue(data.temperature);
pressureHumidityDials.setValue(data.pressure, data.humidity);
// Add to trend chart data buffer
// (Implementation depends on your specific data buffer setup)
}
// Helper class for sensor data
private static class SensorData {
double temperature, pressure, humidity;
}
private SensorData parseData(String rawData) {
// Implementation for parsing Arduino data format
SensorData data = new SensorData();
// ... parsing logic
return data;
}
}Install with Tessl CLI
npx tessl i tessl/maven-com-panamahitek--panama-hitek-arduino