Next: Arduino I2C Functions, Previous: General Functions, Up: Function Reference [Contents][Index]
Create a arduino object with a connection to an arduino board.
port - full path of serial port to connect to. For Linux, usually /dev/ttySXXX, for windows COMXX.
board - name of board to connect (default is ’uno’).
propname, propvalue - property name and value pair for additional properties to pass to the creation of the arduino object.
Currently properties are ignored.
if the arduino function is called without parameters, it will scan for the first available arduino it can find and connect to it.
retval - a successfully connected arduino object.
The arduino object has the following public properties:
name assigned to the arduino object
true / false flag for whether debug in turned on
true / false flag for whether to force show of the arduino IDE to reprogram the arduino
the communications port the board is connected to.
The name of the board type that the arduino connected to
The libraries currently programmed onto the board
The pins available for use on the board
The analog voltage reference
See also: scanForArduinos, arduinosetup.
Check that an address of given address responds on the I2C bus
ar - arduino object connected to a arduino board.
address - I2C address number to check
bus - bus number to check for I2C device, when multiple buses are available. If the bus is not specified, it will default to 0.
retval - boolean value of true if address responds on the I2C bus
# create arduino connection.
ar = arduino();
# scan for devices on the I2C bus
checkI2CAddress (ar)
# output if a device using that address is attached
ans =
1
See also: arduino, scanI2Cbus.
Set/Get pin mode for a specified pin on arduino connection.
configurePin (ar, pin) will get the current mode of the specified pin.
configurePin (ar, pin, mode) will attempt set the pin to the specified mode if the mode is unset.
ar - the arduino object of the connection to an arduino board.
pin - string name of the pin to set/get the mode of.
mode - string mode to set the pin to.
mode - string current mode of the pin.
Valid modes can be:
See also: arduino.
Set/Get pin mode for a specified pin on arduino connection.
configurePinResource (ar, pin) will get the current mode of the specified pin.
configurePinResource (ar, pin, owner, mode) will attempt set the pin to the specified mode and owner.
If the pin is already owned by another owner, the configure will fail unless the force option is used. If the mode is already set, configure will fail unless force is used.
ar - the arduino object of the connection to an arduino board.
pin - string name of the pin to set/get the mode of.
mode - string mode to set the pin to.
owner - string name to use as the pin owner.
force - boolean to force mode change. If not set, it will be false.
currmode - current string mode of the pin.
Valid modes can be:
See also: arduino, configurePin.
Decrement the count of a named resource by 1 and return the new count.
ar - connected arduino object
resource - name of resource to decrement count.
count = count of uses registered to resource.
See also: getResourceCount. incrementResourceCount.
Free resources of an arduino object.
dev - object to free
See also: arduino.
Display the arduino object in a verbose way, showing the board and available pins.
ar - the arduino object.
If the arduino object has debug mode set, additional information will be displayed.
See also: arduino.
Get the endian used by the connected arduino.
ar - arduino object connected to a arduino board.
endian - string representing the endian used by the arduino board.
’L’ means little endian, ’B’ means big endian
See also: arduino, getMCU.
Get a cell list of pin Ids available are used for I2C mode.
ar - the arduino object.
bus - optional bus number 0 or 1 for boards that support more than 1 bus.
pinlist - cell list of pin numbers available for I2C use.
See also: arduino.
Get a cell list of pin Ids available have interrupt functionality
ar - the arduino object.
pinlist - cell list of pin numbers available for interrupt use.
See also: arduino.
Get a cell list of pin Ids available are connected natively to LEDs.
ar - the arduino object.
pinlist - cell list of pin numbers available for LED use.
See also: arduino.
Get the MCU used by the connected arduino.
ar - arduino object connected to a arduino board.
mcu - string representing the mcu used by the arduino board.
See also: arduino.
Get a cell list of pin Ids available for PWM use.
ar - the arduino object.
pinlist - cell list of pin numbers available for PWM use.
See also: arduino.
Get the pin actual pin name from a pin alias.
For example, the arduino Leonardo, pin "D4" is also "A6".
ar - the connected arduino object.
pin - a pin name.
out - alias pin name, or same as pin if the pin doesnt have any alias names.
See also: arduino, configurePinResource, getResourceOwner.
Get the pin information from the input pins values.
getPinInfo (ar, pin) will get information for a single pin.
getPinInfo (ar, pinarray) will get a cell array of pin information
ar - the connected arduino object.
pin - a pin number or pin name.
pinarray - the array of pin numbers or names
The pininfo struct contains the following fields:
Terminal number of the pin
String name of the pin
Current item owner of the pin
Current configured mode for the pin
pininfo - struct on pin information.
pininfolist - cell array of pin info
See also: arduino, configurePinResource, getResourceOwner.
Get the pin names from the input terminal values.
ar - the connected arduino object.
terminals - the numeric pin number, or array of pin numbers to get pin names.
pinnames - the string names of each input pin. If terminals was a single value, the return will be a single string, otherwise it will return a cell array of each pin name.
See also: arduino, getTerminalsFromPins.
Get the count of uses of a given resource.
ar - connected arduino object
resource - name of resource to get count for.
count = count of uses registered to resource.
See also: incrementResourceCount. decrementResourceCount.
Get the owner of pin allocated previously by configurePinResource.
ar - connected arduino object
terminal - terminal number to get owner of.
owner = owner of the terminal pin, or "" if not owned.
See also: configurePinResource.
Get a cell list of pin Ids available for SPI mode.
ar - the arduino object.
pinlist - cell list of pin numbers available for SPI use.
See also: arduino.
Get a cell list of pin Ids available for servo use.
ar - the arduino object.
pinlist - cell list of pin numbers available for servo use.
See also: arduino, getPWMTerminals.
Get the mode of a pin allocated previously by configurePinResource.
ar - connected arduino object
terminal - terminal number to get owner of.
mode - mode of the terminal pin, or "not_set" if not owned.
See also: configurePinResource, getResourceOwner.
Get the terminal number for each pin.
ar - connected arduino object
pins - single pin name or cell or vector array of pin names.
pinnums - pin number of each named pin. If the input was a single string, returns a number. if the input pins was a vector or cell array, return a cell array of pin numbers corresponding to each input pin name.
See also: arduino, getPinsFromTerminals.
Increment the count value of a named resource by 1 and return the new count
ar - connected arduino object
resource - name of resource to increment count.
count = count of uses registered to resource.
See also: getResourceCount. decrementResourceCount.
Return true if pin is capable of analog input
ar - the connected arduino object
terminal is a terminal number to check
ret return 1 if terminal is a analog pin, 0 otherwise
Return true if pin is capable of digital functions
ar - the connected arduino object
terminal is a terminal number to check
ret return 1 if terminal is a digital pin, 0 otherwise
Play a tone of a given frequency on a specified pin.
ar - connected arduino object
pin - digital pin to play tone on
freq - frequency in hertz to play between 0 and 32767Hz.
duration duration in seconds to play tone between 0 and 30 seconds
If duration is 0 or not specified, tone will continue to play until next tone is commanded. If frequency is 0, tone will stop playing
NOTE: use of playTone can interfere with PWM output.
Read analog voltage of pin.
ar - connected arduino object.
pin - string name of the pin to read.
value - analog value of the pin
ar = arduino ();
readAnalogPin(ar, "A4");
ans =
87
See also: arduino, readVoltage.
Read digital value from a digital I/O pin.
ar - connected arduino object.
pin - string name of the pin to read.
value - the logical value (0, 1, true false) of the current pin state.
a = arduino ();
pinvalue = readDigitalPin (a, 'D5');
See also: arduino, writeDigitalPin.
Read analog voltage of a pin.
ar - connected arduino.
pin - pin name or number to query for voltage
voltage - scaled pin value as a voltage
ar = arduino ();
readVoltage(ar, "A4");
ans =
1.401
See also: arduino, readAnalogPin.
Send reset command to arduino hardware to force a hardware reset.
ar - connected arduino object.
See also: arduino.
Send a command with option data to the connected arduino, waiting up to a specified number of seconds for a response.
ar - connected arduino object.
libname - library sending the command. The name should match a programmed library of the arduino, or an error will be displayed.
commandid - integer value for the command being sent to the arduino.
data - optional data sent with the command.
timeout - optional timeout to wait for data
outdata - data returned back from the arduino in response to command
outsize - size of data received
If the arduino fails to respond with a valid reply, sendCommand will error.
See also: arduino.
Get the number of seconds the arduino board has been running concurrently.
ar - the arduino object of the connection to an arduino board.
sec - the number seconds the board has been running. Note that the count will wrap around after approximately 50 days.
See also: arduino.
Validate that the mode is allowed for specified pin
If the mode is not valid, and error will be thrown.
ar - connected arduino object
pin - name of pin to query mode validity of
mode - mode to query
Known modes are:
See also: arduino, configurePin.
Get version of library code installed on arduino board
ar - the arduino object of the connection to an arduino board.
ver - version string in format of X.Y.Z.
See also: arduino.
Write digital value to a digital I/O pin.
ar - connected arduino object.
pin - string name of the pin to write to.
value - the logical value (0, 1, true false) to write to the pin.
If pin was unconfigured before using, pin is set into digital mode.
a = arduino();
writeDigitalPin(a,'D5',1);
See also: arduino, readDigitalPin.
Set pin to output a square wave with a specified duty cycle.
ar - connected arduino object
pin - pin to write to.
value - duty cycle value where 0 = off, 0.5 = 50% on, 1 = always on.
a = arduino();
writePWMDutyCycle(a,'D5',0.5);
See also: arduino, writePWMVoltage.
Emulate an approximate voltage out of a pin using PWM.
ar - connected arduino object
pin - pin to write to.
voltage - voltage to emulate with PWM, between 0 - 5.0
a = arduino();
writePWMVoltage(a,'D5',1.0);
See also: arduino, writePWMDutyCycle.
Next: Arduino I2C Functions, Previous: General Functions, Up: Function Reference [Contents][Index]