# I2C program for MangOH Yellow

**URL:** <https://forum.legato.io/t/i2c-program-for-mangoh-yellow/5853>\
**Category:** Legato Application Framework\
**Created:** [June 21, 2021, 6:28am UTC](https://forum.legato.io/t/i2c-program-for-mangoh-yellow/5853 "2021-06-21T06:28:26Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![r0795090](https://avatars.discourse-cdn.com/v4/letter/r/90db22/32.png) [@r0795090](https://forum.legato.io/u/r0795090)\
**Post date:** [June 21, 2021, 6:28am UTC](https://forum.legato.io/t/i2c-program-for-mangoh-yellow/5853/1 "2021-06-21T06:28:26Z")

</div>

Hi,  
Does someone got a simple program to read i2c data from extern sensor on a mangoh yellow.  
Because i need it soon and i’m not familair with Legato.

Thanks in advanced!

---

<div class="post-metadata">

**Author:** ![jyijyi](https://sea1.discourse-cdn.com/flex019/user_avatar/forum.legato.io/jyijyi/32/822_2.png) [@jyijyi](https://forum.legato.io/u/jyijyi)\
**Post date:** [June 21, 2021, 6:47am UTC](https://forum.legato.io/t/i2c-program-for-mangoh-yellow/5853/2 "2021-06-21T06:47:55Z")

</div>

you can try i2cdetect command and see if it can “see” your sensor

---

<div class="post-metadata">

**Author:** ![r0795090](https://avatars.discourse-cdn.com/v4/letter/r/90db22/32.png) [@r0795090](https://forum.legato.io/u/r0795090)\
**Post date:** [June 21, 2021, 6:49am UTC](https://forum.legato.io/t/i2c-program-for-mangoh-yellow/5853/3 "2021-06-21T06:49:51Z")

</div>

I already did that, and i saw my sensor. but i need to read the data.

---

<div class="post-metadata">

**Author:** ![jyijyi](https://sea1.discourse-cdn.com/flex019/user_avatar/forum.legato.io/jyijyi/32/822_2.png) [@jyijyi](https://forum.legato.io/u/jyijyi)\
**Post date:** [June 21, 2021, 7:33am UTC](https://forum.legato.io/t/i2c-program-for-mangoh-yellow/5853/4 "2021-06-21T07:33:09Z")

</div>

I don’t see problem to read mangoh red sensor bmi160 chipid:

```auto
 root@swi-mdm9x28-wp:~# i2cdetect -y -r 4
     0 1 2 3 4 5 6 7 8 9 a b c d e f
00: -- 04 05 06 07 -- -- -- -- -- -- -- --
10: -- -- -- -- -- -- -- -- -- -- UU -- -- -- -- --
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
30: -- -- -- -- -- -- -- -- -- -- UU -- -- -- -- --
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
50: -- 51 -- -- -- -- -- -- -- -- -- -- -- -- -- --
60: -- -- -- -- -- -- -- -- 68 -- -- -- -- -- -- --
70: -- 71 -- -- -- -- 76 --
 root@swi-mdm9x28-wp:~# i2cget -y 4 0x68 0x00
0xd1

```

---

<div class="post-metadata">

**Author:** ![r0795090](https://avatars.discourse-cdn.com/v4/letter/r/90db22/32.png) [@r0795090](https://forum.legato.io/u/r0795090)\
**Post date:** [June 21, 2021, 7:37am UTC](https://forum.legato.io/t/i2c-program-for-mangoh-yellow/5853/5 "2021-06-21T07:37:01Z")

</div>

With me, that works too. All I need is a simple program to read my data and send it to the data hub. This is because I am not very familiar with Legato.

And a question about the i2cget. Why is the data in hex?

---

<div class="post-metadata">

**Author:** ![jyijyi](https://sea1.discourse-cdn.com/flex019/user_avatar/forum.legato.io/jyijyi/32/822_2.png) [@jyijyi](https://forum.legato.io/u/jyijyi)\
**Post date:** [June 21, 2021, 7:39am UTC](https://forum.legato.io/t/i2c-program-for-mangoh-yellow/5853/6 "2021-06-21T07:39:25Z")

</div>

you can use unsandboxed legato application to call i2cget command by system() API:

root@swi-mdm9x28-wp:~# i2cget -y 4 0x68 0x00 \> /tmp/test.txt  
root@swi-mdm9x28-wp:~# cat /tmp/test.txt  
0xd1

BTW, I also see i2cget source code here:

> <https://github.com/omapconf/omapconf/blob/master/i2c-tools/i2cget.c>

---

<div class="post-metadata">

**Author:** ![r0795090](https://avatars.discourse-cdn.com/v4/letter/r/90db22/32.png) [@r0795090](https://forum.legato.io/u/r0795090)\
**Post date:** [June 21, 2021, 7:42am UTC](https://forum.legato.io/t/i2c-program-for-mangoh-yellow/5853/7 "2021-06-21T07:42:49Z")

</div>

I’m gona try the code you send me, but how can i install it on to my mangoh?

---

<div class="post-metadata">

**Author:** ![jyijyi](https://sea1.discourse-cdn.com/flex019/user_avatar/forum.legato.io/jyijyi/32/822_2.png) [@jyijyi](https://forum.legato.io/u/jyijyi)\
**Post date:** [June 21, 2021, 7:47am UTC](https://forum.legato.io/t/i2c-program-for-mangoh-yellow/5853/8 "2021-06-21T07:47:30Z")

</div>

you can port to your unsandboxed helloworld application

---

<div class="post-metadata">

**Author:** ![r0795090](https://avatars.discourse-cdn.com/v4/letter/r/90db22/32.png) [@r0795090](https://forum.legato.io/u/r0795090)\
**Post date:** [June 21, 2021, 7:48am UTC](https://forum.legato.io/t/i2c-program-for-mangoh-yellow/5853/9 "2021-06-21T07:48:59Z")

</div>

I don’t need any .cdef or .adef file? Or do i need to make it myself?

---

<div class="post-metadata">

**Author:** ![jyijyi](https://sea1.discourse-cdn.com/flex019/user_avatar/forum.legato.io/jyijyi/32/822_2.png) [@jyijyi](https://forum.legato.io/u/jyijyi)\
**Post date:** [June 21, 2021, 7:52am UTC](https://forum.legato.io/t/i2c-program-for-mangoh-yellow/5853/10 "2021-06-21T07:52:22Z")

</div>

you can see here:

> **[legato-af/apps/sample/helloWorld at master · legatoproject/legato-af](https://github.com/legatoproject/legato-af/tree/master/apps/sample/helloWorld)**
>
> master/apps/sample/helloWorld

---

<div class="post-metadata">

**Author:** ![r0795090](https://avatars.discourse-cdn.com/v4/letter/r/90db22/32.png) [@r0795090](https://forum.legato.io/u/r0795090)\
**Post date:** [June 21, 2021, 8:03am UTC](https://forum.legato.io/t/i2c-program-for-mangoh-yellow/5853/11 "2021-06-21T08:03:08Z")

</div>

When i try to install and build my app with ctrl + shift + b i get this error.

```auto
[1/9] Compiling C source
FAILED: /home/lukas/Documents/MangOH/_build_helloWorld/wp77xx/component/18d9b6c36944259de3cc6094b6e7b806/obj/345c983f9563b0189a5a82859aa12ccd.o 
/home/lukas/Documents/MangOH/leaf-data/MangOHYellow/wp77-toolchain/sysroots/x86_64-pokysdk-linux/usr/bin/arm-poky-linux-gnueabi/arm-poky-linux-gnueabi-gcc --sysroot=/home/lukas/Documents/MangOH/leaf-data/MangOHYellow/wp77-toolchain/sysroots/armv7a-neon-poky-linux-gnueabi -MMD -MF /home/lukas/Documents/MangOH/_build_helloWorld/wp77xx/component/18d9b6c36944259de3cc6094b6e7b806/obj/345c983f9563b0189a5a82859aa12ccd.o.d -Wall -Werror -fvisibility=hidden -c /home/lukas/Documents/MangOH/helloworld/helloComponent/helloWorld.c -o /home/lukas/Documents/MangOH/_build_helloWorld/wp77xx/component/18d9b6c36944259de3cc6094b6e7b806/obj/345c983f9563b0189a5a82859aa12ccd.o -DLE_FILENAME=`basename /home/lukas/Documents/MangOH/helloworld/helloComponent/helloWorld.c` -DMK_TOOLS_BUILD -DLEGATO_EMBEDDED -fPIC -I /home/lukas/Documents/MangOH/_build_helloWorld/wp77xx -I/home/lukas/Documents/MangOH/leaf-data/MangOHYellow/wp77-legato/interfaces -I/home/lukas/Documents/MangOH/leaf-data/MangOHYellow/wp77-legato/framework/include -I/home/lukas/Documents/MangOH/leaf-data/MangOHYellow/wp77-legato/build/wp77xx/framework/include -I/home/lukas/Documents/MangOH/helloworld -I/home/lukas/Documents/MangOH/_build_helloWorld/wp77xx/component/18d9b6c36944259de3cc6094b6e7b806/src -DLE_COMPONENT_NAME=helloComponent -DLE_LOG_SESSION=helloComponent_LogSession -DLE_LOG_LEVEL_FILTER_PTR=helloComponent_LogLevelFilterPtr 
/home/lukas/Documents/MangOH/helloworld/helloComponent/helloWorld.c: In function ‘_helloComponent_COMPONENT_INIT’:
/home/lukas/Documents/MangOH/helloworld/helloComponent/helloWorld.c:8:9: error: implicit declaration of function ‘le_thread_Sleep’; did you mean ‘le_thread_Start’? [-Werror=implicit-function-declaration]
         le_thread_Sleep(5);
         ^ ~~~~~~~~~~~~~~
         le_thread_Start
cc1: all warnings being treated as errors
[2/9] Compiling C source
ninja: build stopped: subcommand failed.
The terminal process "bash '-c', 'mkapp ${LEGATO_DEF_FILE} -s components -t ${LEGATO_TARGET} -w ${LEGATO_OBJECT_DIR} -o ${LEGATO_OUTPUT_DIR} && update ${LEGATO_UPDATE_FILE}'" terminated with exit code: 1.

Terminal will be reused by tasks, press any key to close it.

```

---

<div class="post-metadata">

**Author:** ![jyijyi](https://sea1.discourse-cdn.com/flex019/user_avatar/forum.legato.io/jyijyi/32/822_2.png) [@jyijyi](https://forum.legato.io/u/jyijyi)\
**Post date:** [June 21, 2021, 8:19am UTC](https://forum.legato.io/t/i2c-program-for-mangoh-yellow/5853/12 "2021-06-21T08:19:16Z")

</div>

it seems this function only appear in new legato framework, (at lease I don’t see it in legato 19.2)

You might need to use the latest legato release

---

<div class="post-metadata">

**Author:** ![r0795090](https://avatars.discourse-cdn.com/v4/letter/r/90db22/32.png) [@r0795090](https://forum.legato.io/u/r0795090)\
**Post date:** [June 21, 2021, 8:36am UTC](https://forum.legato.io/t/i2c-program-for-mangoh-yellow/5853/13 "2021-06-21T08:36:14Z")

</div>

I deleted the line of code now it is working 😉 I was testing the helloworld app.  
Now i see it into my apps  
But what do i need to set into my cdef and adef. Or can i leave it like this?

---

<div class="post-metadata">

**Author:** ![jyijyi](https://sea1.discourse-cdn.com/flex019/user_avatar/forum.legato.io/jyijyi/32/822_2.png) [@jyijyi](https://forum.legato.io/u/jyijyi)\
**Post date:** [June 21, 2021, 9:17am UTC](https://forum.legato.io/t/i2c-program-for-mangoh-yellow/5853/14 "2021-06-21T09:17:16Z")

</div>

if you need to make it unsandboxed, you need to change adef:  
sandboxed: false

---

<div class="post-metadata">

**Author:** ![r0795090](https://avatars.discourse-cdn.com/v4/letter/r/90db22/32.png) [@r0795090](https://forum.legato.io/u/r0795090)\
**Post date:** [June 21, 2021, 9:18am UTC](https://forum.legato.io/t/i2c-program-for-mangoh-yellow/5853/15 "2021-06-21T09:18:09Z")

</div>

What do you mean with sandboxed? What is the difference?

---

<div class="post-metadata">

**Author:** ![jyijyi](https://sea1.discourse-cdn.com/flex019/user_avatar/forum.legato.io/jyijyi/32/822_2.png) [@jyijyi](https://forum.legato.io/u/jyijyi)\
**Post date:** [June 21, 2021, 9:25am UTC](https://forum.legato.io/t/i2c-program-for-mangoh-yellow/5853/16 "2021-06-21T09:25:08Z")

</div>

you can see here:

> **[Sandbox Overview - Legato Docs](https://docs.legato.io/latest/conceptsSecuritySandboxOverview.html)**
>
> legato™ is an open source Linux-based embedded platform designed to simplify connected IoT application development

Basically if you use sandboxed feature, you cannot use system() API

---

<div class="post-metadata">

**Author:** ![r0795090](https://avatars.discourse-cdn.com/v4/letter/r/90db22/32.png) [@r0795090](https://forum.legato.io/u/r0795090)\
**Post date:** [June 21, 2021, 9:28am UTC](https://forum.legato.io/t/i2c-program-for-mangoh-yellow/5853/17 "2021-06-21T09:28:25Z")

</div>

Ah, thanks and for i2c do i need the sandbox mode? If i understand it well i don’t need it but for sure i ask it

---

<div class="post-metadata">

**Author:** ![jyijyi](https://sea1.discourse-cdn.com/flex019/user_avatar/forum.legato.io/jyijyi/32/822_2.png) [@jyijyi](https://forum.legato.io/u/jyijyi)\
**Post date:** [June 21, 2021, 9:45am UTC](https://forum.legato.io/t/i2c-program-for-mangoh-yellow/5853/18 "2021-06-21T09:45:23Z")

</div>

normally i suggest you not to use sandboxed feature during development, that will cost you a lot of abnormal error during development.

---

<div class="post-metadata">

**Author:** ![r0795090](https://avatars.discourse-cdn.com/v4/letter/r/90db22/32.png) [@r0795090](https://forum.legato.io/u/r0795090)\
**Post date:** [June 21, 2021, 9:49am UTC](https://forum.legato.io/t/i2c-program-for-mangoh-yellow/5853/19 "2021-06-21T09:49:33Z")

</div>

Oke, thanks.  
Now when i’m trying to install and build my app again i get this errors. Do i need to install something i forgot?

 ![afbeelding](https://us1.discourse-cdn.com/flex019/uploads/legato1/original/2X/c/c467e6762485140dcb265f628eab1d3083462f1d.png)

---

<div class="post-metadata">

**Author:** ![jyijyi](https://sea1.discourse-cdn.com/flex019/user_avatar/forum.legato.io/jyijyi/32/822_2.png) [@jyijyi](https://forum.legato.io/u/jyijyi)\
**Post date:** [June 21, 2021, 10:00am UTC](https://forum.legato.io/t/i2c-program-for-mangoh-yellow/5853/20 "2021-06-21T10:00:21Z")

</div>

why don’t you just called sytsem(" i2cget -y 4 0x68 0x00 \> /tmp/test.txt")

and then you can read the /tmp/test.txt

[Next page](https://forum.legato.io/t/i2c-program-for-mangoh-yellow/5853.md?page=2)
