Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PiFace Digital 2 isn't detected #36

Open
peteruran opened this issue Jan 3, 2018 · 9 comments
Open

PiFace Digital 2 isn't detected #36

peteruran opened this issue Jan 3, 2018 · 9 comments

Comments

@peteruran
Copy link

peteruran commented Jan 3, 2018

Evening folks,

I recently got my hands on a PiFace Digital 2, however, I'm struggling to make my Raspberry detect it.

Following the instructions found on the official page, I started by installing the latest Rasbian Stretch Lite and getting everything up to date:

    sudo apt-get update
    sudo apt-get upgrade
    sudo apt-get dist-upgrade

I enabled SPI using raspi-config and downloaded the necessary modules with pip, since they weren't in the repositories anymore:

    sudo pip3 install pifacedigitalio
    sudo pip3 install pifacecommon

Full of hope, I started a Python3 session and wrote the commands found on this page:

    import pifacedigitalio
    pfd = pifacedigitalio.PiFaceDigital()

For my efforts however, I was awarded with this error message:

    Traceback (most recent call last):
        File "<stdin>", line 1, in <module>
        File "/usr/local/lib/python3.5/dist-packages/pifacedigitalio/core.py", line 82, in __init__self.init_board()
        File "/usr/local/lib/python3.5/dist-packages/pifacedigitalio/core.py", line 107, in init_board
    h=self.hardware_addr, b=self.bus, c=self.chip_select))pifacedigitalio.core.NoPiFaceDigitalDetectedError: No PiFace Digital board detected (hardware_addr=0, bus=0, chip_select=0).

Thus, I've found a bunch of people with the same problem but no solution. I've double checked everything a few times and made sure SPI is enabled. Any suggestions?

@Les-A
Copy link

Les-A commented Jan 15, 2018

Further to the above, on an old Pi model B (256mb) with old style PiFace, I upgraded from the previous release of Jessie to 4.9.59+ today, installed pifacecommon and pifacedigitalio for Python 2 using PIP and receive a similar problem ...
$ python reboot.py

file contains:

import pifacedigitalio as pfio
pfio.init(True)

which results in:

Traceback (most recent call last):
File "reboot.py", line 16, in <module>
pfio.init(True) # Init Piface - 'True' resets all leds and relays
File "/usr/local/lib/python2.7/dist-packages/pifacedigitalio/core.py", line 166, in init
raise failed_boards[0]
`pifacedigitalio.core.NoPiFaceDigitalDetectedError: No PiFace Digital board detected (hardware_addr=0, bus=0, chip_select=0).

SPI has been enabled via raspi-config. The PiFace board is configured as address zero.

For completeness, pfio.init() also yields the same result.
`

@feanor12
Copy link

feanor12 commented Mar 7, 2018

i found this today
https://www.raspberrypi.org/forums/viewtopic.php?t=196248
fixed it for me(NoPiFaceDigitalDetectedError)

@feanor12
Copy link

feanor12 commented Mar 7, 2018

Looks like a duplicate of piface/pifacecommon#24

@henkwiedig
Copy link

The fix in spy.py only fixes the issue in pyhton3.
The issue still exists in python2.7
@Les-A Do you also have python 3 installed ?

pyhton3

root@raspberrypi:~# grep speed /usr/lib/python3/dist-packages/pifacecommon/spi.py
            speed_hz=ctypes.c_uint32(100000) 
root@raspberrypi:~# python3
Python 3.5.3 (default, Jan 19 2017, 14:11:04) 
[GCC 6.3.0 20170124] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import pifacedigitalio as pfio
>>> pfio.init(True)
>>> 

pyhton2.7

root@raspberrypi:~# grep speed /usr/lib/python2.7/dist-packages/pifacecommon/spi.py
            speed_hz=ctypes.c_uint32(100000)   
root@raspberrypi:~# python2
Python 2.7.13 (default, Nov 24 2017, 17:33:09) 
[GCC 6.3.0 20170516] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import pifacedigitalio as pfio
>>> pfio.init(True)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "build/bdist.linux-armv7l/egg/pifacedigitalio/core.py", line 166, in init
pifacedigitalio.core.NoPiFaceDigitalDetectedError: No PiFace Digital board detected (hardware_addr=0, bus=0, chip_select=0).
>>> 

@klint-k
Copy link

klint-k commented Apr 12, 2018

I found this on some website. if I find it again I will edit and insert the link.

I guess that there is something about speed from what the person said on that forum.

Here is the culprit;
speed_hz=ctypes.c_uint32(15000)

it needs to be added.

So;
sudo find / -name spi.py > search_result.txt
find and replace all the spi.py with this code.

import posix
import ctypes
from fcntl import ioctl
from .linux_spi_spidev import spi_ioc_transfer, SPI_IOC_MESSAGE


SPIDEV = '/dev/spidev'
SPI_HELP_LINK = "http://piface.github.io/pifacecommon/installation.html" \
    "#enable-the-spi-module"


class SPIInitError(Exception):
    pass


class SPIDevice(object):
    """An SPI Device at /dev/spi<bus>.<chip_select>."""
    def __init__(self, bus=0, chip_select=0, spi_callback=None):
        """Initialises the SPI device file descriptor.

        :param bus: The SPI device bus number
        :type bus: int
        :param chip_select: The SPI device chip_select number
        :param chip_select: int
        :raises: InitError
        """
        self.bus = bus
        self.chip_select = chip_select
        self.spi_callback = spi_callback
        self.fd = None
        spi_device = "%s%d.%d" % (SPIDEV, self.bus, self.chip_select)
        self.open_fd(spi_device)

    # def __del__(self):
    #     if self.fd is not None:
    #         self.close_fd()

    def open_fd(self, spi_device):
        try:
            self.fd = posix.open(spi_device, posix.O_RDWR)
        except OSError as e:
            raise SPIInitError(
                "I can't see %s. Have you enabled the SPI module? (%s)"
                % (spi_device, SPI_HELP_LINK)
            )  # from e  # from is only available in Python 3

    def close_fd(self):
        posix.close(self.fd)
        self.fd = None

    def spisend(self, bytes_to_send):
        """Sends bytes via the SPI bus.

        :param bytes_to_send: The bytes to send on the SPI device.
        :type bytes_to_send: bytes
        :returns: bytes -- returned bytes from SPI device
        :raises: InitError
        """
        # make some buffer space to store reading/writing
        wbuffer = ctypes.create_string_buffer(bytes_to_send,
                                              len(bytes_to_send))
        rbuffer = ctypes.create_string_buffer(len(bytes_to_send))

        # create the spi transfer struct
        transfer = spi_ioc_transfer(
            tx_buf=ctypes.addressof(wbuffer),
            rx_buf=ctypes.addressof(rbuffer),
            len=ctypes.sizeof(wbuffer),
            speed_hz=ctypes.c_uint32(15000)
        )

        if self.spi_callback is not None:
            self.spi_callback(bytes_to_send)
        # send the spi command
        ioctl(self.fd, SPI_IOC_MESSAGE(1), transfer)
        return ctypes.string_at(rbuffer, ctypes.sizeof(rbuffer))

@jwarnier
Copy link

I got the same issue on a Pi 1 model B+, and the suggested fix does not work.

I guess it probably has a different max speed?
I tried (pure guess) already the following values, without success: 100000, 1000000, 150000, 15000
How do I know/compute the actual value to use?

Thanks

@henkwiedig
Copy link

it tuned out to be some kind of compile cache issue for me.
reinstalled raspian and before running any python code i applied the fix in spy.py
this fixed the isssue

@spiro-trikaliotis
Copy link

The fix for this issue for Python3 is already in the git repository.
However, if one installs pifacecommon from the official Raspbian server, one gets version 4.2.1 (which is correct), but it does not include the necessary patch piface/pifacecommon@d4c5689?diff=unified. This is annoying, especially since there is no hint that the version here and in the repository differ.

Does anyone know how to access the correct bug tracker, so this can be fixed?

@montgrand
Copy link

RPi2 B + Piface Digital 2 isn't detected.
python3-pifacedigitalio, newest version (3.1.0-2) installed.

pi@raspberrypi:~ $ python3 /usr/share/doc/python3-pifacedigitalio/examples/blink.py
Traceback (most recent call last):
File "/usr/share/doc/python3-pifacedigitalio/examples/blink.py", line 9, in
pifacedigital = pifacedigitalio.PiFaceDigital()
File "/usr/lib/python3/dist-packages/pifacedigitalio/core.py", line 82, in init
self.init_board()
File "/usr/lib/python3/dist-packages/pifacedigitalio/core.py", line 107, in init_board
h=self.hardware_addr, b=self.bus, c=self.chip_select))
pifacedigitalio.core.NoPiFaceDigitalDetectedError: No PiFace Digital board detected (hardware_addr=0, bus=0, chip_select=0).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants