I bought a GrovePi kit that came with a thumb joystick and my daughter is trying to figure it out. But, it’s different than all of the ones I’ve found online. I just need a wiring diagram. Mine has five posts labelled Gnd, +5v, urx, ury, sw. When I run the joystick script that comes with the software, it says, “Rx = float(1023 - x)* 10/x Zero division error float division by zero” and I assume that this means that I didn’t wire it properly. Anybody have a link to a site with a wiring diagram for this?
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
time.sleep(.5)