dhhagan / py-opc

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

Trouble in establishing communication #60

Closed Zanati123 closed 6 years ago

Zanati123 commented 6 years ago

Dear David, I am a 3rd year university student doing a small project requiring to interface the alphasense sensor with RPi. I am having difficulties to establish communication and was hoping you can help me to solve the issue and/or guide me through the process.

A brief summary of the steps taken so far:

I adjusted Dancing Quanta’s pyusbiss-master/usbiss/init.py line 55/60 syntax positioning with the if statements, as that was the first error. The next error was on line 7 of the suggested script, alpha=opc.OPCN2(spi) shows the following error:

_>>>The module ID is 7 The firmware version is 0x7 The current operating mode is 0x2 The serial number is b'00032122' Initializing USB-ISS in SPI mode with 1 spi_mode and 11 sck_divisor Traceback (most recent call last): File "/home/pi/opc2/opc/init.py", line 55, in init self.firmware['version'] = int(re.findall("\d{3}", self.read_info_string())[-1]) File "/home/pi/opc2/opc/init.py", line 197, in read_info_string self.cnxn.xfer([0x3F]) File "/home/pi/opc2/usbiss/init.py", line 146, in xfer raise RuntimeError('USB-ISS: Transmission Error') RuntimeError: USB-ISS: Transmission Error

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "/home/pi/opc2/opc/init.py", line 59, in init self.firmware['version'] = int(re.findall("\d{1}", self.read_info_string())[-1]) File "/home/pi/opc2/opc/init.py", line 197, in read_info_string self.cnxn.xfer([0x3F]) File "/home/pi/opc2/usbiss/init.py", line 146, in xfer raise RuntimeError('USB-ISS: Transmission Error') RuntimeError: USB-ISS: Transmission Error

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "/home/pi/opc2/test5.py", line 7, in alpha = opc.OPCN2(spi) File "/home/pi/opc2/opc/init.py", line 238, in init super(OPCN2, self).init(spiconnection, model='N2', **kwargs) File "/home/pi/opc2/opc/init.py", line 64, 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.”

I am running on python 3.4.2 and have triple checked the connection from Rpi to alphasense opc-n2. Do you have any advice?

Thank you, Zanati123

DancingQuanta commented 6 years ago

Hi. I am the author of pyusbiss. I made a patch with if mistake. Please can you test it by downloading the HEAD not releases? Also I will update the documentation in py-opc about new changes to pyusbiss. Please change spi_mode = 2 to spi_mode = 1

DancingQuanta commented 6 years ago

Hello, I have released a new version of pyusbiss 0.2.0 which you can install via pip install pyusbiss. This version is a major revision and so I have updated the instructions in https://github.com/dhhagan/py-opc/pull/61.

DancingQuanta commented 6 years ago

Have you made any progress?

Zanati123 commented 6 years ago

Hi DancingQuanta,

Yes with your new release of pyusbiss 0.2.0, communication was achieved to the OPC sensor. spi_mode was set to 1 and setting the firmware to 18.2 made it work for me.

from usbiss.spi import SPI
import opc

spi=SPI("/dev/ttyACM0")
spi.mode=1
spi.max_speed_hz = 500000

alpha = opc.OPCN2(spi, firmware=(18.2))

print( "Communication Status:  ", alpha.ping())
DancingQuanta commented 6 years ago

Great. Can you close this issue please?