Javascript questions unrelated to HM


 

Andy Snider

TVWBB Fan
I'm trying to control a mcp23017 I/O expander from my beaglebone using the built-in bonescript library.
I'm having a hard time finding an example I can hack up that does what I want to do. I'd greatly appreciate a point in the right direction.
I basically want to set all the ports to output & turn them on/off. This will eventually control electric matches & launch fireworks.

I can control it from i2c-tools via SSH.
i2cset -y 1 0x20 0x00 0x00 sets IODIRA to output (1st 8)
i2cset -y 1 0x20 0x12 0x01 turns the 1st output on (using a LED to confirm)

I don't understand the usage of:
i2cWriteByte(port, byte, [callback])
i2cWriteBytes(port, command, bytes, [callback])
(bonescript is on github if you want to see what it has)

I open the port/address, no error, the test function runs & prints to console.
------------------------
var b = require('bonescript');
var port = '/dev/i2c-1';
var address = 0x20;

//i2cOpen(port, address, options, [callback])
b.i2cOpen(port, address, [OnI2C]);

//No Error, but doesn't turn LED on.
//b.i2cWriteBytes(port,[0x20,0x00,0x00],[]); set IODIRA as output
//b.i2cWriteBytes(port,[0x20,0x12,0x01],[]); Set Port1 = 1

OnI2C();
function OnI2C() {
console.log('I2C port 1 open');
}
 

 

Back
Top