It dont gives any error but arduino wont write char on lcd.
I'm using Arduino UNO
I tried sending string using C# and it worked but how to send string using java? what i have to add/change in my code?
You haven't shown the Java code which opens the serial port, so we have no way of knowing whether you're opening the correct serial port and with the correct parameters.
Does your sketch do what you expected when you send the serial input via the Arduino serial monitor? The sketch doesn't look at all robust and I would have thought that by just accumulating every received character in a String (which is never reset) and then printing the accumulated String to the LCD (without controlling where the cursor is) it would probably go wrong after the first few characters but ought to display at least something, if it's receiving anything.
PeterH:
Does your sketch do what you expected when you send the serial input via the Arduino serial monitor? The sketch doesn't look at all robust and I would have thought that by just accumulating every received character in a String (which is never reset) and then printing the accumulated String to the LCD (without controlling where the cursor is) it would probably go wrong after the first few characters but ought to display at least something, if it's receiving anything.
When i send data from serial monitor it works. it writes characters on lcd (it works is my C# application too but it dont works with java)
No you haven't. You've given us a link to a site where we can find the code you started from, but not your actual code. The code snippet you actually posted didn't include the code to open the port.
No you haven't. You've given us a link to a site where we can find the code you started from, but not your actual code. The code snippet you actually posted didn't include the code to open the port.
That Java code is pretty ugly, but I can't see anything that would stop it working. I suggest you try putting a delay after the output so that (a) it doesn't slam the port closed the moment it's buffered the data for transmission, and (b) it hangs around for long enough for you to receive and print anything that is received back over the serial port. Also, modify the sketch to print out some recognisable string at startup and also print something when it receives something over the serial port, so you can see whether you have forward and reverse comms. (Probably you haven't, but this would prove that and get us a step closer to finding out where the problem is.)
Oh, and put a delay after you have opened the port before you write to it. The Arduino would normally reset when you open the port, and you need to wait long enough for the boot loader to time out and the sketch to finish initialisation before it is ready to receive anything on the serial port.
Java is perfectly usable, but the Java posted was pretty poor. In any case I suspect the problem is not related to the Java language, but just the way the Java program opens the port, immediately writes a single character and then closes the port. Whatever language you implement it in, that isn't going to work.