Grovepi+ Is collision sensor working well?

I want to handle this collision sensor,
but it print only 255. If i shaked it, it just stopped running and stucked at try’s print line.
result

Is it works well? Or has some problem?

This is the code what i used

code