Show Posts
Pages: [1]
1  Using Arduino / Interfacing w/ Software on the Computer / Re: Udpsend -> WIFI -> Arduino LOW COST on: April 07, 2013, 07:15:14 pm
If it does not have to be standalone, you can use a computer and transfer commands via serial usb. I am working on it right now but am having trouble communication from computer to arduino but not the other way around.
2  Using Arduino / Interfacing w/ Software on the Computer / Re: Blank serial char[] from Java on: April 07, 2013, 07:12:44 pm
Per suggestion of a friend. I changed the read from (in, 10) to (in, Serial.avialable()) and has not changed any results.
3  Using Arduino / Interfacing w/ Software on the Computer / Blank serial char[] from Java on: April 07, 2013, 04:34:13 pm
I am using a Arduino Uno.  I am experiencing weird behavior with Serial.readbytes();

My currently Arduino code looks like this, the delays are so I can start and stop my java service and look at the serial window in the Arduino IDE, in is a char array;
Code:
void loop() {

       //Get Command
        if (Serial.available() > 0) {
                // read the incoming byte:
               
               Serial.readBytes(in, 10);
               delay(5000);
               Serial.print("I got this ->");
               Serial.print(in);
               Serial.println("<-");
                //newin = true;
               
        }
        delay(5000);
        Serial.println("delay");
       
        Serial.println(in);
       
}

Here is the relevant code for my java side. I modified it from, http://rxtx.qbang.org/wiki/index.php/Two_way_communcation_with_the_serial_port
Code:
public static class SerialWriter implements Runnable
    {
        OutputStream out1;
        DatagramSocket socket = null;
        public byte[] buf = new byte[4];
        public DatagramPacket packet = new DatagramPacket(buf, buf.length);
       
       
        public SerialWriter ( OutputStream out )
        {
            this.out1 = out;
        }
       
        public void run ()
        {
       
        try
        {     
        socket = new DatagramSocket(9876);
        socket.setSoTimeout(1000);
        int c = 5;
        //System.out.print("before");
        byte[] test = ("H567").getBytes();
        this.out1.write(test);
                       
        }
        catch ( IOException e )
        {
        e.printStackTrace();
        }
        }
    }

When I run it my arduino just prints out a blank line. If I prep the arduino with "hiya" using the Serial window first, the when the java is executed it will return back to a blank line. Since the char array is just over-written each time I sent "H567\r\n" and then in the Serial window typed sent "hiya" where the extra newline was still being executed so I know characters are being stored somehow. Another test was to change the last Serial.prinln() to "Serial.println(in[0], DEC)". Using the Serial Window results happen as expected, but from java it just prints out "0"
Serial communication works wonderful coming from the arduino talking to the java, just not from java to the arduino. Any insight would be wonderful!
Pages: [1]