Serial
The Wiring Serial library allows for easily reading and writing data to and from external machines. It allows two machines to communicate and gives you the flexibility to make your own microcontroller devices and use them as the input or output to your Wiring programs.
The serial port is a nine pin I/O port that exists on most PCs and can be emulated through USB on Macintosh and PCs with USB Serial adapters.
The Wiring I/O board has two built-in (hardware) serial ports called Serial and Serial1. The port Serial is available through the USB connector in the Wiring I/O board. The port Serial1 is available on Wiring I/O pins 2(Rx) and 3(Tx).
Serial
Wiring serial port available through the USB port or Wiring I/O pins 32(Rx) and 33(Tx).
Serial1
Wiring serial port available on Wiring I/O pins 2 (Rx) and 3(Tx)
begin()
Opens the serial port for reading and writing.
print()
Writes dat (int, float, byte, char, char[], numbers in base (DEC, BIN, OCT or HEX) or Strings to the serial port.
println()
It works as the print method but prints a new line character at the end of each call.
available()
Returns the number of bytes available.
read()
Returns a number between 0 and 255 for the next byte that's waiting in the buffer. Returns -1 if there is no byte, although this should be avoided by first checking available() to see if data is available.
flush()
Flushes the serial port buffer. Further calls to read() and available() will return data received after the flush() command was issued.
peek()
Peek the next byte of data in serial port buffer. This doesn't retrieve the actual byte from the buffer. Returns -1 If no data is available.
end()
Closes the serial port.
Using the Serial Port
All Platforms
- If you're using a program to check to see if the serial port is working, then it won't be available to Wiring. That means that if you're using HyperTerminal or whatever to see if your serial device is working, then you need to quit out of that application before using that port with Wiring also if the port is in use with Processing.
- The Tools -> Serial ports Menu will only list the ports that are currently available. So if you have a program that's using the serial port that you want to use for your Wiring sketch, it's not going to be available, or even listed.