# Accelerometer (LIS3DH) reading in console

**URL:** <https://forum.makecode.com/t/accelerometer-lis3dh-reading-in-console/632>\
**Category:** Arcade\
**Created:** [October 16, 2019, 9:08pm UTC](https://forum.makecode.com/t/accelerometer-lis3dh-reading-in-console/632 "2019-10-16T21:08:08Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![204maker](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/204maker/32/447_2.png) [@204maker](https://forum.makecode.com/u/204maker)\
**Post date:** [October 16, 2019, 9:08pm UTC](https://forum.makecode.com/t/accelerometer-lis3dh-reading-in-console/632/1 "2019-10-16T21:08:08Z")

</div>

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](https://arcade.makecode.com/beta#editor)) but the code  
won’t compile so I cannot download the uf2 file.

![arcade-test_accel](https://us1.discourse-cdn.com/flex020/uploads/makecode/original/1X/e767e7d76f97e66afcacc6a8639fbea560f7b099.png)

What am I missing here?

---

<div class="post-metadata">

**Author:** ![kjw](https://avatars.discourse-cdn.com/v4/letter/k/e79b87/32.png) [@kjw](https://forum.makecode.com/u/kjw)\
**Post date:** [October 17, 2019, 2:57pm UTC](https://forum.makecode.com/t/accelerometer-lis3dh-reading-in-console/632/2 "2019-10-17T14:57:32Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![204maker](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/204maker/32/447_2.png) [@204maker](https://forum.makecode.com/u/204maker)\
**Post date:** [October 17, 2019, 8:12pm UTC](https://forum.makecode.com/t/accelerometer-lis3dh-reading-in-console/632/3 "2019-10-17T20:12:54Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![jwunderl](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/jwunderl/32/5308_2.png) [@jwunderl](https://forum.makecode.com/u/jwunderl)\
**Post date:** [October 17, 2019, 9:08pm UTC](https://forum.makecode.com/t/accelerometer-lis3dh-reading-in-console/632/4 "2019-10-17T21:08:20Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![204maker](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/204maker/32/447_2.png) [@204maker](https://forum.makecode.com/u/204maker)\
**Post date:** [November 5, 2019, 12:42pm UTC](https://forum.makecode.com/t/accelerometer-lis3dh-reading-in-console/632/6 "2019-11-05T12:42:13Z")

</div>

Referencing a similar post below:  
[https://forum.makecode.com/t/re-d51-sound-mixer/735](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?

---

<div class="post-metadata">

**Author:** ![mmoskal](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/mmoskal/32/20_2.png) [@mmoskal](https://forum.makecode.com/u/mmoskal)\
**Post date:** [November 7, 2019, 6:49pm UTC](https://forum.makecode.com/t/accelerometer-lis3dh-reading-in-console/632/7 "2019-11-07T18:49:30Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![204maker](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/204maker/32/447_2.png) [@204maker](https://forum.makecode.com/u/204maker)\
**Post date:** [November 11, 2019, 6:34pm UTC](https://forum.makecode.com/t/accelerometer-lis3dh-reading-in-console/632/8 "2019-11-11T18:34:23Z")

</div>

Thank you @mmoskal.  
I used LIS3DH\_ALT on the patcher and it worked like a charm. 🤗

---

<div class="post-metadata">

**Author:** ![davidf](https://avatars.discourse-cdn.com/v4/letter/d/f07891/32.png) [@davidf](https://forum.makecode.com/u/davidf)\
**Post date:** [September 7, 2022, 9:18pm UTC](https://forum.makecode.com/t/accelerometer-lis3dh-reading-in-console/632/9 "2022-09-07T21:18:57Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![davidf](https://avatars.discourse-cdn.com/v4/letter/d/f07891/32.png) [@davidf](https://forum.makecode.com/u/davidf)\
**Post date:** [September 9, 2022, 5:05pm UTC](https://forum.makecode.com/t/accelerometer-lis3dh-reading-in-console/632/10 "2022-09-09T17:05:42Z")

</div>

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:

```auto
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:

```auto
    .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?
