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
7d01c6f2
Commit
7d01c6f2
authored
3 years ago
by
francois
Browse files
Options
Downloads
Patches
Plain Diff
mod IKEA PM sensor with new command
parent
8304daaf
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
neosensor/libraries/neocampus_drivers/pm_serial.cpp
+9
-2
9 additions, 2 deletions
neosensor/libraries/neocampus_drivers/pm_serial.cpp
tests/ikea_pm2.5/ikea_pm2.5.ino
+15
-9
15 additions, 9 deletions
tests/ikea_pm2.5/ikea_pm2.5.ino
with
24 additions
and
11 deletions
neosensor/libraries/neocampus_drivers/pm_serial.cpp
+
9
−
2
View file @
7d01c6f2
...
@@ -8,6 +8,8 @@
...
@@ -8,6 +8,8 @@
@section HISTORY
@section HISTORY
feb.22 F.thiebolt IKEA sensor: switched to a new read command borrowed
from on board IKEA PM sensor micro-controller
oct.21 F.thiebolt initial release
oct.21 F.thiebolt initial release
*/
*/
/**************************************************************************/
/**************************************************************************/
...
@@ -868,7 +870,8 @@ boolean pm_serial::_ll_requestRead( void ) {
...
@@ -868,7 +870,8 @@ boolean pm_serial::_ll_requestRead( void ) {
res
=
true
;
res
=
true
;
}
}
else
if
(
_sensor_type
==
pmSensorType_t
::
IKEA
)
{
else
if
(
_sensor_type
==
pmSensorType_t
::
IKEA
)
{
uint8_t
command
[]
=
{
0x11
,
0x01
,
0x02
,
0xEC
};
// uint8_t command[] = { 0x11, 0x01, 0x02, 0xEC }; // regular command
uint8_t
command
[]
=
{
0x11
,
0x02
,
0x0b
,
0x01
,
0xE1
};
// [feb.22] hidden command
_stream
->
write
(
command
,
sizeof
(
command
));
delay
(
50
);
_stream
->
write
(
command
,
sizeof
(
command
));
delay
(
50
);
res
=
true
;
res
=
true
;
}
}
...
@@ -1081,7 +1084,7 @@ boolean pm_serial::serialRead_ikea( uint16_t timeout ) {
...
@@ -1081,7 +1084,7 @@ boolean pm_serial::serialRead_ikea( uint16_t timeout ) {
uint16_t
_frameLen
=
0
;
uint16_t
_frameLen
=
0
;
uint16_t
_checksum
=
0
;
uint16_t
_checksum
=
0
;
uint16_t
_calculatedChecksum
=
0
;
uint16_t
_calculatedChecksum
=
0
;
uint8_t
_payload
[
1
2
];
uint8_t
_payload
[
1
6
];
// [feb.22] newer command send back up to 16 bytes (no idea DF13-DF16 role)
unsigned
long
startTime
=
millis
();
unsigned
long
startTime
=
millis
();
...
@@ -1108,10 +1111,13 @@ boolean pm_serial::serialRead_ikea( uint16_t timeout ) {
...
@@ -1108,10 +1111,13 @@ boolean pm_serial::serialRead_ikea( uint16_t timeout ) {
break
;
break
;
case
2
:
case
2
:
// command byte answer: it could be 0x02 or 0x0b
/*
if( ch != 0x02 ) {
if( ch != 0x02 ) {
_index = 0;
_index = 0;
continue;
continue;
}
}
*/
_calculatedChecksum
+=
ch
;
_calculatedChecksum
+=
ch
;
break
;
break
;
...
@@ -1137,6 +1143,7 @@ boolean pm_serial::serialRead_ikea( uint16_t timeout ) {
...
@@ -1137,6 +1143,7 @@ boolean pm_serial::serialRead_ikea( uint16_t timeout ) {
value
=
makeWord
(
_payload
[
10
],
_payload
[
11
]);
// PM10
value
=
makeWord
(
_payload
[
10
],
_payload
[
11
]);
// PM10
log_debug
(
F
(
"
\n
[pm_serial][IKEA] PM10 = "
));
log_debug
(
value
);
log_flush
();
log_debug
(
F
(
"
\n
[pm_serial][IKEA] PM10 = "
));
log_debug
(
value
);
log_flush
();
_measures
[(
uint8_t
)
ikeaDataIdx_t
::
PM10
].
_currentSum
+=
(
float
)
value
;
_measures
[(
uint8_t
)
ikeaDataIdx_t
::
PM10
].
_currentSum
+=
(
float
)
value
;
// [feb.22] no idea DF13-DF16 bytes from 0x0B command are useful for ??
// data acquired, finisk :)
// data acquired, finisk :)
log_debug
(
F
(
"
\n
[pm_serial][IKEA] "
));
log_debug
(
millis
()
-
startTime
);
log_debug
(
F
(
"
\n
[pm_serial][IKEA] "
));
log_debug
(
millis
()
-
startTime
);
...
...
This diff is collapsed.
Click to expand it.
tests/ikea_pm2.5/ikea_pm2.5.ino
+
15
−
9
View file @
7d01c6f2
/* Simple IKEA PM2.5 particle sensor test
/* Simple IKEA PM2.5 particle sensor test
* https://github.com/fu-hsi/PMS
* https://github.com/fu-hsi/PMS
*
* [feb.22] new command extracted from IKEA sensor 11 02 0b 01 E1
*/
*/
#include
"Arduino.h"
#include
"Arduino.h"
...
@@ -22,6 +24,7 @@ public:
...
@@ -22,6 +24,7 @@ public:
uint16_t
PM_1_0
;
uint16_t
PM_1_0
;
uint16_t
PM_2_5
;
uint16_t
PM_2_5
;
uint16_t
PM_10_0
;
uint16_t
PM_10_0
;
uint16_t
PM_UNKNOWN
;
};
};
PMS
(
Stream
&
);
PMS
(
Stream
&
);
...
@@ -38,7 +41,7 @@ private:
...
@@ -38,7 +41,7 @@ private:
enum
STATUS
{
STATUS_WAITING
,
STATUS_OK
};
enum
STATUS
{
STATUS_WAITING
,
STATUS_OK
};
enum
MODE
{
MODE_ACTIVE
,
MODE_PASSIVE
};
enum
MODE
{
MODE_ACTIVE
,
MODE_PASSIVE
};
uint8_t
_payload
[
1
2
];
uint8_t
_payload
[
1
6
];
Stream
*
_stream
;
Stream
*
_stream
;
DATA
*
_data
;
DATA
*
_data
;
STATUS
_status
;
STATUS
_status
;
...
@@ -95,9 +98,9 @@ void PMS::passiveMode()
...
@@ -95,9 +98,9 @@ void PMS::passiveMode()
// Request read in Passive Mode.
// Request read in Passive Mode.
void
PMS
::
requestRead
()
void
PMS
::
requestRead
()
{
{
if
(
_mode
==
MODE_PASSIVE
)
if
(
_mode
==
MODE_PASSIVE
)
{
{
// uint8_t command[] = { 0x11, 0x01, 0x02, 0xEC }; // [PREFIX] [nb_octets] [code_command] [checksum]
uint8_t
command
[]
=
{
0x11
,
0x0
1
,
0x0
2
,
0xE
C
};
// [PREFIX] [nb_octets] [code_command] [checksum]
uint8_t
command
[]
=
{
0x11
,
0x0
2
,
0x0
b
,
0x01
,
0xE
1
};
// [PREFIX] [nb_octets] [code_command] [checksum]
_stream
->
write
(
command
,
sizeof
(
command
));
_stream
->
write
(
command
,
sizeof
(
command
));
}
}
}
}
...
@@ -148,11 +151,13 @@ void PMS::loop()
...
@@ -148,11 +151,13 @@ void PMS::loop()
break
;
break
;
case
2
:
case
2
:
if
(
ch
!=
0x02
)
// command could be anything like 0x02 or 0x0b
{
/*
if (ch != 0x02) {
_index = 0;
_index = 0;
return;
return;
}
}
*/
_calculatedChecksum
+=
ch
;
_calculatedChecksum
+=
ch
;
break
;
break
;
...
@@ -169,6 +174,7 @@ void PMS::loop()
...
@@ -169,6 +174,7 @@ void PMS::loop()
_data
->
PM_1_0
=
makeWord
(
_payload
[
6
],
_payload
[
7
]);
_data
->
PM_1_0
=
makeWord
(
_payload
[
6
],
_payload
[
7
]);
_data
->
PM_2_5
=
makeWord
(
_payload
[
2
],
_payload
[
3
]);
_data
->
PM_2_5
=
makeWord
(
_payload
[
2
],
_payload
[
3
]);
_data
->
PM_10_0
=
makeWord
(
_payload
[
10
],
_payload
[
11
]);
_data
->
PM_10_0
=
makeWord
(
_payload
[
10
],
_payload
[
11
]);
_data
->
PM_UNKNOWN
=
makeWord
(
_payload
[
14
],
_payload
[
15
]);
}
}
_index
=
0
;
_index
=
0
;
...
@@ -274,7 +280,7 @@ void setup() {
...
@@ -274,7 +280,7 @@ void setup() {
Serial
.
println
(
F
(
"
\n
[PM_sensor] request data ..."
));
Serial
.
flush
();
Serial
.
println
(
F
(
"
\n
[PM_sensor] request data ..."
));
Serial
.
flush
();
delay
(
250
);
delay
(
250
);
while
(
Serial2
.
available
()
)
{
while
(
Serial2
.
available
()
)
{
char
msg
[
64
];
char
msg
[
128
];
char
_cur
=
Serial2
.
read
();
char
_cur
=
Serial2
.
read
();
if
(
_cur
==
0x16
)
{
if
(
_cur
==
0x16
)
{
Serial
.
print
(
F
(
"
\n
[new frame] = "
));
Serial
.
print
(
F
(
"
\n
[new frame] = "
));
...
@@ -311,8 +317,8 @@ void loop() {
...
@@ -311,8 +317,8 @@ void loop() {
Serial
.
print
(
F
(
"*"
));
Serial
.
flush
();
Serial
.
print
(
F
(
"*"
));
Serial
.
flush
();
}
}
unsigned
long
_cur
=
millis
();
unsigned
long
_cur
=
millis
();
char
msg
[
64
];
char
msg
[
128
];
snprintf
(
msg
,
sizeof
(
msg
),
"[PM_sensor] %lums read [PM1|PM2.5|PM10](µg/m3) %d %d %d"
,
(
_cur
-
_lastActive
),
data
.
PM_1_0
,
data
.
PM_2_5
,
data
.
PM_10_0
);
snprintf
(
msg
,
sizeof
(
msg
),
"[PM_sensor] %lums read [PM1|PM2.5|PM10
|PMunknown
](µg/m3) %d %d
%d
%d"
,
(
_cur
-
_lastActive
),
data
.
PM_1_0
,
data
.
PM_2_5
,
data
.
PM_10_0
,
data
.
PM_UNKNOWN
);
Serial
.
println
(
msg
);
Serial
.
flush
();
Serial
.
println
(
msg
);
Serial
.
flush
();
/*
/*
Serial.print("\nPM 1.0 (ug/m3): ");
Serial.print("\nPM 1.0 (ug/m3): ");
...
...
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