could two subsystems (raspberry pi and arduino uno) share pins?

So I'd like to explore options similar to a raspberry pi - I notice one advantage some other dev kits in the space have is like the beaglebone black has analog inputs (a 10-bit adc). The raspberry pi doesn't.

I really, really like the form factor of the raspberry pi zero, which has 40-pin HAT layout that lots of people use unpopulated. (since it has hdmi and usb, which is enough for most people.)

Now, one thing I notice is that the Arduino Uno has 20 pins.

My question is: hypothetically could the same PINs simultaneously be wired to two totally different subsystems, so that if the Raspberry Pi isn't using them, a totally separate subsystem Arduino could!

I mean like this:

https://imgur.com/NhgSmwD

This is just an illustration, ignore the specific pins. I mean to convey that it would be wired to BOTH (the pins are just random ones to illustrate what I mean I could find, it can be any pins), but if one isn't it using it the other could.

Meaning: if the Arduino is using it it could be an analog input that the Raspberry Pi is ignoring (not reading.)

If the Raspberry Pi is ignoring it, the Arduino could be reading it.

Is any part of this possible??

I am really bad at electrical engineering so I can't work out any of this myself. Just curious if it would be possible without ruining both subsystems!

Basically no , without adding an inordinate extra layer to the pi kernel, to somehow arbitrate which CPU has at any time control over the pins. An insanely complicated way to solve a very simple problem, which is to simply add an external ADC to the PI.

Hypothetically, yes, as long as only one device is driving the shared network at any time and the voltage levels are compatible. That said, there is the possibility of inadvertently having multiple drivers simultaneously on the net giving unpredictable results and potentially damaging one or both chips, so there's probably better ways to approach your problem.

really bad at electrical engineering so I can't work out any of this myself. Just curious if it would be possible without ruining both subsystems!

No.

Now, one thing I notice is that the Arduino Uno has 20 pins.

You mean 0 - 13 digital and 0 to 5 analog (13+6) or do you mean the ATmega328 chip ?

My question is: hypothetically could the same PINs simultaneously be wired to two totally different subsystems, so that if the Raspberry Pi isn't using them, a totally separate subsystem Arduino could!

Microprocessor systems have been doing this since their inception using tri-state buses. Your PC has such a bus. There is an address bus, a data bus, a control bus , clock signals, etc. One system is placed in the high impedance Tri-State mode before the data is written to the bus. In addition, the specific devices are address decoded. If you write to a specific address, only the device at that address can respond because the decoding prevents any other device from responding. In short, the answer is yes but it is way over your head.

There is no tristate on the GPIO pins the best you can do is to change the pins to an input. BUT the Arduino is a 5V system and the Pi is. 3V3 system so you can not have an output from the Arduino that does not fry your Pi.

Yes Mike, I know. I actually meant that you would need to add Tri-state traceivers, so technically that makes the answer to the OP's question a NO.

interesting range of answers! What if we didn't mind frying anything if intermediation is done wrong :-D

Since we're only concerned with what happens if one side is for all intents and purposes off (though not disconnected, actually on), can't we at a minimum say:

"The Uno has 6 analog inputs, labeled A0 through A5, each of which provide 10 bits of resolution (i.e. 1024 different values). By default they measure from ground to 5 volts."

The Raspberry Pi has "GPIO voltage levels are 3.3V". So that is within 0 to 5 volts.

At a minimum then, could we say:

-> The Raspberry Pi's 5v pin can go to the Uno's 5V.

-> Ground pins can go to ground pins. Naturally.

-> The six uno analog inputs could go to six of the raspberry pi GPIO pins. This means that measuring only up to 3.3 volts will be safe.

Are the above facts true? Can we go any farther?

So long as you don't configure the Arduino analog pins as outputs, which could fry the Pi.

You'd be better off running the Arduino at 3.3V surely (Pro Mini 8MHz?)

But why not use an MCP3208, or an ADC hat?

I must say the entire concept is quite stupid. It offers no advantage at all. It is just using a common set of physical pins to talk to either the Pi or the Arduino. So in effect it reduces the number of I/O available to the overall system.

Are the above facts true?

Yes - not very pertinent but true.

Can we go any farther?

Only if you want to thoroughly waste your time and ruin two systems.

@MarkT

So long as you don't configure the Arduino analog pins as outputs, which could fry the Pi.

You'd be better off running the Arduino at 3.3V surely (Pro Mini 8MHz?)

If the arduino runs at 3.3 volts (like the Raspberry Pi pins) then have we eliminated this issue? Also, when the Raspberry Pi, or the Arduino, isn't reading or using the respective pins are they leaving them totally alone? (Not changing its electrical nature, not influencing readings). Could the GPIO pins "not mind" any 3.3 volt fluctuation, as long as they aren't actually reading that pin at the moment?

@ Grumpy_Mike

I must say the entire concept is quite stupid. It offers no advantage at all. It is just using a common set of physical pins to talk to either the Pi or the Arduino. So in effect it reduces the number of I/O available to the overall system.

By that standard a USB offers no advantages over a parallel port and serial port, since it reduces to 4 pins what could be better served by 25 PINs parallel printer port and 9-pin serial port. :-D

You might be right that it offers no advantages - unless for some reason it does :) :) You never know...

Can we go any farther?

Only if you want to thoroughly waste your time and ruin two systems.

Yes, I'd like to "thoroughly waste my time" and see if by adding a few cents to the board you can build two subsystems. So, how can we go further down this rabit-hole?

Questions:

1) What's the cheapest Arduino-compatible microcontroller that can run at 3.3 volts?

2) Are there any pins that would NOT be suitable to be wired to one of the GPIO, Ground, 3.3, or other pins on the Raspberry Pi?

3) Would the fact that it's running at 3.3 volts in fact ensure that there is no possibility of frying either system?

4) Is there any effect to having pins connected this way, if they are NOT being read by the respective subsystem, but they are in fact connected? By "any effect" I mean, would an analog input from an arduino read the same if it's connected to GPIO that is NOT being used by the Pi, as if it were separated and standalone? If A is the pi not reading or using the GPIO pin and B is the arduino reading the pin then will B read the same with A [.joined.] B as with under A . ] separated [. B ? Again, assuming the pi isn't actually using that pin at the moment - will it still affect the reading just by virtue of being connected to it and under power?

5) Separately, if both were using the PIN - would this make it possible to directly communicate between the Pi and Arduino (for example between a GPIO and an Analog pin), in addition to another (saner) way for them to communicate, such as over USB?

The usage case I envision is:

Primary usage case: a person does not use any Raspberry Pi pins whatsoever, leaves them totally unpopulated. These are just empty pins. They would like to use a single on-board analog sensor from the built-in tiny little arduino, so they reuse one of the PINs it's connected to.

Secondary usage case:a person does not use any arduino pins whatsoever. it's just a $5 computer to them. They do use a Raspberry Pi Hat to do something else.

Tertiary usage case: they want a real arduino, not one with a couple of pins attached to an irrelevant subsystem. So they use a Raspberry Pi HAT to add a real, full arduino. The onboard arduino is left totally unused.

So what do you guys think? Is this theoretically possible?

Thanks for any thoughts. I realize it's a pretty out-there idea, but whatever. It's like $1 on top of $5.

You might be right that it offers no advantages - unless for some reason it does :) :) You never know...

Yes I do. I have written three Raspberry Pi books. I have a regular column in the MagPi magazine and I have been "doing" electronics for 50 years. So I am very used to evaluating possible systems.

Yes, I'd like to "thoroughly waste my time"

That is fine, it is your time after all. Only I will duck out on this one.

Good luck.

You might be right that it offers no advantages - unless for some reason it does :slight_smile: :slight_smile: You never know…

Yes I do. I have written three Raspberry Pi books. I have a regular column in the MagPi magazine and I have been “doing” electronics for 50 years. So I am very used to evaluating possible systems.

I was curious what you had in mind, but after reading your post three times, I couldn’t find a lot of details. You say you have been used to evaluate possible systems. I’m curious about your perspective regarding why no version of the Pi includes an arduino-like microcontroller. As you’re on the Arduino forum, I think it should be obvious to you that there are loads of applications for which an Arduino is appropriate.

For many of these, no special work by a Pi or any other computer is needed. On the other hand, I think it would be tricky to send a tweet from an arduino without involving a computer, don’t you? :slight_smile:

If you wanted your Arduino to send you an SMS from your cow if an analog sensor showed that it was still out to pasture based on GPS, but that the ambient temperature were below 0 degrees celsius, how would you do it?

With the above setup I would do it by getting a GPS device and an SMS device that both work over USB and a raspberry pi. Then I would put the analog temperature sensor on the analog pin and run only the Arduino side with the raspberry side off. I would run the arduino side in low-power mode, waking twice per hour to quickly read the analog temperature sensor.

If it were below (Cutoff) degrees Celsius I would wake the pi to check the GPS coordinates and to send an SMS with a python script, which it would do every time it booted. (Alternatively, it could also do this every night - you could do it till the cows come home :smiley: :smiley: :-D.)

Here is a preliminary estimate:

  1. Figure out a 3G Internet connection. The top Google hit starts : “Setting up a USB 3G/4G modem on a Raspberry Pi is not a simple task” – But there is a clear How-To Guide! You can follow it in a few minutes since it’s 5 very clearly described steps.

  2. Figure out an Internet to SMS portal. This takes seconds once you’re connected to the Internet.

  3. Figure out how to get GPS coordinates from a device over USB. After looking around it should cost <$30

  4. A temperature sensor on the Arduino side costs $1.50 - It also comes with extremely clear instructions. - An analog temperature sensor costs $1.50 as marked up on Adafruit.

There is no need to use any pin between the Arduino and Pi side assuming that some serial connection is established (it could also be over USB.)

  1. A battery pack with 4 AA batteries should run for a year. a single AA batteries could run a microcontroller for approximately 1 year: How to run an Arduino (clone) on (AA) batteries for over a year – Part 2 | Hardware Startup – Assuming that there is no reason to wake the pi up, since the temperature sensor never gets too low, and only very infrequently waking the microcontroller up, keeping it in sleep mode otherwise.

Every single step above is very clearly described in tutorials. Including assembling all this and writing scripts it would take less than 3 hours. It could even include sending a test SMS once per month with the temperature log. A cow is worth $1000. You do the math as to how crazy of an idea it is.

What way is there to leave the Raspberry Pi out of it and get easy GPS directions 3G connectivity from an arduino?

Project costs:

  1. Arduino / Embedded Linux dual solution - currently raspberry pi zero is $5 - add $1.50 to add microcontroller = $6.50

  2. Temperature sensor (arduino side - pi’s pins left unpopulated): $1.50

  3. USB hub: $2.50

  4. GPS over USB - $11.50 – originally saw like $20 (quick searhc) - http://goo.gl/t0eqhn – but for a cost-sensitive qty 1x I decided to look at http://goo.gl/DOjWek (ebay) which is in new condition, explicitly mentions Linux, stating, “The only problem I encountered was that the drivers were out of date, but the included manual on the installation CD gives the Web site to the company where one can download the newest drivers for Windows, Mac, and Linux, as well as and an updated Satellite checker, for the unit.” so that I would expect it to work. Googling “GlobalSat BU-353 linux” gives extremely explicit instructions including “BU-353 with Linux OS - USGlobalSat” and “[SOLVED] globalsat bu-353 gps device need some setup assistance …”

  5. 3G over USB - like $8 (quick search) - http://goo.gl/SK19Zv - this stuff seems standard as well.

  6. SMS service - like $1 in credit, the script could also send an email at the same time (free) in case the service is disrupted for some reason.

  7. prepaid 3G sim card - like $5

8 ) 4 AA batteries. $2.5

  1. case: $1.

Total:

$6.50 + $1.50 + $2.50 + $11.50 + $8 + $1 + $5 + $2.50 + $1

= $39.5 US plus postage, but you can save on this if you have a prepaid sim card or any of your own AA batteries :slight_smile:

Work estimate:

  1. Setting up the computer: 15 seconds.

  2. Connecting the temperature chip to an analog pin: 45 seconds.

  3. Connecting the USB hub: 7 seconds.

  4. Connecting batteries to battery case: 28 seconds.

  5. Connecting battery case to power port: 15 seconds.

  6. Downloading a Linux installation, flashing new micro SD-drive: 10 minutes.

  7. Booting and configuring Linux for first time. 1 minute

  8. Adding 3G module following exact stepsoutlined in link above: 3 minutes following exact online instructions exactly.

  9. Checking Ping works when connected: 15 seconds.

  10. Connecting GPS device following exact and available-in-multiple-sources online instructions: 45 seconds.

  11. Figuring out an SMS gateway and its API → 30 minutes.

  12. Figuring out when you actually want to send an email, what information to include → 20 minutes

  13. Figuring out how to wake the Pi from the Arduino side → Depends on how easy we make it. Maybe 7 seconds of Googling. Maybe 3 weeks of cursing. Who knows! (Just kidding: 7 seconds following a tutorial.)

  14. Setting the arduino sketch to wake from low-power mode every hour, check the sensor, and wake the pi if it’s under a certain value (too cold) or if it’s report-sending time (once per month). If neither too cold nor report-time, then log to file: 1 hour. Alternatively, it could do this every night. (Reducing battery life though.)

  15. Setting the pi to run the Python script to:

→ On boot wait for GPS, Arduino serial input showing temperature, and 3G modem to all be online. Assuming code reuse from other projects: 1 minute of code adaptation.

→ Attempt to connect to 3G modem and run ping. If successful proceed, otherwise retry. 1 minute of code reuse.

→ Attempt to read GPS value. 3 minutes.

→ Determine if GPS value is In Pasture or Come Home based on programmed application of Point in Polygon: https://goo.gl/RlnPaf — well, well, well. Wouldn’t you know it, the hardest part of this whole thing is figuring out whether the GPS coordinate is inside or out. 40 minutes.

→ Send GPS coordinate and temperature via Email (SMTP) and via SMS API. 40 minutes.

→ Exit script, tell Arduino it is done and can be shut down. 20 seconds

  1. weatherproof the whole thing and test. (1 hour but only if you’re starting out but we don’t need that long.) Now you’re all set for a year and will get regular reports monthly. 12 minutes.

Time adding up all of the above:
15 sec + 45 sec + 7 sec + 28 sec + 15 sec + 10 min+ 1 min + 3 min + 15 sec + 45 sec + 30 min + 20 min + 7 sec + 1 hr + 1 min + 1 min + 3 min + 40 min + 40 min + 20 sec + 12 min = 224.28 min = 3.75 hr.

So this project takes 3.75 hours and $39. Value of your grass-fed pasture cow sending you an SMS if anytime in the next year they’re cold and still out to pasture, and getting an automated email once a month shows temperature logs and that the SMS and email links are still working: priceless.

Now walk me through exactly how you would do the above on an arduino alone. Sure you COULD. But microcontroller programming is much trickier than assembling USB devices and writing a script… (if someone knows how to program). There’s no way you get the level of easy tutorial I just showed. We’re talking start at 2:15 PM and by 6 PM you’re done with the whole project, have 4 AA batteries out there, and don’t need to do anything (including change batteries) for a whole year except make sure you’re getting the automated reports once per month.

Of course, I could always be wrong!!!

:smiley: :smiley: :smiley: :smiley: :smiley:

Can’t you plug the Arduino into the Raspberry Pi via USB and communicate Serially? (Check out a guide I made here: http://www.instructables.com/id/Connect-Your-Raspberry-Pi-and-Arduino-Uno/ )

Or, couldn’t you scrap the Raspberry Pi and use an Arduino MKR with the Blynk app? You could receive email/phone notifications, AND keep track of temperature history with a graph.

@chummer1010

Can't you plug the Arduino into the Raspberry Pi via USB and communicate Serially? (Check out a guide I made here: http://www.instructables.com/id/Connect-Your-Raspberry-Pi-and-Arduino-Uno/ )

Yes of course. This is a very common way to interface with an Arduino. However, it still requires set-up as well as somehow mounting these things to something. I was thinking this connection could be built-in as two subsystems that don't need user putting-them-together. Right now a Raspberry Pi Zero costs $5. The cheapest Arduino-compatible microcontroller seems to be the Attiny85 (requiring a special version of the arduino IDE.) The page I just linked lists 4 Arduino boards based on that. If I read this right this adds a component cost of just $0.78 cents if someone were buying just 1000 of them. I think by bumping from $5 to $6.50 (almost double the 78 cent margin) it should be possible to include an arduino-compatible, microcontroller and no other components except traces and even reusing the pins. But I'm not an expert :-D I'd like to hear what others think about this. Why or why not?

@chummer1010, your other observation was:

Or, couldn't you scrap the Raspberry Pi and use an Arduino MKR with the Blynk app? You could receive email/phone notifications, AND keep track of temperature history with a graph.

How would you get connectivity from a cow in a rainy large rainy field? My suggested $39 + 3 hours systems-level solution if someone made that $5 + Arduino dual system chip includes a complete 3G modem over USB as well as GPS over USB.

How would you do all that from an arduino without massive amounts of work? From the Linux side it's just a few lines.

You are completely right in the first part of your post that this can already be done today by just combining Linux with Arduino. But why not have the arduino (an open design) on the Linux board to begin with, cutting out that extra work?

It doesn't make sense to me. I also haven't received detailed technical feedback on my PIN-sharing quesitons :) :) :)

Of course, I'm a complete beginner and just asking out of curiosity. I like to think big, which sometimes gets me in trouble. :-D

curious48: If you wanted your Arduino to send you an SMS from your cow if an analog sensor showed that it was still out to pasture based on GPS, but that the ambient temperature were below 0 degrees celsius, how would you do it?

With the above setup I would do it by getting a GPS device and an SMS device that both work over USB and a raspberry pi. Then I would put the analog temperature sensor on the analog pin and run only the Arduino side with the raspberry side off. I would run the arduino side in low-power mode, waking twice per hour to quickly read the analog temperature sensor.

..........

Of course, I could always be wrong!!!

:D :D :D :D :D

but you could do it using only an arduino + gps device + gsm shield + sensors you need .

So how have farmers managed to get by all these years without your "cow monitor" ?

So how have farmers managed to get by all these years without your "cow monitor" ?

The same way raspberry pi users have managed to get by all these years without an Arduino subsystem :-D

seriously though, they did it like this: http://www.trackit.co.nz/product/Farm_Management.aspx

while paying so much that you have to call for a price quote, you won't find it online. (Or at least I didn't.) Anyway before we talk about whether including an Arduino subsystem on the same pins is useful, I hope I can find out whether it's possible :-D I'm simply just curious.

Anyway I still haven't had these questions answered:

1) What's the cheapest Arduino-compatible microcontroller that can run at 3.3 volts?

2) Are there any pins that would NOT be suitable to be wired to one of the GPIO, Ground, 3.3, or other pins on the Raspberry Pi?

3) Would the fact that it's running at 3.3 volts in fact ensure that there is no possibility of frying either system?

4) Is there any effect to having pins connected this way, if they are NOT being read by the respective subsystem, but they are in fact connected? By "any effect" I mean, would an analog input from an arduino read the same if it's connected to GPIO that is NOT being used by the Pi, as if it were separated and standalone? If A is the pi not reading or using the GPIO pin and B is the arduino reading the pin then will B read the same with A [.joined.] B as with under A . ] separated [. B ? Again, assuming the pi isn't actually using that pin at the moment - will it still affect the reading just by virtue of being connected to it and under power?

5) Separately, if both were using the PIN - would this make it possible to directly communicate between the Pi and Arduino (for example between a GPIO and an Analog pin), in addition to another (saner) way for them to communicate, such as over USB?

1) Pro Mini 3.3 V - Atmega328

2) Generally one designs what one wants rather than comprehensively ruling out the infinite variety of things that don't solve one's problem.

3) No, the voltage level doesn't prevent the possibility of two outputs actively driving the net simultaneously.

4) There may be a small effect from additional loading. Whether this matters depends on what is sourcing the signal. A low impedance source won't be significantly affected.

5) Yes

@MrMark - thank you for your extremely useful answers! Appreciate it. :)