I2C program for MangOH Yellow

Can i do it in an app? I’m not familair with legato. Just like the helloworld app and instaid of the LE_INFO i need to write system(i2cget -y 5 0x5b 0x00 > /tmp/test.txt)? What i also want is to send this to datahub.

Yes, you can do this in unsandboxed legato app

You can then read /tmp/test.txt inside your app

If i understand it right you get this?

You can add some sleep() inbetween

It looks like my i2cget won’t work

[1/7] 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:7:16: error: ‘i2cget’ undeclared (first use in this function); did you mean ‘socket’?
         system(i2cget -y 5 0x5b 0x00 > /tmp/text.txt);
                ^~~~~~
                socket
/home/lukas/Documents/MangOH/helloworld/helloComponent/helloWorld.c:7:16: note: each undeclared identifier is reported only once for each function it appears in
/home/lukas/Documents/MangOH/helloworld/helloComponent/helloWorld.c:7:24: error: ‘y’ undeclared (first use in this function); did you mean ‘yn’?
         system(i2cget -y 5 0x5b 0x00 > /tmp/text.txt);
                        ^
                        yn
/home/lukas/Documents/MangOH/helloworld/helloComponent/helloWorld.c:7:26: error: expected ‘)’ before numeric constant
         system(i2cget -y 5 0x5b 0x00 > /tmp/text.txt);
                          ^
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}'" failed to launch (exit code: 1).

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

You need to add double quote

Ohw, i need to read better. I’m sorry.
The build and install is succesfully complete. But how can i read the file. And how can i send it to datahub?
Sorry for this many questions!

I also got no text.txt file. Do i need to make it manual?

You need to check logread to see why no file output

Yeah i saw it:

Jun 21 14:04:18 swi-mdm9x28-wp user.err Legato: =ERR= | i2c[1042] | sh:
Jun 21 14:04:18 swi-mdm9x28-wp user.err Legato: =ERR= | i2c[1042] | i2cget: not found
Jun 21 14:04:18 swi-mdm9x28-wp user.err Legato: =ERR= | i2c[1042] |
Jun 21 14:04:19 swi-mdm9x28-wp user.err kernel: [ 1650.266938] i2c-msm-v2 78b8000.i2c: NACK: slave not responding, ensure its powered: msgs(n:2 cur:0 tx) bc(rx:2 tx:1) mode:FIFO slv_addr:0x55 MSTR_STS:0x0d1343c8 OPER:0x00000010
Jun 21 14:04:19 swi-mdm9x28-wp user.err kernel: [ 1650.281797] i2c-msm-v2 78b8000.i2c: NACK: slave not responding, ensure its powered: msgs(n:2 cur:0 tx) bc(rx:2 tx:1) mode:FIFO slv_addr:0x55 MSTR_STS:0x0d1343c8 OPER:0x00000010

Thats the log i get when i do logread -f |grep i2c
My slave adress is 0x5b why does it said 0x55?
My program is correct:

#include "legato.h"

COMPONENT_INIT
{
    while (1)
    {
        system("i2cget -y 5 0x5b 0x00 > /tmp/text.txt");
        sleep(10)
        ;
    }
}

you need to use full path:
system(“/usr/sbin/i2cget -y 5 0x5b 0x00 > /tmp/text.txt”);

I get the same error in logread

Jun 21 14:49:44 swi-mdm9x28-wp user.err Legato: =ERR= | i2c[31996] | sh:
Jun 21 14:49:44 swi-mdm9x28-wp user.err Legato: =ERR= | i2c[31996] | usr/sbin/i2cget: not found
Jun 21 14:49:44 swi-mdm9x28-wp user.err Legato: =ERR= | i2c[31996] |
Jun 21 14:49:49 swi-mdm9x28-wp user.err kernel: [ 4380.266768] i2c-msm-v2 78b8000.i2c: NACK: slave not responding, ensure its powered: msgs(n:2 cur:0 tx) bc(rx:2 tx:1) mode:FIFO slv_addr:0x55 MSTR_STS:0x0d1343c8 OPER:0x00000010
Jun 21 14:49:49 swi-mdm9x28-wp user.err kernel: [ 4380.281660] i2c-msm-v2 78b8000.i2c: NACK: slave not responding, ensure its powered: msgs(n:2 cur:0 tx) bc(rx:2 tx:1) mode:FIFO slv_addr:0x55 MSTR_STS:0x0d1343c8 OPER:0x00000010

you miss “/” at the beginning

Oh, wake me up :sleeping:

Jun 21 14:57:59 swi-mdm9x28-wp user.err kernel: [ 4870.266872] i2c-msm-v2 78b8000.i2c: NACK: slave not responding, ensure its powered: msgs(n:2 cur:0 tx) bc(rx:2 tx:1) mode:FIFO slv_addr:0x55 MSTR_STS:0x011363c8 OPER:0x00000010
Jun 21 14:57:59 swi-mdm9x28-wp user.err kernel: [ 4870.281722] i2c-msm-v2 78b8000.i2c: NACK: slave not responding, ensure its powered: msgs(n:2 cur:0 tx) bc(rx:2 tx:1) mode:FIFO slv_addr:0x55 MSTR_STS:0x011363c8 OPER:0x00000010

Now i only get this. Like i said before the slave adress is nog correct. slv_addr:0x55 how can i fix it?

that message is not related, you can ignore it

Yes, it works
But now i get this: 0x10
I want just want some usefull data form it? And send this to datahub

0x10 is your useful data

Owh, and how can i transform it into themperature or something?

i don’t know, that is your sensor!!!

You need to check datasheet…

Oke :grimacing:
Do you know how i can get this data on Octave with datahub?