-
Notifications
You must be signed in to change notification settings - Fork 92
Arduino recieves transmission in one byte per transmission. #1
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
Comments
The javascript for node.js: var i2c = require('i2c'); wire.write(4, ["RSI".charCodeAt(0), "RSI".charCodeAt(1), "RSI".charCodeAt(2)], function(err) {}); |
The Arduino code: #include "Wire.h" void receiveEvent(int numBytes) { void setup() { void loop() { |
Hey there! Current it's using writeByte to write each byte in the array. I'm going to transition this to a writeBlock feature, that will send all in a single transmission. I'll post a release soon with this update. |
Hello! Ah, that explains. All the extra i2c communication sometimes crashes the Arduino, especially when using a WII nunchuk, which also uses i2c. Thx! |
Hi Duvel, i am running into the same problem. While korevec is able to help us with the single byte receive problem I may be able to help you with your Arduinos crashing. My arduino was also crashing spontaneously while doing i2c. Turns out I was doing serial.println(...) inside the receiveEvent callback which crashed the arduino. More details can be found here: arduino/Arduino#1354 (comment). There is another bug in the Wire library that crashes the arduino when more than 32 bytes are received in one go. This has also been adressed and will likely be fixed with the next release of the Arduino IDE. You can also grab the lastest version from github that should already include that fix. |
Hi Mofux, Thanks for the response, but I don't have either of these situations :( I already moved everything possible outside the recieveEvent function. So I still don't know, where the problem lies, but maybe I have to pull the information instead of pushing. But my guess is that lots of i2c transactions isn't helping as we'll, so I'm waiting on the next version to eliminate everything step-by-step. Groetjes, Remco Op 17 apr. 2013 om 18:06 heeft mofux [email protected] het volgende geschreven:
|
Hi korevec, I have noticed that the read function only reads a single byte. Do you have plans on changing it to readBlock? |
Yep! Next version will support readBlock and writeBock. It also will return a buffer instead of an array and will be based off node's streams2 implementation. |
Will we see the release of the next version anytime soon? I have just implemented writeBlock on my own but would rather wait for your library to include it. I could also create a pull request with my changes if you're interested. |
It should be out within a week. Let me know how this sounds for usage: var i2c = require('i2c');
var compass = new i2c('0x03'); // pass in address
compass.write(['0x04', '0x05', '0x06']); // will accept a buffer and write 3 bytes as a block
buf = compass.read(3) // read a block of 3 bytes
buf.length // 3
buf.readInt8(0) // 4
buf[1] // 5 if you pass in more than a byte, it'll use the writeBlock method. Same with read. Will that work for you? |
Almost :) I guess compass.read should be non blocking, which would translate to: compass.read(3, function(err, buf) {
...
}); |
It'll be non blocking. You can also do: compass.read(3)
compass.on('data', function(buf) { ... }); trying to adhere to the streams2 api http://blog.nodejs.org/2012/12/20/streams2/ |
Hello,
When I send a transmission from a Raspberry Pi to an Arduino, the Arduino recieves the bytes in separate transmissions it seems.
The result on the arduino is:
numBytes: 1
char: R
numBytes: 1
char: S
numBytes: 1
char: I
I post the code in separate comments.
Greetz,
Remco Schoen
The text was updated successfully, but these errors were encountered: