3 Replies Latest reply on Aug 18, 2015 1:25 AM by EricHubert

    Adafruit motor shield speed control


           I have two adafruit motorshields product 1438 and am experiencing the same problem with both.  In all of my code, the example or things I write myself, I am unable to change the speed of a DC motor.  It appears to run at full speed no matter what.  I will even set the speed to 1 or 0 and it will still run full out.  Here is the example code with a change in speed marked with a comment.  I am running it on an Intel Edison with the latest flash as of the date of this post.  Am I missing something?


       myMotorShield_obj = null;
       if (MotorShield_lib)
        MotorShield_lib = null;
      var MotorShield_lib = require('jsupm_adafruitms1438');
      /* Import header values */
      var I2CBus = MotorShield_lib.ADAFRUITMS1438_I2C_BUS;
      var I2CAddr = MotorShield_lib.ADAFRUITMS1438_DEFAULT_I2C_ADDR;
      var M3motor = MotorShield_lib.AdafruitMS1438.MOTOR_M3;
      var MotorDirCW = MotorShield_lib.AdafruitMS1438.DIR_CW;
      var MotorDirCCW = MotorShield_lib.AdafruitMS1438.DIR_CCW;
      // Instantiate an Adafruit MS 1438 on I2C bus 0
      var myMotorShield_obj = new MotorShield_lib.AdafruitMS1438(I2CBus, I2CAddr);
      // Setup for use with a DC motor connected to the M3 port
      // set a PWM period of 50Hz
      // disable first, to be safe
      // set speed at 50%
      myMotorShield_obj.setMotorSpeed(M3motor, 50);
      myMotorShield_obj.setMotorDirection(M3motor, MotorDirCW);
      process.stdout.write("Spin M3 at half speed for 3 seconds, ");
      console.log("then reverse for 3 seconds.");
       console.log("Reversing M3");
       myMotorShield_obj.setMotorSpeed(M3motor, 10); // <******************************* Does not change speed
       myMotorShield_obj.setMotorDirection(M3motor, MotorDirCCW);
      }, 3000);
       console.log("Stopping M3");
      }, 6000);
      process.on('SIGINT', function()
        • 1. Re: Adafruit motor shield speed control

          Hello EricHubert,


          I can see that you are trying the UPM example: adafruitms1438.js. The example spins the motor 3 seconds in one direction and then it reverses another 3 seconds. I read through your code and I noticed that you only changed the speed of the reversing part. Do you think that you could have missed this?

          Anyway, if you encounter any other issue you may have a more accurate answer by contacting the example's creator. His email can be found on the link above.



          • 2. Re: Adafruit motor shield speed control

            I have not overlooked this.  The change was intentional.  The example's creator is unsure as to the cause of the problem.  What should be done now?

            • 3. Re: Adafruit motor shield speed control

              The source of the problem has been found.  The library used to control the pwm had an issue.  This is from the patch documentation:

              There was a bug in the setMotorSpeed() method that did not clear the

              'FullOn' bit in the register used for PWM, causing full power to be

              applied all the time no matter the PWM duty cycle setting.

              I was informed the patch will be in the next release of UPM.  I don't know for certain what the current version of UPM is but I am going to guess it is version 0.3.2.