rwaldron / tessel-io

A Tessel 2 IO Plugin for Johnny-Five JavaScript Robotics programs
http://johnny-five.io
50 stars 11 forks source link

Socket Errors and other I2C Oddities #13

Open lyzadanger opened 7 years ago

lyzadanger commented 7 years ago

Hello!

First and foremost: I am not certain that the issues I am seeing are at the tessel-io level, but it seemed the most probable after a long and fruitless debug session, so this is where I'm starting. Happy to move this over to t2-firmware or elsewhere if that's the culprit.

OK, so. I am having a bear of a time with I2C reads and the T2, suddenly (like, I used to be able to use I2C with my Tessels like a boss a few months ago). The majority of my tests are using J5 and J5 component classes for different I2C sensors. I'm not experiencing the absolute same breakage with every sensor, but I cannot currently get a single sensor to work correctly. The problems I am having fall into three areas.

Most commonly, any form of reading via a J5 component object for an I2C sensor is throwing the following error:

1487614407606 Device(s) Tessel 2 (ichabod)
1487614407762 Connected Tessel 2 (ichabod)
1487614407818 Repl Initialized
>> ok
Socket: Error occurred,  { [Error: write EPIPE] code: 'EPIPE', errno: 'EPIPE', syscall: 'write' }
/usr/lib/node/tessel-export.js:255
      throw new Error('Socket: The Port socket has closed.');
      ^

Error: Socket: The Port socket has closed.
    at Socket.<anonymous> (/usr/lib/node/tessel-export.js:255:13)
    at emitOne (events.js:77:13)
    at Socket.emit (events.js:169:7)
    at Pipe._onclose (net.js:486:12)

Very occasionally this error is not thrown, but any data I'm able to read off of an I2C sensor is invalid—e.g. I'll get constant 0s on an altimeter, constant 32 values for thermometer.F.

Also occasionally I get:

Socket: Error occurred,  { [Error: connect EAGAIN /var/run/tessel/port_a]
  code: 'EAGAIN',
  errno: 'EAGAIN',
  syscall: 'connect',
  address: '/var/run/tessel/port_a' }

but I have a hunch that latter error may be a symptom of the first.

When I started debugging this, I hoped to hell I had just fried a Tessel. But the bad news is that the behavior I'm observing is consistent across both of my Tessels.

OK, now some details:

$ t2 version
INFO Looking for your Tessel...
INFO Connected to ichabod.
INFO Tessel Environment Versions:
INFO t2-cli: 0.1.4
INFO t2-firmware: 0.0.16
INFO Node.js: 4.5.0

Here's some brief sample code for a BMP180 that I'm using:

const five = require('johnny-five');
const Tessel = require('tessel-io');

const board = new five.Board({
  io: new Tessel()
});

board.on('ready', () => {
  const weatherSensor = new five.Multi({
    controller: 'BMP180'
  });
  board.loop(2000, () => {
    console.log(weatherSensor.barometer.pressure);
  });
  console.log("Hey Ho, Let's Go");
});

More than 90% of the time this just crashes outright (with the socket error above). On the rare occasions it doesn't, any data read from the BMP180 is invalid. I'm using board.loop here because the data and/or change events on the BMP never fire.

I'm at the end of what I can think of to debug this. I'm up against a deadline for a chapter in my book about Tessel and serial so I am anxious at being so deeply entrenched and stuck!

lyzadanger commented 7 years ago

Update: I've found the underlying source of the problem, generally. I downgraded a Tessel all the way to firmware version 0.0.13. That release's date was May 2016. Release 0.0.14 and after display the broken behavior as documented here.

There's some possibility, then, that I2C support for Tessel via J5/tessel-io has been broken since last September? Is there anyone out there who can help me test this (trying to interact with any I2C sensor device via J5/tessel-io)?

HipsterBrown commented 7 years ago

I started working to recreate this issue tonight. I'm using a BME280 from the Johnny-Five Inventor's Kit and the sample code you displayed in the description (using 'BME280' instead of 'BMP180'). I also specifically installed tessel-io version 0.9.0 as you described and the latest firmware for Tessel.

My code:

const five = require('johnny-five');
const Tessel = require('tessel-io');

const board = new five.Board({
  io: new Tessel()
});

board.on("ready", () => {
  var monitor = new five.Multi({
    controller: "BME280"
  });

  board.loop(2000, () => {
    console.log(monitor.barometer.pressure);
  });
  console.log("Hey Ho, Let's Go");
});

t2 version:

hipsterbrown:i2c-test $ t2 version
INFO Looking for your Tessel...
INFO Connected to ava.
INFO Tessel Environment Versions:
INFO t2-cli: 0.1.4
INFO t2-firmware: 0.0.16
INFO Node.js: 4.5.0

Results:

hipsterbrown:i2c-test $ t2 run i2c-test.js
INFO Looking for your Tessel...
INFO Connected to ava.
INFO Building project.
INFO Writing project to RAM on ava (750.08 kB)...
INFO Deployed.
INFO Running i2c-test.js...
1475695004163 Device(s) Tessel 2 (ava)
1475695004321 Connected Tessel 2 (ava)
1475695004379 Repl Initialized
>> Hey Ho, Let's Go
72.984
100.907
100.907
100.907
100.909
100.909
100.909
100.912
100.912
100.912
100.913
100.913
100.913

While it seems to be working for all of my available Tessel boards, I'll continue looking for other I2C sensors to test. I'll also try debugging those specific error message within the t2-firmware and tessel-io internals.

lyzadanger commented 7 years ago

Oh, my. I wonder if it could be a combination of the newer firmware and my own system. As I mentioned, I'm on Mac 10.11.6 and have been running various Node.js version (my default system global right now is v6.2.0). Irritatingly, I cannot seem to find my own BME280 (I have one, but it's missing) or I'd test that setup, too.

Maybe I'll try to borrow my partner's laptop (also a Mac) and see if I get the same errors.

HipsterBrown commented 7 years ago

@lyzadanger I was working on my home laptop last night, which is running the latest Mac OS. I'll try again tonight with my work laptop, which is running Mac 10.11.6 as well.

rwaldron commented 7 years ago

How would MacOS version impact remote execution?

lyzadanger commented 7 years ago

@rwaldron No idea, TBH! But I'm trying to grasp at straws as to what makes this reproduce-able...

rwaldron commented 7 years ago

@lyzadanger fair enough (I didn't know if there was some MacOS update that I had missed that was fucking with USB devices)