Code Monkey home page Code Monkey logo

Comments (44)

dhhagan avatar dhhagan commented on May 31, 2024 1

Hmm. I haven't seen errors with the SPI part of it, though there are some other errors associated with string processing since I am using the Particle-specific functions in this library (should be easy to change). I do have an Arduino-specific library that will be released as soon as I get back to the US and can test it.

from opcn2.

Xylord avatar Xylord commented on May 31, 2024 1

Hey Marcello, I tried to use your code, but I couldn't get it to compile. It would seem a bunch of types aren't being accepted by the compiler, such as u_int8, bytes and Strings. Did you go through any steps to make your code compile?
If it doesn't work, does anyone know what changes would need to be made? I'd be willing to make a working version, if I only gotta change variable types; anything more would require precise instructions.

from opcn2.

SWoto avatar SWoto commented on May 31, 2024 1

I couldn't make it work the way it was here, but when changing the opcn2m.h file to .cpp and also removed the constructor and made it a setup function, it worked.

Initializing SPI...
Testing OPC-N2 v18.2

Configuration Variables
	GSC:	1.00
	SFR:	1.47
	Laser DAC:	173
	Fan DAC:	255
	ToF-SFR:	74

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

I'll leave the .zip here in case someone might come look for a solution.

opcn2.zip

from opcn2.

paultanner avatar paultanner commented on May 31, 2024

Thx for the quick reply David.
I look forward to testing the Arduino version.

from opcn2.

dhhagan avatar dhhagan commented on May 31, 2024

Hi @paultanner Just got back from India and I will try and have this out ASAP.

from opcn2.

lshindler avatar lshindler commented on May 31, 2024

Hi @dhhagan I would like to get the opc-n2 and interface it with arduino. Will you release a library for it?
Thank you very much, bye

from opcn2.

dhhagan avatar dhhagan commented on May 31, 2024

Hey @lshindler . I do plan on releasing a seperate Arduino library, but am currently out of town and busy with another project. Which Arduino are you planning to use it with? Just curious.

from opcn2.

lshindler avatar lshindler commented on May 31, 2024

@dhhagan, I am using arduino mega for a self-financed low-cost air quality project... I am using also other alphasense gas sensor. I cannot find any library on the net to interface the opc-n2 with arduino... I only found your good intentions :)
What is your on-going project?

from opcn2.

dhhagan avatar dhhagan commented on May 31, 2024

@lshindler Awesome. Are you familiar with logi-level converters? You will need one to switch the 5V logic on the Arduino to 3v3 logic on the OPC-N2. This is one of the main reasons i haven't got around to releasing the library yet...haven't decided on the best way to deal with that!

I build networks of low-cost sensors as part of my PhD as well as working on improving the technologies/algorithms.

from opcn2.

lshindler avatar lshindler commented on May 31, 2024

@dhhagan great project! Never used logic level converter...
Good luck for your project!

from opcn2.

rtlidster avatar rtlidster commented on May 31, 2024

@dhhagan, Awesome work a very helpful guide to get the grey matter working about what's possible. i'm, interested as to see if there has been any progress with the arduino lib. Like @lshindler i'm looking into using arduino and low cost sensors to monitor air quality. i have set up a few other logging systems using some electrochemical sensors and PID's (some also alphasense) using various Arduino unos and Mega boards. One board i found particularly useful is the ethermega that has a lot of functionality bolted on already for SD logging or uploading to the web. this is the first time I've dabbled with aerosols!

from opcn2.

dhhagan avatar dhhagan commented on May 31, 2024

Hey @rtlidster . I don't really have the time to do it myself right now, but it should just be a matter of switching all of the particle specific classes (String, etc.) to base c++ (char, etc). Hopefully someone out there can take the time to do it, test it, and then send a PR.

from opcn2.

rtlidster avatar rtlidster commented on May 31, 2024

Hi @dhhagan, ok cool I might give it a go, I used to do quite a lot of c++ (Arduino/daq factory/ instrument control etc) although I don't get much time/ nowadays and I'm constantly having to relearn everything! I'll keep you posted if I get anywhere. Good luck with the PhD, sounds like a cool project! I used to postdoc at the University of York (UK) and we did quite a bit with low cost sensors (testing the long term performance and sensor to sensor variation) it might be worth checking the York atmospheric chemistry research group out if you are interested, I know a lot of work is going on there in this area and it seems to be gaining in popularity. I'm sure a few people there would be interested to hear about some of the work you are doing (if they haven't already!) :-)

from opcn2.

lshindler avatar lshindler commented on May 31, 2024

@rtlidster Do you still work in York atmospheric chemistry research group? What type of sensors and logging system have you used? Do you write some articles?

from opcn2.

rtlidster avatar rtlidster commented on May 31, 2024

@lshindler unfortunately not, i left about two years ago (but still try to keep in touch), most of the work i was involved in regarding sensors was some early inter-comparison studies using electrochemical trace gas sensors (O3, NO, NO2, SO2) and PIDs for VOC sensing. Some of the sensors were from alphasense and there were a few from other sources. As we were doing inter comparisons with the high end lab equipment or using them to support data on field work a lot of the logging was either done using Arduino (uno, mega mainly) or labjacks and then logging, calibrating and optimising using lab-view or daqfactory . we use lab view and daqfactory for logging and control of a lot of the lab instrumentation so it was very easy to just connect up some of the sensors and have them all logging in the same software (often into the same logger). We were also investigating Arduino's for logging (SD card shields etc) and wireless networks (Xbee's etc). When i left there were a few post-docs that had fellowships in this area so i would assume things have progressed quite a lot. The person to get in touch with is probably Dr Pete Edwards. There are a few publications here and here but it might just be worth getting in touch if you are interested (the group is awesome and are doing new stuff all the time). Hope that helps!

from opcn2.

semajoel avatar semajoel commented on May 31, 2024

@dhhagan how far with the Arduino library?

from opcn2.

dhhagan avatar dhhagan commented on May 31, 2024

Hi @semajoel I haven't had any free time to look at it recently...maybe after the semester ends next week I can spend a bit of time trying to get it up.

from opcn2.

semajoel avatar semajoel commented on May 31, 2024

from opcn2.

nmarcelo avatar nmarcelo commented on May 31, 2024

I have modified the code for Arduino and it works: I have not enough experience with github, then I have upload to my repository. This is the link:

https://github.com/MarcelloYung/opcn2-Arduino

Thanks #dhhagan

from opcn2.

nmarcelo avatar nmarcelo commented on May 31, 2024

Hi @Xylord I am using the modified code without problem with arduino uno.
u_int8, bytes or Strings types must be not problem for compilation.
Maybe the arduino IDe version is the problem. I am using 2:1.0.5+dfsg2-4 (Jessie 1.0.5 arduino) (in Ubuntu SO).

I know that @semajoel has used the code successfully, then maybe he solved some issues related.

from opcn2.

semajoel avatar semajoel commented on May 31, 2024

from opcn2.

vrmadishetty avatar vrmadishetty commented on May 31, 2024

@MarcelloYung Hi, am using modified code for Arduino uno.

As per OPC-N2 sensor, the sensor SPI level is 3.3 VDC, but Arduino Uno SPI levels are 5V.

My only concern, can i integrate SPI lines of OPC-N2 directly to the Arduino UNO ??

Thanks

from opcn2.

dhhagan avatar dhhagan commented on May 31, 2024

@RamanaMadishetty You have a couple of options: 1) You can use an Arduino that uses 3.3V logic rather than 5V logic and then supply 5V to the power line of the OPC-N2 or 2) you can use a logic-level converter to convert the 5V logic of the Arduino you are using to 3.3V before going into the OPC-N2.

from opcn2.

nmarcelo avatar nmarcelo commented on May 31, 2024

@RamanaMadishetty You cannot integrate directly OPC-N2 with arduino. The solutions are as @dhhagan says. I used the option 2) , a bidirectional logic 5V-3.3V level converter with arduino uno, since I am using another sensor which works with 5V logic level.

from opcn2.

vrmadishetty avatar vrmadishetty commented on May 31, 2024

@MarcelloYung @dhhagan Thanks for your reply. Can u suggest me the level converter?

from opcn2.

dhhagan avatar dhhagan commented on May 31, 2024

@RamanaMadishetty For prototyping, something like this will work.

from opcn2.

vrmadishetty avatar vrmadishetty commented on May 31, 2024

@dhhagan Can i store OPC-N2 data in my SD card?
Because already the SPI lines (of Arduino Uno) used for communicating with OPC-N2 sensor.

Also in datasheet of OPC-N2 stated that, "it is not possible to put the MISO (SDO) line into a high impendance mode (tri-state). This means that it is not possible to use the OPC on a shared SPI bus."

Correct me?

from opcn2.

dhhagan avatar dhhagan commented on May 31, 2024

@RamanaMadishetty I'm not quite sure what you mean...are you trying to use 2 OPC-N2's on the same Arduino? If so, then yes, according to the docs, you cannot have multiple slave devices due to the design. If you are trying to operate and save data from one OPC-N2, then yes, you can! There is also a 16 GB uSD card on-board the OPC-N2 (at least newer versions) that will store data; however, it does not include a real-time clock, so you have to figure out the timing yourself.

from opcn2.

vrmadishetty avatar vrmadishetty commented on May 31, 2024

Thanks for your reply @dhhagan

Please find the attached image.

Yes, am trying to operate and save data from only one OPC-N2. I dont want the data of internal 16 GB SD card

What i mean is, am trying to use external SD card to store the data using Arduino Uno. But SD card also communicates on SPI . Already am using SPI lines for OPC-N2.
Can I use same SPI lines for SD card (chip select will be other pin) and OPC-N2?

Because in OPC-N2 document suggested, it is not possible to use the OPC-N2 on a shared SPI bus
new doc 2017-09-18

from opcn2.

dhhagan avatar dhhagan commented on May 31, 2024

@RamanaMadishetty Which arduino are you using?

from opcn2.

vrmadishetty avatar vrmadishetty commented on May 31, 2024

Am using Arduino Mega.

Or else can i use Arduino Uno as SPI shared bus communication for both SD card and OPC-N2?

from opcn2.

semajoel avatar semajoel commented on May 31, 2024

from opcn2.

dhhagan avatar dhhagan commented on May 31, 2024

@RamanaMadishetty Ahh okay. Yea, as far as I know, you can only use the one SPI slave device then. It's unfortunate, but that wasn't my design decision (I don't work for Alphasense...). There are other similar boards you can use that support multiple SPI devices such as the Particle Photon.

from opcn2.

mahamoodalam avatar mahamoodalam commented on May 31, 2024

@dhhagan @MarcelloYung I am working on Arduino Mega 2560 + OPC-N2. I have used the Arduino library for OPC-N2 updated by @MarcelloYung. I have used a 5V to 3.3V converter to connect the 4 SPI lines. But, it looks the library is not functional.

  1. Have you tested the library with OPC-N2 with Arduino Uno/Mega ?
  2. Is it required to use a specific logic converter or any 5v to 3.3v converter will do ?
    Thanks.

from opcn2.

dhhagan avatar dhhagan commented on May 31, 2024

Hi @mahamoodalam, can you provide a bit more information on how you have it wired, which OPC you are using (model and firmware version), and what you are seeing/symptoms that tell you it's not working? Thanks!

from opcn2.

mahamoodalam avatar mahamoodalam commented on May 31, 2024

opc-n2_wiring

Model and version: "Alphasense OPC-N2v18.2"

When I connect the device to the SPI lines of the Arduino mega 2560 board and call the function alpha.on() as specified in opcn2.ino, it does not turn ON the fan(which is an indicator of the device being turned ON or not). And also when I check the return value of the function call alpha.on(), it is 0. Please note that I have set SPI.setClockDivider(SPI_CLOCK_DIV32); in place of SPI.setClockDivider(SPI_CLOCK_DIV2); in the opcn2m.h file.
Thanks.

from opcn2.

dhhagan avatar dhhagan commented on May 31, 2024

Okay, thanks for the additional information. It sounds like you had no problem compiling the code, which is good. My only other concern is that it appears you are powering it through the Arduino directly - is that correct? The OPC-N2 needs >250 mA at times, and that is probably a bit more than can be pushed across the IO lines. Can you try powering it without going through the Mega?

If not, I will try and locate/get a Mega and try myself sometime this week - I know others have used it successfully though.

from opcn2.

mahamoodalam avatar mahamoodalam commented on May 31, 2024

Ok. Thanks a lot. Can you also please verify the below code updated by @MarcelloYung in your original C++ library ?

uint32_t OPCN2::_32bit_int(byte val0, byte val1, byte val2, byte val3)
{
// Return a 32-bit unsigned int from 4 bytes
//return ((val3 << 24) | (val2 << 16) | (val1 << 8) | val0);

uint32_t val = 0;
val = val + val0;
val << 8;
val = val + val1;
val << 8;
val = val + val2;
val << 8;
val = val + val3;

return val;
}

from opcn2.

mahamoodalam avatar mahamoodalam commented on May 31, 2024

@dhhagan @MarcelloYung Upon verification, the device was not working because of bad wiring which was not visible easily. It is now functional. So, Arduino + OPC-N2 works !!!
I get the output as shown below.

Sampling Period: 4.00
PM1: 0.72
PM2.5: 1.45
PM10: 1.72

Still not sure if there is an issue with the uint32_t OPCN2::_32bit_int(byte val0, byte val1, byte val2, byte val3) function. Though I did not use it yet, thought to get it verified from you.

Thanks.

from opcn2.

dhhagan avatar dhhagan commented on May 31, 2024

@mahamoodalam Thanks for the update and glad to hear it is working! I would change it back to the original function. Those are definitely not equivalent, and the original function is the proper way to convert 4 bytes to a 32-bit unsigned integer.

from opcn2.

nmarcelo avatar nmarcelo commented on May 31, 2024

@dhhagan, @mahamoodalam Thanks for the observation! I will change now!

from opcn2.

SWoto avatar SWoto commented on May 31, 2024

@MarcelloYung, I'm having the same problem as @Xylord said. I'm trying to run the code on an ArduinoDue.

Hey Marcello, I tried to use your code, but I couldn't get it to compile. It would seem a bunch of types aren't being accepted by the compiler, such as u_int8, bytes and Strings. Did you go through any steps to make your code compile?
If it doesn't work, does anyone know what changes would need to be made? I'd be willing to make a working version, if I only gotta change variable types; anything more would require precise instructions.

This is my library folder:
Screen Shot 2020-05-29 at 15 54 11

I created the opcn2m.h and edited the content of opcn2.h, to have the same as Marcello's library and tried to run the .ino code.

In file included from /Users/user/Documents/Arduino/libraries/opcn2-master/src/opcn2.cpp:1:0:
/Users/user/Documents/Arduino/libraries/opcn2-master/src/opcn2.h:171:5: error: 'uint8_t' does not name a type
     uint8_t _CS;
     ^
/Users/user/Documents/Arduino/libraries/opcn2-master/src/opcn2.h:175:5: error: 'uint16_t' does not name a type
     uint16_t _16bit_int(byte MSB, byte LSB);
     ^
/Users/user/Documents/Arduino/libraries/opcn2-master/src/opcn2.h:176:26: error: 'byte' has not been declared
     bool _compare_arrays(byte array1[], byte array2[], int length);
                          ^
/Users/user/Documents/Arduino/libraries/opcn2-master/src/opcn2.h:176:41: error: 'byte' has not been declared
     bool _compare_arrays(byte array1[], byte array2[], int length);
                                         ^
/Users/user/Documents/Arduino/libraries/opcn2-master/src/opcn2.h:177:28: error: 'byte' has not been declared
     float _calculate_float(byte val0, byte val1, byte val2, byte val3);
                            ^
/Users/user/Documents/Arduino/libraries/opcn2-master/src/opcn2.h:177:39: error: 'byte' has not been declared
     float _calculate_float(byte val0, byte val1, byte val2, byte val3);
                                       ^
/Users/user/Documents/Arduino/libraries/opcn2-master/src/opcn2.h:177:50: error: 'byte' has not been declared
     float _calculate_float(byte val0, byte val1, byte val2, byte val3);
                                                  ^
/Users/user/Documents/Arduino/libraries/opcn2-master/src/opcn2.h:177:61: error: 'byte' has not been declared
     float _calculate_float(byte val0, byte val1, byte val2, byte val3);
                                                             ^
/Users/user/Documents/Arduino/libraries/opcn2-master/src/opcn2.h:178:5: error: 'uint32_t' does not name a type
     uint32_t _32bit_int(byte val0, byte val1, byte val2, byte val3);
     ^
/Users/user/Documents/Arduino/libraries/opcn2-master/src/opcn2.h:181:19: error: expected ')' before 'chip_select'
     OPCN2(uint8_t chip_select);
                   ^
/Users/user/Documents/Arduino/libraries/opcn2-master/src/opcn2.h:190:33: error: 'byte' has not been declared
     bool write_config_variables(byte values[]);
                                 ^
/Users/user/Documents/Arduino/libraries/opcn2-master/src/opcn2.h:191:34: error: 'byte' has not been declared
     bool write_config_variables2(byte values[]);
                                  ^
/Users/user/Documents/Arduino/libraries/opcn2-master/src/opcn2.h:192:37: error: 'byte' has not been declared
     bool write_serial_number_string(byte values[]);
                                     ^
/Users/user/Documents/Arduino/libraries/opcn2-master/src/opcn2.h:195:24: error: 'uint8_t' has not been declared
     bool set_fan_power(uint8_t value);
                        ^
/Users/user/Documents/Arduino/libraries/opcn2-master/src/opcn2.h:196:26: error: 'uint8_t' has not been declared
     bool set_laser_power(uint8_t value);
                          ^
/Users/user/Documents/Arduino/libraries/opcn2-master/src/opcn2.h:200:5: error: 'String' does not name a type
     String read_information_string();
     ^
/Users/user/Documents/Arduino/libraries/opcn2-master/src/opcn2.h:201:5: error: 'String' does not name a type
     String read_serial_number();
     ^
/Users/user/Documents/Arduino/libraries/opcn2-master/src/opcn2.cpp:3:13: error: expected constructor, destructor, or type conversion before '(' token
 OPCN2::OPCN2(uint8_t chip_select)
             ^
exit status 1
Error compiling for board Arduino Due (Native USB Port).
Invalid library found in /Users/user/Documents/Arduino/libraries/opcn2-master: Missing 'maintainer' from library
Invalid library found in /Users/user/Documents/Arduino/libraries/opcn2-master: Missing 'maintainer' from libraryIn file included from /Users/user/Documents/Arduino/libraries/opcn2-master/src/opcn2.cpp:1:0:
/Users/user/Documents/Arduino/libraries/opcn2-master/src/opcn2.h:171:5: error: 'uint8_t' does not name a type
     uint8_t _CS;
     ^
/Users/user/Documents/Arduino/libraries/opcn2-master/src/opcn2.h:175:5: error: 'uint16_t' does not name a type
     uint16_t _16bit_int(byte MSB, byte LSB);
     ^
/Users/user/Documents/Arduino/libraries/opcn2-master/src/opcn2.h:176:26: error: 'byte' has not been declared
     bool _compare_arrays(byte array1[], byte array2[], int length);
                          ^
/Users/user/Documents/Arduino/libraries/opcn2-master/src/opcn2.h:176:41: error: 'byte' has not been declared
     bool _compare_arrays(byte array1[], byte array2[], int length);
                                         ^
/Users/user/Documents/Arduino/libraries/opcn2-master/src/opcn2.h:177:28: error: 'byte' has not been declared
     float _calculate_float(byte val0, byte val1, byte val2, byte val3);
                            ^
/Users/user/Documents/Arduino/libraries/opcn2-master/src/opcn2.h:177:39: error: 'byte' has not been declared
     float _calculate_float(byte val0, byte val1, byte val2, byte val3);
                                       ^
/Users/user/Documents/Arduino/libraries/opcn2-master/src/opcn2.h:177:50: error: 'byte' has not been declared
     float _calculate_float(byte val0, byte val1, byte val2, byte val3);
                                                  ^
/Users/user/Documents/Arduino/libraries/opcn2-master/src/opcn2.h:177:61: error: 'byte' has not been declared
     float _calculate_float(byte val0, byte val1, byte val2, byte val3);
                                                             ^
/Users/user/Documents/Arduino/libraries/opcn2-master/src/opcn2.h:178:5: error: 'uint32_t' does not name a type
     uint32_t _32bit_int(byte val0, byte val1, byte val2, byte val3);
     ^
/Users/user/Documents/Arduino/libraries/opcn2-master/src/opcn2.h:181:19: error: expected ')' before 'chip_select'
     OPCN2(uint8_t chip_select);
                   ^
/Users/user/Documents/Arduino/libraries/opcn2-master/src/opcn2.h:190:33: error: 'byte' has not been declared
     bool write_config_variables(byte values[]);
                                 ^
/Users/user/Documents/Arduino/libraries/opcn2-master/src/opcn2.h:191:34: error: 'byte' has not been declared
     bool write_config_variables2(byte values[]);
                                  ^
/Users/user/Documents/Arduino/libraries/opcn2-master/src/opcn2.h:192:37: error: 'byte' has not been declared
     bool write_serial_number_string(byte values[]);
                                     ^
/Users/user/Documents/Arduino/libraries/opcn2-master/src/opcn2.h:195:24: error: 'uint8_t' has not been declared
     bool set_fan_power(uint8_t value);
                        ^
/Users/user/Documents/Arduino/libraries/opcn2-master/src/opcn2.h:196:26: error: 'uint8_t' has not been declared
     bool set_laser_power(uint8_t value);
                          ^
/Users/user/Documents/Arduino/libraries/opcn2-master/src/opcn2.h:200:5: error: 'String' does not name a type
     String read_information_string();
     ^
/Users/user/Documents/Arduino/libraries/opcn2-master/src/opcn2.h:201:5: error: 'String' does not name a type
     String read_serial_number();
     ^
/Users/user/Documents/Arduino/libraries/opcn2-master/src/opcn2.cpp:3:13: error: expected constructor, destructor, or type conversion before '(' token
 OPCN2::OPCN2(uint8_t chip_select)
             ^
exit status 1
Error compiling for board Arduino Due (Native USB Port).
Invalid library found in /Users/user/Documents/Arduino/libraries/opcn2-master: Missing 'maintainer' from library
Invalid library found in /Users/user/Documents/Arduino/libraries/opcn2-master: Missing 'maintainer' from library

from opcn2.

SWoto avatar SWoto commented on May 31, 2024

About the problem above, it was solved after removing the opcn2.cpp file from the folder, having only the opcn2m.h and opcn2.h.

However, the Serial output shows nothing even though the OPC-N2 turns on after some seconds and keeps on forever (forever = more than 15min without displaying anything).

I've tried another Alphasense-OPC-N2 library and it did display something and turned the sensor off after a while. However, this one only plots the histogram data. I'll try to merge it with Marcello's to see if it'll work.

from opcn2.

SWoto avatar SWoto commented on May 31, 2024

I've tried with a MRKZERO board, and the upload goes smoothly. However, the Serial port cant be read...

It looks like that I've some problem when reading the serial port with Marcello's Code.

Using Marcello's Code:

  1. Before Uploading it
    image

  2. After:
    image
    Erro ao abrir porta serial "COM20". (Port not found)

Using JHabeck's Code:

  1. Before Uploading it
    image

  2. After:
    image

from opcn2.

Related Issues (10)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.