Git Product home page Git Product logo

pifacecommon's People

Contributors

johan162 avatar psytester avatar tompreston avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

pifacecommon's Issues

SPI Device not found

The Error: "pifacecommon.spi.SPIInitError: I can't see /dev/spidev0.0. Have you enabled the SPI module?"

After following all the instructions I still get the error.

SPI is enabled, raspberry pi b, raspbien fully updated

less /proc/modules shows
spi_bcm2708 4475 0 - Live 0xbf000000

OverflowError: Python int too large to convert to C long

I get this exception (v1.1 and also in your last Jun 25 checkin):


Traceback (most recent call last):
File "/home/pi/sprinklermory/scheduler.py", line 90, in run
if a_rain_sensor.rain_detected and a_rain_sensor.watering_percent > watering_percent_from_rain_sensor:
File "/home/pi/sprinklermory/rainsensor.py", line 135, in rain_detected
rain_detected = ioserver.get_input_value(self.input_index)
File "/home/pi/sprinklermory/ioserver.py", line 123, in get_input_value
state = _pfd.input_pins[inputIndex].value;
File "/usr/local/lib/python3.2/dist-packages/pifacecommon/core.py", line 190, in value
return 1 ^ super().value
File "/usr/local/lib/python3.2/dist-packages/pifacecommon/core.py", line 170, in value
self.board_num)
File "/usr/local/lib/python3.2/dist-packages/pifacecommon/core.py", line 319, in read_bit
value = read(address, board_num)
File "/usr/local/lib/python3.2/dist-packages/pifacecommon/core.py", line 368, in read
op, addr, data = spisend((devopcode, address, 0)) # data byte is not used
File "/usr/local/lib/python3.2/dist-packages/pifacecommon/core.py", line 411, in spisend
ioctl(spidev_fd, iomsg, ctypes.addressof(transfer))

OverflowError: Python int too large to convert to C long

It's pretty random, but get it after a while.

The exception seem to appear when ctypes.addressof(transfer) return a very big number that fit only in an unsigned int. I believe ctypes.addressof is not necessary here but I'm not familiar with ctypes yet.
I get a fix that seem to works:

diff --git a/pifacecommon/core.py b/pifacecommon/core.py
index c1d5577..9584f0f 100644
--- a/pifacecommon/core.py
+++ b/pifacecommon/core.py
@@ -408,7 +408,7 @@ def spisend(bytes_to_send):

  # send the spi command (with a little help from asm-generic
 iomsg = _IOW(SPI_IOC_MAGIC, 0, ctypes.c_char * ctypes.sizeof(transfer))
  • ioctl(spidev_fd, iomsg, ctypes.addressof(transfer))
  • ioctl(spidev_fd, iomsg, transfer)
    return ctypes.string_at(rbuffer, ctypes.sizeof(rbuffer))

SPI device error

As I mentioned in issue #5, I changed my piface app to use python-pifacecommon 3.1.2-1 and python-pifacedigitalio 2.1.0-1 from the raspian repos 3 weeks ago and everything has been working fine. However, I did a apt-get dist-upgrade today which pulled in python-pifacecommon 4.0.0-1 and python-pifacedigitalio 3.0.0-1 I now get the following error reported. I did not change anything else (i.e. no change to my code).

Exception in thread Thread-1:
Traceback (most recent call last):
  File "/usr/lib/python2.7/threading.py", line 552, in __bootstrap_inner
  File "/usr/lib/python2.7/threading.py", line 505, in run
  File "/home/pi/pialarm/pialarm", line 252, in scanner
  File "/home/pi/pialarm/env/src/pifacedigitalio-master/pifacedigitalio/core.py\
", line 194, in digital_read
  File "/home/pi/pialarm/env/src/pifacedigitalio-master/pifacedigitalio/core.py\
", line 45, in __init__
  File "/home/pi/pialarm/env/src/pifacecommon-master/pifacecommon/mcp23s17.py",\
 line 91, in __init__
  File "/home/pi/pialarm/env/src/pifacecommon-master/pifacecommon/spi.py", line\
 32, in __init__
  File "/home/pi/pialarm/env/src/pifacecommon-master/pifacecommon/spi.py", line\
 44, in open_fd
SPIInitError: I can't see /dev/spidev0.0. Have you enabled the SPI module? (htt\
p://piface.github.io/pifacecommon/installation.html#enable-the-spi-module)

IOError: [Errno 24] Too many open files

I aptitude purged those 2 packages, installed the latest versions for both from master branch on github, built the spi and gpio udev rules, permissions/groups, blacklist removal, etc by hand - but still get the exact same error.

I've checked the owner+group+permissions on /dev/spidev* and on /sys/class/gpio/ and my user and it all looks fine. So the udev rules are installed and working. My user is in correct spi and gpio groups and I have rebooted many times.

spi.py OSError (9) Bad File Descriptor

I have a function that is called when the navigation rocker is pushed to the right:

    def update_display(self, line):
        print('Updating display')
        lcd = self.__cad.lcd
        lcd.home()
        lcd.set_cursor(0, 1)
        lcd.write(' ' * pifacecad.lcd.LCD_WIDTH)
        lcd.set_cursor(0, 1)
        print('Writing {}'.format(line))
        lcd.write(line)

The switch event listener is set up like so:

# ROCKER_RIGHT = 7
listener = pifacecad.SwitchEventListener(chip=cad)
listener.register(ROCKER_RIGHT, pifacecad.IODIR_ON, platypi.next_option)
listener.activate()

On the fifth (5th) time I press the rocker right I ALWAYS get the following error:

Exception in thread Thread-1:
Traceback (most recent call last):
  File "/usr/lib/python3.4/threading.py", line 921, in _bootstrap_inner
    self.run()
  File "/usr/lib/python3.4/threading.py", line 869, in run
    self._target(*self._args, **self._kwargs)
  File "/usr/lib/python3.4/site-packages/pifacecommon/interrupts.py", line 339, in handle_events
    function(event)
  File "platypi.py", line 58, in next_option
    self.update_display(os.path.basename(self.__options[self.__index]))
  File "platypi.py", line 78, in update_display
    lcd.home()
  File "/usr/lib/python3.4/site-packages/pifacecad/lcd.py", line 251, in home
    self.send_command(LCD_RETURNHOME)  # set cursor position to zero
  File "/usr/lib/python3.4/site-packages/pifacecad/lcd.py", line 411, in send_command
    self.control_port.register_select_pin.value = 0
  File "/usr/lib/python3.4/site-packages/pifacecommon/mcp23s17.py", line 358, in value
    self.chip.write_bit(v, self.bit_num, self.address)
  File "/usr/lib/python3.4/site-packages/pifacecommon/mcp23s17.py", line 201, in write_bit
    old_byte = self.read(address)
  File "/usr/lib/python3.4/site-packages/pifacecommon/mcp23s17.py", line 143, in read
    return self._pyver_read(address)
  File "/usr/lib/python3.4/site-packages/pifacecommon/mcp23s17.py", line 147, in _py3read
    op, addr, data = self.spisend(bytes((ctrl_byte, address, 0)))
  File "/usr/lib/python3.4/site-packages/pifacecommon/spi.py", line 74, in spisend
    ioctl(self.fd, SPI_IOC_MESSAGE(1), transfer)
OSError: [Errno 9] Bad file descriptor

Just for curiosity sake, I added a print(self.fd) in spi.py which prints "4"

Documentation

Is anyone actively maintainting the documentation ?

One problem I have is that pifacedigital docs don't line to pifacecommon docs etc.

Am familiar with sphinx so its easy to do, including branding the docs (logo) and sticking a navigation on top. (links to git, blog etc)

pip install fails

I see this new repo and decided to try it. However, I get the following:

(env)pi@pi2:~/pialarm pip install pifacecommon
Downloading/unpacking pifacecommon
  Downloading pifacecommon-2.0.0.tar.gz
  Running setup.py egg_info for package pifacecommon
    Traceback (most recent call last):
      File "<string>", line 16, in <module>
      File "/home/pi/pialarm/env/build/pifacecommon/setup.py", line 54, in <module>
        long_description=open('README.md').read() + open('CHANGELOG').read(),
    IOError: [Errno 2] No such file or directory: 'README.md'
    Complete output from command python setup.py egg_info:
    Traceback (most recent call last):

  File "<string>", line 16, in <module>

  File "/home/pi/pialarm/env/build/pifacecommon/setup.py", line 54, in <module>

    long_description=open('README.md').read() + open('CHANGELOG').read(),

IOError: [Errno 2] No such file or directory: 'README.md'

----------------------------------------
Cleaning up...
Command python setup.py egg_info failed with error code 1 in /home/pi/pialarm/env/build/pifacecommon
Storing complete log in /home/pi/.pip/pip.log

Can you also please add a small description of what this module is for, how it relates to the pifacedigitalio repo, and when we should use it instead of that repo?

I just want init(), read_bit(), and write_bit() with a single polled piface board so it seems to me that this repo is all I need, given the obscure comment at http://piface.github.io/pifacedigitalio/example.html refering me back to this repo?

Thread detector & dispatcher are not daemon threads....

I am building a daemon script to start/stop my PIFace water counter script. I use the pifacedigitalio.InputEventListener class for that but the thread launch @ activate ar enot daemon threads so when my main process hangs / be killed or stops the detector / dispatcher threads are still up... which is really annoying. Can you add a paramater 'daemon' into your activate methods to set daemon thread parameter to true or false depending of what we want ot do.

Import of errno is needed

I get this error from a keyboard interrupt:

File "/usr/lib/python2.7/dist-packages/pifacecommon/interrupts.py", line 265, in watch_port_events
if e.errno != errno.EINTR:
NameError: global name 'errno' is not defined

The import of errno is missing from interrupts.py

IOError: [Errno 2] No such file or directory: '/sys/devices/virtual/gpio/gpio25/value'

Running this stripped down test code, the subject error occurs.

!/usr/bin/python

import pifacecommon.core
import pifacecommon.interrupts
import os
import time

def print_flag(event):
print ("You pressed button" + event.pin_num)

pifacecommon.core.init()
port = pifacecommon.core.GPIOB
listener = pifacecommon.interrupts.PortEventListener(port)

listener.register(0, pifacecommon.interrupts.IODIR_ON, print_flag)

listener.activate()

results in:

Process Process-1:
Traceback (most recent call last):
File "/usr/lib/python3.2/multiprocessing/process.py", line 267, in _bootstrap
self.run()
File "/usr/lib/python3.2/multiprocessing/process.py", line 116, in run
self._target(_self._args, *_self._kwargs)
File "/usr/lib/python3/dist-packages/pifacecommon/interrupts.py", line 207, in watch_port_events
gpio25 = open(GPIO_INTERRUPT_DEVICE_VALUE, 'r') # change to use 'with'?
IOError: [Errno 2] No such file or directory: '/sys/devices/virtual/gpio/gpio25/value'

Piface2 board not detected (Rpi3 B)

Noob at this, but it looks like I'm missing a trick to get the board working.
I've got a Piface 2 and a Pi 3 B.

Started following the instructions, SPI enabled, rebooted, updates done. The Pi is set up fresh with the latest (scratch?) install.

The install commands didn't work (not found). I found alternative install instructions using PIP which did work:

pip install pifacedigitalio
pip install pifacecommon
 
for 3(.5)
pip3 install pifacedigitalio
pip3 install pifacecommon

So now I load up Python (or Python3, same problem) and try:

>>> import pifacedigitalio as pfd
>>> pfd.init()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/pi/.local/lib/python3.5/site-packages/pifacedigitalio/core.py", line 166, in init
    raise failed_boards[0]
  File "/home/pi/.local/lib/python3.5/site-packages/pifacedigitalio/core.py", line 162, in init
    init_board)
  File "/home/pi/.local/lib/python3.5/site-packages/pifacedigitalio/core.py", line 82, in __init__
    self.init_board()
  File "/home/pi/.local/lib/python3.5/site-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).

Any ideas? I've seen some people suggest reverting back to an older "jessie" build, but other topics suggest people made it work. I also saw reference to commenting out a line in a "blacklist" file, however mine is empty.

bring_gpio_interrupt_into_userspace fails on Debian Buster, Rpi3B / 3B+

Just tested the PiFace Digital 2 on just released Debian Buster, and it works great (some messing with device tree required to bring up SPI interface devices), official Debian on arm64 feels much snappier and riding upstream is "right thing to do" ™️...
However, as documented on https://wiki.debian.org/RaspberryPi3, GPIOs have to be accessed by offset of 458 in mind, which will cause bring_gpio_interrupt_into_userspace to fail:

>>> import pifacedigitalio
>>> pfd = pifacedigitalio.PiFaceDigital()
Traceback (most recent call last):
  File "/usr/local/lib/python3.7/dist-packages/pifacecommon/interrupts.py", line 385, in bring_gpio_interrupt_into_userspace
    with open(GPIO_INTERRUPT_DEVICE_VALUE):
FileNotFoundError: [Errno 2] No such file or directory: '/sys/class/gpio/gpio25/value'

During handling of the above exception, another exception occurred:

OSError: [Errno 22] Invalid argument

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.7/dist-packages/pifacedigitalio/core.py", line 82, in __init__
    self.init_board()
  File "/usr/local/lib/python3.7/dist-packages/pifacedigitalio/core.py", line 114, in init_board
    self.enable_interrupts()
  File "/usr/local/lib/python3.7/dist-packages/pifacedigitalio/core.py", line 86, in enable_interrupts
    self.gpio_interrupts_enable()
  File "/usr/local/lib/python3.7/dist-packages/pifacecommon/interrupts.py", line 232, in gpio_interrupts_enable
    bring_gpio_interrupt_into_userspace()
  File "/usr/local/lib/python3.7/dist-packages/pifacecommon/interrupts.py", line 390, in bring_gpio_interrupt_into_userspace
    export_file.write(str(GPIO_INTERRUPT_PIN))
OSError: [Errno 22] Invalid argument

If I change GPIO_INTERRUPT_PIN = 25 to GPIO_INTERRUPT_PIN = 25 + 458 everything just works ™️
I'd like to submit a small patch that does the proper GPIO offset detection by checking /sys/bus/gpio/devices...

Upgrade to 4.0 has UnboundLocalError in deinit

I just upgraded common to v4.0.0 and digitalio to v3.0.0. When I call pifacedigitalio.deinit() I now get the following message:

Exception UnboundLocalError: UnboundLocalError("local variable 'pfd' referenced before assignment",) in <bound method AmoebaTwo.del of <amoebatwo.AmoebaTwo object at 0xb69e0830>> ignored

I didn't see this previously and I'm not sure if it's causing any problems, but as its in the del it doesn't make a lot of difference.

I checked I had followed the installation instructions and all appears to be well.

Any thoughts on this? I played around with the code a bit but didn't seem to ever get to a situation with no errors. Not calling deinit is the workaround for now but I would prefer to have this cleaning up correctly.

Thanks =)

Please release new pifacecommon version 4.2.2 to get the fix for SPI speed setting

Please release a new pifacecommon v4.2.2, because we already know the facts, but there is no fix as official package.
Due to kernel change to have much higher SPI clock speed at 125Mhz (raspberrypi/linux/issues/2165) the PiFace2 Chip MCP23S17 is not longer working.
There where two commits in past.
The first one d4c5689 from 11 Nov 2017 with PR #22 / #23 with hard coded setting in pifacecommon/spi.py by adding the line speed_hz=ctypes.c_uint32(100000) to the transfer struct:

 # 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(100000) 
        )

But the related version.py was updated by #23 from outdated 4.2.0 6098a59 to already existing 4.2.1.

The second commit 25dcca1 from 16 Sep 2018 with PR #26 is passing a clock speed value from the caller,

        # 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(self.speed_hz)
)

which is more flexible and the version.py was finally updated to 4.2.2 with commit 7c6a2b3.

At the end this kind of fix is getting work again the PiFace2.
But due to missing pifacecommon v4.2.2 release an apt-get upgrade does not find this correction and a lot of people are dissatisfied.
I hit the issue and "simple" fix in past due to internet reserch where I was pointed to piface/pifacecad/issues/24, but pifacecad is not the faulty part here

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.