Open paultanner opened 8 years ago
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.
Thx for the quick reply David. I look forward to testing the Arduino version.
Hi @paultanner Just got back from India and I will try and have this out ASAP.
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
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.
@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?
@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.
@dhhagan great project! Never used logic level converter... Good luck for your project!
@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!
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.
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!) :-)
@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?
@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!
@dhhagan how far with the Arduino library?
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.
okay. thank you.
On Wed, Apr 26, 2017 at 12:50 AM, David H Hagan notifications@github.com wrote:
Hi @semajoel https://github.com/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.
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/dhhagan/opcn2/issues/18#issuecomment-297175725, or mute the thread https://github.com/notifications/unsubscribe-auth/AYr7w0G8FX1LH74WuT3mQ8MksmBOjh9xks5rzmqUgaJpZM4JhDIf .
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
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.
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.
Hi@Xylord am using modified code too, but I ain't having any issues, perhaps you should update your IDE. On Jun 8, 2017 10:49 PM, "MarcelloYung" notifications@github.com wrote:
Hi @Xylord https://github.com/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 https://github.com/semajoel has used the code successfully, then maybe he solved some issues related.
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/dhhagan/opcn2/issues/18#issuecomment-307208495, or mute the thread https://github.com/notifications/unsubscribe-auth/AYr7wylTxtdxCDgCinVbT0TEVx0-mqAcks5sCFBGgaJpZM4JhDIf .
@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
@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.
@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.
@MarcelloYung @dhhagan Thanks for your reply. Can u suggest me the level converter?
@RamanaMadishetty For prototyping, something like this will work.
@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?
@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.
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
@RamanaMadishetty Which arduino are you using?
Am using Arduino Mega.
Or else can i use Arduino Uno as SPI shared bus communication for both SD card and OPC-N2?
I tried the setup in the picture but was not successful, sorted to uploading data to a server. On Sep 18, 2017 4:04 PM, "Ramana Madishetty" notifications@github.com wrote:
Thanks for your reply @dhhagan https://github.com/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 Duo. 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 [image: new doc 2017-09-18] https://user-images.githubusercontent.com/7162637/30543219-dc9bbf2a-9c9f-11e7-9b5e-42aadea13dcf.jpg
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/dhhagan/opcn2/issues/18#issuecomment-330213059, or mute the thread https://github.com/notifications/unsubscribe-auth/AYr7w98-i63BA5LzM2OSY0JpAxa5tfOCks5sjmpHgaJpZM4JhDIf .
@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.
@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.
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!
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.
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.
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; }
@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.
@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.
@dhhagan, @mahamoodalam Thanks for the observation! I will change now!
@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:
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
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.
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:
Before Uploading it
After:
Erro ao abrir porta serial "COM20". (Port not found)
Using JHabeck's Code:
Before Uploading it
After:
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.
I'm trying to test the same code in a normal Arduino build using the IDE (mainly 1.05). Specifically, I'm building for Uno or Blend Micro. Same thing happens in both cases. I have the .cpp and .h files inside a folder within the libraries folder. I have successfully built other sketches that use SPI but in those cases SPI is called from the .ino file rather than from within a library.
I made the change in the .h file
SPI not defined so added in .cpp file, the .h file and .ino file (renamed from .cpp file in /examples)
Still getting errors like:
Evidently the IDE is converting to this from "SPI.begin(_CS);" and then failing to find "SPIClass"
A little too much magic buried in IDE? I'm trying to find out why this is happening but posting here in case I'm missing something that would be needed in a case like this. Online I see various instances of this error with other libraries but no useful solutions.
Any help appreciated ;-)