Grove Air Quality Sensor

I’m having a Grove air quality sensor, which can test harmful gases. How to use it with XOD?

Hi, @ahmadsuki!

Here it is a plain ambient air pollution module from Seed Studio. The module based on the MP503 gas sensor.

The data is read from the sensor via a single analog port, for example, A0. In total, the module uses 3 wires to connect V, G, A0.

Now there is no official XOD library for working with this sensor. But it doesn’t matter because the sensor is quite simple, and you can try to create nodes to work by yourself. This module is an excellent source to make the XOD library by wrapping a third-party Arduino library.

As an example, I quickly made the XOD library based on the library from the manufacturer, but I can’t check it because I don’t have this module.

In theory, it should work correctly. The sensor returns one of four values 0, 1, 2, 3. Each value corresponds to the pollution degree of the surrounding air.


Try it.

1 Like

Hi, I’m an experienced electronics hobbyist and C programmer, just now learning XOD.
It’s quite elegant, powerful, easy, and well…more fun. If you have a needed library XODified.

There are so many Arduino libraries, the XOD community can not convert them all but focuses on the common ones and appears to do a great and needed job.
I will therefore follow this project and thread closely.

I looked at the GAQ sensor and their code and it seems a library conversion may not be necessary. The library code has an initial call to init:
and then, at fixed intervals, does repeated analogReads:

If it’s a simple process to insert a call to an Arduino library init(), the rest could probably be done, and much easier, with XOD.

I’m not thinking people should “XODify” a library themselves - leave that to the pros!
But accessing and using a small number of Arduino library routines in XOD might be reasonable. Is there or could there be a simple “call-C-routine-node” which returns the result to XOD?

Do people do this? a lot? or anything like it? Or is it the proverbial “can of worms”?
I’m quite curious. That would be real power!

Creating a patch with the not-implemented-in-xod node and coding in C++ is XOD’s method of “call-C-routine-node”. The down-side is that you cannot just copy IDE C code directly; you need to convert input/output parameters to XOD pins and IDE-specific code needs re-written.

As for the original question about the gas sensor: it is just an analog sensor that can be read using the generic analog-read or analog-sensor nodes. The advantage of wrapping the IDE library to use in XOD is that it will include any conversion formulas and maybe extra code like averaging over time, etc. If it was an I2C sensor that needed specific protocol, the work to wrap the IDE library starts to become less than re-coding what the library does.

Should you wrap an existing IDE library for use in XOD, or just re-code what the library does in XOD? Like many programming questions…it depends. If you wrap a library, you can easily get improvements when the library is updated; or your wrapper might break if they change the library. The library might include a bunch of over-head you don’t need/want. If the library just does a simple function, it is probably easier just to re-code in XOD rather than deal with wrapping a library. If the library performs some complex operations, you are likely to introduce errors trying to re-code it yourself. Is the library available on the internet in a way that can be easily auto-included by XOD? Then there is the final question that is more important than most will admit: Which do you “feel” like doing? :slight_smile:

Wrapping a simple library just to get experience doing it has value…so does re-coding someone else’s work in another language just so you can understand the function and/or language better. Just realize that if you are making the choice for personal value, others will be less likely to follow…It generally doesn’t make much sense for me to use your complex experiment in XOD if I can wrap a library being actively developed by several people & used by 1000’s of other people, but that doesn’t mean you shouldn’t do the experiment for yourself. If the wrapper doesn’t exist and your experiment does, people might use it anyway.

1 Like

It works. Many Thanks.

1 Like

I knew it might. Did you do any init()? or wrap anything? or just the analogRead?

It also prompted the great post by gweimer.
I just checked the “not-implemented-in-xod” node. I was about to ask for an example, but I first searched for one and found the first external library I used in XOD, gweimer’s lcd-i2c-init.

The interesting thing is he actually XODify’d (my term) the Arduino lcd-I2C in only 45 lines of code. It’s all about the “context” and what inputs and outputs one can include and how to use them. His second one even shows varadic input.

Don’t give me too much credit…I only slightly modified the built-in lcd-i2c node :slight_smile:

There are a lot of built-in nodes that use not-implemented-in-xod, but I don’t think there is an easy way to find them. I think you have to open each node & see what it uses.

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.