monster moto shield VNH2SP30 and matlab

hi
I want to use the Matlab to control a dc motor with monster moto shield VNH2SP30, I use this shield and control the dc motor with Arduino program but with Matlab, it does not work my code in Matlab is:

a=arduino('Com9','Uno');
writeDigitalPin(a,'D7',1);
writeDigitalPin(a,'D8',0);

but nothing happened

Is there some kind of sketch loaded on to the Arduino, that is meant to understand what those Matlab commands mean?

JohnLincoln:
Is there some kind of sketch loaded on to the Arduino, that is meant to understand what those Matlab commands mean?

actually, writeDigitalPin(a,'D7',1) in the Matlab is same as digitalWrite(7, HIGH) in the Arduino program and I write this code because of the monster moto shield attached to the arduino board and digital pins 7 and 8 are INA and INB of dc motor

koronus:
actually, writeDigitalPin(a,'D7',1) in the Matlab is same as digitalWrite(7, HIGH) in the Arduino program and I write this code because of the monster moto shield attached to the arduino board and digital pins 7 and 8 are INA and INB of dc motor

I thought that would be the case.

Do you just connect a brand new arduino up to your motor motor shield and it will work straight away? ( I don't see how that could happen).

Or do you have to have to load some kind of sketch onto the Arduino to enable it to operate in conjunction with Matlab?

Have you been able to control other items such as the LED connected to pin 13 of the Arduino?

JohnLincoln:
I thought that would be the case.

Do you just connect a brand new arduino up to your motor motor shield and it will work straight away? ( I don't see how that could happen).

Or do you have to have to load some kind of sketch onto the Arduino to enable it to operate in conjunction with Matlab?

Have you been able to control other items such as the LED connected to pin 13 of the Arduino?

I add the plugin of Arduino to Matlab and I test the other item and I could control the brightness of LED but for the monster moto shield, it does not work!

is there any way to use monster moto shield and Matlab?

Don't you have to send an enable and / or speed signal?

outsider:
Don't you have to send an enable and / or speed signal?

No, I didn't, I just use that code, I know about the speed signal (PWM) but I have no idea about enable one?

Hi,

Can you post the code you have loaded into the UNO?

Thanks... Tom... :slight_smile:

TomGeorge:
Hi,

Can you post the code you have loaded into the UNO?

Thanks... Tom... :slight_smile:

I wrote it at the first post
here you are:

a=arduino('com9','uno');
writeDigitalPin(a,'D7',1);
writeDigitalPin(a,'D8',0);

Hi,

Have you followed something like this?

Sorry I have no Matlab experience.

This is the suggested code structure, your code looks like it is missing some statements.

% create an arduino object

a = arduino('com3', 'uno');     

% start the loop to blink led for 10 seconds

for i = 1:10

    writeDigitalPin(a, 'D11', 1);

    pause(0.5);

    writeDigitalPin(a, 'D11', 0);

    pause(0.5);

end

% end communication with arduino

clear a

When you run it in Matlab, Matlab will load this code to the UNO.

Tom... :slight_smile:

TomGeorge:
Hi,

Have you followed something like this?

https://www.allaboutcircuits.com/projects/arduino-interface-with-matlab/

Sorry I have no Matlab experience.

This is the suggested code structure, your code looks like it is missing some statements.

% create an arduino object

a = arduino('com3', 'uno');

% start the loop to blink led for 10 seconds

for i = 1:10

writeDigitalPin(a, 'D11', 1);

pause(0.5);

writeDigitalPin(a, 'D11', 0);

pause(0.5);

end

% end communication with arduino

clear a




When you run it in Matlab, Matlab will load this code to the UNO.

Tom... :)

thanks for your answer but, this code is for looping and it does the blinking 10 times and if you want to do it just for one time (for example turn the led on ) you can use these 2 lines code:

a=arduino('com9','uno');
writeDigitalPin(a,'D11',1);

Hi,
What about the end statement, where is yours?

The MatLab IDE might be looking for end so that it knows to run the UNO.

Tom.. :slight_smile:

TomGeorge:
Hi,
What about the end statement, where is yours?

The MatLab IDE might be looking for end so that it knows to run the UNO.

Tom.. :slight_smile:

hi
the end command is just for ending the (FOR loop) command

thanks to all of you(JohnLincoln,outsider,TomGeorge),outsider you were right it needs the speed signal and the correct code is:

a=arduino('com9','uno');
writePWMVoltage(a,'D5',3);
writeDigitalPin(a,'D7',1);
writeDigitalPin(a,'D8',0);