E
@Oridroo said in How to read out the output of 'ezPyro SMD I2C Pyroelectric Infrared Sensor' via I2C command?:
Would you please explain a bit how you did this calculation, like why you divided it by 4 and then right shifted?
No, not and but OR, shift a binary number to left is equal to multiply this number by 2, shift a binary number to rigth is equal to divide this number by 2. This work for all power of 2 value.
My question is, why we are shifting the bits to get the decimal value?
Your sensor compute a value between 0 and (2^24-1), then we need to transfer this value by i2c bus, but i2c bus can only transport bytes by bytes. So manufacturer say in datasheet the sensors send the on i2c 3 bytes, the first byte is [23..16] bits of this number, the next is [15..8] bits of this value and the last is [7..0] of this value. So we have a byte array[3] of 8 bit after reading on i2c. To compute this in decimal we have to shift the first byte of array by 16 bits (or multiply by 65536 it's same result), the second byte as to be shifted by 8 bits (or multiply by 256 it's same result) and the last byte is added to the value.
For the time being, my current working code is as below. I was getting continuous "OSError: I2C bus error" until I added one delay in between print("Analogue:", analog) & ana_sett = i2c.writeto_mem(0x65, 0x14, analog)
The code was executing till printing 'Analogue' and then showing that I2C error. Please suggest me if you have any recommendation for the programme.
No idea why you have this, but for me it's mean that the sensors doesn't be ready to anwser to the command.
You can use smaller delay if you use time.sleep(0.1) you have 100 ms delay