-
Good thing that things like the
Puck
object andPuck.light()
aren't yet implemented on RuuviTag (right?), since they make assumptions about how on and off are mapped to1
and0
. One way to mitigate these would be to abstract them:
LED1.write(ledOn);
LED1.write(ledOff);
var buttonState = buttonPressed();
… where
ledOn
,ledOff
, andbuttonPressed()
are mapped to1
or0
in platform specific ways.But those don't solve the problem of running existing Espruino JS apps on RuuviTag. Maybe the IDE could spot things like
LED1
andBTN
, and in the case of RuuviTag, tag the line with an informational icon (not quite a warning).…… answer = 42;
💡 btnOn = digitalRead(BTN);
…… console.log(btnOn);
-
-
@user75202, additionally, if you want to quickly prototype something like this and have a modern Android phone, you could alternatively use
NRF.nfcURL()
.The user would bring the back of her phone right next to the Puck.JS on the fire extinguisher (closer than iBeacon or Eddystone), and the page opens. But, it requires only one line of code to work, and makes for a satisfying demo.
You can see it in action in this 30-second tour of Puck.js.
-
@jtq, I see in your code that you're using
JSON.stringify()
with text as a parameter. Doesn't this usually take a JavaScript object as input? -
-
That code looks a lot cleaner, @countxerox!
Thanks for that advice @oesterle. I've had a go and I think it's improved but I can't close the wifi connection. wifi.disconnect() isn't recognized.
Well, at least it's perfectly OK to call
wifi.connect()
even when already connected according to the docs. And, your callback is called.I wonder why
wifi.disconnect()
isn't working? @Gordon, any idea? -
@Gordon, can you show us some video of these, or at least the black one, and original white, with the LEDs on?
-
Right now, everything lives inside
onInit()
. Can you reorganize your code into separate task-focused functions? That may relieve memory issues, and also make your code more reusable on other projects.I'd try to make
onInit()
focused on just the setup you need to do on power on.You also have a long-lived nest of multiple callback functions. I'd pull the connection and sending out into a separate function that's called every 2 minutes. In that function, I'd also turn off Wi-Fi when done sending. This is good practice for IoT sensors that you intend to battery power, also.
Finally, you'll still probably have rare occasions where connection or sending fails, but these should be less frequent.
-
Can you post your source?
Serial
defaults to 9600 baud. I'd first try setting up Serial at 57600 or 115200 baud, likeSerial1.setup(57600, {rx:B7,tx:B6});
(where B7 and B6 are the pins you're using).Serial1.pipe()
might be another option, but I haven't played with that.Next, sending chunks on an interval would probably work, but isn't the most efficient or robust, since you are depending on the receiving Pico always being ready on time for the next chunk. Which it might not always: sometimes it may have another task on its plate.
A somewhat more robust, brute force method, is to do your own chunking. Instead of waiting a fixed interval between chunks, you send a chunk, then wait for the receiving device to send you an acknowledgment. Then you send the next chunk, etc. Before all this, you send something like
sending 152\n
, where 152 is the number of chunks you plan on sending. That way receiver knows when it's done. (Serial1.pipe()
probably does exactly this, internally.) -
Awesome, @Gordon! Is there a way to guess which CI builds contain something emerging like this? (I certainly don't want to create another documentation task. :-D )
-
@user75010, If you are just talking test, you can instrument your C code with something like a very lightweight serial command line. For example, CmdMessenger is an Arduino C++ library that enables you to exercise compiled C(++) functions (with or without arguments) via serial connection. CmdMessenger on GitHub
-
Is the build not finding protobuf (Google Protocol Buffers)?
pkg_resources.DistributionNotFound: protobuf
-
Nice, thanks! How does the hue work? Blue->red rainbow colors?
Yep.
t.hexToColor = (hexChar)=> { var hue = parseInt(hexChar,16) / 16; var rgb = hueToRGB(hue); return rgb; };
The colors are a nice "visual hash" of the Puck address.
It's annoying that I don't have control of the Web Bluetooth device listing, because then I could put the 4 colors next to each Puck in the list!
It would still be useful to find a way to put the address of the currently connected Puck in the IDE. Puck address colors would be very cool. When working with multiple Pucks (I got your 5-pack on Kickstarter), I lose track of which one is connected in the IDE.
-
Was just about to suggest WebSockets as a possibility. There's an Espruino WebSocket module.
-
Not sure. But I know the converse is possible: you can write libraries in C, and expose methods as JavaScript objects and functions.
When you build Espruino, the build scripts scan your C code for
/*JSON{…
comments, in which you describe the mapping between C and JavaScript.Some of that is documented here:
https://github.com/espruino/Espruino/blob/master/libs/README.mdI'd also suggest taking a look at the C source of Espruino's built-in libraries, like Math, to see actually working examples.
-
-
Wow. OK, then! Sorta cool when you code something up, and it runs on someone else's hardware the first time. Cheers, @countxerox.
-
I just got a chance to try this - looks nice!
Thanks for taking a look, @Gordon!
I guess for something pre-installed, people won't actually see any of the text that appears (initially) - and when they get to that point they could easily have loaded up your code themselves.
True that. Still, it's nice to see something more than that red flash on battery insertion.
(just an aside, but if I added https://www.espruino.com/ide/#code_url_here it could be really helpful for posting up code?)
I'm not sure what you mean.
So I'm wondering what we could do 'out of the box' - when you first insert the battery and do nothing else - that would be fun, and that didn't drain the battery for those that turn the Puck on and then just leave it (including if they put it in a bag and the button kept being pressed).
I do put a lot of stuff to sleep after 20 seconds right now, until the next button press. Maybe I could be smarter about detecting unintentional button presses. Hmm.
The rainbow is nice, and maybe it could detect rotation using the magnetometer.
YES. I'm totally thinking along the lines of making it more playful before connecting to an IDE. I'm going to fork this, and make something more of a game.
Perhaps it could flash out rainbow colours in 4 groups of pulses, where the number of pulses corresponded with the Puck's MAC address that was displayed when advertising?
Or maybe it just maps each hex digit to a hue, and does a 4-color sequence unique to that Puck. More quickly recognizable.
It'd be nice to it to be able to connect to Pucks that are very close (high signal strength) and make them flash or something - but I think in a classroom environment that would just be more annoying than anything else :)
I'm thinking of a separate program that enables you to select a nearby puck, and say "hi".
I guess after an hour of not being used it could just completely clear itself so it went back to not using much power?
Perhaps a long press of the button does a
reset()
. Or a long press followed by a short confirmation press. Maybe a super long press ("Help, I'm trapped under books in a backpack!") is detected and basically ignored. -
I'd try breaking
sendForm()
andbh.read()
out of thedht.read()
callback. Not sure if that will help, but it might relieve some memory shortage. Untested code:// global vars up near the top var lastTemp = ""; var lastHumidity = ""; var lastLight = ""; function sendSensorData(){ sendForm(lastTemp, lastHumidity, lastLight); } // ........ // further down, in place of your setInterval() section setInterval(function() { lastLight = Math.round(bh.read()).toString(); dht.read(function (a) { lastTemp = a.temp.toString(); lastHumidity = a.rh.toString(); // let's give Espruino an opportunity to do housekeeping // before sending our form setTimeout(sendSensorData, 5000); }); }, 60000); // once a minute
-
@Robin, @OwenBrotherwood: Yeah, maybe a 3.3v buck converter like this:
https://www.adafruit.com/products/1066…plus a USB 5v 1A battery pack.
I've made this to replace the CR2032 on Puck.js with AA batteries:
-
Very cool, @OwenBrotherwood! Laser cutting the wood, I see!
-
I had some ideas for improving the robustness of your code, and forked your gist.
- Ensure BLE is turned on when Puck is powered on or battery is replaced.
- Ensure mag turning off doesn’t happen in the middle of presenting.
Puck.magOn()
doesn’t return a Boolean to check if on/off; added code to
fix this.- Simplified character sending code to remove duplicate code.
- Added catchy keyboard Bluetooth device name. :-)
Feel free to incorporate the changes into your code.
- Ensure BLE is turned on when Puck is powered on or battery is replaced.
-
@OwenBrotherwood, This sensor from Adafruit is small, and will work on a fingertip, or clipped to an earlobe:
https://www.adafruit.com/products/1093It uses 4mA at 5v, and will also run at 3v, with just 3 wires – power, ground, and analog output.
The hardware is open source, and detailed here:
https://pulsesensor.com/pages/open-hardware -
@Gordon, I've cleaned up the code quite a bit, and created a Hello, Puck! repo on Github.
Download and try it out. I welcome y'all's ideas!
It has quite a few convenience functions to make it easier to use the sensors, button, and LEDs.
The idea is, how can we make Puck.js more interesting out-of-the-box, i.e., before it's connected to the IDE.
Hey, @al! I've been following, and love this thoughtful project.
True that the cables give more freedom on where to place the board, in the Seeed Studio / CoolComponents EMG sensor. However, I'd also read the excellent tech notes/datasheets on both:
Note that the MyoWare device has some good recommendations on placement of electrodes that should also apply to the Seeed Studio device. Additionally, the MyoWare device has an on-board gain potentiometer – Seeed Studio's does not.