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.

-- 
For more options, visit http://beagleboard.org/discuss
--- 
You received this message because you are subscribed to the Google Groups 
"BeagleBoard" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/beagleboard/6429df25-775f-457f-a046-26f73c1dd530%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to