Accelerometer (LIS3DH) reading in console

I was trying to display my I2C acelerometer (x) value on the console using Meowbit.
It works fine in the simulator (https://arcade.makecode.com/beta#editor) but the code
won’t compile so I cannot download the uf2 file.

arcade-test_accel

What am I missing here?

In beta beta I get a Compilated failed, please check your code for errors for Meowbit target. Is that what you get?

The first one took a long time, maybe a minute to appear. It then becomes near-instant if I hit Download again. built/output.txt isn’t helpful, it says, Everything sems fine!. I switched board to the PyGamer target. It took a long time again but did work, downloaded ok to the device and tests fine.

For me it appears not to like the Meowbit.

Here’s what I found:
It did not compile with Makecode Arcade BETA but it worked just fine with Makecode Arcade.

Hm, thanks for pointing this out, filed here: https://github.com/microsoft/pxt-arcade/issues/1406

Referencing a similar post below:
https://forum.makecode.com/t/re-d51-sound-mixer/735

But my LIS3DH has a default address at 0x18.

Does that mean I have to set the config to this value when compiling the bootloader?

1, 0x36, // PIN_ACCELEROMETER_INT = PB22
2, 0xd, // PIN_ACCELEROMETER_SCL = PA13
3, 0xc, // PIN_ACCELEROMETER_SDA = PA12
70, 0x18, // ACCELEROMETER_TYPE = LIS3DH

How do I set/change the LIS3DH address on the patcher?

There is a bit of confusion around i2c addresses being 7 or 8 bit. 0x18<<1==0x30 so I suspect you need 0x30. 0x18 will not work.

1 Like

Thank you @mmoskal.
I used LIS3DH_ALT on the patcher and it worked like a charm. :hugs:

Hi there,

I am trying to make a LIS3DH work as well, but with a Trinket M0.
The LIS3DH is connected to the SDA and SCL pins of the Trinket, but I get the reading 0 for all the axis.
I tried with SDO connected to 3.3V and unconnected, but it doesn’t change.
Is there anything I can try to make this work?

Cheers, David

So, I went through “accelhw.cpp” and found that it should just work, if there are sda and scl pins with a LIS3DH connected. Nevertheless I tried to set the variables in the config like 204maker mentioned.

In “main.ts” I wrote:

namespace config{
    export const ACCELEROMETER_TYPE = DAL.ACCELEROMETER_TYPE_LIS3DH_ALT;
    export const PIN_ACCELEROMETER_SDA = DAL.PA08;
    export const PIN_ACCELEROMETER_SCL = DAL.PA09;
    export const PIN_ACCELEROMETER_INT = DAL.PA02;
}

Now the binary.asm says:

    .word 1, 2  ; PIN_ACCELEROMETER_INT=2
    .word 2, 9  ; PIN_ACCELEROMETER_SCL=9
    .word 3, 8  ; PIN_ACCELEROMETER_SDA=8
...
    .word 70, 48  ; ACCELEROMETER_TYPE=48

But now the Trinket hangs completely and I even don’t get the 0 reading.
Is there a way to debug this?