How can I find out if a peripheral device is connected to the GPIO?

I want to be able to detect when a peripheral sensor is NOT connected to my Raspberry Pi 3.

For example, if I have a passive infrared GPIO sensor.

I can get all the GPIO ports as follows:

PeripheralManagerService manager = new PeripheralManagerService(); List<String> portList = manager.getGpioList(); if (portList.isEmpty()) { Log.i(TAG, "No GPIO port available on this device."); } else { Log.i(TAG, "List of available ports: " + portList); } 

Then I can connect to the port as follows:

  try { Gpio pir = new PeripheralManagerService().openGpio("BCM4") } catch (IOException e) { // not thrown in the case of an empty pin } 

However, even if the pin is empty, I can still connect to it (which technically makes sense, since gpio is only binary. It seems that there is no api, and I cannot legitimately think of the logic of how you can distinguish the pin that has the connected peripheral sensor, and one that is "empty."

Therefore, at the moment I can not programmatically claim that my sensors and circuit are installed correctly.

Does anyone have any ideas? Is this possible electronically?

Reference documents:

https://developer.android.com/things/sdk/pio/gpio.html

+6
source share
2 answers

There are many ways to “detect presence” electrically, but nothing you can find inside SoC. Normally, you would not request a GPIO contact if something were attached - this could not tell you.

Additional GPIO pins are often used to determine if a peripheral device is connected to the connector. A plug for some sensor may include a “detection” line that is shorted to ground and, for example, pulls a GPIO when a sensor is connected. USB and SDIO do something similar with some specialized circuits in the interface.

You can also create more sophisticated detection schemes using things like current perception, but they will inevitably have to set up a binary signal that you capture through a dedicated GPIO.

This is easier for serial peripherals, as you can usually send a basic command and make sure you get a response.

+6
source

Detection using only the input line can be hard. First, you want to limit the scope of the problem. Consider the non-existent state of the sensor as it is not connected, the sensor is connected but not responding, or the sensor is uncharacteristic.

So, if it is a digital sensor, then communication with the sensor may be sufficient to determine if it is present or not (especially if checksums or parity bits are used). Some analog sensors also have specific characteristics of how they behave when triggered. You can use the deviation from these specifications to determine if there is a sensor.

If you have a digital sensor without any error checking on it, where you synchronize data (so that all 0 or all 1s are valid) or it is just binary 1 or 0 for output, then you will need external help. The same goes for most analog sensors.

This external help would be something when you put the system in a known controlled state, press a button, and then check the sensors for output in a specific range. To be absolutely sure, you would like at least two different states so that your digital or analog inputs are not stuck in the correct state for your test.

Almost any other method will be external to the system. Using an additional IO to “detect” the sensor can help increase confidence that the sensor exists, but you can get false positives when all you know is that “something” is not the expected sensor.

+2
source

Source: https://habr.com/ru/post/1014292/


All Articles