I am making a simulation for my second year project which needs to output a boolean value through USB to an arduino. I was wondering what the best way to do this is and if I need to use a library or something? I am using java. Any help would be appreciated, thanks!
Asked
Active
Viewed 142 times
-1
-
Boolean through USB? as in send a 1 or a 0 on the serial port connected to the USB ? – lostbard Mar 21 '19 at 14:35
-
Yes, I am trying to get a 1 or 0 to be sent to an arduino needs to read the this value. – ol1ie310 Mar 21 '19 at 14:45
-
https://stackoverflow.com/questions/900950/how-to-send-data-to-com-port-using-java or https://stackoverflow.com/questions/264277/java-serial-communication-on-windows – vincrichaud Mar 21 '19 at 15:11
-
USB uses differential line to send data. You will need some adapter to convert signal from USB to TTL levels. For example you can use FTDI chip based USB - UART adapter and some java library that supports bit bang mode for it. https://github.com/KeyBridge/lib-usb3-ftdi seems to support bit bang according to readme file. – devmind Mar 21 '19 at 15:15
1 Answers
0
Many arduinos have a USB serial port, so use the port on the USB - example just changes the Boolean value that is being sent each second.
int bool_val = 0;
void setup() {
// initialize the serial communication:
Serial.begin(9600);
}
void loop() {
// send the value
Serial.println(bool_val);
delay(1000);
// toggle value
bool_val = !bool_val;
}
You can then open the serial of the USB connected from the Arduino to read the values in your java code using something like RXTX http://users.frii.com/jarvi/rxtx/

lostbard
- 5,065
- 1
- 15
- 17