-
As for the extra features - just by looking at these pictures - Iskra definitely looks more appealing and user friendly because of clear pin labels. I really hate looking up the Espruino reference just to double check where PWM or ADC is, and for that reason alone I would often choose Arduino for simple toy projects.
The good thing is you can get improvements/ideas like that back to Espruino when the time comes for your next kickstarter campaign - which I will happily support :)
-
@allObjects thanks to your suggestions I have played with different timers and debounce values again and I think I'm getting somewhere.
@Gordon it's even less reliable this way, it's difficult to describe LED's behavior now so I have changed the code to use
console.log
and it looks interesting.First try:
var door = new Pin(A8); //pull-up E.on("init", function () { door.mode("input"); }); function doorOpenedHandler() { console.log("door opened"); } function doorClosedHandler() { console.log("door closed"); } setWatch(function () { doorOpenedHandler(); }, door, {repeat: true, edge: "falling", debounce: 500}); setWatch(function () { doorClosedHandler(); }, door, {repeat: true, edge: "rising", debounce: 500});
1v81 Copyright 2015 G.Williams >echo(0); =undefined >save() =undefined Erasing Flash..... Writing..... Compressed 81600 bytes to 2942 Checking... Done! // I'm starting with closed switch door closed >door.read() =true // I'm opening the switch door opened >door.read() =false // I'm closing the switch door opened >door.read() =true // wait, what? wrong handler got called but the door value is correct
Now let's try with
e.state
:... setWatch(function (e) { if (e.state) {doorOpenedHandler();} else {doorClosedHandler();} }, door, {repeat: true, edge: "both", debounce: 500});
// I'm starting with closed switch again, looks like the logic has changed door opened >door.read() =true // I'm opening the switch door closed >door.read() =false // I'm closing the switch door opened >door.read() =true // I'm opening the switch door closed // I'm closing the switch door closed // wrong handler again i.e. after seeing "door closed" the last time I would expect "door opened" now
Any ideas, please? Is my wiring ok?
-
Hello, I'm having problems with Pico and magnetic reed switches.
The idea is that on board LED indicate state of that switch i.e. green LED on when open, green LED off when closed. It all works well at first but when I quickly toggle the switch for a little while then LED gets "out of sync" with my switch, that is it lights green when closed.
I'm having this issue both with pull-up and pull-down connections, tried with a different switch and debounce values. I must be missing something - but what? :)
Example code:
var door = new Pin(A8); var ledOpen = LED2; var ledHold = LED1; E.on("init", function () { door.mode("input"); }); function doorOpenedHandler() { ledOpen.set(); } function doorHeldHandler() { ledHold.set(); } function doorClosedHandler() { ledOpen.reset(); ledHold.reset(); } setWatch(function () { doorOpenedHandler(); }, door, {repeat: true, edge: "falling", debounce: 0}); setWatch(function () { doorHeldHandler(); }, door, {repeat: true, edge: "falling", debounce: 2000}); setWatch(function () { doorClosedHandler(); }, door, {repeat: true, edge: "rising", debounce: 0});
-
-
-
@DrAzzy I will try to get hold of a multimeter tomorrow and answer your question. For now I can only say that it's a one channel Arduino relay module connected with Espruino Board with shared GND, IN to C9 and VCC to VBat. I should also clarify that it fails when no explicit pin mode specified by me, but works when I set pin mode to "output" beforehand.
And don't get me wrong guys, I'm not claiming that there is no good explanation for this behaviour. All I'm saying is that it has nothing to do with beginners friendliness :)
-
Ehh say what you want but for me (that is a beginner with no understanding of Figure 16) this whole thing is getting hairy.
After reading example codes I assumed that
pin.write(!pin.read())
simply toggles given pin right? Well no, it turns out it's not that simple. It works like a toggle for an LED, but it doesn't work for a relay module.Yes you said charging capacitors and square waves, but I say toggling is more likely a beginner's thing.
-
-
You are right. I will have to delegate it to some utility classes. This project is mostly in my head at this time so you probably saved me some trouble later on.
I also realized that using pinMode is a good idea, wasn't even aware of it.
Am I right thinking that onInit is a good place for pin mode configuration?
-
Thank you @Gordon for such detailed explanation.
I have used the LED example but in fact my use case is a bit different. So I have a bunch of things toggling a relay from a number of places in the code. Then there is other things logic depending on relay's state, so I want to check if it's on or off.
Now I could simply use a variable just like you suggested but it adds this overhead of keeping it in sync with a real state - as I said in multiple places of the code. I just feel more confident when operating directly on a given pin with Pin.write and - I wish - Pin.read.
I hope you will change your mind and see some value in adding something like readOutputValue :)
-
@DrAzzy yes it does the same thing.
-
Oh dear I find it so confusing :)
Reading a pin is not a read-only operation. So I check if LED1 is on and it returns 1 meaning yes. Except it's not any more, LED1 is off now.
Could you tell a bit more about the reasoning for this? I'm just trying to make sense of it.Reading pinMode documentation with its eight possible values is a bit rough. Do I have to know pullup, opendrain and the difference between "output" and "af_output" just to play around with LED1 like in op example?
I really admire Espruino's API and find it superior to other things I've tried, but this one seems like NaN in JS - weird.
-
-
Hi, I want to play around with my doorbell now and don't really know where to start.
Using off the shelf wireless doorbell is not an option as the installation is already there. So I'm stuck with these thick wires - one goes to a button, one goes to the sounder and the third one (I guess?) is a power source. I got them all meeting in one box so I can put Espruino there :) Espruino will have external USB power adapter.
Ideally I would like to be able to setWatch on the button and then Pin.write to the sounder. Programming is not an issue, but cabling is - don't want to burn the house down.
To get the signal out of Espruino I was thinking I could use a relay module. How about getting the signal into the board? Any suggestions?
-
Hi, just found this really nice set of Espruino examples (I'm not an author of that project):
https://github.com/anars/Espruino
Hello.
I just stumbled on Ecma TC53 and want to bring it to your attention in case if you missed it - searching these forums returned zero items. Turns out, there is a formal group of people working on standardizing JavaScript for embedded systems specifically.
I guess it doesn't make much financial sense for @Gordon to attend these meetings, but still as a creator of the most successful (in my eyes) JS engine|interpreter, he should have a say.
It may also be in Espruino's interest to explore it further.
So here is a link: https://www.ecma-international.org/memento/tc53.htm
The IO Class Pattern proposal looks interesting: https://github.com/Moddable-OpenSource/moddable/blob/public/documentation/io/io.md#tc53-io-a-new-take-on-javascript-inputoutput-on-microcontrollers