Skip to content

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

Closed
Duvel opened this issue Mar 21, 2013 · 12 comments
Closed

Arduino recieves transmission in one byte per transmission. #1

Duvel opened this issue Mar 21, 2013 · 12 comments
Assignees

Comments

@Duvel
Copy link

Duvel commented Mar 21, 2013

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

@Duvel
Copy link
Author

Duvel commented Mar 21, 2013

The javascript for node.js:

var i2c = require('i2c');
var wire = new i2c('/dev/i2c-0'); // point to your i2c device, debug provides REPL interface

wire.write(4, ["RSI".charCodeAt(0), "RSI".charCodeAt(1), "RSI".charCodeAt(2)], function(err) {});

@Duvel
Copy link
Author

Duvel commented Mar 21, 2013

The Arduino code:

#include "Wire.h"

void receiveEvent(int numBytes) {
Serial.print("numBytes: ");
Serial.println(numBytes);
char ch = Wire.read();
Serial.print("char: ");
Serial.println(ch);
}

void setup() {
Serial.begin(115200);
Wire.begin(4);
Wire.onReceive(receiveEvent);
}

void loop() {
}

@ghost ghost assigned kelly Mar 21, 2013
@kelly
Copy link
Owner

kelly commented Mar 21, 2013

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.

@Duvel
Copy link
Author

Duvel commented Mar 24, 2013

Hello! Ah, that explains. All the extra i2c communication sometimes crashes the Arduino, especially when using a WII nunchuk, which also uses i2c. Thx!

@mofux
Copy link

mofux commented Apr 17, 2013

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.

@Duvel
Copy link
Author

Duvel commented Apr 21, 2013

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 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. 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.


Reply to this email directly or view it on GitHub.

@mofux
Copy link

mofux commented Apr 25, 2013

Hi korevec,

I have noticed that the read function only reads a single byte. Do you have plans on changing it to readBlock?

@kelly
Copy link
Owner

kelly commented Apr 25, 2013

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.

@mofux
Copy link

mofux commented Apr 25, 2013

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.

@kelly
Copy link
Owner

kelly commented Apr 25, 2013

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?

@mofux
Copy link

mofux commented Apr 25, 2013

Almost :) I guess compass.read should be non blocking, which would translate to:

compass.read(3, function(err, buf) {
...
});

@kelly
Copy link
Owner

kelly commented Apr 26, 2013

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/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants