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.
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:
Then, you should get something like this:
Serial Port Object : Serial-COM5
STEP 2. Run in your Matlab command window,
Call the command above several times until you get numbers. Because first 2 times I got
Warning: Unsuccessful read: Matching failure in format..
And then after few calls I got the correct answer:
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 :)
#define BLYNK_PRINT Serial // Comment this out to disable prints and save space
Then it should work.
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.
Nice! Good to hear it works.
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.
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:
if (Serial.available() > 0)
int val = Serial.read(); // 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(" ");
output = fscanf(s,'%f %f %f');
I hope this helps. If you have issues let me know.
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 ;)
Or connect with your social account:
New here? Create an account