I wrote the GrovePi Python Joystick script
Make sure you update your GrovePi to the latest firmware.
There are instructions on the Dexter Industries website.
The Grove Thumb Joystick is a 4 pin sensor which is basically two potentiometers with a tactile switch which shorts one axis.
Pins are: GND, VCC, Y, X.
It’s an analog sensor.
You need to connect it to one of your GrovePi’s analog sockets.
The GrovePi is basically an Arduino shield for the Raspberry Pi.
It sounds like your joystick’s 5th pin is a separate pin for the centre button.
Can you provide a model number for your joystick, or a link to where you bought it?
The “Rx = float()…” line is calculating resistance on the x axis, based on the analog read of the x pin.
Divide by zero error is indicative that the analog read failed.
I presume you are using a non standard grove cable.
Have a look on your GrovePi at socket labelled A0.
Looking from the top, from left to right the pins are: 1, 0, VCC, GND.
You should wire your sensor like so:
“urx” -> “0” (yellow)
“ury” -> “1” (white)
“+5v” -> “VCC” (red)
“GND” -> “GND” (black)
Try commenting out all lines after “y = grovepi.analogRead(yPin)” and add:
print “x =”, x, " y =", y