i2c - Cannot read property 'path' undefined error

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. (/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.

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

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. (/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.

On Mon, 28 Jan 2019 22:14:26 -0800 (PST),
prasad.aditi1@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