Controlling an mg996r using digitalPulse

Posted on
  • Im about 80% sure it's a hardware issue, which is why I posted this here. I have flashed Espruino to a doit devkitV1, using some silicon shrunk jumper wires, I have created a simple testing apparatus connecting a 4.8 V 8000 Mili Amp power supply into the servo, the grounds work and power does successfully reach the servo. The real issue appears to be the interpretation of the digitalPulse signals from the esp32 kit, I just DO not know why, but every time digital pulse fires the servo seems to seemingly at random decide to move. If I fire off 50 pulses from 1 iterating to 2, and 2 iterating back down to 1. The servo sporadically whirs and moves slightly right and left seemingly at random. Any ideas?

  • Try the servo module.

  • using the base module. s.move 0, moves sporadically, s.move(1), moves more violently sporadically, s.move(0.5), moves in between the previous two in terms of sporadic movement. Notably only seems to be moving in one direction, that being to the right from the pinout.

  • Also, correct me if I'm wrong but the servo module is just a digitalPulse function dressed up with a few checks right?

  • @user156239 Hello,
    Im 90% sure the issue is in the implementation of the digitalPulse function for the ESP32.

    Im having very similiar issues with trying to drive a servo(LDX218) with ESP32 and Espruino. Im using the Espruino servo tutorial here . Having tried the servo module and using the digitalPulse command directly on its own and in setInterval().

    Im 90% sure the issue is in the implementation of the digitalPulse function for the ESP32. I have put a logic analyser on the pulsed pin and it seems the pulse width is always about 600us in response to a digitalPulse(D4,1,x) command no matter what the value of x. Where x should be the length of the pulse in milli seconds. I should really compare to the output of digitalpulse on an espruino Pico to be 100%.

    Ive also put the anayser on a servo test board, so can compare to a pulse signal that works.

    @JumJum explains, at the time of implementation, in the docs here, that the function was not 100% tested. So maybe never worked or something has changed.

    Any way it needs further investigation. The digitalPulse function code is here. And the ESP32 RTM functionality the code uses is described here . This RTM doc may be better explainations with examples than was available at the original implementation so maybe comparing to examples would find the issue. (also theres a risk examples may not be applicable in our older ESp32 sdk version. )

    Any help appreciated, I was trying to sort out what I thought was a relatively easy WIFI servo driver for a PTZ streaming camera for a charity .

  • Further to above, after a few builds of Espruino ( with make clean && BOARD=ESP32 make) having added some console prints to /targets/esp32/jshardwarePulse.c I am pretty sure that this code is not executed on a digitalPulse function call.

    With similiar tests it does look like the function is built in src/jswrap_io.c and the function jswrap_io_digitalPulse() is used to execute the call..

    Looking though this code I can not see any special treatment for the ESP32.

    My C skills are at the 'cut and paste level', so It will take me allot more time to try to figure out the issue (pulse period not varying) in that code and the risk is this method hasnever beentestd and just does not work on the ESP32.

    Im going to raise an issue just in case, but I dont think I can take this much further.

    Please bring on a supported Espruino WIFI option (with lower overhead than a an Espruino Pico with ESP83266 he says with tears in his eyes. :)

  • I've encountered the same riddle, but it seems my superpower of solving it is still in the mail.

  • I solved this problem because I was using a 360° servo, and its principle is different from that of a 180° servo. Therefore, the library is different. For a 360° servo, it should be written like this.

    function servo_360 (pin, speed) {
      if ( 0.5 <= speed <= 2.5) {
          console.log(speed);
          analogWrite(pin, speed / 50.0, {freq:20});
      } else {
          analogWrite(pin, 0, {freq:20}); // stop
      }
    }
    
  • Post a reply
    • Bold
    • Italics
    • Link
    • Image
    • List
    • Quote
    • code
    • Preview
About

Controlling an mg996r using digitalPulse

Posted by Avatar for user156239 @user156239

Actions