Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8387567
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T18:14:52+00:00 2026-06-09T18:14:52+00:00

How do I make communications go between Arduino Uno and a Java app? I’ve

  • 0

How do I make communications go between Arduino Uno and a Java app?

I’ve found Arduino and Java, but that’s not clear to me.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T18:14:54+00:00Added an answer on June 9, 2026 at 6:14 pm

    Ok, I’ll modify the same code to help you understand. (I’ll remove the listener and add a substitution, which is not good. You should use the listener)

    import java.io.IOException;
    import java.io.InputStream;
    import java.io.OutputStream;
    import gnu.io.CommPortIdentifier;
    import gnu.io.SerialPort;
    import gnu.io.SerialPortEvent;
    import gnu.io.SerialPortEventListener;
    import java.util.Enumeration;
    
    public class SerialTest implements SerialPortEventListener {
    
        SerialPort serialPort;
        private static final String PORT = "COM32";
        private InputStream input;
        private OutputStream output;
        private static final int TIME_OUT = 2000;
        private static final int DATA_RATE = 9600;
    
        public void initialize() {
            CommPortIdentifier portId = null;
            Enumeration portEnum = CommPortIdentifier.getPortIdentifiers();
            while (portEnum.hasMoreElements()) {
                CommPortIdentifier currPortId = (CommPortIdentifier) portEnum.nextElement();
                if (currPortId.getName().equals(PORT)) {
                    portId = currPortId;
                    break;
                }
            }
            if (portId == null) {
                System.out.println("Could not find COM port.");
                return;
            }
            try {
                // open serial port, and use class name for the appName.
                serialPort = (SerialPort) portId.open(this.getClass().getName(),
                        TIME_OUT);
    
                // set port parameters
                serialPort.setSerialPortParams(DATA_RATE,
                        SerialPort.DATABITS_8,
                        SerialPort.STOPBITS_1,
                        SerialPort.PARITY_NONE);
    
                // open the streams
                input = serialPort.getInputStream();
                output = serialPort.getOutputStream();
            } catch (Exception e) {
                System.err.println(e.toString());
            }
        }
    
        /**
         * This should be called when you stop using the port.
         * This will prevent port locking on platforms like Linux.
         */
        public synchronized void close() {
            if (serialPort != null) {
                serialPort.removeEventListener();
                serialPort.close();
            }
        }
    
        public static void main(String[] args) throws Exception {
            SerialTest main = new SerialTest();
            main.start();
        }
    
        public void start() throws IOException {
            initialize();
            System.out.println("Started");
            byte[] readBuffer = new byte[400];
            while (true) {
                int availableBytes = input.available();
                if (availableBytes > 0) {
                    // Read the serial port
                    input.read(readBuffer, 0, availableBytes);
                    // Print it out
                    System.out.print(new String(readBuffer, 0, availableBytes));
                }
            }
        }
    }
    

    Run this and load a code to Arduino which write to the serial. Then those values will be displayed by the program. (you may need to change the PORT accordingly)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

what's the best way to make communications between page widgets residing on differents ViewPart?
I make an app that have to printing image. I need to print image
My goal is to make a secure communication between a Java server and client
I'm trying to make a communication between a PHP page and running Java server.
I want to make the communication between native app and web app in android.How
I'm new to JSP and netbeans, I'm trying to make a simple communication between
Is that worth it to use some JS encryption library to make safe communication
I make a bot program and i want to send some keyboard keys between
As a seasoned Spring user I was assuming that Spring Integration would make the
Is it a requirement that RESTful interactions occur between physically separate clients and servers?

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.