Grove encoder with GrovePi+[SOLVED]


Can you provide me a example for the Grove Encoder (D2) connected to GrovePi+ board?
I tried following code but I always receive zeros.

import time
import grovepi
import atexit


print "Reading from the encoder"
while True:
[new_val,encoder_val] = grovepi.encoderRead()
if new_val:
print encoder_val

except IOError:
    print ("Error")"

and this is definations;
"def encoder_en():
write_i2c_block(address, encoder_en_cmd + [unused, unused, unused])

def encoder_dis():
write_i2c_block(address, encoder_dis_cmd + [unused, unused, unused])

def encoderRead():
write_i2c_block(address, encoder_read_cmd + [unused, unused, unused])
data_back= bus.read_i2c_block_data(address, 1)[0:2]
#print data_back
if data_back[0]!=255:
return [data_back[0],data_back[1]]
return [-1,-1]

If you can also suggest how to change D2 to other port to test the GrovePi+ or Grove encoder has a problem.

Thank you

The Grove encoder only works with firmware version 1.2.5 and up. Can you make sure that you have it on your Pi: and run a firmware update to upload it to the Atmega using: avrdude -c gpio -p m328p -U flash:w:grove_pi_v1_2_5.cpp.hex . After uploading the firmware, make sure that it is on there by running: . Once the firmware is updated, connect the encoder to port D2 and try running this

Do let us know if this helps.


Hi Karan,

Can you please give instructions for uploading firmware.

Hey Sam,
Make sure that you have the latest version of the GrovePi repository on the Raspberry Pi.

Go to the firmware folder: Grovepi/Firmware/Source/v1.2/grove_pi_v1_2_5 . It should look like this: .

Double-check that this file is there: grove_pi_v1_2_5.cpp.hex

Run the firmware update using: avrdude -c gpio -p m328p -U flash:w:grove_pi_v1_2_5.cpp.hex.

Once the firmware update is done, run the in the Grovepi/Software/Python folder and make sure that it shows 1.2.5.


Hi Karan

Do I need to follow this as well -


Not since you have a GrovePi+. The old GrovePi-without-plus needed that to be able to be flashed with avrdude.

Thank you Karan & Mirar,

Can you please advice how do I port Grove encoder to D3 or D4 port?

Thank you
I manage to update firmware sucessfully.

Hey Sam,
The Grove encoder can only work on Port 2 because it needs interrupts to work and the pins on Port 2 are the only ones that support it.


Thank you Karan.