Hardware Reference
In-Depth Information
openFrameworks Serial Functions
The following reference list is for the openFrameworks serial functions. Most of the functions work just like the
Arduino's counterpart functions. The serial object must be declared before using and calling the openFrameworks
serial functions. The serial object comes from the ofSerial class; just as a variable is declared, a serial object is
created by using the following:
ofSerial serial;
To use any of the functions, use the name declared for the object—for example, serial.setup(); . Here are the
functions:
void enumerateDevices() : Lists the available serial devices.
void close() : Closes the serial connection.
bool setup(int, int) : Connects to the device number corresponding to the list outputted by
enumerateDevices () at the desired baud speed.
bool setup() : Opens a serial connection on the first available device at baud 9600 and returns
a fail or succeed.
bool setup(string, int) : Uses a string to declare what serial device to connect to. The
second parameter sets the baud speed and returns a fail or succeed.
int readBytes(unsigned char, int) : Takes a pointer to an array of characters, attempts to
retrieve the number of bytes equal to the second parameter, and returns the number of actual
bytes read (compare to the requested amount of bytes to error-check).
int readByte() : Returns a single byte from the connected device.
int writeBytes(unsigned char, int) : Takes a character array or string and an amount of
bytes to write, and returns the amount written for error checking.
bool writeByte(unsigned char) : Sends a single byte to the connected device and returns a
fail or succeed.
void flush(bool, bool) : Clears one or both of the serial buffers (one buffer for send, one
buffer for receive).
int available() : Returns the number of available bytes in the receive buffer.
Coding Once Using Firmata and ofArduino
In keeping with the spirit of “work fosters ideas,” working with two different pieces of code (one on the Arduino
and one using openFrameworks) is a bit inefficient for exploring ideas, especially when changing things frequently.
Luckily, there are items included with the Arduino IDE and openFrameworks (a program for the Arduino and a
built-in class for openFrameworks) that make it possible to write single programs that take care of having to separately
code the Arduino.
Firmata is a communication protocol for the Arduino that allows for on-the-fly configurations
without having to restart or reprogram the Arduino. Standard Firmata is included with the
Arduino IDE.
ofArduino , which handles
openFrameworks complements Firmata by including a class called
both communication and configuration of the Arduino.
 
Search WWH ::




Custom Search