I am making an interface for the arduino to processing involving a joystick. It should work so the processing sketch sends the character 'b' or 'c' depending on if it wants to find the state of the 'b'utton on the joystick or the 'c'oordinates of the position of the joystick. ( a number 1-9, set up like a telephone keypad.)
I have been testing the arduino side in the serial monitor, but with no luck. Nothing gets sent back.
I think this may just be a simple error I did not catch, but here's the code:
By the way the arduino can read the joystick itself properly. It is one of the ones used in claw machines: 4 switches and one more for the red button on top. The switches are wired to pins 3-7, and pin 2 acts as a connection to ground so the joystick can be connected by one row of headers on the end of a ribbon cable.
If, by "nothing gets sent back", you mean that Processing does not get any data, then, we'd need to see the processing code, too.
Typically, though, you need to include a carriage return at the end of the data being sent. Either use Serial.println to send the data, or add Serial.print("\n"); after the (last) Serial.print.
Yes I've been typing b or c then pressing enter.
I've also tried sending the decimal ASCII equivalent, I didn't really think it would work, and it doesn't.
Oh, and the rx light flashes, so it is recieving the byte. No transmitting though.
I just got a chance to try some stuff with the code, and I got it to work.
Thanks, Coding Badly, the DEC addition fixed it.
My question is, why exactly does this solution work?
pressed returns one of these single byte values: 0x01 or 0x00. crossGet returns one of these single byte values: 0x05, 0x08, 0x02, 0x04, 0x06. Serial.print(coor) and Serial.print(press) send that single byte, unmodified, to the PC. Byte values less than 0x20 are "non printable characters". So, your Sketch was sending data to the PC but Serial Monitor wasn't displaying it.
Serial.print(coor,DEC) and Serial.print(press,DEC) first convert the byte value to a text string and then send the string over the serial port to the PC. 0x00 is converted to "0"; 0x01 is converted to "1", etcetera. Serial Montior then displays the converted strings.