GrovePi Python Issue

I am trying to use the basic Python libraries with the GrovePi. I have test one I had and kept getting the same error.

  File "dwPY_OpenMQTT.py", line 208, in <module>
    sensor_value = grovepi.analogRead(potentiometer);
  File "build/bdist.linux-armv7l/egg/grovepi.py", line 226, in analogRead
    return number[1] * 256 + number[2]
TypeError: 'int' object has no attribute '__getitem__'

Seems that even if I run the sample code that is supplied with the git, I get the same error.

pi@raspberrypi:~/Desktop/GrovePi/Software/Python/firmware_tests $ python multi_analog_read.py 
Traceback (most recent call last):
  File "multi_analog_read.py", line 46, in <module>
    sensor_value0 = grovepi.analogRead(sensor0)
  File "build/bdist.linux-armv7l/egg/grovepi.py", line 226, in analogRead
    return number[1] * 256 + number[2]
TypeError: 'int' object has no attribute '__getitem__'

Script seems to run until it tries to perform the analogRead function.
Any help would be great.

Thanks in advance

Hello,
in order to help you out more efficiently, could you run the script found in GrovePi/Troubleshooting. all_tests.sh and upload the log here ?

=============================
GrovePi Troubleshooting Script
=============================

Adding permissions to the scripts
=================================

Check space left
================
Filesystem      Size  Used Avail Use% Mounted on
/dev/root       7.4G  1.5G  5.6G  21% /
devtmpfs        459M     0  459M   0% /dev
tmpfs           463M     0  463M   0% /dev/shm
tmpfs           463M  6.3M  457M   2% /run
tmpfs           5.0M  4.0K  5.0M   1% /run/lock
tmpfs           463M     0  463M   0% /sys/fs/cgroup
/dev/mmcblk0p1   63M   21M   42M  33% /boot
tmpfs            93M     0   93M   0% /run/user/1000

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+deb8u2 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 install ok installed
dpkg-query: no packages found matching scratch

wiringPi Not Found (ERR)
I2C still in blacklist (ERR)
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 3, Revision: 02, Memory: 1024MB, Maker: Embest 
  * Device tree is enabled.
  *--> Raspberry Pi 3 Model B Rev 1.2
  * 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
========
mrbit


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 initialized and ready to accept instructions

Reading | ################################################## | 100% 0.00s

avrdude: Device signature = 0x1e950f
avrdude: safemode: lfuse reads as FF
avrdude: safemode: hfuse reads as DE
avrdude: safemode: efuse reads as 5

avrdude: safemode: lfuse reads as FF
avrdude: safemode: hfuse reads as DE
avrdude: safemode: efuse reads as 5
avrdude: safemode: Fuses OK

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:          -- 04 -- -- -- -- -- -- -- -- -- -- -- 
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
70: -- -- -- -- -- -- -- --                         

Checking for firmware version
=============================
GrovePi has firmware version: 255.255.255
Log has been saved to Desktop. Please copy it and send it by email or upload it on the forums

I notice it states:

wiringPi Not Found (ERR)
I2C still in blacklist (ERR)
SPI still in blacklist (ERR)

But I have enables I2C and SPI in raspi-config and I have got wiringPi installed.

The grovepi is working fine when the grovepi.py is in the same directory of the script I’m running, it’s not able to load modules (like pinMode) when used from the package.

Thanks.
Based on this log, you’re running the standard version of Raspbian and not Raspbian for Robots?
Did you follow the installation steps ?

It seems we posted at the same time.

It does seem like an install problem if grovepi.py works when in the same directory.
Run grovepi/script/install.sh to be certain.

ah in my haste I was reading from here https://github.com/initialstate/grovepi/wiki/Part-2.-GrovePi-Setup

I will pip uninstall grovepi to remove it from the dist-packages and test again.

tom

hmmm, thanks for the link there. The pip install will not work. The grovepi installation script already puts the module in the main python system library so it will be reachable from any directory.

Thanks for your help cloeqc - It’s all working now I’ve pip uninstall grovepi

(annoyingly I should have noticed that I was reading something from a wrong github acc).

Tom

Seems that the cause of my issue is different. I am running the install.sh script. I am running it via a script that I wrote. I have the snippet below. I am also running the python3 install script and the regular python setup.py file.

Seems that possibly the script is not successfully removing SPI and I2C off the blacklist.

cd /home/pi/Desktop
sudo git clone https://github.com/DexterInd/GrovePi
sudo chmod 777 /home/pi/Desktop/GrovePi/Script/install.sh
sudo chmod 777 /home/pi/Desktop/GrovePi/Script/grovepi_python3_install.sh
sudo bash /home/pi/Desktop/GrovePi/Script/install.sh
sudo bash /home/pi/Desktop/GrovePi/Script/grovepi_python3_install.sh
cd /home/pi/Desktop/GrovePi/Software/Python
sudo python setup.py install

When I get the chance, possibly monday, I can run the test scripts.

Thanks

I am preforming a brand new installation on a brand new updated Raspbian.

  1. Created new SD card with latest Raspbian, 3-2-2017
  2. Connected to wifi and configured raspberry pi. Ran apt-get update && upgrade
  3. Followed your instructions to install GrovePi git
  4. ran all_tests.sh. Outcome below

I can re-run the install with a script and have that output to a log. But I am not doing anything special, at least not that I am aware of.

I can’t even check the firmware version of the grovepi as the python file fails.

‘’'
Check space left

Filesystem Size Used Avail Use% Mounted on
/dev/root 7.1G 4.3G 2.6G 63% /
devtmpfs 427M 0 427M 0% /dev
tmpfs 432M 4.0K 432M 1% /dev/shm
tmpfs 432M 6.0M 426M 2% /run
tmpfs 5.0M 4.0K 5.0M 1% /run/lock
tmpfs 432M 0 432M 0% /sys/fs/cgroup
/dev/mmcblk0p1 63M 21M 42M 33% /boot
tmpfs 87M 0 87M 0% /run/user/1000

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+deb8u2 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 install ok installed
scratch 1.4.0.6~dfsg1-5 install ok installed

wiringPi Not Found (ERR)
wiringPi Found
I2C still in blacklist (ERR)
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 © 2012-2015 Gordon Henderson
This is free software with ABSOLUTELY NO WARRANTY.
For details type: gpio -warranty

Raspberry Pi Details:
Type: Pi 3, Revision: 02, Memory: 1024MB, Maker: Embest

  • Device tree is enabled.
    *–> Raspberry Pi 3 Model B Rev 1.2
  • This Raspberry Pi supports user-level GPIO access.

Check the /dev folder

i2c-1
spidev0.0
spidev0.1
ttyAMA0

USB device status

Bus 001 Device 005: ID 046d:c077 Logitech, Inc.
Bus 001 Device 004: ID 413c:2107 Dell Computer Corp.
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
|__ Port 3: Dev 4, If 0, Class=Human Interface Device, Driver=usbhid, 1.5M
|__ Port 5: Dev 5, If 0, Class=Human Interface Device, Driver=usbhid, 1.5M
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 © 2000-2005 Brian Dean, http://www.bdmicro.com/
Copyright © 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 initialized and ready to accept instructions

Reading | ################################################## | 100% 0.00s

avrdude: Device signature = 0x1e950f
avrdude: safemode: lfuse reads as FF
avrdude: safemode: hfuse reads as DA
avrdude: safemode: efuse reads as 5

avrdude: safemode: lfuse reads as FF
avrdude: safemode: hfuse reads as DA
avrdude: safemode: efuse reads as 5
avrdude: safemode: Fuses OK

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: – -- – -- – -- – -- – -- – -- –
10: – -- – -- – -- – -- – -- – -- – -- – --
20: – -- – -- – -- – -- – -- – -- – -- – --
30: – -- – -- – -- – -- – -- – -- – -- – --
40: – -- – -- – -- – -- – -- – -- – -- – --
50: – -- – -- – -- – -- – -- – -- – -- – --
60: – -- – -- – -- – -- – -- – -- – -- – --
70: – -- – -- – -- – --

Checking for firmware version

Traceback (most recent call last):
File “/home/pi/Desktop/GrovePi/Software/Python/grove_firmware_version_check.py”, line 40, in
print(“GrovePi has firmware version: %s” %grovepi.version())
File “/home/pi/Desktop/GrovePi/Software/Python/grovepi.py”, line 265, in version
return “%s.%s.%s” % (number[1], number[2], number[3])
TypeError: ‘int’ object has no attribute ‘getitem
’’’

Seems I figured out one issue, the GrovePi was missing its firmware. Flashed the firmware to the GrovePi and now I have the i2cdetect showing the 4.

I am still having the all_tests.sh show some ERRs.
’’'
Check space left

Filesystem Size Used Avail Use% Mounted on
/dev/root 7.1G 4.3G 2.6G 63% /
devtmpfs 427M 0 427M 0% /dev
tmpfs 432M 4.0K 432M 1% /dev/shm
tmpfs 432M 6.0M 426M 2% /run
tmpfs 5.0M 4.0K 5.0M 1% /run/lock
tmpfs 432M 0 432M 0% /sys/fs/cgroup
/dev/mmcblk0p1 63M 21M 42M 33% /boot
tmpfs 87M 0 87M 0% /run/user/1000

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+deb8u2 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 install ok installed
scratch 1.4.0.6~dfsg1-5 install ok installed

wiringPi Not Found (ERR)
wiringPi Found
I2C still in blacklist (ERR)
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 © 2012-2015 Gordon Henderson
This is free software with ABSOLUTELY NO WARRANTY.
For details type: gpio -warranty

Raspberry Pi Details:
Type: Pi 3, Revision: 02, Memory: 1024MB, Maker: Embest

  • Device tree is enabled.
    *–> Raspberry Pi 3 Model B Rev 1.2
  • This Raspberry Pi supports user-level GPIO access.

Check the /dev folder

i2c-1
spidev0.0
spidev0.1
ttyAMA0

USB device status

Bus 001 Device 005: ID 046d:c077 Logitech, Inc.
Bus 001 Device 004: ID 413c:2107 Dell Computer Corp.
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
|__ Port 3: Dev 4, If 0, Class=Human Interface Device, Driver=usbhid, 1.5M
|__ Port 5: Dev 5, If 0, Class=Human Interface Device, Driver=usbhid, 1.5M
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 © 2000-2005 Brian Dean, http://www.bdmicro.com/
Copyright © 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 initialized and ready to accept instructions

Reading | ################################################## | 100% 0.00s

avrdude: Device signature = 0x1e950f
avrdude: safemode: lfuse reads as FF
avrdude: safemode: hfuse reads as DA
avrdude: safemode: efuse reads as 5

avrdude: safemode: lfuse reads as FF
avrdude: safemode: hfuse reads as DA
avrdude: safemode: efuse reads as 5
avrdude: safemode: Fuses OK

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: – 04 – -- – -- – -- – -- – -- –
10: – -- – -- – -- – -- – -- – -- – -- – --
20: – -- – -- – -- – -- – -- – -- – -- – --
30: – -- – -- – -- – -- – -- – -- – -- – --
40: – -- – -- – -- – -- – -- – -- – -- – --
50: – -- – -- – -- – -- – -- – -- – -- – --
60: – -- – -- – -- – -- – -- – -- – -- – --
70: – -- – -- – -- – --

Checking for firmware version

GrovePi has firmware version: 1.2.7
’’’