: dev = device (ar, 'I2CAddress', address)
: dev = device (ar, 'SPIChipSelectPin', pin)
: dev = device (ar, 'Serial', serialid)
: dev = device (..., propname, propvalue)

Create an i2c, spi or serial object to communicate on a connected arduino.

Inputs

ar - connected arduino object

propname, propvalue - property name/value pair for values to pass to devices.

A property of ’i2caddress’, ’spichipselectpin’ or ’serial’ must be specified to denote the device type to create.

i2caddress - address to use for device on I2C bus.

pin - pin to use for device SPI chip select.

serialid - Serial port id to use

Additional properties can also be specified for the device object

Currently known input I2C properties values:

bus

bus number (when arduino board supports multiple I2C buses) with value of 0 or 1.

noprobe

Do not probe the existence of device on creation if set to 1 (default 0)

bitrate

bit rate speed in Mbs - default 100000

Currently known input SPI properties values:

bitrate

bit rate speed in Mbs

bitorder

’msbfirst’ or ’lsbfirst’

spimode

SPI mode 0 - 3.

Currently known input Serial properties values:

baudrate

baudrate value (default 9600)

databits

number of databits (5,6,7,8) (default 8)

stopbits

number of stopbits (1,2) (default 1)

parity

parity of device (’odd’,’even’,’none’) (default ’none’)

Outputs

dev - new created device object.

Properties

The object has the following public properties:

parent

The parent (arduino) for this device

interface

The interface type for this device ("SPI" or "I2C" or "Serial")

In addition, depending on type, the object will have these properties:

I2C Properties

The object has the following public properties:

bus

bus used for created object

i2caddress

I2C address set for object

sclpin

the SCL pin of the device

sdapin

the SDA pin of the device

bitrate

bit rate for the i2c clock

SPI Properties

The object has the following public properties:

spimode

mode used for created object

bitrate

Bitrate set for object

bitorder

Bitorder set for object

spichipselectpin

Pin used for chipselect

mosipin

Pin used for mosi

misopin

Pin used for miso

sckpin

Pin used for sckpin

Serial Properties

The object has the following public properties:

id

serial port id

baudrate

baudrate

databits

number of databits (5,6,7,8)

stopbits

number of stopbits (1,2)

parity

parity of device (’odd’,’even’,’none’)

See also: arduino, i2cdev, spidev.

Package: arduino