You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If I stream writes from the master (Raspberry pi) to a slave (Arduino uno) I end up with a [Error: Cannot write to device] error on the master side if the delayBetweenPackets is to low. It doesnt seem to be consistent, but at around 50ms between packets I can normally get away with streaming data. At 10 ms between packets I can only get 11 packets sent before the error.
Is there a way to tell when bus is ready for another packet or will I just need to calibrate this delay between packets by trial and error?
Here is the test script running on the pi
var delayBetweenPackets = 50;
var numberOfPackets = 100;
var i2c = require('i2c');
var address = 0x18;
var wire = new i2c(address, {device: '/dev/i2c-1', debug: false}); // point to your i2c address, debug provides REPL interface
var i = 0;
sendPacket();
function sendPacket()
{
var buf = new Buffer(4);
buf.writeInt32LE(i, 0, true);
wire.writeBytes(0x0, buf, function(err)
{
if(!err && i < numberOfPackets)
{
i++;
setTimeout(sendPacket, delayBetweenPackets);
}
else console.log("writeBytes result: ", err);
});
}
and here is the code running on the Arduino
#include <Wire.h>
void setup()
{
Wire.begin(0x18); // join i2c bus with address #4
Wire.onReceive(receiveEvent); // register event
Serial.begin(9600); // start serial for output
Serial.println("Listening for i2c com");
}
void loop()
{
delay(100);
}
void receiveEvent(int howMany)
{
if(howMany >= 5)
{
Wire.read(); //first byte is the "command byte" and I don't what to do with it
long value = (long)Wire.read();
value += (long)Wire.read() << 8;
value += (long)Wire.read() << 16;
value += (long)Wire.read() << 24;
Serial.print("Long value: ");
Serial.println(value);
}
}
The text was updated successfully, but these errors were encountered:
If I stream writes from the master (Raspberry pi) to a slave (Arduino uno) I end up with a [Error: Cannot write to device] error on the master side if the delayBetweenPackets is to low. It doesnt seem to be consistent, but at around 50ms between packets I can normally get away with streaming data. At 10 ms between packets I can only get 11 packets sent before the error.
Is there a way to tell when bus is ready for another packet or will I just need to calibrate this delay between packets by trial and error?
Here is the test script running on the pi
and here is the code running on the Arduino
The text was updated successfully, but these errors were encountered: