Arduino receiving data from java Help !

Hello, I am new to programming with Arduino and was trying to get Java to send data to Arduino in this instance, when I click a button created with JavaFX it would be able to send the 255 bit value to Arduino where Arduino connected to to beginner grove board would then turn on an analogue pin where I happen to have a MOSFET connected to water pump. I attached the code below, not sure how much help I will receive given my limited knowledge and ability to explain what in the heck I actually doing. Thanks in advance !

don't post code as an image... it's text... (and use code tags)

are you sure your Java code is sending just 1 byte?
are you sure it's sending it to the right com port where the arduino is attached?
are you sure the baud rate used is 9600?

can you modify the Java program so that it prints out whatever it gets from the Serial line?

if so try running this on your Arduino

void setup() {
  Serial.begin(9600);
}

void loop() {
  if (Serial.available()) {
    byte r = Serial.read();
    Serial.print(F("got ")); Serial.print(r);
    if (isalnum(r)) {
      Serial.print(F("\t('")); Serial.print((char)r); Serial.print(F("')"));
    } else if (r == '\r') Serial.print(F("\t(Carriage return)"));
    else if (r == '\n') Serial.print(F("\t(New line)"));
    Serial.println();
  }
}

it will send back to the Serial line some information about what was received. for example sending Hello123 with CR/LF active as end of message shows

[color=purple]
got 72	 ('H')
got 101	('e')
got 108	('l')
got 108	('l')
got 111	('o')
got 49	 ('1')
got 50	 ('2')
got 51	 ('3')
got 13	 (Carriage return)
got 10	 (New line)
[/color]

Although it makes no difference to how a program runs, experience shows that when a comment so obviously does not match the code then the programmer is not being very careful and may have slipped up elsewhere

Please follow the advice on posting code given in Read this before posting a programming question in order to make your sketch easy to read, copy and test

In particular note the advice to Auto format code in the IDE and to use code tags when posting code here as it prevents some combinations of characters in code being interpreted as HTML commands such as italics, bold or a smiley character, all of which render the code useless

If the code exceeds the 9000 character inline limit then attach it to a post

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.