Avatar for larry

larry

Member since Sep 2018 • Last active Jan 2020
  • 3 conversations
  • 23 comments

Most recent activity

  • in Electronics
    Avatar for larry

    https://luftdaten.info/ has a service & map where you can post dust-data (works outside of Germany too). They have a complete guide about how to make a stationary sensor with ESP8266, if you are interested.

    yes, I've seen this! maybe I'll build their module and contribute to!

  • in Electronics
    Avatar for larry

    I did something more concise, following your advice:

    const o = {};
    
    function checkvalidity(buff) {
        let sum =  E.sum(buff.slice(2,8));
        sum = sum & 0xFF;
        const validCheckSum = buff[8];
        return sum == validCheckSum;
    }
    
    o.init = function (serial, callback) {
    
        //--- Exemple buffer
        //  data <Buffer aa  c0  1b  05  7d  08  9c  eb  2c  ab>
        //               170 192 27  5   125 8   156 235 44  171
    
        let bufferDecimal = [];
        let bufferLength = 0;
    
        serial.on('data', function (data) {
    
            for (index in data) {
    
                let charDecimal = data.charCodeAt(index); // chope la valeur decimal du caractère
                bufferDecimal.push(charDecimal);
    
                bufferLength++;
    
                if (bufferLength == 10) {
    
    
                    let validity = checkvalidity(bufferDecimal);
    
                    if(validity){
                        // PM2.5 value -  ((PM2.5 High byte[3] *256) + PM2.5 low byte[2] ) / 10
                        // PM10 value -  ((PM10 High byte[5] *256) + PM10 low byte[4] ) / 10
                        let pm2_5 = ((bufferDecimal[3] * 256 ) + bufferDecimal[2])/10;
                        let pm10 = ((bufferDecimal[5] * 256 ) + bufferDecimal[4])/10;
    
                        callback({
                            pm2_5:pm2_5,
                            pm10:pm10
                        });
    
                    } else {
                        console.log("validity false");
                    }
    
                    bufferLength = 0;
                    bufferDecimal=[];
    
                }
            }
        });
    };
    
    module.exports = o;
    
    

    I 've started to build a closure with an soap plastic box, with inside the dust sensor, an ESP8266 or Espruino Pico and a small 128*64 Oled screen.

    I would take data measurements while walking in Paris. I am curious about the results especially at the level of the big automobile hub, and close to the ring road.

    I'll post the full project in the "Project" section of the forum if I do not encounter new problems ! (I have never used the Oled screen)

  • in Electronics
    Avatar for larry

    Hope you don't mind too much as effectively I have given you some work to do :)

    yeah, it's a shame! nooo, it's the first time I try to interpret raw output data from sensor, so your comment helps me better understand on what's going on.

    din't know about E.sum, i found more informations from the waveform exemple code very interresting, like :

    Note: When dealing the large amounts of elements in Waveforms you'll start to notice Espruino's relatively slow execution speed. We'd recommend using E.sum, E.variance, E.convolve and E.FFT to work on large arrays wherever possible, and Array.forEach and Array.map to iterate over their elements.

    I correct my duties at home, and I come back with a better copy, lol!

  • in Electronics
    Avatar for larry

    Here is the module for the SDS011, according to the manual to check the checksum and get proper value for PM2.5 and PM10.

    const o = {};
    
    function checkvalidity(bufferHex) {
    
        let  sum = 0;
        for (let i = 2; i < 8; i++) {
            sum = sum + parseInt(bufferHex[i], 16);
        }
    
        sum = sum &0xFF;
        const validCheckSum = parseInt(bufferHex[8],16);
    
        return sum == validCheckSum;
    }
    
    o.init = function (serial, callback) {
        console.log("> mod-dustsensor - init");
    
        //--- Exemple buffer
        //  data <Buffer aa  c0  1b  05  7d  08  9c  eb  2c  ab>
        //               170 192 27  5   125 8   156 235 44  171
    
        let bufferDecimal = [];
        let bufferHex = [];
        let bufferLength = 0;
    
        serial.on('data', function (data) {
    
            for (index in data) {
                let charDecimal = data.charCodeAt(index); // chope la valeur decimal du caractère
                let charHex = data.charCodeAt(index).toString(16); // chope la valeur Hex du caractère
    
                bufferDecimal.push(charDecimal);
                bufferHex.push(charHex);
                bufferLength++;
    
                if (+charDecimal == 171 && bufferLength == 10) {
    
                    let validity = checkvalidity(bufferHex);
    
                    if(validity){
                        // PM2.5 value -  ((PM2.5 High byte[3] *256) + PM2.5 low byte[2] ) / 10
                        // PM10 value -  ((PM10 High byte[5] *256) + PM10 low byte[4] ) / 10
                        let pm2_5 = ((bufferDecimal[3] * 256 ) + bufferDecimal[2])/10;
                        let pm10 = ((bufferDecimal[5] * 256 ) + bufferDecimal[4])/10;
                        callback({
                            pm2_5:pm2_5,
                            pm10:pm10
                        });
                    }
    
                     bufferLength = 0;
                     bufferDecimal=[];
                     bufferHex=[];
    
                }
            }
        });
    };
    
    module.exports = o;
    

    Entry point :

    const modDustSensor = require('mod-sds011');
    
    function onInit() {
    
        Serial1.setup(9600, {rx: B7, tx: B6});
    
        modDustSensor.init(Serial1, function(pmValues){
            console.log(`PM-2.5: ${pmValues.pm2_5} --- PM-10: ${pmValues.pm10} `);
        });
    
    }
    
  • in Electronics
    Avatar for larry

    @maze1980 I'm on the way for it, I'll post a module to easily use the sensor here :) hope very soon !

  • in Electronics
    Avatar for larry

    Powering SDS0111 module to Pico VBAT & GND give correct buffer serial sequence, how cool is that ? hum ? thank's bro, Espruino rock's, yeah!

    got an PM2.5 sensor ready to go, I will be able to leave with and be disgusted to be completely in a cloud of pollution nearly all day long, cool!

    > data:170
    > data:192
    > data:83
    > data:8
    > data:136
    > data:12
    > data:156
    > data:235
    > data:118
    > data:171
    
    > data:170
    > data:192
    > data:35
    > data:8
    > data:71
    > data:12
    > data:156
    > data:235
    > data:5
    > data:171
    
    > data:170
    > data:192
    > data:15
    > data:8
    > data:60
    > data:12
    > data:156
    > data:235
    > data:230
    > data:171
    
    > data:170
    > data:192
    > data:248
    > data:7
    > data:32
    > data:12
    > data:156
    > data:235
    > data:178
    > data:171
    ...
    
  • in Electronics
    Avatar for larry

    The Pico also has a VBAT pin which provides somewhere in the region of
    4.5v when from USB or battery voltage when powered from battery, so I would use that: https://www.espruino.com/Pico#pinout

    I'll try this tonight !

    There's even a self-resetting fuse in there so if you draw too much
    power (>500mA sustained) from USB it'll just temporarily cut out
    without breaking anything.

    didn't know that, it's cool

  • in Electronics
    Avatar for larry

    first, thank you all for your post!

    @Robin

    • Settings >> Communications >> Baud Rate set to 9600 > ok
    • pins Tx/Rx reversed test > checked
    • Same serial port (B7, B6 ) is working on other project of mine, tested on the same Pico (I will post the link of the complete tutorial on hackster.io probably tomorrow or before the end of this week), from now not yet tried to test with Software Serial on other Pico pin...
    • console.log(Serial1.available()) give me 0 output, it seem's ok reading the doc.
    • no clock line being used (in fact, I'm not sure what it is?, RTC module connected to the Pico?)
    • process.env output :

    "VERSION": "2v03",
    "GIT_COMMIT": "e77d74f6",
    "BOARD": "PICO_R1_3",
    "FLASH": 393216, "RAM": 98304,
    "SERIAL": "3f006300-04513432-33343134",
    "CONSOLE": "USB",
    "MODULES": "Flash,Storage,heatshrink,fs,net,dgram,tls,http,NetworkJS,WIZnet,tv,crypto,neopixel",
    "EXPTR": 536871212

    • Same Gnd for Pico and SDS011 : well, this thing, it can be a bit complicated:

    Pico is connected by USB to my PC, and the SDS011 (5V needed) sensor is powered by an Breadboard Power Supply Module 3.3V 5V.
    I do not think I can connect the Pico GND to the power supply module.
    There may be another solution, I have a power boost module 3.3V to 5V. I could connect Pico pin 3.3V & Gnd output to the power boost module to power the SDS011, but would not I risk wanting too much power from the Pico and damaging it?

    @AkosLukacs
    Unfortunatly, I need more time and skill in the protocol Serie to adapt your code! but I will do some test on my project reading your scripts.

    @maze1980

    below, sample output of

        for (index in data) { 
          console.log("> data:" + data.charCodeAt(index));
        }
    
    > data:170
    > data:192
    > data:134
    > data:80
    > data:239
    > data:170
    > data:192
    > data:107
    > data:179
    > data:170
    > data:192
    > data:92
    > data:251
    > data:170
    > data:192
    > data:82
    > data:255
    > data:170
    > data:192
    > data:110
    > data:170
    > data:248
    > data:251
    > data:170
    > data:252
    > data:171
    > data:255
    > data:170
    > data:255
    > data:170
    > data:255
    > data:171
    > data:255
    > data:171
    > data:253
    > data:235
    > data:247
    > data:235
    > data:253
    > data:251
    > data:245
    > data:255
    > data:245
    > data:255
    > data:171
    > data:255
    > data:183
    > data:255
    > data:107
    > data:255
    > data:91
    ...
    

    well, It's maybe a correct output, comparing the output serial from the Node.js script when the sds011 module is running, I've got

        <Buffer aa  c0  1b  05  7d  08  9c  eb  2c  ab>
    

    converting to decimal is

    [170 192 27  5   125 8   156 235 44  171]
    

    Reading the SDS011 doc, I should always get aa c0 (170 192 ) starting byte ... and ending with ab (171).
    But, from my new decimal WebIDE output reading,
    there not clean [170 192 data data data data data data data 171] repetitive sequence ?

    I have to go to work now (already late)
    thank's for your precious time folks!

  • in Electronics
    Avatar for larry

    @Robin

    Here my small Node script, I've just connect de SDS011 to an USB to my computer (port COM8):

    ///////////////////////////////////
    // Hello, SDS011
    ///////////////////////////////////
    const SDS011Wrapper = require("sds011-wrapper");
    
    const sensor = new SDS011Wrapper("COM8"); // Use your system path of SDS011 sensor.
    
    console.log("process.env " , process.env);
    
    sensor
        .setReportingMode('active')
        .then(() => {
            console.log("Sensor is now working in active mode.");
            return sensor.setWorkingPeriod(0); // Sensor will send data as soon as new data is available.
        })
        .then(() => {
            console.log("Working period set to 0 minutes.");
            console.log("\nSensor readings:");
    
            // Since working period was set to 0 and mode was set to active, this event will be emitted as soon as new data is received.
            sensor.on('measure', (data) => {
                console.log(`[${new Date().toISOString()}] ${JSON.stringify(data)}`);
            });
        });
    

    I've added a console.log to know what the serialPort npm Node module serial output is like (I've edited the file wrapper.js in the node module directory : node_modules\sds011-wrapper\wrapper.js)

    Here a sample view of wrapper.js where I've put my console.log:

    const SerialPort = require('serialport');
    const EventEmitter = require('events');
    
    const SensorState = require("./core/sensor-state.js");
    const SensorCommand = require("./core/sensor-command.js");
    
    const addChecksumToCommandArray = require("./core/packet-utils.js").addChecksumToCommandArray;
    const verifyPacket = require("./core/packet-utils.js").verifyPacket;
    
    const PacketHandlers = require("./core/packet-handlers.js");
    
    const ALLOWED_RETRIES = 10; // Number of retries allowed for single command request. 
    const COMMAND_RETRY_INTERVAL = 150; // Time between sequential retries.
    
    class SDS011Wrapper extends EventEmitter {
    
        /**
         * Open sensor.
         *
         * @param {string} portPath - Serial port path
         */
        constructor(portPath) {
            super();
    
            this._port = new SerialPort(portPath, { baudRate: 9600 });
            this._state = new SensorState();
    
            this._commandQueue = [];
            this._isCurrentlyProcessing = false;
            this._retryCount = 0;
    
            this._port.on('error', function (err) {
                console.log('Error: ', err.message);
            });
    
            this._port.on('close', () => {
                console.log('SDS011Wrapper port closed');
                this.close();
            });
    
            /**
              * Listen for incoming data and react: change internal state so queued commands know that they were completed or emit data.
              */
            this._port.on('data', (data) => {
                console.log("///// data ////// " , data);
                if (verifyPacket(data)) {
                ...
                ...
    

    now the output :

    ///// data //////  <Buffer aa c0 f3 1b 1f 4e 9c eb 02 ab>
    [2019-06-22T16:29:46.134Z] {"PM2.5":715.5,"PM10":1999.9}
    
    

    you can see that the BaudRate is default to 9600 (wrapper.js), and I've set the same value when I use the sensor connected to Espruino Pico, here is my code :

    function onInit() {
      
            Serial1.setup(9600, {rx: B7, tx: B6});
            Serial1.on('data', function (data) {
                 console.log("> data  : " , data);
            }
    }
    
    

    with result like :

    > data  :  ­
    > data  :  ¶
    > data  :  
    > data  :  «
    > data  :  =
    > data  :  ¼
    > data  :  Œ
    > data  :  ¶
    > data  :  
    > data  :  ¯
    > data  :  ¾
    > data  :  ä
    > data  :  q
    > data  :  =
    > data  :  }
    > data  :  þ
    > data  :  ú
    > data  :  N
    > data  :  œ
    > data  :  ë
    > data  :  Ï
    > data  :  ÿ
    > data  :  
    > data  :  
    > data  :  N
    > data  :  Ü
    > data  :  ÿ
    > data  :  ü
    > data  :  ¡
    > data  :  
    > data  :  
    > data  :  Î
    > data  :  œ
    > data  :  ÿ
    
Actions