Pi + arduino + sensors

In a remote building I have a raspberry pi set up with, sometimes battery, sometimes AC, logging data, along, but anyway those details are not important. What I want to do is add some analog sensors via arduimo.

I hooked all my sensors up to my arduino, and boom, works great. I can flash LEDs or write values to serial and I am happy with those results so far. But now, how do I get that data to the pi? It sounds like either serial over USB or i2c would both work well. I want data about once every ten minutes. In the pure software world, I would initiate a connection from the data source to host, send data, disconnect and be happy.

Can I achieve this sort of "interrupt" behavior using my pi+duino or do I need to have the pi polling for data? Does my choice between serial or i2c make any difference or is that part simply a transport detail? How would an expert accomplish the task of shipping a few integers duino->pi once every few minutes?

Thanks!

I would connect it through USB and have the Pi pole the serial input.

Using I2C is a bit tricky because the two boards work off different voltages so you would need some logic level shifting between the two.

Edit. I might be considered an expert as I have written two books about the Raspberry Pi.

I’m not an expert, but this is how I’d do it.

  1. I’d use a pro mini, or similar 3.3v Arduino board.

  2. I would connect directly to the GPIO, using the serial pins: http://lavalink.com/2012/03/raspberry-pi-serial-interfacing/

RaspberryPi —> Arduino

RX - D1
TX - D0
GND - GND
(I think you will need a separate power source for the Arduino. Check max ratings and do the math)
(I confuse RX and TX sometimes. double-check this.)

  1. I would set the Arduino up to wait for commands (Basically treat it as a slave). If the software on your raspberry pi needs a new value, it sends out a message through the serial port to the Arduino, and the Arduino responds by sending back the requested value.

EDIT: Yep - Grumpy Mike is the expert. My post was not intended to suggest that his solution is not easy/fast/smart/good. Just offering up a method I find more interesting.

Grumpy_Mike:
Edit. I might be considered an expert as I have written two books about the Raspberry Pi.

I am just starting out with the Pi. Which books are these? I know this is kinda out of scope for this forum, but you can scold me later.

and

Thanks, Mike! Are you Grumpy_Mike on the Pi forum also?

SurferTim:
Are you Grumpy_Mike on the Pi forum also?

Yes :slight_smile:
But I don't go on much.

Grumpy_Mike:
I would connect it through USB and have the Pi pole the serial input.

Using I2C is a bit tricky because the two boards work off different voltages so you would need some logic level shifting between the two.

Edit. I might be considered an expert as I have written two books about the Raspberry Pi.

Thanks! The 5v vs 3.3v bit struck me as an issue for i2c. However this fellow claims that due to pullup arrangement, it works fine -

Is that bum advice or simply not best practice?

He is wrong when he says:-

The reason it works is because the Arduino does not have any pull-ups resistors installed, but the P1 header on the Raspberry Pi has 1k8 ohms resistors to the 3.3 volts power rail.

Some versions of the Arduino do have external pull up resistors and even the ones that don't have the external pull up enabled by the driver software, that includes the standard driver.
You can either hack the driver or get a driver that allows you to disable the internal pull ups.
However the other problem is that only pulling up to 3V3 is not enough to meet the minimum logic one voltage levels on an Arduino. It might work but driving things outside the spec is always a silly thing to do.

Is that bum advice or simply not best practice?

Given the above what would you call it?

Grumpy_Mike:
He is wrong when he says:-

The reason it works is because the Arduino does not have any pull-ups resistors installed, but the P1 header on the Raspberry Pi has 1k8 ohms resistors to the 3.3 volts power rail.

Some versions of the Arduino do have external pull up resistors and even the ones that don't have the external pull up enabled by the driver software, that includes the standard driver.
You can either hack the driver or get a driver that allows you to disable the internal pull ups.
However the other problem is that only pulling up to 3V3 is not enough to meet the minimum logic one voltage levels on an Arduino. It might work but driving things outside the spec is always a silly thing to do.

Is that bum advice or simply not best practice?

Given the above what would you call it?

Apologies for the total newb status over here, and thanks for the explanation. Given your explanation I agree with you and will not be crossing voltages in i2c.

Apologies for the total newb status over here,

Absolutely no need to apologies that is what we are here for.
Any more questions feel free to ask.