Chapter 7. Arduino Libraries

The Arduino IDE comes with a collection of libraries that can be used with program sketches. These contain functions to access peripheral devices like an Ethernet interface, a liquid crystal display, a conventional serial interface, and many others.

Note that although the term “library” is used to describe auxiliary code, the modules themselves aren’t always what one might think of as a library in the sense of a precompiled module, such as the .a (archive) or .so (shared object) libraries in Unix or Linux. In many cases they’re just standard C or C++ source files (with AVR-GCC limitations, of course), but the end result is largely the same. Library code is compiled as necessary along with the sketch code into object files and linked with the sketch (see Chapters 5 and 6). In other cases a library really is a binary object, such as the components supplied with the avr-libc library suite. If you want to know where a library or external code module is coming from, check both the avr-libc documentation and the Arduino documentation.

After a program sketch and any library modules are compiled, the linker utility resolves the address references between the library components and the user-supplied functions, and then binds all the components into one executable binary image. The AVRDUDE utility employed by the IDE (discussed in Chapter 6) handles the process of interacting with the on-board bootloader (covered in Chapter 5) to transfer the compiled binary code onto an AVR device and save it in the processor’s on-board memory.

For an overview of the software development process using the Arduino IDE, see Chapter 5. Chapter 6 covers code development using just the AVR-GCC toolchain.

Library Components

The Arduino development environment comes with a selection of support libraries for things such as serial I/O over the USB connection, EEPROM read/write, Ethernet I/O, an LCD interface, and support for servo and stepper motor actuators, among other things. These are described in the following sections.

Note

These descriptions are, by necessity, terse. For more details and usage examples refer to the Arduino libraries page or see the reference documentation supplied in the form of HTML files with the Arduino IDE (the built-in help pages). Bear in mind that the Arduino website will have the latest documentation for the most recent versions of the libraries, but what comes with the Arduino IDE will describe the libraries included with that release.

You can examine a list of available libraries by selecting Sketch→Import Library from the IDE toolbar. This will also show any libraries that you have added to the environment (adding libraries is described in Chapter 5).

The following descriptions cover the libraries supplied with a basic Arduino IDE installation (additional libraries are available from Arduino and from other sources like shield suppliers):

EEPROM

Supports reading and writing to “permanent” storage using an AVR’s built-in EEPROM

Ethernet

Used with the Arduino Ethernet shield for Ethernet connectivity

Firmata

Provides communications with applications on the computer using a standard serial protocol

GSM

Used with the GSM shield to connect to a GSM/GPRS network

LiquidCrystal

Contains functions for controlling liquid crystal displays (LCDs)

SD

Provides support for reading and writing SD flash memory cards

Servo

A collection of functions for controlling servo motors

SPI

Supports the use of the Serial Peripheral Interface (SPI) bus

SoftwareSerial

Implements serial communication on any of the digital pins

Stepper

A collection of functions for controlling stepper motors

TFT

Provides functions for drawing text, images, and shapes on the Arduino TFT screen

WiFi

Supports the Arduino WiFi shield for wireless networking

Wire

Supports the two-wire interface (TWI/I2C) for sending and receiving data over a network of devices or sensors

Esplora

Provides functions to access the various actuators and sensors mounted on the Esplora board (used with Esplora only)

USB

Used with the Leonardo, Micro, Due, and Esplora boards for serial I/O over the USB connection

Keyboard

Sends keystrokes to an attached computer

Mouse

Controls cursor movement on a connected computer

EEPROM

The EEPROM library supports reading and writing to “permanent” storage using an AVR’s built-in EEPROM. The EEPROM is persistent, and it will retain whatever was written into it when power is removed from the board. Although the microcontroller’s primary flash memory is also nonvolatile, the EEPROM is not disturbed when new executable code is uploaded to the board. It must be specifically accessed via software. The different types of AVR microcontrollers used on Arduino boards have different amounts of EEPROM storage available, ranging from 512 bytes for the ATmega168 to 4 KB for the ATmega1280 and ATmega2560. Refer to Chapter 3 for microcontroller-specific details.

The EEPROM class defines the functions used to read, write, and update the contents of the AVR on-board EEPROM. It must be instantiated before any of the EEPROM functions can be used.

The library include file, EEPROM.h, declares EEPROM as a static instance of the EEPROM class. If you want to use the class by instantiating an EEPROM object yourself you can do the following:

EEPROMClass eeprom;

Older versions of the EEPROM library have only two functions for accessing the built-in EEPROM of an AVR MCU:

read()

Reads a byte value from a specific address in the EEPROM. Uninitialized locations will contain a value of 255. This function returns the byte value read from the given address. Addresses start at zero (0).

uint8_t eeprom.read(int address);
write()

Writes a byte value to the microcontroller’s EEPROM storage at a specific address. Addresses start at zero (0). About 3.3 ms is required to perform an EEPROM write operation, and the AVR EEPROM has a rated endurance of 100,000 write/erase cycles, so it should last a while. The function returns nothing.

void eeprom.write(int address, uint8_t value);

The latest version of the EEPROM library has four additional functions: update(), get(), put(), and EEPROM[]. The source code for the EEPROM library class is worth reading to see how the code deals with arbitrary data types.

update()

The update() function writes a byte of data to the EEPROM at a specific address, but only if the value currently at the address is different from the value supplied as an argument to the function. This function returns nothing.

void eeprom.update(int address, uint8_t value);
put()

The put() function writes any data type to the EEPROM, starting at the specified address. The data can be a primitive type (e.g., int or float), or it can be a structure. The function returns a reference to the data object passed in via the data argument. Note that this function uses update() to preform the write operation, so a write will not occur if the data at the specified address is the same as the data passed into the put() call.

data_ref eeprom.put(int address, data);
get()

The get() function reads and returns any data type or object from the EEPROM. The data read from the EEPROM is written to the address of the data argument in byte-wise fashion, with as many bytes as the size of the object pointed to by data. The function returns a reference to the data object passed in via the data argument.

data_ref eeprom.get(int address, data);
EEPROM[]

The EEPROM[] operator allows the EEPROM to be accessed like an array object. The actual EEPROM address is simply EEPROM_base_address + int index. The operator returns a reference to the EEPROM cell.

data_ref EEPROM[int index]

The following simple example is based loosely on what is provided by Arduino.cc in the EEPROM library documentation, but with a few twists. It writes to as well as reads from the EEPROM memory space, and it uses the remainder operator to determine if a value is odd or even:

#include <EEPROM.h>
// Instantiate our own copy of an EEPROMClass object rather than
// using the static declaration in EEPROM.h
EEPROMClass eeprom;
int a = 0;
int value;
void setup()
{
    Serial.begin(9600);
    // preload EEPROM with data pattern
    for (int i = 0; i < 512; i++) {
        if (i % 2)    // see if even or odd
            eeprom.write(i, 0);  // value is odd
        else
            eeprom.write(i, 1);  // value is even
    }
}
// An ATmega168 has 512 bytes of EEPROM, and an ATmega328 has 1024.
// Only 512 are used here, so it should be safe with any AVR that
// you might find in an Arduino.
void loop()
{
    value = eeprom.read(a);
    Serial.print(a);
    Serial.print("	");
    Serial.print(value);
    Serial.println();
    // The variable a is declared outside of loop(), so it will
    // persist between calls from main().
    a++;
    if (a == 512)
        a = 0;
    delay(500);
}

Ethernet

The Ethernet library provides the functionality necessary to interact with an Arduino Ethernet shield. As Arduino libraries go, it is rather complex, and provides both server and client functionality. It also supports four concurrent input or output connections, or a mix of either. The Ethernet shield uses the SPI interface to communicate with the host Arduino board.

The Ethernet library is comprised of a collection of five C++ classes. Most of the classes inherit from parent classes, but you don’t need to bother with the details for most applications. However, if you do need to see the low-level class definitions, they can be found in the directory hardware/arduino/avr/cores/arduino in the Arduino source code. The following list shows the five classes of the Ethernet library and the public member functions of each class. We’ll look at each of these in turn in the following sections:

  • Ethernet class

    • begin()

    • localIP()

    • maintain()

  • IPAddress class

  • Server class

    • EthernetServer()

    • begin()

    • available()

    • write()

    • print()

    • println()

  • Client class

    • EthernetClient()

    • connected()

    • connect()

    • write()

    • print()

    • println()

    • available()

    • read()

    • flush()

    • stop()

  • EthernetUDP class

    • begin()

    • read()

    • write()

    • beginPacket()

    • endPacket()

    • parsePacket()

    • available()

    • stop()

    • remotePort()

Ethernet class: EthernetClass

The Ethernet class initializes the Ethernet library and network settings. The actual class name is EthernetClass, and an object named Ethernet is instantiated in the library file Ethernet.cpp and exported in Ethernet.h. You can create your own instance of EthernetClass if you wish, or just use what the library provides.

begin()

Used to initialize the Ethernet library and establish networking parameters. The begin() method (or, function, if you prefer) is overloaded so that there are five ways to invoke it.

All of the arguments are arrays of uint8_t bytes. The DHCP-only form of this method (Ethernet.begin(mac)) returns 1 if a DHCP lease was successfully obtained, or 0 if it failed. All other forms return nothing. The IPAddress class type is described in the next section.

int Ethernet.begin(uint8_t *mac);
void Ethernet.begin(uint8_t *mac, IPAddress ip);
void Ethernet.begin(uint8_t *mac, IPAddress ip, IPAddress dns);
void Ethernet.begin(uint8_t *mac, IPAddress ip, IPAddress dns, 
                    IPAddress gateway);
void Ethernet.begin(uint8_t *mac, IPAddress ip, IPAddress dns, 
                    IPAddress gateway, IPAddress subnet);
localIP()

Obtains the IP address of the local host (i.e., the Ethernet shield). This is useful for determining the local IP address when DHCP is used. If the local Ethernet has been initialized successfully, Ethernet.localIP() will return an IPAddress object containing the assigned or specified IP address.

IPAddress Ethernet.localIP();
maintain()

This method does not appear in older versions of the library. When a device is assigned an IP address by a DHCP server it is called a lease, and a DHCP lease is given for a specific period of time (it depends on how the DHCP server has been configured). The Ethernet.maintain() method is used to renew a DHCP lease.

Ethernet.maintain() will return 0 if nothing occurred, 1 if the lease renewal failed, 2 if the lease was successfully renewed, 3 if the DHCP rebind failed, and 4 if the rebind succeeded.

int Ethernet.maintain();
IPAddress class

The IPAddress class defines a data object that is used to contain data for local and remote IP addressing. The class has four types of overloaded constructors. Each accepts a different form of IP address, as shown here:

IPAddress()
IPAddress(uint8_t first_octet,
          uint8_t second_octet,
          uint8_t third_octet,
          uint8_t fourth_octet)
IPAddress(uint32_t address)
IPAddress(const uint8_t *address)

An IPAddress object can hold a set of four IP address octets (the 192.168.1.100 format, for example, sans the periods), a 32-bit integer version of an IP address, or an array of unsigned bytes. The IPAddress class is used to create instances of address data types. For example:

IPAddress ip(192, 168, 0, 2);
IPAddress dnServer(192, 168, 0, 1);
IPAddress gateway(192, 168, 0, 1);
IPAddress subnet(255, 255, 255, 0);

ip, dnServer, gateway, and subnet are objects of type IPAddress. The Ethernet library knows to look for these names when initializing an Ethernet interface. Notice that they all use the multiple-octet form of initialization.

You can find the source files for IPAddress in the directory Arduino/hardware/arduino/avr/cores/arduino of the Arduino source.

Server class: EthernetServer

In Ethernet parlance, a server is a system (or host) that will accept a request for a connection from another system and establish a communications channel. The system requesting the connection is called a client. A server waits passively for clients to contact it; it doesn’t initiate a connection. For a real-world example, consider a web server. The web server waits for browser clients to connect and request web pages. It returns the requested data to the client and then waits for the next request. Each time a link is selected, a button clicked, or text entered into a text field of a browser display, a request is created and sent to the web server.

The Server class is the base class for the EthernetServer class in the Ethernet library. It is not called directly. The other classes utilize it. As with IPAddress, the source for the Server class is located in the directory Arduino/hardware/arduino/avr/cores/arduino of the Arduino source.

EthernetServer()

Establishes the port to use when listening for a connection request from a client. The port is typically specified when an object of type EthernetServer is instantiated. It returns nothing (void).

EthernetServer server(int port);

Example:

EthernetServer newserv = EthernetServer(port);

The value of the port argument may be any number between 0 and 65535, but values between 0 and 1024 are typically reserved for system services such as FTP, SSH, and possibly a web server. Use high port values (greater than 9000, for instance) to avoid conflicts.

begin()

Commands the server to begin listening for connections from clients on the port set when the server object was created.

void newserv.begin();
available()

Returns a connection to a client that is connected and ready to communicate.

EthernetClient newclient = newserv.available();
write()

Writes data to a client connected to a server. The data is written to all connected clients. Accepts either a single char (or byte) value, or a pointer to an array of char values, and returns the number of bytes written.

int newserv.write(char data);
int newserv.write(char *data, int size);
print()

Prints data to all clients connected to a server as a sequence of ASCII characters.

println()

Similar to print(), but adds a newline character at the end of the output. Accepts data as char, byte (uint8_t), int, long, or string types. Returns the number of bytes written. With no arguments, the function simply sends a newline character.

int newserv.println();
int newserv.println(char *data);
int newserv.println(char *data, int BASE);
Client class: EthernetClient

The Client class creates client objects, which can connect to a server to send and receive data. A transaction, or exchange, of data between a server and a client is typically initiated by the client. A server listens and waits for a client to connect, and once connected the client can request data from the server, send data to the server, or request that the server perform some action on the client’s behalf.

The Client class is the base class for the EthernetClient class in the Ethernet library. It is not called directly; the EthernetClient class inherits from it. As with Server, the source for the Client base class is located in the directory Arduino/hardware/arduino/avr/cores/arduino of the Arduino source.

EthernetClient()

Creates a client object that can connect to a server at a specific IP address using a specific port. The connect() method is used to define the server and the port to use. For example:

byte servaddr[] = {172, 120, 40, 10};
EthernetClient newclient;
newclient.connect(servaddr, 80);
connected()

Determines whether a client is connected or not. Returns true or false.

bool newclient.connected();
if (newclient.connected()) {
    // do something
}
connect()

Connects to a server at a specific IP address (an array of four bytes) and port. Instead of an IP address, a URL (web address) may be used.

int newclient.connect();
int newclient.connect(byte *servIP, int port);
int newclient.connect(char *URL, int port);

Returns an integer representing the connection status:

  • SUCCESS = 1

  • TIMED_OUT = -1

  • INVALID_SERVER = -2

  • TRUNCATED = -3

  • INVALID_RESPONSE = -4

write()

Sends either a value or the contents of a buffer to the connected server. The data is sent as a series of bytes. The write() method returns the number of bytes written. This return value can be safely ignored.

int newclient.write(uint8_t value);
int newclient.write(uint8_t *buffer, int len);
print()

Prints data to the connected server as a sequence of ASCII characters. Accepts data as char, byte (uint8_t), int, long, or string types. Can also take a base specified. The valid base types are BIN (binary), DEC (base 10), OCT (base 8), and HEX (base 16). Returns the number of bytes written.

int newclient.print(data);
int newclient.print(data, base);
println()

Identical to the print() method except that a newline character is appended to the end of the output of ASCII characters. A println() with no parameters will send a single newline character to the connected server.

int newclient.println();
int newclient.println(data);
int newclient.println(data, base);
available()

Returns the number of characters available for reading from the connected server. Can be used to check for presence of incoming data.

int newclient.available();
read()

Reads the next available byte from the server. Use a loop to read multiple characters, or read and evaluate each character one at a time.

char newclient.read();
flush()

Discards any unread characters from the server that are in the receive buffer.

void newclient.flush();
stop()

Disconnects from the currently connected server. Once disconnected, the client may connect to another server (or to the same server again, of course).

void newclient.stop();
EthernetUDP class

Unlike TCP/IP, which is a stream protocol (i.e., it has no definite start and stop boundaries), UDP is a datagram protocol. Each item of data is a single packet, called a datagram, and the data must fit within the boundaries of the datagram packet. UDP does not have error detection, nor does it guarantee delivery of the data, but for short packets of noncritical data, or where the upper-level software can handle things like error detection and retries, it offers a fast and relatively simple way to move data around between hosts.

begin()

Initializes the UDP class to start listening for incoming data on a specific port.

byte UDP.begin(int port);
read()

Reads incoming data from the specified buffer. If no parameters are given, it will return one character from the current buffer. If the buffer and size are specified, it will return up to maxsize bytes from the buffer.

char UDP.read();
char *UDP.read(char *pkt_buffer, int maxsize)

Note that this function is intended to be used immediately after a call to UDP.parsePacket().

write()

Sends data to a remote connection. The write() function must be placed between beginPacket() and endPacket() calls. beginPacket() initializes the data packet, and the endPacket() call actually sends the data to the remote host.

byte UDP.write(char *message);
byte UDP.write(char *buffer, int size)
beginPacket()

Opens a UDP connection to a remote host at a specific IP address and port. Returns 1 (true) if the connection succeeded or 0 on failure.

int UDP.beginPacket(byte *ip, int port);
endPacket()

Sends a UDP packet created by the write() function to the remote host specified by the beginPacket() function.

int UDP.endPacket();
parsePacket()

Checks an open UDP connection for the presence of a datagram packet and returns the size of the waiting data. parsePacket() must be called before the read() or available() function is used to retrieve the data (if any).

int UDP.parsePacket();
available()

Returns the number of bytes of received data currently in the receive buffer. Note that this should only be called after a call to parsePacket().

int UDP.available();
stop()

Disconnects from the remote UDP host and releases any resources used during the UDP session.

void USP.stop();
remoteIP()

Returns the IP address of the remote UDP connection as an array of 4 bytes. This function should only be called after a call to parsePacket().

byte *UDP.remoteIP();
remotePort()

Returns the UDP port of the remote UDP connection as an integer. This function should only be called after a call to parsePacket().

int UDP.remotePort();

Firmata

Firmata is an interesting library with a lot of potential applications. Firmata provides the means to use serial communications between an Arduino and an application on a host computer using a protocol similar to MIDI. It was developed with the intention of allowing as much of the functionality of an Arduino to be controlled from a host computer as possible—in other words, to use the Arduino as if it was an extension of the host’s own I/O capabilities.

Before embarking on a Firmata project for the first time, you might want to try out the demonstration software. A suitable client can be downloaded from the old Firmata wiki, and the Arduino portion of the code is already included in the libraries distributed with the Arduino IDE.

This section provides only a summary of the functions available in the Firmata library. The following list shows the organization of the library components. Unfortunately, these components don’t seem to be extensively documented, so some of what you might want to know in order to use them will need to be gleaned from the source code. For more details and usage examples, refer to the Firmata wiki (now idle and no longer maintained) or check out the Firmata GitHub repository. You should pay particular attention to the protocol definition, as this is what the host application uses to communicate with a Firmata application running on an Arduino.

Tip

The Firmata library code included with the Arduino IDE may not be the latest version. Check the GitHub repository. The documentation presented here may refer to functions that your version does not have.

The Firmata library is organized as follows:

Base methods

We’ll look at each of these categories in turn in the following sections.

begin()

The basic form of begin() initializes the Firmata library and sets the serial data rate to a default of 57,600 baud. The second form accepts an argument of type long, which contains the desired baud rate for the communication between Firmata and a host system. The third form starts the library using a stream other than Serial. It is intended to work with any data stream that implements the Stream interface (Ethernet, WiFi, etc.). Refer to the issue discussions on Firmata’s GitHub page for more information on the current status of this method.

void Firmata.begin();
void Firmata.begin(long);
void Firmata.begin(Stream &s);
printVersion()

Sends the library protocol version to the host computer.

void Firmata.printVersion();
blinkVersion()

Blinks the protocol version on pin 13 (the on-board LED on an Arduino).

void Firmata.blinkVersion();
printFirmwareVersion()

Sends the firmware name and version to the host computer.

void Firmata.printFirmwareVersion();
setFirmwareVersion()

Sets the firmware name and version using the sketch’s filename, minus the extension.

void Firmata.setFirmwareVersion(const char *name, 
                                     byte vers_major, byte vers_minor);
Sending messages
sendAnalog()

Sends an analog data message.

void Firmata.sendAnalog(byte pin, int value);
sendDigitalPort()

Sends the state of digital ports as individual bytes.

void Firmata.sendDigitalPort(byte pin, int portData);
sendString()

Sends a string to the host computer.

void Firmata.sendString(const char* string);
sendString()

Sends a string to the host computer using a custom command type.

void Firmata.sendString(byte command, const char* string);
sendSysex()

Sends a command containing an arbitrary array of bytes.

void Firmata.sendSysex(byte command, byte bytec, byte* bytev);
Receiving messages
available()

Checks to see if there are any incoming messages in the input buffer.

int Firmata.available();
processInput()

Retreives and processes incoming messages from the input buffer and sends the data to registered callback functions.

void Firmata.processInput();
Callback functions

In order to attach a function to a specific message type, the function must match a callback function. There are three basic types of callback functions in Firmata. We’ll look at each of these in turn in the following sections: generic, string, and sysex, and a fourth type to handle a system reset. The callback functions are:

attach()

Attaches a function to a specific incoming message type.

void attach(byte command, callbackFunction newFunction);
void attach(byte command, systemResetCallbackFunction newFunction);
void attach(byte command, stringCallbackFunction newFunction);
void attach(byte command, sysexCallbackFunction newFunction);
detach()

Detaches a function from a specific incoming message type.

void Firmata.detach(byte command);
Message types

A function may be attached to a specific message type. Firmata provides the following message types:

ANALOG_MESSAGE

The analog value for a single pin

DIGITAL_MESSAGE

Eight bits of digital pin data (one port)

REPORT_ANALOG

Enables/disables the reporting of an analog pin

REPORT_DIGITAL

Enables/disables the reporting of a digital port

SET_PIN_MODE

Changes the pin mode between INPUT/OUTPUT/PWM/etc.

FIRMATA_STRING

For C-style strings; uses stringCallbackFunction for the function type

SYSEX_START

For generic, arbitrary-length messages (via MIDI SysEx protocol); uses sysexCallbackFunction for the function type

SYSTEM_RESET

Resets firmware to its default state; uses systemResetCallbackFunction for the function type

GSM

The GSM library is used with the GSM shield to connect to a GSM/GPRS network. It is included with the 1.0.4 and later versions of the Arduino IDE. The GSM library supports most of the functions one would expect from a GSM phone, such as the ability to place and receive calls, send and receive SMS messages, and connect to the Internet via a GPRS network. GSM stands for global system for mobile communications, and GPRS is the acronym for General Packet Radio Service.

The GSM shield incorporates a modem to transfer data from a serial port to the GSM network. The modem utilizes AT-type commands to perform various functions. In normal usage each AT command is part of a longer series that performs a specific function. The GSM library relies on the SoftwareSerial library to support communication between the Arduino and the GSM modem.

Note

The GSM library is a recent addition. If you have an older version of the IDE, then you may not have this library. Check the list of available libraries in the IDE to see if you do or do not have the GSM library available.

The suite of GSM library classes is complex, and a full description of all of the capabilities would be beyond the scope of this book. This section presents a summary of the functionality. For more detailed information, refer to the Arduino GSM library reference or check the built-in help in the Arduino IDE. Some vendors, such as Adafruit, also produce Arduino-compatible GSM shields, and they provide their own libraries for their products.

Ethernet library compatibility

The GSM library is largely compatible with the current Arduino Ethernet library, such that porting a program that uses the Arduino Ethernet or WiFi libraries to the GSM for use with the GSM shield should be relatively straightforward. Some minor library-specific modifications will be necessary, such as including the GSM- and GPRS-specific libraries and obtaining network settings from your cellular network provider.

Library structure

The GSM library is rather complex, and is comprised of 10 primary classes. The following list shows the functions in each of the GSM classes:

  • GSM class

    • begin()

    • shutdown()

  • GSMVoiceCall class

    • getVoiceCallStatus()

    • ready()

    • voiceCall()

    • answerCall()

    • hangCall()

    • retrieveCallingNumber()

  • GSM_SMS class

    • beginSMS()

    • ready()

    • endSMS()

    • available()

    • remoteNumber()

    • read()

    • write()

    • print()

    • peek()

    • flush()

  • GPRS class

    • attachGPRS()

  • GSMClient class

    • ready()

    • connect()

    • beginWrite()

    • write()

    • endWrite()

    • connected()

    • read()

    • available()

    • peek()

    • flush()

    • stop()

  • GSMServer class

    • ready()

    • beginWrite()

    • write()

    • endWrite()

    • read()

    • available()

    • stop()

  • GSMModem class

    • begin()

    • getIMEI()

  • GSMScanner class

    • begin()

    • getCurrentCarrier()

    • getSignalStrength()

    • readNetworks()

  • GSMPIN class

    • begin()

    • isPIN()

    • checkPIN()

    • checkPUK()

    • changePIN()

    • switchPIN()

    • checkReg()

    • getPINUsed()

    • setPINUsed()

  • GSMBand class

    • begin()

    • getBand()

    • setBand()

GSM class

This class prepares the functions that will communicate with the modem. It manages the connectivity of the shield and performs the necessary system registration with the GSM infrastructure. All Arduino GSM/GPRS programs need to include an object of this class to handle the low-level communications functions.

This is the base class for all GSM-based functions. It should be instantiated as shown:

GSM gsmbase;
begin()

Starts the GSM/GPRS modem and attaches to a GSM network. The full prototype for the begin() method looks like this:

begin(char* pin=0, bool restart=true, bool synchronous=true);

The begin() method can be called four different ways because each argument has been assigned a default value. The first form takes no arguments, and it is assumed that the SIM has no configured pin.

gsmbase.begin();
gsmbase.begin(char *pin);
gsmbase.begin(char *pin, bool restart);
gsmbase.begin(char *pin, bool restart, bool sync);
shutdown()

Shuts down the modem (power-off).

gsmbase.shutdown();
GSMVoiceCall class

The GSMVoiceCall class enables voice communication through the modem, provided that a microphone, a speaker, and a small amount of circuitry are connected to the GSM shield.

This is the base class for all GSM functions used to receive and make voice calls and should be instantiated as follows:

GSMVoiceCall gsmvc;
getVoiceCallStatus()

Returns the status of a voice call as one of IDLE_CALL, CALLING, RECEIVINGCALL, or TALKING.

GSM3_voiceCall_st getVoiceCallStatus();
gsmvc.getVoiceCallStatus();
ready()

Returns the status of the last command: 1 if the last command was successful, 0 if the last command is still executing, and >1 if an error occurred.

int ready();
gsmvc.ready();
voiceCall()

Places a voice call in either asynchronous or synchronous mode. If asynchronous, voiceCall() returns while the number is ringing. In synchronous mode voiceCall() will not return until the call is either established or cancelled.

The first argument is a string containing the number to call. A country extension can be used or not. The buffer should not be released or used until voiceCall() is complete (the command is finished). The timeout argument is given in milliseconds, and is used only in synchronous mode. If set to 0, then voiceCall() will wait indefinitely for the other end to pick up.

int voiceCall(const char* to, unsigned long timeout=30000);
gsmvc.voiceCall(to);           // use default timeout
gsmvc.voiceCall(to, timeout);  // specify a timeout period
answerCall()

Accepts an incoming voice call. In asynchronous mode answerCall() returns 0 if the last command is still executing, 1 on success, and >1 if an error has occurred. In synchronous mode answerCall() returns 1 if the call is answered, and 0 if not.

gsmvc.answerCall();
hangCall()

Hangs up an established call or an incoming ring. In asynchronous mode hangCall() returns 0 if the last command is still executing, 1 on success, and >1 if an error has occurred. In synchronous mode hangCall() returns 1 if the call is answered, and 0 if not.

gsmvc.hangCall();
retrieveCallingNumber()

Retrieves the calling number and puts it into a buffer. The argument buffer is a pointer to a char buffer, and bufsize is the size of the buffer, in bytes. The buffer should be large enough to hold at least 10 characters.

In asynchronous mode retrieveCallingNumber() returns 0 if the last command is still executing, 1 on success, and >1 if an error has occurred. In synchronous mode retrieveCallingNumber() returns 1 if the number is correctly acquired and 0 if not.

int retrieveCallingNumber(char* buffer, int bufsize);
gsmvc.retrieveCallingNumber(buffer, bufsize);
GSM_SMS class

This class provides the capability to send and receive SMS (Short Message Service) messages.

beginSMS()

Defines the telephone number to receive an SMS message. The phone number is a char array. In asynchronous mode the function will return 0 if the last command is still active, 1 if it was successful, and a value >1 if an error occurred. In synchronous mode the function will return 1 if the previous command was successful and 0 if it failed.

int SMS.beginSMS(char *phone_number)
ready()

Returns the status of the last GSM SMS command. In asynchronous mode ready() will return 0 if the last command is still active, 1 if it was successful, and a value >1 if an error occurred. In synchronous mode the function will return 1 if the previous command was successful and 0 if it failed.

int SMS.ready()
endSMS()

Used to inform the modem that the message is complete and ready to send. In asynchronous mode the function returns 0 if it is still executing, 1 if successful, and >1 if an error has occurred. In synchronous mode it returns 1 if successful, and 0 otherwise.

int SMS.endSMS()
available()

If an SMS message is available to read, this function returns the number of characters in the message. If no message is available, it returns 0.

int SMS.available()
remoteNumber()

Extracts the remote phone number from an incoming SMS message and returns it in a char array. The size argument defines the maximum size of the array passed to remoteNumber(). In asynchronous mode the function returns 0 if still executing, 1 if successful, and >1 if an error has occurred. In synchronous mode the function returns 1 if successful, 0 otherwise.

int SMS.remoteNumber(char *remote_phone, int number_size)
read()

Reads a byte (a character) from an SMS message. Returns the byte as an integer, or -1 if no data is available.

int SMS.read()
write()

Writes a byte-sized character to an SMS message.

int write(int character)
print()

Writes a character array to an SMS message. Returns the number of bytes successfully written.

int SMS.print(char *message)
peek()

Returns the next available byte (a character) from an SMS message, without removing the character, or -1 if no data is available.

int SMS.peek()
flush()

Clears the modem of any sent messages after all outbound characters have been sent.

void SMS.flush()
GPRS class

GPRS is the base class for all GPRS functions. This includes Internet client and server functions. This class is also responsible for including the files that are involved with TCP communication.

attachGPRS()

Connects with a given access point name (APN) to initiate GPRS communications. Cellular providers have APNs the act as bridges between the cellular network and the Internet. Returns one of the following strings: ERROR, IDLE, CONNECTING, GSM_READY, GPRS_READY, TRANSPARENT_CONNECTED.

char *GPRS.attachGPRS(char *apn, char *user, char *password)
GSMClient class

This class creates clients that can connect to servers and send and receive data.

ready()

Returns the status of the last command. In asynchronous mode the function returns 0 if still executing, 1 if successful, and >1 if an error has occurred. In synchronous mode the function returns 1 if successful, and 0 otherwise.

int GSMClient.ready()
connect(char *IP, int port)

Connects to a specific port of a specified IP address. Returns true if the connection was successful, or false if not.

bool GSMClient.connect(char *hostip, int port)
beginWrite()

Starts a write operation to the connected server.

void GSMClient.beginWrite()
write()

Writes data to a connected server. Returns the number of bytes written.

int GSMClient.write(char data)
int GSMClient.write(char *data)
int GSMClient.write(char *data, int size)
endWrite()

Stops writing data to a connected server.

void GSMClient.endWrite()
connected()

Returns the connection status of a client. Note that a client is considered to be connected if the connection has been closed but there is still unread data in the buffer. Returns true if the client is connected, or false if not.

bool GSMClient.connected()
read()

Reads the next available byte of data from the server the client is connected with. Returns the next byte, or -1 if no data is available.

int GSMClient.read()
available()

Returns the number of bytes from the connected server that are waiting to be read.

int GSMClient.available()
peek()

Returns the next available byte of an incoming message without removing it from the incoming buffer. Successive calls to peek() will simply return the same byte.

int GSMClient.peek()
flush()

Discards any data currently waiting in the incoming buffer and resets the available data count to zero.

void GSMClient.flush()
stop()

Forces a disconnect from a server.

void GSMClient.stop()
GSMServer class

The GSMServer class creates servers that can send data to and receive data from connected clients. It implements network server functionality, similar to the Ethernet and WiFi libraries. Note that some network operators do not permit incoming network connections from outside their own network.

ready()

Returns the status of the last command. In asynchronous mode this function returns 0 if still executing, 1 if successful, and >1 if an error has occurred. In synchronous mode the function returns 1 if successful, and 0 otherwise.

int GSMServer.ready()
beginWrite()

Starts a write operation to all connected clients.

void GSMServer.beginWrite()
write()

Writes data to connected clients. Returns the number of bytes written.

int GSMServer.write(char data)
int GSMServer.write(char *data)
int GSMServer.write(char *data, int size)
endWrite()

Stops writing data to connected clients.

void GSMServer.endWrite()
read()

Reads the next available byte from a connected client. Returns the byte read, or -1 if no data is available.

int GSMServer.read()
available()

Listens for connection requests from clients. Returns the number of connected clients.

int GSMServer.available()
stop()

Stops the server from listening for client connection requests.

void GSMServer.stop()
GSMModem class

The GSMModem class provides diagnostic support functions for the internal GSM modem.

begin()

Checks the status of the modem and restarts it. This function must be called before a call to getIMEI(). Returns 1 if the modem is working correctly, or an error if it is not.

int GSMModen.begin()
getIMEI()

Queries the modem to retrieve its IMEI (International Mobile Equipment Identifier) number. The IMEI number is returned as a string. This function should only be called after a call to begin().

char *GSMModen.getIMEI()
GSMScanner class

The GSMScanner class provides functions to obtain diagnostic information about the network and carrier.

begin()

Resets the modem. Returns 1 if the modem is operating correctly, or an error code if it is not.

int GSMSScanner.begin()
getCurrentCarrier()

Returns the name of the current network server provider (the carrier) as a string.

char *GSMSScanner.getCurrentCarrier()
getSignalStrength()

Returns the relative signal strength of the network connection as a string with ASCII digits from 0 to 31 (31 indicates that the power is > 51 dBm), or 99 if no signal is detected.

char *GSMSScanner.getSignalStrength()
readNetworks()

Searches for available network carriers. Returns a string containing a list of the carriers detected.

char *GSMSScanner.readNetworks()
GSMPIN class

The GSMPIN class contains utility functions for communicating with the SIM card.

begin()

Resets the modem. Returns 1 if the modem is operating correctly, or an error code if it is not.

int GSMPIN.begin()
isPIN()

Examines the SIM card to determine if it is locked with a PIN or not. Returns 0 if the PIN lock is off, 1 if the lock is on, -1 if the PUK lock is on, and -2 if an error was encountered.

int GSMPIN.isPIN()
checkPIN()

Queries the SIM card with a PIN to determine whether it is valid or not. Returns 0 if the PIN is valid, and -1 if it is not.

int GSMPIN.checkPIN(char *PIN)
checkPUK()

Queries the SIM to determine if the PUK code is valid and establishes a new PIN code. Returns 0 if successful, and -1 if not.

int GSMPIN.checkPUK(char *PUK, char *PIN)
changePIN()

Changes the PIN code of a SIM card after verifying that the old PIN is valid.

void GSMPIN.changePIN(char *oldPIN, char *newPIN)
switchPIN()

Changes the PIN lock status.

void GSMPIN.switchPIN(char *PIN)
checkReg()

Checks to determine if the modem is registered in a GSM/GPRS network. Returns 0 if the modem is registered, 1 if the modem is roaming, and -1 if an error was encountered.

int GSMPIN.checkReg()
getPINUsed()

Checks to determine if the PIN lock is used. Returns true if locked, and false if not.

bool GSMPIN.getPINUsed()
setPINUsed()

Sets the PIN lock status. If the argument is true, then the PIN is locked; if false, it is unlocked.

void GSMPIN.setPINUsed(bool used)
GSMBand class

The GSMBand class provides information about the frequency band the modem connects to. There are also methods for setting the band.

begin()

Resets the modem. Returns 1 if the modem is operating correctly, or an error code if it is not.

int GSMBand.begin()
getBand()

Returns the frequency band the modem is currently using for a connection.

char *GSMBand.getBand()
setBand()

Sets the frequency band for the modem to use.

bool GSMBand.setBand(char *band)

LiquidCrystal

This class allows an Arduino board to control a liquid crystal display (LCD) module. It is specifically intended for LCDs that are based on the Hitachi HD44780 (or compatible) chipset, which is found on most text-based LCDs. The library supports either 4- or 8-bit interface mode, and also uses three of the Arduino pins for the RS (register select), clock enable, and R/W (read/write) control lines.

LiquidCrystal()

Creates an instance of a LiquidCrystal class object. The different forms of the class allow it to accommodate different LCD interface methods.

LiquidCrystal(uint8_t rs, uint8_t enable, uint8_t d0, uint8_t d1,
              uint8_t d2, uint8_t d3, uint8_t d4, uint8_t d5,
              uint8_t d6, uint8_t d7);
LiquidCrystal(uint8_t rs, uint8_t rw, uint8_t enable, uint8_t d0,
              uint8_t d1, uint8_t d2, uint8_t d3, uint8_t d4,
              uint8_t d5, uint8_t d6, uint8_t d7);
LiquidCrystal(uint8_t rs, uint8_t rw, uint8_t enable, uint8_t d0,
              uint8_t d1, uint8_t d2, uint8_t d3);
LiquidCrystal(uint8_t rs, uint8_t enable, uint8_t d0, uint8_t d1,
              uint8_t d2, uint8_t d3);

Where:

rs

The Arduino pin connected to the LCD’s RS pin

rw

The Arduino pin connected to the LCD’s RW pin

enable

The Arduino pin connected to the LCD’s enable pin

d0 .. d7

The Arduino pins connected to the LCD’s data pins

The use of the d4, d5, d6, and d7 signals is optional. If only four digital lines are used, these can be omitted.

Example:

LiquidCrystal lcd(12, 11, 10, 5, 4, 3, 2);
begin()

Initializes the interface to the LCD controller on the LCD module. The arguments specify the width and height of the LCD. The default character size is 5 × 8 pixels. This function must be called before any other LCD library functions can be used.

void lcd.begin(uint8_t cols, uint8_t rows, 
                    uint8_t charsize = LCD_5x8DOTS)
clear()

Clears the LCD screens and resets the cursor to the upper-left corner.

void lcd.clear()
home()

Positions the cursor at the upper-left position on the LCD. Does not clear the LCD; use the clear() function for that.

void home()
setCursor()

Positions the cursor at the location specified by the column and row arguments.

void setCursor(uint8_t column, uint8_t row)
write()

Writes a byte (char) of data to the LCD. Returns the number of bytes written.

size_t write(uint8_t)
print()

This function is actually a part of the standard Arduino runtime AVR-GCC code, and it is overloaded to accept data of different types. The file Print.h, found at hardware/arduino/avr/cores/arduino/Print.h, defines the following forms of the print() function:

size_t print(const __FlashStringHelper *);
size_t print(const String &);
size_t print(const char[]);
size_t print(char);
size_t print(unsigned char, int = DEC);
size_t print(int, int = DEC);
size_t print(unsigned int, int = DEC);
size_t print(long, int = DEC);
size_t print(unsigned long, int = DEC);
size_t print(double, int = 2);
size_t print(const Printable&);
cursor()

Enables the cursor, an underscored character, at the position where the next character will be written on the LCD screen.

void cursor()
noCursor()

Disables the cursor, effectively hiding it. Does not affect the position where the next character will be displayed.

void noCursor()
blink()

Displays a blinking cursor.

void blink()
noBlink()

Turns off a blinking cursor.

void noBlink()
display()

Enables the LCD, if it was initially disabled with the noDisplay() function. Restores the cursor and any text that was previously visible or which may have been added, deleted, or modified since the display was disabled.

void display()
noDisplay()

Disables the LCD display without altering any existing text on the screen.

void noDisplay()
scrollDisplayLeft()

Scrolls the text on the display one space to the left.

void scrollDisplayLeft()
scrollDisplayRight()

Scrolls the text on the display one space to the right.

void scrollDisplayRight()
autoscroll()

Enables automatic scrolling. As text is added to the display it moves the existing characters one space to either the left or the right, depending on the current text direction.

void autoscroll()
noAutoscroll()

Disables the autoscroll function of the LCD.

void noAutoscroll()
leftToRight()

Sets the direction the text will shift in when autoscroll is enabled, in this case from left to right.

void leftToRight()
rightToLeft()

Sets the direction the text will shift in when autoscroll is enabled, in this case from right to left.

void rightToLeft()
createChar()

Creates a custom 5 × 8-pixel character. The character is defined by an array of bytes, one per row. Only the five least significant bits of each byte are used.

void createChar(uint8_t, uint8_t[])

SD

The SD library provides support for reading and writing SD flash memory cards, both full-size and micro SD types (they’re identical in terms of interface and functions, just different sizes). The library is based on sdfatlib by William Greiman.

This library treats an SD card as a small disk with either a FAT16 or a FAT32 filesystem. It uses short filenames (8.3 format). Filenames passed to the SD library functions may include a path, with directory names separated by forward slashes (like on Linux, not the backslashes used by MS-DOS or Windows).

The SPI interface is used to communicate with the SD card. This uses the digital pins 11, 12, and 13 on a standard Arduino board. One additional pin, usually pin 10, is used as the select pin, or another pin can be assigned to this role. Note that even if another pin is used for the select, the SS pin (pin 10) must remain as an output for the library to work.

SD class

The SD class provides functions for accessing the SD card and manipulating files and directories.

begin()

Initializes the SD library and the interface with the SD card. The optional argument csPin defines the pin to use as the select. The default is to use pin 10 (SD_CHIP_SELECT_PIN). This function must be called before any other of the SD functions are used. Returns true if successful, or false if not.

bool SD.begin(uint8_t csPin = SD_CHIP_SELECT_PIN);
exists()

Tests for the presence of a file or directory on the SD card. The string filepath may be a fully qualified path name (FQPN). Returns true if the file or directory exists, or false if not.

bool SD.exists(char *filepath);
mkdir()

Creates a directory on the SD card. It will also create any necessary intermediate directories. Returns true if the directory was created successfully, or false if not.

bool SD.mkdir(char *filepath);
open()

Opens a file on an SD card for reading or writing. If the mode argument is not provided, the default is to open the file for reading. Returns a File object that can be tested as a Boolean value. If the file could not be opened, then File will evaluate to false. The available modes are FILE_READ and FILE_WRITE.

File SD.open(const char *filename, uint8_t mode = FILE_READ);
remove()

Deletes (removes) a file from the SD card. filepath is an FQPN. Returns true if the removal succeeded, or false if not.

bool SD.remove(char *filepath);
rmdir()

Removes an empty directory from an SD card. Returns true if the directory was successfully deleted, or false if an error occurred (such as the directory not empty).

bool SD.rmdir(char *filepath);
File class

The File class provides functions for reading and writing individual files on an SD card. Objects of type File are created by the SD.open() function:

fname = SD.open("data.txt", FILE_WRITE);

There are a number of methods in a File object to manipulate the contents of a file:

available()

Returns the number of available bytes to read from a file.

int fname.available()
close()

Closes a file, ensuring that any remaining data is written to the file beforehand.

void fname.close()
flush()

Writes any remaining data in the file buffer to the file. Does not close the file.

void fname.flush()
peek()

Reads a byte from a file without advancing the internal data pointer. Successive calls to peek() will return the same byte.

int fname.peek()
position()

Returns the current position in the file that the next byte will be read from or written to.

uint32_t fname.position()
print()

Writes data to a file that has been opened for writing. Accepts data as char, byte (uint8_t), int, long, or string types. Can also take a base specified. The valid base types are BIN (binary), DEC (base 10), OCT (base 8), and HEX (base 16). Returns the number of bytes written.

int fname.print(data)
int fname.print(char *data, int BASE)

Note: string data is shown in this example.

println()

Writes data to a file that has been opened for writing followed by a carriage return and newline character pair. Accepts data as char, byte (uint8_t), int, long, or string types. Can also take a base specified. The valid base types are BIN (binary), DEC (base 10), OCT (base 8), and HEX (base 16). Returns the number of bytes written.

int fname.println()
int fname.println(data)
int fname.println(data, int BASE)
seek()

Moves the internal pointer to a new position in the file. The position must be between 0 and the size of the file, inclusive. Returns true if successful, or false if an error occurs (seeking beyond the end of the file, for example).

bool fname.seek(uint32_t pos)
size()

Returns the size of the file, in bytes.

uint32_t fname.size()
read()

Reads the next byte from the file, or returns a value of -1 if no data is available.

int fname.read(void *buf, uint16_t nbyte)
write()

Writes data to a file. Accepts either a single byte, or a data object that may be a byte, character, or string. The size argument defines the amount of data to write to the SD card. Returns the number of bytes written.

size_t fname.write(uint8_t)
size_t fname.write(const uint8_t *buf, size_t size)
isDirectory()

Returns true if the fname object refers to a directory, or false otherwise.

bool fname.isDirectory()
openNextFile()

Opens the next file folder in a directory and returns a new instance of a File object.

File openNextFile(uint8_t mode = O_RDONLY)
rewindDirectory()

Used with openNextFile(), this function returns to the first file or subdirectory in a directory.

void fname.rewindDirectory()

Servo

The Servo library is a collection of functions for controlling servo motors, such as the ones used with RC aircraft. Once an instance of the Servo class has been created, the attach() function is used to pass in the pin number to use with the servo. The pulses that control a servo are generated in the background. The class is instantiated as follows:

Servo servo;
attach()

Attaches a servo motor to an I/O pin. The second form allows the caller to specify the minimum and maximum write time values in microseconds. Returns the channel number, or 0 if the function fails.

uint8_t servo.attach(int pin)
uint8_t servo.attach(int pin, int min, int max)
write()

Sets the servo angle in degrees. If the value is > 200 it is treated as a pulse width in microseconds.

void servo.write(int value)
read()

Returns the last written servo pulse width as an angle between 0 and 180 degrees.

int servo.read()
writeMicroseconds()

Sets the servo pulse width in microseconds.

void servo.writeMicroseconds(int value)
readMicroseconds()

Returns the current pulse width in microseconds for this servo.

int servo.readMicroseconds()
attached()

Returns true if the servo object has been attached to a physical servo.

bool servo.attached()
detach()

Stops an attached servo object from generating pulses on its assigned I/O pin.

void servo.detach()

SPI

The SPI library supports the use of the Serial Peripheral Interface (SPI) bus for communication with SPI-compatible peripherals, typically chips with a built-in SPI interface. It can also be used for communications between two microcontrollers.

The SPISettings class is used to configure the SPI port. The arguments are combined into a single SPISettings object, which is passed to SPI.beginTransaction().

SPISettings(uint32_t clock, uint8_t bitOrder, uint8_t dataMode)

Example:

SPISettings spiset(uint32_t clock, 
                        uint8_t bitOrder, 
                        uint8_t dataMode)
beginTransaction()

Initializes the SPI interface using the settings defined in an SPISettings object.

void SPI.beginTransaction(SPISettings)
endTransaction()

Stops communication with the SPI interface. Typically called after the select pin is de-asserted to allow other libraries to use the SPI interface.

void SPI.endTransaction()
usingInterrupt()

Used when SPI communications will occur within the context of an interrupt.

void SPI.usingInterrupt(uint8_t interruptNumber)
begin()

Starts the SPI library and initializes the SPI interface. Sets the SCK, MOSI, and SS pins to output mode, and pulls SCK and MOSI low while setting SS high.

void SPI.begin()
end()

Disables the SPI interface but leaves the pin modes (in or out) unchanged.

void SPI.end()
transfer()

Transfers one byte over an SPI interface, either sending or receiving.

uint8_t SPI.transfer(uint8_t data)
setBitOrder()

Sets the order of the bit shifted out to the SPI interface. The two choices are LSBFIRST (least significant bit first) and MSBFIRST (most significant bit first). This function should not be used with new projects. Use the beginTransaction() function to configure the SPI interface.

void SPI.setBitOrder(uint8_t bitOrder)
setClockDivider()

Sets the SPI clock divider relative to the system clock. For AVR-based Arduino boards the valid divisors are 2, 4, 8, 16, 32, 64, or 128. This function should not be used with new projects. Use the beginTransaction() function to configure the SPI interface.

void SPI.setClockDivider(uint8_t clockDiv)
setDataMode()

Sets the clock polarity and phase of the SPI interface. This function should not be used with new projects. Use the beginTransaction() function to configure the SPI interface.

void SPI.setDataMode(uint8_t dataMode)

SoftwareSerial

The SoftwareSerial library implements software-based serial communication on the digital I/O pins of an Arduino. In other words, it is a “bit-banger” that emulates a conventional serial interface. It is useful when more than one serial interface is required, but the built-in USART in the AVR microcontroller is assigned to some other function (such as a USB interface).

The SoftwareSerial library supports multiple serial interfaces, each with a speed of up to 115,200 bits per second. When using multiple instances of SoftwareSerial only one can receive data at a time. The I/O pins used must support pin change interrupts. SoftwareSerial provides a 64-byte receive buffer for each instance of a serial interface.

An object of type SoftwareSerial is created to use with other serial I/O operations. The class constructor is passed the digital pins to use for input (rx) and output (tx).

SoftwareSerial(uint8_t rxPin, uint8_t txPin, bool inv_logic = false)

Example:

SoftwareSerial serial = SoftwareSerial(rxPin, txPin)
available()

Returns the number of bytes in the serial buffer that are available for reading.

int serial.available()
begin()

Sets the baud rate (speed) of the serial interface. Valid baud rates are 300, 600, 1200, 2400, 4800, 9600, 14400, 19200, 28800, 31250, 57600, and 115200.

void serial.begin(long speed)
isListening()

Tests the serial interface to see if it is listening for input. Returns true if the interface is actively waiting for input, false otherwise.

bool serial.isListening()
overflow()

If the input exceeds the 64-byte size of the receive buffer in the SoftwareSerial object, a flag is set. Calling the overflow() function will return the flag. A return value of true indicates that an overflow has occurred. Calling the overflow() function clears the flag.

bool serial.overflow()
peek()

Returns the oldest character from the serial input buffer, but does not remove the character. Subsequent calls will return the same character. If there are no bytes in the buffer, then peek() will return -1.

int serial.peek()
read()

Returns a character from the receive buffer and removes the character. The read() function is typically used in a loop. Returns -1 if no data is available. Note that only one instance of SoftwareSerial can receive incoming data at any given time. The listen() function is used to select the active interface.

int serial.read()
print()

The print() function behaves the same as the Serial.print() function. Accepts any data type that the Serial.print() will accept, which includes char, byte (uint8_t), int, long, or string types, and returns the number of bytes written.

int serial.print(data)
println()

Identical to the serial.print() function, except that a carriage return/line feed (CR/LF) pair is appended to the output. Returns the number of bytes written. If no data is provided, it will simply emit a CR/LF.

int serial.println(data)
listen()

Enables listening (data receive) for an instance of SoftwareSerial. Only one instance of a SoftwareSerial object can receive data at any given time, and the object whose listen() function is called becomes the active listener. Data that arrives on other interface instances will be discarded.

bool serial.listen()
write()

Transmits data from the serial interface as raw bytes. Behaves the same as the Serial.write() function. Returns the number of bytes written.

size_t serial.write(uint8_t byte)

Stepper

The Stepper library can be used to control both unipolar and bipolar stepper motors with the appropriate hardware to handle the required current.

The Stepper library has two forms of constructors, one for unipolar motors and one for bipolar motor types. Each creates a new instance of the Stepper class. It is called at the start of a sketch, before the setup() and loop() functions. The steps argument defines the number of steps in a full revolution of the motor’s output shaft. The pin1, pin2, pin3, and pin4 arguments specify the digital pins to use.

Stepper(int steps, int pin1, int pin2);
Stepper(int steps, int pin1, int pin2, int pin3, int pin4);

Example:

Stepper stepdrv = Stepper(100, 3, 4);
setSpeed()

Sets the speed (step rate) in terms of RPM. Does not cause the motor to turn; it just sets the speed to use when the step() function is called.

void stepdrv.setSpeed(long speed);
step()

Commands the motor to move a specific number of steps. A positive count turns the motor one direction, and a negative count causes it to turn in the opposite direction.

void stepdrv.step(int stepcount);

TFT

The TFT (thin-film transistor) display library provides functions for drawing text, images, and shapes on a TFT display. It is included with versions 1.0.5 and later of the Arduino IDE. This library simplifies the process for displaying graphics on a display. It is based on the Adafruit ST7735H library, which can be found on GitHub. The ST7735H library is based on the Adafruit GFX library, also available on GitHub.

The TFT library is designed to work with interfaces that use the SPI communications capabilities of an AVR microcontroller. If the TFT shield includes an SD card slot, then the SD library can be used to read and write data by using a separate select signal from an Arduino. The TFT library relies on the SPI library for communication with the screen and SD card, and it also needs to be included in all sketches that use the TFT library.

TFT class

The TFT class constructor is available in two forms. One is used when the standard Arduino SPI pins are used (the hardware SPI), and the second form allows you to specify which pins to use:

TFT(uint8_t cs, uint8_t dc, uint8_t rst)
TFT(uint8_t cs, uint8_t dc, uint8_t mosi, uint8_t sclk, uint8_t rst)

Where:

cs

Chip select pin

dc

Data or command mode select

rst

Reset pin

mosi

Pin used for MOSI if not using hardware SPI

sclk

Pin used for clock if not using hardware SPI

Example:

 #define cs  10
 #define dc  9
 #define rst 8
 TFT disp = TFT(cs, ds, rst);

The Esplora version of the TFT library uses predefined pins. All that is necessary is to instantiate the TFT object:

EsploraTFT disp = EsploraTFT;
begin()

Called to initialize the TFT library components. Must be called before any other functions are used. Typically called in the setup() function of a sketch.

void disp.begin()
background()

Overwrites the entire display screen with a solid color. May be used to clear the display. Note that the screen cannot actually display 256 unique levels per color, but instead uses 5 bits for the blue and red colors, and 6 bits for green.

void disp.background(uint8_t red, uint8_t green, uint8_t blue)
stroke()

Called before drawing on the screen, and sets the color of lines and borders. Like the background() function, stroke() uses 5 bits for the blue and red colors, and 6 bits for green.

void disp.stroke(uint8_t red, uint8_t green, uint8_t blue)
noStroke()

Removes all outline stroke color.

void disp.noStroke()
fill()

Sets the fill color of objects and text on the screen. Like the stroke() function, fill() uses 5 bits for the blue and red colors, and 6 bits for green.

void disp.fill(uint8_t red, uint8_t green, uint8_t blue)
noFill()

Disables color fills for objects and text.

void disp.noFill()
setTextSize()

Sets the size of the text written by a call to the text() function. The default text size is 1, or 10 pixels. Each increase in the text size increases the height of the text on the screen by 10 pixels.

void disp.setTextSize(uint8_t size)
text()

Writes text to the display at the specified coordinates. The text color is set by calling the fill() function before calling text().

void disp.text(const char * text, int16_t x, int16_t y),
point()

Draws a point at a specific location on the screen. The point color will be what was specified by a preceding fill() function call.

void disp.point(int16_t x, int16_t y)
line()

Draws a line between start and end coordinates using the color set by the stroke() function.

void disp.line(int16_t x1, int16_t y1, int16_t x2, int16_t y2)
rect()

Draws a rectangle starting at an upper-left point (x, y) with a specified width and height.

void disp.rect(int16_t x, int16_t y, int16_t width, int16_t height)
width()

Reports the width of the TFT screen in pixels.

int disp.width()
height()

Reports the height of the TFT screen in pixels.

int disp.height()
circle()

Draws a circle on the display with a center point of (x, y), and radius of r.

int disp.circle(int16_t x, int16_t y, int16_t r)
image()

Draws an image loaded from an SD card onto the screen at a specified position.

void image(PImage image, int xpos, int yPos)
loadImage()

Creates an instance of a PImage object using the image file name provided. The image file must be a 24-bit BMP type, and it must reside on the root directory of the SD card. Uses the PImage function loadImage().

PImage disp.loadImage(char *imgname)

PImage

The PImage class contains functions to encapsulate and draw a bitmap image on a TFT display.

PImage.height()

Once an image has been encapsulated in a PImage object it may be queried to obtain its height. This function returns the height as an int value.

PImage.width()

Returns the width of an encapsulated image object as an int value.

PImage.isValid()

Returns a Boolean true if the image object contains a valid bitmap file, or false if it does not.

WiFi

The WiFi library gives an Arduino the ability to connect to a wireless network. The descriptions here don’t define all the available functions in detail, since many of them are similar or identical to those found in the Ethernet library. The built-in help in early versions of the Arduino IDE (which, unfortunately, seems to be all that some Linux distributions have available at the time of writing) do not have the WiFi library reference pages, but later versions do. The library source code does seem to be installed with the older versions of the IDE, or at least it is on my Kubuntu development system.

The WiFi library is used with the SPI library to communicate with the WiFi module and an optional SD memory card. A baseline-type Arduino (see Chapter 4) communicates with the WiFi shield using the SPI pins 10, 11, 12, and 13. The Mega-type boards use pins 10, 50, 51, and 52. Also, on the Arduino WiFi shield pin 7 is used as a handshake signal between the Arduino and the WiFi shield, so it should not be used for anything else. Other WiFi shields may have similar restrictions.

The Arduino WiFi shield can act either as a server for accepting incoming connections, or as a client to make a connection with an existing server. The library provides WEP and WPA2 Personal encryption modes, but it does not support WPA2 Enterprise encryption. Also, if a server node does not broadcast its SSID (Service Set Identifier), the WiFi shield will not be able to make a connection.

Like the Ethernet library, the WiFi library is comprised of a collection of five C++ classes. Most of the classes inherit from parent classes, but you don’t need to bother with the details for most applications. However, if you need to see the low-level class definitions for Client, Server, UDP, and others, they can be found in the directory libraries/WiFi in the Arduino source code. The following list shows the five classes of the WiFi library and the public member functions of each class:

  • WiFi class

    • begin()

    • disconnect()

    • config()

    • setDNS()

    • SSID()

    • BSSID()

    • RSSI()

    • encryptionType()

    • scanNetworks()

    • getSocket()

    • macAddress()

  • IPAddress class

    • localIP()

    • subnetMask()

    • gatewayIP()

  • Server class

    • WiFiServer()

    • begin()

    • available()

    • write()

    • print()

    • println()

  • Client class

    • WiFiClient()

    • connected()

    • connect()

    • write()

    • print()

    • println()

    • available()

    • read()

    • flush()

    • stop()

  • UDP class

    • begin()

    • available()

    • beginPacket()

    • endPacket()

    • write()

    • parsePacket()

    • peek()

    • read()

    • flush()

    • stop()

    • remoteIP()

    • remotePort()

Note

The Arduino WiFi shield is based on the HDG204 802.11b/g chip. Be aware that other WiFi shields, such as Adafruit’s WiFi shield based on the TI CC3000 WiFi chip, may use a different library specifically for a particular WiFi chip. Much of the functionality should be similar to what is listed here, but there will still be some differences to take into consideration. The Adafruit library is available on GitHub. Refer to the Adafruit website for details.

WiFi class

The following is a quick summary of the WiFi classes. For function descriptions, refer to the Ethernet library.

The WiFi class contains functions to initialize the library and the network settings. The class definition cna be found in the include file WiFi.h.

WiFiClass()
int begin(char* ssid)
int begin(char* ssid, uint8_t key_idx, const char* key)
int begin(char* ssid, const char *passphrase)
int disconnect()
void config(IPAddress local_ip)
void config(IPAddress local_ip, IPAddress dns_server)
void config(IPAddress local_ip, IPAddress dns_server, IPAddress gateway)
void config(IPAddress local_ip, IPAddress dns_server, 
            IPAddress gateway, IPAddress subnet)
void setDNS(IPAddress dns_server1)
void setDNS(IPAddress dns_server1, IPAddress dns_server2)
char* SSID()
char* SSID(uint8_t networkItem)
uint8_t* BSSID(uint8_t* bssid)
int32_t RSSI()
int32_t RSSI(uint8_t networkItem)
uint8_t encryptionType()
uint8_t encryptionType(uint8_t networkItem)
int8_t scanNetworks()
static uint8_t getSocket()
uint8_t* macAddress(uint8_t* mac)
static char* firmwareVersion()
uint8_t status()
int hostByName(const char* aHostname, IPAddress& aResult)

IPAddress class

Like the IPAddress in the Ethernet library, the IPAddress class in the WiFi library provides a container for information about the network configuration.

IPAddress localIP()
IPAddress subnetMask()
IPAddress gatewayIP()

Server class

The Server class creates servers that can accept connections from clients to exchange data.  A client may be another Arduino with a WiFi shield, a desktop PC, notebook computer, or just about any device with compatible WiFi capability. Refer to “Server class: EthernetServer” for descriptions of print() and println().

WiFiServer(uint16_t)
WiFiClient available(uint8_t* status = NULL)
void begin()
int print(data)
int print(data, base)
int println()
int println(data)
int println(data, base)
size_t write(uint8_t)
size_t write(const uint8_t *buf, size_t size)
uint8_t status()

Client class

The Client class creates WiFi clients that can connect to servers in order to send and receive data. A server may be another Arduino with a WiFi shield, a desktop PC, and notebook computer, or just about any device with compatible WiFi server capability. Refer to “Server class: EthernetServer” for descriptions of print() and println().

WiFiClient()
WiFiClient(uint8_t sock)
uint8_t connected()
int connect(IPAddress ip, uint16_t port)
int connect(const char *host, uint16_t port)
size_t write(uint8_t)
size_t write(const uint8_t *buf, size_t size)
int print(data)
int print(data, base)
int println()
int println(data)
int println(data, base)
int available()
int read()
int read(uint8_t *buf, size_t size)
int peek()
void flush()
void stop()

UDP class

The UDP class enables short messages to be sent and received using the UDP protocol. Unlike TCP/IP, which is a stream protocol (i.e., it has no definite start and stop boundaries), UDP is a datagram protocol. In this case, each item of data is a single packet, called a datagram, and the data must fit within the boundaries of the datagram packet. UDP does not have error detection, nor does it guarantee delivery of the data, but for short packets of noncritical data, or where the upper-level software can handle things like error detection and retries, it offers a fast and relatively simple way to move data around between hosts.

WiFiUDP()
uint8_t begin(uint16_t)
void stop()
int beginPacket(IPAddress ip, uint16_t port)
int beginPacket(const char *host, uint16_t port)
int endPacket()
size_t write(uint8_t)
size_t write(const uint8_t *buffer, size_t size)
int parsePacket()
int available()
int read()
int read(unsigned char* buffer, size_t len)
int peek()
void flush()
IPAddress remoteIP()
uint16_t remotePort()

Wire

The Wire library is used to communicate with TWI- or I2C-type devices. Refer to Chapters 2 and 3 for more information about the TWI capabilities of the AVR microcontrollers. Chapter 8 describes some shields that use I2C for communications with the Arduino.

The following table defines where the TWI pins are located on different types of Arduino boards. Refer to Chapter 4 for board pinout diagrams.

Board SDA SCL

Uno, Ethernet

A4

A5

Mega2560

20

21

Leonardo

2

3

The core of the Wire library is the TwoWire class.

Example:

TwoWire twi = TwoWire()
begin()

Initializes the TWI library and activates the I2C interface in either master or servant mode. If the address is not specified, the I2C interface defaults to master mode.

void twi.begin()
void twi.begin(uint8_t addr)
void twi.begin(int addr)
requestFrom()

Used by the interface master to request data from a servant device. The data bytes are retrieved with the available() and read() functions. Returns the number of bytes of data read from the addressed device.

uint8_t twi.requestFrom(uint8_t addr, uint8_t quantity)
uint8_t twi.requestFrom(uint8_t addr, uint8_t quantity, uint8_t stop)
uint8_t twi.requestFrom(int addr, int quantity)
uint8_t twi.requestFrom(int addr, int quantity, int stop)
beginTransmission()

Begins a data transmission to an I2C servant device at the spefifiend address. Data is queued for transmission using the write() function and then actually transmitted using the endTransmission() function.

void twi.beginTransmission(uint8_t addr)
void twi.beginTransmission(int addr)
endTransmission()

Transmits the bytes that were queued by write() to a servant device and then ends a transmission that was initiated by beginTransmission().

uint8_t twi.endTransmission()
uint8_t twi.endTransmission(uint8_t stop)
write()

Writes the supplied data to a queue for transmission from a master to a servant device, or from a servant device to a master in response to a data request. Returns the number of bytes written into the queue.

size_t twi.write(uint8_t data)
size_t twi.write(const uint8_t *data)
size_t twi.write(const uint8_t *data, size_t len)
available()

Returns the number of bytes available to the read() function. Called by a master device after a call to requestFrom(), and on a servant device after a data receive event.

int twi.available()
read()

Reads a byte that was transferred from master to servant, or vice versa.

int twi.read()
onReceive()

Registers the function to call (a handler function) when a servant device receives data from a master.

void twi.onReceive(void (*)(int))
onRequest()

Registers the function to call when a master requests data from a servant device.

void twi.onRequest(void (*)(void))

Esplora

The Arduino Esplora library provides a set of functions for easily interfacing with the sensors and actuators on the Esplora board via the Esplora class. For pinout information refer to Chapter 4.

The sensors available on the board are:

  • Two-axis analog joystick

  • Center pushbutton of the joystick

  • Four pushbuttons

  • Microphone

  • Light sensor

  • Temperature sensor

  • Three-axis accelerometer

  • Two TinkerKit input connectors

The actuators available on the board are:

  • Bright RGB (Red-Green-Blue) LED

  • Piezo buzzer

  • 2 TinkerKit output connectors

Esplora()

Creates an instance of an Esplora object.

Esplora esp = Esplora()
readSlider()

Returns an integer value corresponding to the current position of the slider control. The value can range from 0 to 1023.

unsigned int esp.readSlider()
readLightSensor()

Returns an integer value corresponding to the amount of light impinging on the light sensor on an Esplora board.

unsigned int esp.readLightSensor()
readTemperature()

Returns a signed integer with the current ambient temperature in either Fahrenheit or Celsius. The scale argument takes either DEGREES_C or DEGREES_F. The temperature ranges are –40C to 150C, and –40F to 302F.

int esp.readTemperature(const byte scale);
readMicrophone()

Returns an integer value corresponding to the amount of ambient noise detected by the microphone. The returned value can range from 0 to 1023.

unsigned int esp.readMicrophone()
readJoystickSwitch()

Reads the joystick button and returns either 0 or 1023. An alternative is the readJoystickButton() function.

unsigned int esp.readJoystickSwitch()
readJoystickButton()

Reads the joystick’s button and returns either LOW or HIGH (pressed or not pressed). This function performs the same function as readJoystickSwitch(), but it returns a value that is consistent with the readButton() function.

bool readJoystickButton()
readJoystickX()

Returns the x-axis position of the joystick as a value between –512 and 512.

int esp.readJoystickX()
readJoystickY()

Returns the y-axis position of the joystick as a value between –512 and 512.

int esp.readJoystickY()
readAccelerometer()

Returns the current value for a selected axis, with the possible values for the axis argument being X_AXIS, Y_AXIS, and Z_AXIS. A return value of 0 indicates that the accelerometer is perpendicular to the direction of gravity, and positive or negative values indicate the direction and rate of acceleration.

int esp.readAccelerometer(const byte axis)
readButton()

Reads the current state of a particular button on an Esplora. Returns a low (false) value if the button is pressed, or a high (true) value if not.

bool esp.readButton(byte channel)
writeRGB()

Writes a set of values defining the brightness levels of the red, green, and blue elements in the Esplora’s RGB LED.

void esp.writeRGB(byte red, byte green, byte blue)
writeRed()

Accepts an argument that defines the brightness of the red LED with a range of 0 to 255.

void esp.writeRed(byte red)
writeGreen()

Accepts an argument that defines the brightness of the green LED with a range of 0 to 255.

void esp.writeGreen(byte green)
writeBlue()

Accepts an argument that defines the brightness of the blue LED with a range of 0 to 255.

void esp.writeBlue(byte blue)
readRed()

Returns the value last used to set the brightness of the red LED.

byte esp.readRed()
readGreen()

Returns the value last used to set the brightness of the green LED.

byte esp.readGreen()
readBlue()

Returns the value last used to set the brightness of the blue LED.

byte esp.readBlue()
tone()

Emits a tone from the Esplora’s on-board annunciator at a given frequency. If no duration argument is supplied the tone will continue until the noTone() function is called. Only one frequency at a time can be used. Note that using the tone() function will interfere with controlling the level of the red LED.

void esp.tone(unsigned int freq)
void esp.tone(unsigned int freq, unsigned long duration)
noTone()

Terminates the output of the square wave signal to the annunciator.

void esp.noTone()
USB libraries

The core USB libraries allow an Arduino Leonardo or Micro to appear as a mouse and/or keyboard device to a host computer.

Note

If the Mouse or Keyboard library is constantly running, it will be difficult to program the Arduino. Functions such as Mouse.move() and Keyboard.print() should only be called when the host is ready to handle them. One way to deal with this is to use a control system or a physical switch to control when the Arduino will emit mouse or keyboard messages.

Mouse

The mouse functions allow a Leonardo or Micro to control cursor movement on a host computer. The reported cursor position is always relative to the cursor’s previous location; it is not absolute.

Mouse.begin()
Mouse.click()
Mouse.end()
Mouse.move()
Mouse.press()
Mouse.release()
Mouse.isPressed()
Keyboard

The keyboard functions allow a Leonardo or Micro to send keystrokes to an attached host computer. While not every possible ASCII character, particularly the nonprinting ones, can be sent with the Keyboard library, the library does support the use of modifier keys.

Keyboard.begin()
Keyboard.end()
Keyboard.press()
Keyboard.print()
Keyboard.println()
Keyboard.release()
Keyboard.releaseAll()
Keyboard.write()

Modifier keys change the behavior of another key when pressed simultaneously. Table 7-1 lists the modifier keys supported by the Leonardo.

Table 7-1. USB keyboard modifier keys
Key Hex value Decimal value Key Hex value Decimal value

KEY_LEFT_CTRL

0x80

128

KEY_PAGE_UP

0xD3

211

KEY_LEFT_SHIFT

0x81

129

KEY_PAGE_DOWN

0xD6

214

KEY_LEFT_ALT

0x82

130

KEY_HOME

0xD2

210

KEY_LEFT_GUI

0x83

131

KEY_END

0xD5

213

KEY_RIGHT_CTRL

0x84

132

KEY_CAPS_LOCK

0xC1

193

KEY_RIGHT_SHIFT

0x85

133

KEY_F1

0xC2

194

KEY_RIGHT_ALT

0x86

134

KEY_F2

0xC3

195

KEY_RIGHT_GUI

0x87

135

KEY_F3

0xC4

196

KEY_UP_ARROW

0xDA

218

KEY_F4

0xC5

197

KEY_DOWN_ARROW

0xD9

217

KEY_F5

0xC6

198

KEY_LEFT_ARROW

0xD8

216

KEY_F6

0xC7

199

KEY_RIGHT_ARROW

0xD7

215

KEY_F7

0xC8

200

KEY_BACKSPACE

0xB2

178

KEY_F8

0xC9

201

KEY_TAB

0xB3

179

KEY_F9

0xCA

202

KEY_RETURN

0xB0

176

KEY_F10

0xCB

203

KEY_ESC

0xB1

177

KEY_F11

0xCC

204

KEY_INSERT

0xD1

209

KEY_F12

0xCD

205

Contributed Libraries

There are many contributed libraries available for the Arduino boards. Some have been created by individuals, others by firms that sell and support Arduino hardware and accessories. In addition, some vendors also provide libraries or support software for their products, and a search of the appropriate website or examination of an eBay listing will often uncover this code.

Tables 7-2 through 7-8 list a selection of these libraries, broken down by category. The descriptions are necessarily brief; there is just no way they could all be described sufficiently to do them justice and still have this be a compact-format book. For links for further details, see http://www.arduino.cc/en/Reference/Libraries.

Table 7-2. Communication (networking and protocols)
Library Description

Messenger

For processing text-based messages from the computer

NewSoftSerial

An improved version of the SoftwareSerial library

OneWire

For controlling devices (from Dallas Semiconductor) that use the One Wire protocol

PS2Keyboard

For reading characters from a PS2 keyboard

Simple Message System

For sending messages between the Arduino and the computer

SSerial2Mobile

For sending text messages or emails using a cell phone (via AT commands over SoftwareSerial)

Webduino

An extensible web server library (for use with the Arduino Ethernet shield)

X10

For sending X10 signals over AC power lines

XBee

For communicating with XBees in API mode

SerialControl

For remote control of other Arduinos over a serial connection

Table 7-3. Sensing
Library Description

Capacitive Sensing

For turning two or more pins into capacitive sensors

Debounce

For reading noisy digital inputs (e.g., from buttons)

Table 7-4. Displays and LEDs
Library Description

GFX

Base class with standard graphics routines (by Adafruit Industries)

GLCD

Graphics routines for LCDs based on the KS0108 or equivalent chipset

LedControl

For controlling LED matrixes or 7-segment displays with a MAX7221 or MAX7219

LedControl

An alternative to the Matrix library for driving multiple LEDs with Maxim chips

LedDisplay

For controlling an HCMS-29xx scrolling LED display

Matrix

Basic LED matrix display manipulation library

PCD8544

For the LCD controller on Nokia 55100-like displays (by Adafruit Industries)

Sprite

Basic image sprite manipulation library for use in animations with an LED matrix

ST7735

For the LCD controller on a 1.8”, 128 × 160-pixel TFT screen (by Adafruit Industries)

Table 7-5. Audio and waveforms
Library Description

FFT

For frequency analysis of audio or other analog signals

Tone

For generating audio frequency square waves in the background on any microcontroller pin

Table 7-6. Motors and PWM
Library Description

TLC5940

For controlling the TLC5940 IC, a 16-channel, 12-bit PWM unit

Table 7-7. Timing
Library Description

DateTime

A library for keeping track of the current date and time in software

Metro

Helps you time actions at regular intervals

MsTimer2

Uses the timer 2 interrupt to trigger an action every N milliseconds

Table 7-8. Utilities
Library Description

PString

A lightweight class for printing to buffers

Streaming

A library that simplifies print statements

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.145.87.161