dhhagan / py-opc

Python wrapper for the Alphasense OPC-N2 built around py-spidev
MIT License
30 stars 26 forks source link

How to connect to PM2.5 SPI version? #55

Closed H60gh closed 6 years ago

H60gh commented 6 years ago

I connect a PM2.5 sensor into Reaspberry pi using SPI. Then I follow the example in Python 3.4.2, but it seems "alpha/alphasense" variable does not work well and alpha.ping() returns "False". As I test, spidev works well. I switch into Python 2.7.9 ("alpha = opc.OPCN2(spi)" is modified to "alpha = opc.OPC(spi))" and now alpha is an unknown variable. How can I solve this problem?

I should mentioned that alpha.on() and alpha.off() functions work well, but it seems something is wrong during data transfer between the sensor and the Rpi.

dhhagan commented 6 years ago

Hi there @H60gh,

If alpha.ping() is returning False, then the device is connected properly, but is not returning the correct value when the SPI command is sent. Have you tried any other commands? With Python2.7, try using the OPCN2 class rather than the OPC class. Also, which version of the library are you using?

H60gh commented 6 years ago

Hi @dhhagan I have same problem in Pytho 2.7 (Warning: Data Transfer was incomplete). Also I test other commands likes "read_info_string", only blank lines are printed!

My using libraries are: py-opc (1.4.1) spidev (3.0)

H60gh commented 6 years ago

In addition, I am using GPIO pins.

H60gh commented 6 years ago

Ok. I add one minute sleep and it works. But all values are zero!!

dhhagan commented 6 years ago

Hmm. Have you tried multiple readings? How are you wiring up the device? Can you post an image or wiring diagram?

H60gh commented 6 years ago

Thank you Hagan. After multiple reading, I receive PM1, PM2.5 and PM10 values.

dhhagan commented 6 years ago

No problem. Depending on the unit you purchased, it may not physically be installed. I think Alphasense stopped adding them a couple of years ago unless you special order it (not sure why...). I add an external RHT sensor (SHT31 by Sensirion).