1

I'm working on a project where I want to be able to program a robotic arm in Arduino using MatLab. I've used the Arduino Uno with an Adafruit Motor Shield V2.3 and the OWI Robotic Arm Edge kit. The arm is perfectly assembled and works just fine with the standard remote it comes with. All of the connections with the Adafruit Motor Shield are correctly placed, and the shield has been soldered onto pins that connect to the Uno.

I am absolutely positive that the physical and electronic setup is correct. However, whenever I try to move the motors attached to the shield, none of them register. Below is my code:

a = arduino('COM3', 'Uno', 'Libraries', 'Adafruit\MotorShieldV2')
shield = addon(a, 'Adafruit\MotorShieldV2')
addrs = scanI2CBus(a,0);

dcm = dcmotor(shield, 1);
dcm.Speed = 0.01;
start(dcm)

dcm2 = dcmotor(shield, 2);
dcm2.Speed = 0.2;
start(dcm2)

dcm3 = dcmotor(shield, 3);
dcm3.Speed = 0.2;
start(dcm3)

dcm4 = dcmotor(shield, 4);
dcm4.Speed = 0.2;
start(dcm4)

I believe the issue is with the third line:

addrs = scanI2CBus(a,0);

When I run the code, the shield has the following properties:

shield = 

motorshieldv2 with properties:

          Pins: A4(SDA), A5(SCL)
    I2CAddress: 96 (0x60)
  PWMFrequency: 1600 (Hz)

So while the I2C address should be 0x60, the actual value of the addrs variable is a 2x1 cell instead of 0x60, as the project demands/specifies as seen in the workspace:

Workspace

I'm almost certain that this is the reason behind why none of the motors are being registered, but how can I fix it?

Thanks in advance for any assistance! Please let me know if I need to supply more information.

1 Answer 1

1

The documentation in MATLAB for scanI2CBus() notes that the return is a cell array of character vectors

They even give the example:

a = arduino('COM9');
scanI2CBus(a,1)

with result:

ans = 
            '0x48'

It appears you will need to parse the cell array into the numeric value or otherwise convert it to a number, perhaps using the MATLAB function hex2dec('hex_value')

4
  • Thank you for your help, I'll give it a try as soon as I get home! I'll also be sure to share my results, hopefully I'll get feedback from my motors. Out of curiosity, is it "allowed" for me to assign the value '0x60' to the I2C address variable?
    – Malik
    Commented Nov 30, 2017 at 22:44
  • The I2C address is defined by the device. Your sensor probably has it hard coded or it may be set by hardware jumpers on the sensor. It’s not likely you can change it by just assigning a value to the variable. Commented Dec 1, 2017 at 0:05
  • I think I found out what the defecting factor is--the I2C address issue may be due to improper soldering of the Motor Shield to the Arduino itself; I realized that the power of the Motor Shield flickers in and out, so that may be the root of the problem.
    – Malik
    Commented Dec 2, 2017 at 14:16
  • Don’t try to power the motor shield from the Arduino. Commented Dec 2, 2017 at 14:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.