i2c - Cannot read property 'path' undefined error

82 views
Skip to first unread message

Chris Bohler

unread,
Sep 27, 2018, 4:17:36 PM9/27/18
to BeagleBoard

I have set up a Beaglebone Black with the latest Debian download. A circuitco Bacon Cape is mounted.

I am attempting to read the 3-axis accelerometer data via i2c (p9_19,20) using existing code downloaded from baconcapelabs (see code below):

 

var b = require('bonescript'); // Read BoneScript library

var port = '/dev/i2c-2';

var address = 0x1c;

b.i2cOpen(port, address, {}, onI2C);    // Open I2C port 

b.i2cWriteBytes(port, 0x2a, [0x00]); // Set STANDBY mode

b.i2cWriteBytes(port, 0x0e, [0x00]); // Set scale to 2G

b.i2cWriteBytes(port, 0x2a, [0x01]); // Set ACTIVE mode

setInterval(readA, 200); // Call readA() every 200ms

 

function onI2C() {

}

 

function readA() {

 b.i2cReadBytes(port, 1, 6, onReadBytes);

}

 

function onReadBytes(x) {

 if(x.event == 'callback') { var X = convertToG(x.res[0]); // First byte is X

                             var Y = convertToG(x.res[2]); // Third byte is Y

                             var Z = convertToG(x.res[4]); // Fifth byte is Z

 console.log('X: ' + X + ' Y: ' + Y + ' Z: ' + Z);

 }

}

function convertToG(x) {

 if(x >= 128) x = -((x^0xFF)+1); // Get two's complement

 x = x / 64; // Scale to G

 x = x.toFixed(2); // Limit decimal places

 return(x);

}

 

When I run this javascript code on Cloud9 IDE, I receive the following error:

 

/usr/local/lib/node_modules/bonescript/src/iic.js:15

    if (m.ports[args.port[0]].path) path = m.ports[args.port[0]].path;

                             ^

 

TypeError: Cannot read property 'path' of undefined

  at Object.m.doOpen (/usr/local/lib/node_modules/bonescript/src/iic.js:15:30)

  at Object.newFunction [as i2cOpen] (/usr/local/lib/node_modules/bonescript/src/my.js:451:31)

  at Object.<anonymous> (/var/lib/cloud9/examples/BBB_Accelerometer.js:7:3)

  at Module._compile (module.js:577:32)

  at Object.Module._extensions..js (module.js:586:10)

  at Module.load (module.js:494:32)

  at tryModuleLoad (module.js:453:12)

  at Function.Module._load (module.js:445:3)

  at Timeout.Module.runMain [as _onTimeout] (module.js:611:10)

  at ontimeout (timers.js:386:11)

  at tryOnTimeout (timers.js:250:5)

  at Timer.listOnTimeout (timers.js:214:5)

 

Changing the i2c channel to i2c-1 allows me to get past this error (had seen that bonescript naming scheme different); however, “x.event” is now undefined upon function onReadBytes.

 

SSH over USB using i2c tools indicates i2c2 acting as expected.

 

Any help would be much appreciated.

Mala Dies

unread,
Nov 16, 2018, 6:45:13 PM11/16/18
to BeagleBoard
Hello,

I do not know if you are still working w/ the BaconCape or not but here goes it: 

...

sudo config-pin P9.19 uart 

...

If that cmd does not work, please reply. I would like to help and I have had some ideas w/ past Capes. 

Seth

prasad...@gmail.com

unread,
Jan 29, 2019, 8:03:16 AM1/29/19
to BeagleBoard
Hello,
 could you help me with this
I'm using beaglebone green ,but since the processors are same i used the following code to see if my i2c is working.
but when i run this code in cloud9 ,it shows a similar error as the previous post.
 

var b = require('bonescript');

var port = '/dev/i2c-1';

var address = 0x0D;

b.pinMode("P9_29", b.OUTPUT);

b.pinMode("P9_30", b.OUTPUT);

b.digitalWrite("P9_29", b.HIGH);

b.digitalWrite("P9_30", b.LOW);

b.i2cOpen('/dev/i2c-1',0x0D, {});

b.i2cWriteBytes('/dev/i2c-1', 0x00, [0x00]);

b.i2cWriteBytes('/dev/i2c-1', 0x80, 0x07);

b.i2cWriteBytes('/dev/i2c-1', 0x81, 0x18);



ERROR :

/var/lib/cloud9/NewFolder/i2cTest.js:6

b.i2cOpen(port, address, {});

  ^

Debugger listening on [::]:15454

/usr/local/lib/node_modules/bonescript/src/my.js:425

                if(callback) callback({err:'Kernel does not include CapeMgr module'});

                             ^

 

TypeError: callback is not a function

  at Object.newFunction [as i2cOpen] (/usr/local/lib/node_modules/bonescript/src/my.js:425:30)

  at Object.<anonymous> (/var/lib/cloud9/i2c.js:8:3)

  at Module._compile (module.js:570:32)

  at Object.Module._extensions..js (module.js:579:10)

  at Module.load (module.js:487:32)

  at tryModuleLoad (module.js:446:12)

  at Function.Module._load (module.js:438:3)

  at Timeout.Module.runMain [as _onTimeout] (module.js:604:10)

  at ontimeout (timers.js:386:11)

  at tryOnTimeout (timers.js:250:5)

  at Timer.listOnTimeout (timers.js:214:5)

 

 

 

Process exited with code: 1


Could you please help me with this. I'm new to the beaglebone Board.

 

Dennis Lee Bieber

unread,
Jan 29, 2019, 1:58:52 PM1/29/19
to beagl...@googlegroups.com
On Mon, 28 Jan 2019 22:14:26 -0800 (PST),
prasad...@gmail.com declaimed the
following:

>Hello,
> could you help me with this
>I'm using beaglebone green ,but since the processors are same i used the
>following code to see if my i2c is working.
>but when i run this code in cloud9 ,it shows a similar error as the
>previous post.
>
<SNIP>

>/usr/local/lib/node_modules/bonescript/src/my.js:425
>
> if(callback) callback({err:'Kernel does not include CapeMgr
>module'});
>

What version of bonescript do you have... that error message is
produced at line 439 in the source at
https://github.com/jadonk/bonescript/blob/master/src/my.js


https://github.com/jadonk/bonescript

-=-=-=-
debian@beaglebone:~$ node -pe
"require('bonescript').getPlatform().bonescript"
0.7.0
debian@beaglebone:~$
-=-=-=-

NOTE: apt-get update/upgrade did find a bonescript update dated this week!
-=-=-=-
Preparing to unpack
.../01-bonescript_0.7.1-git20190123.0-0rcnee2~stretch+20190127_armhf.deb
...
Unpacking bonescript (0.7.1-git20190123.0-0rcnee2~stretch+20190127) over
(0.7.0-git20180821.0-0rcnee1~stretch+20180821) ...
-=-=-=-
debian@beaglebone:~$ node -pe
"require('bonescript').getPlatform().bonescript"
0.7.1
debian@beaglebone:~$
-=-=-=-

I'm not having much luck with Cloud9 -- trying to run the code causes a
"disconnect"... From the command line I'm getting:

-=-=-=-
root@beaglebone:/var/lib/cloud9# cat i2ctest.js
// JavaScript File
var b = require('bonescript');
var port = '/dev/i2c-1';
var address = 0x0D;

b.pinMode("P9_29", b.OUTPUT);
b.pinMode("P9_30", b.OUTPUT);
b.digitalWrite("P9_29", b.HIGH);
b.digitalWrite("P9_30", b.LOW);

b.i2cOpen(port, address, {});
b.i2cWriteBytes(port, 0x00, [0x00]);
b.i2cWriteBytes(port, 0x80, 0x007);
b.i2cWriteBytes(port, 0x81, 0x18);root@beaglebone:/var/lib/cloud9#

root@beaglebone:/var/lib/cloud9# node i2ctest.js
info: No pinmux for P9_29
info: No pinmux for P9_29
/usr/local/lib/node_modules/bonescript/src/my.js:438
if (callback) callback({
^

TypeError: callback is not a function
at Object.newFunction [as i2cOpen]
(/usr/local/lib/node_modules/bonescript/src/my.js:438:31)
at Object.<anonymous> (/var/lib/cloud9/i2ctest.js:11:3)
at Module._compile (module.js:577:32)
at Object.Module._extensions..js (module.js:586:10)
at Module.load (module.js:494:32)
at tryModuleLoad (module.js:453:12)
at Function.Module._load (module.js:445:3)
at Module.runMain (module.js:611:10)
at run (bootstrap_node.js:394:7)
at startup (bootstrap_node.js:160:9)
at bootstrap_node.js:507:3

root@beaglebone:/var/lib/cloud9#
-=-=-=-

Commenting out the digital I/O stuff

-=-=-=-
root@beaglebone:/var/lib/cloud9# cat i2ctest.js
// JavaScript File
var b = require('bonescript');
var port = '/dev/i2c-1';
var address = 0x0D;

//b.pinMode("P9_29", b.OUTPUT);
//b.pinMode("P9_30", b.OUTPUT);
//b.digitalWrite("P9_29", b.HIGH);
//b.digitalWrite("P9_30", b.LOW);

b.i2cOpen(port, address, {});
b.i2cWriteBytes(port, 0x00, [0x00]);
b.i2cWriteBytes(port, 0x80, 0x007);
b.i2cWriteBytes(port, 0x81, 0x18);
root@beaglebone:/var/lib/cloud9# node i2ctest.js
/usr/local/lib/node_modules/bonescript/src/my.js:438
if (callback) callback({
^

TypeError: callback is not a function
at Object.newFunction [as i2cOpen]
(/usr/local/lib/node_modules/bonescript/src/my.js:438:31)
at Object.<anonymous> (/var/lib/cloud9/i2ctest.js:11:3)
at Module._compile (module.js:577:32)
at Object.Module._extensions..js (module.js:586:10)
at Module.load (module.js:494:32)
at tryModuleLoad (module.js:453:12)
at Function.Module._load (module.js:445:3)
at Module.runMain (module.js:611:10)
at run (bootstrap_node.js:394:7)
at startup (bootstrap_node.js:160:9)
at bootstrap_node.js:507:3

root@beaglebone:/var/lib/cloud9#
-=-=-=-

Removing that empty 3rd argument from the Open call...

-=-=-=-
root@beaglebone:/var/lib/cloud9# cat i2ctest.js
// JavaScript File
var b = require('bonescript');
var port = '/dev/i2c-1';
var address = 0x0D;

//b.pinMode("P9_29", b.OUTPUT);
//b.pinMode("P9_30", b.OUTPUT);
//b.digitalWrite("P9_29", b.HIGH);
//b.digitalWrite("P9_30", b.LOW);

b.i2cOpen(port, address);
b.i2cWriteBytes(port, 0x00, [0x00]);
b.i2cWriteBytes(port, 0x80, 0x007);
b.i2cWriteBytes(port, 0x81, 0x18);
root@beaglebone:/var/lib/cloud9# node i2ctest.js
root@beaglebone:/var/lib/cloud9#
-=-=-=-

NO ERROR. I suspect to use the digital I/O will require first exporting
those pins from the command line (I'm not a bonescript/node use -- I don't
know if the library is supposed to export stuff, which the Python
Adafruit_BBIO might do)



--
Wulfraed Dennis Lee Bieber AF6VN
wlf...@ix.netcom.com HTTP://wlfraed.home.netcom.com/

Reply all
Reply to author
Forward
0 new messages