Avatar for ColinP


Member since Jan 2016 • Last active Sep 2020
  • 6 conversations

Most recent activity

  • in Projects
    Avatar for ColinP

    Thanks for the capsense info. I saw it before, but couldn't remember where. (You might notice the two 470k resistors connected to the module. That was a previous attempt at sending morse code!)...

  • in Projects
    Avatar for ColinP

    The modifications to the above to get it to work with MPR121 - put the following into onInit()

    sensor = require("MPR121").connect(I2C1, function() {});
    // Function to be called when MPR121 notifies us of change
    setWatch(function(e) {
        var value = sensor.touched() & 0x0f; // Filter out other inputs
        if (value==0) { // All buttons up: Emit the key
    // Buttons map to MP121 inputs 0,1,2,3 -> bits 1,2,4,8
        if (value==1) keydown(0);
        if (value==2) keydown(1);
        if (value==4) keydown(2);
        if (value==8) keydown(3);
    }, IRQ, {edge: 'falling', repeat: true});
  • in Projects
    Avatar for ColinP

    In a stunning example of high quality electronics construction(!) - no amateur construction of sticky tape, Pritt stick and tin foil here - I had a go this afternoon at making a gesture version, so you "write" letters by swiping the patterns above.

    There are four pieces of tin foil glued to a piece of cardboard, an MPR121 breakout board and a MDBT42 module at the top. To ensure a quality construction the tin foil is covered with a thin piece of plastic from an old envelope.

    It works surprisingly well, and I find the gestures are becoming part of muscle memory.

    It would be cool to see if the nRF52 chip could implement four touch sensors directly -without the mpr121-, and then 4 pads could be attached to the cover of a puck. I know there is one cap sense input, but unsure if it can be easily extended to four, and how well they would work compared to the auto-calibration and filtering that the mpr121 chip does.

  • in Tutorials
    Avatar for ColinP


    I had a TTP229 capacitative keypad module lying around and thought it would be useful with Espruino. These can be picked up fairly cheaply online. Just be careful: There are actually two variants of this chip and it isn't always clear which is which!

    The modules I see on ebay seem to have the TTP229-BSF version of the chip - this is what mine is and what this code works with. I think if the module has "SCL" and "SDO" pins on it things should be OK. The other version has an I2C interface and won't work with this code.

    To explain the code: You can treat the chip as though it has an SPI interface, and read out 2 bytes of data from it. These contain the keypresses, but inverted - ie '1' means not set, and '0' means set.

    I hope the code below makes sense and is useful to somebody!

    // Espruino example for TTP229-BSF keypad
    // Connect keypad SCL and SDO lines to these pins:
    SCL = D14;
    SDO = D15;
    // Setup SPI interface but clock needs to be quite slow otherwise we get data errors
    SPI1.setup({miso:SDO, sck:SCL, mode:integer=3,baud:integer=10000});
    // Periodically read the keys and display on the console
    setInterval(function() {
      // Read 2 bytes of data from the device
      // Invert the data so that a '1' means button pressed. This gives us
      // two bytes: 
      // Top = buttons 1-8 : Bits are Button 1,2,3,4,5,6,7,8
      // Bottom = buttons 9-16 : Bits are Button 9,10,11,12,13,14,15,16
      // Now display as binary
  • in Projects
    Avatar for ColinP


    Thanks for the block hint. I've actually got a 12 key version of that somewhere which I could try. The joystick switch also sounds interesting.

    I ordered an MPR121 touch sensor board, which has just arrived. I'm currently glueing pieces of tin foil onto a piece of cardboard as an experiment. I'm firstly going to try a chord keyboard to compare, then will see if I can fashion some touch sensors into a square such that they detect swipe movements.

  • in Projects
    Avatar for ColinP


    Inspired by the "Pixl.js home computer" tutorial (https://www.espruino.com/Pixl.js+Home+Co­mputer) I figured I'd make a tiny laptop.

    I had a Microsoft chatpad keyboard in my box of electronic stuff. These can be obtained quite cheaply now and can be easily used with microcontrollers.

    They output a 4800baud serial signal which can be connected straight to the serial port of a microcontroller.

    The pinout for the one I have is:

    red wire: 3.3v supply
    black wire: data out (I connected to pin A0 but it doesn't really matter)
    orange wire: gnd supply

    (Note that black isn't used for its traditional use of ground- a mistake I nearly made while wiring this up)

    I figured that this could be quite neat when combined with a SIM800 mobile phone module - could build a programmable mobile phone to send and receive SMS, download text data etc etc.

    The code is:

    function onInit() {
      Serial1.setup(4800, {rx:A0, tx:A2});
      Serial1.on('data', function (data) {

    OK. Time to get rid of this Macbook. It's now obsolete, having been replaced by the latest low powered Espurino open source DIY laptop. (I think....)

  • Avatar for ColinP

    Hmm. The posting above went a bit wrong - I guess I'm posting Python code rather than Javascript.

    Here is the garbled bit, not marked as code to hopefully keep the forum happy

    def colin_hotp_token(secret, intervals_no):
    # Key is a 10 byte array
    key = base64.b32decode(secret, True)
    # Python debug : print the key as bytes
    #print "KEY",[ord(x) for x in key]

    #keybytes=[0, 68, 50, 20, 199, 66, 64, 17, 12, 133]
    # msg is 8 bytes long - number with last byte = least significant
    msg = struct.pack(">Q", intervals_no)
    #msgbytes=[0, 0, 0, 0, 0, 0, 0, 1]