Avatar for Andreas_Rozek

Andreas_Rozek

Member since Dec 2019 • Last active Nov 2021
  • 41 conversations
  • 181 comments

Physicist, Senior Developer and IT Consultant, University Lecturer, Freelancer and Startup Founder

Most recent activity

  • in Pico / Wifi / Original Espruino
    Avatar for Andreas_Rozek

    Well, the primary problem was that I passed my callback as the second argument - where you expect a time. And because of a proper check I did not immediately find the mistake.

    move worked as intended - the endless loop was a side-effect of the wrong time argument.

  • in Projects
    Avatar for Andreas_Rozek

    This is probably the strangest "project" I ever made...

    Since none of the five 360° servos in a set bought on eBay worked, and the dealer's "assistance" was limited to repeatedly telling me the required pulse widths, I built a setup using an "Original Espruino" as servo controller and recorded a "proof video" to show:

    • voltage, current and pulse widths are correct (this shows a competitor's product)
    • in fact, not a single one of the servos supplied worked!

    The video is available on Vimeo

    Thanks to Espruino, experimenting with the servos and testing them was just trivial - and all the rest took less than an hour to build, record and upload!

    FYI: the code I had to write for the proof video was just

    analogWrite(C7, 0.10, {freq:100});
    
  • in News
    Avatar for Andreas_Rozek

    Hello Gordon,

    thank you very much for your response - and don't worry about the delay (as a backer I'm following your activities and problems myself and know how busy your days are).

    But it's good to know how simple it may be to use and refer to Espruino-specific diagrams and images!

    Thank you and good success with Bangle 2!

  • in Pico / Wifi / Original Espruino
    Avatar for Andreas_Rozek

    I changed your code a bit, and now everything works as foreseen. Here is my complete test

    //var Servo = require('servo').connect(C7, { range:2 });
    
    
    function Servo_connect (pin,options) {
      var interval, currentPos;
      var offs = 1, mul = 1;
      if (options && options.range) {
        mul = options.range;
        offs = 1.5-(mul/2);
      }
    
      return {move:function(pos, time, callback) {
        if (typeof time === 'function') {
          callback = time; time = undefined;
        }
        if (typeof time !== 'number') time = 1000;
        
        var amt = 0;
        if (currentPos===undefined) currentPos = pos;
        if (interval)
          clearInterval(interval);
        var initial = currentPos;
        interval = setInterval(function() {
          currentPos = pos*amt + initial*(1-amt);
          digitalPulse(pin, 1, offs+E.clip(currentPos,0,1)*mul);
    
          if (amt >= 1) {
            clearInterval(interval);
            interval = undefined;
            if (callback) callback();
            return;
          } else {
            amt += 1000.0 / (20*time);
          }
        }, 20);
      }};
    }
    
    
    let Servo = Servo_connect(C7, { range:2 });
    
    let Count = 0;
    function move () {
      if (Count < 10) {
        Count++;
    print('Count: ' + Count);
        Servo.move(1, 1000, move);
      }
    }
    move();
    

    Since you clearInterval, an explicit return is not necessary, but it may be a good idea to restrict time to values > 0 in order to avoid a division by zero (or negative values)

  • in Pico / Wifi / Original Espruino
    Avatar for Andreas_Rozek

    I just looked into the code you referenced - and I found a potential problem:

            if (callback) callback();
    

    Shouldn't you always return callback()?

    Amendment: I found the mistake - if a callback is given, time must be specified as well, otherwise the callback function is taken as the time argument.

    If you like, you may change the beginning of your move function like so:

      return {move:function(pos, time, callback) {
        if (typeof time === 'function') {
          callback = time; time = undefined;
        }
        if (typeof time !== 'number') time = 1000;
    

    At least, you should protect the time argument better (an error message would be fine, but you may not have enough resources on the device for such an approach)

  • in Pico / Wifi / Original Espruino
    Avatar for Andreas_Rozek

    indeed, that's all my code - I just wanted to "quickly" test a servo (but nothing works quickly if I am touching it - I tend to break everything)

    Amendment: I also just checked the firmware state (just to be sure): and, yes, it is 2v10

    Amendment 2: just to be sure, I flashed 2v10 one more time and tried my code again - with the same result.

  • in Pico / Wifi / Original Espruino
    Avatar for Andreas_Rozek

    I just tried to drive an SG90 Micro Servo with 360° gear from an Original Espruino, wired to pin C7 (as the example suggests) - { range:2 } was the outcome of another test with an "ordinary" SG90.

    var Servo = require('servo').connect(C7, { range:2 });
    
    let Count = 0;
    
    function move () {
      if (Count < 10) {
        Count++;
        Servo.move(1, move);
      }
    }
    move();
    

    However, when uploading this code from the Web IDE it leads to an endless loop of error messages (and finally crashes the Chrome browser):

    Uncaught Error: Pulse Time given for digitalPulse is less than 0, or not a number
     at line 1 col 87
    ...Pulse(l,1,g+E.clip(b,0,1)*e);c+=1E3/(­20*f)
                                   ^
    in function called from system
    ...
    

    Does this code try to recursively call Servo.move rather than my function move? But why does it then lead to an endless loop?

    Amendment: renaming my function move to moveServo still loops endlessly

Actions