I have about 8-9 gas sensors I want to use on my Pi but I'm trying to understand how to use The TCA9548A. The TCA9548A Has 8 pairs of SDL and SCL pins to handle multiple I2C devices, but the output from the MQ gas sensors is one line AO for Analog out or DO for Digital out. How would I go about using 8 to 9 gas sensors on a single Pi with the TCA9548A?
-
Your gas sensor does not have an I2C interface. Therefore, the TCA9548A will not (by itself) lead to a reasonable solution. Suggest you think this through, and edit your question: either delete it, or explain how you intend to get from a one-wire analog or binary output to an I2C channel. To be clear, there are other techniques available for interfacing your gas sensors to an RPi; for example a Multiplexed A/D Converter. Is this what you meant?– SeamusJan 25 at 0:49
-
Sorry I'm still learning when it comes to multiplex stuff. How would you solve this or how do you suggest I wire 8 to 9 gas sensors? For example, I tried wiring 3 PCF8591 to the TCA9548A multiplexer but I was not able to get that to work. I'm thinking there might be an easier/better way to do this? (here is my old post for my first attempt raspberrypi.stackexchange.com/questions/124766/…)– KatianieJan 25 at 1:17
-
Ok I think I might understand, what if I just used something like this? tindie.com/products/cburgess129/… it would have 12 channels (I just need 9 for the gas)– KatianieJan 25 at 3:26
-
Can you read ONE sensor? If so include details in your question.– MilliwaysJan 25 at 3:55
-
This might help: raspberrypi.stackexchange.com/questions/105116/…– tlfong01Jan 25 at 5:45
1 Answer
It seems to me your earlier question, is a feasible approach. And this one is almost a feasible approach :) All you need to do here is replace the TCA9548A
with a Multiplexed A/D Converter. I'll try to explain how this works in general, and you'll see it's not conceptually difficult at all once you understand what's going on.
Before I do that however, I'll bend the rules here a wee bit and recommend a different A/D Converter: This unit from Adafruit should be enough to meet your objectives: it will handle a max of 8 gas sensors, it is considerably less expensive than the unit you found, and Adafruit supplies software and a tutorial for Raspberry Pi. That's only a recommendation of course; there are many hardware solutions that will get you to a functional solution. You may wish to consider this as your initial prototype, and make subsequent improvements.
So, how does this work? The MCP3008 is an IC that combines an Analog-to-Digital (A/D) converter with a multiplexer in a single package. The A/D converter is needed because the RPi has no analog input. The multiplexer simply connects one of its eight inputs to the single input of the A/D converter. The timing and sequencing for making these connections and performing the A/D conversion are controlled in your software - which runs on the RPi.
Now imagine the analog output of each of your 8 gas sensors being wired to one of the 8 channels of the MCP3008: channel 0 - channel 7. Your software communicates with the MCP3008 over an SPI bus, effectively accomplishing the following steps repetitively:
tell the MCP3008 to do an A/D conversion of the analog input at channel 0.
send the result of the A/D conversion at channel 0 (Step 1) to the RPi as a serial bitstream over the SPI bus.
process the received data in the RPi. This may be as simple as comparing the value of the reading to a threshold, and setting an alarm if the threshold is exceeded.
Repeat steps 1-3 for each of the other 7 channels.
Repeat steps 1-4 repetitively for continuous monitoring.
As far as the wiring interconnections, I'd suggest you forego Adafruit's more elaborate recommendations, and take a minimalist approach - as shown here.
Finally, you will need to enable the Raspberry Pi's SPI bus; this may be done by editing the file at /boot/config.txt
or by using the raspi-config
software tool. This search should provide explanatory examples for both approaches.
Final recommendation: Learn by doing. If you have questions, please feel free to ask as many as you'd like. Do your homework (read and study the alternatives), and try to ask specific questions.
-
-
I was going to try to use 3 PCF8591 but the pi only has one pair of SDL/SCL pins.– KatianieJan 25 at 16:13
-
@Katianie: This should probably be another question, but some Pis have more than 1 I2C bus. And don't overlook the fact that I2C is a bus; that means that you can connect up to 8 PCF8591 chips on the same bus by using its
A0, A1, A2
bus address inputs.– SeamusJan 25 at 23:13