nmarcelo / opcn2-Arduino

C++ Library for the Alphasense OPC-N2 particle counter-Arduino
3 stars 4 forks source link

Arduino 101 output all zeros #2

Open philiporlando opened 6 years ago

philiporlando commented 6 years ago

MarcelloYung,

Thank you for adapting David Hanagan's code for Arduino! While this is extremely helpful, I was hoping to receive some additional guidance with interfacing my Arduino with the OPCN2.

I've saved your modified code in a directory labeled "opcn2" within "Arduino/libraries" directory. I am able to successfully compile and upload your "opcn2.ino" sketch onto my Arduino101. However, when using the serial monitor, the output for each variable is always zero (including the Configuration Variables output when the code is first executed).

I have the SS/CS pin connected to A2, but I'm pretty sure the correct SS pin for the Arduino101 is pin 10. The MOSI pin from the OPCN2 is connected to pin 11 on the Arduino, and the MISO on pin 12, with SCK connected to pin 13. Can you clarify which pins I should be using for the four data lines coming from the OPCN2?

If it's not a pin assignment issue, then my next guess is with incompatible logic-levels. After doing a little digging, it seems like the OPCN2 requires 5V for power, but uses 3.3V TTL for data. I am pretty sure the Arduino101 is capable of doing 3.3V TTL with 5V tolerance, but it would be great to get some clarification on this. Does interfacing the OPCN2 require a logic-level converter if using the Arduino101?

Any additional information you can provide is greatly appreciated!

Thank you, spacedSparking

nmarcelo commented 6 years ago

@spacedSparking
If you didn't solve the problem yet, here are the recomendation: 1) You need the bidirectional logic level converter, otherwise with this arduino (5V level) it is not posible to read the OPCN2 values. 2) The CS pin can be set to work in any analogic port. In the example was set to A2, then you need to connect the OPCN2-CS on pin A2. 3) The others ports must be connected according the SPI protocols and datasheet of arduino 101 and OPCN2 pin reference. Your connections seems be ok. Tell me if the you solve the problem.

beleme commented 6 years ago

MarcelloYung,

i have the problem, you can helpme please?? captura

Thank you

nmarcelo commented 6 years ago

@beleme
Perhaps you have some error in your connections. Are you using the logic converter or Arduino of 3.3V?

semajoel commented 6 years ago

Make connections using its ICSP header with SPI signals and I2C dedicated pins.

beleme commented 6 years ago

@MarcelloYung

I'm using an arduino mega and the logic converter I have it connected in this way: SS/CS pin connected to A2, but I'm pretty sure the correct SS pin for the Arduino is pin 53, the MOSI pin from the OPCN2 is connected to pin 51 on the Arduino, and the MISO on pin 50, with SCK connected to pin 52.

and another problem is that the fan is not activated

Thank you!!

semajoel commented 6 years ago

screenshot_2018-01-17-00-43-37

I use it on an arduino mega with out a logic converter, It works fine. The fun turns on automatically else you can use a fiction to turn it on.

semajoel commented 6 years ago

screenshot_2018-01-17-00-58-59

philiporlando commented 6 years ago

@beleme

The OPC-N2 has a 1-minute warm-up sequence before the fans start working.

@MarcelloYung

Have you tried using the Teensyduino with the OPC-N2? I am planning to go this route instead of using the 3.3V logic converter. The Teensy3.2 uses 3.3V TTL but is also 5V tolerant. I was just curious if this would require any edits to your source code in order to associate the correct Teensy SPI pins. On the Teensy3.2, the CS is on pin 10, MOSI is pin 11, MISO is pin 12, and SCK is pin 13.

I'll check back with more specific troubleshooting details as I make more progress.

beleme commented 6 years ago

@semajoel

thanks for the tips were help now if opc-n2 works. An question how can I save the opc-n2 data in a micro SD?

beleme commented 6 years ago

@semajoel

thank you captura1

semajoel commented 6 years ago

@beleme Your welcome. I tried many techniques last year but failed, will give it another try before the month ends.

nmarcelo commented 6 years ago

@spacedSparking I didn't try with this device, but I'm sure that it works. Be carefully with the connections and in the code only change the chip select definition (#define CS Ax) for the analog x port that you desire. Hope all run well in your project.

JoernDwigs commented 6 years ago

Hi there, I'm quite new to the topic of programming and working with a micro controller but my bachelor degree relies on an experiment with the OPC-N2. I have an Arduino Uno and already tried a couple of wiring combinations but can't manage to get anything else than zeros as output, the professors at the university are clueless too and can't help me... Sometimes the fan starts working and afterwards I can read the data from the internal SD-Card if I connect the OPC directly to my Laptop, but during the measurement the Serial Monitor sticks with the zeros. I phoned with some guy from Alphasense and he told me the pin nearest to the USB Port is pin 1 and the pin on the opposite side is pin 6, which is the very reverse sequence than in the posts above, so now I'm confused af which connections are the right ones. I can't seem to find the correct ports on the Arduino Uno I guess. Can somebody help me, please?

nmarcelo commented 6 years ago

@JoernDwigs Just now, I cannot help you. But if you still not solve your problem on the next weeks, I will return on my project with the OPCN2 , so perhaps I could help you with the diagrams that I used.

semajoel commented 6 years ago

The SPI socket is a Molex 'Pico Clasp' 6 way Housing, Part Number 501330-0600. Pins are assigned in table 2. Pin 1 on the OPC-N2 is closest to the USB micro connector. Pin Function 1 Vcc 2 SCK 3 SDO 4 SDI 5 /SS 6 GND Table 2. SPI pin assignments Please note that it is not possible to put the MISO (SDO) line into a high impedance mode (tri-state). This means that it is not possible to use the OPC on a shared SPI bus. OPC power requirement The OPC-N2 requires a 4.8 to 5.2 Volt DC supply with minimum electrical noise, this is then stepped down to a 3v3 supply (via the SPI-ISS adapter) for the SPI logic lines. The logic lines are NOT 5 volt tolerant. The OPC N2 requires 175 mA continuous (95 mA continuous with fan off and laser at low power) with a short one amp current surge at switch-on. Care must be taken that the current limit is not exceeded if multiple units are operated from of a single computer It is recommended to allow 1 second for the OPC to respond to the first SPI command after poweron and >0.5s after any control system code. (Note this is longer than on previous versions).

On Fri, Mar 2, 2018 at 6:39 AM, MarcelloYung notifications@github.com wrote:

@JoernDwigs https://github.com/joerndwigs Just now, I cannot help you. But if you still not solve your problem on the next weeks, I will return on my project with the OPCN2 , so perhaps I could help you with the diagrams that I used.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/MarcelloYung/opcn2-Arduino/issues/2#issuecomment-369810792, or mute the thread https://github.com/notifications/unsubscribe-auth/AYr7w52rqKgy5yKeyneqVIT7FWWStLeyks5taL7hgaJpZM4QeBTG .

JoernDwigs commented 6 years ago

Is there a way without using the logic level converter or do I definitively have to buy one? I connected it this way (view image), is it okay like this? Or do I have to use the ICSP-Header? If I connect the wires like in the picture, the fan starts working after a minute or so, but only if pin 2, the SCK, is not in position. If it is, the fan won't start for a reason I don't know. If the pin 2 isn't connected ad the fan runs and I put pin 2 back in the fan continues to run. Why though? schaltplan2

MattW commented 6 years ago

@beleme Can you detail what you changed? I'm in the same situation...cannot seem to communicate at all, but I feel it is set up properly. Can still communicate using the USB connector as normal with their application, so the OPC-N2 is working.

@JoernDwigs I was noticing some odd behavior with the fan as well, but have not completely troubleshot. Trying to get a clean setup to fully test. I do not however think the 5V on the arduino is enough to power the OPC-N2. I'm just using the 5V & 3.3V to power the logic level converter.

nmarcelo commented 6 years ago

@JoernDwigs as @semajoel said, the spi of the OPCN2 does not work at 5V level. You need the logic converter. In addition, your connections are ok, although, note that in the example-code the chip select (pin 5 in OPCN2) is A2 in the arduino. You have changed to pin 10 in your arduino, so be carefully to be consistent with your code. At the end, check carefully your connection, i.e. the wiring from your arduino to the OPCN2 port, since the intermediate connectors could be changing the correct sequence between the devices OPCN2 to arduino.

Also as @MattW said, the 5V of the arduino couldn't be enough to power OPCN2 powering.

I used the arduino uno like you, with a logic level converter and a external 5V power for the OPCN2.

FlyingIMuK commented 6 years ago

Thanks for all the work in this intersting materia.

I try to connect my OPC-N2 using a logical converter and an UNO. The connection seems to work because I got a reply using the OPC-N2_simple_test +++++++++++++++++++++++ digitalWrite(SS,LOW); vals[0]=SPI.transfer(0x03); digitalWrite(SS,HIGH);

delay(10);

digitalWrite(SS,LOW); vals[1]=SPI.transfer(0x00); digitalWrite(SS,HIGH);

delay(10);

Serial.println(vals[0],HEX); Serial.println(vals[1],HEX); ++++++++++++++++++++++++++++

OPC TESTING F3 F3 The OPC has not started!

++++++++++++++++++++++++++++++++

I should get "F3" and "03" and the fan should start but I get "F3" and "F3" and no fan works . It seems as if the OPC will not start.

I have also tried the opcn2.ino but the results look as if the Fan is not running.

+++++++++++++++++++++++++++++++++++ Testing OPC-N2 v18.2

Configuration Variables GSC: 1.00 SFR: 3.70 Laser DAC: 144 Fan DAC: 255 ToF-SFR: 74

Sampling Period: 14.65 PM1: 0.00 PM2.5: 0.00 PM10: 0.00

Sampling Period: 4.00 PM1: 0.00 PM2.5: 0.00 PM10: 0.00 ++++++++++++++++++++++++++++++++++++++++

The opc-n2 runs perfectly together with a RasPi. The fan starts immediatly and values are displayed. So I do not think that the OPC-N2 is defect. I have also tried an external powersource but I get a lot of "ovf" values and a sampling period of 0. The lab powersource produces precise 5V. Without external powersupply the voltage in the circuit powered by the UNO is 4.78V.

@semajoel: You wrote "It is not possible to put the MISO (SDO) line into a high impedance mode (tri-state). This means that it is not possible to use the OPC on a shared SPI bus." Will the logic converter not change the impedance, too? I get some values back from the OPC...

@beleme: Did you use the SPI-entry of the arduino for your output or did you use the adapter SPI => USB and then a serial imput?

Does anyone connect the OPC using the SPI entrance of the arduino?

JoernDwigs commented 6 years ago

@MarcelloYung @semajoel Soo, I had to wait a few days for the Logic Converter to arrive, now it's connected to the Arduino Board and the OPC-N2 (see picture). I've an external power source for the OPC and the fan runs consistently. But the results are still looking like this: Configuration Variables GSC: 0.00 SFR: 0.00 Laser DAC: 56 Fan DAC: 14 ToF-SFR: 28

Sampling Period: 0.00 PM1: 0.00 PM2.5: 0.00 PM10: 0.00

So how do I manage to get a decent Sampling Period? Or did I made a mistake somewhere? schaltplan3

nmarcelo commented 6 years ago

@JoernDwigs I am sharing the circuit. Note that the 3.3V lines of the logic level converter are connected to the OPCN2, and the 5V to the arduino. In addition, note that if you are using the connector showed in the image, between the logic level converter and the OPCN2, the lines are interchanged. Then, be carefully that each line of the SPI communication are consistently connected from the OPCN2 to the ports of the arduino . For the PCB design purposes, I am using the digital port 10 instead of A2, then, in the code this parameter must be changed.

The code is running correctly, I just have tried it.

foro

JoernDwigs commented 6 years ago

Huh, I have the plug in the grey rectangle plus the cable, the plug in the blue rectangle is completly new to me. I had to split up the cables to see which is which, enlongered them, then soldered them to the Logic Level Converter, I've attached a picture (the power supply is at the university at the moment, I'm sorry, you have to imagine it). The connections are exactly the way I presented them in the picture above. Is it possible that the error lies within this blue rectangle? 20180314_195626

MattW commented 6 years ago

Just as a point to maybe help a few folks. I was getting extremely inconsistent results. I would get response from the get info commands, but could not turn the device on. It also varied what I would get each turn-on. Most of the time, I got only F3 back....over and over and over. Solution for me was that the OPC-N2 was unable to drive the logic level converter. Tried to use some pull-up resistors and it continued to have issues. Ended up plugging the SDO line directly into the Arduino and had success. Beyond there, I still cannot use the github library...haven't troubleshot my issues all of the way yet. It works for testing and I wrote simple code to turn on/off/get info/get firmware/get readings/etc. Looking into the Arduino Uno and Mega, they are both capable of digitizing 3.3V logic, so try plugging SDO of the OPC-N2 directly back into MISO of the Arduino.

nmarcelo commented 6 years ago

@JoernDwigs Your connections seems to be fine. The connector in blue is just for the PCB connection, so you only need to verify that the SPI lines are correctly connected. Check also that all the GND lines are connected.

FlyingIMuK commented 6 years ago

@MattW have tried out your Idea with the direct connection of SDO. By the way I disconnected the SDO and found out that the OPC-N2 was starting. It seems to me that the SDO connection makes the trouble. I have tried out a 820R resistor in the SDO line between the logic converter and OPC. It seems versy strange to be but now I have the first success in connecting to the OPC-N2 with a UNO.

uno_opc-n2_1_steckplatine

Futheron I have changed in opcn2m the SPI_CLOCK to SPI_CLOC_DIV32. And now it works!!!

Unfortunatly the memory of 32KB of the UNO is not enough for me. So I want to switch to a Teensy3.5. This system has a 3.3V SPI bus, which should be more simple, but it makes trouble, too. So I am curious of your solutions with the Teensy

semajoel commented 6 years ago

@FlyinglMUK sorry for the delay, Please note that it is not possible to put the MISO (SDO) line into a high impedance mode (tri-state). This means that it is not possible to use the OPC on a shared SPI bus. This is communication from Alphasense, personally have been successful sharing SPI line with others devices before but have failed doing so with the OPCN2, have reverted to using a separate micro-controller to handle SD storage then have communication between the two micro-controller to sync processes.

On Tue, Mar 13, 2018 at 9:29 PM, FlyingIMuK notifications@github.com wrote:

Thanks for all the work in this intersting materia.

I try to connect my OPC-N2 using a logical converter and an UNO. The connection seems to work because I got a reply using the OPC-N2_simple_test +++++++++++++++++++++++ digitalWrite(SS,LOW); vals[0]=SPI.transfer(0x03); digitalWrite(SS,HIGH);

delay(10);

digitalWrite(SS,LOW); vals[1]=SPI.transfer(0x00); digitalWrite(SS,HIGH);

delay(10);

Serial.println(vals[0],HEX); Serial.println(vals[1],HEX); ++++++++++++++++++++++++++++

OPC TESTING F3 F3 The OPC has not started!

++++++++++++++++++++++++++++++++

I should get "F3" and "03" and the fan should start but I get "F3" and "F3" and no fan works . It seems as if the OPC will not start.

I have also tried the opcn2.ino but the results look as if the Fan is not running.

+++++++++++++++++++++++++++++++++++ Testing OPC-N2 v18.2

Configuration Variables GSC: 1.00 SFR: 3.70 Laser DAC: 144 Fan DAC: 255 ToF-SFR: 74

Sampling Period: 14.65 PM1: 0.00 PM2.5: 0.00 PM10: 0.00

Sampling Period: 4.00 PM1: 0.00 PM2.5: 0.00 PM10: 0.00 ++++++++++++++++++++++++++++++++++++++++

The opc-n2 runs perfectly together with a RasPi. The fan starts immediatly and values are displayed. So I do not think that the OPC-N2 is defect. I have also tried an external powersource but I get a lot of "ovf" values and a sampling period of 0. The lab powersource produces precise 5V. Without external powersupply the voltage in the circuit powered by the UNO is 4.78V.

@semajoel https://github.com/semajoel: You wrote "It is not possible to put the MISO (SDO) line into a high impedance mode (tri-state). This means that it is not possible to use the OPC on a shared SPI bus." Will the logic converter not change the impedance, too? I get some values back from the OPC...

@beleme https://github.com/beleme: Did you use the SPI-entry of the arduino for your output or did you use the adapter SPI => USB and then a serial imput?

Does anyone connect the OPC using the SPI entrance of the arduino?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/MarcelloYung/opcn2-Arduino/issues/2#issuecomment-372771236, or mute the thread https://github.com/notifications/unsubscribe-auth/AYr7w8c37INyZmJf1HJPqEPPDk5ZiMS6ks5teBAfgaJpZM4QeBTG .

JoernDwigs commented 6 years ago

Which line in the Code do I have to change when I'm using Pin 10? As I said, I'm relatively new to programming and don't know where to start. The Serial Monitor currently looks like this:

Testing OPC-N2 v18.2

Configuration Variables GSC: 0.00 SFR: 0.00 Laser DAC: 48 Fan DAC: 48 ToF-SFR: 48

Sampling Period: 2.00 PM1: 2.00 PM2.5: 9.02 PM10: 9.02

Sampling Period: 0.00 PM1: 0.00 PM2.5: 0.00 PM10: 0.00

Sampling Period: nan PM1: nan PM2.5: nan PM10: nan

Sampling Period: 0.00 PM1: 0.00 PM2.5: 0.00 PM10: 0.00

Sampling Period: 2.25 PM1: 2.00 PM2.5: 9.02 PM10: 0.00

Sampling Period: 0.00 PM1: 0.00 PM2.5: 0.00 PM10: 0.00

Sampling Period: 0.00 PM1: 0.00 PM2.5: 0.00 PM10: 0.00

nmarcelo commented 6 years ago

Dear all, Please note the change the library, on the opcn2m.h file. Thanks @dhhagan, @mahamoodalam for the advise!

elephone26 commented 6 years ago

I read all responder, but I didn't solve the problem yet. I use logic level converter with Arduino uno connection opc n2, cs/ss I use pin 10 I have also tried the opcn2.ino but the results look as if the Fan is not running.

Testing OPC-N2 v18.2

Configuration Variables GSC: ovf SFR: ovf Laser DAC: 252 Fan DAC: 252 ToF-SFR: 252

Sampling Period: ovf PM1: ovf PM2.5: ovf PM10: ovf

Thank you~

mahamoodalam commented 6 years ago

@elephone26 can you give an idea of how you have connected(wired) the Arduino Uno board to the OPC-N2 with the 5V to 3.3V logic level converter ? If you also attach an image it would be helpful to analyze better. By the way, have you tried changing the SPI_CLOCK to SPI_CLOC_DIV32 in the opcn2m.h file?

elephone26 commented 6 years ago

@mahamoodalam The pictures are my circuits. opc_bb 12179

And this is my logic level converter 12178 I am sorry , I do not know how to compile .h file, so not changing yet. Can tech me how to " changing the SPI_CLOCK to SPI_CLOC_DIV32 in the opcn2m.h file". Thank you~

mahamoodalam commented 6 years ago

@elephone26 1) In opcn2.ino replace #define CS A2 with #define CS 10 2) In opcn2m.h replace SPI.setClockDivider(SPI_CLOCK_DIV2); with SPI.setClockDivider(SPI_CLOCK_DIV32);

elephone26 commented 6 years ago

@mahamoodalam I am changing yet, but the Serial Monitor currently looks like this: all zero.

arduino3

\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ Testing OPC-N2 v18.2

Configuration Variables GSC: 0.00 SFR: 0.00 Laser DAC: 0 Fan DAC: 0 ToF-SFR: 0

Sampling Period: 0.00 PM1: 0.00 PM2.5: 0.00 PM10: 0.00

Sampling Period: 0.00 PM1: 0.00 PM2.5: 0.00 PM10: 0.00 \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ wait One minute is the same all zero and the fan is not activated. I reconnect the circuits, the Serial Monitor currently like this: \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ Testing OPC-N2 v18.2

Configuration Variables GSC: ovf SFR: ovf Laser DAC: 243 Fan DAC: 231 ToF-SFR: 207

Sampling Period: 0.31 PM1: -0.00 PM2.5: ovf PM10: 0.31

Sampling Period: 0.31 PM1: -0.00 PM2.5: ovf PM10: 0.31

\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ They look strange. Thank you~

nmarcelo commented 6 years ago

@elephone26 It seams like an error connection of the SPI. Check your connections according the comments here published. In fact, as you're using the arduino UNO, you can check one of my previous comments, where I show the diagram with the arduino UNO and the logic level converter.

elephone26 commented 6 years ago

@MarcelloYung What is the opc's pin1 give? My logic level converter to opc n2 connection is making by myself.Connection like: opc_bb My Arduino uno, logic level converter and opc n2 connection like my second commented.And I comparison other commented.I do not know where different. Thank you~

mahamoodalam commented 6 years ago

@elephone26 Just connect +5V and GND from the Arduino UNO board to the OPC and remove the SPI lines connection. After 60 seconds the fan of the OPC will start(default behavior). If the fan is not getting turned ON then the Uno board is not giving sufficient power to the OPC. If the fan is turned ON, then there is loose connection somewhere. Try to replace the wires with new one if available.

elephone26 commented 6 years ago

@mahamoodalam I connect +5V and GND from the Arduino UNO board to the OPC.After 60 seconds the fan turned ON, but connection the SPI lines the fan is not getting turned ON.I use oscilloscope to inspect the logic level converter 3.3V out put. CLK and ss/cs like: 12262 CLK and MOSI like: 12264 Can see the voltage,V(CLK)=2.08V, V(SS)=3.2V and V(MOSI)=3.03V.The voltage are not up to standard, the stanfard is 3.3V.So it's my logic level converter out of order? Will get new one? Thank you~

mahamoodalam commented 6 years ago

@elephone26 Why don't you power the Uno board from the DC power jack ? It could be that the USB power is not sufficient to drive the Arduino Uno + OPC. The logic level converter HV sides for HIGH logic should be ~5V and the corresponding LV sides should be ~3.3V.

MattW commented 6 years ago

@elephone26 I have heard that the SPI on the OPC-N2 is finicky, and I have experienced it. With that, I give you the changes to match the setup I had working. I soldered the 5V power to the USB connector on the arduino. Unsure of anything limiting current between the USB connector and the output on the board, so I just went straight to the source. I still connect the HV on the level shifter to the 5V socket on the board. The SS, SCK, SDI lines connect to the OPC-N2 thru the level shifter. THe SDO line connects directly to the MISO line on the Arduino. The level shifter (I have the same one as you) was pulling the OPC-N2 and not allow data comm. The UNO is capable of measuring 3.3V logic on the input. With this, hopefully you can at least get some responses. I also had issue where the scope was pulling the SDO line, which made it tough. End of the day, it is extremely sensitive to timing on the messages sent.

As for the fan coming on, the documentation explains this process. If the OPC-N2 senses a USB plugged in, it goes into firmware programming/data pulling from the SD card mode. If not, it checks for an SPI clock. If it sees SCK within the first 60 seconds, it goes into SPI mode. If it does not get a clock, after 60 seconds the fan turns on and it goes into the mode where it collects data and stores to the internal SD. Pulling the clock and checking to see if the fan turns on is a good way to determine if power is setup properly, but it will not come on after 60 seconds if you are set up properly for SPI.

elephone26 commented 6 years ago

@mahamoodalam Because I will use aircraft to carry OPC N2 and detect PM in the sky.So it can't be too heavy and If it can reduce weight, it is best. At this stage I just want to test the OPC N2,so I want to use the power supply directly to provide OPC N2 power.Can I take power supply out 5v,175mA give OPC N2? Connect like: opc_bb1 @MattW I don't know the 5V socket is how large the current on the uno board.I know the measurement mode need 175mA and Non-measurement mode need 95mA, After reading the user manual.I will use power supply 5v,175mA give OPC N2, OPC N2 should not be damaged? Thank you~

mahamoodalam commented 6 years ago

@elephone26 http://forum.arduino.cc/index.php?topic=70450.0

MattW commented 6 years ago

@elephone26 If it still does not work, try directly connecting the yellow wire from the OPC-N2 to the Arduino.

JoernDwigs commented 6 years ago

@MattW And if it still doesn't work despite the right connections and the changes @mahamoodalam posted? The fan works exactly as it should but still the output is nonsense...

MattW commented 6 years ago

@JoernDwigs Please explain "the fan works exactly as it should". Can you, with code, turn the fan on and off?

JoernDwigs commented 6 years ago

@MattW if I connect the external powersource to the OPC and the Arduino has power, too, the fan starts working after a minute. If I power the OPC through the USB-plug and the Arduino has power, the fan also starts after a minute. But if I use the USB-plug and Arduino has no power, the fan does not start. You posted "As for the fan coming on, the documentation explains this process. If the OPC-N2 senses a USB plugged in, it goes into firmware programming/data pulling from the SD card mode. If not, it checks for an SPI clock. If it sees SCK within the first 60 seconds, it goes into SPI mode. If it does not get a clock, after 60 seconds the fan turns on and it goes into the mode where it collects data and stores to the internal SD. Pulling the clock and checking to see if the fan turns on is a good way to determine if power is setup properly, but it will not come on after 60 seconds if you are set up properly for SPI." So I guess the SPI-Lines and the powersource is set up properly and are not the problem, but what's the problem with the incorrect output instead I wonder.

FlyingIMuK commented 6 years ago

In my setup I need a resistor in the MISO line. 100R is enough. Without this resistor the system UNO-OPC will not work in my setup. Further I have not found out the reason why the connection Teensy3.5 - OPC has not worked: Its the SPI library. The Teensyduino comes with a special version of SPI.H. The arduino SPI.H has to be archived so that you can be shure that the special SPI.H from Teensyduino is used. The teensy comes with its own SD-card reader so that a major problem how to store the data is solved, too.

JHabeck commented 6 years ago

Hello all... I've written my own Arduino code to operate the OPC-N2, but continue to get inconsistent results... after sending the appropriate commands to power the laser and fan, the sensor will return F3 (as expected), but then consistently returns E7 in response to the second command byte. This problem comes-and-goes as I modify connections... I am guessing it's a faulty connection issue, but am uncertain as I feel like I've tried everything. Any thoughts? Please help!

bvlabx commented 6 years ago

Hi All, I am entering this communication just to share my experience with the communication between Arduino and OPC-N2 sensor and how I fixed it. So, as many of you reported here, by connecting OPC-N2 to Arduino through level converter and using the modified library and example sketch of MarcelloYung, I also got zeros as an output in my serial monitor and the fan of the OPC-N2 was not turning. My connections were as described above (the Arduino UNO standard SPI pins and A2 as CS). I've tried all the described solutions in this conversation and nothing fixed my problem. I knew already that the problem is not in the OPC-N2 sensor, because I managed to connect it with Particle Photon and it was working without any issues. Then I suspected also the logic converter ... my first replacement attempt with another one did not change the results. Then after some time of searching and trying other solutions I once again replaced the level converter with a third type (Adafruit 4-channel I2C-safe Bi-directional Logic Level Converter - BSS138) and then .... everything was working as expected, the fan was on and PM data were not zeros anymore. I did not investigated further what is the difference between the converters that I tried, but clearly that was the problem in my case. I am attaching a picture of the converters that I've tried. image image

@MarcelloYung Thank you for the great work.

jstarks19 commented 5 years ago

Hi there, So i have been working with the N2 for a week or so now and i have it up and running thanks to some of the comments in this thread. However, like @JoernDwigs, my N2 only starts up if the CLK pin is removed. Then if you plug it back in it starts actually transmitting the correct data. Obviously i don't want to unplug and replug in a pin if i don't have to. Does anyone know of a solution to this problem? might i need a pull down resistor? I'm a little new to this but i just don't understand why it only works if that pin is removed and placed back in.

jstarks19 commented 5 years ago

well in the course of 10 minutes i figured out the issue. If you are having this issue as well, DO NOT CHANGE THE .h FILE. People in this thread were saying to switch CLOCK_DIV2 to CLOCK_DIV32, do not do this. It is not necessary. The only thing i needed to do to get it working was bypass the logic converter for pin 3 on the N2. Connect that pin directly to D12 on the arduino and you should get the appropriate readings, provided everything is wired up correctly.