Grove encoder with GrovePi+[SOLVED]

Hi

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

atexit.register(grovepi.encoder_dis)

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

except IOError:
    print ("Error")"

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

def encoder_dis():
write_i2c_block(address, encoder_dis_cmd + [unused, unused, unused])
time.sleep(.2)

def encoderRead():
write_i2c_block(address, encoder_read_cmd + [unused, unused, unused])
time.sleep(.2)
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]]
else:
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

Hi,
The Grove encoder only works with firmware version 1.2.5 and up. Can you make sure that you have it on your Pi: https://github.com/DexterInd/GrovePi/tree/master/Firmware/Source/v1.2/grove_pi_v1_2_5 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: https://github.com/DexterInd/GrovePi/blob/master/Software/Python/grove_firmware_version_check.py . Once the firmware is updated, connect the encoder to port D2 and try running this https://github.com/DexterInd/GrovePi/blob/master/Software/Python/grove_encoder_read.py.

Do let us know if this helps.

-Karan

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: https://github.com/DexterInd/GrovePi/tree/master/Firmware/Source/v1.2/grove_pi_v1_2_5 .

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 grove_firmware_version_check.py in the Grovepi/Software/Python folder and make sure that it shows 1.2.5.

-Karan

Hi Karan

Do I need to follow this as well - http://www.dexterindustries.com/GrovePi/get-started-with-the-grovepi/updating-firmware/

Regards,
Sam

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.

-Karan

Thank you Karan.