Avatar for user94249

user94249

Member since Sep 2018 • Last active Feb 2020
  • 3 conversations
  • 14 comments

Most recent activity

  • in Puck.js, Pixl.js and MDBT42
    Avatar for user94249

    Using Puck.js :)
    Yeah so I've polled every address on the I2C bus - the only thing that responds is the humidity sensor. From this I can assume that there must be something wrong with the wiring to the accelerometer.
    I'm going to look further into the wiring here and let you know. For those interested in checking whether your sensor(s) can be contacted through I2C:

    let i2c = new I2C();
    i2c.setup({sda: D25, scl: D26}); 
    for (i=0; i<128; i++) {
      i2c.writeTo(i, 0x0F);
      console.log("I2C addr is: " + i + ", response: " + i2c.readFrom(i, 1)[0]);
    }
    
    
  • in Puck.js, Pixl.js and MDBT42
    Avatar for user94249

    Thanks for your help,
    1) CS is set to high according to my schematic
    2) Wiring is good as far as I can tell
    3) I2C address is correct as far as I can tell too, although I have tried many different ones and still get the WHO_AM_I check fail

  • in Puck.js, Pixl.js and MDBT42
    Avatar for user94249

    Espruino version: 2v03
    Using LIS2DH12 Module, I2C

    Hi Gordon,

    I'm struggling to read from the LIS2DH12 accelerometer. The error I get when using the hardware I2C is a bit cryptic (only info I found on this was an old forum post), but when I use software I2C I get a more descriptive error: WHO_AM_I check failed. I have confirmed that I've specified the correct pinouts when instantiating I2C... Was hoping you could give me more information on the errors?
    I'm just using the sample code, but here's what I have anyway:

    var i2c = new I2C();
    
    i2c.setup({sda: D25, scl: D26});
    var accel = require("LIS2DH12").connectI2C(i2c, {callback:function(xyz) {
       // callback whenever data is received
       console.log(xyz);
       // prints { "x": 3.90625, "y": -7.8125, "z": 984.375 }
    }});
    accel.setPowerMode(on?"low":"powerdown")­;
    
    

    When using hardware I2C, I get a write error:

    Connected
    --] >
    --]  ____                 _ 
    --] |  __|___ ___ ___ _ _|_|___ ___ 
    --] |  __|_ -| . |  _| | | |   | . |
    --] |____|___|  _|_| |___|_|_|_|___|
    --]          |_| espruino.com
    --]  2v03 (c) 2018 G.Williams
    --] 
    --] >
    --] Uncaught InternalError: I2C Write Error 33281
    --] 
    --]  at line 1 col 18
    --] b.writeTo(c,a|128);return b.readFrom(c,d)
    --]                  ^
    --] in function "r" called from line 1 col 96
    --] ...back;if(this.r(b.WHO_AM_I,1)[0]!=b.I_­AM_MASK)throw"LIS2DH12 ...
    --]                               ^
    --] in function "f" called from line 2 col 118
    --] ...on(a,d){b.writeTo(c,a,d)},a)
    --]                               ^
    --] in function "connectI2C" called from line 10 col 3
    --] }});
    --]   ^
    
    

    When using software I2C, I get a who_am_i error:

    Connected
    --] >
    --]  ____                 _ 
    --] |  __|___ ___ ___ _ _|_|___ ___ 
    --] |  __|_ -| . |  _| | | |   | . |
    --] |____|___|  _|_| |___|_|_|_|___|
    --]          |_| espruino.com
    --]  2v03 (c) 2018 G.Williams
    --] 
    --] >
    --] Uncaught LIS2DH12 WHO_AM_I check failed
    
    

    Thanks!

  • Avatar for user94249

    Hi @Gordon
    I've figured out what the data in the arrays are.

    new Uint8Array([162, 4, 3, 10, 209, 1]).buffer
    162: NFC command for "write"
    4: Index for where to put data within tag array
    3: Type length
    10: Record length
    209: NDEF record header
    1: Type Name Field
    
    new Uint8Array([162, 5, 6, 84, 2, 101]).buffer   
    6: Payload Length
    84: Well known record
    2: Well known record type (in this case - the encoding for this text (UTF))
    101: e 
    
    new Uint8Array([162, 6, 110, 112, 111, 111]).buffer
    110: n - ("en" is locale)
    112: p
    111: o
    111: o
    
    new Uint8Array([162, 7, 254, 0, 0, 48]).buffer 
    254: Marks the end of the payload
    

    Further information on this can be found here.
    I am now able to send custom commands/string through NFC to Puck.js.

  • Avatar for user94249

    Hi Gordon - Only just got around to looking at this one again - it seems to be working now (for whatever reason...)

    I have a much better understanding of how this all works too - I'm working on a way today read the data transmitted via NFC and action upon it based on whether it matches an expected format.
    I've got reading and writing working fine - but I'm tripping over the format of the data that's actually being sent. I'll spill my thoughts here, in case anyone else stumbles across this.
    When a 'write' command is sent to the chip, (if it complies to NTAG213/215/216) it'll be formatted like so:
    [[command code] [address of data to be changed] [data] [crc]]
    Pretty basic so far. But the NFC writer app that I'm using to test actually writes some prefix and suffix data, which makes it hard to find the data that I have specified to be written, as it is surrounded by metadata. Here is an example of a write sent to the chip (actually ends up being 4 write commands):

    new Uint8Array([162, 4, 3, 10, 209, 1]).buffer
    new Uint8Array([162, 5, 6, 84, 2, 101]).buffer
    new Uint8Array([162, 6, 110, 112, 111, 111]).buffer // <-- my data, following the 110, in ASCII
    new Uint8Array([162, 7, 254, 0, 0, 48]).buffer
    

    So the question I'm looking into is, what is the prefix/suffix data? And even if I wish to ignore this, there is no callback function on the tag to detect that it has finished being written to, so it's hard to locate my data afterwards - or even know when afterwards is.
    I'll keep the thread posted, for archive sake!

  • in Puck.js, Pixl.js and MDBT42
    Avatar for user94249

    I'm using Puck.js (Espruino v2.01) and I want to be able to manipulate variables based on data that is written to the NFC tag using NFCrx.
    If I use the 'NFCon' event, and console log based on that, everything works when I scan NFC:

    >NRF.on('NFCon', () => { console.log("test"); });
    =undefined
    test
    test
    test
    

    But when I use the NFCrx event instead, after NFCStart of course, the event callback is not called (almost as if the event is not registered):

    >NRF.nfcStart();
    =new Uint8Array([95, 193, 71, 81, 42, 138, 1, 165, 4, 3]).buffer
    >NRF.on('NFCrx', (rx) => { console.log(rx); });
    =undefined
    >NRF.on('NFCrx', (rx) => { NRF.nfcSend("test"); });
    =undefined
    >NRF.on('NFCrx', (rx) => { console.log("test"); });
    =undefined
    

    What am I missing?
    Thanks in advance

  • in General
    Avatar for user94249

    Ah of course! I know the code, but for some reason it completely slipped my mind that disabling the UART service would have that effect (duh).
    Cheers Gordon.

Actions