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