Clear Filters
Clear Filters

Arduino Engineering Kit encoders return incorrect readings

17 views (last 30 days)
I'm working through the Arduino Engineering Kit material, using MATLAB/Simulink R2018b on Windows 7.
The examples in Chapters 2.1 (Arduino Getting Started) and 2.2 (MATLAB Getting Started) worked OK, and so did everything in Chapter 2.3 (Simulink Getting Started) as far as the open-loop control example - but when I tried the closed-loop control example the motor went haywire, running erratically forwards and backwards at maximum speed. Looking at the outputs from the encoder block on the scope, the position, and speed if I add that as a second output, are both varying apparently at random in the range +/- 2e+9, even if the motor is stationary:
simulink encoder issue 2018-11-28_09h19_04.png
Now when I go back to the MATLAB examples that worked previously, the encoder object returns a constant value of 12 for readCount and 65 for readSpeed no matter what the position of the actual motor is.
I haven't changed the connections between the Arduino and motor/encoder since the point when it was working, I've checked with a voltmeter that the encoder outputs are changing between 0 V and 3.3 V as I rotate the motor, as expected, so I don't think it's the hardware, and I've tried uninstalling all Arduino-related add-ons and reinstalling them in the order specified in the Engineering Kit instructions, but no success.
I have the latest versions of everything, as far as I know: MATLAB/Simulink 2018b, MATLAB Support Package for Arduino Hardware 18.2.0, Simulink Support Package for Arduino Hardware 18.2.0, Arduino Engineering Kit Hardware Support 18b 1.1.1, Arduino IDE 1.8.7, Arduino SAMD Boards 1.6.19, and MKRMotorCarrier library 1.0.1 as specified in the ArduinoKitHardwareSupportReadMe.txt file, although I see the latest version available of that library is 1.0.3.
What can I try next? My best guess is that something in the configuration or firmware of the MKR motor carrier has been incorrectly changed by the Simulink support package, but how do I fix that? Should I try reflashing the motor carrier firmware as described here? Any ideas?

Accepted Answer

Madhu Govindarajan
Madhu Govindarajan on 28 Nov 2018
So when you are going through steps shown in the online material, what happens if you try to do open loop control again and measure the speed of the encoder? Is it anywhere close to the figures shown in the material. Feel free to email me from here and I can help you check what is wrong.
Tom Hawkins
Tom Hawkins on 12 Dec 2018
The response from Arduino technical support suggested reflashing the firmware on the motor carrier board using the Flasher example (Arduino IDE > Files > Examples > Mkrmotor Carrier> Flasher).
The first time I tried this it worked once then the same behaviour came back again. After repeating the procedure it so far seems to have fixed the problem. I'll let you know whether this fix turns out to be permanent.

Sign in to comment.

More Answers (0)


Find more on Arduino Hardware in Help Center and File Exchange




Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!