cheese5505 cheese5505 - 1 year ago 77
Java Question

Sending data to Arduino Uno with Java

I have just bought an Arduino Uno and I am currently trying to make a flashing LED. I was wondering how I could do this, and I have looked at the Arduino Playground and have found a program to get input. I need to output to the Arduino. It is not possible for me to use anything but Java because I already have another program that requires an Arduino. Please leave any ideas.

Answer Source

EDIT: Kind of sounds like you want to do this in java.

And excerpt from the site mentioned by jayeff:

The OutputStream comes with 3 different write methods to send data from the computer to the Arduino. In the above example, you could use output.write(String) to send data, as in output.write("Hello Arduino!").

If you're trying to use Java to write to the Arduino, then this is your answer.

EDIT: If you want to use something other than Java, here you go:

Ask and you shall receive. You can do this in any programming language that has serial support.

There are certainly other methods for each language, but here are some I found in 5 minutes at the Google Machine

Note: Watch out for the nasty Auto Reset on Serial issue. See my previous answer for more details on that.

Here's my C++ Code (it's ugly but it works)

#include <SerialStream.h>
#include <iostream>
#include <string>
#include <stdio.h>
#include <stdlib.h>

using namespace std;
class SerialComm {
    LibSerial::SerialStream myss;

    SerialComm(int argc, char** argv) {
        myss = new LibSerial::SerialStream("/dev/ttyS0", ios_base::out);

        const int Dsize = 2;
        char buffer[1];
        buffer[0] = 125; //0b00000001;
        buffer[1] = '\0';
        //myss << buffer;

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download