I2C program for MangOH Yellow

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!

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

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

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

 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

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?

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:

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

you can port to your unsandboxed helloworld application

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

you can see here:

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

[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.

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

I deleted the line of code now it is working :wink: 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?

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

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

you can see here:
https://docs.legato.io/latest/conceptsSecuritySandboxOverview.html

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

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

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

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?

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

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