├── .gitattributes
├── .github
└── workflows
│ └── sync_issues.yml
├── .gitignore
├── .gitlab-ci.yml
├── .travis.yml
├── LICENSE.txt
├── License.txt
├── MutichannelGasSensor.cpp
├── MutichannelGasSensor.h
├── README.md
├── examples
├── GetVersion
│ └── GetVersion.ino
├── I2C_Address
│ └── I2C_Address.ino
├── RawData
│ └── RawData.ino
├── ReadSensorValue_Grove
│ └── ReadSensorValue_Grove.ino
├── ReadSensorValue_Xadow
│ └── ReadSensorValue_Xadow.ino
├── UpdateFrimware
│ ├── .DS_Store
│ ├── UpdateFrimware.ino
│ ├── bootloader_atmega168.h
│ └── gpl.txt
├── calibration
│ └── calibration.ino
├── factory_setting
│ └── factory_setting.ino
└── new_firmware
│ └── new_firmware.ino
├── keywords.txt
└── library.properties
/.gitattributes:
--------------------------------------------------------------------------------
1 | # Auto detect text files and perform LF normalization
2 | * text=auto
3 |
4 | # Custom for Visual Studio
5 | *.cs diff=csharp
6 | *.sln merge=union
7 | *.csproj merge=union
8 | *.vbproj merge=union
9 | *.fsproj merge=union
10 | *.dbproj merge=union
11 |
12 | # Standard to msysgit
13 | *.doc diff=astextplain
14 | *.DOC diff=astextplain
15 | *.docx diff=astextplain
16 | *.DOCX diff=astextplain
17 | *.dot diff=astextplain
18 | *.DOT diff=astextplain
19 | *.pdf diff=astextplain
20 | *.PDF diff=astextplain
21 | *.rtf diff=astextplain
22 | *.RTF diff=astextplain
23 |
--------------------------------------------------------------------------------
/.github/workflows/sync_issues.yml:
--------------------------------------------------------------------------------
1 | name: Automate Issue Management
2 |
3 | on:
4 | issues:
5 | types:
6 | - opened
7 | - edited
8 | - assigned
9 | - unassigned
10 | - labeled
11 | - unlabeled
12 | - reopened
13 |
14 | jobs:
15 | add_issue_to_project:
16 | runs-on: ubuntu-latest
17 | steps:
18 | - name: Add issue to GitHub Project
19 | uses: actions/add-to-project@v1.0.2
20 | with:
21 | project-url: https://github.com/orgs/Seeed-Studio/projects/17
22 | github-token: ${{ secrets.ISSUE_ASSEMBLE }}
23 | labeled: bug
24 | label-operator: NOT
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | #################
2 | ## Eclipse
3 | #################
4 |
5 | *.pydevproject
6 | .project
7 | .metadata
8 | bin/
9 | tmp/
10 | *.tmp
11 | *.bak
12 | *.swp
13 | *~.nib
14 | local.properties
15 | .classpath
16 | .settings/
17 | .loadpath
18 |
19 | # External tool builders
20 | .externalToolBuilders/
21 |
22 | # Locally stored "Eclipse launch configurations"
23 | *.launch
24 |
25 | # CDT-specific
26 | .cproject
27 |
28 | # PDT-specific
29 | .buildpath
30 |
31 |
32 | #################
33 | ## Visual Studio
34 | #################
35 |
36 | ## Ignore Visual Studio temporary files, build results, and
37 | ## files generated by popular Visual Studio add-ons.
38 |
39 | # User-specific files
40 | *.suo
41 | *.user
42 | *.sln.docstates
43 |
44 | # Build results
45 |
46 | [Dd]ebug/
47 | [Rr]elease/
48 | x64/
49 | build/
50 | [Bb]in/
51 | [Oo]bj/
52 |
53 | # MSTest test Results
54 | [Tt]est[Rr]esult*/
55 | [Bb]uild[Ll]og.*
56 |
57 | *_i.c
58 | *_p.c
59 | *.ilk
60 | *.meta
61 | *.obj
62 | *.pch
63 | *.pdb
64 | *.pgc
65 | *.pgd
66 | *.rsp
67 | *.sbr
68 | *.tlb
69 | *.tli
70 | *.tlh
71 | *.tmp
72 | *.tmp_proj
73 | *.log
74 | *.vspscc
75 | *.vssscc
76 | .builds
77 | *.pidb
78 | *.log
79 | *.scc
80 |
81 | # Visual C++ cache files
82 | ipch/
83 | *.aps
84 | *.ncb
85 | *.opensdf
86 | *.sdf
87 | *.cachefile
88 |
89 | # Visual Studio profiler
90 | *.psess
91 | *.vsp
92 | *.vspx
93 |
94 | # Guidance Automation Toolkit
95 | *.gpState
96 |
97 | # ReSharper is a .NET coding add-in
98 | _ReSharper*/
99 | *.[Rr]e[Ss]harper
100 |
101 | # TeamCity is a build add-in
102 | _TeamCity*
103 |
104 | # DotCover is a Code Coverage Tool
105 | *.dotCover
106 |
107 | # NCrunch
108 | *.ncrunch*
109 | .*crunch*.local.xml
110 |
111 | # Installshield output folder
112 | [Ee]xpress/
113 |
114 | # DocProject is a documentation generator add-in
115 | DocProject/buildhelp/
116 | DocProject/Help/*.HxT
117 | DocProject/Help/*.HxC
118 | DocProject/Help/*.hhc
119 | DocProject/Help/*.hhk
120 | DocProject/Help/*.hhp
121 | DocProject/Help/Html2
122 | DocProject/Help/html
123 |
124 | # Click-Once directory
125 | publish/
126 |
127 | # Publish Web Output
128 | *.Publish.xml
129 | *.pubxml
130 |
131 | # NuGet Packages Directory
132 | ## TODO: If you have NuGet Package Restore enabled, uncomment the next line
133 | #packages/
134 |
135 | # Windows Azure Build Output
136 | csx
137 | *.build.csdef
138 |
139 | # Windows Store app package directory
140 | AppPackages/
141 |
142 | # Others
143 | sql/
144 | *.Cache
145 | ClientBin/
146 | [Ss]tyle[Cc]op.*
147 | ~$*
148 | *~
149 | *.dbmdl
150 | *.[Pp]ublish.xml
151 | *.pfx
152 | *.publishsettings
153 |
154 | # RIA/Silverlight projects
155 | Generated_Code/
156 |
157 | # Backup & report files from converting an old project file to a newer
158 | # Visual Studio version. Backup files are not needed, because we have git ;-)
159 | _UpgradeReport_Files/
160 | Backup*/
161 | UpgradeLog*.XML
162 | UpgradeLog*.htm
163 |
164 | # SQL Server files
165 | App_Data/*.mdf
166 | App_Data/*.ldf
167 |
168 | #############
169 | ## Windows detritus
170 | #############
171 |
172 | # Windows image file caches
173 | Thumbs.db
174 | ehthumbs.db
175 |
176 | # Folder config file
177 | Desktop.ini
178 |
179 | # Recycle Bin used on file shares
180 | $RECYCLE.BIN/
181 |
182 | # Mac crap
183 | .DS_Store
184 |
185 |
186 | #############
187 | ## Python
188 | #############
189 |
190 | *.py[co]
191 |
192 | # Packages
193 | *.egg
194 | *.egg-info
195 | dist/
196 | build/
197 | eggs/
198 | parts/
199 | var/
200 | sdist/
201 | develop-eggs/
202 | .installed.cfg
203 |
204 | # Installer logs
205 | pip-log.txt
206 |
207 | # Unit test / coverage reports
208 | .coverage
209 | .tox
210 |
211 | #Translations
212 | *.mo
213 |
214 | #Mr Developer
215 | .mr.developer.cfg
216 |
217 | *.bin
218 | *.elf
--------------------------------------------------------------------------------
/.gitlab-ci.yml:
--------------------------------------------------------------------------------
1 | build:
2 | tags:
3 | - nas
4 | script:
5 | - wget -c https://files.seeedstudio.com/arduino/seeed-arduino-ci.sh
6 | - chmod +x seeed-arduino-ci.sh
7 | - bash $PWD/seeed-arduino-ci.sh new_firmware:uno/new_firmware:servo:seeed_XIAO_m0/UpdateFrimware:uno/UpdateFrimware:servo:seeed_XIAO_m0/ReadSensorValue_Xadow:uno/ReadSensorValue_Xadow:servo:seeed_XIAO_m0
8 |
9 |
--------------------------------------------------------------------------------
/.travis.yml:
--------------------------------------------------------------------------------
1 |
2 | language: generic
3 | dist: bionic
4 | sudo: false
5 | cache:
6 | directories:
7 | - ~/arduino_ide
8 | - ~/.arduino15/packages/
9 |
10 | before_install:
11 | - wget -c https://files.seeedstudio.com/arduino/seeed-arduino-ci.sh
12 |
13 | script:
14 | - chmod +x seeed-arduino-ci.sh
15 | - cat $PWD/seeed-arduino-ci.sh
16 | - bash $PWD/seeed-arduino-ci.sh new_firmware:uno/new_firmware:servo:seeed_XIAO_m0/UpdateFrimware:uno/UpdateFrimware:servo:seeed_XIAO_m0/ReadSensorValue_Xadow:uno/ReadSensorValue_Xadow:servo:seeed_XIAO_m0
17 |
18 | notifications:
19 | email:
20 | on_success: change
21 | on_failure: change
22 |
--------------------------------------------------------------------------------
/LICENSE.txt:
--------------------------------------------------------------------------------
1 | This file includes licensing information for arduino-cli
2 |
3 | Copyright (c) 2018 ARDUINO SA (www.arduino.cc)
4 |
5 | The software is released under the GNU General Public License, which covers the main body
6 | of the arduino-cli code. The terms of this license can be found at:
7 | https://www.gnu.org/licenses/gpl-3.0.en.html
8 |
9 | You can be released from the requirements of the above licenses by purchasing
10 | a commercial license. Buying such a license is mandatory if you want to modify or
11 | otherwise use the software for commercial activities involving the Arduino
12 | software without disclosing the source code of your own applications. To purchase
13 | a commercial license, send an email to license@arduino.cc
14 |
15 | GNU GENERAL PUBLIC LICENSE
16 | Version 3, 29 June 2007
17 |
18 | Copyright (C) 2007 Free Software Foundation, Inc.
19 | Everyone is permitted to copy and distribute verbatim copies
20 | of this license document, but changing it is not allowed.
21 |
22 | Preamble
23 |
24 | The GNU General Public License is a free, copyleft license for
25 | software and other kinds of works.
26 |
27 | The licenses for most software and other practical works are designed
28 | to take away your freedom to share and change the works. By contrast,
29 | the GNU General Public License is intended to guarantee your freedom to
30 | share and change all versions of a program--to make sure it remains free
31 | software for all its users. We, the Free Software Foundation, use the
32 | GNU General Public License for most of our software; it applies also to
33 | any other work released this way by its authors. You can apply it to
34 | your programs, too.
35 |
36 | When we speak of free software, we are referring to freedom, not
37 | price. Our General Public Licenses are designed to make sure that you
38 | have the freedom to distribute copies of free software (and charge for
39 | them if you wish), that you receive source code or can get it if you
40 | want it, that you can change the software or use pieces of it in new
41 | free programs, and that you know you can do these things.
42 |
43 | To protect your rights, we need to prevent others from denying you
44 | these rights or asking you to surrender the rights. Therefore, you have
45 | certain responsibilities if you distribute copies of the software, or if
46 | you modify it: responsibilities to respect the freedom of others.
47 |
48 | For example, if you distribute copies of such a program, whether
49 | gratis or for a fee, you must pass on to the recipients the same
50 | freedoms that you received. You must make sure that they, too, receive
51 | or can get the source code. And you must show them these terms so they
52 | know their rights.
53 |
54 | Developers that use the GNU GPL protect your rights with two steps:
55 | (1) assert copyright on the software, and (2) offer you this License
56 | giving you legal permission to copy, distribute and/or modify it.
57 |
58 | For the developers' and authors' protection, the GPL clearly explains
59 | that there is no warranty for this free software. For both users' and
60 | authors' sake, the GPL requires that modified versions be marked as
61 | changed, so that their problems will not be attributed erroneously to
62 | authors of previous versions.
63 |
64 | Some devices are designed to deny users access to install or run
65 | modified versions of the software inside them, although the manufacturer
66 | can do so. This is fundamentally incompatible with the aim of
67 | protecting users' freedom to change the software. The systematic
68 | pattern of such abuse occurs in the area of products for individuals to
69 | use, which is precisely where it is most unacceptable. Therefore, we
70 | have designed this version of the GPL to prohibit the practice for those
71 | products. If such problems arise substantially in other domains, we
72 | stand ready to extend this provision to those domains in future versions
73 | of the GPL, as needed to protect the freedom of users.
74 |
75 | Finally, every program is threatened constantly by software patents.
76 | States should not allow patents to restrict development and use of
77 | software on general-purpose computers, but in those that do, we wish to
78 | avoid the special danger that patents applied to a free program could
79 | make it effectively proprietary. To prevent this, the GPL assures that
80 | patents cannot be used to render the program non-free.
81 |
82 | The precise terms and conditions for copying, distribution and
83 | modification follow.
84 |
85 | TERMS AND CONDITIONS
86 |
87 | 0. Definitions.
88 |
89 | "This License" refers to version 3 of the GNU General Public License.
90 |
91 | "Copyright" also means copyright-like laws that apply to other kinds of
92 | works, such as semiconductor masks.
93 |
94 | "The Program" refers to any copyrightable work licensed under this
95 | License. Each licensee is addressed as "you". "Licensees" and
96 | "recipients" may be individuals or organizations.
97 |
98 | To "modify" a work means to copy from or adapt all or part of the work
99 | in a fashion requiring copyright permission, other than the making of an
100 | exact copy. The resulting work is called a "modified version" of the
101 | earlier work or a work "based on" the earlier work.
102 |
103 | A "covered work" means either the unmodified Program or a work based
104 | on the Program.
105 |
106 | To "propagate" a work means to do anything with it that, without
107 | permission, would make you directly or secondarily liable for
108 | infringement under applicable copyright law, except executing it on a
109 | computer or modifying a private copy. Propagation includes copying,
110 | distribution (with or without modification), making available to the
111 | public, and in some countries other activities as well.
112 |
113 | To "convey" a work means any kind of propagation that enables other
114 | parties to make or receive copies. Mere interaction with a user through
115 | a computer network, with no transfer of a copy, is not conveying.
116 |
117 | An interactive user interface displays "Appropriate Legal Notices"
118 | to the extent that it includes a convenient and prominently visible
119 | feature that (1) displays an appropriate copyright notice, and (2)
120 | tells the user that there is no warranty for the work (except to the
121 | extent that warranties are provided), that licensees may convey the
122 | work under this License, and how to view a copy of this License. If
123 | the interface presents a list of user commands or options, such as a
124 | menu, a prominent item in the list meets this criterion.
125 |
126 | 1. Source Code.
127 |
128 | The "source code" for a work means the preferred form of the work
129 | for making modifications to it. "Object code" means any non-source
130 | form of a work.
131 |
132 | A "Standard Interface" means an interface that either is an official
133 | standard defined by a recognized standards body, or, in the case of
134 | interfaces specified for a particular programming language, one that
135 | is widely used among developers working in that language.
136 |
137 | The "System Libraries" of an executable work include anything, other
138 | than the work as a whole, that (a) is included in the normal form of
139 | packaging a Major Component, but which is not part of that Major
140 | Component, and (b) serves only to enable use of the work with that
141 | Major Component, or to implement a Standard Interface for which an
142 | implementation is available to the public in source code form. A
143 | "Major Component", in this context, means a major essential component
144 | (kernel, window system, and so on) of the specific operating system
145 | (if any) on which the executable work runs, or a compiler used to
146 | produce the work, or an object code interpreter used to run it.
147 |
148 | The "Corresponding Source" for a work in object code form means all
149 | the source code needed to generate, install, and (for an executable
150 | work) run the object code and to modify the work, including scripts to
151 | control those activities. However, it does not include the work's
152 | System Libraries, or general-purpose tools or generally available free
153 | programs which are used unmodified in performing those activities but
154 | which are not part of the work. For example, Corresponding Source
155 | includes interface definition files associated with source files for
156 | the work, and the source code for shared libraries and dynamically
157 | linked subprograms that the work is specifically designed to require,
158 | such as by intimate data communication or control flow between those
159 | subprograms and other parts of the work.
160 |
161 | The Corresponding Source need not include anything that users
162 | can regenerate automatically from other parts of the Corresponding
163 | Source.
164 |
165 | The Corresponding Source for a work in source code form is that
166 | same work.
167 |
168 | 2. Basic Permissions.
169 |
170 | All rights granted under this License are granted for the term of
171 | copyright on the Program, and are irrevocable provided the stated
172 | conditions are met. This License explicitly affirms your unlimited
173 | permission to run the unmodified Program. The output from running a
174 | covered work is covered by this License only if the output, given its
175 | content, constitutes a covered work. This License acknowledges your
176 | rights of fair use or other equivalent, as provided by copyright law.
177 |
178 | You may make, run and propagate covered works that you do not
179 | convey, without conditions so long as your license otherwise remains
180 | in force. You may convey covered works to others for the sole purpose
181 | of having them make modifications exclusively for you, or provide you
182 | with facilities for running those works, provided that you comply with
183 | the terms of this License in conveying all material for which you do
184 | not control copyright. Those thus making or running the covered works
185 | for you must do so exclusively on your behalf, under your direction
186 | and control, on terms that prohibit them from making any copies of
187 | your copyrighted material outside their relationship with you.
188 |
189 | Conveying under any other circumstances is permitted solely under
190 | the conditions stated below. Sublicensing is not allowed; section 10
191 | makes it unnecessary.
192 |
193 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law.
194 |
195 | No covered work shall be deemed part of an effective technological
196 | measure under any applicable law fulfilling obligations under article
197 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or
198 | similar laws prohibiting or restricting circumvention of such
199 | measures.
200 |
201 | When you convey a covered work, you waive any legal power to forbid
202 | circumvention of technological measures to the extent such circumvention
203 | is effected by exercising rights under this License with respect to
204 | the covered work, and you disclaim any intention to limit operation or
205 | modification of the work as a means of enforcing, against the work's
206 | users, your or third parties' legal rights to forbid circumvention of
207 | technological measures.
208 |
209 | 4. Conveying Verbatim Copies.
210 |
211 | You may convey verbatim copies of the Program's source code as you
212 | receive it, in any medium, provided that you conspicuously and
213 | appropriately publish on each copy an appropriate copyright notice;
214 | keep intact all notices stating that this License and any
215 | non-permissive terms added in accord with section 7 apply to the code;
216 | keep intact all notices of the absence of any warranty; and give all
217 | recipients a copy of this License along with the Program.
218 |
219 | You may charge any price or no price for each copy that you convey,
220 | and you may offer support or warranty protection for a fee.
221 |
222 | 5. Conveying Modified Source Versions.
223 |
224 | You may convey a work based on the Program, or the modifications to
225 | produce it from the Program, in the form of source code under the
226 | terms of section 4, provided that you also meet all of these conditions:
227 |
228 | a) The work must carry prominent notices stating that you modified
229 | it, and giving a relevant date.
230 |
231 | b) The work must carry prominent notices stating that it is
232 | released under this License and any conditions added under section
233 | 7. This requirement modifies the requirement in section 4 to
234 | "keep intact all notices".
235 |
236 | c) You must license the entire work, as a whole, under this
237 | License to anyone who comes into possession of a copy. This
238 | License will therefore apply, along with any applicable section 7
239 | additional terms, to the whole of the work, and all its parts,
240 | regardless of how they are packaged. This License gives no
241 | permission to license the work in any other way, but it does not
242 | invalidate such permission if you have separately received it.
243 |
244 | d) If the work has interactive user interfaces, each must display
245 | Appropriate Legal Notices; however, if the Program has interactive
246 | interfaces that do not display Appropriate Legal Notices, your
247 | work need not make them do so.
248 |
249 | A compilation of a covered work with other separate and independent
250 | works, which are not by their nature extensions of the covered work,
251 | and which are not combined with it such as to form a larger program,
252 | in or on a volume of a storage or distribution medium, is called an
253 | "aggregate" if the compilation and its resulting copyright are not
254 | used to limit the access or legal rights of the compilation's users
255 | beyond what the individual works permit. Inclusion of a covered work
256 | in an aggregate does not cause this License to apply to the other
257 | parts of the aggregate.
258 |
259 | 6. Conveying Non-Source Forms.
260 |
261 | You may convey a covered work in object code form under the terms
262 | of sections 4 and 5, provided that you also convey the
263 | machine-readable Corresponding Source under the terms of this License,
264 | in one of these ways:
265 |
266 | a) Convey the object code in, or embodied in, a physical product
267 | (including a physical distribution medium), accompanied by the
268 | Corresponding Source fixed on a durable physical medium
269 | customarily used for software interchange.
270 |
271 | b) Convey the object code in, or embodied in, a physical product
272 | (including a physical distribution medium), accompanied by a
273 | written offer, valid for at least three years and valid for as
274 | long as you offer spare parts or customer support for that product
275 | model, to give anyone who possesses the object code either (1) a
276 | copy of the Corresponding Source for all the software in the
277 | product that is covered by this License, on a durable physical
278 | medium customarily used for software interchange, for a price no
279 | more than your reasonable cost of physically performing this
280 | conveying of source, or (2) access to copy the
281 | Corresponding Source from a network server at no charge.
282 |
283 | c) Convey individual copies of the object code with a copy of the
284 | written offer to provide the Corresponding Source. This
285 | alternative is allowed only occasionally and noncommercially, and
286 | only if you received the object code with such an offer, in accord
287 | with subsection 6b.
288 |
289 | d) Convey the object code by offering access from a designated
290 | place (gratis or for a charge), and offer equivalent access to the
291 | Corresponding Source in the same way through the same place at no
292 | further charge. You need not require recipients to copy the
293 | Corresponding Source along with the object code. If the place to
294 | copy the object code is a network server, the Corresponding Source
295 | may be on a different server (operated by you or a third party)
296 | that supports equivalent copying facilities, provided you maintain
297 | clear directions next to the object code saying where to find the
298 | Corresponding Source. Regardless of what server hosts the
299 | Corresponding Source, you remain obligated to ensure that it is
300 | available for as long as needed to satisfy these requirements.
301 |
302 | e) Convey the object code using peer-to-peer transmission, provided
303 | you inform other peers where the object code and Corresponding
304 | Source of the work are being offered to the general public at no
305 | charge under subsection 6d.
306 |
307 | A separable portion of the object code, whose source code is excluded
308 | from the Corresponding Source as a System Library, need not be
309 | included in conveying the object code work.
310 |
311 | A "User Product" is either (1) a "consumer product", which means any
312 | tangible personal property which is normally used for personal, family,
313 | or household purposes, or (2) anything designed or sold for incorporation
314 | into a dwelling. In determining whether a product is a consumer product,
315 | doubtful cases shall be resolved in favor of coverage. For a particular
316 | product received by a particular user, "normally used" refers to a
317 | typical or common use of that class of product, regardless of the status
318 | of the particular user or of the way in which the particular user
319 | actually uses, or expects or is expected to use, the product. A product
320 | is a consumer product regardless of whether the product has substantial
321 | commercial, industrial or non-consumer uses, unless such uses represent
322 | the only significant mode of use of the product.
323 |
324 | "Installation Information" for a User Product means any methods,
325 | procedures, authorization keys, or other information required to install
326 | and execute modified versions of a covered work in that User Product from
327 | a modified version of its Corresponding Source. The information must
328 | suffice to ensure that the continued functioning of the modified object
329 | code is in no case prevented or interfered with solely because
330 | modification has been made.
331 |
332 | If you convey an object code work under this section in, or with, or
333 | specifically for use in, a User Product, and the conveying occurs as
334 | part of a transaction in which the right of possession and use of the
335 | User Product is transferred to the recipient in perpetuity or for a
336 | fixed term (regardless of how the transaction is characterized), the
337 | Corresponding Source conveyed under this section must be accompanied
338 | by the Installation Information. But this requirement does not apply
339 | if neither you nor any third party retains the ability to install
340 | modified object code on the User Product (for example, the work has
341 | been installed in ROM).
342 |
343 | The requirement to provide Installation Information does not include a
344 | requirement to continue to provide support service, warranty, or updates
345 | for a work that has been modified or installed by the recipient, or for
346 | the User Product in which it has been modified or installed. Access to a
347 | network may be denied when the modification itself materially and
348 | adversely affects the operation of the network or violates the rules and
349 | protocols for communication across the network.
350 |
351 | Corresponding Source conveyed, and Installation Information provided,
352 | in accord with this section must be in a format that is publicly
353 | documented (and with an implementation available to the public in
354 | source code form), and must require no special password or key for
355 | unpacking, reading or copying.
356 |
357 | 7. Additional Terms.
358 |
359 | "Additional permissions" are terms that supplement the terms of this
360 | License by making exceptions from one or more of its conditions.
361 | Additional permissions that are applicable to the entire Program shall
362 | be treated as though they were included in this License, to the extent
363 | that they are valid under applicable law. If additional permissions
364 | apply only to part of the Program, that part may be used separately
365 | under those permissions, but the entire Program remains governed by
366 | this License without regard to the additional permissions.
367 |
368 | When you convey a copy of a covered work, you may at your option
369 | remove any additional permissions from that copy, or from any part of
370 | it. (Additional permissions may be written to require their own
371 | removal in certain cases when you modify the work.) You may place
372 | additional permissions on material, added by you to a covered work,
373 | for which you have or can give appropriate copyright permission.
374 |
375 | Notwithstanding any other provision of this License, for material you
376 | add to a covered work, you may (if authorized by the copyright holders of
377 | that material) supplement the terms of this License with terms:
378 |
379 | a) Disclaiming warranty or limiting liability differently from the
380 | terms of sections 15 and 16 of this License; or
381 |
382 | b) Requiring preservation of specified reasonable legal notices or
383 | author attributions in that material or in the Appropriate Legal
384 | Notices displayed by works containing it; or
385 |
386 | c) Prohibiting misrepresentation of the origin of that material, or
387 | requiring that modified versions of such material be marked in
388 | reasonable ways as different from the original version; or
389 |
390 | d) Limiting the use for publicity purposes of names of licensors or
391 | authors of the material; or
392 |
393 | e) Declining to grant rights under trademark law for use of some
394 | trade names, trademarks, or service marks; or
395 |
396 | f) Requiring indemnification of licensors and authors of that
397 | material by anyone who conveys the material (or modified versions of
398 | it) with contractual assumptions of liability to the recipient, for
399 | any liability that these contractual assumptions directly impose on
400 | those licensors and authors.
401 |
402 | All other non-permissive additional terms are considered "further
403 | restrictions" within the meaning of section 10. If the Program as you
404 | received it, or any part of it, contains a notice stating that it is
405 | governed by this License along with a term that is a further
406 | restriction, you may remove that term. If a license document contains
407 | a further restriction but permits relicensing or conveying under this
408 | License, you may add to a covered work material governed by the terms
409 | of that license document, provided that the further restriction does
410 | not survive such relicensing or conveying.
411 |
412 | If you add terms to a covered work in accord with this section, you
413 | must place, in the relevant source files, a statement of the
414 | additional terms that apply to those files, or a notice indicating
415 | where to find the applicable terms.
416 |
417 | Additional terms, permissive or non-permissive, may be stated in the
418 | form of a separately written license, or stated as exceptions;
419 | the above requirements apply either way.
420 |
421 | 8. Termination.
422 |
423 | You may not propagate or modify a covered work except as expressly
424 | provided under this License. Any attempt otherwise to propagate or
425 | modify it is void, and will automatically terminate your rights under
426 | this License (including any patent licenses granted under the third
427 | paragraph of section 11).
428 |
429 | However, if you cease all violation of this License, then your
430 | license from a particular copyright holder is reinstated (a)
431 | provisionally, unless and until the copyright holder explicitly and
432 | finally terminates your license, and (b) permanently, if the copyright
433 | holder fails to notify you of the violation by some reasonable means
434 | prior to 60 days after the cessation.
435 |
436 | Moreover, your license from a particular copyright holder is
437 | reinstated permanently if the copyright holder notifies you of the
438 | violation by some reasonable means, this is the first time you have
439 | received notice of violation of this License (for any work) from that
440 | copyright holder, and you cure the violation prior to 30 days after
441 | your receipt of the notice.
442 |
443 | Termination of your rights under this section does not terminate the
444 | licenses of parties who have received copies or rights from you under
445 | this License. If your rights have been terminated and not permanently
446 | reinstated, you do not qualify to receive new licenses for the same
447 | material under section 10.
448 |
449 | 9. Acceptance Not Required for Having Copies.
450 |
451 | You are not required to accept this License in order to receive or
452 | run a copy of the Program. Ancillary propagation of a covered work
453 | occurring solely as a consequence of using peer-to-peer transmission
454 | to receive a copy likewise does not require acceptance. However,
455 | nothing other than this License grants you permission to propagate or
456 | modify any covered work. These actions infringe copyright if you do
457 | not accept this License. Therefore, by modifying or propagating a
458 | covered work, you indicate your acceptance of this License to do so.
459 |
460 | 10. Automatic Licensing of Downstream Recipients.
461 |
462 | Each time you convey a covered work, the recipient automatically
463 | receives a license from the original licensors, to run, modify and
464 | propagate that work, subject to this License. You are not responsible
465 | for enforcing compliance by third parties with this License.
466 |
467 | An "entity transaction" is a transaction transferring control of an
468 | organization, or substantially all assets of one, or subdividing an
469 | organization, or merging organizations. If propagation of a covered
470 | work results from an entity transaction, each party to that
471 | transaction who receives a copy of the work also receives whatever
472 | licenses to the work the party's predecessor in interest had or could
473 | give under the previous paragraph, plus a right to possession of the
474 | Corresponding Source of the work from the predecessor in interest, if
475 | the predecessor has it or can get it with reasonable efforts.
476 |
477 | You may not impose any further restrictions on the exercise of the
478 | rights granted or affirmed under this License. For example, you may
479 | not impose a license fee, royalty, or other charge for exercise of
480 | rights granted under this License, and you may not initiate litigation
481 | (including a cross-claim or counterclaim in a lawsuit) alleging that
482 | any patent claim is infringed by making, using, selling, offering for
483 | sale, or importing the Program or any portion of it.
484 |
485 | 11. Patents.
486 |
487 | A "contributor" is a copyright holder who authorizes use under this
488 | License of the Program or a work on which the Program is based. The
489 | work thus licensed is called the contributor's "contributor version".
490 |
491 | A contributor's "essential patent claims" are all patent claims
492 | owned or controlled by the contributor, whether already acquired or
493 | hereafter acquired, that would be infringed by some manner, permitted
494 | by this License, of making, using, or selling its contributor version,
495 | but do not include claims that would be infringed only as a
496 | consequence of further modification of the contributor version. For
497 | purposes of this definition, "control" includes the right to grant
498 | patent sublicenses in a manner consistent with the requirements of
499 | this License.
500 |
501 | Each contributor grants you a non-exclusive, worldwide, royalty-free
502 | patent license under the contributor's essential patent claims, to
503 | make, use, sell, offer for sale, import and otherwise run, modify and
504 | propagate the contents of its contributor version.
505 |
506 | In the following three paragraphs, a "patent license" is any express
507 | agreement or commitment, however denominated, not to enforce a patent
508 | (such as an express permission to practice a patent or covenant not to
509 | sue for patent infringement). To "grant" such a patent license to a
510 | party means to make such an agreement or commitment not to enforce a
511 | patent against the party.
512 |
513 | If you convey a covered work, knowingly relying on a patent license,
514 | and the Corresponding Source of the work is not available for anyone
515 | to copy, free of charge and under the terms of this License, through a
516 | publicly available network server or other readily accessible means,
517 | then you must either (1) cause the Corresponding Source to be so
518 | available, or (2) arrange to deprive yourself of the benefit of the
519 | patent license for this particular work, or (3) arrange, in a manner
520 | consistent with the requirements of this License, to extend the patent
521 | license to downstream recipients. "Knowingly relying" means you have
522 | actual knowledge that, but for the patent license, your conveying the
523 | covered work in a country, or your recipient's use of the covered work
524 | in a country, would infringe one or more identifiable patents in that
525 | country that you have reason to believe are valid.
526 |
527 | If, pursuant to or in connection with a single transaction or
528 | arrangement, you convey, or propagate by procuring conveyance of, a
529 | covered work, and grant a patent license to some of the parties
530 | receiving the covered work authorizing them to use, propagate, modify
531 | or convey a specific copy of the covered work, then the patent license
532 | you grant is automatically extended to all recipients of the covered
533 | work and works based on it.
534 |
535 | A patent license is "discriminatory" if it does not include within
536 | the scope of its coverage, prohibits the exercise of, or is
537 | conditioned on the non-exercise of one or more of the rights that are
538 | specifically granted under this License. You may not convey a covered
539 | work if you are a party to an arrangement with a third party that is
540 | in the business of distributing software, under which you make payment
541 | to the third party based on the extent of your activity of conveying
542 | the work, and under which the third party grants, to any of the
543 | parties who would receive the covered work from you, a discriminatory
544 | patent license (a) in connection with copies of the covered work
545 | conveyed by you (or copies made from those copies), or (b) primarily
546 | for and in connection with specific products or compilations that
547 | contain the covered work, unless you entered into that arrangement,
548 | or that patent license was granted, prior to 28 March 2007.
549 |
550 | Nothing in this License shall be construed as excluding or limiting
551 | any implied license or other defenses to infringement that may
552 | otherwise be available to you under applicable patent law.
553 |
554 | 12. No Surrender of Others' Freedom.
555 |
556 | If conditions are imposed on you (whether by court order, agreement or
557 | otherwise) that contradict the conditions of this License, they do not
558 | excuse you from the conditions of this License. If you cannot convey a
559 | covered work so as to satisfy simultaneously your obligations under this
560 | License and any other pertinent obligations, then as a consequence you may
561 | not convey it at all. For example, if you agree to terms that obligate you
562 | to collect a royalty for further conveying from those to whom you convey
563 | the Program, the only way you could satisfy both those terms and this
564 | License would be to refrain entirely from conveying the Program.
565 |
566 | 13. Use with the GNU Affero General Public License.
567 |
568 | Notwithstanding any other provision of this License, you have
569 | permission to link or combine any covered work with a work licensed
570 | under version 3 of the GNU Affero General Public License into a single
571 | combined work, and to convey the resulting work. The terms of this
572 | License will continue to apply to the part which is the covered work,
573 | but the special requirements of the GNU Affero General Public License,
574 | section 13, concerning interaction through a network will apply to the
575 | combination as such.
576 |
577 | 14. Revised Versions of this License.
578 |
579 | The Free Software Foundation may publish revised and/or new versions of
580 | the GNU General Public License from time to time. Such new versions will
581 | be similar in spirit to the present version, but may differ in detail to
582 | address new problems or concerns.
583 |
584 | Each version is given a distinguishing version number. If the
585 | Program specifies that a certain numbered version of the GNU General
586 | Public License "or any later version" applies to it, you have the
587 | option of following the terms and conditions either of that numbered
588 | version or of any later version published by the Free Software
589 | Foundation. If the Program does not specify a version number of the
590 | GNU General Public License, you may choose any version ever published
591 | by the Free Software Foundation.
592 |
593 | If the Program specifies that a proxy can decide which future
594 | versions of the GNU General Public License can be used, that proxy's
595 | public statement of acceptance of a version permanently authorizes you
596 | to choose that version for the Program.
597 |
598 | Later license versions may give you additional or different
599 | permissions. However, no additional obligations are imposed on any
600 | author or copyright holder as a result of your choosing to follow a
601 | later version.
602 |
603 | 15. Disclaimer of Warranty.
604 |
605 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
606 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
607 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
608 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
609 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
610 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
611 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
612 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
613 |
614 | 16. Limitation of Liability.
615 |
616 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
617 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
618 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
619 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
620 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
621 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
622 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
623 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
624 | SUCH DAMAGES.
625 |
626 | 17. Interpretation of Sections 15 and 16.
627 |
628 | If the disclaimer of warranty and limitation of liability provided
629 | above cannot be given local legal effect according to their terms,
630 | reviewing courts shall apply local law that most closely approximates
631 | an absolute waiver of all civil liability in connection with the
632 | Program, unless a warranty or assumption of liability accompanies a
633 | copy of the Program in return for a fee.
634 |
635 | END OF TERMS AND CONDITIONS
636 |
637 | How to Apply These Terms to Your New Programs
638 |
639 | If you develop a new program, and you want it to be of the greatest
640 | possible use to the public, the best way to achieve this is to make it
641 | free software which everyone can redistribute and change under these terms.
642 |
643 | To do so, attach the following notices to the program. It is safest
644 | to attach them to the start of each source file to most effectively
645 | state the exclusion of warranty; and each file should have at least
646 | the "copyright" line and a pointer to where the full notice is found.
647 |
648 |
649 | Copyright (C)
650 |
651 | This program is free software: you can redistribute it and/or modify
652 | it under the terms of the GNU General Public License as published by
653 | the Free Software Foundation, either version 3 of the License, or
654 | (at your option) any later version.
655 |
656 | This program is distributed in the hope that it will be useful,
657 | but WITHOUT ANY WARRANTY; without even the implied warranty of
658 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
659 | GNU General Public License for more details.
660 |
661 | You should have received a copy of the GNU General Public License
662 | along with this program. If not, see .
663 |
664 | Also add information on how to contact you by electronic and paper mail.
665 |
666 | If the program does terminal interaction, make it output a short
667 | notice like this when it starts in an interactive mode:
668 |
669 | Copyright (C)
670 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
671 | This is free software, and you are welcome to redistribute it
672 | under certain conditions; type `show c' for details.
673 |
674 | The hypothetical commands `show w' and `show c' should show the appropriate
675 | parts of the General Public License. Of course, your program's commands
676 | might be different; for a GUI interface, you would use an "about box".
677 |
678 | You should also get your employer (if you work as a programmer) or school,
679 | if any, to sign a "copyright disclaimer" for the program, if necessary.
680 | For more information on this, and how to apply and follow the GNU GPL, see
681 | .
682 |
683 | The GNU General Public License does not permit incorporating your program
684 | into proprietary programs. If your program is a subroutine library, you
685 | may consider it more useful to permit linking proprietary applications with
686 | the library. If this is what you want to do, use the GNU Lesser General
687 | Public License instead of this License. But first, please read
688 | .
689 |
--------------------------------------------------------------------------------
/License.txt:
--------------------------------------------------------------------------------
1 | The MIT License (MIT)
2 |
3 | Copyright (c) 2015 Seeed Technology Inc.
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in
13 | all copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21 | THE SOFTWARE.
--------------------------------------------------------------------------------
/MutichannelGasSensor.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | MutichannelGasSensor.cpp
3 | 2015 Copyright (c) Seeed Technology Inc. All right reserved.
4 |
5 | Author: Jacky Zhang
6 | 2015-3-17
7 | http://www.seeed.cc/
8 | modi by Jack, 2015-8
9 |
10 | The MIT License (MIT)
11 |
12 | Copyright (c) 2015 Seeed Technology Inc.
13 |
14 | Permission is hereby granted, free of charge, to any person obtaining a copy
15 | of this software and associated documentation files (the "Software"), to deal
16 | in the Software without restriction, including without limitation the rights
17 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
18 | copies of the Software, and to permit persons to whom the Software is
19 | furnished to do so, subject to the following conditions:
20 |
21 | The above copyright notice and this permission notice shall be included in
22 | all copies or substantial portions of the Software.
23 |
24 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
25 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
26 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
27 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
28 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
29 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
30 | THE SOFTWARE.
31 | */
32 |
33 | #include
34 | #include
35 | #include
36 | #include "MutichannelGasSensor.h"
37 |
38 | MutichannelGasSensor::MutichannelGasSensor() : __version(2), i2cAddress(0x19) {
39 |
40 | }
41 | /*********************************************************************************************************
42 | ** Function name: begin
43 | ** Descriptions: initialize I2C
44 | *********************************************************************************************************/
45 | void MutichannelGasSensor::begin(int address) {
46 | __version = 1; // version 1/2
47 | r0_inited = false;
48 |
49 | Wire.begin();
50 | i2cAddress = address;
51 | __version = getVersion();
52 | }
53 |
54 | unsigned char MutichannelGasSensor::getVersion() {
55 | if (get_addr_dta(CMD_READ_EEPROM, ADDR_IS_SET) == 1126) { // get version
56 | __version = 2;
57 | _SERIAL.println("version = 2");
58 | return 2;
59 | }
60 |
61 | __version = 1;
62 | _SERIAL.println("version = 1");
63 | return 1;
64 | }
65 |
66 | void MutichannelGasSensor::begin() {
67 | begin(DEFAULT_I2C_ADDR);
68 | }
69 |
70 | /*********************************************************************************************************
71 | ** Function name: sendI2C
72 | ** Descriptions: send one byte to I2C Wire
73 | *********************************************************************************************************/
74 | void MutichannelGasSensor::sendI2C(unsigned char dta) {
75 | Wire.beginTransmission(i2cAddress); // transmit to device #4
76 | Wire.write(dta); // sends one byte
77 | Wire.endTransmission(); // stop transmitting
78 | }
79 |
80 |
81 | unsigned int MutichannelGasSensor::get_addr_dta(unsigned char addr_reg) {
82 | START:
83 | Wire.beginTransmission(i2cAddress);
84 | Wire.write(addr_reg);
85 | Wire.endTransmission(); // stop transmitting
86 | delay(2);
87 |
88 | Wire.requestFrom(i2cAddress, 2);
89 |
90 | unsigned int dta = 0;
91 |
92 | unsigned char raw[10];
93 | int cnt = 0;
94 |
95 | while (Wire.available()) {
96 | raw[cnt++] = Wire.read();
97 | }
98 |
99 | if (cnt == 0) {
100 | goto START;
101 | }
102 |
103 | dta = raw[0];
104 | dta <<= 8;
105 | dta += raw[1];
106 |
107 | switch (addr_reg) {
108 | case CH_VALUE_NH3:
109 |
110 | if (dta > 0) {
111 | adcValueR0_NH3_Buf = dta;
112 | } else {
113 | dta = adcValueR0_NH3_Buf;
114 | }
115 |
116 | break;
117 |
118 | case CH_VALUE_CO:
119 |
120 | if (dta > 0) {
121 | adcValueR0_CO_Buf = dta;
122 | } else {
123 | dta = adcValueR0_CO_Buf;
124 | }
125 |
126 | break;
127 |
128 | case CH_VALUE_NO2:
129 |
130 | if (dta > 0) {
131 | adcValueR0_NO2_Buf = dta;
132 | } else {
133 | dta = adcValueR0_NO2_Buf;
134 | }
135 |
136 | break;
137 |
138 | default:;
139 | }
140 | return dta;
141 | }
142 |
143 | unsigned int MutichannelGasSensor::get_addr_dta(unsigned char addr_reg, unsigned char __dta) {
144 |
145 | START:
146 | Wire.beginTransmission(i2cAddress);
147 | Wire.write(addr_reg);
148 | Wire.write(__dta);
149 | Wire.endTransmission(); // stop transmitting
150 | delay(2);
151 |
152 | Wire.requestFrom(i2cAddress, 2);
153 |
154 | unsigned int dta = 0;
155 |
156 | unsigned char raw[10];
157 | int cnt = 0;
158 |
159 | while (Wire.available()) {
160 | raw[cnt++] = Wire.read();
161 | }
162 |
163 | if (cnt == 0) {
164 | goto START;
165 | }
166 |
167 | dta = raw[0];
168 | dta <<= 8;
169 | dta += raw[1];
170 |
171 |
172 | return dta;
173 | }
174 |
175 | void MutichannelGasSensor::write_i2c(unsigned char addr, unsigned char* dta, unsigned char dta_len) {
176 | Wire.beginTransmission(addr);
177 | for (int i = 0; i < dta_len; i++) {
178 | Wire.write(dta[i]);
179 | }
180 | Wire.endTransmission();
181 | }
182 |
183 |
184 | /*********************************************************************************************************
185 | ** Function name: readData
186 | ** Descriptions: read 4 bytes from I2C slave
187 | *********************************************************************************************************/
188 | int16_t MutichannelGasSensor::readData(uint8_t cmd) {
189 | uint16_t timeout = 0;
190 | uint8_t buffer[4];
191 | uint8_t checksum = 0;
192 | int16_t rtnData = 0;
193 |
194 | //send command
195 | sendI2C(cmd);
196 | //wait for a while
197 | delay(2);
198 | //get response
199 | Wire.requestFrom(i2cAddress, (uint8_t)4); // request 4 bytes from slave device
200 | while (Wire.available() == 0) {
201 | if (timeout++ > 100) {
202 | return -2; //time out
203 | }
204 | delay(2);
205 | }
206 | if (Wire.available() != 4) {
207 | return -3; //rtnData length wrong
208 | }
209 | buffer[0] = Wire.read();
210 | buffer[1] = Wire.read();
211 | buffer[2] = Wire.read();
212 | buffer[3] = Wire.read();
213 | checksum = (uint8_t)(buffer[0] + buffer[1] + buffer[2]);
214 | if (checksum != buffer[3]) {
215 | return -4; //checksum wrong
216 | }
217 | rtnData = ((buffer[1] << 8) + buffer[2]);
218 |
219 | return rtnData;//successful
220 | }
221 |
222 | /*********************************************************************************************************
223 | ** Function name: readR0
224 | ** Descriptions: read R0 stored in slave MCU
225 | *********************************************************************************************************/
226 | int16_t MutichannelGasSensor::readR0(void) {
227 | int16_t rtnData = 0;
228 |
229 | rtnData = readData(0x11);
230 |
231 | if (rtnData > 0) {
232 | res0[0] = rtnData;
233 | } else {
234 | return rtnData; //unsuccessful
235 | }
236 |
237 | rtnData = readData(0x12);
238 | if (rtnData > 0) {
239 | res0[1] = rtnData;
240 | } else {
241 | return rtnData; //unsuccessful
242 | }
243 |
244 | rtnData = readData(0x13);
245 | if (rtnData > 0) {
246 | res0[2] = rtnData;
247 | } else {
248 | return rtnData; //unsuccessful
249 | }
250 |
251 | return 1;//successful
252 | }
253 |
254 | /*********************************************************************************************************
255 | ** Function name: readR
256 | ** Descriptions: read resistance value of each channel from slave MCU
257 | *********************************************************************************************************/
258 | int16_t MutichannelGasSensor::readR(void) {
259 | int16_t rtnData = 0;
260 |
261 | rtnData = readData(0x01);
262 | if (rtnData >= 0) {
263 | res[0] = rtnData;
264 | } else {
265 | return rtnData; //unsuccessful
266 | }
267 |
268 | rtnData = readData(0x02);
269 | if (rtnData >= 0) {
270 | res[1] = rtnData;
271 | } else {
272 | return rtnData; //unsuccessful
273 | }
274 |
275 | rtnData = readData(0x03);
276 | if (rtnData >= 0) {
277 | res[2] = rtnData;
278 | } else {
279 | return rtnData; //unsuccessful
280 | }
281 |
282 | return 0;//successful
283 | }
284 |
285 | /*********************************************************************************************************
286 | ** Function name: readR
287 | ** Descriptions: calculate gas concentration of each channel from slave MCU
288 | ** Parameters:
289 | gas - gas type
290 | ** Returns:
291 | float value - concentration of the gas
292 | *********************************************************************************************************/
293 | float MutichannelGasSensor::calcGas(int gas) {
294 |
295 | float ratio0, ratio1, ratio2;
296 | if (1 == __version) {
297 | if (!r0_inited) {
298 | if (readR0() >= 0) {
299 | r0_inited = true;
300 | } else {
301 | return -1.0f;
302 | }
303 | }
304 |
305 | if (readR() < 0) {
306 | return -2.0f;
307 | }
308 |
309 | ratio0 = (float)res[0] / res0[0];
310 | ratio1 = (float)res[1] / res0[1];
311 | ratio2 = (float)res[2] / res0[2];
312 | } else if (2 == __version) {
313 | // how to calc ratio/123
314 | ledOn();
315 | int A0_0 = get_addr_dta(6, ADDR_USER_ADC_HN3);
316 | int A0_1 = get_addr_dta(6, ADDR_USER_ADC_CO);
317 | int A0_2 = get_addr_dta(6, ADDR_USER_ADC_NO2);
318 |
319 | int An_0 = get_addr_dta(CH_VALUE_NH3);
320 | int An_1 = get_addr_dta(CH_VALUE_CO);
321 | int An_2 = get_addr_dta(CH_VALUE_NO2);
322 |
323 | ratio0 = (float)An_0 / (float)A0_0 * (1023.0 - A0_0) / (1023.0 - An_0);
324 | ratio1 = (float)An_1 / (float)A0_1 * (1023.0 - A0_1) / (1023.0 - An_1);
325 | ratio2 = (float)An_2 / (float)A0_2 * (1023.0 - A0_2) / (1023.0 - An_2);
326 |
327 | }
328 |
329 | float c = 0;
330 |
331 | switch (gas) {
332 | case CO: {
333 | c = pow(ratio1, -1.179) * 4.385; //mod by jack
334 | break;
335 | }
336 | case NO2: {
337 | c = pow(ratio2, 1.007) / 6.855; //mod by jack
338 | break;
339 | }
340 | case NH3: {
341 | c = pow(ratio0, -1.67) / 1.47; //modi by jack
342 | break;
343 | }
344 | case C3H8: { //add by jack
345 | c = pow(ratio0, -2.518) * 570.164;
346 | break;
347 | }
348 | case C4H10: { //add by jack
349 | c = pow(ratio0, -2.138) * 398.107;
350 | break;
351 | }
352 | case CH4: { //add by jack
353 | c = pow(ratio1, -4.363) * 630.957;
354 | break;
355 | }
356 | case H2: { //add by jack
357 | c = pow(ratio1, -1.8) * 0.73;
358 | break;
359 | }
360 | case C2H5OH: { //add by jack
361 | c = pow(ratio1, -1.552) * 1.622;
362 | break;
363 | }
364 | default:
365 | break;
366 | }
367 |
368 | if (2 == __version) {
369 | ledOff();
370 | }
371 | return isnan(c) ? -3 : c;
372 | }
373 |
374 | /*********************************************************************************************************
375 | ** Function name: changeI2cAddr
376 | ** Descriptions: change I2C address of the slave MCU, and this address will be stored in EEPROM of slave MCU
377 | *********************************************************************************************************/
378 | void MutichannelGasSensor::changeI2cAddr(uint8_t newAddr) {
379 | Wire.beginTransmission(i2cAddress); // transmit to device
380 | Wire.write(0x23); // sends one byte
381 | Wire.write(newAddr); // sends one byte
382 | Wire.endTransmission(); // stop transmitting
383 | i2cAddress = newAddr;
384 | }
385 |
386 | /*********************************************************************************************************
387 | ** Function name: doCalibrate
388 | ** Descriptions: tell slave to do a calibration, it will take about 8s
389 | after the calibration, must reread the R0 values
390 | *********************************************************************************************************/
391 | void MutichannelGasSensor::doCalibrate(void) {
392 |
393 | if (1 == __version) {
394 | START:
395 |
396 | sendI2C(0x22);
397 | if (readR0() > 0) {
398 | for (int i = 0; i < 3; i++) {
399 | _SERIAL.print(res0[i]);
400 | _SERIAL.print('\t');
401 | }
402 | } else {
403 | delay(5000);
404 | _SERIAL.println("continue...");
405 | for (int i = 0; i < 3; i++) {
406 | _SERIAL.print(res0[i]);
407 | _SERIAL.print('\t');
408 | }
409 | _SERIAL.println();
410 | goto START;
411 | }
412 | } else if (2 == __version) {
413 | unsigned int i, a0, a1, a2;
414 | while (1) {
415 | a0 = get_addr_dta(CH_VALUE_NH3);
416 | a1 = get_addr_dta(CH_VALUE_CO);
417 | a2 = get_addr_dta(CH_VALUE_NO2);
418 |
419 | _SERIAL.print(a0);
420 | _SERIAL.print('\t');
421 | _SERIAL.print(a1);
422 | _SERIAL.print('\t');
423 | _SERIAL.print(a2);
424 | _SERIAL.println('\t');
425 | ledOn();
426 |
427 | int cnt = 0;
428 | for (i = 0; i < 20; i++) {
429 | if ((a0 - get_addr_dta(CH_VALUE_NH3)) > 2 || (get_addr_dta(CH_VALUE_NH3) - a0) > 2) {
430 | cnt++;
431 | }
432 | if ((a1 - get_addr_dta(CH_VALUE_CO)) > 2 || (get_addr_dta(CH_VALUE_CO) - a1) > 2) {
433 | cnt++;
434 | }
435 | if ((a2 - get_addr_dta(CH_VALUE_NO2)) > 2 || (get_addr_dta(CH_VALUE_NO2) - a2) > 2) {
436 | cnt++;
437 | }
438 |
439 | if (cnt > 5) {
440 | break;
441 | }
442 | delay(1000);
443 | }
444 |
445 | ledOff();
446 | if (cnt <= 5) {
447 | break;
448 | }
449 | delay(200);
450 | }
451 |
452 | _SERIAL.print("write user adc value: ");
453 | _SERIAL.print(a0); _SERIAL.print('\t');
454 | _SERIAL.print(a1); _SERIAL.print('\t');
455 | _SERIAL.print(a2); _SERIAL.println('\t');
456 |
457 | unsigned char tmp[7];
458 |
459 | tmp[0] = 7;
460 |
461 | tmp[1] = a0 >> 8;
462 | tmp[2] = a0 & 0xff;
463 |
464 | tmp[3] = a1 >> 8;
465 | tmp[4] = a1 & 0xff;
466 |
467 | tmp[5] = a2 >> 8;
468 | tmp[6] = a2 & 0xff;
469 |
470 | write_i2c(i2cAddress, tmp, 7);
471 | }
472 | }
473 |
474 | /*********************************************************************************************************
475 | ** Function name: powerOn
476 | ** Descriptions: power on sensor heater
477 | *********************************************************************************************************/
478 | void MutichannelGasSensor::powerOn(void) {
479 | if (__version == 1) {
480 | sendI2C(0x21);
481 | } else if (__version == 2) {
482 | dta_test[0] = 11;
483 | dta_test[1] = 1;
484 | write_i2c(i2cAddress, dta_test, 2);
485 | }
486 | }
487 |
488 | /*********************************************************************************************************
489 | ** Function name: powerOff
490 | ** Descriptions: power off sensor heater
491 | *********************************************************************************************************/
492 | void MutichannelGasSensor::powerOff(void) {
493 | if (__version == 1) {
494 | sendI2C(0x20);
495 | } else if (__version == 2) {
496 | dta_test[0] = 11;
497 | dta_test[1] = 0;
498 | write_i2c(i2cAddress, dta_test, 2);
499 | }
500 | }
501 |
502 | void MutichannelGasSensor::display_eeprom() {
503 | if (__version == 1) {
504 | _SERIAL.println("ERROR: display_eeprom() is NOT support by V1 firmware.");
505 | return ;
506 | }
507 |
508 | _SERIAL.print("ADDR_IS_SET = "); _SERIAL.println(get_addr_dta(CMD_READ_EEPROM, ADDR_IS_SET));
509 | _SERIAL.print("ADDR_FACTORY_ADC_NH3 = "); _SERIAL.println(get_addr_dta(CMD_READ_EEPROM, ADDR_FACTORY_ADC_NH3));
510 | _SERIAL.print("ADDR_FACTORY_ADC_CO = "); _SERIAL.println(get_addr_dta(CMD_READ_EEPROM, ADDR_FACTORY_ADC_CO));
511 | _SERIAL.print("ADDR_FACTORY_ADC_NO2 = "); _SERIAL.println(get_addr_dta(CMD_READ_EEPROM, ADDR_FACTORY_ADC_NO2));
512 | _SERIAL.print("ADDR_USER_ADC_HN3 = "); _SERIAL.println(get_addr_dta(CMD_READ_EEPROM, ADDR_USER_ADC_HN3));
513 | _SERIAL.print("ADDR_USER_ADC_CO = "); _SERIAL.println(get_addr_dta(CMD_READ_EEPROM, ADDR_USER_ADC_CO));
514 | _SERIAL.print("ADDR_USER_ADC_NO2 = "); _SERIAL.println(get_addr_dta(CMD_READ_EEPROM, ADDR_USER_ADC_NO2));
515 | _SERIAL.print("ADDR_I2C_ADDRESS = "); _SERIAL.println(get_addr_dta(CMD_READ_EEPROM, ADDR_I2C_ADDRESS));
516 | }
517 |
518 | float MutichannelGasSensor::getR0(unsigned char ch) { // 0:CH3, 1:CO, 2:NO2
519 | if (__version == 1) {
520 | _SERIAL.println("ERROR: getR0() is NOT support by V1 firmware.");
521 | return -1;
522 | }
523 |
524 | int a = 0;
525 | switch (ch) {
526 | case 0: // CH3
527 | a = get_addr_dta(CMD_READ_EEPROM, ADDR_USER_ADC_HN3);
528 | _SERIAL.print("a_ch3 = ");
529 | _SERIAL.println(a);
530 | break;
531 |
532 | case 1: // CO
533 | a = get_addr_dta(CMD_READ_EEPROM, ADDR_USER_ADC_CO);
534 | _SERIAL.print("a_co = ");
535 | _SERIAL.println(a);
536 | break;
537 |
538 | case 2: // NO2
539 | a = get_addr_dta(CMD_READ_EEPROM, ADDR_USER_ADC_NO2);
540 | _SERIAL.print("a_no2 = ");
541 | _SERIAL.println(a);
542 | break;
543 |
544 | default:;
545 | }
546 |
547 | float r = 56.0 * (float)a / (1023.0 - (float)a);
548 | return r;
549 | }
550 |
551 | float MutichannelGasSensor::getRs(unsigned char ch) { // 0:CH3, 1:CO, 2:NO2
552 |
553 | if (__version == 1) {
554 | _SERIAL.println("ERROR: getRs() is NOT support by V1 firmware.");
555 | return -1;
556 | }
557 |
558 | int a = 0;
559 | switch (ch) {
560 | case 0: // NH3
561 | a = get_addr_dta(1);
562 | break;
563 |
564 | case 1: // CO
565 | a = get_addr_dta(2);
566 | break;
567 |
568 | case 2: // NO2
569 | a = get_addr_dta(3);
570 | break;
571 |
572 | default:;
573 | }
574 |
575 | float r = 56.0 * (float)a / (1023.0 - (float)a);
576 | return r;
577 | }
578 |
579 | // 1. change i2c address to 0x04
580 | // 2. change adc value of R0 to default
581 | void MutichannelGasSensor::factory_setting() {
582 |
583 | unsigned char tmp[7];
584 |
585 | unsigned char error;
586 | unsigned char address = 0;
587 |
588 | for (address = 1; address < 127; address++) {
589 | // The i2c_scanner uses the return value of
590 | // the Write.endTransmisstion to see if
591 | // a device did acknowledge to the address.
592 | Wire.beginTransmission(address);
593 | error = Wire.endTransmission();
594 |
595 | if (error == 0) {
596 | // change i2c to 0x04
597 |
598 | _SERIAL.print("I2C address is: 0x");
599 | _SERIAL.println(address, HEX);
600 | _SERIAL.println("Change I2C address to 0x04");
601 |
602 | dta_test[0] = CMD_CHANGE_I2C;
603 | dta_test[1] = 0x04;
604 | write_i2c(address, dta_test, 2);
605 |
606 | i2cAddress = 0x04;
607 | delay(100);
608 | getVersion();
609 | break;
610 | }
611 | }
612 |
613 | unsigned int a0 = get_addr_dta(CMD_READ_EEPROM, ADDR_FACTORY_ADC_NH3);
614 | unsigned int a1 = get_addr_dta(CMD_READ_EEPROM, ADDR_FACTORY_ADC_CO);
615 | unsigned int a2 = get_addr_dta(CMD_READ_EEPROM, ADDR_FACTORY_ADC_NO2);
616 |
617 | tmp[0] = 7;
618 | tmp[1] = a0 >> 8;
619 | tmp[2] = a0 & 0xff;
620 | tmp[3] = a1 >> 8;
621 | tmp[4] = a1 & 0xff;
622 |
623 | tmp[5] = a2 >> 8;
624 | tmp[6] = a2 & 0xff;
625 | delay(100);
626 | write_i2c(i2cAddress, tmp, 7);
627 | delay(100);
628 | }
629 |
630 | void MutichannelGasSensor::change_i2c_address(unsigned char addr) {
631 | dta_test[0] = CMD_CHANGE_I2C;
632 | dta_test[1] = addr;
633 | write_i2c(i2cAddress, dta_test, 2);
634 |
635 |
636 | _SERIAL.print("FUNCTION: CHANGE I2C ADDRESS: 0X");
637 | _SERIAL.print(i2cAddress, HEX);
638 | _SERIAL.print(" > 0x");
639 | _SERIAL.println(addr, HEX);
640 |
641 | i2cAddress = addr;
642 | }
643 |
644 | MutichannelGasSensor gas;
645 | /*********************************************************************************************************
646 | END FILE
647 | *********************************************************************************************************/
--------------------------------------------------------------------------------
/MutichannelGasSensor.h:
--------------------------------------------------------------------------------
1 | /*
2 | MutichannelGasSensor.h
3 | 2015 Copyright (c) Seeed Technology Inc. All right reserved.
4 |
5 | Author: Jacky Zhang
6 | 2015-3-17
7 | http://www.seeed.cc/
8 | modi by Jack, 2015-8
9 |
10 | V2 by Loovee
11 | 2016-11-11
12 |
13 | The MIT License (MIT)
14 |
15 | Copyright (c) 2015 Seeed Technology Inc.
16 |
17 | Permission is hereby granted, free of charge, to any person obtaining a copy
18 | of this software and associated documentation files (the "Software"), to deal
19 | in the Software without restriction, including without limitation the rights
20 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
21 | copies of the Software, and to permit persons to whom the Software is
22 | furnished to do so, subject to the following conditions:
23 |
24 | The above copyright notice and this permission notice shall be included in
25 | all copies or substantial portions of the Software.
26 |
27 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
28 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
29 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
30 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
31 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
32 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
33 | THE SOFTWARE.
34 | */
35 |
36 | #ifndef __MUTICHANNELGASSENSOR_H__
37 | #define __MUTICHANNELGASSENSOR_H__
38 |
39 | #if defined (ARDUINO_SAMD_ZERO)
40 | #define _SERIAL SerialUSB
41 | #elif defined(ARDUINO_ARCH_SEEED_STM32F4)
42 | #define _SERIAL SerialUSB
43 | #elif defined (ARDUINO_ARCH_SAMD)
44 | #define _SERIAL Serial
45 | #elif defined (ARDUINO_ARCH_AVR)
46 | #define _SERIAL Serial
47 | #else
48 | #error "Architecture not matched"
49 | #endif
50 |
51 |
52 | #define DEFAULT_I2C_ADDR 0x04
53 |
54 | #define ADDR_IS_SET 0 // if this is the first time to run, if 1126, set
55 | #define ADDR_FACTORY_ADC_NH3 2
56 | #define ADDR_FACTORY_ADC_CO 4
57 | #define ADDR_FACTORY_ADC_NO2 6
58 |
59 | #define ADDR_USER_ADC_HN3 8
60 | #define ADDR_USER_ADC_CO 10
61 | #define ADDR_USER_ADC_NO2 12
62 | #define ADDR_IF_CALI 14 // IF USER HAD CALI
63 |
64 | #define ADDR_I2C_ADDRESS 20
65 |
66 | #define CH_VALUE_NH3 1
67 | #define CH_VALUE_CO 2
68 | #define CH_VALUE_NO2 3
69 |
70 | #define CMD_ADC_RES0 1 // NH3
71 | #define CMD_ADC_RES1 2 // CO
72 | #define CMD_ADC_RES2 3 // NO2
73 | #define CMD_ADC_RESALL 4 // ALL CHANNEL
74 | #define CMD_CHANGE_I2C 5 // CHANGE I2C
75 | #define CMD_READ_EEPROM 6 // READ EEPROM VALUE, RETURN UNSIGNED INT
76 | #define CMD_SET_R0_ADC 7 // SET R0 ADC VALUE
77 | #define CMD_GET_R0_ADC 8 // GET R0 ADC VALUE
78 | #define CMD_GET_R0_ADC_FACTORY 9 // GET FACTORY R0 ADC VALUE
79 | #define CMD_CONTROL_LED 10
80 | #define CMD_CONTROL_PWR 11
81 |
82 | enum {CO, NO2, NH3, C3H8, C4H10, CH4, H2, C2H5OH};
83 |
84 | class MutichannelGasSensor {
85 |
86 | private:
87 |
88 | int __version;
89 | unsigned char dta_test[20];
90 |
91 | unsigned int readChAdcValue(int ch);
92 | unsigned int adcValueR0_NH3_Buf;
93 | unsigned int adcValueR0_CO_Buf;
94 | unsigned int adcValueR0_NO2_Buf;
95 |
96 | public:
97 |
98 | uint8_t i2cAddress; //I2C address of this MCU
99 | uint16_t res0[3]; //sensors res0
100 | uint16_t res[3]; //sensors res
101 | bool r0_inited;
102 |
103 | MutichannelGasSensor();
104 | inline unsigned int get_addr_dta(unsigned char addr_reg);
105 | inline unsigned int get_addr_dta(unsigned char addr_reg, unsigned char __dta);
106 | inline void write_i2c(unsigned char addr, unsigned char* dta, unsigned char dta_len);
107 |
108 | void sendI2C(unsigned char dta);
109 | int16_t readData(uint8_t cmd);
110 | int16_t readR0(void);
111 | int16_t readR(void);
112 | float calcGas(int gas);
113 |
114 | public:
115 |
116 | void begin(int address);
117 | void begin();
118 | void changeI2cAddr(uint8_t newAddr);
119 | void powerOn(void);
120 | void powerOff(void);
121 | void doCalibrate(void);
122 |
123 | //get gas concentration, unit: ppm
124 | float measure_CO() {
125 | return calcGas(CO);
126 | }
127 | float measure_NO2() {
128 | return calcGas(NO2);
129 | }
130 | float measure_NH3() {
131 | return calcGas(NH3);
132 | }
133 | float measure_C3H8() {
134 | return calcGas(C3H8);
135 | }
136 | float measure_C4H10() {
137 | return calcGas(C4H10);
138 | }
139 | float measure_CH4() {
140 | return calcGas(CH4);
141 | }
142 | float measure_H2() {
143 | return calcGas(H2);
144 | }
145 | float measure_C2H5OH() {
146 | return calcGas(C2H5OH);
147 | }
148 |
149 | float getR0(unsigned char ch); // 0:CH3, 1:CO, 2:NO2
150 | float getRs(unsigned char ch); // 0:CH3, 1:CO, 2:NO2
151 |
152 | public:
153 |
154 | void ledOn() {
155 | dta_test[0] = CMD_CONTROL_LED;
156 | dta_test[1] = 1;
157 | write_i2c(i2cAddress, dta_test, 2);
158 | }
159 |
160 | void ledOff() {
161 | dta_test[0] = CMD_CONTROL_LED;
162 | dta_test[1] = 0;
163 | write_i2c(i2cAddress, dta_test, 2);
164 | }
165 |
166 | void display_eeprom();
167 | void factory_setting();
168 | void change_i2c_address(unsigned char addr);
169 | unsigned char getVersion();
170 | };
171 |
172 | extern MutichannelGasSensor gas;
173 |
174 | #endif
175 |
176 | /*********************************************************************************************************
177 | END FILE
178 | *********************************************************************************************************/
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Mutichannel_Gas_Sensor [](https://travis-ci.com/Seeed-Studio/Mutichannel_Gas_Sensor)
2 | This Arduino library is used for driving "Xadow - Mutichannel Gas Sensor" and "Grove - Mutichanel Gas Sensor"
3 |
4 | 
5 |
6 | [Grove - Multichannel Gas Sensor](https://www.seeedstudio.com/s/Grove-Multichannel-Gas-Sensor-p-2502.html)
7 |
8 | ## Usage:
9 |
10 | mutichannelGasSensor.begin(0x04);
11 |
12 | mutichannelGasSensor.powerOn();
13 |
14 | then read the concentration of the specific gas you want to measure:
15 |
16 | mutichannelGasSensor.measure_NH3();
17 |
18 | mutichannelGasSensor.measure_CO();
19 |
20 | mutichannelGasSensor.measure_NO2();
21 |
22 | mutichannelGasSensor.measure_C3H8();
23 |
24 | mutichannelGasSensor.measure_C4H10();
25 |
26 | mutichannelGasSensor.measure_CH4();
27 |
28 | mutichannelGasSensor.measure_H2();
29 |
30 | mutichannelGasSensor.measure_C2H5OH();
31 |
32 | For details please move to [wiki page](http://wiki.seeedstudio.com/Grove-Multichannel_Gas_Sensor/).
33 |
34 |
35 |
36 | ----
37 |
38 | This software is written by Jacky Zhang () from [Seeed Technology Inc.](http://www.seeed.cc) and is licensed under [The MIT License](http://opensource.org/licenses/mit-license.php). Check License.txt/LICENSE for the details of MIT license.
39 |
40 | Contributing to this software is warmly welcomed. You can do this basically by
41 | [forking](https://help.github.com/articles/fork-a-repo), committing modifications and then [pulling requests](https://help.github.com/articles/using-pull-requests) (follow the links above
42 | for operating guide). Adding change log and your contact into file header is encouraged.
43 | Thanks for your contribution.
44 |
45 | Seeed is a hardware innovation platform for makers to grow inspirations into differentiating products. By working closely with technology providers of all scale, Seeed provides accessible technologies with quality, speed and supply chain knowledge. When prototypes are ready to iterate, Seeed helps productize 1 to 1,000 pcs using in-house engineering, supply chain management and agile manufacture forces. Seeed also team up with incubators, Chinese tech ecosystem, investors and distribution channels to portal Maker startups beyond.
46 |
47 |
48 | [](https://github.com/igrigorik/ga-beacon)
49 |
--------------------------------------------------------------------------------
/examples/GetVersion/GetVersion.ino:
--------------------------------------------------------------------------------
1 | // Get firmware version of Grove Multichannel Gas Sensor
2 | #include
3 | #include "MutichannelGasSensor.h"
4 |
5 | #define SENSOR_ADDR 0X04 // default to 0x04
6 |
7 | void setup() {
8 | Serial.begin(115200);
9 | gas.begin(SENSOR_ADDR);
10 |
11 | unsigned char version = gas.getVersion();
12 | Serial.print("Version = ");
13 | Serial.println(version);
14 | }
15 |
16 | void loop() {
17 | // nothing to do
18 | }
--------------------------------------------------------------------------------
/examples/I2C_Address/I2C_Address.ino:
--------------------------------------------------------------------------------
1 | // change i2c address
2 | // Loovee
3 | // 2016-11-10
4 |
5 | #include
6 | #include "MutichannelGasSensor.h"
7 |
8 | #define SENSOR_ADDR_OLD 0x04 // default to 0x04
9 | #define SENSOR_ADDR_NEW 0x19 // change i2c address to 0x19
10 |
11 | void setup() {
12 | Serial.begin(115200);
13 | gas.begin(SENSOR_ADDR_OLD); //
14 | gas.change_i2c_address(SENSOR_ADDR_NEW);
15 | Serial.print("I2C ADDRESS SET TO 0X");;
16 | Serial.println(SENSOR_ADDR_NEW, HEX);
17 | }
18 |
19 | void loop() {
20 |
21 | }
22 |
23 | // END FILE
24 |
--------------------------------------------------------------------------------
/examples/RawData/RawData.ino:
--------------------------------------------------------------------------------
1 | // get RAW data from the sensor
2 | // Loovee
3 | // 2016-11-10
4 |
5 | #include
6 | #include "MutichannelGasSensor.h"
7 |
8 | #define SENSOR_ADDR 0X04 // default to 0x04
9 |
10 | void setup() {
11 | Serial.begin(115200);
12 | gas.begin(SENSOR_ADDR); //
13 | }
14 |
15 | void loop() {
16 | float R0_NH3, R0_CO, R0_NO2;
17 | float Rs_NH3, Rs_CO, Rs_NO2;
18 | float ratio_NH3, ratio_CO, ratio_NO2;
19 |
20 | R0_NH3 = gas.getR0(0);
21 | R0_CO = gas.getR0(1);
22 | R0_NO2 = gas.getR0(2);
23 |
24 | Rs_NH3 = gas.getRs(0);
25 | Rs_CO = gas.getRs(1);
26 | Rs_NO2 = gas.getRs(2);
27 |
28 | ratio_NH3 = Rs_NH3 / R0_NH3;
29 | ratio_CO = Rs_CO / R0_CO;
30 | ratio_NO2 = Rs_NO2 / R0_NO2;
31 |
32 | Serial.println("R0:");
33 | Serial.print(R0_NH3);
34 | Serial.print('\t');
35 | Serial.print(R0_CO);
36 | Serial.print('\t');
37 | Serial.println(R0_NO2);
38 |
39 | Serial.println("Rs:");
40 | Serial.print(Rs_NH3);
41 | Serial.print('\t');
42 | Serial.print(Rs_CO);
43 | Serial.print('\t');
44 | Serial.println(Rs_NO2);
45 |
46 | Serial.println("ratio:");
47 | Serial.print(ratio_NH3);
48 | Serial.print('\t');
49 | Serial.print(ratio_CO);
50 | Serial.print('\t');
51 | Serial.println(ratio_NO2);
52 |
53 | Serial.println("------------------------");
54 | delay(1000);
55 | }
56 |
--------------------------------------------------------------------------------
/examples/ReadSensorValue_Grove/ReadSensorValue_Grove.ino:
--------------------------------------------------------------------------------
1 | /*
2 | This is a demo to test gas library
3 | This code is running on Xadow-mainboard, and the I2C slave is Xadow-gas
4 | There is a ATmega168PA on Xadow-gas, it get sensors output and feed back to master.
5 | the data is raw ADC value, algorithm should be realized on master.
6 |
7 | please feel free to write email to me if there is any question
8 |
9 | Jacky Zhang, Embedded Software Engineer
10 | qi.zhang@seeed.cc
11 | 17,mar,2015
12 | */
13 |
14 | #include
15 | #include "MutichannelGasSensor.h"
16 |
17 | void setup() {
18 | Serial.begin(115200); // start serial for output
19 | Serial.println("power on!");
20 | gas.begin(0x04);//the default I2C address of the slave is 0x04
21 | gas.powerOn();
22 | Serial.print("Firmware Version = ");
23 | Serial.println(gas.getVersion());
24 | }
25 |
26 | void loop() {
27 | float c;
28 |
29 | c = gas.measure_NH3();
30 | Serial.print("The concentration of NH3 is ");
31 | if (c >= 0) {
32 | Serial.print(c);
33 | } else {
34 | Serial.print("invalid");
35 | }
36 | Serial.println(" ppm");
37 |
38 | c = gas.measure_CO();
39 | Serial.print("The concentration of CO is ");
40 | if (c >= 0) {
41 | Serial.print(c);
42 | } else {
43 | Serial.print("invalid");
44 | }
45 | Serial.println(" ppm");
46 |
47 | c = gas.measure_NO2();
48 | Serial.print("The concentration of NO2 is ");
49 | if (c >= 0) {
50 | Serial.print(c);
51 | } else {
52 | Serial.print("invalid");
53 | }
54 | Serial.println(" ppm");
55 |
56 | c = gas.measure_C3H8();
57 | Serial.print("The concentration of C3H8 is ");
58 | if (c >= 0) {
59 | Serial.print(c);
60 | } else {
61 | Serial.print("invalid");
62 | }
63 | Serial.println(" ppm");
64 |
65 | c = gas.measure_C4H10();
66 | Serial.print("The concentration of C4H10 is ");
67 | if (c >= 0) {
68 | Serial.print(c);
69 | } else {
70 | Serial.print("invalid");
71 | }
72 | Serial.println(" ppm");
73 |
74 | c = gas.measure_CH4();
75 | Serial.print("The concentration of CH4 is ");
76 | if (c >= 0) {
77 | Serial.print(c);
78 | } else {
79 | Serial.print("invalid");
80 | }
81 | Serial.println(" ppm");
82 |
83 | c = gas.measure_H2();
84 | Serial.print("The concentration of H2 is ");
85 | if (c >= 0) {
86 | Serial.print(c);
87 | } else {
88 | Serial.print("invalid");
89 | }
90 | Serial.println(" ppm");
91 |
92 | c = gas.measure_C2H5OH();
93 | Serial.print("The concentration of C2H5OH is ");
94 | if (c >= 0) {
95 | Serial.print(c);
96 | } else {
97 | Serial.print("invalid");
98 | }
99 | Serial.println(" ppm");
100 |
101 | delay(1000);
102 | Serial.println("...");
103 | }
--------------------------------------------------------------------------------
/examples/ReadSensorValue_Xadow/ReadSensorValue_Xadow.ino:
--------------------------------------------------------------------------------
1 | /*
2 | This is a demo to test gas library
3 | This code is running on Xadow-mainboard, and the I2C slave is Xadow-gas
4 | There is a ATmega168PA on Xadow-gas, it get sensors output and feed back to master.
5 | the data is raw ADC value, algorithm should be realized on master.
6 |
7 | please feel free to write email to me if there is any question
8 |
9 | Jacky Zhang, Embedded Software Engineer
10 | qi.zhang@seeed.cc
11 | 17,mar,2015
12 | */
13 |
14 | #include "xadow.h"
15 | #include
16 | #include "MutichannelGasSensor.h"
17 |
18 | void setup() {
19 | Xadow.init();
20 |
21 | Serial.begin(9600); // start serial for output
22 | Serial.println("power on!");
23 |
24 | gas.begin(0x04);//the default I2C address of the slave is 0x04
25 | //gas.changeI2cAddr(0x10);
26 | //gas.doCalibrate();
27 |
28 | gas.powerOn();
29 | }
30 |
31 | void loop() {
32 | float c;
33 |
34 | c = gas.measure_NH3();
35 | Serial.print("The concentration of NH3 is ");
36 | if (c >= 0) {
37 | Serial.print(c);
38 | } else {
39 | Serial.print("invalid");
40 | }
41 | Serial.println(" ppm");
42 |
43 | c = gas.measure_CO();
44 | Serial.print("The concentration of CO is ");
45 | if (c >= 0) {
46 | Serial.print(c);
47 | } else {
48 | Serial.print("invalid");
49 | }
50 | Serial.println(" ppm");
51 |
52 | c = gas.measure_NO2();
53 | Serial.print("The concentration of NO2 is ");
54 | if (c >= 0) {
55 | Serial.print(c);
56 | } else {
57 | Serial.print("invalid");
58 | }
59 | Serial.println(" ppm");
60 |
61 | c = gas.measure_C3H8();
62 | Serial.print("The concentration of C3H8 is ");
63 | if (c >= 0) {
64 | Serial.print(c);
65 | } else {
66 | Serial.print("invalid");
67 | }
68 | Serial.println(" ppm");
69 |
70 | c = gas.measure_C4H10();
71 | Serial.print("The concentration of C4H10 is ");
72 | if (c >= 0) {
73 | Serial.print(c);
74 | } else {
75 | Serial.print("invalid");
76 | }
77 | Serial.println(" ppm");
78 |
79 | c = gas.measure_CH4();
80 | Serial.print("The concentration of CH4 is ");
81 | if (c >= 0) {
82 | Serial.print(c);
83 | } else {
84 | Serial.print("invalid");
85 | }
86 | Serial.println(" ppm");
87 |
88 | c = gas.measure_H2();
89 | Serial.print("The concentration of H2 is ");
90 | if (c >= 0) {
91 | Serial.print(c);
92 | } else {
93 | Serial.print("invalid");
94 | }
95 | Serial.println(" ppm");
96 |
97 | c = gas.measure_C2H5OH();
98 | Serial.print("The concentration of C2H5OH is ");
99 | if (c >= 0) {
100 | Serial.print(c);
101 | } else {
102 | Serial.print("invalid");
103 | }
104 | Serial.println(" ppm");
105 |
106 | Xadow.greenLed(LEDON);
107 | delay(500);
108 | Xadow.greenLed(LEDOFF);
109 | delay(500);
110 | Serial.println("...");
111 | }
--------------------------------------------------------------------------------
/examples/UpdateFrimware/.DS_Store:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Seeed-Studio/Mutichannel_Gas_Sensor/abb44bec847b03690f70d9a39af5e23615791bde/examples/UpdateFrimware/.DS_Store
--------------------------------------------------------------------------------
/examples/UpdateFrimware/UpdateFrimware.ino:
--------------------------------------------------------------------------------
1 | // Atmega chip programmer
2 | // Author: Nick Gammon
3 | // Date: 22nd May 2012
4 | // Version: 1.17
5 |
6 | // Version 1.1: Reset foundSig to -1 each time around the loop.
7 | // Version 1.2: Put hex bootloader data into separate files
8 | // Version 1.3: Added verify, and MD5 sums
9 | // Version 1.4: Added signatures for ATmeag8U2/16U2/32U2 (7 May 2012)
10 | // Version 1.5: Added signature for ATmega1284P (8 May 2012)
11 | // Version 1.6: Allow sketches to read bootloader area (lockbyte: 0x2F)
12 | // Version 1.7: Added choice of bootloaders for the Atmega328P (8 MHz or 16 MHz)
13 | // Version 1.8: Output an 8 MHz clock on pin 9
14 | // Version 1.9: Added support for Atmega1284P, and fixed some bugs
15 | // Version 1.10: Corrected flash size for Atmega1284P.
16 | // Version 1.11: Added support for Atmega1280. Removed MD5SUM stuff to make room.
17 | // Version 1.12: Added signatures for ATtiny2313A, ATtiny4313, ATtiny13
18 | // Version 1.13: Added signature for Atmega8A
19 | // Version 1.14: Added bootloader for Atmega8
20 | // Version 1.15: Removed extraneous 0xFF from some files
21 | // Version 1.16: Added signature for Atmega328
22 | // Version 1.17: Allowed for running on the Leonardo, Micro, etc.
23 |
24 | /*
25 |
26 | Copyright 2012 Nick Gammon.
27 |
28 |
29 | PERMISSION TO DISTRIBUTE
30 |
31 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software
32 | and associated documentation files (the "Software"), to deal in the Software without restriction,
33 | including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
34 | and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so,
35 | subject to the following conditions:
36 |
37 | The above copyright notice and this permission notice shall be included in
38 | all copies or substantial portions of the Software.
39 |
40 |
41 | LIMITATION OF LIABILITY
42 |
43 | The software is provided "as is", without warranty of any kind, express or implied,
44 | including but not limited to the warranties of merchantability, fitness for a particular
45 | purpose and noninfringement. In no event shall the authors or copyright holders be liable
46 | for any claim, damages or other liability, whether in an action of contract,
47 | tort or otherwise, arising from, out of or in connection with the software
48 | or the use or other dealings in the software.
49 |
50 | */
51 |
52 | #include
53 | #include
54 |
55 | const unsigned long BAUD_RATE = 115200;
56 |
57 | const byte CLOCKOUT = 9;
58 | const byte RESET = 10; // --> goes to reset on the target board
59 |
60 | #if ARDUINO < 100
61 | const byte SCK = 13; // SPI clock
62 | #endif
63 |
64 | // number of items in an array
65 | #define NUMITEMS(arg) ((unsigned int) (sizeof (arg) / sizeof (arg [0])))
66 |
67 | // programming commands to send via SPI to the chip
68 | enum {
69 | progamEnable = 0xAC,
70 |
71 | // writes are preceded by progamEnable
72 | chipErase = 0x80,
73 | writeLockByte = 0xE0,
74 | writeLowFuseByte = 0xA0,
75 | writeHighFuseByte = 0xA8,
76 | writeExtendedFuseByte = 0xA4,
77 |
78 | pollReady = 0xF0,
79 |
80 | programAcknowledge = 0x53,
81 |
82 | readSignatureByte = 0x30,
83 | readCalibrationByte = 0x38,
84 |
85 | readLowFuseByte = 0x50, readLowFuseByteArg2 = 0x00,
86 | readExtendedFuseByte = 0x50, readExtendedFuseByteArg2 = 0x08,
87 | readHighFuseByte = 0x58, readHighFuseByteArg2 = 0x08,
88 | readLockByte = 0x58, readLockByteArg2 = 0x00,
89 |
90 | readProgramMemory = 0x20,
91 | writeProgramMemory = 0x4C,
92 | loadExtendedAddressByte = 0x4D,
93 | loadProgramMemory = 0x40,
94 |
95 | }; // end of enum
96 |
97 | // structure to hold signature and other relevant data about each chip
98 | typedef struct {
99 | byte sig [3];
100 | char* desc;
101 | unsigned long flashSize;
102 | unsigned int baseBootSize;
103 | const byte* bootloader;
104 | unsigned long loaderStart; // bytes
105 | unsigned int loaderLength; // bytes
106 | unsigned long pageSize; // bytes
107 | byte lowFuse, highFuse, extFuse, lockByte;
108 | } signatureType;
109 |
110 | const unsigned long kb = 1024;
111 |
112 | // hex bootloader data
113 | #include "bootloader_atmega168.h"
114 |
115 | // see Atmega328 datasheet page 298
116 | signatureType signatures [] = {
117 | // signature description flash size bootloader size
118 |
119 | // Attiny84 family
120 | { { 0x1E, 0x91, 0x0B }, "ATtiny24", 2 * kb, 0 },
121 | { { 0x1E, 0x92, 0x07 }, "ATtiny44", 4 * kb, 0 },
122 | { { 0x1E, 0x93, 0x0C }, "ATtiny84", 8 * kb, 0 },
123 |
124 | // Attiny85 family
125 | { { 0x1E, 0x91, 0x08 }, "ATtiny25", 2 * kb, 0 },
126 | { { 0x1E, 0x92, 0x06 }, "ATtiny45", 4 * kb, 0 },
127 | { { 0x1E, 0x93, 0x0B }, "ATtiny85", 8 * kb, 0 },
128 |
129 | // Atmega328 family
130 | { { 0x1E, 0x92, 0x0A }, "ATmega48PA", 4 * kb, 0 },
131 | { { 0x1E, 0x93, 0x0F }, "ATmega88PA", 8 * kb, 256 },
132 | { { 0x1E, 0x94, 0x0B }, "ATmega168PA", 16 * kb, 256,
133 | atmega168_optiboot, // loader image
134 | //0x3E00, // start address
135 | 0x0,
136 | sizeof atmega168_optiboot,
137 | 128, // page size (for committing)
138 | 0xC6, // fuse low byte: external full-swing crystal
139 | 0xde, // fuse high byte: SPI enable, brown-out detection at 2.7V
140 | 0xf8, // fuse extended byte: boot into bootloader, 512 byte bootloader
141 | 0xcf
142 | }, // lock bits: SPM is not allowed to write to the Boot Loader section.
143 | }; // end of signatures
144 |
145 | // if signature found in above table, this is its index
146 | int foundSig = -1;
147 | byte lastAddressMSB = 0;
148 |
149 | // execute one programming instruction ... b1 is command, b2, b3, b4 are arguments
150 | // processor may return a result on the 4th transfer, this is returned.
151 | byte program(const byte b1, const byte b2 = 0, const byte b3 = 0, const byte b4 = 0) {
152 | SPI.transfer(b1);
153 | SPI.transfer(b2);
154 | SPI.transfer(b3);
155 | return SPI.transfer(b4);
156 | } // end of program
157 |
158 | // read a byte from flash memory
159 | byte readFlash(unsigned long addr) {
160 | byte high = (addr & 1) ? 0x08 : 0; // set if high byte wanted
161 | addr >>= 1; // turn into word address
162 |
163 | // set the extended (most significant) address byte if necessary
164 | byte MSB = (addr >> 16) & 0xFF;
165 | if (MSB != lastAddressMSB) {
166 | program(loadExtendedAddressByte, 0, MSB);
167 | lastAddressMSB = MSB;
168 | } // end if different MSB
169 |
170 | return program(readProgramMemory | high, highByte(addr), lowByte(addr));
171 | } // end of readFlash
172 |
173 | // write a byte to the flash memory buffer (ready for committing)
174 | byte writeFlash(unsigned long addr, const byte data) {
175 | byte high = (addr & 1) ? 0x08 : 0; // set if high byte wanted
176 | addr >>= 1; // turn into word address
177 | program(loadProgramMemory | high, 0, lowByte(addr), data);
178 | } // end of writeFlash
179 |
180 | // show a byte in hex with leading zero and optional newline
181 | void showHex(const byte b, const boolean newline = false, const boolean show0x = true) {
182 | if (show0x) {
183 | Serial.print(F("0x"));
184 | }
185 | // try to avoid using sprintf
186 | char buf [4] = { ((b >> 4) & 0x0F) | '0', (b & 0x0F) | '0', ' ', 0 };
187 | if (buf [0] > '9') {
188 | buf [0] += 7;
189 | }
190 | if (buf [1] > '9') {
191 | buf [1] += 7;
192 | }
193 | Serial.print(buf);
194 | if (newline) {
195 | Serial.println();
196 | }
197 | } // end of showHex
198 |
199 | // convert a boolean to Yes/No
200 | void showYesNo(const boolean b, const boolean newline = false) {
201 | if (b) {
202 | Serial.print(F("Yes"));
203 | } else {
204 | Serial.print(F("No"));
205 | }
206 | if (newline) {
207 | Serial.println();
208 | }
209 | } // end of showYesNo
210 |
211 | // poll the target device until it is ready to be programmed
212 | void pollUntilReady() {
213 | while ((program(pollReady) & 1) == 1)
214 | {} // wait till ready
215 | } // end of pollUntilReady
216 |
217 | // commit page
218 | void commitPage(unsigned long addr) {
219 | //Serial.print (F("Committing page starting at 0x"));
220 | //Serial.println (addr, HEX);
221 |
222 | addr >>= 1; // turn into word address
223 |
224 | // set the extended (most significant) address byte if necessary
225 | byte MSB = (addr >> 16) & 0xFF;
226 | if (MSB != lastAddressMSB) {
227 | program(loadExtendedAddressByte, 0, MSB);
228 | lastAddressMSB = MSB;
229 | } // end if different MSB
230 |
231 | program(writeProgramMemory, highByte(addr), lowByte(addr));
232 | pollUntilReady();
233 | } // end of commitPage
234 |
235 | // write specified value to specified fuse/lock byte
236 | void writeFuse(const byte newValue, const byte instruction) {
237 | if (newValue == 0) {
238 | return; // ignore
239 | }
240 |
241 | program(progamEnable, instruction, 0, newValue);
242 | pollUntilReady();
243 | } // end of writeFuse
244 |
245 | void getFuseBytes() {
246 | Serial.print(F("LFuse = "));
247 | showHex(program(readLowFuseByte, readLowFuseByteArg2), true);
248 | Serial.print(F("HFuse = "));
249 | showHex(program(readHighFuseByte, readHighFuseByteArg2), true);
250 | Serial.print(F("EFuse = "));
251 | showHex(program(readExtendedFuseByte, readExtendedFuseByteArg2), true);
252 | Serial.print(F("Lock byte = "));
253 | showHex(program(readLockByte, readLockByteArg2), true);
254 | Serial.print("Clock calibration = ");
255 | showHex(program(readCalibrationByte), true);
256 | } // end of getFuseBytes
257 |
258 | // burn the bootloader to the target device
259 | void writeBootloader() {
260 |
261 | if (signatures [foundSig].bootloader == 0) {
262 | Serial.println(F("No bootloader support for this device."));
263 | return;
264 | } // end if
265 |
266 | int i;
267 |
268 | byte lFuse = program(readLowFuseByte, readLowFuseByteArg2);
269 |
270 | byte newlFuse = signatures [foundSig].lowFuse;
271 | byte newhFuse = signatures [foundSig].highFuse;
272 | byte newextFuse = signatures [foundSig].extFuse;
273 | byte newlockByte = signatures [foundSig].lockByte;
274 |
275 | unsigned long addr = signatures [foundSig].loaderStart;
276 | unsigned int len = signatures [foundSig].loaderLength;
277 | unsigned long pagesize = signatures [foundSig].pageSize;
278 | unsigned long pagemask = ~(pagesize - 1);
279 | const byte* bootloader = signatures [foundSig].bootloader;
280 |
281 |
282 | Serial.print(F("Bootloader address = 0x"));
283 | Serial.println(addr, HEX);
284 | Serial.print(F("Bootloader length = "));
285 | Serial.print(len);
286 | Serial.println(F(" bytes."));
287 |
288 | byte subcommand = 'U';
289 |
290 | // Atmega328P or Atmega328
291 | if (signatures [foundSig].sig [0] == 0x1E &&
292 | signatures [foundSig].sig [1] == 0x95 &&
293 | (signatures [foundSig].sig [2] == 0x0F || signatures [foundSig].sig [2] == 0x14)
294 | ) {
295 | Serial.println(F("Type 'L' to use Lilypad (8 MHz) loader, or 'U' for Uno (16 MHz) loader ..."));
296 | do {
297 | subcommand = toupper(Serial.read());
298 | } while (subcommand != 'L' && subcommand != 'U');
299 |
300 | if (subcommand == 'L') { // use internal 8 MHz clock
301 | Serial.println(F("Using Lilypad 8 MHz loader."));
302 | bootloader = atmega168_optiboot;
303 | newlFuse = 0xE2; // internal 8 MHz oscillator
304 | newhFuse = 0xDA; // 2048 byte bootloader, SPI enabled
305 | addr = 0x7800;
306 | len = sizeof atmega168_optiboot;
307 | } // end of using the 8 MHz clock
308 | else {
309 | Serial.println(F("Using Uno Optiboot 16 MHz loader."));
310 | }
311 | } // end of being Atmega328P
312 |
313 | unsigned long oldPage = addr & pagemask;
314 |
315 | Serial.println(F("Type 'V' to verify, or 'G' to program the chip with the bootloader ..."));
316 | char command;
317 | do {
318 | command = toupper(Serial.read());
319 | } while (command != 'G' && command != 'V');
320 |
321 | if (command == 'G') {
322 | Serial.println(F("Erasing chip ..."));
323 | program(progamEnable, chipErase); // erase it
324 | pollUntilReady();
325 | Serial.println(F("Writing bootloader ..."));
326 | for (i = 0; i < len; i += 2) {
327 | unsigned long thisPage = (addr + i) & pagemask;
328 | // page changed? commit old one
329 | if (thisPage != oldPage) {
330 | commitPage(oldPage);
331 | oldPage = thisPage;
332 | }
333 |
334 | unsigned char c1 = pgm_read_byte(bootloader + i);
335 | unsigned char c2 = pgm_read_byte(bootloader + i + 1);
336 |
337 | writeFlash(addr + i, c1);
338 | writeFlash(addr + i + 1, c2);
339 | } // end while doing each word
340 |
341 | Serial.println();
342 |
343 | // commit final page
344 | commitPage(oldPage);
345 | Serial.println("Written.");
346 | } // end if programming
347 |
348 | Serial.println(F("Verifying ..."));
349 |
350 | // count errors
351 | unsigned int errors = 0;
352 | // check each byte
353 | for (i = 0; i < signatures [foundSig].loaderLength; i++) {
354 | //if(i==0)Serial.print(" ");
355 | byte found = readFlash(addr + i);
356 |
357 | byte expected = pgm_read_byte(bootloader + i);
358 | if (found != expected) {
359 | if (errors <= 100) {
360 | Serial.print(F("Verification error at address "));
361 | Serial.print(addr + i, HEX);
362 | Serial.print(F(". Got: "));
363 | showHex(found);
364 | Serial.print(F(" Expected: "));
365 | showHex(expected, true);
366 | } // end of haven't shown 100 errors yet
367 | errors++;
368 | } // end if error
369 | } // end of for
370 |
371 | Serial.println("\r\n");
372 | if (errors == 0) {
373 | Serial.println(F("No errors found."));
374 | } else {
375 | Serial.print(errors, DEC);
376 | Serial.println(F(" verification error(s)."));
377 | if (errors > 100) {
378 | Serial.println(F("First 100 shown."));
379 | }
380 | return; // don't change fuses if errors
381 | } // end if
382 |
383 | if (command == 'G') {
384 | Serial.println(F("Writing fuses ..."));
385 |
386 | writeFuse(newlFuse, writeLowFuseByte);
387 | writeFuse(newhFuse, writeHighFuseByte);
388 | writeFuse(newextFuse, writeExtendedFuseByte);
389 | writeFuse(newlockByte, writeLockByte);
390 |
391 | // confirm them
392 | getFuseBytes();
393 | } // end if programming
394 |
395 | Serial.println(F("Done."));
396 |
397 | } // end of writeBootloader
398 |
399 |
400 | void startProgramming() {
401 | byte confirm;
402 | pinMode(RESET, OUTPUT);
403 | pinMode(SCK, OUTPUT);
404 |
405 | // we are in sync if we get back programAcknowledge on the third byte
406 | do {
407 | delay(100);
408 | // ensure SCK low
409 | digitalWrite(SCK, LOW);
410 | // then pulse reset, see page 309 of datasheet
411 | digitalWrite(RESET, HIGH);
412 | delay(1); // pulse for at least 2 clock cycles
413 | digitalWrite(RESET, LOW);
414 | delay(25); // wait at least 20 mS
415 | SPI.transfer(progamEnable);
416 | SPI.transfer(programAcknowledge);
417 | confirm = SPI.transfer(0);
418 | SPI.transfer(0);
419 | } while (confirm != programAcknowledge);
420 |
421 | Serial.println(F("Entered programming mode OK."));
422 | } // end of startProgramming
423 |
424 | void getSignature() {
425 | foundSig = -1;
426 | lastAddressMSB = 0;
427 |
428 | byte sig [3];
429 | Serial.print(F("Signature = "));
430 | for (byte i = 0; i < 3; i++) {
431 | sig [i] = program(readSignatureByte, 0, i);
432 | showHex(sig [i]);
433 | } // end for each signature byte
434 | Serial.println();
435 |
436 | for (int j = 0; j < NUMITEMS(signatures); j++) {
437 | if (memcmp(sig, signatures [j].sig, sizeof sig) == 0) {
438 | foundSig = j;
439 | Serial.print(F("Processor = "));
440 | Serial.println(signatures [j].desc);
441 | Serial.print(F("Flash memory size = "));
442 | Serial.print(signatures [j].flashSize, DEC);
443 | Serial.println(F(" bytes."));
444 | return;
445 | } // end of signature found
446 | } // end of for each signature
447 |
448 | Serial.println(F("Unrecogized signature."));
449 | } // end of getSignature
450 |
451 | void setup() {
452 | Serial.begin(BAUD_RATE);
453 | while (!Serial) ; // for Leonardo, Micro etc.
454 | Serial.println();
455 | Serial.println(F("Atmega chip programmer."));
456 | Serial.println(F("Written by Nick Gammon."));
457 |
458 | digitalWrite(RESET, HIGH); // ensure SS stays high for now
459 | SPI.begin();
460 |
461 | // slow down SPI for benefit of slower processors like the Attiny
462 | SPI.setClockDivider(SPI_CLOCK_DIV64);
463 |
464 | pinMode(CLOCKOUT, OUTPUT);
465 |
466 | // set up Timer 1
467 | TCCR1A = _BV(COM1A0); // toggle OC1A on Compare Match
468 | TCCR1B = _BV(WGM12) | _BV(CS10); // CTC, no prescaling
469 | OCR1A = 0; // output every cycle
470 |
471 | } // end of setup
472 |
473 | void loop() {
474 | startProgramming();
475 | getSignature();
476 | getFuseBytes();
477 |
478 | // if we found a signature try to write a bootloader
479 | if (foundSig != -1) {
480 | writeBootloader();
481 | }
482 |
483 | // release reset
484 | digitalWrite(RESET, HIGH);
485 |
486 | Serial.println(F("Type 'C' when ready to continue with another chip ..."));
487 | while (toupper(Serial.read()) != 'C')
488 | {}
489 |
490 | } // end of loop
--------------------------------------------------------------------------------
/examples/UpdateFrimware/gpl.txt:
--------------------------------------------------------------------------------
1 | GNU GENERAL PUBLIC LICENSE
2 | Version 2, June 1991
3 |
4 | Copyright (C) 1989, 1991 Free Software Foundation, Inc.,
5 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
6 | Everyone is permitted to copy and distribute verbatim copies
7 | of this license document, but changing it is not allowed.
8 |
9 | Preamble
10 |
11 | The licenses for most software are designed to take away your
12 | freedom to share and change it. By contrast, the GNU General Public
13 | License is intended to guarantee your freedom to share and change free
14 | software--to make sure the software is free for all its users. This
15 | General Public License applies to most of the Free Software
16 | Foundation's software and to any other program whose authors commit to
17 | using it. (Some other Free Software Foundation software is covered by
18 | the GNU Lesser General Public License instead.) You can apply it to
19 | your programs, too.
20 |
21 | When we speak of free software, we are referring to freedom, not
22 | price. Our General Public Licenses are designed to make sure that you
23 | have the freedom to distribute copies of free software (and charge for
24 | this service if you wish), that you receive source code or can get it
25 | if you want it, that you can change the software or use pieces of it
26 | in new free programs; and that you know you can do these things.
27 |
28 | To protect your rights, we need to make restrictions that forbid
29 | anyone to deny you these rights or to ask you to surrender the rights.
30 | These restrictions translate to certain responsibilities for you if you
31 | distribute copies of the software, or if you modify it.
32 |
33 | For example, if you distribute copies of such a program, whether
34 | gratis or for a fee, you must give the recipients all the rights that
35 | you have. You must make sure that they, too, receive or can get the
36 | source code. And you must show them these terms so they know their
37 | rights.
38 |
39 | We protect your rights with two steps: (1) copyright the software, and
40 | (2) offer you this license which gives you legal permission to copy,
41 | distribute and/or modify the software.
42 |
43 | Also, for each author's protection and ours, we want to make certain
44 | that everyone understands that there is no warranty for this free
45 | software. If the software is modified by someone else and passed on, we
46 | want its recipients to know that what they have is not the original, so
47 | that any problems introduced by others will not reflect on the original
48 | authors' reputations.
49 |
50 | Finally, any free program is threatened constantly by software
51 | patents. We wish to avoid the danger that redistributors of a free
52 | program will individually obtain patent licenses, in effect making the
53 | program proprietary. To prevent this, we have made it clear that any
54 | patent must be licensed for everyone's free use or not licensed at all.
55 |
56 | The precise terms and conditions for copying, distribution and
57 | modification follow.
58 |
59 | GNU GENERAL PUBLIC LICENSE
60 | TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
61 |
62 | 0. This License applies to any program or other work which contains
63 | a notice placed by the copyright holder saying it may be distributed
64 | under the terms of this General Public License. The "Program", below,
65 | refers to any such program or work, and a "work based on the Program"
66 | means either the Program or any derivative work under copyright law:
67 | that is to say, a work containing the Program or a portion of it,
68 | either verbatim or with modifications and/or translated into another
69 | language. (Hereinafter, translation is included without limitation in
70 | the term "modification".) Each licensee is addressed as "you".
71 |
72 | Activities other than copying, distribution and modification are not
73 | covered by this License; they are outside its scope. The act of
74 | running the Program is not restricted, and the output from the Program
75 | is covered only if its contents constitute a work based on the
76 | Program (independent of having been made by running the Program).
77 | Whether that is true depends on what the Program does.
78 |
79 | 1. You may copy and distribute verbatim copies of the Program's
80 | source code as you receive it, in any medium, provided that you
81 | conspicuously and appropriately publish on each copy an appropriate
82 | copyright notice and disclaimer of warranty; keep intact all the
83 | notices that refer to this License and to the absence of any warranty;
84 | and give any other recipients of the Program a copy of this License
85 | along with the Program.
86 |
87 | You may charge a fee for the physical act of transferring a copy, and
88 | you may at your option offer warranty protection in exchange for a fee.
89 |
90 | 2. You may modify your copy or copies of the Program or any portion
91 | of it, thus forming a work based on the Program, and copy and
92 | distribute such modifications or work under the terms of Section 1
93 | above, provided that you also meet all of these conditions:
94 |
95 | a) You must cause the modified files to carry prominent notices
96 | stating that you changed the files and the date of any change.
97 |
98 | b) You must cause any work that you distribute or publish, that in
99 | whole or in part contains or is derived from the Program or any
100 | part thereof, to be licensed as a whole at no charge to all third
101 | parties under the terms of this License.
102 |
103 | c) If the modified program normally reads commands interactively
104 | when run, you must cause it, when started running for such
105 | interactive use in the most ordinary way, to print or display an
106 | announcement including an appropriate copyright notice and a
107 | notice that there is no warranty (or else, saying that you provide
108 | a warranty) and that users may redistribute the program under
109 | these conditions, and telling the user how to view a copy of this
110 | License. (Exception: if the Program itself is interactive but
111 | does not normally print such an announcement, your work based on
112 | the Program is not required to print an announcement.)
113 |
114 | These requirements apply to the modified work as a whole. If
115 | identifiable sections of that work are not derived from the Program,
116 | and can be reasonably considered independent and separate works in
117 | themselves, then this License, and its terms, do not apply to those
118 | sections when you distribute them as separate works. But when you
119 | distribute the same sections as part of a whole which is a work based
120 | on the Program, the distribution of the whole must be on the terms of
121 | this License, whose permissions for other licensees extend to the
122 | entire whole, and thus to each and every part regardless of who wrote it.
123 |
124 | Thus, it is not the intent of this section to claim rights or contest
125 | your rights to work written entirely by you; rather, the intent is to
126 | exercise the right to control the distribution of derivative or
127 | collective works based on the Program.
128 |
129 | In addition, mere aggregation of another work not based on the Program
130 | with the Program (or with a work based on the Program) on a volume of
131 | a storage or distribution medium does not bring the other work under
132 | the scope of this License.
133 |
134 | 3. You may copy and distribute the Program (or a work based on it,
135 | under Section 2) in object code or executable form under the terms of
136 | Sections 1 and 2 above provided that you also do one of the following:
137 |
138 | a) Accompany it with the complete corresponding machine-readable
139 | source code, which must be distributed under the terms of Sections
140 | 1 and 2 above on a medium customarily used for software interchange; or,
141 |
142 | b) Accompany it with a written offer, valid for at least three
143 | years, to give any third party, for a charge no more than your
144 | cost of physically performing source distribution, a complete
145 | machine-readable copy of the corresponding source code, to be
146 | distributed under the terms of Sections 1 and 2 above on a medium
147 | customarily used for software interchange; or,
148 |
149 | c) Accompany it with the information you received as to the offer
150 | to distribute corresponding source code. (This alternative is
151 | allowed only for noncommercial distribution and only if you
152 | received the program in object code or executable form with such
153 | an offer, in accord with Subsection b above.)
154 |
155 | The source code for a work means the preferred form of the work for
156 | making modifications to it. For an executable work, complete source
157 | code means all the source code for all modules it contains, plus any
158 | associated interface definition files, plus the scripts used to
159 | control compilation and installation of the executable. However, as a
160 | special exception, the source code distributed need not include
161 | anything that is normally distributed (in either source or binary
162 | form) with the major components (compiler, kernel, and so on) of the
163 | operating system on which the executable runs, unless that component
164 | itself accompanies the executable.
165 |
166 | If distribution of executable or object code is made by offering
167 | access to copy from a designated place, then offering equivalent
168 | access to copy the source code from the same place counts as
169 | distribution of the source code, even though third parties are not
170 | compelled to copy the source along with the object code.
171 |
172 | 4. You may not copy, modify, sublicense, or distribute the Program
173 | except as expressly provided under this License. Any attempt
174 | otherwise to copy, modify, sublicense or distribute the Program is
175 | void, and will automatically terminate your rights under this License.
176 | However, parties who have received copies, or rights, from you under
177 | this License will not have their licenses terminated so long as such
178 | parties remain in full compliance.
179 |
180 | 5. You are not required to accept this License, since you have not
181 | signed it. However, nothing else grants you permission to modify or
182 | distribute the Program or its derivative works. These actions are
183 | prohibited by law if you do not accept this License. Therefore, by
184 | modifying or distributing the Program (or any work based on the
185 | Program), you indicate your acceptance of this License to do so, and
186 | all its terms and conditions for copying, distributing or modifying
187 | the Program or works based on it.
188 |
189 | 6. Each time you redistribute the Program (or any work based on the
190 | Program), the recipient automatically receives a license from the
191 | original licensor to copy, distribute or modify the Program subject to
192 | these terms and conditions. You may not impose any further
193 | restrictions on the recipients' exercise of the rights granted herein.
194 | You are not responsible for enforcing compliance by third parties to
195 | this License.
196 |
197 | 7. If, as a consequence of a court judgment or allegation of patent
198 | infringement or for any other reason (not limited to patent issues),
199 | conditions are imposed on you (whether by court order, agreement or
200 | otherwise) that contradict the conditions of this License, they do not
201 | excuse you from the conditions of this License. If you cannot
202 | distribute so as to satisfy simultaneously your obligations under this
203 | License and any other pertinent obligations, then as a consequence you
204 | may not distribute the Program at all. For example, if a patent
205 | license would not permit royalty-free redistribution of the Program by
206 | all those who receive copies directly or indirectly through you, then
207 | the only way you could satisfy both it and this License would be to
208 | refrain entirely from distribution of the Program.
209 |
210 | If any portion of this section is held invalid or unenforceable under
211 | any particular circumstance, the balance of the section is intended to
212 | apply and the section as a whole is intended to apply in other
213 | circumstances.
214 |
215 | It is not the purpose of this section to induce you to infringe any
216 | patents or other property right claims or to contest validity of any
217 | such claims; this section has the sole purpose of protecting the
218 | integrity of the free software distribution system, which is
219 | implemented by public license practices. Many people have made
220 | generous contributions to the wide range of software distributed
221 | through that system in reliance on consistent application of that
222 | system; it is up to the author/donor to decide if he or she is willing
223 | to distribute software through any other system and a licensee cannot
224 | impose that choice.
225 |
226 | This section is intended to make thoroughly clear what is believed to
227 | be a consequence of the rest of this License.
228 |
229 | 8. If the distribution and/or use of the Program is restricted in
230 | certain countries either by patents or by copyrighted interfaces, the
231 | original copyright holder who places the Program under this License
232 | may add an explicit geographical distribution limitation excluding
233 | those countries, so that distribution is permitted only in or among
234 | countries not thus excluded. In such case, this License incorporates
235 | the limitation as if written in the body of this License.
236 |
237 | 9. The Free Software Foundation may publish revised and/or new versions
238 | of the General Public License from time to time. Such new versions will
239 | be similar in spirit to the present version, but may differ in detail to
240 | address new problems or concerns.
241 |
242 | Each version is given a distinguishing version number. If the Program
243 | specifies a version number of this License which applies to it and "any
244 | later version", you have the option of following the terms and conditions
245 | either of that version or of any later version published by the Free
246 | Software Foundation. If the Program does not specify a version number of
247 | this License, you may choose any version ever published by the Free Software
248 | Foundation.
249 |
250 | 10. If you wish to incorporate parts of the Program into other free
251 | programs whose distribution conditions are different, write to the author
252 | to ask for permission. For software which is copyrighted by the Free
253 | Software Foundation, write to the Free Software Foundation; we sometimes
254 | make exceptions for this. Our decision will be guided by the two goals
255 | of preserving the free status of all derivatives of our free software and
256 | of promoting the sharing and reuse of software generally.
257 |
258 | NO WARRANTY
259 |
260 | 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
261 | FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
262 | OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
263 | PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
264 | OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
265 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
266 | TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
267 | PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
268 | REPAIR OR CORRECTION.
269 |
270 | 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
271 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
272 | REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
273 | INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
274 | OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
275 | TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
276 | YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
277 | PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
278 | POSSIBILITY OF SUCH DAMAGES.
279 |
280 | END OF TERMS AND CONDITIONS
281 |
282 | How to Apply These Terms to Your New Programs
283 |
284 | If you develop a new program, and you want it to be of the greatest
285 | possible use to the public, the best way to achieve this is to make it
286 | free software which everyone can redistribute and change under these terms.
287 |
288 | To do so, attach the following notices to the program. It is safest
289 | to attach them to the start of each source file to most effectively
290 | convey the exclusion of warranty; and each file should have at least
291 | the "copyright" line and a pointer to where the full notice is found.
292 |
293 |
294 | Copyright (C)
295 |
296 | This program is free software; you can redistribute it and/or modify
297 | it under the terms of the GNU General Public License as published by
298 | the Free Software Foundation; either version 2 of the License, or
299 | (at your option) any later version.
300 |
301 | This program is distributed in the hope that it will be useful,
302 | but WITHOUT ANY WARRANTY; without even the implied warranty of
303 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
304 | GNU General Public License for more details.
305 |
306 | You should have received a copy of the GNU General Public License along
307 | with this program; if not, write to the Free Software Foundation, Inc.,
308 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
309 |
310 | Also add information on how to contact you by electronic and paper mail.
311 |
312 | If the program is interactive, make it output a short notice like this
313 | when it starts in an interactive mode:
314 |
315 | Gnomovision version 69, Copyright (C) year name of author
316 | Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
317 | This is free software, and you are welcome to redistribute it
318 | under certain conditions; type `show c' for details.
319 |
320 | The hypothetical commands `show w' and `show c' should show the appropriate
321 | parts of the General Public License. Of course, the commands you use may
322 | be called something other than `show w' and `show c'; they could even be
323 | mouse-clicks or menu items--whatever suits your program.
324 |
325 | You should also get your employer (if you work as a programmer) or your
326 | school, if any, to sign a "copyright disclaimer" for the program, if
327 | necessary. Here is a sample; alter the names:
328 |
329 | Yoyodyne, Inc., hereby disclaims all copyright interest in the program
330 | `Gnomovision' (which makes passes at compilers) written by James Hacker.
331 |
332 | , 1 April 1989
333 | Ty Coon, President of Vice
334 |
335 | This General Public License does not permit incorporating your program into
336 | proprietary programs. If your program is a subroutine library, you may
337 | consider it more useful to permit linking proprietary applications with the
338 | library. If this is what you want to do, use the GNU Lesser General
339 | Public License instead of this License.
340 |
--------------------------------------------------------------------------------
/examples/calibration/calibration.ino:
--------------------------------------------------------------------------------
1 | // Calibration code for Grove - Multichannel Gas Sensor
2 | // Note that it need 10 minutes pre-heat before calibration
3 | // This code is writen by Loovee@2016-5-18
4 |
5 | #include
6 | #include "MutichannelGasSensor.h"
7 |
8 | #define SENSOR_ADDR 0X04 // default to 0x04
9 | #define PRE_HEAT_TIME 0 // pre-heat time, 10-30 minutes is recommended
10 |
11 | void setup() {
12 | Serial.begin(115200);
13 | gas.begin(SENSOR_ADDR); //
14 | Serial.println("power on, and pre-heat");
15 |
16 | for (int i = 60 * PRE_HEAT_TIME; i >= 0; i--) {
17 | Serial.print(i / 60);
18 | Serial.print(":");
19 | Serial.println(i % 60);
20 | delay(1000);
21 | }
22 |
23 | Serial.println("Begin to calibrate...");
24 | gas.doCalibrate();
25 | Serial.println("Calibration ok");
26 |
27 | gas.display_eeprom();
28 | }
29 |
30 | void loop() {
31 |
32 | }
33 |
--------------------------------------------------------------------------------
/examples/factory_setting/factory_setting.ino:
--------------------------------------------------------------------------------
1 | // factory setting
2 | // Loovee
3 | // 2016-11-10
4 |
5 | #include
6 | #include "MutichannelGasSensor.h"
7 |
8 | #define SENSOR_ADDR 0X04 // default to 0x04
9 |
10 | void setup() {
11 | Serial.begin(115200);
12 | Serial.println("Please input something to continue");
13 | while (!Serial.available());
14 |
15 | gas.begin(SENSOR_ADDR); //
16 |
17 | Serial.println("FACTORY SETTING OK");
18 |
19 | float R0_NH3, R0_CO, R0_NO2;
20 |
21 | R0_NH3 = gas.getR0(0);
22 | R0_CO = gas.getR0(1);
23 | R0_NO2 = gas.getR0(2);
24 |
25 | Serial.print("R0_NH3 = ");
26 | Serial.println(R0_NH3);
27 | Serial.print("R0_CO = ");
28 | Serial.println(R0_CO);
29 | Serial.print("R0_NO2 = ");
30 | Serial.println(R0_NO2);
31 | }
32 |
33 | void loop() {
34 | }
35 |
--------------------------------------------------------------------------------
/examples/new_firmware/new_firmware.ino:
--------------------------------------------------------------------------------
1 | /* firmware of multichannel gas sensor v2.0*3
2 | write by loovee
3 | 2016-11-6
4 |
5 | Factory adc value of 3 channels:
6 | NH3 = 860
7 | CO = 950
8 | NO2 = 155
9 |
10 | Default address is 0x04
11 | */
12 |
13 | #include
14 | #include
15 |
16 | #define DEFAULT_I2C_ADDR 0x04
17 | #define DBG 1
18 | // EEPROM ADDRESS
19 | #define ADDR_IS_SET 0 // if this is the first time to run, if 1126, set
20 | #define ADDR_FACTORY_ADC_NH3 2
21 | #define ADDR_FACTORY_ADC_CO 4
22 | #define ADDR_FACTORY_ADC_NO2 6
23 |
24 | #define ADDR_USER_ADC_HN3 8
25 | #define ADDR_USER_ADC_CO 10
26 | #define ADDR_USER_ADC_NO2 12
27 | #define ADDR_IF_CALI 14 // IF USER HAD CALI
28 | #define ADDR_I2C_ADDRESS 20
29 | // I2C COMMAND
30 |
31 | #define CMD_ADC_RES0 1 // NH3
32 | #define CMD_ADC_RES1 2 // CO
33 | #define CMD_ADC_RES2 3 // NO2
34 | #define CMD_ADC_RESALL 4 // ALL CHANNEL
35 | #define CMD_CHANGE_I2C 5 // CHANGE I2C
36 | #define CMD_READ_EEPROM 6 // READ EEPROM VALUE, RETURN UNSIGNED INT
37 | #define CMD_SET_R0_ADC 7 // SET R0 ADC VALUE
38 | #define CMD_GET_R0_ADC 8 // GET R0 ADC VALUE
39 | #define CMD_GET_R0_ADC_FACTORY 9 // GET FACTORY R0 ADC VALUE
40 | #define CMD_CONTROL_LED 10
41 | #define CMD_CONTROL_PWR 11
42 |
43 | // EEPROM READ AND WRITE - UNSIGNED INT
44 | void eeprom_write(int addr, unsigned int value) {
45 | EEPROM.write(addr, value >> 8);
46 | EEPROM.write(addr + 1, value & 0xff);
47 | }
48 |
49 | unsigned int eeprom_read(int addr) {
50 | unsigned int r = EEPROM.read(addr);
51 | r <<= 8;
52 | r += EEPROM.read(addr + 1);
53 | return r;
54 | }
55 |
56 | const int pin_pwr = 8;
57 | const int pin_led = 9;
58 |
59 | const int pin_NH3 = A0; // RES0
60 | const int pin_CO = A1; // RES1
61 | const int pin_NO2 = A2; // RES2
62 |
63 | unsigned char i2c_address = 0;
64 |
65 | #define LED_ON() digitalWrite(pin_led, LOW)
66 | #define LED_OFF() digitalWrite(pin_led, HIGH)
67 |
68 | void factory_init() {
69 | #if DBG
70 | Serial.print("FACTORY: ");
71 | #endif
72 | if (1126 != eeprom_read(ADDR_IS_SET)) { // IF FACTORY SET
73 | #if DBG
74 | Serial.println("YES");
75 | #endif
76 | eeprom_write(ADDR_IS_SET, 1126);
77 | eeprom_write(ADDR_FACTORY_ADC_NH3, 860);
78 | eeprom_write(ADDR_FACTORY_ADC_CO, 950);
79 | eeprom_write(ADDR_FACTORY_ADC_NO2, 155);
80 | eeprom_write(ADDR_USER_ADC_HN3, 860);
81 | eeprom_write(ADDR_USER_ADC_CO, 950);
82 | eeprom_write(ADDR_USER_ADC_NO2, 155);
83 | eeprom_write(ADDR_IF_CALI, 0);
84 | eeprom_write(ADDR_I2C_ADDRESS, DEFAULT_I2C_ADDR);
85 | }
86 | #if DBG
87 | else {
88 | Serial.println("NO");
89 | }
90 | #endif
91 | }
92 |
93 | int getAnalog(int pin) {
94 | long sum = 0;
95 | for (int i = 0; i < 64; i++) {
96 | sum += analogRead(pin);
97 | }
98 | return sum >> 6;
99 | }
100 |
101 | unsigned int ADC_RES0 = 0;
102 | unsigned int ADC_RES1 = 0;
103 | unsigned int ADC_RES2 = 0;
104 |
105 | unsigned char raw_adc[6];
106 |
107 | void updateValue() {
108 | static unsigned long timer_s = millis();
109 | if (millis() - timer_s < 1000) {
110 | return;
111 | }
112 | timer_s = millis();
113 |
114 | ADC_RES0 = getAnalog(pin_NH3);
115 | ADC_RES1 = getAnalog(pin_CO);
116 | ADC_RES2 = getAnalog(pin_NO2);
117 |
118 | raw_adc[0] = ADC_RES0 >> 8;
119 | raw_adc[1] = ADC_RES0;
120 | raw_adc[2] = ADC_RES1 >> 8;
121 | raw_adc[3] = ADC_RES1;
122 | raw_adc[4] = ADC_RES2 >> 8;
123 | raw_adc[5] = ADC_RES2;
124 | }
125 |
126 | void setup() {
127 | #if DBG
128 | Serial.begin(115200);
129 | #endif
130 | pinMode(pin_pwr, OUTPUT);
131 | digitalWrite(pin_pwr, HIGH);
132 | pinMode(pin_led, OUTPUT);
133 |
134 | factory_init();
135 | i2c_address = eeprom_read(ADDR_I2C_ADDRESS);
136 | #if DBG
137 | Serial.print("i2d address = 0x");
138 | Serial.println(i2c_address, HEX);
139 | #endif
140 | for (int i = 0; i < 5; i++) {
141 | digitalWrite(pin_led, LOW);
142 | delay(100);
143 | digitalWrite(pin_led, HIGH);
144 | delay(100);
145 | }
146 |
147 | Wire.begin(i2c_address); // join i2c bus with address
148 | Wire.onReceive(receiveCallback); // register receive callback
149 | Wire.onRequest(requestCallback); // register request callback
150 | }
151 |
152 | void loop() {
153 | updateValue();
154 | }
155 |
156 | unsigned char recvCmd = 0;
157 | unsigned char recvDta = 0;
158 | unsigned char recvDtaStr[10];
159 |
160 | void receiveCallback(int dtaCount) {
161 | if (dtaCount == 1) {
162 | recvCmd = Wire.read();
163 | } else if (dtaCount == 2) { // set i2c address
164 | recvCmd = Wire.read();
165 | recvDta = Wire.read();
166 |
167 | if (CMD_CHANGE_I2C == recvCmd) {
168 | i2c_address = recvDta;
169 | eeprom_write(ADDR_I2C_ADDRESS, i2c_address);
170 | Wire.begin(i2c_address);
171 | } else if (CMD_CONTROL_LED == recvCmd) {
172 | if (0 == recvDta) {
173 | LED_OFF();
174 | } else if (1 == recvDta) {
175 | LED_ON();
176 | }
177 | } else if (CMD_CONTROL_PWR == recvCmd) {
178 | if (0 == recvDta) {
179 | digitalWrite(pin_pwr, LOW);
180 | } else if (1 == recvDta) {
181 | digitalWrite(pin_pwr, HIGH);
182 | }
183 | }
184 | } else if (dtaCount == 7) { // set ADC value
185 | recvCmd = Wire.read();
186 | unsigned int dta[3];
187 |
188 | for (int i = 0; i < 3; i++) {
189 | dta[i] = Wire.read();
190 | dta[i] <<= 8;
191 | dta[i] += Wire.read();
192 | }
193 |
194 | if (recvCmd == CMD_SET_R0_ADC) {
195 | eeprom_write(ADDR_USER_ADC_HN3, dta[0]);
196 | eeprom_write(ADDR_USER_ADC_CO, dta[1]);
197 | eeprom_write(ADDR_USER_ADC_NO2, dta[2]);
198 | }
199 | }
200 | }
201 |
202 | unsigned char rcDta[10];
203 | void requestCallback() {
204 | switch (recvCmd) {
205 | case CMD_ADC_RES0: // NH3
206 | Wire.write(&raw_adc[0], 2); // HIGH FIRST
207 |
208 | break;
209 |
210 | case CMD_ADC_RES1: // CO
211 | Wire.write(&raw_adc[2], 2); // HIGH FIRST
212 | break;
213 |
214 | case CMD_ADC_RES2: // NO2
215 | Wire.write(&raw_adc[4], 2); // HIGH FIRST
216 | break;
217 |
218 | case CMD_ADC_RESALL:
219 | Wire.write(raw_adc, 6);
220 | break;
221 |
222 | case CMD_READ_EEPROM:
223 | rcDta[0] = EEPROM.read(recvDta);
224 | rcDta[1] = EEPROM.read(recvDta + 1);
225 | Wire.write(rcDta, 2);
226 | break;
227 |
228 | case CMD_GET_R0_ADC:
229 |
230 | rcDta[0] = EEPROM.read(ADDR_USER_ADC_HN3);
231 | rcDta[1] = EEPROM.read(ADDR_USER_ADC_HN3 + 1);
232 | rcDta[2] = EEPROM.read(ADDR_USER_ADC_CO);
233 | rcDta[3] = EEPROM.read(ADDR_USER_ADC_CO + 1);
234 | rcDta[4] = EEPROM.read(ADDR_USER_ADC_NO2);
235 | rcDta[5] = EEPROM.read(ADDR_USER_ADC_NO2 + 1);
236 |
237 | Wire.write(rcDta, 6);
238 |
239 | break;
240 |
241 | case CMD_GET_R0_ADC_FACTORY:
242 |
243 | rcDta[0] = EEPROM.read(ADDR_FACTORY_ADC_NH3);
244 | rcDta[1] = EEPROM.read(ADDR_FACTORY_ADC_NH3 + 1);
245 | rcDta[2] = EEPROM.read(ADDR_FACTORY_ADC_CO);
246 | rcDta[3] = EEPROM.read(ADDR_FACTORY_ADC_CO + 1);
247 | rcDta[4] = EEPROM.read(ADDR_FACTORY_ADC_NO2);
248 | rcDta[5] = EEPROM.read(ADDR_FACTORY_ADC_NO2 + 1);
249 |
250 | Wire.write(rcDta, 6);
251 | break;
252 |
253 | default:;
254 | }
255 | }
256 |
257 | // END FILE
258 |
--------------------------------------------------------------------------------
/keywords.txt:
--------------------------------------------------------------------------------
1 |
2 | #######################################
3 | # Syntax Coloring Map For
4 | #######################################
5 |
6 | #######################################
7 | # Datatypes (KEYWORD1)
8 | #######################################
9 |
10 |
11 |
12 | #######################################
13 | # Methods and Functions (KEYWORD2)
14 | #######################################
15 | get_addr_dta KEYWORD2
16 | get_addr_dta KEYWORD2
17 | write_i2c KEYWORD2
18 | sendI2C KEYWORD2
19 | readData KEYWORD2
20 | readR0 KEYWORD2
21 | readR KEYWORD2
22 | calcGas KEYWORD2
23 | begin KEYWORD2
24 | changeI2cAddr KEYWORD2
25 | powerOn KEYWORD2
26 | powerOff KEYWORD2
27 | doCalibrate KEYWORD2
28 | measure_CO KEYWORD2
29 | measure_NO2 KEYWORD2
30 | measure_NH3 KEYWORD2
31 | measure_C3H8 KEYWORD2
32 | measure_C4H10 KEYWORD2
33 | measure_CH4 KEYWORD2
34 | measure_H2 KEYWORD2
35 | measure_C2H5OH KEYWORD2
36 | getR0 KEYWORD2
37 | getRs KEYWORD2
38 | ledOn KEYWORD2
39 | ledOff KEYWORD2
40 | display_eeprom KEYWORD2
41 | factory_setting KEYWORD2
42 | change_i2c_address KEYWORD2
43 | getVersion KEYWORD2
44 |
45 | #######################################
46 | # Constants (LITERAL1)
47 | #######################################
--------------------------------------------------------------------------------
/library.properties:
--------------------------------------------------------------------------------
1 | name=Grove - Multichannel Gas Sensor
2 | version=1.0.0
3 | author=Seeed Studio
4 | maintainer=Seeed Studio
5 | sentence=Arduino library to control Grove - Multichannel Gas Sensor .
6 | paragraph=Grove – Multichannel Gas sensor is a environment detecting sensor with a built in MiCS-6814 which can detect many unhealthful gases, and three gases can be measured simultaneously due to its multi channels, so it can help you to monitor the concentration which more than one gas..
7 | category=Sensors
8 | url=https://github.com/Seeed-Studio/Mutichannel_Gas_Sensor
9 | architectures=*
--------------------------------------------------------------------------------