Avatar for Rollo

Rollo

Member since Dec 2014 • Last active Mar 2017
  • 3 conversations
  • 15 comments

Most recent activity

  • in General
    Avatar for Rollo

    As for the extra features - just by looking at these pictures - Iskra definitely looks more appealing and user friendly because of clear pin labels. I really hate looking up the Espruino reference just to double check where PWM or ADC is, and for that reason alone I would often choose Arduino for simple toy projects.

    The good thing is you can get improvements/ideas like that back to Espruino when the time comes for your next kickstarter campaign - which I will happily support :)

    • 6 comments
    • 528 views
  • in General
    Avatar for Rollo

    @allObjects thanks to your suggestions I have played with different timers and debounce values again and I think I'm getting somewhere.

    @Gordon it's even less reliable this way, it's difficult to describe LED's behavior now so I have changed the code to use console.log and it looks interesting.

    First try:

    var door = new Pin(A8); //pull-up
    
    E.on("init", function () {
      door.mode("input");
    });
    
    function doorOpenedHandler() {
      console.log("door opened");
    }
    
    function doorClosedHandler() {
      console.log("door closed");
    }
    
    setWatch(function () {
      doorOpenedHandler();
    }, door, {repeat: true, edge: "falling", debounce: 500});
    
    setWatch(function () {
      doorClosedHandler();
    }, door, {repeat: true, edge: "rising", debounce: 500});
    
     1v81 Copyright 2015 G.Williams
    >echo(0);
    =undefined
    >save()
    =undefined
    Erasing Flash.....
    Writing.....
    Compressed 81600 bytes to 2942
    Checking...
    Done!
    
    // I'm starting with closed switch
    door closed
    >door.read()
    =true
    
    // I'm opening the switch
    door opened
    >door.read()
    =false
    
    // I'm closing the switch
    door opened
    >door.read()
    =true
    // wait, what? wrong handler got called but the door value is correct
    

    Now let's try with e.state:

    ...
    setWatch(function (e) {
      if (e.state) {doorOpenedHandler();} else {doorClosedHandler();}
    }, door, {repeat: true, edge: "both", debounce: 500});
    
    // I'm starting with closed switch again, looks like the logic has changed
    door opened
    >door.read()
    =true
    
    // I'm opening the switch
    door closed
    >door.read()
    =false
    
    // I'm closing the switch
    door opened
    >door.read()
    =true
    
    // I'm opening the switch
    door closed
    
    // I'm closing the switch
    door closed
    // wrong handler again i.e. after seeing "door closed" the last time I would expect "door opened" now
    

    Any ideas, please? Is my wiring ok?

  • in General
    Avatar for Rollo

    Hello, I'm having problems with Pico and magnetic reed switches.

    The idea is that on board LED indicate state of that switch i.e. green LED on when open, green LED off when closed. It all works well at first but when I quickly toggle the switch for a little while then LED gets "out of sync" with my switch, that is it lights green when closed.

    I'm having this issue both with pull-up and pull-down connections, tried with a different switch and debounce values. I must be missing something - but what? :)

    Example code:
    ```
    var door = new Pin(A8);
    var ledOpen = LED2;
    var ledHold = LED1;

    E.on("init", function () {
    door.mode("input");
    });

    function doorOpenedHandler() {
    ledOpen.set();
    }

    function doorHeldHandler() {
    ledHold.set();
    }

    function doorClosedHandler() {
    ledOpen.reset();
    ledHold.reset();
    }

    setWatch(function () {
    doorOpenedHandler();
    }, door, {repeat: true, edge: "falling", debounce: 0});

    setWatch(function () {
    doorHeldHandler();
    }, door, {repeat: true, edge: "falling", debounce: 2000});

    setWatch(function () {
    doorClosedHandler();
    }, door, {repeat: true, edge: "rising", debounce: 0});
    ```

  • in News
    Avatar for Rollo

    Nice one, thanks. Is it possible to use Pin.getInfo (or something else) to find out if given pin is PWM -able?

  • in General
    Avatar for Rollo

    Personally I would be happy to get my code cleaner and fix these nasty mistakes.

    I guess after update it would fail badly so it would be easy to fix, otherwise one can spend hours chasing bugs in the wrong place (because they will bite you eventually).

  • in JavaScript
    Avatar for Rollo

    @DrAzzy I will try to get hold of a multimeter tomorrow and answer your question. For now I can only say that it's a one channel Arduino relay module connected with Espruino Board with shared GND, IN to C9 and VCC to VBat. I should also clarify that it fails when no explicit pin mode specified by me, but works when I set pin mode to "output" beforehand.

    And don't get me wrong guys, I'm not claiming that there is no good explanation for this behaviour. All I'm saying is that it has nothing to do with beginners friendliness :)

  • in JavaScript
    Avatar for Rollo

    Ehh say what you want but for me (that is a beginner with no understanding of Figure 16) this whole thing is getting hairy.

    After reading example codes I assumed that pin.write(!pin.read()) simply toggles given pin right? Well no, it turns out it's not that simple. It works like a toggle for an LED, but it doesn't work for a relay module.

    Yes you said charging capacitors and square waves, but I say toggling is more likely a beginner's thing.

  • in JavaScript
    Avatar for Rollo

    Set the pin mode properly in the first place and use pin.read()

    I suppose it all comes down to documentation so I'll make a PR and we're good ;)

  • in JavaScript
    Avatar for Rollo

    You are right. I will have to delegate it to some utility classes. This project is mostly in my head at this time so you probably saved me some trouble later on.

    I also realized that using pinMode is a good idea, wasn't even aware of it.

    Am I right thinking that onInit is a good place for pin mode configuration?

Actions