soend
Posts: 9
Joined: Sun Jun 17, 2012 7:23 pm

Raspberry Pi to Arduino -> i2c or serial

Wed Oct 24, 2012 1:50 pm

Im making a little project where i need to communicate with arduino board and need to decide what im going to use for it. What are benefits for one and another?

I actually have serial connection working between two of them and with baudrate 9600 i measured that for doing one "transaction" between 2 boards takes ~1 second (Sending 18 bytes to arduino and receiving 18 back form it). And this made me think if using i2c would be faster (or even SPI?). In my case i would like the "transaction" to take less than second (half a second would be perfect).

User avatar
joan
Posts: 14482
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: Raspberry Pi to Arduino -> i2c or serial

Wed Oct 24, 2012 3:32 pm

An an interim measure why not change the serial baud rate? They both support 115200 which is 12 times faster.

User avatar
[email protected]
Posts: 2020
Joined: Tue Feb 07, 2012 2:14 pm
Location: Devon, UK
Contact: Website

Re: Raspberry Pi to Arduino -> i2c or serial

Wed Oct 24, 2012 3:35 pm

soend wrote:Im making a little project where i need to communicate with arduino board and need to decide what im going to use for it. What are benefits for one and another?

I actually have serial connection working between two of them and with baudrate 9600 i measured that for doing one "transaction" between 2 boards takes ~1 second (Sending 18 bytes to arduino and receiving 18 back form it). And this made me think if using i2c would be faster (or even SPI?). In my case i would like the "transaction" to take less than second (half a second would be perfect).
I've been communicating to Arduinos/ATmegas via both the on-board serial and USB at 115200 baud.

If your transaction is taking that long to exchange 18 bytes then there is something very wrong. 9600 baud is approximately 1000 characters/sec. so I'd look to see where your delays are before blaming the transport technology you're using.

E.g. this setup which I did waaay back:

Image

has a BASIC program running in the Pi talking via usb serial to an arduino running a very simple remote control program and it's updating the display based on the little potentiometer on the arduino, outputting LEDs and reading the switches - and the cycle time in the BASIC program is over 100 cycles/sec...

-Gordon
--
Gordons projects: https://projects.drogon.net/

soend
Posts: 9
Joined: Sun Jun 17, 2012 7:23 pm

Re: Raspberry Pi to Arduino -> i2c or serial

Wed Oct 24, 2012 6:56 pm

If i increase the baudrate then i start getting back some random bytes what doesnt look like the data at all.

Im using RX and TX pins from GPIO header not the USB virtual serial.

Levaillant
Posts: 18
Joined: Wed Sep 26, 2012 7:10 am
Location: France, Paris

Re: Raspberry Pi to Arduino -> i2c or serial

Wed Oct 24, 2012 7:06 pm

Hi,
Simply implements a small CRC control so... no?
Cheers

User avatar
joan
Posts: 14482
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: Raspberry Pi to Arduino -> i2c or serial

Wed Oct 24, 2012 7:56 pm

soend wrote:If i increase the baudrate then i start getting back some random bytes what doesnt look like the data at all.

Im using RX and TX pins from GPIO header not the USB virtual serial.
Perhaps you haven't connected the Pi and Arduino ground pins, or the connection is loose?

soend
Posts: 9
Joined: Sun Jun 17, 2012 7:23 pm

Re: Raspberry Pi to Arduino -> i2c or serial

Wed Oct 24, 2012 8:01 pm

Oh, all this made me think and i started debugging where this delay comes from. So what i found is that getting temperature from DS18b20 sensor is the bottleneck.

Return to “Automation, sensing and robotics”