-
Just an update on what you can expect:
- The connection to WiFI is 115200 baud - so around 11k bytes a second absolute maximum
- There's a few characters overhead when sending data, and then there's a bit of a handshake so Espruino can't be sending data all the time
- Websockets add some overhead too
- You're sending ~80 bytes of JSON by the look of it? at 60fps that's around 5kB/sec but not including any of the overheads.
- The connection to WiFI is 115200 baud - so around 11k bytes a second absolute maximum
-
Yes, I imagine every 16ms is too quick, and likely the data is just getting buffered until you run out of memory.
It's a difficult one - it is possible to actually look at the internals of the socket connection and see how much data there is in the buffer, but personally I'd say just back off a bit until you get something that works reliably. Obviously if you've got the buffer even at all full then that's data that is being delayed from being sent - so having slower data is better than having fast data that's out of date.
Also - try sending the data as binary, or at the very least change the existing JSON so you sent a
a
field rather thanacceleration
and so on - which should reduce the amount of bytes that need to be sent.As for the pause, I don't know what to suggest - maybe blink an LED each time Espruino takes a reading so you can see if it's the Espruino or something else that's causing the delay. Espruino's GC is called very rarely, and is designed to be super-fast (it should be well under 2ms) so you shouldn't notice it at all.
-
It'll only happen for you if the board is powered from a PC (so there's an active USB connection) - if it's powered from a USB wall supply or any external power then it won't be a problem.
You can move the console to something like Loopback with
LoopbackA.setConsole(1)
- but you probably want some way to move it back withUSB.setConsole()
when you want to interface to the device.Of course the other option is just to do
console.log = function(){};
- but if there are other prints (for example exceptions) then that is capable of filling up the buffer as well. -
It's not just that code that's running if you're getting that error.
As it says, it's to do with I2C. It happens when you're trying to access an I2C device that isn't connected. I guess somehow you have still got the other code running.
Are you sure that is all you're uploading?
If the MPU6050 is still connected then you'll need to check your I2C wiring as well - that could explain a lot.
-
Have you read that quick start guide I've linked above? I think that would answer your questions.
Just want to clarify if following your instructions
You do need to upload as well.
- Copy code above to right hand side of IDE
- Connect to Puck
- Click the
upload
button - Go to left-hand side
- Type
save()
Then the code will run, but will also be saved.
If code saved then there's a way to clear the code or modify after save() action?
You can easily just connect and modify it right after, but in some cases (not the code above) you might be able to do something that stops you from logging in.
In that case, see this: http://www.espruino.com/Puck.js#i-saved-some-code-and-my-puck-js-no-longer-works
- Copy code above to right hand side of IDE
-
Please ask on the ESP8266 section of the forum. That's what it's for.
-
-
Thanks! Yes, I think those probably make more sense given the number of pixels. I'll add that font in now (as
Font4x8Numeric
)For anyone who is interested in trying stuff like this, here's the code I used to make the font:
var font = ""+ "### "+ "# # "+ "# # "+ "# # "+ "# # "+ "# # "+ "# # "+ "### "+ " # "+ " # "+ " # "+ " # "+ " # "+ " # "+ " # "+ " # "+ "### "+ " # "+ " # "+ " ## "+ "## "+ "# "+ "# "+ "### "+ "### "+ " # "+ " # "+ " ## "+ " # "+ " # "+ " # "+ "### "+ "# # "+ "# # "+ "# # "+ "### "+ " # "+ " # "+ " # "+ " # "+ "### "+ "# "+ "# "+ "## "+ " ## "+ " # "+ " # "+ "### "+ "### "+ "# "+ "# "+ "### "+ "# # "+ "# # "+ "# # "+ "### "+ "### "+ " # "+ " # "+ " # "+ " # "+ " # "+ " # "+ " # "+ "### "+ "# # "+ "# # "+ "### "+ "# # "+ "# # "+ "# # "+ "### "+ "### "+ "# # "+ "# # "+ "### "+ " # "+ " # "+ " # "+ "### "; var fdata = ""; for (var col=0;col<font.length/8;col++) { var i = (col&3)+((col&~3)<<3); console.log(i); fdata += String.fromCharCode( (font[i ]==" "?0:128)| (font[i+ 4]==" "?0:64)| (font[i+ 8]==" "?0:32)| (font[i+12]==" "?0:16)| (font[i+16]==" "?0:8)| (font[i+20]==" "?0:4)| (font[i+24]==" "?0:2)| (font[i+28]==" "?0:1)); } // ... g.setFontCustom(fdata, "0".charCodeAt(0), 4, 8);
As it happens I forgot that the font data is column-ordered. If I'd originally made the characters at right-angles to where they are, the code for it would have been amazingly simple.
-
I was just doing a video
showing how to display realtime YouTube video views on a 32x8 LED display, and I was having some difficulty fitting any number above 100k on the display with the normal 8 pixel high font (which is also basically 7px for most characters).It struck me it'd be really handy to have a proper 8 pixel high number font that fitted into 3 pixels wide (4 pixels with a gap), so I've sketched up what's below. What does everyone think?
I'm not a big fan of 6, 8 and 9 - any ideas how to make them better? @jose1711 ?
"███ " "█ █ " "█ █ " "█ █ " "█ █ " "█ █ " "█ █ " "███ " " █ " "██ " " █ " " █ " " █ " " █ " " █ " "███ " " █ " "█ █ " " █ " " █ " " █ " "█ " "█ " "███ " " █ " "█ █ " " █ " " █ " " █ " " █ " "█ █ " " █ " "█ █ " "█ █ " "█ █ " " ██ " " █ " " █ " " █ " " █ " "███ " "█ " "█ " "██ " " █ " " █ " "█ █ " " █ " " ██ " "█ " "█ " "██ " "█ █ " "█ █ " "█ █ " " █ " "███ " " █ " " █ " " █ " " █ " " █ " " █ " " █ " " █ " "█ █ " "█ █ " " █ " "█ █ " "█ █ " "█ █ " " █ " " █ " "█ █ " "█ █ " " ██ " " █ " " █ " " █ " "██ "
I'll cope up with some code to create a font from this later - it's just convenient to be able to post stuff on the forum so we can see/edit them easily.
-
Ok, thanks for giving that a go. It's difficult to track down without having an MPU6050 here (it's a contributed module).
If you uncomment the
console.log
, how quickly is it being called?It'd be interesting if you could compare
getTime
before and after the call indmpLoop
, to see if the function call is actually taking the majority of the time or not.If you're able to change the module yourself, I think the while loop in this line: https://github.com/espruino/EspruinoDocs/blob/master/devices/MPU6050_DMP.js#L121
should be removed, and the check moved into the
if
statement above.My hunch is that the interrupt line is maybe getting pulled low for reasons other than the FIFO having data, and that's causing it to enter the
getData
function and then get stuck polling for more data. -
Hi -
Serial
is a built-in object, so by setting it toSerial1
you're probably causing yourself a lot of trouble. Try the following:var serial=Serial1 USB.setConsole(true); serial.setup(9600); serial.on('data', function (data) { console.log(data); if (data==='1'){ LED1.write(1); serial.print("test\n"); } if (data==='0'){ LED1.write(0); } if (data==='d'){ LED2.write(1); serial.print("sensor: t="+temp_act+", p="+press_act+", h="+hum_act); LED2.write(0); } });
Using
Serial2.setConsole
should work, but I'd setSerial2
up first or it'll use the default pins. Personally I'd useUSB.setConsole(true)
(as above) because then the console is still available on USB for updating code. -
To do that, they would have to physically connect a debugger device to it - and you have the same problems you would with any microcontroller.
One method is to simply check the chip's serial number in your code.
You can also turn on 'read-out protection' on the chip? Are you using Puck.js, or one of the other Espruino boards? The method for doing that would be different on different chips - it's off by default because it can make it more likely you'll make your chip unusable during development.
-
You can add a password or move the interactive console away, which will stop any casual reading of the code. Your code is stored as source but is fragmented all over memory so is still pretty garbled and would be hard to read out.
However if you then also turn on minification your code will be made pretty much unreadable. You could even use a javascript obfuscator. Add that to the way the code itself is fragmented around the memory space and it's very difficult to read out, and even when you do the result doesn't make much sense. I'd say it's on a par, if not more difficult to reconstruct than compiled code now.
-
-
-
What happens when you type
save()
that means that you need to re-update the firmware? Updating the firmware won't actually delete your saved code so I wonder what's happening.Try uploading this code:
var kb = require("ble_hid_keyboard"); function onInit() { NRF.setServices(undefined, { hid : kb.report }); setWatch(btnPressed, BTN, {edge:"rising",repeat:true,debounce:50}); } function btnPressed() { kb.tap(kb.KEY[" "], 0); }
from the right-hand side, and then type
save()
on the left-hand side. I'm sure this works just fine on 1v92. -
-
Take a look at http://www.espruino.com/Quick+Start#start-writing-code- - or in fact a lot of the other tutorials mention it as well. You just type
save()
on the left hand side of the IDE when your code is working, and it will be saved to flash.You might also want to execute something when power is applied - for instance the
setServices
command - so just do that inside anonInit()
command.And no - you can't emulate a keyboard over Wifi, so you'd have to do something completely different for the Espruino Wifi, writing some software for your PC that would communicate with Espruino over the network connection
-
The firebase js file is 360kB, and most Espruino devices have in the region of 50kB available RAM, so there's no way you can use the lib directly. It sounds like you might be trying to use just a bare ESP8266? In that case you'll have even less memory available.
Potentially you could try to use tree-shaking tools to strip out the bits you're not using, but I think this is more effort that doing it directly, and you're very unlikely to get it small enough that you could run other code as well.
-
As for WiFi, I have this: http://www.espruino.com/WiFi
But not in the Puck.js form factor - WiFi just uses too much energy for it to be possible to run it off a coin cell for any sensible length of time
-
Unless you type
save()
, all the code that was running on Puck.js will be lost - so I think that was your problem initially when you removed the battery. It's worth reading http://www.espruino.com/Quick+Start#start-writing-code- for an intro, and how to write code that runs at startup.What drivers did you reinstall? Puck.js should need no drivers, so all I can assume is that it is the drivers for your Bluetooth LE dongle that Windows is complaining about?
However the 3 LEDs lighting up points to some problem in Puck.js's software. It's most likely related to bonding.
When you do manage to connect, please could you run the following code on Puck.js:
var f = require("Flash"); for (var i=119;i>=115;i--) { print(i); f.erasePage(i*4096); }
That should clear out any saved code, along with the bonding information - which will hopefully return it to normal and fix the 3 LED lighting issue. I'm hoping to try and fix that properly in a later release, but am having trouble reproducing it here, and it seems to be an internal issue in Nordic's software libraries :(
-
I have a post here, which is what I've been using to detect movement:
http://forum.espruino.com/conversations/301185/
By default it measures the magnetic field at 0.63Hz, which keeps the wakeups to a minimum while still being fast enough to detect movement pretty well.
Hope that helps!
-
-
Thanks - I think on normal Espruino boards it could be added just fine without too many issues with memory. There's actually an issue open for this here: https://github.com/espruino/Espruino/issues/504
I'll see what I can do - which board are you using?