VernierST/godirect-py

Godirect USB connection not working with starter code

Closed this issue · 15 comments

I have 2 go direct sensors, ammonium and calcium, and they are connected through USB to a Pi3. When I run the starter code with [3],[4] as my sensor types in the code as it explains, I get the error below. It only runs 1/3 times every time. Has anyone had success connecting 2 sensors with the starter code with a Pi?
image

Hello,

What happens if you run the code without entering sensor numbers. In other words, leave the argument blank:
instead of:
gdx.select_sensors([3],[4])
do this:
gdx.select_sensors()

Also, did you run a single go direct device using the example 'gdx_getting_started_usb.py' without any modifications to the example? When you run this example it should provide you a list of sensors to choose from. What sensors are on that list and what are the numbers?

Sam

Hello, I was just looking for ammonium and calcium sensors to use with raspberry pi or arduino. Could you recommend me a supplier of these sensors?

Hello,

Please be aware that you posted your question on top of someone else's question.

This issue forum is for discussing the Python package for Vernier Go Direct sensors. These are sensors specifically designed for use in education with Python support for Windows, Mac, and Linux (raspberry pi).

Hi,
Yes, it runs smoothly when only 1 is connected.
As for the menu options you asked about, below is what it shows. We have ammonium and calcium, which is why in our code we put ([3],[4]).
1: Potential (mV)
2: Nitrate (mg/L)
3: Ammonium (mg/L)
4: Calcium (mg/L)
5: Chloride (mg/L)
6: Potassium (mg/L)

Have you had success running the two together at all on your end?
Also, when you have 2 sensors connected at once, i.e. 3 and 4, is there a way to call only one of them at a time to get its output?

Do you have two Go Direct devices (two USB cables connected to two different devices)? Or are you connecting one device (one USB cable)?

If you have two devices, then when you run the code you will get feedback like this in the console:

number of usb devices found = 2
attempting to open 2 device(s)...
open device 0 = True
open device 1 = True

Is that what you see when you run the code?

yes, it is 2 devices with 2 separate USB connections, and yes we get that when it runs. In the original screenshot you can see even when it throws error it does mention 2 devices were found before it throws the error.

In that original screenshot that you mention, there is feedback that the first device opens, but it does not give feedback that the second device was opened. That is not an error with the sensor selection, that is an error with trying to open the second device. Is that the error you always see?

Now I am reading your other comment more closely and you say that when you leave gdx.select_sensors() blank, it runs when you have one device connected. But what happens when you have two devices connected? You can test this by running our example called 'gdx_getting_started_usb.py'. Do you get to the prompt to select sensors when you have two devices connected, or does the error also occur while trying to open the second device?

yes, the prompt still shows up when 2 are connected and it makes me pick 2 devices in the prompt.

Can you paste a screenshot of what you see in the console when you run 'gdx_getting_started_usb.py' with your two devices connected.

Here you go.
image
image

Thanks! So that appears to work fine, correct? Looks like both devices connected, you selected the channels you wanted and data was returned. If you run this code multiple times does it continue to work correctly?

If you then change this code to...
gdx.select_sensors([4],[3])

and run it multiple times, what happens?

It throws an error if I do gdx.select_sensors([4],[3])
but I tried doing gdx.select_sensors(([4],[3])) and it seems to work so far. Is there any way you can call only 1 sensor when both are connected by any chance?

I did make a mistake in the way I said to select sensors for two devices. If you are setting up sensors of two devices then you will have to make a 2D list in the select_sensor() argument. This is explained in the getting started document in the 'Notes Regarding the gdx Functions' section.

I am sorry I made that mistake. If it is one device, then the argument is a 1D list. If it is multiple devices, then the argument is a 2D list. So for your example it would be:
gdx.select_sensors([[4],[3]])

I'm not exactly sure what you are asking in your question about calling only 1 sensor (when both devices are connected). If you set up both sensors, of the two devices, when you read it will send back a list of all of the readings. If you only want to analyze one sensor, from one of the devices, then you could just index out the value that you were interested in. Does that work for what you are trying to do? If not, you will need to explain in more detail what you are trying to do. Thanks.

yes, the gdx.select_sensors([[4],[3]]) seems to be functional, not sure what was wrong originally to be honest.

As for calling 1 sensor, the concern was to understand which sensor it reads first and which second to see if I need to call [[3],[4]] or [[4],[3]] but I believe I was able to figure it out! Thank you for the help!

Oh good, I'm glad you got it working!