beagleboard / bonescript

Scripting tools for the BeagleBoard and BeagleBone
http://beagleboard.org
MIT License
32 stars 9 forks source link

i2cscan returns empty data array #21

Open jadonk opened 6 years ago

jadonk commented 6 years ago

From @snidera on March 4, 2014 20:31

i2cscan is returning an empty array on '/dev/i2c-2', when I have a device connected at 0x20 & 0x21 (and can read/write to both via another script & i2cdetect -r 1 shows both)

Clean 9/4 image installed yesterday. Tried both before & after updated to bonescript 0.2.4

I've modified the 'test-i2c' from github as follows:

var b = require('bonescript'); var port = '/dev/i2c-2';

b.i2cOpen(port); b.i2cScan(port, onScan);

function onScan(err, data) { console.log('scan = ' + JSON.stringify(arguments)); }

If I run it using '/dev/i2c-0', I get the same output as 'test-i2c' (data=[52,80])

scan = {"0":{"err":null,"data":[52,80],"event":"callback"}} scan = {"0":{"event":"return","return":[ -1,-1,-1,-1,-1,-1,-1,-1,-1,-1, -1,-1,-1,-1,-1,-1,-1,-1,-1,-1, -1,-1,-1,-1,-1,-1,-1,-1,-1,-1, -1,-1,-1,-1,-1,-1,-1,-1,-1,-1, -1,-1,-1,-1,-1,-1,-1,-1,-1,-1, -1,-1,52,-1,-1,-1,-1,-1,-1,-1, -1,-1,-1,-1,-1,-1,-1,-1,-1,-1, -1,-1,-1,-1,-1,-1,-1,-1,-1,-1, 80,-1,-1,-1,-1,-1,-1,-1,-1,-1, -1,-1,-1,-1,-1,-1,-1,-1,-1,-1, -1,-1,-1,-1,-1,-1,-1,-1,-1,-1, -1,-1,-1,-1,-1,-1,-1,-1,-1,-1, -1,-1,-1,-1,-1,-1,-1,-1]}}

If I run on /dev/i2c-1 or /dev/i2c-2, I get an empty array in data.

scan = {"0":{"err":null,"data":[],"event":"callback"}} scan = {"0":{"event":"return","return":[ -1,-1,-1,-1,-1,-1,-1,-1,-1,-1, -1,-1,-1,-1,-1,-1,-1,-1,-1,-1, -1,-1,-1,-1,-1,-1,-1,-1,-1,-1, -1,-1,-1,-1,-1,-1,-1,-1,-1,-1, -1,-1,-1,-1,-1,-1,-1,-1,-1,-1, -1,-1,-1,-1,-1,-1,-1,-1,-1,-1, -1,-1,-1,-1,-1,-1,-1,-1,-1,-1, -1,-1,-1,-1,-1,-1,-1,-1,-1,-1, -1,-1,-1,-1,-1,-1,-1,-1,-1,-1, -1,-1,-1,-1,-1,-1,-1,-1,-1,-1, -1,-1,-1,-1,-1,-1,-1,-1,-1,-1, -1,-1,-1,-1,-1,-1,-1,-1,-1,-1, -1,-1,-1,-1,-1,-1,-1,-1]}}

What am I doing wrong?

Copied from original issue: jadonk/bonescript#77

jadonk commented 6 years ago

Which pins do you have connected? https://github.com/jadonk/bonescript/blob/7e5e6e72ce821b8cec36748adaa60f3814f97d51/src/bone.js#L1535 shows the pin mapping for the various port selections.

jadonk commented 6 years ago

From @snidera on March 11, 2014 13:14

P9 19 & 20 (Now I understand why i2c-2 in bonescript = port 1 in i2c tools). i2cdetect -r 1 shows the device(s) at the proper address

I have 3 MCP23017 connected, I want to have n connected & have the program adjust. The following code functions as expected, but is condensed to save space. I can control the 3 MCPs from a web page (click button, turn on output for 500ms)

var app = require('http').createServer(handler).listen(8090); var io = require('socket.io').listen(app); var fs = require('fs'); var b = require('bonescript'); var port = '/dev/i2c-2'; var mcp = [0x20,0x21,0x22]; //This is where I want to use i2cScan to detect n MCPs for (var i=0,len=mcp.length; i<len; i++){ b.i2cOpen(port, mcp[i], {}); b.i2cWriteBytes(port, 0x12, [0x00]); b.i2cWriteBytes(port, 0x00, [0x00]); b.i2cWriteBytes(port, 0x13, [0x00]); b.i2cWriteBytes(port, 0x01, [0x00]); } io.sockets.on('connection', function (socket) { socket.on('FIRE', function (data) { var delay = 500; b.i2cOpen(port, data.ADDRESS, {}); b.i2cWriteBytes(port, data.BANK, [data.VALUE]);
setTimeout(function() {b.i2cWriteBytes(port, data.BANK, [0x00])},delay); }); }); function handler (req,res) { fs.readFile('Javascript/sock123/index.html', function (err, data) { res.writeHead(200); res.end(data); }); }.