Send Data from a PC to an Arduino with Java

Поделиться
HTML-код
  • Опубликовано: 7 июл 2024
  • Here's how to send data from your PC to an Arduino. This project is a simple clock that shows the PC's time and date on a 16x2 character LCD attached to an Arduino. We use Java to write a minimalist GUI that lets the user select the Arduino's COM port, and then the PC just streams the current date and time to the Arduino over USB.
    Source code:
    Software - farrellf.com/arduino/LcdClock....
    Firmware - farrellf.com/arduino/LcdClockF...
    IMPORTANT: If you have not seen my previous video on serial communication, check it out. That video covers all of the basics, and shows how to install all of the software you need.
    • Graph Arduino Sensor D...
  • НаукаНаука

Комментарии • 99

  • @SmallSoldierX
    @SmallSoldierX 6 лет назад +1

    Very good tutorial man! Thank you very much for that. Now I can sync my RTC module without needing to manually write each value and estimate the time of upload to eliminate difference caused by various compiling/uploading times. It took me half a day to understand and modify your code, but now it's written and I can reuse it every time, when the RTC module collect some delay over time.

  • @saahiththiyanmathivathanan7135
    @saahiththiyanmathivathanan7135 6 лет назад +1

    Just the video i was looking for. Thanks mate!

  • @deant6168
    @deant6168 7 лет назад

    been looking for this code for a university project you do amazing work thank you

  •  8 лет назад +2

    Really great explanation and exactly the information I needed. Thanks

  • @maartenvd84
    @maartenvd84 7 лет назад +1

    Thanks! Was a good starting point!

  • @Cptnbond
    @Cptnbond 5 лет назад

    Another great video, thanks. I like the way you comment and explain the java-code. Now just looking for how to get real-time data from Arduino without the USB-cable attached. I'm sure you have made a video for that as well.

  • @ghasemzolfaghari
    @ghasemzolfaghari 8 лет назад +1

    very compelete.
    thanks alot

  • @bahalphaamadou1639
    @bahalphaamadou1639 8 лет назад +1

    Thanks you so much for these video it really helpfull and easy to understand

  • @armandramones8916
    @armandramones8916 4 года назад +1

    Awesome! Thanks for sharing.

  • @rbnlight
    @rbnlight 6 лет назад +1

    That was great! Many thanks

  • @radityoperwianto1339
    @radityoperwianto1339 5 лет назад +1

    I really appreciate it bro...

  • @thomaslin66
    @thomaslin66 8 лет назад +1

    Very, very appreciate sir.

  • @SantoshSahu-nd1bw
    @SantoshSahu-nd1bw 5 лет назад

    your videos are really helpful
    sir, please make videos on RFID READER using java
    thanks in advance

  • @downmaster2154
    @downmaster2154 5 лет назад +1

    Really helpful video.
    Could you please tell me how to send a string instead of date in order to control something via Arduino.(I only need to know the java part)
    Thanks in advance

  • @temirkhanamanbaev42
    @temirkhanamanbaev42 9 лет назад +1

    Excellent.

  • @darrinmcland4236
    @darrinmcland4236 7 лет назад

    worked perfectly, only issue was I created class main, and had to change it to LCD
    I am attempting to use a 2.8 inch TFT display.
    I can assume, that the process of reading the string is the same,
    I will include the tft.h file and have to know my coordinates on the display
    Ill let you know
    thank you

  • @jenterl
    @jenterl 7 лет назад

    Could you do a video where you create a basic radio button or data entry Java program that sends the data (ex. radio button = led and data is displayed on LCD) to the Arduino. Would the Arduino store the setting you send once you remove the USB connection or powered off the circuit? This would be for a datalogger that could have settings for time or event triggers based on sunlight (i.e. turn on pump to water plant), but would not have to be recompiled each time a setting is changed.

  • @alirezaghaderi
    @alirezaghaderi 8 лет назад

    doest it work if i want to send and receive at the same time?

  • @abhishekkumarjha4751
    @abhishekkumarjha4751 8 лет назад

    I want to rotate servo motor by using the output of Java code(suppose if output will be 1 it should rotate clockwise and for 0 it should rotate anti clockwise) how to do it??

  • @Hotwire_RCTrix
    @Hotwire_RCTrix 7 лет назад

    Reconnecting locks-up the program and requires jaraw.exe process killed. Does this occur for you?

  • @nildhamecha9746
    @nildhamecha9746 5 лет назад

    You used Object Printwriter to send text to the arduino, what if i only wanted to send ints, what object would i used then?

  • @MsJohnK1
    @MsJohnK1 8 лет назад

    Very helpful video. Thanks. I want to ask- I started to make a Java program to operate signal generator and read data from my oscilloscope. I am pretty newbe in Java programming and I got as far as to design the graphical interface, connecting to ports, validate my input data etc. Now the hard part - what do I need to be able to communicate with those two devices? The devices they both have USB ports. Will he PrintWrier in this case work too?? (I have list of command for my SG) ? I got a bit stuck on this. Thank you for your advice. Regards,

    • @upgrdman
      @upgrdman  8 лет назад

      +MrJohnK1 Many USB devices use custom protocols. You could check with the manufacturer of your devices to see if they offer any technical details, but they probably wont. Good luck.

  • @mayukhgoswami7480
    @mayukhgoswami7480 4 года назад

    Can you make a video for lighting up an LED using java eclipse

  • @euklid216
    @euklid216 7 лет назад

    Thank you for this video, I got it working.
    Just one thing: Is there any way to get rid of the flicker? As far as I can tell it's related to the second Thread.sleep.

    • @euklid216
      @euklid216 7 лет назад

      Never mind, I fixed it by not clearing the display at all. Apparently, you don't need to do it for this to work.

  • @rob5580
    @rob5580 5 лет назад +1

    Thanks bro

  • @keshavdk3080
    @keshavdk3080 8 лет назад

    Nice explanation. I have interfaced Arduino Uno with ESP8266-01 and 16*2 LCD. Now i wanted to send text typed from webpage. Can you please have a look ?

  • @vnb10kke
    @vnb10kke 6 лет назад

    Hi,is it possible to send production counter from pc to ardunio and to led dot matrix.display.

  • @dushanindunil500
    @dushanindunil500 3 года назад

    sir , could you suggest me a online course to follow for java for robotics control ?

  • @seeufx
    @seeufx 6 лет назад +1

    很好!👍

  • @HarunRahmi
    @HarunRahmi 5 лет назад

    Can you do it simple?

  • @johncarlooporto7353
    @johncarlooporto7353 8 лет назад

    Thank you sir! I would like to respectfully request that maybe you can make a tutorial on how to send text message using Arduino and a GSM module in Java? Hope you consider sir. Thank you!

    • @upgrdman
      @upgrdman  8 лет назад

      +Carlok Oporto Thanks for the feedback. I'll keep that in mind for future projects.

  • @lamiriahmed7058
    @lamiriahmed7058 8 лет назад

    does it works with android studio !!

  • @Harsha_AI
    @Harsha_AI 5 лет назад

    Iam trying to build my own CNC. But I have a problem. If I connect Arduino uno to my PC an error msg dispaly like " error opening connection (jssc.serialportexception): port name - method name - openport(); exception type - port busy." Please tell me how to clear this error. May I know the meaning of this type of error.
    Thank you

  • @abzounsaid6227
    @abzounsaid6227 5 лет назад

    i wanna to connect a vibration sensor to java application

  • @hassanel-khatib7634
    @hassanel-khatib7634 8 лет назад +1

    Hello,is it possible to send data from arduino to pc and send back from pc to arduino in the same time? if yes,how? Thank's!

  • @lumennganje2721
    @lumennganje2721 6 лет назад +2

    Wow this is great. I honestly think more of this will multivate young talents to engage in AI

  • @Sandpiper131
    @Sandpiper131 8 лет назад

    Is there a way to control servos from java and if you can are there any tutorials or source code that you have that can point me in the right direction?

    • @upgrdman
      @upgrdman  8 лет назад

      +Sandpiper131 Hi. It should be fairly easy but I don't have enough time right now to try it. I'll keep it in mind for future videos. It's probably something like having the PC send a number to the Arduino, and having the Arduino pass that on to a Servo.write() call.

    • @Sandpiper131
      @Sandpiper131 8 лет назад

      +upgrdman That's what I was thinking but I still don't understand quite how to do that. Thank you for taking it into consideration. I will have to watch this video over again and try to figure it out. Thanks for the help.

  • @uweschlenker9564
    @uweschlenker9564 6 лет назад

    Thanks for the very good training videos. I can follow the excercises "Send Data from a PC to an Arduino with Java" and "Graph Arduino Sensor Data with Java and JFreeChart". But since a couple of time I am working on a communication sending data from Java to Arduino, Receiving data from Arduino with Java, sending, receiving, sending, receiving and so on. I believe it is called the hand shake problem. So I wand to read with the Arduino a LDR, sending the value to a Java-program. Depending on the received LDR-number Java decide wich LED should switched on. This information should send from Java to the Arduino. And so on. This should be done with the SerialPort of jSerialComm. But it will not run at me. Can anybody help please?
    Bye Uwe

  • @youseflv
    @youseflv 3 года назад

    How can we set BuadRate on code ?

  • @makarioss
    @makarioss 5 лет назад

    hi thanks for your email. I have started learning Java in the last months and through the anduido ,I have seen the potential to develop do a number of different of interesting projects like yours. However I don't how to program this controller. Thus I would like to give me some references like books or tutorias which I could use the anduido with Java. thanks

  • @sandaruwanlakjeewa5491
    @sandaruwanlakjeewa5491 8 лет назад +1

    Can I do this using bluetooth module

  • @jeanshirimpaka8095
    @jeanshirimpaka8095 7 лет назад

    In order to receive data on arduino side, what method are you using?

    • @upgrdman
      @upgrdman  7 лет назад

      Hi. There's a link to the firmware in the video description. Serial.readString() is used.

    • @fettagrabbar2648
      @fettagrabbar2648 5 лет назад

      @@upgrdman but what if I wnat to send a integer how do you do that?

  • @soniaantao7468
    @soniaantao7468 8 лет назад

    hello, i'm a student and i really need a little help on this please:
    i have watched all your videos (congrats btw, it was very helpfull) thought i can't do what i really need.
    i have a arduino uno. i put a code there (which i created) and on the code i made a while cycle that expect the user to clic the "x" in order to arduino print out the values.
    therefore what i'm asking you is that if you can show me how can i use this code that u made but sending an "x" first and then reading from arduino? please?
    i already used your first code video, which was great for this. it has open the port, however don't print anything because i need to send an "x" to arduino in order to receive all the 1000 values...
    i don't need graphical windows, i just need to print my values :( ...
    can u please help me??

  • @sime3250
    @sime3250 8 лет назад

    I want to be able to send it text (like RED) to toggle leds , as were currently using javascript in school , could i use : " prompt("Color","RED"); " to send my text ?!?

    • @upgrdman
      @upgrdman  8 лет назад

      +SIME_LP As far as I know, Javascript has no way to communicate with a USB port. You would need to setup a web server on the Arduino (with an ESP8266 or something similar) if you want to interact with it via Javascript.

    • @sime3250
      @sime3250 8 лет назад

      +upgrdman thats not what i tryed to ask ... Does prompt work in that eclipse or what should i use to replace it ???

    • @PhilippZwei
      @PhilippZwei 8 лет назад

      +SIME_LP "prompt" is a Javascript command. And Javascript and Java are totally different things. Javascript runs in a Webbrowser and Java runs direct on the Operating system (i.e. Windows). So you can't call a Javascript function from Java.

    • @mayonasalspray1898
      @mayonasalspray1898 8 лет назад

      +SIME_LP use the jframe Java library (it comes with the jdk) just look up Java jframe user input on google because I'm lazy and I don't want to type the code in the comments XD

  • @Samooh616
    @Samooh616 7 лет назад

    I copied your exact code and it's not working. The weird thing is is that my tx light starts blinking when I press connect, while it should be the rx light that's blinking right?

    • @jackieboi5275
      @jackieboi5275 Год назад

      Hey, the same thing is happening to me, so I decided to look in the comments and I found this comment. Did you figure it out?

  • @darrinmcland4236
    @darrinmcland4236 7 лет назад

    got this to work with TFT it scrolls but works
    your java code and this arduino uno
    #include
    #include
    #include
    char buffer[50];
    byte index;
    void setup ()
    {
    Serial.begin (9600);
    TFT_BL_ON; // turn on the background light
    Tft.TFTinit(); // init TFT library
    } // end of setup
    void loop () {
    index = 0;
    while (Serial.available () > 0) {
    char inChar = (char)Serial.read(); // receive a byte as character
    buffer[index++] = inChar; // Store the character and advance the pointer
    buffer[index] = '
    '; // NULL terminate the string
    // All the received data is now in buffer. Send it to the TFT
    }
    Tft.drawString(buffer,0,2,3, WHITE);
    delay(900);
    Tft.drawString(buffer,0,2,3, BLACK);
    }

  • @matricsneo
    @matricsneo 8 лет назад

    Hi I am a newbie in terms of connecting arduino to java.... I tried doing all your tutorials specially what is in this video however when I tried to run the java app I'm getting this error...
    Exception in thread "main" java.lang.Error: Unresolved compilation problem:
    at lcdClock.LcdClock.main(LcdClock.java:17)
    I double checked everything on my eclipse java file and everything is what it should be according to your video... Could you please help me with this?

    • @upgrdman
      @upgrdman  8 лет назад +1

      +simond caesar Semblante Hi. An "unresolved compilation problem" means there is a problem with the syntax of your code. It's probably something simple -- a missing semicolon, a misspelled identifier, etc. If you can't figure it out, please pastebin the entire page of code.

    • @matricsneo
      @matricsneo 8 лет назад

      +upgrdman its pretty much the same code u posted...
      import java.awt.BorderLayout;
      import java.awt.event.ActionEvent;
      import java.awt.event.ActionListener;
      import java.io.PrintWriter;
      import java.text.SimpleDateFormat;
      import java.util.Date;
      import javax.swing.JButton;
      import javax.swing.JComboBox;
      import javax.swing.JFrame;
      import javax.swing.JPanel;
      import com.fazecast.jSerialComm.SerialPort;
      public class LcdClock {
      static SerialPort chosenPort;
      public static void main(String[] args) {
      // create and configure the window
      JFrame window = new JFrame();
      window.setTitle("Arduino LCD Clock");
      window.setSize(400, 75);
      window.setLayout(new BorderLayout());
      window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
      // create a drop-down box and connect button, then place them at the top of the window
      JComboBox portList = new JComboBox();
      JButton connectButton = new JButton("Connect");
      JPanel topPanel = new JPanel();
      topPanel.add(portList);
      topPanel.add(connectButton);
      window.add(topPanel, BorderLayout.NORTH);
      // populate the drop-down box
      SerialPort[] portNames = SerialPort.getCommPorts();
      for(int i = 0; i < portNames.length; i++)
      portList.addItem(portNames[i].getSystemPortName());
      // configure the connect button and use another thread to send data
      connectButton.addActionListener(new ActionListener(){
      @Override public void actionPerformed(ActionEvent arg0) {
      if(connectButton.getText().equals("Connect")) {
      // attempt to connect to the serial port
      chosenPort = SerialPort.getCommPort(portList.getSelectedItem().toString());
      chosenPort.setComPortTimeouts(SerialPort.TIMEOUT_SCANNER, 0, 0);
      if(chosenPort.openPort()) {
      connectButton.setText("Disconnect");
      portList.setEnabled(false);
      // create a new thread for sending data to the arduino
      Thread thread = new Thread(){
      @Override public void run() {
      // wait after connecting, so the bootloader can finish
      try {Thread.sleep(100); } catch(Exception e) {}
      // enter an infinite loop that sends text to the arduino
      PrintWriter output = new PrintWriter(chosenPort.getOutputStream());
      while(true) {
      output.print(new SimpleDateFormat("hh:mm:ss a MMMMMMM dd, yyyy").format(new Date()));
      output.flush();
      try {Thread.sleep(100); } catch(Exception e) {}
      }
      }
      };
      thread.start();
      }
      } else {
      // disconnect from the serial port
      chosenPort.closePort();
      portList.setEnabled(true);
      connectButton.setText("Connect");
      }
      }
      });
      // show the window
      window.setVisible(true);
      }
      }
      I tried tracing it myself but like I said I am still in the learning stages so can't find it.. Hehehe.. Thanks for the very quick reply m8t... And thanks for the video tutorials... really helped a lot in my studies...

    • @matricsneo
      @matricsneo 8 лет назад

      +upgrdman Oh never mind... I found out the problem.. hahahah.. I placed the java file on the wrong folder... I got it to work now literally just second after I gave up and posted the code here... ahahhah... Thanks again!

    • @upgrdman
      @upgrdman  8 лет назад +1

      +simond caesar Semblante Sure, glad it worked out.

  • @jairojunoth
    @jairojunoth 8 лет назад

    Hey man, are you developing on Windows for some reason?

    • @upgrdman
      @upgrdman  8 лет назад

      +Jairo Junot Hi. I use a mix of Linux, Mac OS and Windows. Most of my videos are done with Windows since it seems to be more common with my viewers.

  • @subhampatro3342
    @subhampatro3342 8 лет назад

    Hello Sir, I am a beginner in this field. I tried copy pasting your program but I am getting two errors. They are "Cannot refer to a non-final variable portList inside an inner class defined in a different method" and "Cannot refer to a non-final variable connectButton inside an inner class defined in a different method".
    Can you please help me figure out what they are and how to remove them?

    • @upgrdman
      @upgrdman  8 лет назад

      +Subham Patro Not really sure how your code is laid out. Try starting with just the code I posted, then modifying it progressively to fit your needs.

    • @subhampatro3342
      @subhampatro3342 8 лет назад

      Sir, I am using the same code as yours and it was giving me these errors...Is it because I am using eclipse Indigo?

    • @upgrdman
      @upgrdman  8 лет назад

      +Subham Patro Might be. More importantly, make sure you are using a recent version of Java.

  • @samirmaliqi1253
    @samirmaliqi1253 5 лет назад

    20:46 - mm isn't month but minutes

  • @katembovictor7710
    @katembovictor7710 8 лет назад

    please can you add zoom in your code

    • @upgrdman
      @upgrdman  8 лет назад

      +katembo victor Thanks for the comment. So you want the screen recording software to zoom in on the code region? Sure, I'll keep that in mind for future videos.

    • @katembovictor7710
      @katembovictor7710 8 лет назад

      think you!!!!

  • @Dzatoah
    @Dzatoah 8 лет назад

    It doesnt work for me.
    The arduino does not recognize...
    When i try it with the Arduino Programm software then it works.
    if(text == "sets01maunzi"){
    digitalWrite(p0,HIGH);
    }
    if(text == "sets00maunzi"){
    digitalWrite(p0,LOW);
    }
    private static void sendToArduino(String string,SerialPort s) {
    System.out.println("Sending: "+string);
    OutputStream os = chosenPort.getOutputStream();
    PrintWriter p = new PrintWriter(os);
    p.print(string);
    p.flush();
    p.close();
    try {
    os.close();
    } catch (IOException e) {System.out.println("ERROR!");}
    }

    • @upgrdman
      @upgrdman  8 лет назад

      +DanielsLPecke Hi. I'm not sure. If you have a logic analyzer or oscilloscope you could check to see exactly what is being sent by your PC. You could also check some basic stuff, like making sure your Java program is connecting to the correct COM port, or wire up the Arduino as a loopback, etc.

    • @Dzatoah
      @Dzatoah 8 лет назад

      How do i check what my PC sends?

    • @upgrdman
      @upgrdman  8 лет назад

      +DanielsLPecke With a logic analyzer or oscilloscope. Probe the TX and RX lines.

    • @Dzatoah
      @Dzatoah 8 лет назад

      I found the Error.
      My Windows restarts the Arduino when i open the COM-Port.
      SO NOW IT WORKS.
      Its so frustrating.. it works on Ubuntu.

    • @upgrdman
      @upgrdman  8 лет назад

      +DanielsLPecke If your Arduino restarts when connecting to it, just wait a second before you "talk" to it, and everything should be fine. This will give your Arduino time to start back up and run your sketch. In order words, have your Java program open the COM port, then have your Java program wait a second, then start using the COM port. You can wait for one second in Java with "try {Thread.sleep(1000);} catch(Exception e){}". Good luck!

  • @maniad4203
    @maniad4203 2 года назад

    ❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤

  • @princejoogie
    @princejoogie 5 лет назад

    runs windows on a mac

  • @pierresamaha8402
    @pierresamaha8402 5 лет назад

    waw

  • @samhess3964
    @samhess3964 8 лет назад

    That is NOT Java. That is c++ or c

    • @upgrdman
      @upgrdman  8 лет назад

      What? It most certainly is Java. Look at the code:
      farrellf.com/arduino/LcdClock.java