Matlab and Arduino Mega 2560

Hi all

I am using MatLab to control a Arduino Mega 2560. I am using the analogwrite() function to write a PWM duty cycle value to the output pins. I would like to use 7 outputs but when I try to use a pin e.g. 4 I receive the following error message:

Unallowed value for pwm pin number, the value must be one of the following: [3 5 6 9 10 11]

Unfortunately there are only 6 available pins here! I attempted to modify the arduino.m file as well as the adiosrv.pde file in the following way (advised in the readme.txt file for working with an Arduino Mega board and MatLab):

  1. In the file ‘arduino.m’, replace every occurrence of
    errstr=arduino.checknum(pin,‘pin number’,2:19);
    with:
    errstr=arduino.checknum(pin,‘pin number’,2:69);
    replace every occurrence of:
    errstr=arduino.checknum(pin,‘analog input pin number’,0:5);
    with:
    errstr=arduino.checknum(pin,‘analog input pin number’,0:15);
    then replace every occurrence of:
    for i=2:19,
    with
    for i=2:69,
    and finally replace :
    a.pins=-1ones(1,19);
    with:
    a.pins=-1
    ones(1,69);

  2. In the file ‘srv.pde’, change every occurrence of
    if (val>98 && val <117) {
    with the following:
    if (val>98 && val <167) {
    (basically replace 117 with 167)
    and also change the line
    if (val>96 && val <103) {
    with the line
    if (val>96 && val <113) {
    (basically replace 103 with 113).

However, I still received the same error message.

I would be very grateful for some help with this issue!

Nothing in part one changes which pins can be PWM'd, and part two could be anything, as there is no context to it.

Apologies for the lack of context.

I was using the MATLAB support package (aka ArduinoIO Pakage) from http://www.mathworks.com/matlabcentral/fileexchange/32374.

The blue text is from the readme.txt file that I was following.

I resolved the issue. I changed the line (line 565 in the arduino.m file) from

errstr=arduino.checknum(pin,'pwm pin number',[3 5 6 9 10 11]);

to

errstr=arduino.checknum(pin,'pwm pin number',[3 4 5 6 7 8 9 10 11]);

which allows for the analogWrite function to be carried out on pins 3-11 instead of just the six pins listed originally.

You were right in that it doesn't change which pins can be PWM'd, but it does allow the MatLab script to be carried out without interruptions or errors.

Hope this helps anyone else if they are using the same package.