pcfens / RaspberryPi-AS3935

A basic library for working with the AS3935 that's connected to the Raspberry Pi.
Other
52 stars 24 forks source link

several coments on AS3935 library #19

Closed IshikawaHiroshi closed 9 years ago

IshikawaHiroshi commented 9 years ago

Thank you very much for your wonderful Python library about AS3935.

When I installed AS3935 library on RaspberryPi and experimented, there were several defects, so it'll be reported.

About class RPi_AS3935

  1. set_indoors(True) registers [0x00] isn't set right . It's better to change it as follows.

def set_indoors(self, indoors):
    self.read_data()
    if indoors:
        write_value = (self.registers[0x00] & 0xC1) | (0b10010 << 1) #0b10010:AEF indoor
    else:
        write_value = (self.registers[0x00] & 0xC1) | (0b01110 << 1) #0b01110:AEF outdoor
    self.set_byte(0x00, write_value)

  1. calibrate(tun_cap=0x0F) There is a defect . It's better to add 1 line.

def calibrate(self, tun_cap=None):
    """Calibrate the lightning sensor - this takes up to half a second and is blocking"""
    time.sleep(0.08)
    self.read_data()
    if tun_cap is not None:
        if tun_cap < 0x10 and tun_cap > -1:
            self.set_byte(0x08, (self.registers[0x08] & 0xF0) | tun_cap)
            time.sleep(0.002)
        else:
            raise Exception("Value of TUN_CAP must be between 0 and 15")
    self.set_byte(0x3D, 0x96)
    time.sleep(0.002)
    self.read_data() #add this line
    self.set_byte(0x08, self.registers[0x08] | 0x20)
    time.sleep(0.002)
    self.read_data()
    self.set_byte(0x08, self.registers[0x08] & 0xDF)
    time.sleep(0.002)

pcfens commented 9 years ago

Hi @IshikawaHiroshi - Thanks for finding these issues. I've fixed the first part, but could you elaborate on what's broken in part 2?

I read the documentation as though nothing should be modifying the 0x08 register other than us. If that's true, then adding the extra read seems like it might slow things down when we don't need to. Could you explain what I'm missing here?

IshikawaHiroshi commented 9 years ago

I'm sorry. I experimented on part 2 once again. It was my misunderstanding. It wasn't necessary to add self.read_data(). Thank you very much for your quick answer.

pcfens commented 9 years ago

Thanks for getting back to me so quickly.

I've pushed an updated version (0.1.0) to PyPI that contains the fix. Thanks again for your help.

IshikawaHiroshi commented 9 years ago

I'd like to make a comment once again about part 2. Next is test program setting 32pF.


!/usr/bin/python

from RPi_AS3935 import RPi_AS3935 sensor = RPi_AS3935(address=0x00, bus=1) sensor.calibrate(tun_cap=0x04) #32pF sensor.read_data() print (sensor.registers[0x08])


4 has to be printout, but 0 is output. To avoid this ,as it was proposed last time, inside "def calibrate(self, tun_cap=None)", self.read_data () should be added.

pcfens commented 9 years ago

I think this was fixed by moving the read to before the first time we set 0x08 bit 5.

I've uploaded a new version to PyPI and tagged it - let me know if you're still having issues.

IshikawaHiroshi commented 9 years ago

Thank you very much. I agree to new version.