Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Driving an RPi GPIO input from the output of an opto isolator

Status
Not open for further replies.

njminchin

New Member
I have essentially two controllers, an RPi, another 5V-based controller (a Hunter Hydrawise irrigation controller), and a flow sensor that I want to connect to both controllers. For this I thought I'd use an opto-isolator/coupler.

I want to connect the flowmeter to the 5V controller using the circuit below. I just don't know how to connect the output side of the opto-coupler to the RPi GPIO input.

Can I use what I've got here or am I missing some components? (resistors/transistor)


1650098682384.png


Any help would be great, thanks!
 

Attachments

  • 1650098493820.png
    1650098493820.png
    18.6 KB · Views: 177
I'd tend to swap the photo-transistor and 10K on the GPIO pin over, so you're switching rather than using it in a linear fashion, rather like the input side.

This will invert the logic, but you simply alter the code accordingly.

I've recently done something similar with software SPI, as the processor runs at 3.3V and the MAX7219 really wants 5V, and didn't work reliably at 3.3V. So I altered all the references to 0 and 1, and defined names for them:

C:
#define SPIINV                                  // SPI inverted for 2n7000 SPI drivers

#ifdef SPIINV
    //inverted SPI for 2N7000 level shifters
    #define SPIHIGH 0;
    #define SPILOW 1;
#else
    //non-inverted SPI for no level shifters
    #define SPIHIGH 1;
    #define SPILOW 0;
#endif

If you do something similar, you can easily change the logic by commenting out the #define.

As a matter of interest, the inverted SPI works fine, and seems to have cured the occasional reliability problem.
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top