GrovePi/Software/Python/grovepi.py", line 227, in analogRead return number[1] * 256 + number[2] TypeError: 'int' object has no attribute '__getitem__'

pending

#1

Hello,

I installed Raspberian lite, allowed ssh, installed vim, git (using apt-get) and GrovePi using instructions here on my RPII. Literally nothing more (therefore my case should be pretty reproducible).

The LED and buzzer work (I guess everything in digital pins). However, when I tried to read analog input I got :

>>> from grovepi import *
>>> pinAdc = 1
>>> analogRead(pinAdc)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/slim/GrovePi/Software/Python/grovepi.py", line 227, in analogRead
    return number[1] * 256 + number[2]
TypeError: 'int' object has no attribute '__getitem__'

I found this thread where they are describing very similar (if not the same) issues, but I could not find a link to fix scripts they talk about. And since that thread is closed I am opening a new one… How to fix my problem?

Troubleshooting log:

slim@raspberrypi:~/GrovePi/Troubleshooting $ ./all_tests.sh 
=============================
GrovePi Troubleshooting Script
=============================

Adding permissions to the scripts
=================================
[sudo] password for slim: 

Check space left
================
Filesystem      Size  Used Avail Use% Mounted on
/dev/root        15G  1.6G   12G  12% /
devtmpfs        458M     0  458M   0% /dev
tmpfs           462M     0  462M   0% /dev/shm
tmpfs           462M  6.2M  456M   2% /run
tmpfs           5.0M  4.0K  5.0M   1% /run/lock
tmpfs           462M     0  462M   0% /sys/fs/cgroup
/dev/mmcblk0p1   42M   21M   21M  51% /boot
tmpfs            93M     0   93M   0% /run/user/1001

Check for dependencies
======================
python 2.7.9-1 install ok installed
python-pip 1.5.6-5 install ok installed
git 1:2.1.4-2.1+deb8u3 install ok installed
libi2c-dev 3.1.1+svn-2 install ok installed
python-serial 2.6-1.1 install ok installed
python-rpi.gpio 0.6.3~jessie-1 install ok installed
i2c-tools 3.1.1+svn-2 install ok installed
python-smbus 3.1.1+svn-2 install ok installed
arduino 2:1.0.5+dfsg2-4 install ok installed
minicom 2.7-1+deb8u1 install ok installed
dpkg-query: no packages found matching scratch

wiringPi Found
wiringPi Found
grep: /etc/modprobe.d/raspi-blacklist.conf: No such file or directory
I2C still in blacklist (ERR)
grep: /etc/modprobe.d/raspi-blacklist.conf: No such file or directory
SPI still in blacklist (ERR)


Check for addition in /modules
==============================
I2C-dev already there
i2c-bcm2708 already there
spi-dev already there


Hardware revision
=================
gpio version: 2.36
Copyright (c) 2012-2015 Gordon Henderson
This is free software with ABSOLUTELY NO WARRANTY.
For details type: gpio -warranty

Raspberry Pi Details:
  Type: Pi 2, Revision: 01, Memory: 1024MB, Maker: Sony 
  * Device tree is enabled.
  *--> Raspberry Pi 2 Model B Rev 1.1
  * This Raspberry Pi supports user-level GPIO access.


Check the /dev folder
=====================
i2c-1
ttyAMA0

USB device status
=================
Bus 001 Device 003: ID 0424:ec00 Standard Microsystems Corp. SMSC9512/9514 Fast Ethernet Adapter
Bus 001 Device 002: ID 0424:9514 Standard Microsystems Corp. 
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub

/:  Bus 01.Port 1: Dev 1, Class=root_hub, Driver=dwc_otg/1p, 480M
    |__ Port 1: Dev 2, If 0, Class=Hub, Driver=hub/5p, 480M
        |__ Port 1: Dev 3, If 0, Class=Vendor Specific Class, Driver=smsc95xx, 480M
Raspbian for Robots Version
===========================
cat: /home/pi/di_update/Raspbian_For_Robots/Version: No such file or directory


Hostname
========
raspberrypi


Checking for Atmega chip
========================


avrdude: Version 5.10, compiled on Jun 18 2012 at 12:38:29
         Copyright (c) 2000-2005 Brian Dean, http://www.bdmicro.com/
         Copyright (c) 2007-2009 Joerg Wunsch

         System wide configuration file is "/etc/avrdude.conf"
         User configuration file is "/root/.avrduderc"
         User configuration file does not exist or is not a regular file, skipping

         Using Port                    : unknown
         Using Programmer              : gpio
         AVR Part                      : ATMEGA328P
         Chip Erase delay              : 9000 us
         PAGEL                         : PD7
         BS2                           : PC2
         RESET disposition             : dedicated
         RETRY pulse                   : SCK
         serial program mode           : yes
         parallel program mode         : yes
         Timeout                       : 200
         StabDelay                     : 100
         CmdexeDelay                   : 25
         SyncLoops                     : 32
         ByteDelay                     : 0
         PollIndex                     : 3
         PollValue                     : 0x53
         Memory Detail                 :

                                  Block Poll               Page                       Polled
           Memory Type Mode Delay Size  Indx Paged  Size   Size #Pages MinW  MaxW   ReadBack
           ----------- ---- ----- ----- ---- ------ ------ ---- ------ ----- ----- ---------
           eeprom        65     5     4    0 no       1024    4      0  3600  3600 0xff 0xff
           flash         65     6   128    0 yes     32768  128    256  4500  4500 0xff 0xff
           lfuse          0     0     0    0 no          1    0      0  4500  4500 0x00 0x00
           hfuse          0     0     0    0 no          1    0      0  4500  4500 0x00 0x00
           efuse          0     0     0    0 no          1    0      0  4500  4500 0x00 0x00
           lock           0     0     0    0 no          1    0      0  4500  4500 0x00 0x00
           calibration    0     0     0    0 no          1    0      0     0     0 0x00 0x00
           signature      0     0     0    0 no          3    0      0     0     0 0x00 0x00

         Programmer Type : GPIO
         Description     : Use sysfs interface to bitbang GPIO lines

avrdude: AVR device not responding
avrdude: initialization failed, rc=-1
         Double check connections and try again, or use -F to override
         this check.


avrdude done.  Thank you.


Checking I2C bus for devices
============================

Checking I2C bus 0
==================
Error: Could not open file `/dev/i2c-0' or `/dev/i2c/0': No such file or directory

Checking I2C bus 1
==================
     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
00:          03 04 -- -- -- -- -- -- -- -- -- -- -- 
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- 3e -- 
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
60: -- -- 62 -- -- -- -- -- -- -- -- -- -- -- -- -- 
70: 70 -- -- -- -- -- -- --                         

Checking for firmware version
=============================
Traceback (most recent call last):
  File "/home/slim/GrovePi/Software/Python/grove_firmware_version_check.py", line 40, in <module>
    print("GrovePi has firmware version: %s" %grovepi.version())
  File "/home/slim/GrovePi/Software/Python/grovepi.py", line 266, in version
    return "%s.%s.%s" % (number[1], number[2], number[3])
TypeError: 'int' object has no attribute '__getitem__'
cp: cannot create regular file '/home/pi/Desktop/log.txt': No such file or directory
Log has been saved to Desktop. Please copy it and send it by email or upload it on the forums

#2

Hi @kjaron,

Have you flashed the firmware on the GrovePi?
If the GrovePi doesn’t have the latest firmware, then communications between the GrovePi and the Raspberry Pi might fail.

Also, can you tell us what is the version of the kernel?
You can find out by typing the uname -a command inside a terminal.

Thank you!


#3

I did not flashed the firmware before, so I tried.

sudo ./firmware_update.sh
[sudo] password for slim: 
Updating the GrovePi firmware
=============================
 http://www.dexterindustries.com/grovepi 
 Run this program: 
 sudo ./firmware_update.sh
 
=============================
Do you want to update the firmware? [y,n]y
Make sure that GrovePi is connected to Raspberry Pi
Firmware found
Press any key to start firmware update
. . .

avrdude: AVR device not responding
avrdude: initialization failed, rc=-1
         Double check connections and try again, or use -F to override
         this check.


avrdude done.  Thank you.

so I checked this thread and conclusions are fairly depressing. However, I have no equipment to run the test you described there. So I at least have taken pic of my setup:

Linux raspberrypi 4.9.35-v7+ #1014 SMP Fri Jun 30 14:47:43 BST 2017 armv7l GNU/Linux

My GrovePi is brand new (the first time used), but It was bought about a year and half ago, which is very depressing since there is no warranty on it any more. If the GrovePi board is not working, I guess I have no right for replacement :frowning:
(it was bought through http://pi-shop.ch/)


#4

Hi @kjaron,


I think the reason for why I2C isn’t working on your GrovePi is because you have a more recent version of the kernel which does have a bug.

Could you please type in the following command inside a terminal on your Raspberry Pi?
sudo rpi-update 52241088c1da59a359110d39c1875cda56496764.

This will downgrade your kernel to version 4.4.50-v7+.
After the downgrade is successful, please try running some examples in Python.


As for the problem of flashing the firmware, I think we have a way of diagnosing the board.
Here’s a link to another thread where I had written a tutorial for reprogramming it the “hard” way:
http://forum.dexterindustries.com/t/solved-grovepi-firmware-update-fails-avr-device-not-responding/3144/8?u=robertlucian


Thank you!


#5

Downgrading my kernel worked.

Yes, I am finally getting values! I mean, I am able to read analog output (I have not checked if it is meaningful, but I do not see a reason why it should not be).

I2C port also works (tested on LCD display).

Thanks a lot.

I also tried to update firmware, but I get very same output (avrdude: AVR device not responding). The thread you shared looks the same as the one I have link I posted in the last message. Not sure how to diagnose it now, since I have no jumper cables and header pins.


#6

I have the same error thus I believe there is more to this.

a) I have plain rasbian and i think I followed the directions to get grovepi working. But I may miss a step

b) whenever I reboot I get the same warning after i start the pi up e.g. python grove_thumb_joystick.py
Traceback (most recent call last):
File “grove_thumb_joystick.py”, line 75, in
x = grovepi.analogRead(xPin)
File “/home/pi/Desktop/GrovePi/Software/Python/grovepi.py”, line 227, in analogRead
return number[1] * 256 + number[2]
TypeError: ‘int’ object has no attribute ‘getitem

Now when I flash the OS with the firmware_update.py program, and I run the same program immediatly after the firmware update the error disapears. However when I reboot that error comes again till I reflash

Thoughts, what step do I miss?

After

sudo rpi-update 52241088c1da59a359110d39c1875cda56496764

Linux boat01 4.4.50-v7+ #970 SMP Mon Feb 20 19:18:29 GMT 2017 armv7l GNU/Linux


#7

Hi @laszewski,

It would be better to reiterate things. So, in order to have it up and working you need to:

  1. Have the GrovePi stacked on top of your Pi.

  2. Use the latest R4R image and run curl -kL dexterindustries.com/update_grovepi | sudo bash.

  3. Have this 4.4.50-v7+ kernel version. You can check it with uname -a. I assume you already did that by reading your last line in your reply - this is a bug we’re working on it.

  4. Run this file here https://github.com/DexterInd/GrovePi/blob/master/Firmware/firmware_update.sh. I assume you already did that, but it’s better to safe than sorry.

If after running all these it still doesn’t work, can you give us the output of this i2cdetect -y 1 command?

I know this isn’t the best way to install it and make it functional, but we’re already working on bug-fixing and improving it. It should take us some time.

I’m waiting for a reply from you.

Thank you!


#8
  1. yes grovepi is stacked
    2 yes we did run the curl command piped into bash
  2. from our previous msg all our images were Linux boat01 4.50-v7+ #970 SMP Mon Feb 20 19:18:29 GMT 2017 armv7l GNU/Linu or newer (we tried a whole bunch of them)
  3. we did everytime we rebooted the machine the command under four. Once you do this the grove pi works. However when we reboout the grovepi does not .

I had 3 different grovepi shields and we could reliably repliacte this on all of them.

We do not yet know the cause of this. The reason we did this is as we could the dexter os also not to work.

In a last ditch effort what we did is

a) put the very latest rasbian on the sd card, I tried multiple to make sure that there is not issue with the cards, all of them verified correctly

b) we did the usual update

c) we followed the instructions from the web site.

d) than we did something different which in my view should have not made any difference. We burned the firmware three times in a row on the dexter cards. Then we rebooted, installed the dexter software, and ran the joystick example.

Interestingly enough all 4 grovepi cards seem now to work.

I bought them at the approximately the same time from dexter. They were version 3.0.

We experienced this behavior like this before. E.g. we needed to reflash the firmware. I wonder if the batch of cards we bought have a manufacturing issue or if there is some kind of different program we could run to do a more intense test of the cards. As we run analog, SPI, I2C, maybe there is a posibility to effect the card in some way. The question is could we be running a program that instead of flashing the firmware, reads it and compares it with what should be on the card.

Note that our intention is to document what we have done as we use an enhanced groovepi object oriented library so others can benefit from this

The now working instructions are at

other than the reflashing 3 times, we do not see a difference to the once you provide. We made sure that we replaced the PIs, and SD cards, so we could narrow it down to some unkown issue of the grovePI cards.