addon

Connection to add-on device for Arduino hardware

Description

An object created by addon represents a connection to an add-on device on Arduino® hardware. You can use the addon function to create add-on libraries such as L3G, LSM303, 1–Wire, HC-SR04, and Capacitive sensor. These libraries are not part of the MATLAB® Support Package for Arduino Hardware and must be downloaded separately. You can also create your own custom Arduino add-on libraries as mentioned in Create Custom Arduino Add-On Device, Library, or Code.

This page is specifically about the 'Adafruit\MotorshieldV2' add-on library for the motorshieldv2 object, included in the MATLAB Support Package for Arduino Hardware. Attach an Adafruit® Motor Shield V2 to Arduino hardware, and use 'Adafruit\MotorshieldV2' as an input argument to create a motorshieldv2 object. You can create connections to motors on the shield using object functions.

Creation

Description

example

shield = addon(a,'Adafruit\MotorshieldV2') creates an add-on connection to Adafruit Motor Shield V2 connected to the Arduino hardware a.

example

shield = addon(a,'Adafruit\MotorshieldV2',Name,Value) adds additional options specified by one or more Name,Value pair arguments.

Input Arguments

expand all

Arduino hardware connection created using arduino, specified as an arduino object.

Example: shield = addon(a,'Adafruit\MotorshieldV2') creates a connection to motor shield on the specified arduino object a.

Name-Value Pair Arguments

Specify optional comma-separated pairs of Name,Value arguments. Name is the argument name and Value is the corresponding value. Name must appear inside quotes. You can specify several name and value pair arguments in any order as Name1,Value1,...,NameN,ValueN.

Example: motor = addon(a, 'Adafruit\MotorshieldV2','I2CAddress', '0x07' 'pwmfrequency', 3200);

I2C address, specified as the comma-separated pair consisting of 'I2CAddress' and either a hexadecimal value specified as a character vector or a scalar integer.

Example: shield = addon(a,'Adafruit\MotorshieldV2','I2CAddress',0x61); sets the I2C address to 97 or 0x61.

PWM frequency of Adafruit Motor Shield V2, specified as the comma-separated pair consisting of 'PWMFrequency' and a number in hertz.

Example: shield = addon(a,'Adafruit\MotorshieldV2','PWMFrequency',3200); sets the PWM frequency to 3200Hz.

Properties

expand all

This property is read-only.

Arduino pins used by AdafruitMotor Shield V2. This is a read only property.

Example:

>> shield.SCLPin

ans =

    'A5'

Data Types: char

This property is read-only.

Arduino pins used by AdafruitMotor Shield V2. This is a read only property.

Example:

>> shield.SDAPin

ans =

    'A4'

Data Types: char

This property is read-only.

I2C device address, specified as a character vector that represents a hexadecimal value or a scalar integer.

Example:

>> shield.I2CAddress

ans =

    96

Data Types: double | char

This property is read-only.

PWM frequency of Adafruit Motor Shield V2, specified as a number in hertz.

Example:

>> shield.PWMFrequency

ans =

        1600

Data Types: double

Object Functions

Use these object functions to create a connection to a motor on the Adafruit Motor Shield V2.

dcmotorConnection to DC motor on Adafruit Motor Shield V2 for Arduino
servoConnection to servo motor on Adafruit Motor Shield V2 for Arduino
stepperConnection to stepper motor on Adafruit Motor Shield V2 for Arduino

Examples

collapse all

Connect to Arduino hardware, and create an add-on connection to an Adafruit Motor Shield.

a = arduino('COM4','Uno','Libraries','Adafruit/MotorShieldV2');
motor = addon(a,'Adafruit\MotorshieldV2')
motor = 
  motorshieldv2 with properties:

          SCLPin: 'A5'
          SDAPin: 'A4'
      I2CAddress: 96 ('0x60')
    PWMFrequency: 1600 (Hz)

Connect to Arduino hardware, and create an add-on connection to an Adafruit Motor Shield with an I2C address of 0x61 and PWM frequency of 1200.

a = arduino('COM4','Uno','Libraries','Adafruit/MotorShieldV2');
Updating server code on board Uno (COM4). This may take a few minutes.
motor = addon(a,'Adafruit/MotorShieldV2','I2CAddress','0x61','PWMFrequency',1200)
motor = 
  motorshieldv2 with properties:

          SCLPin: 'A5'
          SDAPin: 'A4'
      I2CAddress: 97 ('0x61')
    PWMFrequency: 1200 (Hz)

Introduced in R2014b