Creates a variable of type MultiSerial, to communciate with the MultiSerial Shield.
MultiSerial(address, port)
address - Address on the I2C bus of the shield to communicate with port - Which port (0 or 1) on the shield to associate this instance with
Instance of MultiSerial associated with a specific port on a specific shield.
#include <MultiSerial.h>
// Create a MultiSerial instance to communicate with port 0 on shield 0x4D
MultiSerial msInstance = MultiSerial(0x4D, 0);
Sets the data rate in bits per second for serial data transmission.
MultiSerialInstance.begin(speed)
speed - communications speed in bits per second
nothing
#include <MultiSerial.h>
// Create a MultiSerial instance to communicate with port 0 on shield 0x4D
MultiSerial msInstance = MultiSerial(0x4D, 0);
void setup() {
// Set up port for communications at 9600 bits per second
msInstance.begin(9600);
}
Transmit a byte of data out the serial port.
MultiSerialInstance.write(data)
data - byte of data to write
nothing
#include <MultiSerial.h>
// Create a MultiSerial instance to communicate with port 0 on shield 0x4D
MultiSerial msInstance = MultiSerial(0x4D, 0);
void setup() {
// Set up port for communications at 9600 bits per second
msInstance.begin(9600);
// Send 42 out the serial port initialized above
msInstance.write(42);
}
Read the next available byte of available serial data.
MultiSerialInstance.read(**)
*none
first available byte of serial data, or -1 if no data is available
#include <MultiSerial.h>
// Create a MultiSerial instance to communicate with port 0 on shield 0x4D
MultiSerial msInstance = MultiSerial(0x4D, 0);
void setup() {
// Set up port for communications at 9600 bits per second
msInstance.begin(9600);
}
void loop () {
byte data;
if(msInstance.available() > 0) {
// read in whatever the next byte of available data is and store it in data
data = msInstance.read()
}
}
Get the number of bytes available for reading from the serial port.
MultiSerialInstance.available(**)
*none
number of bytes available to read
#include <MultiSerial.h>
// Create a MultiSerial instance to communicate with port 0 on shield 0x4D
MultiSerial msInstance = MultiSerial(0x4D, 0);
void setup() {
// Set up port for communications at 9600 bits per second
msInstance.begin(9600);
}
void loop () {
if(msInstance.available() > 0) {
// take action only if there are bytes available for reception on the port
}
}
Store one byte of data associated with a specific shield and port. This byte is stored on the shield itself, not in the Arduino's memory. Each successive call to store() will overwrite any previous byte stored.
MultiSerialInstance.store(data)
one byte of data to associate with a specific port on a specific shield
nothing
#include <MultiSerial.h>
// Create a MultiSerial instance to communicate with port 0 on shield 0x4D
MultiSerial msInstance = MultiSerial(0x4D, 0);
void setup() {
// Store the number 42 associated with shield 4D, port 0 (as initialized above)
msInstance.write(42);
}
Retrieve the byte of data aassociated with a specific shield and port, that had been stored earlier.
MultiSerialInstance.retrieve(**)
*none
one byte of data that is associated with a specific port on a specific shield
#include <MultiSerial.h>
// Create a MultiSerial instance to communicate with port 0 on shield 0x4D
MultiSerial msInstance = MultiSerial(0x4D, 0);
void setup() {
byte data;
// Store the number 42 associated with shield 4D, port 0 (as initialized above)
msInstance.write(42);
// Read back the byte associated with this shield
data = msInstance.retrieve();
}
Configured the specified GPIO pin to be an input or an output.
MultiSerialInstance.flush() MultiSerialInstance.flush() MultiSerialInstance.flush(pin, mode);
*none *none pin - GPIO pin number to change mode - either INPUT or OUTPUT
nothing
#include <MultiSerial.h>
// Create a MultiSerial instance to communicate with port 0 on shield 0x4D
MultiSerial msInstance = MultiSerial(0x4D, 0);
void setup() {
// Set up port for communications at 9600 bits per second
msInstance.begin(9600);
// the device we're talking to generates garbage as it starts, use flush() to get rid of it
// after waiting one second for the device to start
delay(1000);
msInstance.flush();
}
Set a specified GPIO pin to a HIGH or LOW state. Unlike the Arduino digital pins, these do not have pullup resistors, so digitalWrite when the pin is set to an input has no effect.
MultiSerialInstance.digitalWrite(pin, value)
pin - GPIO pin number to change value - HIGH or LOW
nothing
#include <MultiSerial.h>
// Create a MultiSerial instance to communicate with port 0 on shield 0x4D
MultiSerial msInstance = MultiSerial(0x4D, 0);
void setup() {
// Configure GPIO pin 0 as an output
msInstance.pinMode(0, OUTPUT);
// Set GPIO pin 0 to a HIGH level
msInstance.digitalWrite(0, HIGH);
}
Read the current value of a specific GPIO pin.
MultiSerialInstance.digitalRead(pin)
pin - GPIO pin number to read the value of
HIGH or LOW
#include <MultiSerial.h>
// Create a MultiSerial instance to communicate with port 0 on shield 0x4D
MultiSerial msInstance = MultiSerial(0x4D, 0);
void setup() {
byte level;
// Configure GPIO pin 1 as an input
msInstance.pinMode(1, INPUT);
// Read the current value of pin 1 into the level variable
level = msInstance.digitalRead(1);
}
Set the data word size to use on a specific serial port. Defaults to 8 bits when begin() is called, but can be changed if required.
MultiSerialInstance.setWordSize(size)
size - word size to use on the port, valid values are 5, 6, 7, or 8
nothing
#include <MultiSerial.h>
// Create a MultiSerial instance to communicate with port 0 on shield 0x4D
MultiSerial msInstance = MultiSerial(0x4D, 0);
void setup() {
// Set up port for communications at 9600 bits per second
msInstance.begin(9600);
// Change the word size to 7 bits
msInstance.setWordSize(7);
}
Enable specific interrupt types.
MultiSerialInstance.enableInterrupt(types)
types - bitmask of INT_RX and/or INT_TX for which interrupt(s) to enable
nothing
#include <MultiSerial.h>
// Create a MultiSerial instance to communicate with port 0 on shield 0x4D
MultiSerial msInstance = MultiSerial(0x4D, 0);
void dataReceived() {
// this will be called each time there's new data in the shield's receive buffer
}
void setup() {
// Set up port for communications at 9600 bits per second
msInstance.begin(9600);
// Turn on the shield's receive interrupt
msInstance.enableInterrupt(INT_RX);
// Attach the Arduino's interrupt pin 0 to the 'dataReceived' function
attachInterrupt(0, dataReceived, FALLING);
}
Disable specific interrupt types.
MultiSerialInstance.disableInterrupt(types)
types - bitmask of INT_RX and/or INT_TX for which interrupt(s) to disable
nothing
Outputs data to the serial port, converting numbers to their human-readable ASCII representations.
MultiSerialInstance.print(value) MultiSerialInstance.print(value, base) MultiSerialInstance.print(string)
value - Variable or literal to output base - Base to display number in (OCT, DEC, BIN, HEX) or number of decimal places for floating point values, DEC assumed if not supplied string - String to output
nothing
#include <MultiSerial.h>
// Create a MultiSerial instance to communicate with port 0 on shield 0x4D
MultiSerial msInstance = MultiSerial(0x4D, 0);
void setup() {
// Set up port for communications at 9600 bits per second
msInstance.begin(9600);
// Outputs "Hello, World!"
msInstance.print("Hello, World!");
// Outputs "30" in text
msInstance.print(30);
// Outputs "1E" in text
msInstance.print(30, HEX);
// Outputs "36" in text
msInstance.print(30, OCT);
// Outputs "3.14" in text
msInstance.print(3.14159, 2);
}