<< return to Pixycam.com

max cable length for SPI vs. UART

hello,
which is the max cable length for SPI vs. UART mode?

any information?

Hello,

there is no specified maximum length…shorter is better, since the ribbon cable is unshielded.

If you give more info about what you’re trying to do, or what length you are considering, it would help us give better feedback.

Thanks!
Jesse

hello,
the Arduino board is inside of the mobile robot chassis, but the cam has to be mounted close to the gripper of a robot arm on top of the chassis, all over about 1m distance.
I’m afraid that SPI will not support 1m cable length, or does it?
I2C must be even more than just 1m because other i2c devices are already plugged (70cm cable additionally).
So what about UART and /or I2C?

Hello,
There are no hard-fast rules regarding cable length. Variables that affect cable length (data reliability) are EMI in the environment, electrical noise in the system/power supply, the communication medium and the data rate. We can more easily control the medium and the data rate, the others are harder to control and measure. I2C tends to be less noise-immune because it lacks a push-pull driver and is higher impedance as a result. SPI and UART are better. When using SPI, Pixy acts as a slave, so your microcontroller will be supplying the clock and you’ll determine the data rate.

I would make the cable the length that you want and see if it works. You can use the checksums on the protocol to determine if you are getting bitstream errors. If you are getting too many errors, try lowering the data rate.

Hope this helps!

Edward

Hello,
There are no hard-fast rules regarding cable length. Variables that affect cable length (data reliability) are EMI in the environment, electrical noise in the system/power supply, the communication medium and the data rate. We can more easily control the medium and the data rate, the others are harder to control and measure. I2C tends to be less noise-immune because it lacks a push-pull driver and is higher impedance as a result. SPI and UART are better. When using SPI, Pixy acts as a slave, so your microcontroller will be supplying the clock and you’ll determine the data rate.

I would make the cable the length that you want and see if it works. You can use the checksums on the protocol to determine if you are getting bitstream errors. If you are getting too many errors, try lowering the data rate.

Hope this helps!

Edward

thanks, can you tell me please how to poll a checksum error in the following example code?

@sprintf(buf, “Detected %d:\n”, blocks);
Serial.print(buf);
for (j=0; j<blocks; j++) {
sprintf(buf, " block %d: ", j);
Serial.print(buf);
signature = pixy.blocks[j].signature; //get object’s signature
int x = pixy.blocks[j].x; //get x position
int y = pixy.blocks[j].y; //get y position
int width = pixy.blocks[j].width; //get width
int height = pixy.blocks[j].height; //get height
int angle = pixy.blocks[j].angle; //get height
pixy.blocks[j].print();
}
@

so how to poll the checksum error?

no information available?

why is here no support about checksums?
ok, I’ll open a new topic now. Hopefully there will be a better support then.

Hello,
The checksum code is currently in the Pixy Arduino library. See line 225:

For now, an error is just printed to the serial console. It’s not returned as an error code, although it probably should be (this would be easy to add/change). For your testing, you can just look at the console for the cs errors.

Hope this helps

Edward

I don’t understand:
in line 225 I don’t see how to calculate or retrieve the checksum.
@Serial.println(“cs error”);
w = link.getWord();
if (w==PIXY_START_WORD)
blockType = NORMAL_BLOCK;
else if (w==PIXY_START_WORD_CC)
blockType = CC_BLOCK;
else
return blockCount;
@
but:

  • what is “link” ?
  • what is “link.getword()?” ?
  • what is w==PIXY_START_WORD?
  • what is blockType = NORMAL_BLOCK ?
  • what is (w==PIXY_START_WORD_CC) ?
  • what is blockType = CC_BLOCK ?
  • what does this snippet do at all ?
  • why does it return blockCount ?
  • what does it return at all?
  • what does all this coding mean for sort of “checksum” ???

can’t you please just provide a working code for a function, e.g.

bool checksum_OK()

which returns if a checksum is/was valid?

Hey, you’re missing it. Edward pointed to line 225, but you’re reading the lines below that. Line 225 is where the checksum error gets returned. The code handles it automatically. You don’t have to do anything else. Just look for “cs error” in the console. If that shows up, you have a checksum error.

Jesse

The conditional statement actually starts on line 222:

@ if (checksum==sum)
blockCount++;
else
Serial.println(“cs error”);@

That’s the logic that tests for error.

I don’t need letters in a console, I need the data in my program, to count and evaluate the checksum errors over time.
So I need I C(++) function to detect them and to count them, something like e.g.

bool checksum_OK()

OK…the snippet I posted above is easily modifiable, just edit your TPixy.h file in the Pixy Arduino library on your local machine, and add the code you want. Creating a variable and assigning it a value is dead simple.

I’m starting to get frustrated helping you. You seem impatient, full of blame, and unwilling to take responsibility for doing the work on your end to get the functionality you’re specifically looking for. I understand it can be frustrating, but please be patient and put in the effort to get where you’re trying to go.

Thanks,
Jesse

I thought you sounded familiar, Helmut. :slight_smile: