Closed bwarp closed 10 years ago
Try this:
var i2c = require ('i2c');
var MCP23017 = new i2c (0x20);
MCP23017.writeBytes (0x00, [0x80], function (err) { handle err});
MCP23017.writeBytes (0x14, [0x01], function (err) { handle err});
Your problem is at data type, you have to use "[ ]" for data to send. Like:
wire.writeBytes("register", ["byte1", "byte2", "byte3" ...]);
That worked when I added the callback err function! Thanks!
function callback(err) { if (err) { console.log(err.message); } }
I am using a raspberryPi and nodeJS. I am trying to communicate to an MCP23017. I can manually init the chip, and turn a led on and off with i2cset below. // configure Port A pins GPA0-6 as outputs and GPA7 as an input. (10000000 in binary and 0×80 in hex) : // i2cset -y 1 0x20 0x00 0x80 // Then we set GPA0 to logic high which will enable the LED : // i2cset -y 1 0x20 0x14 0x01
But in node I cannot get it to work! What am I doing wrong? var i2c = require('i2c'); var address = 0x20; // point to your i2c address, debug provides REPL interface var wire = new i2c(address, {device: '/dev/i2c-1', debug: true}); wire.writeBytes(0x00, 0x80); // Init MCP 23017 wire.writeBytes(0x14, 0x01); // Turn LED ON Thanks!!!!