Greetings, I am interested in transmitting a string to the arduino from my computers com port with Java. Right now I am using this :
code to receive, and this works well. Can someone show me the example code to output a string? The article itself says :
"Transmitting data to the arduino from the computer. In my experience, it seems that the Serial connection must be connected somewhere above 1 second (I have 1.5 seconds in my program) before a transmission can be made. It seems that for at least the atmega168 and diecimila, doing so ensures your transmission actually is transmitted. For doing that, Thread.sleep(delay) is used and delay is specified in milliseconds so I would use Thread.sleep(1500) after the Serial port is established. It seems this might be due to the program resetting when a serial connection is made, and the program has a necessary setup time.
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!"). There's also one that'll send an integer value and another that will transmit an array of Bytes.
I found on the arduino's program, to accurately receive the data instead of receiving non-intelligible "255" data points, I had to maintain a generous delay between the Serial.read() commands. I ended up using 20 ms for safe measure, but the actual necessary number is likely much lower and one could use a "255 filter" to extract meaningful data, assuming none of your meaningful data consists of the number 255.
But neglect to show any code. Please help!
Thank you muchly!
The simple Serial.read() function will process a byte at a time, although there are more interesting read functions available. "