
Ttgo Paxcounter with fine dust sensor and BME280
wird aktuell überarbeitet für v.3 Stack CEwird aktuell überarbeitet für v.3 Stack CEHardware:
Optional components, depending on the location and housing request:
Assembly / wiring
The pen strips are soldered on the Paxcounter board and on the BME sensor, depending on the installation position or installation location, the pen strip on the top or underside of the board is available. The screw antenna is installed - here too you can install a prolonged cable depending on the sensor structure. Then the two sensors are connected to the Paxcounter as follows:
The environmental sensor is wired as follows:
VCC (VDC 3,3 Volt) wird mit Pin 3.3V angeschlossen ORANGE
GND (Ground) wird mit dem GND am Paxcounter verbunden GELB
SCL (i2c Bus) --> Pin 22 am Paxcounter (mit SCL oder 22 beschriftet) GRÜN
SDA (i2c Bus) --> Pin 21 am Paxcounter (mit SDA oder 21 beschriftet) BLAU
frei
frei
The fine dust sensor is wired as follows:
TXD (Daten senden) wird mit Pin 23 am Paxcounter verbunden WEISS
RXD (Daten empfangen) wird mit Pin LoRa2 am Paxcounter verbunden SCHWARZ
GND (Ground) wird mit einem weiteren Pin GND am Paxcounter angeschlossen BRAUN
frei
VCC (VDC 5 Volt) kommt an den 5 Volt Pin (beschriftet mit 5V) ROT
frei
frei
Please take a look at the pictures in the folder /IMG, so you can clearly see the wiring again! I have listed the cable colors used in the example for you in the wiring plan! For a stable hold of the> connecting cable on the pen strip, we recommend that the plugs simply fix the plugs with a little hot glue. So for a while you avoid slipping the partial cable quite loosely. In the picture folder you can now also see the recommended assembly that I have documented for you. We basically followed the project from Stuttgart, but a little modified
Thethingsnetwork --- wird aktuell überarbeitet für v.3 Stack CE In the next step we prepare our account at thethingsnetwork.org-first (unless already available) an account is created. A new application is then created. In addition to a clear name, only the TTN handler is entered here as "TTN-Handler-EU".
Within this application we create our device - so almost our TTN fine dust sensor. To do this, we click on "Register Device". In the next window we award a short, unique name, for example "fine dust sensor-01"-we can automatically generate the deviceui. To do this, we click on the double arrow in front of the corresponding field. More is not needed at this point, later you can store the location and similar data to the device if you want. We leave the browser window with "Device Overview", it will be needed later!
software
For programming we use Microsoft Visual Studio Code with the Platformio ID expansion. First, Visual Studio Code is installed, then entered and installed under "File" and "Preferences", "Extensions" in the Platformio IDE search field. After restarting the software, our programming environment is ready.
Note: Numerous extensive instructions in the WWW describe the installation and setting up of the VS Code very detailed
Github repository
We have been using the Cybmerman54 from Github as basic software for some time. https://github.com/cyberman54/esp32-paxcounter/releases
Important note: Since this repo has also been revised strongly from version 3.2, the connection from the fine dust sensor via the serial interface, as described in our instructions, also no longer seems to work. So download version 3.1 to build the environmental sensor based on the TTGO PAXCOUNER board !!!
The repository is downloaded and unpacked, then opened in the VS code.
Changes and adjustments
(1) In the first step, the Platformio_orig.ini file is renamed or copied from the main directory and then renamed Platformi.ini. Then the line 10 is replaced in this file ;halfile = generic.h . In this file too, line 19 is replaced to halfile = ttgov21new.h - the semicolon removed and thus activated (see picture)
(2) In the folder/SRC/HAL/the file "ttgov21new.h" is adjusted as follows, the following code is simply inserted into line 21:
// BME280 sensor on I2C bus
#define HAS_BME 1 // Enable BME sensors in general
#define HAS_BME280 GPIO_NUM_21, GPIO_NUM_22 // SDA, SCL
#define BME280_ADDR 0x76 // change to 0x77 depending on your wiring
// SDS011 dust sensor settings
#define HAS_SDS011 1 // use SDS011
// used pins on the ESP-side:
#define SDS_TX 12 // connect to RX on the SDS011
#define SDS_RX 35 // connect to TX on the SDS011
Simply copy the code above and insert it in the VS code in the file. The result can be seen in the picture.
(3) /SRC/ota_sample.conf: The file is renamed or copied to "OTA.CONF", in the file itself we do not have to make any changes
(4) /SRC/loraconf_sample.h: Rename or copy into "Loraconf.H" in line 38, 40 and 42 insert the DEveUI, Appeui and AppKey (as MSB). To do this, we go back to the browser window with "Device Overview". In order to get the keys into the correct number format, the <> symbol of the respective line is clicked, the key changes its format. We need the MSB format each
Excursus: When programming, you have certainly stumbled through the abbreviations "MSB" and "LSB". You can find out what the abbreviations are in this practical tip. Bit value: MSB & LSB simply explains the bitterworthy is to determine the importance of each bits. For example, this is important for serial transmissions.
- LSB stands for "Least Significant Bit". If a bit sequence is numbered according to the LSB-0-bit number, then the bit with the index 0 is the lowest status.
- MSB stands for "Most Significant Bit". With MSB-0-bit numbering, the BIT with the index 0 has the highest importance. If with a binary number with positions 0, 1, ..., N-1 the BIT with the index 0 has the highest importance, its value must be multiplied by 2 (N-1).
At the end of the respective line With the key you can copy the entire part into the clipboard, back in the VS code, the three keys are copied in the corresponding lines one after the other - the specified sample keys are simply overwritten. Here, too, I created a picture for you to illustrate.
(5) The file /.pio/libdepepsusb/sds011 sensor library/sds011.cpp is now being processed:
This code comes from Cyberman54/ESP32-Paxcounter#597 (Comment) and describes the "work command"
The text is inserted into line 35:
static const byte WORKCMD[19] = {
0xAA, // head
0xB4, // command id
0x06, // data byte 1
0x01, // data byte 2 (set mode)
0x01, // data byte 3 (work)
0x00, // data byte 4
0x00, // data byte 5
0x00, // data byte 6
0x00, // data byte 7
0x00, // data byte 8
0x00, // data byte 9
0x00, // data byte 10
0x00, // data byte 11
0x00, // data byte 12
0x00, // data byte 13
0xFF, // data byte 14 (device id byte 1)
0xFF, // data byte 15 (device id byte 2)
0x06, // checksum
0xAB // tail
};
In addition, we have to change line 113 in:
void SDS011::wakeup() {
// sds_data->write(0x01);
// sds_data->flush();
for (uint8_t i = 0; i < 19; i++) {
sds_data->write(WORKCMD[i]);
}
sds_data->flush();
while (sds_data->available() > 0) {
sds_data->read();
}
}
Decoder and Converter --- wird aktuell überarbeitet für v.3 Stack CE at the end of the software changes, we will still get the content of this file from the following via Copy & Paste /Src/Packed_converter.js -> Converter and go back to the browser window. In the properties of the TTN application we go to the "Payoad Format" tab and select the converter there for inserting. If there is already text in the window, it is simply completely deleted and then the text from the OG file is inserted there.
Then we get the decoder from the File /SRC/Tn/packed_decoder.js in the VS code and copy it just as in the "Payoad Format -> Decoder" field is still a small, manual change:
Add the following in line 37 (Payoad Formats -> Decoder):
// combined wifi + ble + SDS011
if (bytes.length === 8) {
return decode(bytes, [uint16, uint16, uint16, uint16], ['wifi', 'ble', 'PM10', 'PM25']);
}
A short test in the console brings security that the decoder works: Insert 16x 0 in the field for Payoad, put port on 1 and click "Test" and then click "Save Payoad Function".
Compile and upload
As a last step, only the compilation of the program in the VS Code is necessary, after which the entire program is loaded onto the Pax Counter via USB. The sensor is therefore connected via a micro USB cable and activated with the sliding switch.
At the bottom of the blue bar, unnecessary and code content and files are automatically cleaned up on "Clean" (symbol clicked garbage bin).
Then click on the symbol with the "Built" hook in the blue bar at the bottom - it can take a moment, but should be closed after a few minutes at the latest.
Ultimately, the entire program code is sent to the sensor. Simply click on the right arrow "Upload"; The program is transferred and then the sensor restarted when the transmission has been successfully finished.
If you click on the "Serial Monitor" connector symbol in the blue bar, you can observe in a console what the sensor is active and measured values are also displayed there.
For a direct function test in the TTN console, a TTN gateway is essential within reach, otherwise the sensor will send its data into the surrounding area, but are nowhere to be received and processed.
--- wird aktuell überarbeitet für v.3 Stack CE in parallel to open the TTN application in the browser, select the device and click on the "Data" field at the top right. After a short time, data should also be displayed here that are transmitted to Thethingsnetwork via Lora Funktechnik. Note, since the fine dust values are transmitted as the "full election", the measured values displayed in the TTN console must be shared by 10 !!! Congratulations, your Lora fine dust sensor is ready !!! In two other chapters we give an outlook on what can be done with the data obtained and how to publish it on OPENDATA cards.
Outlook 1 - Node -Red, InfluxDB and Grafana The text follows here
Outlook 2 - Opendata cards, air data and OpenSensemap The text follows here