ascallonisi ascallonisi - 11 months ago 79
Java Question

Java Arduino Serial Read

I'm making a Serial to MIDI interface in Java, with the serial data coming from an Arduino and being processed through the RXTX library.
Unfortunately, using the suggested code from Arduino website link, I'm unable to retrieve the serial data.
The example code uses

on the Arduino side and
on the Java side. In my codeI'm not writing a line through Serial.println, but a MIDI message.


void MIDI_TX(unsigned char MESSAGE, unsigned char PITCH, unsigned char VELOCITY)
status = MESSAGE + midichannel;

I tried reading the serial data on a char buffer:


char buf[] = new char[3];;
int channel = (int)buf[0] ;
int key = (int)buf[1] ;
int vel = (int)buf[2] ;

but I'm getting weird data...

Answer Source

SOLVED: It was just an error in the port.setSerialPortParams, I was writing at baudrate 115200 but reading at 9600.