Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
N
neOCampus-arduino
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
GIS-neOCampus
neOSensor
neOCampus-arduino
Commits
2b005364
Commit
2b005364
authored
3 years ago
by
francois
Browse files
Options
Downloads
Patches
Plain Diff
sample PMS5003 code update
parent
7e8bfd82
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
tests/pms5003/pms5003.ino
+33
-11
33 additions, 11 deletions
tests/pms5003/pms5003.ino
with
33 additions
and
11 deletions
tests/pms5003/pms5003.ino
+
33
−
11
View file @
2b005364
...
@@ -218,10 +218,15 @@ void PMS::loop()
...
@@ -218,10 +218,15 @@ void PMS::loop()
/* Declarations */
/* Declarations */
#define PM_COOLDOWN 30 // seconds inactive betwwen two measures
#define PM_ENABLE 5 // PMS5003 has an Enable pin featuring a pullup resistor:
// input or output high ==> normal ops
// low ==> disable
/* Global variables */
/* Global variables */
PMS
pms
(
Serial2
);
PMS
pms
(
Serial2
);
PMS
::
DATA
data
;
PMS
::
DATA
data
;
unsigned
long
_lastActive
;
const
char
_pattern
[]
=
{
0x42
,
0x4d
,
'\0'
};
const
char
_pattern
[]
=
{
0x42
,
0x4d
,
'\0'
};
/*
/*
...
@@ -230,11 +235,18 @@ const char _pattern[] = { 0x42, 0x4d, '\0' };
...
@@ -230,11 +235,18 @@ const char _pattern[] = { 0x42, 0x4d, '\0' };
void
setup
()
{
void
setup
()
{
delay
(
5000
);
delay
(
5000
);
Serial
.
begin
(
115200
);
// debug link
Serial
.
begin
(
115200
);
// debug link
Serial
.
println
(
F
(
"
\n
[PMS5003] demo ..."
));
Serial
.
flush
();
Serial
.
println
(
F
(
"
\n
\n\n
[PMS5003] demo ..."
));
Serial
.
flush
();
delay
(
1000
);
delay
(
1000
);
Serial
.
println
(
F
(
"
\n
[PMS5003] setup Serial2"
));
Serial
.
flush
();
Serial
.
println
(
F
(
"
\n
[PMS5003] setup Serial2"
));
Serial
.
flush
();
Serial2
.
begin
(
9600
);
// PMS link
Serial2
.
begin
(
9600
);
// PMS link
// enable pin is input as default
pinMode
(
PM_ENABLE
,
INPUT
);
digitalWrite
(
PM_ENABLE
,
LOW
);
// useless ... till we set it as an ouput
Serial
.
println
(
F
(
"
\n
[PMS5003] activate PMS ..."
));
Serial
.
flush
();
_lastActive
=
millis
();
delay
(
500
);
/*
/*
while( true ) {
while( true ) {
while( Serial2.available() ) {
while( Serial2.available() ) {
...
@@ -254,22 +266,32 @@ void setup() {
...
@@ -254,22 +266,32 @@ void setup() {
/*
/*
* LOOP
* LOOP
*/
*/
void
loop
()
void
loop
()
{
{
if
(
pms
.
read
(
data
))
// activation ?
{
if
(
digitalRead
(
PM_ENABLE
)
==
LOW
and
(
millis
()
-
_lastActive
)
>=
PM_COOLDOWN
*
1000
)
{
Serial
.
println
(
F
(
"
\n
[PMS5003] activation ..."
));
Serial
.
flush
();
pinMode
(
PM_ENABLE
,
INPUT
);
}
// may we read ?
bool
_res
=
(
digitalRead
(
PM_ENABLE
)
==
HIGH
)
&&
pms
.
read
(
data
);
if
(
_res
)
{
Serial
.
print
(
"PM 1.0 (ug/m3): "
);
Serial
.
print
(
"PM 1.0 (ug/m3): "
);
Serial
.
println
(
data
.
PM_AE_UG_1_0
);
Serial
.
println
(
data
.
PM_AE_UG_1_0
);
Serial
.
print
(
"PM 2.5 (ug/m3): "
);
Serial
.
print
(
"PM 2.5 (ug/m3): "
);
Serial
.
println
(
data
.
PM_AE_UG_2_5
);
Serial
.
println
(
data
.
PM_AE_UG_2_5
);
Serial
.
print
(
"PM 10.0 (ug/m3): "
);
Serial
.
print
(
"PM 10.0 (ug/m3): "
);
Serial
.
println
(
data
.
PM_AE_UG_10_0
);
Serial
.
println
(
data
.
PM_AE_UG_10_0
);
Serial
.
println
();
Serial
.
println
(
F
(
"
\n
[PMS5003] disabling ..."
));
Serial
.
flush
();
pinMode
(
PM_ENABLE
,
OUTPUT
);
_lastActive
=
millis
();
}
}
// Do other stuff...
// Do other stuff...
//
delay(250);
delay
(
250
);
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment