Ultrasonic range ioerror


#1

Hi,

I am completely new to the grovepi.

I attached the ultrasonic ranger to D4 and ran grovepi_ultrasonic.py and got the following error. Any ideas on how to trouble shoot this?

IOError
IOError
IOError
Traceback (most recent call last):
File “./grovepi_ultrasonic.py”, line 5, in <module>
print ultrasonicRead(pin)
File “/home/pi/GrovePi/Software/Python/grovepi.py”, line 111, in ultrasonicRead
return (number[1]*256+number[2])
TypeError: ‘int’ object has no attribute ‘getitem

Thanks,
Eric


#2

Hi Eric,
The Ultrasonic sensor functionality was added in the recent firmware update, so just make sure that you have the latest firmware on the GrovePi. Use this http://www.dexterindustries.com/GrovePi/get-started-with-the-grovepi/updating-firmware/ to update you firmware and try running the program again, if you still face the problem, do let us know.

Thanks,
Karan


#3

Thanks Karan!

There were a couple of things I wanted to check on.

I am getting the same error with the temperature and humidity sensor.
I tried running new_fw_search.sh and it said that I had the latest firmware. my version.txt showed 1.1

I have a friend that was going to help me with the soldering pads, he was wondering if it would work if we connected all of the metal points together with a metal or wire piece with the insulation striped out.


#4

Hi Guys,

I am having a similar problem to this only I am using the DHT Sensor. I have updated the firmware to the newest version.

When I run the example script, the temperature and humidity values are polled but eventually I get the same IOError.

Here’s my test.py code :


#!usr/bin/python

from grovepi import *

while True:
        print dht(2,1)

This outputs an IOError after 20-30 seconds.

I have a second script which takes the DHT Values [temperature, humidity] and adds them to into a mysql database.


29.5
29.5
29.5
29.5
29.5
IOError
nan
Traceback (most recent call last):
  File &quot;temperature_port2.py&quot;, line 49, in &lt;module&gt;
    cur.execute(&quot;INSERT INTO sensor_data(sensorid, value) VALUES(&#039;2&#039;, %s)&quot;, (tem                                                      perature))
  File &quot;/usr/lib/python2.7/dist-packages/MySQLdb/cursors.py&quot;, line 174, in execu                                                      te
    self.errorhandler(self, exc, value)
  File &quot;/usr/lib/python2.7/dist-packages/MySQLdb/connections.py&quot;, line 36, in de                                                      faulterrorhandler
    raise errorclass, errorvalue
_mysql_exceptions.OperationalError: (1054, &quot;Unknown column &#039;nan&#039; in &#039;field list&#039;                                                      &quot;)

I’ll upload a video from a Putty terminal that shows the error in real time. The script works 100% until it encounters the IOError / [nan,nan] problem.

Any help would be much appreciated.

My DHT is connected to D2.


#5

Hi guys, the video -

https://drive.google.com/file/d/0B43TulfisyoGU0wwV0RqRXc0cWM/edit?usp=sharing

and… another error different to the previous one :


29.6
29.6
29.6
29.6
29.6
29.6
29.6
29.6
IOError
Traceback (most recent call last):
  File &quot;temperature_port2.py&quot;, line 40, in &lt;module&gt;
    [temperature, humidity] = dht(port,1)
TypeError: &#039;int&#039; object is not iterable
root@centersense:~/centersense/sensors#


#6

Hi,
There are certain cases where the GrovePi is unable to communicate properly with the Raspberry Pi and hence gives out the IOError and returns -1. I think you can add a condition to check for -1 and only proceed when that condition is resolved.

Also try handling the TypeError exception in the second case. That should work out well for you.

Please let us know if you need anymore help and sorry for the troubles.

Thanks,
Karan


#7

Hi Karan,

Thanks for your reply. Are you able to provide the code that would check for a -1 and TypeError? I’m not really sure where I should be starting with that.

Moreover, I assumed when purchasing the GrovePi and the Sensors that everything would work out of the box and wouldn’t have to deal with this kind of thing?

Thanks in advance,

Dave.


#8

Hi Dave,
Sorry for all the troubles. I have attached a code that should solve your problem. Please let me know if you still face any problems.

Thanks,
Karan


#9

Hi Karan,

No worries. Just frustrating that is all!

The code seems to be working now. However, when it encounters an IOError sometimes it says

IOError
29.7 66.8
29.7 66.8
IOError
Unable to read values

an continues on with the script.

With that being said, the script works like a charm with this error handling code.

Thanks for your help and support.


#10

Hi Dave,

can you be please so kind and share with us your final python script for mysql storage of DHT temp/humidity incl. creating proper mysql tabs?

Many thanks!


#11

Hi Dave - I second the request re the SQL script. Currently I’m storing data to a CSV file with buffering set to 0 so I can read / analyze temp / humid and other sensor data while my loop() runs. Am interested in using mySQL instead.


#12

Hi Karan,

Could you provide more info on how to fix the underlying communications problem referenced above in:

There are certain cases where the GrovePi is unable to communicate properly with the Raspberry Pi and hence gives out the IOError and returns -1. I think you can add a condition to check for -1 and only proceed when that condition is resolved.

I already have error handling in place to catch / log / continue on these low level IO errors. Basically I’ve updated the GrovePi file to “share” the same error logging and to throw an error that my top level routing catches and handles.

I’m trying to determine if your code is a different way to handle the condition (ie. another or a better solution) vs. a fix for the problem. If I read this thread correctly, it almost like I’d integrate the suggested code as a retry in the GrovePi file (i.e. modify the routines in that file) and re-try a few times before throwing an error? That would be an alternative to my current code that throws the error right away, bc as my code is written I’m missing a reading every time I get an IO error.

I’m also wondering if this communication problem is related to the long cable length issue I’m experiencing?


#13

Hi,
We left the final error handling for the users to decide how they want to handle the error. We didn’t keep retries explicitly, because the GrovePi library is already very slow and if someone has a project that is time sensitive, then it might cause problems for them. Also there are different places where the IOError’s can be thrown from different sensors so we didn’t add them in the Library.

If someone needs to add retries, it should be very easy to make a function for their own use. If you have already written an example that works out well for you, it would be great if you send a pull request to our Github repository. We’ll be happy to add the example.

-Karan


#14

Hi Karan,

I’ll work on the error/retry code over the next week or so. Once I’ve got it tested and working, I’ll do the pull so you can add the code.