-
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)
-
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!
-
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} `); }); }
-
@maze1980 I'm on the way for it, I'll post a module to easily use the sensor here :) hope very soon !
-
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 ...
-
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#pinoutI'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
-
first, thank you all for your post!
- 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.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! - Settings >> Communications >> Baud Rate set to 9600 > ok
-
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 : ÿ
-
I bought a fine particle sensor, the sds011. This sensor has a USB socket that allows me to test it super fast with a Node.js script (SDS011-Wrapper) it works very well.
Now I want to make a "more" portable solution, by connecting the sensor with Espruino Pico.
This sensor is connected in Serial.
During my tests using a Node.js script, I have exactly an hex bytes buffer output that corresponds to the documentation, like :
<Buffer aa c0 1b 05 7d 08 9c eb 2c ab>
For exemple, to get the PM2.5 value :
PM2.5 value: PM2.5 (μg /m3) = ((PM2.5 High byte *256) + PM2.5 low byte)/10Where PM2.5 High byte = 05(Hex) = 5(decimal)
and PM2.5 low byte = 1b(Hex) = 27(decimal)(reading de doc), after converting the Hex data to Decimal
const PM2.5 = ( ( 5 * 256 ) + 27 ) /10 = 130.7
Now, connecting Pico serial to this sensor and console.log the serial output give me weird result (exotic characters, like ÿ ô , etc ...). I know I missing something, I know I should convert the sensor serial output to decimal data but I don't know where to start?, well in fact I don't know what is the type of data the sensor give me? an array of Hex?, decimal ASCII values ?
Will apreciate your help if someone have already use this little cool device !
larry -
I forgot to answer:
the wemos lipo charger work's very well
thank's guy -
-
@AkosLukacs, yeah , I've checked before the batteries, I think they are not dead, (3.4V for all).
@MaBe, @Gordon , let's try your recommendations, I've found a seller from France on Ebay, very soon I'll tell you if I finally manage to load my batteries.
Thank's a lot!
PS: you'r right Gordon, I wanted some batteries with a protection circuit, I hope I'll use then when I'll receive the charger you and Mabe propose.
-
Hello all
I've nearly finish an awesome project with Espruino Pico ;-) ... Now, to get this project as small as possible I've bought some small single cell Lipo batteries (450mAh - 800mah - 1200mah ) for tests.
But now I really don't know what king of charger I do need for this.
I've bought this one, but nothing happens when in plug one of my battery . I know I have to be carreful with this king of batteries, and all I can find, I mean, what I've found is mostly online ressources speaking about multiple cells for drones...
thank's for your advices
-
@DrAzzy, ok I'll try your suggestion!
But I think I changed my mind about in which situation I use Espruino! : I'm not an expert in Microcontroller Stuff and Espruino give me a "so easy way "to play with, but in the case of Lora & LoraWan stuff, I will use the traditional way (I've discovered that VisualStudioCode IDE has an Arduino extension, pretty cool).
Before doing this, I have ordered an Espruino Pico and, magically, there is no more Serial problems ! but nothing is listed on the "data" board on my personnal TTN console, but it's another problem (maybe I'm too far away from the next Gateway...)
I use your excellent board to connect the RN2483, it's very nice job, but I think I underestimate the soldering part ! I finally done , but it's not so easy!
Anyway, I'm continuing doing projects with Espruino and it's so cool to doing this in JavaScript !
-
Hi all
I'm trying to setup an serial connexion to the RN2483A to achieve an LoraWan test with TTN, like this exemple on Espruino site with no result. I've connect TX/RX from @DrAzzy plate to RN2384A TX/RX, power and try :
var RN2483 = require("RN2483"); Serial2.setup(9600, { tx:D17, rx:D16 }); var lora = new RN2483(Serial2); lora.getStatus(function(x){console.log(x);});
and get this result:{ "EUI": undefined, "VDD": NaN, "appEUI": undefined, "devEUI": undefined, "band": undefined, "dataRate": undefined, "rxDelay1": undefined, "rxDelay2": undefined, "rxFreq2_868": undefined }
So I'm trying first to get some console.log from the Serial2 on this ESP32 MCU board .I wired GPIO16 and GPIO17 and try this :
Serial2.setup(9600, { tx:D17, rx:D16 }); Serial2.on('data', function(data) { console.log('Serial2: ', data); }); Serial2.print('/// Hello UART ///');
Well... with no result too :(
Does someone succeed in this project? -
@Gordon, ok, now I understand that LoRaWan is built on top of transmit/receive stuff that is already available.
Well, from now, as I've ordered some RN2483A at this place, with some cool plates made by @DrAzzy, I'll first try implementing loraWan to TTN with Espruino !
-
-
@allObjects , I've read (maybe not so carefully) your example code.
I understand that you are doing node-to-node (no loraWan protocole) communication with 2 RN2309A modules.
My question is, how can the receiver module knows that is listen to your emitter module ? I mean, wath's happen if another guy in your neighbourhood start sending "lora"message too ? -
-
@allObjects, yeah cool!, I'll purchase the DrAzzy's stand alone plate for the RN2483 as I use to solder stuff for my crappy projects (I mean sometimes). I've seen your test fields from the RN2309A module, I'll try to do the same way but with an SMA antenna and a node connected to the The Things Networks. Hopefully, some geeky guys have setup gateways here in Paris.
@Robin, thank's mate, I'll follow you links concerning the use of the RN2483 module , but I think the things I wanted is in the official repo , where some .md file explain the core concept, where I'm afraid, I must learn how to program in C/C++ before start anything else ! (far, far away from my JavaScript skills)
Hope coming soon to talk about my test
thank's a lot folks, Espruino Rocks!
-
-
hello all,
Concerning Lora Module compatible with Espruino, I take this post opportunity to ask fews questions.My goal : use Lora module hardware and LoraWan to connect my nodes running Espruino to The Things Network gateways or later to a private network, like a gateway builded with my friend RasperryPi + openSource Lora server.
Actually Only the RN2483 module has a Espruino "driver" to achieved this (lora.LoRaWAN(.....) ). But , after long researches, I'm afraid I can no more order this device (Chinese online store, googleing....). I presume this piece of hardware is to old ?
On the other hand, the SX1276 can be found, I'll say , easily, but there no driver implementation for create a loraWan "communication?!".
My questions :
- Do you guys, have a secret links to order the un-reachable RN2483 868Mhz for EU ?
- @Gordon when you say
"... so nothing would stop someone else from making a JS module that
implemented LoRaWAN"how can I try to achieve this?, I mean, from a webdev guy, rather JS than C/C++ skills like I am, well, I don't know where to start learning "how to convert C/C++ code to Espruino Module". there a "Writing and Submitting Modules" on this site, but , from my poor skills, it's not enought reading to understand the magic of how Espruino interpreter works to drive microcontroller chip.
A word for my first message on this forum :
What you've done at Espruino team and clever forum user with JS on MicroController is HUGE !!, coming from near zero skill in C/C++ , i've tried small sketch with Arduino IDE & ESP - with Espruino i've tested nearly all thing I wanted to do so quikly. I meanly use esp8266, but I've just purchase an Puck.js to contribute to this excellent project, I'm sure I'll find cool things to do with.wizzz
- Do you guys, have a secret links to order the un-reachable RN2483 868Mhz for EU ?
yes, I've seen this! maybe I'll build their module and contribute to!