upm  1.7.1
Sensor/Actuator repository for libmraa (v2.0.0)
Public Member Functions | Protected Member Functions | Protected Attributes

API for the NLGPIO16 16 channel USB GPIO Module. More...

Detailed Description

The NLGPIO16 is a USB adapter providing access to 16 GPIO's, 7 of which can be used as analog inputs. The GPIO's are 3.3v only. An external power supply can be connected to provide more current if the need arises.

It is recommended to use a series resistor with the GPIO/ADC pins when interfacing with other circuits. In output mode, GPIOs can source up to 8mA (gpio8-gpio15). So no additional circuitry is needed to drive regular LEDs. A 470 Ohms series resistor is recommended for current limiting when connecting an LED to a GPIO. In contrast to GPIOs, analog inputs can read voltages at any level between 0 to 3.3V volts. It is recommended to use a series resistor to protect the input from stray voltages and spikes. The internal Analog to Digital converter supports 10 bits resolution which is adequate for most applications.

Maximum IO source/sink current on GPIO 0-7 is 2mA Maximum IO source/sink current on GPIO 8-15 is 8mA

int
main(int argc, char** argv)
{
// Instantiate a NLGPIO16 Module on the default UART (/dev/ttyACM0)
upm::NLGPIO16 sensor;
// get the Version
cout << "Device Version: " << sensor.getVersion() << endl;
// read the gpio at pin 3
cout << "GPIO 3 Value: " << sensor.gpioRead(3) << endl;
// read the analog voltage at pin 5
cout << "Analog 5 Voltage: " << sensor.analogReadVolts(5) << endl;
// set the gpio at pin 14 to HIGH
sensor.gpioSet(14);
return 0;
}

Public Member Functions

 NLGPIO16 (std::string uart=NLGPIO16_DEFAULT_UART_DEV)
 
 ~NLGPIO16 ()
 
std::string getVersion ()
 
std::string getID ()
 
void setID (std::string id)
 
void gpioSet (int gpio)
 
void gpioClear (int gpio)
 
bool gpioRead (int gpio)
 
unsigned int gpioReadAll ()
 
void gpioSetIOMask (int mask)
 
void gpioSetIODir (int mask)
 
void gpioWriteAll (int mask)
 
int analogReadValue (int adc)
 
float analogReadVolts (int adc)
 

Protected Member Functions

bool dataAvailable (unsigned int millis)
 
std::string readStr (int len)
 
int writeStr (std::string data)
 
std::string sendCommand (std::string cmd)
 

Protected Attributes

mraa::Uart m_uart
 

Constructor & Destructor Documentation

NLGPIO16 ( std::string  uart = NLGPIO16_DEFAULT_UART_DEV)

NLGPIO16 object constructor

Parameters
uartUART device path to use. Default is /dev/ttyACM0.
~NLGPIO16 ( )

NLGPIO16 object destructor

Member Function Documentation

string getVersion ( )

Get the version of the device

Returns
String containing device revision
string getID ( )

Get the device ID. The device ID is an 8 character alpha-numeric string.

Returns
String containing device ID
void setID ( std::string  id)

Set the device ID. The device ID is an 8 character alpha-numeric string. The supplied ID must be exactly 8 characters in length.

Parameters
idString containing a new 8 character device ID
void gpioSet ( int  gpio)

Set a gpio output to the HIGH (1) state. The gpio is automatically set as an output when this call is made, regardless of it's previous mode.

Parameters
gpioThe gpio to set. Valid values are between 0-15
void gpioClear ( int  gpio)

Set a gpio output to the LOW (0) state. The gpio is automatically set as an output when this call is made, regardless of it's previous mode.

Parameters
gpioThe gpio to clear. Valid values are between 0-15
bool gpioRead ( int  gpio)

Read the state of a gpio. The gpio is automatically set as an input when this call is made, regardless of it's previous mode.

Parameters
gpioThe gpio to read. Valid values are between 0-15
Returns
true if the gpio is in the HIGH state, false otherwise
unsigned int gpioReadAll ( )

Read the state of all gpios. The returned integer is a bitmask of all 16 gpios, where a 0 bit means the gpio is in the LOW state, whereas a 1 bit means the gpio is in a HIGH state.

Returns
bitmask of the state of all 16 gpios. The LSB is gpio0.
void gpioSetIOMask ( int  mask)

Set a mask for selectively updating multiple gpios with the gpioIODir() and gpioWriteAll() methods. Each bit set in the 16 bit argument (LSB = gpio0) represents whether the two previously mentioned methods will act on a given gpio or not. A 0 in a given bit position will cause any update to that gpio via gpioIODir() and gpioWriteAll() to be ignored, while a 1 bit enables that gpio to be affected by those two methods.

Parameters
maskA bitmask of the 16 gpios affected by gpioIODir() and gpioWriteAll()
void gpioSetIODir ( int  mask)

Set the driection mode (input or output) for all gpios enabled by gpioSetIOMask(). A 0 in a given bit position (LSB = gpio0) configures the gpio as an output, and a 1 bit configures the gpio as an input. Only the gpios enabled by gpioSetMask() are affected by this call.

Parameters
maskA bitmask of the 16 gpios whose direction mode is to be set
void gpioWriteAll ( int  mask)

Write all enabled gpios (set via gpioSetIOMask()) to a given value. A 1 bit (LSB = gpio0) sets the given output to HIGH, a zero sets the given output to LOW. Only the gpios enabled by gpioSetMask() are affected by this call.

Parameters
maskThe values to set for the 16 gpios (LSB = gpio0)
int analogReadValue ( int  adc)

Read the raw analog input value present at the given gpio. The gpio is switched to analog input mode by this call, regardless of any previous mode. The returned value will be a number between 0-1023 (10 bit resolution). Only the first 7 gpios (0-6) can be used for analog input.

Parameters
adcThe gpio number to read (0-6)
Returns
The raw integer value from the ADC (0-1023)

Here is the caller graph for this function:

float analogReadVolts ( int  adc)

Read the raw analog input value present at the given gpio and return the corresponding voltage value at the pin. The gpio is switched to analog input mode by this call, regardless of any previous mode. The returned value will be a number between 0.0-3.3, depending on the voltage present at the pin. Only the first 7 gpios (0-6) can be used for analog input.

Parameters
adcThe gpio number to read (0-6)
Returns
The voltage present at the pin

Here is the call graph for this function:


The documentation for this class was generated from the following files: