dhhagan / py-opc

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

ERROR: opc: Could not parse the firmware version from #76

Closed mc13756 closed 6 years ago

mc13756 commented 6 years ago

I tried to run the code and I got the following errors:

ERROR:opc:Could not parse the fimrware version from ???????????????????????????????????????????????????????????? Traceback (most recent call last): File "/home/pi/.local/lib/python3.5/site-packages/opc/init.py", line 77, in init self.firmware['version'] = int(re.findall("\d{3}", infostring)[-1]) IndexError: list index out of range

IndexError: list index out of range Traceback (most recent call last): File "/home/pi/Desktop/opc_test_3.py", line 31, in alpha = OPCN2(spi) File "/home/pi/.local/lib/python3.5/site-packages/opc/init.py", line 293, in init super(OPCN2, self).init(spi_connection, model='N2', **kwargs) File "/home/pi/.local/lib/python3.5/site-packages/opc/init.py", line 71, in init raise FirmwareVersionError(msg) opc.exceptions.FirmwareVersionError: Your firmware version could not be automatically detected. This is usually caused by bad wiring or a poor power supply. If niether of these are likely candidates, please open an issue on the GitHub repository at https://github.com/dhhagan/py-opc/issues/new. Another option would be to increase the max_cnxn_retries variable if you feel the serial communication is being held up for some reason. Can you please help me solve this? I have no idea where these errors come from

dhhagan commented 6 years ago

Hi @mc13756 The error comes from not being able to correctly parse the firmware version of the OPC. Often, this is caused by a wiring issue, power issue, or sometimes a code issue. Can you please let us know which version of the software you are using (opc.__version__) and post the code you used to get to this point?

mc13756 commented 6 years ago

I am using opc.N2 firmware version 18.2 and I used the following code:

import spidev import opc spi = spidev.SpiDev() spi.open(0, 0) spi.mode = 1 spi.max_speed_hz = 500000 try: alpha = opc.OPCN2(spi) except Exception as e: print ("Startup Error: {}".format(e)) alpha.on() for key, value in alpha.histogram().items(): print ("Key: {}\tValue: {}".format(key, value)) alpha.off()

dhhagan commented 6 years ago

Thanks for that information. Which version of the py-opc library are you using? You can get it by issuing the command opc.__version__; you can also get it by running $pip list at the terminal and finding the version number of the package.

mc13756 commented 6 years ago

I am using the library py-opc (1.6.0)

dhhagan commented 6 years ago

Thanks. How is it wired up? I assume you are using the GPIO pins? How is it being powered?

mc13756 commented 6 years ago

Yes, I am using the GPIO pins. I give 4.6 V through an external battery. I've already checked the wiring connection and it's working fine.

dhhagan commented 6 years ago

Ahh okay. Have you verified the OPC-N2 will work with 4.6V? I believe it requires at least 4.8VDC and > 250 mA. You could test it by simply plugging the battery into the micro-USB slot on the OPC; it will start up by itself after a minute and log data internally. You can then grab that data via the micro-USB slot and see if it makes sense.

mc13756 commented 6 years ago

I increased the voltage to 4.9 V with the same result. Also, I tried the following code too, in order to get the results analytically:

https://gist.github.com/dhhagan/bfb17459f0067a120f09?signup=true

Sometimes the code starts compiling and I get an error at line 83 and sometimes I have the same result as the previous code. Error: opc: Firmware version is invalid for this device.

dhhagan commented 6 years ago

Hmm. Can you draw the wiring diagram. It's fairly easy to mix up MISO and MOSI, so I'd like to rule that out..

mc13756 commented 6 years ago

37278118_10217657498454997_2256412015855665152_n

metallicano commented 6 years ago

how can i now what firmaware version am using?

dhhagan commented 6 years ago

Hi @metallicano; are you able to connect to the device? If so, you can use either read_information_string() or read_firmware_version().

dhhagan commented 6 years ago

@mc13756 This seems like a wiring issue (hopefully an easy fix!). According to this diagram, you should have the following:

If you haven't already seen this, the instructions can be found here.

Let me know if this doesn't work.

mc13756 commented 6 years ago

I've checked the wiring and is just like you mentioned above. I run the extended version of code https://gist.github.com/dhhagan/bfb17459f0067a120f09?signup=true and I got the following error.

ERROR:opc:Firmware version is invalid for this device. Traceback (most recent call last): File "/home/pi/Desktop/opc_test_3.py", line 31, in alpha = OPCN2(spi) File "/home/pi/.local/lib/python3.5/site-packages/opc/init.py", line 301, in init raise FirmwareVersionError("Your firmware is not yet supported. Only versions 14-18 are currently supported.") opc.exceptions.FirmwareVersionError: Your firmware is not yet supported. Only versions 14-18 are currently supported

Also, when I tried to install py-opc by typing: pip install py-opc [--upgrade] in a terminal I got: "Invalid requirement: '[--upgrade]' so I've installed it by typing only: pip install py-opc

dhhagan commented 6 years ago

@mc13756 Try pip install py-opc --upgrade - the brackets are just to indicate it is optional

mc13756 commented 6 years ago

ok. thank you. It seems like OPC works randomly. Sometimes I got the following error:

ERROR:opc:Firmware version is invalid for this device. Traceback (most recent call last): File "/home/pi/Desktop/opc_test_3.py", line 31, in alpha = OPCN2(spi) File "/home/pi/.local/lib/python3.5/site-packages/opc/init.py", line 301, in init raise FirmwareVersionError("Your firmware is not yet supported. Only versions 14-18 are currently supported.") opc.exceptions.FirmwareVersionError: Your firmware is not yet supported. Only versions 14-18 are currently supported

Sometimes the code runs normally and I got numbers every 10 seconds, and some other times it looks like it runs ok but I got only zeros. In this case the OPC's fan isn't working and I get false on turning ON or OFF the opc.

Turning on the opc ON: False

or

Turning off the opc OFF: False

dhhagan commented 6 years ago

@mc13756 Interesting - the script your using is pretty outdated (from 2015, I think). I would take a look at the most up-to-date docs for reference. When did you buy the OPC and do you have the SPI-USB connector for debugging purposes? Your OPC is most likely v18.2, but I can't be sure..

mc13756 commented 6 years ago

I think we bought the OPC on 2015 and our version is 18.2. Yes, I have the SPI-USB connentor

dhhagan commented 6 years ago

@mc13756 Could you try using the SPI-USB connector and then using the library utilizing pyusbiss just to check to make sure it's working? Or even use the Alphasense software to double check? I still think there is a poor connection somewhere or something like that. Maybe @DancingQuanta has some ideas?

metallicano commented 6 years ago

hi , the problem persist , but in the end of the text i have this : your firmware is not supported :C

metallicano commented 6 years ago

now the code runs but sometimes XD,

dhhagan commented 6 years ago

@metallicano Can you post the code and wiring you're using?

metallicano commented 6 years ago

import spidev import opc from time import sleep

spi = spidev.SpiDev() spi.open(0, 0) spi.mode = 1 spi.max_speed_hz = 500000

alphasense = opc.OPCN2(spi) alphasense.on() sleep(1) print (alphasense.read_info_string()) print (alphasense.histogram()) alphasense.off()

metallicano commented 6 years ago

the wiring is the same : SCK -> GPIO 14, Pin 23 SDO/MISO -> GPIO 13, Pin 21 SDI/MOSI -> GPIO 12, Pin 19 /SS -> GPIO 10 or 11, Pins 24, 26

metallicano commented 6 years ago

hi , problem solved , thanks for all 💯

mc13756 commented 6 years ago

Hello! @dhhagan I changed my breadboard connection with a more stable wiring method and the firmware version error doesn't appear any more. At least for now... The code runs normally. Is it normal to get decimal numbers? I was waiting to see integers, considering that OPC counts particles.

DancingQuanta commented 6 years ago

The decimals could be an average. Can you show the data you are getting please?

dhhagan commented 6 years ago

Hey @mc13756 The reason you are getting decimals is because the default argument for number_concentration is True (read more about it in the docs). Thus, the number concentration in units of #/cc is being returned rather than the raw count. If you want the raw count, simply set number_concentration=False.

mc13756 commented 6 years ago

How can I get access to change the number_concentration to False?

dhhagan commented 6 years ago

@mc13756 It's just an argument to opc.histogram(). So if you wanted to return the values as a raw histogram, you would do opc.histogram(False) or opc.histogram(number_concentration=False).

mc13756 commented 6 years ago

I changed the argument to False and everything looks to work normally.

Thank you very much!!!

dhhagan commented 6 years ago

Good to hear, @mc13756: just be aware that the number you are seeing is the total number of particles in each bin since the last time you called either pm() or histogram(). In doing the conversion to #/cc, I was accounting for the sampling time and flow rate.