-
• #2
Hi Nick, are you typing this into the left hand side or right hand side of the IDE? Most modules aren't built into the firmware, the IDE loads it onto the board when you upload code from the right hand side. You could try typing the same code into the right hand side, or type
require("DS18B20")
into the right hand side and click upload, which will load the module, then type your code into the left hand side.
-
• #3
Thanks very much
That'll almost certainly be it - as I am pasting code into the left, 'immediate' window.
I don't imagine I'm the first - or will be the last to make this mistake.
Will try later - I would take silence as - it's working.
-
• #4
No problem. :) Yeah, I've seen a few other people miss that before. FYI, the left side is running commands directly on the board via a console, if a module isn't on the board yet, the board can't grab it. The right side will search your code for "require" and send the modules you need to the board before uploading your code.
-
• #5
In fairness - the example even says to paste on the right - I just jumped the gun in my excitement to get something working.
Perhaps you can help with the next problem - I wired up the DS18b20
and after stripping the whitespace - which broke the pasted code
I upload and run this (from the right window!) :-
var ow = new OneWire(D13); var sensor = require("DS18B20").connect(ow); setInterval(function() {sensor.getTemp(function (temp) {console.log("Temp is "+temp+"°C");});}, 1000);
Which - might be working - but it certainly isn't outputting anything to either the left window or the Pixl's screen
So I thought i'd add a console.log to the Setinterval callback - like this:-
var ow = new OneWire(D13); var sensor = require("DS18B20").connect(ow); setInterval(function() {console.log("hi");sensor.getTemp(function (temp) {console.log("Temp is "+temp+"°C");});}, 1000);
When I upload and run this .. there is a very short delay (probably the 1000ms) .. then it throws (on the left)
1v99 (c) 2018 G.Williams >Uncaught SyntaxError: Got EOF expected '}' at line 1 col 101 ...console.loC");});}, 1000); ^ =undefined >
It seems incredibly fragile - and like anything I write breaks it - I've seen other posts where peoples program are getting corrupted - Am I suffering with that?
-
• #6
Hmm, not sure about that one. The code looks good, but the error message is indicating some of the code didn't make it, no idea why, I've never had an issue with sending code (to official boards) before. Might need @Gordon 's help. I'd recommend power cycling both your computer and the Pixl if you try again in the meantime, might be a Bluetooth connection issue.
-
• #7
@Nickax, sad to hear your tough start... so lucky me, it was a no brainer to leave A..o (and other decade old fun with Z8) aline and enjoy very much iot w/ JS on Espruino.
To cut to the chase: copy-paste can have its issues since sometimes invisible rendering sequences make it into the code and mess it up.
Take a look at some of these conversations... Temperature Web Monitor (you going for BLE), Developing Modules... latter uses the DS18B20 but just as an example to discuss the topic.
Furthermore, as a general thing: 'never ever' - even though never ever say 'never ever' - do active things in level 0 - like
setInterval(...
- ... it just calls for puzzling waste of time. Unfortunately, many of the examples do so... and just get lucky most of the time. Being wired while developing, such as for Espruino Original board, Pico, Espruino-WiFi,... luck is almost guaranteed (for the small examples). With Puck and Pixl, luck is just in short supply, because over the air - ota - may get impacted from the electro smog around you and delay completion of upload - and uploading of code and firing timeouts don't like each other - as they are setup on upload when in level 0.Therefor, safest approach is using
onInit()
, even though there are other avenues that make sure that uploading completes first because any other (of your application stuff) gets underway.Take a look at simple explanation how to save code that espruino run on start? conversation. Even though a bit outdated, provides some insight what happens on upload and saving of code.
btw, if you put posted code between lines that have three (3) back-ticks (accent-grave) with a blank line before and after, your code because easy to read...
-
• #8
Thanks allObjects
I will try moving my code into onInit() and restarting the board after each upload - although that seems like the bad old days.
If OTA is so flaky - why is there no wired option for the Pixl ? - rhetorical question don't worry.
My Pixl is 20cms from my laptop - and actually powered from in over a USB cable.I can see how it should work - and if it did - it would be a thing of beauty - But I have stumbled on some really silly fundamental problems.
I understand about copy and paste - and invisible whitespace characters - (carriage returns, line feeds etc).. that caught me out early on but I have enough experience to spot it.
The 'Level 0' setInterval() thing - I will need to read up on - I took setInterval() to be the primary mechanism for running asynchronous code - I'm just surprised and frustrated the upload mechanism is so fundamentally flawed.
Again thanks for your reply
Nick
-
• #9
Sorry it's been such a pain to get started. Out of interest, did you go through http://www.espruino.com/Quick+Start+Code ? It seems modules and
require
aren't mentioned there, so I should definitely add a bit on them to help clear this up.If data is getting lost, something is definitely going wrong (that's not normal at all!). I think it's possible that you may have got a
FIFO_FULL
error message at some point during your uploads, but maybe didn't notice it. That basically says "Espruino was doing something that kept it busy during the upload, and the PC kept pushing data in and eventually some data got lost".As @allObjects says, the issue is likely that the code example isn't expecting to be executed at upload time, and some part of it takes a while to execute.
It'd explain why everything is feeling so flaky - whitespace shouldn't cause any issues at all, but by reducing it you're reducing the amount of code that is sent after the
require("DS18B20").connect
, which might pause for a while.Maybe try this - the difference is that
require("DS18B20").connect
will be called after everything has been uploaded.var ow, sensor; function onInit() { ow = new OneWire(D13); sensor = require("DS18B20").connect(ow); setInterval(function() { sensor.getTemp(function (temp) { console.log("Temp is "+temp+"°C"); }); }, 1000); } onInit();
or your other option is to just use the
Save on Send
option in the Web IDE's settings (which saves you code verbatim and then executes, rather than executing it line by line on upload). The only gotcha with that is that you can't then make changes on the left-hand side of the IDE and change them - at power-on it'd just execute exactly the same code you uploaded.If you're uploading code in future, please could you just highlight it and click the 'code' button in the editor? It makes it way easier for us to read :)
-
• #10
It seems my reply was a bit late, but:
why is there no wired option for the Pixl ?
It's a frustrating combination of power usage, cost, and not enough pins on the microcontroller. However if you have a USB-TTL dongle handy it's just 4 wires away
copy and paste - and invisible whitespace characters
The IDE itself should strip those out when you paste into it (especially on the right-hand side). The other issues you're having are I think a symptom of what's described above.
The 'Level 0' setInterval() thing
That shouldn't be an issue at all - it's actually the code that comes before it...
I'm just surprised and frustrated the upload mechanism is so fundamentally flawed.
If you turn on
Save on send
in settings I think you'll find it'll do what you expect, but there are some trade-offs.It's just a bit unfortunate really as the vast majority of things you'd upload would work just fine - it's just the DS18B20/OneWire stuff pauses for some time when it is called.
-
• #11
Hi Gordon
Nice to meet you .. I (potentially) love what you are doing and have high hopes for my Pixl.
I did indeed see that FIFO buffer error at least once .. but definitely not every time.
I will try both of your suggestions - I'm not sure of the rationale for executing each line as it uploads - I can see that any setInterval could fire for a function not yet defined - or for that matter simple function calls could fail. Maybe I misunderstand (entirely).
I could see I was getting syntax error on code I hadn't written - some sort of corruption.
Apologies for my bad manners in code formatting.
My laptop is an HP Spectre 360 - it has Bluetooth but I don't know if it's 'LE' - could that have anything to do with it ?
BTW I'm using the native IDE not the web one .. I will see if it has a save on send option.
-
• #12
Right... the fix appears to be to use the 'throttle send' option in the communications section of settings.
Without it - I get stupid syntax errors about EOF encountered and expecting } - when all my braces are present and correct.
With it .. worked first time
(This is with the code refactored as per @Gordon 's suggestion - but I suspect the original may work)
(Well, I say worked - my temperature comes back as null all the time but that's a different problem)
I feel like I'm in with a chance now.
Thanks everyone
-
• #13
Hi! I don't generally work at the weekend so I'm afraid I'm a bit slow to offer any help here.
I did indeed see that FIFO buffer error at least once .. but definitely not every time.
Yes, you wouldn't - once reported it doesn't get sent again unless the error flags are explicitly cleared (as generally repeatedly reporting it just compounds any overflow issues).
I'm not sure of the rationale for executing each line as it uploads - I can see that any setInterval could fire for a function not yet defined
Basically on a microcontroller you haven't got a whole bunch of RAM available. If you had to store the whole program in memory and then run it, you'd be extremely limited by what you can get in - you basically need double the amount of memory (one for the text version, one for the version that's just been interpreted).
You can save to flash with
Save on send
and execute from there, but then you don't get the same ability to 'tweak' your code while it's running and then save the state of it (a bit like a PC hibernating).It's a bit of a compromise because we're trying to cram a JS engine into sometimes quite limited microcontrollers - but hopefully when you're used to it you'll find it's worth it!
I could see I was getting syntax error on code I hadn't written - some sort of corruption.
This is almost certainly your code, but with sections missing? Or errors can get thrown from modules like DS18B20 but they're unlikely to be syntax errors.
My laptop is an HP Spectre 360
If it's connected to the Pixl via Bluetooth then you can be pretty sure it's got Bluetooth LE. I haven't heard of cases where BLE is working and connecting but losing some data, so I think given what you've got so far, you're probably fine.
I just tried the code I posted above and it works fine with the DS18B20 between GND and 3.3v.
However, one thing to watch out of is that the OneWire implementation is software-based, and unfortunately the Bluetooth stack has to take absolute priority or the Bluetooth connection will drop out. It means that while you're connected by bluetooth,
getTemp
may returnnull
every so often if Bluetooth has jumped in and messed up the timings. When you're disconnected from Bluetooth it'll work perfectly though - and it's easy enough to work around by just callinggetTemp
again... -
• #14
Thanks again for another comprehensive reply.
I could live with/check for the odd null .. what I'm actually getting now is the '85°c' problem.
I get lots of nulls - then squish my dodgy wiring together and start getting repeated 85°c
I thought it might be farenheit for a while.. but it's not that warm in here .. yet.
And I see on the forums that 85 is a magic numberI have a 4k7 (yellow,purple, red,gold) resistor between 3.3v and Data and the sensor accross D13 and GND
Power 3.3v is applied to pin3 (not parasitic mode)I think this is as per your example page - but maybe I misread somewhere
-
• #15
Could you just double-check the 3.3v connection? It should be 2nd or 4th from the end of the Arduino connection : http://www.espruino.com/Pixl.js#pinout
You don't actually need the 4k7 resistor now (we use the internal resistor in software) but it won't hurt.
85 is the magic number you get when the sensor has just initialised - which is what you might expect if it wasn't powered all the time.
-
• #16
My (dumb) mistake ... I was caught out by the unused pin
First little label - first pin .. WRONG25.9375 C
Hurrah !
What's a software resistor ? - sounds like the kind of thing you send the apprentice down to the stores for - like a long weight, or green oil for the starboard lamp.
1 Attachment
-
• #17
What's a software resistor ?
Using software, the pin is set topull up
mode which connects an internal resistor in the chip ( about 40k ) . Have a look at pin modes in the reference for examples. -
• #18
Thanks ... I have a lot to learn
It seems some JS knowledge helps - but there is a lot more to know.
All good fun. -
• #19
...in deed, it is JS... and that got my excitement going a while ago... and still goes on, even though I just made - at work -a very deep plunge into python - still trying to swim and not to drown (I mean to code and not to err out) ...and there are (micro) pythons similar to espruinos out there... and if power and size is not an issue, raspberry pi is the perfect platform (have to confess - to @Gordon - that I just received my 1st ordered berry... connected it - 3 B+ to display and mouse, and was blown away by it: just works, and a nice Linux is there... had not connected keyboard yet, but still could play a game (reversi). The plan is to use id from now on... as possible Espruino IDE environment and BLE bridge to WiFi / LAN - either with node.js or python... after all, I got that also going on for me...).
I'm just surprised and frustrated the upload mechanism is so fundamentally flawed.
That's kind of an interesting comment... As @Gordon points out, RAM is not there to store and forward and do all the things... so this is what I see happening on upload:
- IDE switches echo is off with a (console) command - actually a JS function - that Espruino interpreter understands (built-in)
- JS expressions are sent (via/through console connection) to the interpreter line by line - expressions can span multiple lines - and as soon as a complete expression is detected, it is executed... after all, it is JS and the receiving end is the interpreter.
- This goes on and on until the all is sent from the IDE to the board, the board has worked trough all expressions and actually built the programs object model, so to speak... almost like html DOM.
- The IDE then waits for a prompt to come back from the board, upon which it turns echo on again. If that prompt is not coming back in time - controlled by a (generous) timeout, or instead the control some out put comes back and confuses the IDE, then upload sequence (and switching between command and upload mode and back) falls apart... (except you do the save on send as hinted by @Gordon. Regarding the time-flakiness, matter of fact if the band-width is used up (by nose or other communications - as I read in another forum post) there is nothing that can be done to get connections right away and throughput, no matter how fast frequency hopping happens. It's almost like not having enough access points and no ip is received and no connection setup happens... and the intendedly built-in timeouts let as (at least) know about.
You can see that by using arrow up after an upload: echo on and sent program come 'up'... that's also why after an upload you cannot get easily back to your last console command... @Nickax, keep sharing the pit falls we so glaringly glance over... RTM - Read The Manual, and more timely - WTY - Watch The Youtube can not be skipped to get the best out of any situation...
No doubt, I can say for me - and @Gordon as well? - that we enjoy your excitement... it is received as rewards... no kidding: it spars to get and do even better than already good.
- IDE switches echo is off with a (console) command - actually a JS function - that Espruino interpreter understands (built-in)
-
• #20
Hi again
Just to repeat that the thing that solved it for me was the 'throttle send' option in the communications section of settings.
All (well, most) of the problems melt away once it actually runs the code you send.
Interestingly - I was also able to go back to the original code sample - with the require() up-front, and it worked just fine.
I think the lesson here is to rule out the simplest causes first.
The real question is why do some people 'experience lost characters' and what is the real fix.
I don't know how common the problem is - common enough for there to be a tickbox.
-
• #21
I have an r-pi ... two in fact - and my experience with those has been equally, if not more frustrating - the plethora of languages and versions - and the sea of incompatible out out of date samples made it more or less impossible to work with.
The elegance and simplicity of Espruino are what drew me to it - JS is NOT my favourite language but a year of writing TypeScript as a day job has softened my hatred slightly. What I can see is that for someone with no prior knowledge it is relatively easy to pick up as it is fairly compact. For someone from an OO background its a more difficult switch.
I have limited spare time so I make the classic mistake of trying to skip the examples and videos - but I will try and avoid that temptation and get a better understanding of how it all works.
-
• #22
the thing that solved it for me was the 'throttle send' option in the communications section of settings
That's great - but you should be aware that it hasn't solved the underlying problem, so at some point you might have code that takes a lot longer to execute, and that'll cause you similar issues.
It's good to hear what issues people hit when they just dive right in. I'll see if I can find a way of making the Web IDE detect common errors on the left-hand side and offer advice (eg. 'try this on the right-hand side, or do you want to upload the module?')
The upload issue is unfortunate - on the USB-based boards there's flow control within the USB com port, so lost characters really aren't a problem. However the Bluetooth LE UART implementation doesn't have any flow control. That's rarely a problem since the transfer rate is pretty slow, but in some cases (which you just hit!) one command will take long enough to execute that it's still enough to cause problems.
I'll see if I can get some flow control implemented for the uploads on top of Bluetooth for the next version though, which should avoid issues like this.
-
• #23
Just to add - new versions of Espruino do implement
class
- so if you're coming from an OO background it might be a lot more friendly for you. -
• #24
Thanks
-
• #25
...JS is NOT my favorite[...] What I can see is that for someone with no prior [JS] knowledge it is relatively easy to pick up as it is fairly compact. For someone from an OO background its a more difficult switch.
...oops - or - OOPSLA/ECOOP - SIGPLAN... ok, my favorite is BD or ME... but I'd not like to explain (those or myself). Any language I can express myself in and makes my vis-a-vis to get me, is my favorite (for communication) - and of course, fluency (and walking the mile in my vis-a-vis shoes) is on me. All the rest is the pic(ture) in my head - and (unfortunately), when that pic is messed up, no language ever solved it for me.
When it comes to JS, I'm not thinking flow or structured - from flow or structured languages - but OO and Lambda - and that's the (language) pic(k) in my head (hence my screen name). In the end, hybrid is what the world is made of for me - and sometimes a elaborate concepts and their tool are just plain overkill. Under the gun of limited resources - space AND cycles - JS has for me in an optimized way what I need and Espruino HW gets me... most of the time. After all, JS is the language @Gordon made for and taught his babies - I don't mean the real one(s)... I have a sone named Pascal, but that did't help much: he skipped that part, which was my 1st love... ;-)
I know that green thumbs help with gardening, but I don't what kind of color thumbs help with programming MCs. Something is for sure: when TS will blow my way, I know where and from whom I can get professional help.
If you still find some time, take a (reading) look at Man a Machine
Hi Gordon
I've recently purchased a Pixel JS for a specific project
I'm converting a minibus to a campervan - and want to run (temperature control) the fridge (off a UPS) , Switch the Inverter out as the fridge starts, Run hot and cold water pumps (mix), and pumps to scavenge waste heat from the exhaust to heat water.
I'm not having the greatest user experience with the Pixel .. the latest in a line of frustrations is that it doesn't appear to find any of the 'requred' modules
here's the output - using a one of your simple examples
I haven't updated the firmware - as I hoped that as shipped it might be able to run such a simple example.
I'm sure i'm doing something stupid
I have had the flashing LED example working
I'm using the native IDE on a Windows 10 Machine
My module extensions are set thus:-
Module URL
Where to search online for modules when
require()
is usedhttps://www.espruino.com/modules
Module Extensions
The file extensions to use for each module. These are checked in order and the first that exists is used. One or more file extensions (including the dot) separated by
|
.min.js|.js
Hope you can help put me on track
Nick