picandies
Posts: 192
Joined: Wed Nov 26, 2014 5:13 pm

Best way to commonly setup io

Sat Oct 20, 2018 4:01 pm

Hello: I have several classes for different sensors (pressure, rpm, adc, etc)...each of these use several I/O lines, some of them are somewhat shared (ex: ser data line is used everywhere & one switch line is read both pressure & current monitor activity). Some classes are in a different file & imported before use. So the serial data line needs to be defined & usable by the various classes & the switch line by a few of the classes. Everything works "fine" , each class is setting up its own I/o as though the others don't even exist at all...but not sure if that is the proper way to do it with the shared pins. I get the old "this pin is already in use warnings". Seems like ALL of the I/o's should be set up ONCE, in ONE place somewhere, then used as needed in different classes. Maybe this is an improper thought. I'd think it would be a problem for one pin to be brute force defined independently 2 different classes at the same time (though it seems to be working). Not sure how to set things so each I/O is only configured once. Is this some sort of a "class inheriting a class" problem?
Last edited by picandies on Sun Oct 21, 2018 2:54 am, edited 1 time in total.

scotty101
Posts: 3674
Joined: Fri Jun 08, 2012 6:03 pm

Re: Best way to commonly setup io

Sat Oct 20, 2018 11:59 pm

Share some real code rather than jibberish.
Electronic and Computer Engineer
Pi Interests: Home Automation, IOT, Python and Tkinter

picandies
Posts: 192
Joined: Wed Nov 26, 2014 5:13 pm

Re: Best way to commonly setup io

Sun Oct 21, 2018 3:01 am

I got rid of the sample arrangement, since it was likely wrong.

What is the proper setup of the classes to use the I/O s defined such that each of the different sensor classes can use them? Some sensors will be using the same io lines. Ser clk & data will be used by almost everybody. Other lines might signal one (or more) sensors that it is time to take a reading, resync, etc.

scotty101
Posts: 3674
Joined: Fri Jun 08, 2012 6:03 pm

Re: Best way to commonly setup io

Mon Oct 22, 2018 8:47 am

It is impossible to tell you given that you haven't shared any detailed information about the type of sensors you are using.
Ser clk & data will be used by almost everybody
This seems to suggest that you will be using a sensor that connects via the SPI port. In this case, you don't mess around with the GPIO config for these pins, you use the SPI device support provided by linux and the spidev module within python.

If other devices are sharing pins, and it isn't via a defined protocol like SPI or I2C, you may have problems.

But until you share some code or information about the sensors, it is impossible to give you any real advice.
Electronic and Computer Engineer
Pi Interests: Home Automation, IOT, Python and Tkinter

Return to “General discussion”