Smartibot

Posted on
  • Hi, not sure if this is the right place to post about this board. I have got one and think it's great and am looking forward to exploring it more.

    I'm trying to figure out how to access the capacitive touch sensors but can't figure it out. I have looked at the boards/smartibot.py file and can't see anything mentioning about capacitive sensors like in the puck.js file. I am keen to explore the board and somehow figure this sort of stuff out but can't really get my head around it!

    Any guidance would be appreciated.

  • Hi,

    Yes, it's the right place! There's no dedicated capacitive sense hardware on the board itself.

    Basically:

    • Sense pad 1 is directly connected to D5
    • Sense pad 2 is directly connected to D31
    • They're both connected to D25 via 100k resistors

    This is the same way that Puck.js does it too. Puck.js uses a software polling approach which hasn't (yet) been added to Smartibot, so for now if you actually want capacitive touch you're on your own (JS execution speed likely isn't fast enough to do anything usefully).

    However you could actually configure the underlying hardware to do this for you using http://www.espruino.com/NRF52LL - set up a timer to send a square wave on D25, and then when D5/D31 change you trigger a 'capture' event.

    If you did something like that it'd be great if you could post it up, as it might be an interesting thing for other boards too.

  • Thanks for the info. I'm messing about using the examples, but I don't really know what I'm doing to be honest. I keep peek32()ign at everything I can think of, but the returned values stay the same. I don't have ~much~ any experience with low level stuff.

    Is the code that does this on the Puck available somewhere for me to look at to try and understand it, or will that not really help?

  • Mon 2019.03.18

    Does this summation provide some insight?

    Under heading at page end: Capacitive Touch Sensor

    https://www.espruino.com/STM32+Periphera­ls

    Would need to be adapted from STM32 to nRF52 pin designations

  • The Puck's capsense code is here: https://github.com/espruino/Espruino/blo­b/master/targets/nrf5x/nrf5x_utils.c#L61­

    But I actually don't use the hardware variant - I use the simple software one below it.

    Just FYI -if you want to see how something is done, look in http://www.espruino.com/Reference and after the title of a function there's a => symbol - click on that and you'll go right to GitHub where it's defined.

    Here's some code you can use. I'll update the NRF52LL page:

    function capSense2(PINDRV, PIN1, PIN2) {
      var ll = require("NRF52LL");
      digitalWrite(PINDRV,0);
      digitalRead([PIN1,PIN2]);
      // create a 'toggle' task for output
      var t0 = ll.gpiote(0, {type:"task",pin:PINDRV,lo2hi:1,hi2lo:1,­initialState:0});
      // two input tasks, one for each cap sense input
      var e1 = ll.gpiote(1, {type:"event",pin:PIN1,lo2hi:1,hi2lo:0})­;
      var e2 = ll.gpiote(2, {type:"event",pin:PIN2,lo2hi:1,hi2lo:0})­;
      // create a timer that counts up to 1000 and back at full speed
      var tmr = ll.timer(3,{cc:[1000],cc0clear:1});
      // use a PPI to trigger toggle events
      ll.ppiEnable(0, tmr.eCompare[0], t0.tOut);
      // use 2 more to 'capture' the current timer value when a pin changes from low to high
      ll.ppiEnable(1, e1.eIn, tmr.tCapture[1]);
      ll.ppiEnable(2, e2.eIn, tmr.tCapture[2]);
      // Manually trigger a task to clear and start the timer
      poke32(tmr.tClear,1);
      poke32(tmr.tStart,1);
      return { read : function() {
        return [ peek32(tmr.cc[1]), peek32(tmr.cc[2]) ];
      } };
    }
    
    var cap = capSense2(D25, D31, D5);
    
    setInterval(function() {
      console.log(cap.read());
    },500);
    
  • Thanks for the info @Robin I'll have a look at that to try and further my understanding.

    Thanks for the code @Gordon and for the tip about finding the underlying code. I find it fun to dig about and try and understand these things, even if it usually comes to nothing! There is a lot of information about the chip here http://infocenter.nordicsemi.com/pdf/nRF­52832_PS_v1.1.pdf which looks pretty exciting, so I'm going to mess about with it using the js interface and see what happens.

  • Post a reply
    • Bold
    • Italics
    • Link
    • Image
    • List
    • Quote
    • code
    • Preview
About

Smartibot

Posted by Avatar for Bennr @Bennr

Actions