-
-
Espruino version: 2v03
Using LIS2DH12 Module, I2CHi 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!
-
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. -
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! -
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 -
-
We actually have a bunch of Espruino Bluetooth devices here - which is why it's a bit confusing. The IDE actually worked for someone else with a Mac yesterday, but I can't for the life of me get it working - after trying on two separate Ubuntu machines and a Mac. See the attached image for our Espruino Bluetooth devices (prefixed with SB) showing up on the Web Bluetooth Example (gonna call it WBE so I don't have to keep typing that out)
-
Hi Gordon,
When I click the connect icon, it says "select a port", with the (only) option being "web bluetooth". When clicked, it then opens the modal saying "no compatible devices found" (see attached image).
But when I use the testing page mentioned before, the same prompt shows many devices. I can provide a screenshot of that too if you need.Thanks for the quick response!
-
Hi,
I'm using the Espruino Web IDE on Google Chrome Version 69.0.3497.100 (Official Build) (64-bit) with Ubuntu 18.04.1.
I have tried enabling web Experimental Web Platform features, running bluetoothd in experimental mode, and I still get the same error:Handling URL "https://www.espruino.com/ide/" Couldn't connect to wss://localhost:31234 - disabling websockets for this session ERROR: getURL("/serial/ports") error : Not Found /serial/ports doesn't exist - disabling WebSocket support ERROR: serial_frame: getPorts timeout, disabling >>> Connecting... Set Slow Write = true
EDIT - From the browser console:
index.js:81181 WebSocket connection to 'wss://localhost:31234/' failed: Error in connection establishment: net::ERR_CONNECTION_REFUSED ensureConnection @ index.js:81181 index.js:78249 Couldn't connect to wss://localhost:31234 - disabling websockets for this session /serial/ports:1 Failed to load resource: the server responded with a status of 404 (Not Found) index.js:78259 getURL("/serial/ports") error : Not Found console.error @ index.js:78259 index.js:78249 /serial/ports doesn't exist - disabling WebSocket support index.js:78259 serial_frame: getPorts timeout, disabling
This isn't an issue with the browser's connection to the bluetooth adapter, as I can successfully find devices using the web-bluetooth testing page, so I know it's specifically a problem with the web IDE.
I tried this on my Mac too, and the same problem occurred. Is the service down at the moment or ?
I can provide screenshots upon request.
Thanks in advance
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: