The processing program would need to look for the : as the marker for the start of the 1st temperature, the as the marker for the end of the first temperature and the start of the second temperature, and the ! as the marker for the end of the second temperature. The processing program would then receive the characters: If you put some delimiter between the values you send, like this: The Serial.print on the arduino is converting the byte to a string, and sending the string one character at a time. When I upload the code to the arduino, and start the processing program, I get this output: If (byteCount > 5) // don't do anything until you get 3 characters (header plus the two data bytes The processing code looks like this: //import Serial communication libraryįont24 = createFont(PFont.list(), 12) ĬommPort = new Serial(this, "COM4", 9600) TempC = 54 //convert the analog data to temperature ![]() The arduino code looks like this: int tempC If(commPort.read() = 255) // only proceed if you get your header If (commPort.available() > 2) // don't do anything until you get 3 characters (header plus the two data bytes setup fonts for use throughout the applicationĬommPort = new Serial(this, "COM7", 9600) More detailed: ' ' is character with code 0x0A called 'new line', while '\r' is 0x0D - 'carriage return'. Probably you should use '\r ' instead of ' ' at the end of lines. Serial.print((int)tempC) //send the int data to the computer- does not workĪnd here if the Processing code //import Serial communication library You could have set Implicit CR in every LF option from PuTTY's terminal options instead of changing every line termination in your code from to \r. Serial.print((byte)tempC) //send the byte data to the computer- works TempC = 254 //convert the analog data to temperature Serial.print((byte)255) //send the header For every variable you add to the output, you add two more serial prints. What if you wanted to print a line with 4 variables inserted into a string like this: The 3 burritos are 147.7 degrees F, weigh 14 oz, and were finished 3 minutes ago. Serial.begin(9600) //opens serial port, sets data rate to 9600 bps In fact, using Serial.print() to build a string gets even more clunky the more variables you add. So it basically, sends whatever text you want with a newline. This is the arduino code //declare variables The Serial.println() function is similar to the Serial.print() function with only one difference which is following the printed text with a carriage return character (ASCII 13, or ‘\r’) and a newline character (ASCII 10, or ‘ ’). ![]() I first tried that with "byte" variables and it went fine. I am working on my first project submitting two temperatures to Processing.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |