rups22
Posts: 22
Joined: Thu Oct 24, 2019 3:22 pm

Arduino GPIO Output to Raspberry Pi Input

Mon Aug 03, 2020 12:49 pm

Hi all

I'm using a Wemos D1 mini and a HC-SR04 Ultrasonic sensor to detect object proximity.
The Wemos outputs HIGH or LOW to a digital pin if the object is within or out of range

I need to take this output (3.3v) from the Wemos and use it as an input on the Rasberry GPIO

I have found a 6N138 optocoupler that I believe is adequate
https://www.onsemi.com/pub/Collateral/HCPL2731-D.PDF


From my calculations, the emitter operates at 1.3v @ 1.6mA

3.3v-1.3v=2v

2/0.0016=1250 Ohm

I have used this to obtain a resistor value of 1.5K

I would also like the raspberry pi input to be pulled down to ground to avoid floating values.


Have I calculated correctly and is my schematic correct?
Optocoupler.png
Optocoupler.png (118.02 KiB) Viewed 422 times

Many thanks

LTolledo
Posts: 3585
Joined: Sat Mar 17, 2018 7:29 am
Location: Anime Heartland

Re: Arduino GPIO Output to Raspberry Pi Input

Mon Aug 03, 2020 1:24 pm

why do you need WeMos in the circuit?

can't you connect the ultrasonic sensor directly to the optocoupler?
"Don't come to me with 'issues' for I don't know how to deal with those
Come to me with 'problems' and I'll help you find solutions"

Some people be like:
"Help me! Am drowning! But dont you dare touch me nor come near me!"

rups22
Posts: 22
Joined: Thu Oct 24, 2019 3:22 pm

Re: Arduino GPIO Output to Raspberry Pi Input

Mon Aug 03, 2020 1:28 pm

LTolledo wrote:
Mon Aug 03, 2020 1:24 pm
why do you need WeMos in the circuit?

can't you connect the ultrasonic sensor directly to the optocoupler?
I am building a remotely operated gate opener.

I am using redundancy in most parts of the build. Both the Wemos and Raspberry will be able to turn on the relays remotely and I need the Ultrasonic sensor information on both devices to prevent the gate closing if an object is in the way.

drgeoff
Posts: 10831
Joined: Wed Jan 25, 2012 6:39 pm

Re: Arduino GPIO Output to Raspberry Pi Input

Mon Aug 03, 2020 1:29 pm

Why do you need the optocoupler? Two resistors will interface a 5 volt logic signal to a RPi input.
Quis custodiet ipsos custodes?

rups22
Posts: 22
Joined: Thu Oct 24, 2019 3:22 pm

Re: Arduino GPIO Output to Raspberry Pi Input

Mon Aug 03, 2020 1:33 pm

drgeoff wrote:
Mon Aug 03, 2020 1:29 pm
Why do you need the optocoupler? Two resistors will interface a 5 volt logic signal to a RPi input.
The wemos output is 3.3v and I was concerned that using a resistor might drop the voltage too much for the raspberry to detect a state change.

If I can simplify the circuit and I don't need the protection offered by the optocoupler then I would like to know more

pcmanbob
Posts: 9612
Joined: Fri May 31, 2013 9:28 pm
Location: Mansfield UK

Re: Arduino GPIO Output to Raspberry Pi Input

Mon Aug 03, 2020 2:50 pm

If the wemos output is 3.3v you could connect that directly to a pi gpio pin ,

You might use a 1K resistor if you want some protection in the event you accidentally set the pi gpio pin to output and low.
We want information… information… information........................no information no help
The use of crystal balls & mind reading are not supported

rups22
Posts: 22
Joined: Thu Oct 24, 2019 3:22 pm

Re: Arduino GPIO Output to Raspberry Pi Input

Mon Aug 03, 2020 2:53 pm

pcmanbob wrote:
Mon Aug 03, 2020 2:50 pm
If the wemos output is 3.3v you could connect that directly to a pi gpio pin ,

You might use a 1K resistor if you want some protection in the event you accidentally set the pi gpio pin to output and low.
hippy wrote:
Mon Aug 03, 2020 2:08 pm
You should be able to take your Wemos 3V3 output via an in-line 1K resistor straight to a Pi's GPIO input pin with no problems. Connect the Wemos 0V (GND) to the PI's 0V (GND).
Will try this, Should I add another resistor to pull the input pin to ground as well? If so what value?

pcmanbob
Posts: 9612
Joined: Fri May 31, 2013 9:28 pm
Location: Mansfield UK

Re: Arduino GPIO Output to Raspberry Pi Input

Mon Aug 03, 2020 3:02 pm

If the wemos output is going from low 0V to high 3.3V you should not need any pull up/down as the wemos is providing it.
We want information… information… information........................no information no help
The use of crystal balls & mind reading are not supported

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

Re: Arduino GPIO Output to Raspberry Pi Input

Mon Aug 03, 2020 3:22 pm

If you connect directly you also need to add a ground connection between Pi and wemos.

hippy
Posts: 7908
Joined: Fri Sep 09, 2011 10:34 pm
Location: UK

Re: Arduino GPIO Output to Raspberry Pi Input

Mon Aug 03, 2020 4:57 pm

rups22 wrote:
Mon Aug 03, 2020 2:53 pm
hippy wrote:
Mon Aug 03, 2020 2:08 pm
You should be able to take your Wemos 3V3 output via an in-line 1K resistor straight to a Pi's GPIO input pin with no problems. Connect the Wemos 0V (GND) to the PI's 0V (GND).
Will try this, Should I add another resistor to pull the input pin to ground as well? If so what value?
Ah; you spotted that before I deleted it. I deleted it because, with a re-reading, I wasn't confident that was absolutely safe for how your system is. Being seemingly outside there might be induced spikes and whatnots on the signal which would make opto-coupling a safer thing to do.

emma1997
Posts: 868
Joined: Sun Nov 08, 2015 7:00 pm
Location: New England (not that old one)

Re: Arduino GPIO Output to Raspberry Pi Input

Mon Aug 03, 2020 5:42 pm

pcmanbob wrote:
Mon Aug 03, 2020 2:50 pm
If the wemos output is 3.3v you could connect that directly to a pi gpio pin ,
My how times have changed. The 'old' pcmanbob would never have suggested using only components needed for the job: "that will destroy your Pi instantly!". If only we could get back to those old days . lol

Even projects that do use 5v like Arduino can usually be solved with simple divider. But I suppose adding optos, relays, level-shifter ICs, etc, even if unnecessary, do teach how these things work so not totally pointless.

BTW running Arduino off 3.3v is a much simpler solution and works fine at least for hobby projects.

PS You know I'm joking Bob. We like to kid. I will admit to having picked up more than a couple tips from your replies.

pcmanbob
Posts: 9612
Joined: Fri May 31, 2013 9:28 pm
Location: Mansfield UK

Re: Arduino GPIO Output to Raspberry Pi Input

Mon Aug 03, 2020 10:56 pm

emma1997 wrote:
Mon Aug 03, 2020 5:42 pm
pcmanbob wrote:
Mon Aug 03, 2020 2:50 pm
If the wemos output is 3.3v you could connect that directly to a pi gpio pin ,
My how times have changed. The 'old' pcmanbob would never have suggested using only components needed for the job: "that will destroy your Pi instantly!". If only we could get back to those old days . lol

Even projects that do use 5v like Arduino can usually be solved with simple divider. But I suppose adding optos, relays, level-shifter ICs, etc, even if unnecessary, do teach how these things work so not totally pointless.

BTW running Arduino off 3.3v is a much simpler solution and works fine at least for hobby projects.

PS You know I'm joking Bob. We like to kid. I will admit to having picked up more than a couple tips from your replies.
Had the wemos been running at 5V then yes I would have suggested a potential divider circuit or an opto isolator, but as it's running at 3.3V a single 1K resistor is all that is required for that little bit of protection , if you like to live dangerously then you can leave it out .

Now if I could just add a couple of npn transistors :D just kidding of course. :lol:
We want information… information… information........................no information no help
The use of crystal balls & mind reading are not supported

emma1997
Posts: 868
Joined: Sun Nov 08, 2015 7:00 pm
Location: New England (not that old one)

Re: Arduino GPIO Output to Raspberry Pi Input

Mon Aug 03, 2020 11:26 pm

MOSFET !!! MOSFET !!! lol

I don't argue to much against the 1k series resistor these days after seeing a few burnt LEDs in hardware lab.

"Professor, Professor, is it supposed to light up orange? I thought you said red. Oooops.. now it's off."

Mostly in the case of beginners and prototyping but not so much Pi with it's weaker IO and off the shelf products that are known to be warm and fuzzy. I tend to leave it out but I have thousands of LEDs and spare Pi. Must admit to replacing a few IR LEDs until code bugs were ironed out.

Return to “Automation, sensing and robotics”