Comments 7

  • Arduino IoT Robotic Arm almost 5 years ago

    In Malab, put "pause(2)" immediately after the line "[arduino, serialFlag] = setupSerial(comPort);"

    In Arduino sketch, comment out the line "#define BLYNK_PRINT Serial". So Blynk does not write to Serial port. Otherwise, it messes up our transmission.

  • Arduino IoT Robotic Arm almost 5 years ago

    I think I have the solution for you.

    STEP 1. Run only the fist 2 commands from MainScript, which are (use your own COM port):

    comPort = 'COM5';
    [arduino, serialFlag] = setupSerial(comPort);

    and then type in Matlab command window:

    '>> arduino

    Then, you should get something like this:

    Serial Port Object : Serial-COM5

    Communication Settings
    Port: COM5
    BaudRate: 9600
    Terminator: 'LF'

    Communication State
    Status: open
    RecordStatus: off

    Read/Write State

    TransferStatus: idle
    BytesAvailable: 0
    ValuesReceived: 0
    ValuesSent: 0

    STEP 2. Run in your Matlab command window,

    '>> readValue(arduino,'R')

    Call the command above several times until you get numbers. Because first 2 times I got
    '>> readValue(arduino,'R')
    Warning: Unsuccessful read: Matching failure in format..

    ans =





    And then after few calls I got the correct answer:

    '>> readValue(arduino,'R')

    ans =

         100        90        70        50           120

    1. If you have the same first times you call 'readValue', maybe you can add a delay of 2 seconds or more in Matlab after the call of 'setupSerial(comPort)' by using 'pause(2)'.
    The delay is necessary to let the connection settle. Because, also Blynk writes on Serial and if you read too fast, then you read their messages, as I got above :)

    1. Maybe even a better idea is to disable Blynk messages by commenting first line in your sketch, which is:

    #define BLYNK_PRINT Serial // Comment this out to disable prints and save space

    Then it should work.

  • Arduino IoT Robotic Arm almost 5 years ago

    Can you share your 'MainScript.m' and 'readValue.m'? I will have a look, maybe I can help.
    Because it seems that your Arduino outputs the 5 values correctly.

  • Arduino IoT Robotic Arm almost 5 years ago

    Nice! Good to hear it works.

  • Arduino IoT Robotic Arm almost 5 years ago

    Ok. So you actually print 5 values on the Serial (as the original code).

    Can you check in the Serial Monitor (press Ctrl+Shift+M) if the sketch actually prints the values?
    - if not, there is something with the sketch. Maybe it gets stuck somewhere, even if the code is compiled to the board.
    - if yes, so in case you see those 5 numbers, then there must be something in Matlab than cannot read the numbers. First thing to check is the COM port.

  • Arduino IoT Robotic Arm almost 5 years ago

    Hi, sorry for my late reply.

    I can help you. The error you get is because the variable "val" is 3 dimensional while the code expects 5 dimensional.

    To solve it you can do the following:

    1. Check the number of variables you are sending on the Serial COM in your sketch (I guess you are only sending 3 values). In my sketch, I am sending 5 values (see below)

    if (Serial.available() > 0)
    int val =; // read the incoming byte
    if (val == 'R')
    // Write to serial
    Serial.print(y1); Serial.print(" ");
    Serial.print(y2); Serial.print(" ");
    Serial.print(y3); Serial.print(" ");
    Serial.print(y4); Serial.print(" ");

    1. Modify the Matlab file "readValue.m" accordingly. If you have 3 variables sent on the Serial, then you should have (change line 6 in "readValue.m")

    output = fscanf(s,'%f %f %f');

    1. Adapt the MainScript.m to use those 3 variables and plot them.

    I hope this helps. If you have issues let me know.

  • Arduino IoT Robotic Arm about 5 years ago

    Hi Marcus,
    Nice to hear from you. Because I used high torque servos, the robot can easily lift up to 100g with the base fixed well. Above that value it starts to struggle too much.

    I agree with you that with a 3d printer a better design can be made, however I do not have one, so I used wood for now.
    The Arduino 101 can be used for servo control with no problem. If you want to do more advanced things like inverse kinematics, machine learning, etc. you need an additional board or computer. At the moment, I am just using my laptop that runs Matlab. So all the heavy stuff runs on Matlab. In the future, I am considering to interface the Arduino with a Rasberry Pi 3.

    Good luck with your project and looking forward to see the outcome ;)

Add projectSign up / Login