-
-
-
-
-
-
-
____ _ | __|___ ___ ___ _ _|_|___ ___ | __|_ -| . | _| | | | | . | |____|___| _|_| |___|_|_|_|___| |_| espruino.com 2v08.80 (c) 2019 G.Williams Espruino is Open Source. Our work is supported only by sales of official boards and donations: http://espruino.com/Donate Flash map 512KB:256/256, manuf 0xc8 chip 0x4013 >di digitalPulse digitalRead digitalWrite >digitalWrite(D13,1) =undefined >digitalPulse(D13,1,10) =undefined Uncaught Error: Invalid pin!
Occurs only with digitalPulse ()
-
-
-
// lan-test00 - esp8266_01 var ver = 'ver = V1.0'; function onInit(a) { debug = (typeof a==='undefined')?0:a; var wlan = require("Wifi"); var http = require("http"); var logon = require('LOGON'); wlan.stopAP(); wlan.disconnect(); var boola; function lan() { //wlan.connect(yourssid, {password: yourpassword}, function (s) { wlan.connect(logon.ssid, {password: logon.pass}, function (s) { boola = true; if(s==='bad password') { if(debug)console.log('restart lan'); lan(); } }); if(debug)console.log("Frida is my watchdog"); if(debug)console.log(wlan.getIP().ip); } // end lan() setTimeout(lan,400); wlan.on('connected', function(s) { if(debug)console.log('Starter test', wlan.getIP().ip); if(boola) { boola = false; //do what you need to do. if(debug)console.log('tilsluttet lan'); } }); } // end onInit() onInit(2); // comment or remove before save
You should not use logon and use your own logon values instead. That's because I have my logon values in a module.
I use debug until the program runs properly. -
That mistake I had several years ago
It turned out that one of my routers was teasing.
I use the showed up start and since then there have been no problems.
The other routers have no problems.function lan() { wlan.connect(logon.ssid, {password: logon.pass}, function (s) { boola = true; if(s==='bad password') { if(debug>0) {console.log('restart lan');} lan(); } }); if(debug)console.log("Frida is my watchdog"); if(debug)console.log(wlan.getIP().ip); } // end lan() setTimeout(lan,400); wlan.on('connected', function(s) { if(debug)console.log('Starter test', wlan.getIP().ip); if(boola) { boola = false; startTimeServer(); //httpSrv.listen(80); } });
-
-
-
I use function() instead of ()=>, because it doesn't work in my browser.
And to stop analogWrite, use digatalRead.// sinus.js //setInterval( ()=> {analogWrite(D2, (Math.sin(getTime()) / 2.01) + 0.5 );},10); //setInterval( function() {analogWrite(D2, (Math.sin(getTime()) / 2.001) + 0.5 );},10); analogWrite(D2, 0.5, {freq:1000}); //setTimeout(function() {analogWrite(D2, 0);},1700); setTimeout(function() {digitalRead(D2);},10);
-
-
-
I use this:
*** To flash a 512KB esp8266 (e.g. esp-01) using the serial port use: esptool.py --port /dev/ttyUSB0 --baud 115200 write_flash \ --flash_freq 40m --flash_mode qio --flash_size 4m \ 0x0000 "boot_v1.6.bin" 0x1000 espruino_esp8266_user1.bin \ 0x7C000 esp_init_data_default.bin 0x7E000 blank.bin
because it is only 512KB
-
-
-
-
Ok, time to bring the toys back.
With this test I have set a LED to pin, active low.First test.
function tt () { ht = {}; //ht.pin = D0; // esp8266 ht.pin = D12; // esp32 pico4 setInterval (function () { var d = ""; ta = getTime (); tb = 0; pinMode (ht.pin, 'opendrain'); ht.watch = setWatch (function (t) { d = 0 + | (t.time-t.lastTime> 0.000050); // 50 usec (time in sec) }, ht.pin, {edge: 'falling', repeat: true}); //pinMode(ht.pin, 'opendrain'); setTimeout (function () { pinMode (ht.pin, 'input_pullup'); tb = getTime (); console.log (tb-ta); }, 1000); setTimeout (function () { Clear watch (ht.watch); console.log ('d =' + d); console.log (process.memory ()); }, 200); }, 3000); } TT ();
It only gives me short pulses, and not for 1 second, as expected.
If I remove clearWatch (ht.watch), I get a short pulse, then full pulse length and it uses all the memory.On esp8266 there are no problems.
Next test.
function tt () { ht = {}; //ht.pin = D0; // esp8266 ht.pin = D12; // esp32 pico4 setInterval (function () { var d = ""; ta = getTime (); tb = 0; //pinMode(ht.pin, 'opendrain'); ht.watch = setWatch (function (t) { d = 0 + | (t.time-t.lastTime> 0.000050); // 50 usec (time in sec) }, ht.pin, {edge: 'falling', repeat: true}); pinMode (ht.pin, 'opendrain'); setTimeout (function () { pinMode (ht.pin, 'input_pullup'); tb = getTime (); console.log (tb-ta); }, 1000); setTimeout (function () { Clear watch (ht.watch); console.log ('d =' + d); console.log (process.memory ()); }, 200); }, 3000); } TT ();
Here pinMode has been moved to after set_Watch and I can determine pulse length on LED.
Also works on esp8266.And now for a workaround, so it works on both esp8266 and esp32 pico4 as I have.
Hope this is something you can use?
// testWatch02 function DHT22 (pin) { this.pin = pin; } DHT22.prototype.read = function (cb, n) { if (! n) n = 10; var d = ""; var ht = this; // start watching for state change ht.watch = setWatch (function (t) { d = 0 + | (t.time-t.lastTime> 0.00005); }, ht.pin, {edge: 'falling', repeat: true}); pinMode (ht.pin, 'opendrain'); // PB obs It sets the output low immediately // raise pulse after 10ms setTimeout (function () {pinMode (ht.pin, 'input_pullup'); pinMode (ht.pin);}, 10); // stop looking after 100ms setTimeout (function () { if (ht.watch) {ht.watch = clearWatch (ht.watch); } d = d.substr (1); // PB you are a genius var cks = parseInt (d.substr (2.8) 2) + parseInt (d.substr (10.8), 2) + parseInt (d.substr (18.8), 2) + parseInt (d.substr (26.8), 2); if (cks && (((cks & 0xFF) == parseInt (d.substr (34.8), 2))) { cb ({ raw: d, rh: parseInt (d.substr (2.16), 2) * 0.1, temp: parseInt (d.substr. (19.15), 2) * 0.2 * (0.5-d [18]) }); } else { if (n> 1) setTimeout (function () {ht.read (cb, - n);}, 500); // else cb ({err: true, checksumError: cks> 0, raw: d, temp: -1, rh: -1}); else cb ({err: true, checksumError: cks> 0, raw: d, temp: -1, rh: -1, n: n}); } }, 100); }; DHT22.prototype.getName = function () { return 'Frida'; }; / * exports.connect = function (pin) { return new DHT22 (pin); }; * / function dd () { esp = 0; if (esp) { pin = D0; // esp8266 // esp8266 version 2v00.68 (c) 2018 G.Williams var ESP8266 = require ('ESP8266'); ESP8266.setCPUFreq (80); console.log (ESP8266.getState ()); } else { pin = D12; // esp32 pico4 // esp32 pico4 version 2v02 (c) 2018 G.Williams console.log (ESP32.getState ()); } // var dht = require ("DHT22a"). connect (pin); var dht = new DHT22 (pin); console.log (dht.getName ()); setInterval (function () { dht.read (function (a) { console.log ("Temp is" + a.temp.toFixed (1) .toString () + ", RH is" + a.rh.toFixed (1) .toString () + "\ Nraw:" + a.raw + "\ nn:" + a.n + "\ Nerr:" + a.err + ", cse:" + a.checksumError);}, 1); setTimeout (function () { console.log ("E-Flags: [" + E.getErrorFlags () + "] \ n \ n");}, 1000); }, 3000); } dd (); // save ();
And some outputs.
Temp is 35.1, RH is 92.3 raw:010000001110011011000000010101111111111110 n: undefined err:undefined, cse:undefined E-Flags: [] Temp is 35.1, RH is 92.4 raw:010000001110011100000000010101111111111111 n: undefined err:undefined, cse:undefined E-Flags: [] Temp is 35.1, RH is 92.5 raw:010000001110011101000000010101111100000000 n: undefined err:undefined, cse:undefined E-Flags: [] Temp is 35.1, RH is 92.6 raw:010000001110011110000000010101111100000001 n: undefined err:undefined, cse:undefined E-Flags: [] Temp is 35.1, RH is 92.7 raw:010000001110011111000000010101111100000010 n: undefined err:undefined, cse:undefined E-Flags: [] Temp is 35.1, RH is 92.8 raw:010000001110100000000000010101111100000011 n: undefined err:undefined, cse:undefined E-Flags: [] Temp is 35.1, RH is 92.9 raw:010000001110100001000000010101111100000100 n: undefined err:undefined, cse:undefined E-Flags: [] Temp is 35.1, RH is 93.0 raw:010000001110100010000000010101111100000101 n: undefined err:undefined, cse:undefined E-Flags: [] Temp is 35.1, RH is 93.1 raw:010000001110100011000000010101111100000110 n: undefined err:undefined, cse:undefined E-Flags: [] Temp is 35.1, RH is 93.2 raw:010000001110100100000000010101111100000111 n: undefined err:undefined, cse:undefined E-Flags: []
Happy coding.
-
-
Only used it for a few months.
Just uploaded and updated it to 2V24.
Is a kickstarter clock, without buzzer.
Poul