mraa  2.0.0
Low Level Skeleton Library for Communication on GNU/Linux platforms
Functions | Typedefs
aio.h File Reference

API Description

AIO is the anlog input & output interface to libmraa. It is used to read or set the voltage applied to an AIO pin.

/* initialize AIO */
aio = mraa_aio_init(AIO_PORT);
if (aio == NULL) {
fprintf(stderr, "Failed to initialize AIO\n");
return EXIT_FAILURE;
}
while (flag) {
value = mraa_aio_read(aio);
float_value = mraa_aio_read_float(aio);
fprintf(stdout, "ADC A0 read %X - %d\n", value, value);
fprintf(stdout, "ADC A0 read float - %.5f\n", float_value);
}
/* close AIO */
status = mraa_aio_close(aio);
if (status != MRAA_SUCCESS) {
goto err_exit;
}

Go to the source code of this file.

Functions

mraa_aio_context mraa_aio_init (unsigned int pin)
 
int mraa_aio_read (mraa_aio_context dev)
 
float mraa_aio_read_float (mraa_aio_context dev)
 
mraa_result_t mraa_aio_close (mraa_aio_context dev)
 
mraa_result_t mraa_aio_set_bit (mraa_aio_context dev, int bits)
 
int mraa_aio_get_bit (mraa_aio_context dev)
 

Typedefs

typedef struct _aio * mraa_aio_context
 

Function Documentation

mraa_aio_context mraa_aio_init ( unsigned int  pin)

Initialise an Analog input device, connected to the specified pin. Aio pins are always 0 indexed reguardless of their position. Check your board mapping for details. An arduino style layout will have A0 as pin14 but AIO0.

Parameters
pinChannel number to read ADC inputs
Returns
aio context or NULL

Here is the caller graph for this function:

int mraa_aio_read ( mraa_aio_context  dev)

Read the input voltage. By default mraa will shift the raw value up or down to a 10 bit value.

Parameters
devThe AIO context
Returns
The current input voltage or -1 for error

Here is the caller graph for this function:

float mraa_aio_read_float ( mraa_aio_context  dev)

Read the input voltage and return it as a normalized float (0.0f-1.0f).

Parameters
devThe AIO context
Returns
The current input voltage as a normalized float (0.0f-1.0f), error will be signaled by -1.0f

Here is the caller graph for this function:

mraa_result_t mraa_aio_close ( mraa_aio_context  dev)

Close the analog input context, this will free the memory for the context

Parameters
devThe AIO context
Returns
Result of operation

Here is the caller graph for this function:

mraa_result_t mraa_aio_set_bit ( mraa_aio_context  dev,
int  bits 
)

Set the bit value which mraa will shift the raw reading from the ADC to. I.e. 10bits

Parameters
devthe analog input context
bitsthe bits the return from read should be i.e 10
Returns
mraa result type

Here is the caller graph for this function:

int mraa_aio_get_bit ( mraa_aio_context  dev)

Gets the bit value mraa is shifting the analog read to.

Parameters
devthe analog input context
Returns
bit value mraa is set return from the read function

Here is the caller graph for this function:

Typedef Documentation

typedef struct _aio* mraa_aio_context

Opaque pointer definition to the internal struct _aio. This context refers to one single AIO pin on the board.

Include dependency graph for aio.h: