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

TypeError: 'module' object is not callable with Python 3.7.3 #30

Open
grilli303 opened this issue Jun 29, 2021 · 3 comments
Open

TypeError: 'module' object is not callable with Python 3.7.3 #30

grilli303 opened this issue Jun 29, 2021 · 3 comments

Comments

@grilli303
Copy link

Hi there
I tried to run demo.py with Python 3.7.3 and get the following error:

Traceback (most recent call last):
File "demo.py", line 13, in
sensor = RPi_AS3935(address=0x03, bus=1)
TypeError: 'module' object is not callable

When I run demo.py with Python 2.7.16 it works
Does someone can know, how I can modify the code to make it work with Python 3.7.3 ?

Kind regards, Daniel

@schorschfunke
Copy link

schorschfunke commented Aug 8, 2021

The fix is simple. Change the line "from RPi_AS3935...." in _ init _.py to "from .RPi_AS3935....".

@ivannunyadambiz
Copy link

that didn't seem to fix it...

@eelcohn
Copy link

eelcohn commented May 19, 2022

This worked for me on Python 3.7.3:

#!/usr/bin/env python
from RPi_AS3935 import RPi_AS3935

import RPi.GPIO as GPIO
import time
from datetime import datetime

GPIO.setmode(GPIO.BCM)

# Rev. 1 Raspberry Pis should leave bus set at 0, while rev. 2 Pis should set
# bus equal to 1. The address should be changed to match the address of the
# sensor. (Common implementations are in README.md)
sensor = RPi_AS3935.RPi_AS3935(address=0x03, bus=1)

sensor.set_indoors(True)
sensor.set_noise_floor(0)
sensor.calibrate(tun_cap=0x0F)


def handle_interrupt(channel):
    time.sleep(0.003)
    global sensor
    reason = sensor.get_interrupt()
    if reason == 0x01:
        print("Noise level too high - adjusting")
        sensor.raise_noise_floor()
    elif reason == 0x04:
        print("Disturber detected - masking")
        sensor.set_mask_disturber(True)
    elif reason == 0x08:
        now = datetime.now().strftime('%H:%M:%S - %Y/%m/%d')
        distance = sensor.get_distance()
        print("We sensed lightning!")
        print("It was " + str(distance) + "km away. (%s)" % now)
        print("")

pin = 17

GPIO.setup(pin, GPIO.IN)
GPIO.add_event_detect(pin, GPIO.RISING, callback=handle_interrupt)

print("Waiting for lightning - or at least something that looks like it")

while True:
    time.sleep(1.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

4 participants