New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Can't find a connected GrovePi board #1343
Comments
The expander-GROVEPI.js example linked to above expects the Raspberry Pi to be connected to an Arduino which isn't the case here. The GrovePi is connected directly to the Raspberry Pi. In this case |
@fivdi I tried with the example and had the same error as follows. $ sudo node test.js
1495205611191 Available RaspberryPi-IO
1495205611507 Connected RaspberryPi-IO
1495205611521 Repl Initialized
>> fs.js:787
return binding.writeBuffer(fd, buffer, offset, length, position);
^
Error: EIO: i/o error, write
at Error (native)
at Object.fs.writeSync (fs.js:787:20)
at Bus.i2cWriteSync (/home/pi/johnny-five/node_modules/i2c-bus/i2c-bus.js:348:13)
at I2C.writeSync (/home/pi/johnny-five/node_modules/raspi-i2c/dist/index.js:297:37)
at RaspiIOCore.i2cWrite (/home/pi/johnny-five/node_modules/raspi-io-core/dist/index.js:744:19)
at Expander.value (/home/pi/johnny-five/lib/expander.js:1218:17)
at Expander.value (/home/pi/johnny-five/lib/expander.js:1187:20)
at new Expander (/home/pi/johnny-five/lib/expander.js:1876:10)
at Board.<anonymous> (/home/pi/johnny-five/eg/test.js:9:8)
at emitNone (events.js:91:20) To make sure, the version of $ npm list raspi-io
johnny-five@0.10.13 /home/pi/johnny-five
└── raspi-io@8.0.1 extraneous
npm ERR! extraneous: raspi-io@8.0.1 /home/pi/johnny-five/node_modules/raspi-io The following is an excerpt of
|
And thank your for your reply! Can you change the following line in
to
and report your findings please? |
I'm not 100% sure but think the Pi needs to be rebooted after changing |
@fivdi
Unfortunately, it seems that the same error occurs even after the change. $ sudo node test.js
1495232263765 Available RaspberryPi-IO
:)
1495232264084 Connected RaspberryPi-IO
1495232264097 Repl Initialized
>> ready
fs.js:787
return binding.writeBuffer(fd, buffer, offset, length, position);
^
Error: EIO: i/o error, write
at Error (native)
at Object.fs.writeSync (fs.js:787:20)
at Bus.i2cWriteSync (/home/pi/Desktop/scs2017/tutorial/physical-computing/node_modules/i2c-bus/i2c-bus.js:348:13)
at I2C.writeSync (/home/pi/Desktop/scs2017/tutorial/physical-computing/node_modules/raspi-i2c/dist/index.js:297:37)
at RaspiIOCore.i2cWrite (/home/pi/Desktop/scs2017/tutorial/physical-computing/node_modules/raspi-io-core/dist/index.js:744:19)
at Expander.value (/home/pi/Desktop/scs2017/tutorial/physical-computing/node_modules/johnny-five/lib/expander.js:1218:17)
at Expander.value (/home/pi/Desktop/scs2017/tutorial/physical-computing/node_modules/johnny-five/lib/expander.js:1187:20)
at new Expander (/home/pi/Desktop/scs2017/tutorial/physical-computing/node_modules/johnny-five/lib/expander.js:1876:10)
at Board.<anonymous> (/home/pi/Desktop/scs2017/tutorial/physical-computing/j5.js:13:5)
at emitNone (events.js:91:20) As I wrote in the beginning, access with |
Just to make sure, this is the complete content of file
|
It looks like I was barking up the wrong tree. I thought the I2C baudrate was too high but this doesn't appear to be the case.
Unfortunately I don't have a GrovePi to test with, so it may take a while to figure things out :) As far as I can tell, the I2C write operations being performed by Johnny-Five are correct. Perhaps it's a timing issue. Johnny-Five performs quite a number of I2C write operations in quick succession during initialization of the GrovePi. Perhaps these operations are being performed too quickly for the GrovePi. The two lines of code here are in a loop that's executed during the initialization phase. Let's slow things down to see if it helps. Add the following function at the top or bottom of function sleepus(usDelay) {
var startTime = process.hrtime();
var deltaTime;
var usWaited = 0;
while (usDelay > usWaited) {
deltaTime = process.hrtime(startTime);
usWaited = (deltaTime[0] * 1E9 + deltaTime[1]) / 1000;
}
} When called, Then, to slow things down a bit and provide some debug information, add the following lines at the beginning of pinMode.value and digitalWrite.value in sleepus(10000);
console.log(pin); Please give this a try to see if anything changes. |
Thank you very much for your suggestion! I just modified var Board = require("./board");
var Emitter = require("events").EventEmitter;
var util = require("util");
var nanosleep = require("./sleep").nano;
var Fn = require("./fn");
var priv = new Map();
var active = new Map();
function sleepus(usDelay) {
var startTime = process.hrtime();
var deltaTime;
var usWaited = 0;
while (usDelay > usWaited) {
deltaTime = process.hrtime(startTime);
usWaited = (deltaTime[0] * 1E9 + deltaTime[1]) / 1000;
}
}
function Base() {
...
GROVEPI: {
...
pinMode: {
value: function(pin, mode) {
sleepus(10000);
console.log(pin);
...
digitalWrite: {
value: function(pin, value) {
sleepus(10000);
console.log(pin);
... The result was as follows:
If there are points that I misunderstood, it will be appreciated if you can point out. |
You understood everything correctly :) The error is thrown when attempting to set the mode for pin D2. The I2C write operation that sets the pin mode is called here and looks like this: Bus.prototype.i2cWriteSync = function (addr, length, buffer) {
return fs.writeSync(peripheralSync(this, addr), buffer, 0, length, 0);
}; Can you modify this code to the following, try again, and report your findings please: Bus.prototype.i2cWriteSync = function (addr, length, buffer) {
console.log(peripheralSync(this, addr), buffer);
return fs.writeSync(peripheralSync(this, addr), buffer, 0, length, 0);
}; If I'm not mistaken, the output should look like this:
On your system the code to modify is at /home/pi/Desktop/scs2017/tutorial/physical-computing/node_modules/i2c-bus/i2c-bus.js:348:13 The GrovePi example that works for you does the same thing here. |
Leave the |
I just tried as you suggested and the result was like this: 1495263769551 Available RaspberryPi-IO
1495263769846 Connected RaspberryPi-IO
1495263769860 Repl Initialized
>> pinMode: D2 1
18 <Buffer 05 02 01 00>
fs.js:787
return binding.writeBuffer(fd, buffer, offset, length, position);
^
Error: EIO: i/o error, write
at Error (native)
at Object.fs.writeSync (fs.js:787:20)
at Bus.i2cWriteSync (/home/pi/Desktop/scs2017/tutorial/physical-computing/node_modules/i2c-bus/i2c-bus.js:353:13)
at I2C.writeSync (/home/pi/Desktop/scs2017/tutorial/physical-computing/node_modules/raspi-i2c/dist/index.js:297:37)
at RaspiIOCore.i2cWrite (/home/pi/Desktop/scs2017/tutorial/physical-computing/node_modules/raspi-io-core/dist/index.js:744:19)
at Expander.value (/home/pi/Desktop/scs2017/tutorial/physical-computing/node_modules/johnny-five/lib/expander.js:1242:17)
at Expander.value (/home/pi/Desktop/scs2017/tutorial/physical-computing/node_modules/johnny-five/lib/expander.js:1205:20)
at new Expander (/home/pi/Desktop/scs2017/tutorial/physical-computing/node_modules/johnny-five/lib/expander.js:1906:10)
at Board.<anonymous> (/home/pi/Desktop/scs2017/tutorial/physical-computing/j5.js:10:8)
at emitNone (events.js:91:20) Just to make sure, the test code was like this: var five = require('johnny-five');
var raspi = require('raspi-io');
var board = new five.Board({
io: new raspi()
});
board.on('ready', function() {
var virtual = new five.Board.Virtual(
new five.Expander('GROVEPI')
);
var led = new five.Led({
pin: 'D4',
board: virtual
});
led.on();
}); I wonder why the address is 18 instead of 4... |
Sorry, I made a mistake. console.log(peripheralSync(this, addr), buffer); Should be: console.log(addr, buffer); |
I tried again, and the result was as follows (as you expected):
|
Well, that looks good to me. I'm not sure what's going on. The test program is currently using the raspi-io plugin. There's an alternative plugin called pi-io. Can you give pi-io a try to see if anything changes please. |
Sure. I replaced var raspi = require('raspi-io'); with var raspi = require('pi-io'); and tried again. First time failed as follows: 1495266304617 Available unknown
1495266304704 Connected undefined
1495266304731 Repl Initialized
>> pinMode: D2 1
4 <Buffer 05 02 01 00>
fs.js:787
return binding.writeBuffer(fd, buffer, offset, length, position);
^
Error: EIO: i/o error, write
at Error (native)
at Object.fs.writeSync (fs.js:787:20)
at Bus.i2cWriteSync (/home/pi/Desktop/scs2017/tutorial/physical-computing/node_modules/i2c-bus/i2c-bus.js:354:13)
at PiIO.LinuxIO.i2cWrite (/home/pi/Desktop/scs2017/tutorial/physical-computing/node_modules/linux-io/lib/linux-io.js:322:9)
at Expander.value (/home/pi/Desktop/scs2017/tutorial/physical-computing/node_modules/johnny-five/lib/expander.js:1241:17)
at Expander.value (/home/pi/Desktop/scs2017/tutorial/physical-computing/node_modules/johnny-five/lib/expander.js:1204:20)
at new Expander (/home/pi/Desktop/scs2017/tutorial/physical-computing/node_modules/johnny-five/lib/expander.js:1905:10)
at Board.<anonymous> (/home/pi/Desktop/scs2017/tutorial/physical-computing/j5.js:10:5)
at emitNone (events.js:91:20)
at Board.emit (events.js:185:7) However, after the second time it operates normally as follows! 1495266661781 Available unknown
1495266661877 Connected undefined
1495266661923 Repl Initialized
>> pinMode: D2 1
4 <Buffer 05 02 01 00>
digitalWrite: D2 0
4 <Buffer 02 02 00 00>
pinMode: D3 1
4 <Buffer 05 03 01 00>
digitalWrite: D3 0
4 <Buffer 02 03 00 00>
pinMode: D4 1
4 <Buffer 05 04 01 00>
digitalWrite: D4 0
4 <Buffer 02 04 00 00>
pinMode: D5 1
4 <Buffer 05 05 01 00>
digitalWrite: D5 0
4 <Buffer 02 05 00 00>
pinMode: D6 1
4 <Buffer 05 06 01 00>
digitalWrite: D6 0
4 <Buffer 02 06 00 00>
pinMode: D7 1
4 <Buffer 05 07 01 00>
digitalWrite: D7 0
4 <Buffer 02 07 00 00>
pinMode: D8 1
4 <Buffer 05 08 01 00>
digitalWrite: D8 0
4 <Buffer 02 08 00 00>
pinMode: A0 2
4 <Buffer 05 0e 00 00>
pinMode: A1 2
4 <Buffer 05 0f 00 00>
pinMode: A2 2
4 <Buffer 05 10 00 00>
pinMode: D4 1
4 <Buffer 05 04 01 00>
digitalWrite: D4 1
4 <Buffer 02 04 01 00> I tried deleting
|
Just to be sure, I created a new directory in another hierarchy, installed var five = require('johnny-five');
var raspi = require('pi-io');
var board = new five.Board({
io: new raspi()
});
board.on('ready', function() {
var virtual = new five.Board.Virtual(
new five.Expander('GROVEPI')
);
var led = new five.Led({
pin: 'D4',
board: virtual
});
led.on();
}); |
Well, at least we've made progress. Does everything still work after a reboot of the Pi? |
We certainly made progress! However, the problem seems to have not been solved completely. I checked it after restart. First of all, I found that the code in the previous example crashes at a probability of about a few percent. Next, I realized that crashing would be done every time by executing code which was made slightly complicated as follows. var five = require('johnny-five');
var raspi = require('pi-io');
var board = new five.Board({
io: new raspi()
});
function sleep(ms) {
console.log('sleep ' + ms);
return new Promise(resolve => setTimeout(resolve, ms));
}
board.on('ready', function() {
var virtual = new five.Board.Virtual(
new five.Expander('GROVEPI')
);
var led = new five.Led({
pin: 'D4',
board: virtual
});
var button = new five.Button({
pin: 'D3',
board: virtual
});
button.on('down', function() {
console.log('button down');
led.on();
});
button.on('up', function() {
console.log('button up');
led.off();
});
this.on('exit', function() {
led.off();
});
}); Regarding this code, adding the same change as before (adding 10,000 microsecond sleep to 1495269663467 Available unknown
1495269663556 Connected undefined
1495269663578 Repl Initialized
>> pinMode: D2 1
digitalWrite: D2 0
pinMode: D3 1
digitalWrite: D3 0
pinMode: D4 1
digitalWrite: D4 0
pinMode: D5 1
digitalWrite: D5 0
pinMode: D6 1
digitalWrite: D6 0
pinMode: D7 1
digitalWrite: D7 0
pinMode: D8 1
digitalWrite: D8 0
pinMode: A0 2
fs.js:787
return binding.writeBuffer(fd, buffer, offset, length, position);
^
Error: EIO: i/o error, write
at Error (native)
at Object.fs.writeSync (fs.js:787:20)
at Bus.i2cWriteSync (/home/pi/Desktop/test/node_modules/i2c-bus/i2c-bus.js:348:13)
at PiIO.LinuxIO.i2cWrite (/home/pi/Desktop/test/node_modules/linux-io/lib/linux-io.js:322:9)
at Expander.value (/home/pi/Desktop/test/node_modules/johnny-five/lib/expander.js:1232:17)
at Expander.value (/home/pi/Desktop/test/node_modules/johnny-five/lib/expander.js:1194:20)
at new Expander (/home/pi/Desktop/test/node_modules/johnny-five/lib/expander.js:1893:10)
at Board.<anonymous> (/home/pi/Desktop/test/b.js:14:5)
at emitNone (events.js:91:20)
at Board.emit (events.js:185:7) That was a share about what I knew for a while. |
Can you lower the baudrate from 100000 to 10000 or maybe 50000 to see if there are less or no errors? |
I changed the communication speed and tried it. First, at 10,000 bps, I did not add sleep to pinMode and digitalWrite, nor did it crash within the range of 50 tests for each code. Next, at 50,000 bps, there was never a crash in the range where 50 tests were done for each code as well. |
Furthermore, after returning the communication speed to 100,000 bps once, I lowered the communication speed little by little and checked it. As a result, I found that at 70,000 bps, it is as almost stable as 10,000 bps. While it is slightly different, 75,000 bps makes it unstable suddenly, so there seems to be a boundary around here. |
Looking at the GrovePi led_blink.js example the flow of control through the code when turning the LED on is from here to here to here to here. The code more or less ignores errors and is implemented in a way that will attempt to do the best it can in the case of errors. To me, it looks like the GrovePi developers had similar issues. The underlying problem here is a hardware bug in the Raspberry Pi. It doesn't support I2C clock stretching correctly. AVR microcontrollers (like on the GrovePi) run at fairly low clock speeds and it's not easy to implement code that runs without stretching the I2C clock at a baudrate of 100000. The boundary that you are seeing somewhere around 70000 baud doesn't surprise me and it's what I'd expect under these conditions. |
Also, I2C interrupts on AVR microcontrollers have a lower priority than all other interrupts. So the more interrupts handlers there are, the worse things get and the lower the baudrate can be. Lowering the baudrate will increase the chance of the AVR not needing to stretch the I2C clock. |
Thank you for the detailed information. I tried the second sample which used the button and the LED at the same time afterwards. It never crashed (as I reported earlier), however there seemed to be a malfunction related to input, such as a It is very disappointing, but I am beginning to think that switching to Arduino Uno etc. via USB is better... 😢 |
I'm afraid I haven't used a GrovePi so I'm unable to comment on any Johnny-Five related issues there may be. Maybe you could open issues for the problems you found? What features of the GrovePi would you like to use that the Raspberry Pi doesn't directly support? For example, buttons and pulsing LED will work directly with a Raspberry Pi. Or have you already purchased sensors with the appropriate connectors for the GrovePi and need to use them? |
@nebrius There appears to be scenarios where raspi-io has I2C issues. For example, it's unclear to me why switching from rasp-io to pi-io resulted in GrovePi functioning above. I see that raspi-i2c has been reimpemented in TypeScript. Some of the corresponding JavaScript code is no longer what it used to be, for example, in writeSync the var |
Oh whoops, yeah I made a porting error. I just published v5.0.4 of raspi-i2c with a fix, let me know if it works! |
@nebrius var five = require('johnny-five');
var raspi = require('raspi-io');
var board = new five.Board({
io: new raspi()
});
board.on('ready', function() {
var virtual = new five.Board.Virtual(
new five.Expander('GROVEPI')
);
var led = new five.Led({
pin: 'D3',
board: virtual
});
led.on();
}); However, the result was as follows: $ npm list | grep "raspi-i2c\|raspi-io\|johnny-five"
├─┬ johnny-five@0.10.13
├─┬ raspi-io@8.0.1
│ ├─┬ raspi-i2c@5.0.4
│ ├── raspi-io-core@2.0.1
$ sudo node a.js
1495333830532 Available RaspberryPi-IO
1495333830871 Connected RaspberryPi-IO
1495333830884 Repl Initialized
>> fs.js:787
return binding.writeBuffer(fd, buffer, offset, length, position);
^
Error: EIO: i/o error, write
at Error (native)
at Object.fs.writeSync (fs.js:787:20)
at Bus.i2cWriteSync (/home/pi/Desktop/test/node_modules/i2c-bus/i2c-bus.js:348:13)
at I2C.writeSync (/home/pi/Desktop/test/node_modules/raspi-i2c/dist/index.js:307:37)
at RaspiIOCore.i2cWrite (/home/pi/Desktop/test/node_modules/raspi-io-core/dist/index.js:744:19)
at Expander.value (/home/pi/Desktop/test/node_modules/johnny-five/lib/expander.js:1218:17)
at Expander.value (/home/pi/Desktop/test/node_modules/johnny-five/lib/expander.js:1187:20)
at new Expander (/home/pi/Desktop/test/node_modules/johnny-five/lib/expander.js:1876:10)
at Board.<anonymous> (/home/pi/Desktop/test/a.js:10:5)
at emitNone (events.js:91:20) |
Hmm... Can you do me a favor and run:
and report back the output of the second command? |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. |
I am trying to use GrovePi with johnny-five in the following environment, but even if I run the sample (expander-GROVEPI.js), the display will not proceed from
Looking for connected device
.Board
Software
$ node expander-GROVEPI.js 1495202610738 Board Looking for connected device
The GrovePi board seems to be recognized according to the execution results of i2cdetect. Actually, the samples of node-grovepi works fine.
If you have any other things to check, things to try, etc., please let me know. Thank you very much in advance.
The text was updated successfully, but these errors were encountered: