This makes no sense - Ultrasonic Ranger

So to get the reading from the ultrasonic ranger, you need to do ultrasonicRead(4) where 4 is where the ultrasonic ranger is plugged in. I’m getting an error - int object is not subscriptable. When I remove the argument, it tells me that the function needs an argument! When I add the argument, it tells me that ultrasonicRead is an integer and not a function! I am really frustrated by this! Any help would be much appreciated. Thanks.

Here is what is written in the Python Shell. As you can see, at first it tells me I am missing an argument. Then it tells me I cannot index an integer… It just said it’s a function though, not an integer

>>> 
============== RESTART: /home/pi/Desktop/Assignment3_answers.py ==============
Traceback (most recent call last):
  File "/home/pi/Desktop/Assignment3_answers.py", line 16, in <module>
    print(ultrasonicRead())
TypeError: ultrasonicRead() missing 1 required positional argument: 'pin'
>>> 
============== RESTART: /home/pi/Desktop/Assignment3_answers.py ==============
Traceback (most recent call last):
  File "/home/pi/Desktop/Assignment3_answers.py", line 16, in <module>
    print(ultrasonicRead(4))
  File "/home/pi/Desktop/GrovePi/Software/Python/grovepi.py", line 257, in ultrasonicRead
    return (number[1] * 256 + number[2])
TypeError: 'int' object is not subscriptable
>>>

Hi @hhill917

Just like in the following thread, you have to flash the firmware onto the GrovePi:

Go to /home/pi/Dexter/GrovePi/Firmware and run the bash firmware_update.sh to flash the firmware:

After this, you can re-execute your code and it’ll work.

Thank you!