-
I was looking at the datasheet for the accelerometer in the bangleJS2 and was wondering about the magnitude range that is available.
https://www.espruino.com/datasheets/KX023-1025.pdf
I see there is a +/- 2, 4, and 8g sensitivity setting that is 'user selectable':
"Resolution and acceleration ranges are user selectable via I2C or SPI." (I don't know much about these protocols)
But I am wondering how / if we can interact with that through the API and also what the 'default' setting is.
At the moment, through experimentation, I haven't been able to produce a reading above 5.65 g's (total magnitude). I could see that reading coming from a combination of axes though, which leads me to think the accelerometer is in 4g mode, however it is possible that my timid nature / feeble physique are imposing the limit here, not the sensor (lol)
EDIT: I may be finding what I need over in
https://github.com/espruino/BangleApps/blob/master/apps/accelrec/app.jsUsing deduction, it seems like you CAN change those things with accelWR, the default is 4gs, and you just need to find the right numbers in the datasheet that correspond with the setting you want to change. I actually think I have what I need - just have to review the data sheet in more detail.
EDIT: again. I think I have everything I need. Thank you Espruino forums for being a rubber duck for me :)
So here's the D/L for anyone else that comes by.
The default is definitely 4g's. You configure the accelerometer by writing to these eight bit binary numbers called "registers". The two important registers in the manual I referenced are called "ODCNTL" and "CNTL1". References for these are on pages 40 and 44 of the manual.
Once you change the sensitivity of the sensor, your magnitude numbers from bangle will either be 0.5 at rest of 2.0 at rest (instead of 1.0), so correct for that accordingly.
My goal was to measure peak throw acceleration, but I think humans can pull of 10's of g's when throwing objects so I might be out of luck with even the 8g setting.
-
So actually I may have solved my problem entirely, but I'd be happy to hear from people as to why I solved it, because I think I Maxwell Smart'ed / Mr. Magoo'ed my way through it.
The code I am running now
Bangle.setUI({mode: "custom", btn: () => { Bluetooth.println(""); Bluetooth.println(JSON.stringify({t:"info",msg:"Hello World"+getTime()})) console.log("HELLO"); }}) function GB(argumentados) { g.clear(); g.drawString(JSON.stringify(argumentados),0,0,true) }
with the android integration uninstalled works PERFECTLY. I noticed that in the android integration there was a random looking
Bluetooth.println("")
hanging out above thesend stuff to gadgetbridge
code so I added that to mine, and that made it work. TAH DAH.I get the info popup every time on the phone. I get the simulated notifications from GadgetBridge drawn on the screen. It's magnificently simple. I'm very happy.
Edit: okay it's not EVERY time I press the button that I see the toast message, but it's like 80%. Which is good enough.
-
However, when checking the log it does show multiple presses. So it does seem to be receiving them from the bangle, just not showing them in Android every time.
Thanks for confirming. This is sort of what I suspected. Like maybe android is debouncing them somehow to avoid spamming the end user or something.
For Bluetooth print line you shouldn't need it, but I could be wrong.
Yeah that's what I thought but it doesn't seem to work at all if I uninstall the android integration app from the Bangle. Admittedly I am in a little over my head with this right now, but will probably understand it better after learning a bit more about how everything works.
I agree that simple transmission seems to work without the app on the Bangle side, but gadget bridge doesn't seem to acknowledge them (even once, like when the app is installed). I'm guessing there's something in the integration app that might facilitate that.
-
Hey folks! Have been fiddling with the integration aspect of my BangleJS and have been struggling a little bit to figure out what's what. I have been following this:
https://www.espruino.com/Gadgetbridge
I installed the bangle version of gadgetbridge on my phone, then installed the android integration on my BangleJS (not 100% sure if this was required for transmit only, but I did it anyway).
Then I loaded this code into ram in the web IDE:
Bangle.setUI({mode: "custom", btn: () => { Bluetooth.println(JSON.stringify({t:"info",msg:"Hello World"+getTime()})) console.log("HELLO"); }})
disconnected from the web IDE, then connected to GadgetBridge. I then hit the side button on my watch, and saw the little info toast pop up on my phone. Wohoo! Then I hit the button again... Nothing! Strange.
I hit the button a few more times over the course of about 10 minutes and it seemed to work maybe once or twice more. I proceeded to disconnect from gadgetbridge then reconnect, hit the button again, and it works again - but only once.
Wonder if anyone with a little more familiarity with these things could weigh in.
- Is this unexpected, or am I doing something wrong?
- Did I actually need the full android integration app with all the message and message icon dependencies to send info messages to the phone? (It didn't seem to work before I did that, but the integration app only mentions receiving messages, not sending them.)
My interest right now is just getting the most minimalistic possible setup and get a little bit of hello world data to reliably go both ways, even just to log it to the console.
- Is this unexpected, or am I doing something wrong?
-
I am working on an app where it makes sense to immediately turn off the LCD screen backlight after the user has touched the screen. I have found ways to do this, but only with side effects, so I was hoping someone might be able to point me in the right direction. Here's what I've tried:
Bangle.setLCDPower(false)
: This turns off the backlight temporarily like I want... but also turns off the sunlight-readable display forever unless I turn it back on. Not really what I want. Just want to hit the backlight.Bangle.setLCDBrightness(0)
: This turns off the backlight! Yay! ... forever. Boooooo.
I am hoping to just say "Hey turn off the backlight right now, and otherwise continue operating like normal".
One possible solution I thought of, but seems a lot more hacky than it should be is:
const prev = Bangle.getOptions().backlightTimeout; // record current setting Bangle.setOptions({backlightTimeout: 1}); // Timeout to 1ms setTimeout(() => Bangle.setOptions({backlightTimeout: prev}), 100); // resume previous setting
Is that the best way to do this right now?
-
I am running default apps on my Bangle right now - I do have one custom app I am working on, but it doesn't interact with bluetooth.
so you think without the Logitech keyboard it all works? To be honest it sounds a lot like a Bluetooth driver issue on your PC.
Yeah if I turn off the logitech keyboard everything works perfectly - and it only needs to be off at the moment the bangle connects, then I can turn it right back on. I'm interested in the idea it might be something with the bluetooth driver on my PC. I have a couple other bluetooth devices - a keyboard, a camera, and some speakers (all are typically disconnected). If the same issue does not happen with them it might suggest its specific to this keyboard. I'll also see if there are any driver updates out there.
Utimately, the issue is very small for me now - it's extremely easy to work around, just a flick of a switch and then back one second later. Happy to help with additional diagnostics but just want to make sure the lack of urgency on my end is clear.
Edit: Ooh I can also try with my phone, since that has bluetooth as well - eliminate the PC from the equation. Will report back if I find out anything useful.
-
Edit: Deleted previous content in this comment because I am positive I have found the root cause for myself.
The exact reproduction steps are
Turn on Logitech K380 bluetooth keyboard. Make sure it's paired and connected with computer.
Connect the BangleJS2 to the web IDE or the app loader (with compatibility mode turned off in the app loader)
Send commands through the console (left side) - noting that they work fine.
Send code snippets through the IDE editor to RAM (right side) - or attempt to send data with the app loader - noting that it fails and the connection is lost.
To resolve the issue you merely
Run the app loader in bluetooth compatibility mode all the time OR
Connect the BangleJS2 to either the app loader or the web IDE while the keyboard is turned off. (you can turn the keyboard back on after the initial connection is made)
It seems like some kind of bluetooth interference but I am not familiar enough with the technology to say exactly what could be happening. Some connection parameter negotiation problem / incongruity? It definitely connects either way, it just has issues sending data (MTU related?)
-
I am using chrome on windows 10 with both the web IDE, the app loader, the unofficial forked app loader with my in-progress apps, and sometimes the chrome plugin version of the web IDE.
So far the issue only seems to appear when I have already connected at least once. I intuitively suspect it has to do with trying to connect to one service after having already connected to another, similar service, but I have not tried systemic reproduction yet. Will comment again if I can get exact reproduction. Will also check the Bluetooth compatibility mode on the app loader.
EDIT:
Another tidbit - when I am using the web IDE, the user interface doesn't even let me choose what to connect to.Found out I had bookmarkedhttps://www.espruino.com/ide/?emulator
and that caused that issue.After a complete reboot of my computer it seems to work just fine at least once in the web IDE. Then, if I disconnect and attempt to reconnect, it fails to upload code chunks, access device storage, etc.
This seems to be 100% predictable based on whether or not I see the word
paired
written next to the bangle device in the web bluetooth selection interface. Reproduction so far only requires a reboot of computer (plus clearing all cookies and site data for the web IDE), visiting the web IDE, connecting to the bangle, uploading code, disconnecting, and reconnecting. -
I always feel a little goofy when I solve my own problems only moments after posting about them on these forums, but apparently I have no problem anymore:
Steps to resolve:
Update and restart computer.
Try exact same thing again.
Note that this time the Banglejs2 device was NOT in the list for connections in the IDE, I had to pick web bluetooth and pair with it again.
Everything just seems to work now. Didn't restart the bangle or anything.
Huzzah!
Edit: A similar, or the same issue has arisen again, this time with the app launcher. I am going to reboot my computer again to see if it still resolves the issue.
<BLE> Device Name: Bangle.js dbad puck.js:408 <BLE> Device ID: mhStQJUeTW1Tlah21FzG+Q== puck.js:408 <BLE> Connected comms.js:231 <COMMS> Ctrl-C gave "" comms.js:278 <COMMS> getDeviceInfo Object loader.js:85 sendUsageStats: Submitting usage stats... index.js:941 Current device time is Mon Jun 05 2023 23:23:04 GMT-0400 (Eastern Daylight Time) loader.js:91 sendUsageStats (200): espruinotools.js:139 Minifying espruinotools.js:139 Minification complete espruinotools.js:139 Minifying espruinotools.js:139 Minification complete comms.js:150 <COMMS> uploadApp: barometer.app.js, barometer.img, barometer.info comms.js:41 <COMMS> reset comms.js:43 <COMMS> reset: got "\u001b[?7l\r\n ____ _ \r\n| __|___ ___ ___ _ _|_|___ ___ \r\n| __|_ -| . | _| | | | | . |\r\n|____|___| _|_| |___|_|_|_|___|\r\n |_| espruino.com\r\n 2v18 (c) 2021 G.Williams\r\n\r\n>" comms.js:52 <COMMS> reset: rebooted - sending commands to clear out any boot code puck.js:408 <BLE> SEND ERROR: NotSupportedError: GATT operation failed for unknown reason. puck.js:408 <BLE> Disconnected (gattserverdisconnected)
Edit: Yes that fixed it again. The issue seems to be associated with whether or not the bangle appears "paired" already in the 'connection' dialogue. I suspect a similar thing is going on between both the web IDE and the app loader.
I notice if I navigate in chrome to : chrome://bluetooth-internals/#devices
I can see my device (DB:AD) and it sometimes shows stuff in the services column and even shows "connected" at times despite not being in the "connected" state in the app loader. Fiddling around with the "forget" and "disconnect" buttons in the chrome bluetooth management tab seemed to eventually get the app loader to work again. -
I hit the post character limit, so here's a little more info about the board:
VERSION 2v18 GIT_COMMIT 7171b2832 BOARD BANGLEJS2 RAM 262144 FLASH 1048576 SPIFLASH 8388608 HWVERSION 2 STORAGE 8388608 SERIAL 366870f4-6dfecf14 CONSOLE Bluetooth MODULES Flash,Storage,heatshrink,crypto,tensorflow,locale EXPTR 485764 APP_RAM_BASE 536882880
And Bangle bluetooth settings:
BLE: Checked Programmable: Checked HID: Off Passkey BETA: none Whitelist: on
Code I'm trying to send to RAM:
console.log("hello world"); Bangle.beep(200,220.00*8);
Additionally, I have written at least one custom app, got the app loaded running in a fork, and uploaded my app on the device, and that all works fine. I did have a few hiccups with connections and loading working initially but restarting the device seemed to fix things. The only issue I'm experiencing is with the IDE upload feature.
-
Hi there! Just got my physical Bangle JS2 device today and have been tinkering, after using the emulator and the web IDE for about a week.
I have been having a couple fishy issues with bluetooth, but this one particular issue has me scratching my head. I hope someone can offer some suggestions! Basically what happens is:
I load up the web IDE, hit the connect button, and select my bangle from the list (it's there!)
Once connected, I send a couple commands through the console on the left of the IDE (console.log, Bangle.beep, etc). Everything works fine.
I take some benign code and put it in the right side:
console.log("Hello world!");
I hit UPLOAD (RAM). It looks like it is trying to do it, but then it says the Bangle has disconnected.
Same thing happens if I hit the little Database icon (view storage). Here's what I am seeing in the developer console for the IDE
Pre disconnect:
>>> BLE configured. Receiving data... index.js:92945 Connected {portName: 'Bangle.js dbad'} index.js:92945 Received a prompt after sending newline... good! index.js:92945 >>> Sending... index.js:92945 ---> "\u0010print(\"<\",\"<<\",JSON.stringify(process.env),\">>\",\">\")\n" index.js:92945 >>> Sent index.js:92945 BT> Received packet of length 128 - assuming increased MTU index.js:92945 >>> Receiving... index.js:92945 Got "< << {\"VERSION\":\"2v18\",\"GIT_COMMIT\":\"7171b2832\",\"BOARD\":\"BANGLEJS2\",\"RAM\":262144,\"FLASH\":1048576,\"SPIFLASH\":8388608,\"HWVERSION\":2,\"STORAGE\":8388608,\"SERIAL\":\"366870f4-6dfecf14\",\"CONSOLE\":\"Bluetooth\",\"MODULES\":\"Flash,Storage,heatshrink,crypto,tensorflow,locale\",\"EXPTR\":485764,\"APP_RAM_BASE\":536882880} >> >\r\n>" index.js:92945 >>> index.js:92945 [notify_info] Found BANGLEJS2, 2v18 index.js:92945 Loading https://www.espruino.com/json/BANGLEJS2.json index.js:92945 Board JSON loaded blockly_espruino.js:114 Blockly.setBoardJSON {VERSION: '2v18', GIT_COMMIT: '7171b2832', BOARD: 'BANGLEJS2', RAM: 262144, FLASH: 1048576, …} index.js:92945 Firmware >1.43 supports faster writes over USB index.js:92945 Set Slow Write = false ('Throttle Send'='Auto') index.js:92945 FIRMWARE: Current 2v18, Available 2v18 index.js:92945 Device found {"portName":"Bangle.js dbad"} index.js:92945 [success] Connected to Bangle.js dbad index.js:92945 >>> Connected to Bangle.js dbad
And then this additional content appears in the console after I hit "Send to Espruino (RAM)"
>>> Minifying index.js:92945 >>> Minification complete index.js:92945 Found a prompt... great! index.js:92945 Splitting for reset(), delay 250 index.js:92945 BT> SEND ERROR: NotSupportedError: GATT operation failed for unknown reason. index.js:92945 BT> Disconnected (gattserverdisconnected) index.js:92945 Disconnect callback... {"port":"Bangle.js dbad","portName":"Bangle.js dbad"} index.js:92950 [notify_warn] Disconnected from Bangle.js dbad (anonymous) @ index.js:92950 warning @ index.js:94266 (anonymous) @ index.js:100843 (anonymous) @ index.js:95763 cb @ index.js:92895 (anonymous) @ index.js:131777 cb @ index.js:92893 (anonymous) @ index.js:130080 cb @ index.js:92893 (anonymous) @ index.js:101952 cb @ index.js:92893 (anonymous) @ index.js:100710 cb @ index.js:92893 (anonymous) @ index.js:100609 cb @ index.js:92893 (anonymous) @ index.js:98239 cb @ index.js:92893 (anonymous) @ index.js:94319 cb @ index.js:92893 callProcessor @ index.js:92898 (anonymous) @ index.js:95762 closeSerial @ index.js:96758 btDevice.addEventListener.once @ index.js:96697 closeSerial @ index.js:96751 (anonymous) @ index.js:96782 Promise.catch (async) writeSerial @ index.js:96780 writeSerialWorker @ index.js:95899 (anonymous) @ index.js:95902 setTimeout (async) (anonymous) @ index.js:95901 (anonymous) @ index.js:96779 Promise.then (async) writeSerial @ index.js:96777 writeSerialWorker @ index.js:95899 writeSerial @ index.js:95921 (anonymous) @ index.js:98706 getEspruinoPrompt @ index.js:93244 writeToEspruino @ index.js:98691 cb @ index.js:92895 (anonymous) @ index.js:130010 cb @ index.js:92893 wrap @ index.js:129922 (anonymous) @ index.js:129914 cb @ index.js:92893 (anonymous) @ index.js:129682 cb @ index.js:92893 findBinary @ index.js:130846 (anonymous) @ index.js:130782 cb @ index.js:92893 callback @ index.js:129621 minify @ index.js:129642 (anonymous) @ index.js:129489 cb @ index.js:92893 (anonymous) @ index.js:102993 cb @ index.js:92893 findASMBlocks @ index.js:102649 (anonymous) @ index.js:102548 cb @ index.js:92893 compileCode @ index.js:102162 (anonymous) @ index.js:102049 cb @ index.js:92893 loadModules @ index.js:99117 (anonymous) @ index.js:98953 cb @ index.js:92893 callProcessor @ index.js:92898 getEspruinoCode @ index.js:95472 (anonymous) @ index.js:100593 ensureConnected @ index.js:100852 click @ index.js:100589 index.js:92945 >>> Disconnected from Bangle.js dbad
Any ideas of what I might be able to try?
-
Been working on an app - just finished it. Well, two apps, a keyboard and a reminder thingy.
Anyway, keyboard uses
drag
events to get input, app takestouch
inputs. Keyboard returns a promise which eventually resolves with the typed text. Works great. Only issue is what I think is the following race condition (determined with super high tech debug strategy console.logs):- User submits their text input using a drag gesture (on release,
b == 0
) - Promise resolves. Keyboard is unloaded.
- App receives text, applies it, renders appropriate UI and menu
- Lingering
touch
event caused by the same finger motion that resulted in event #1 resolves - App presses whatever button is now under where the user's finger was in step 1, leading them to a different menu or input than intended.
I can solve this pretty trivially by adding like a 50ms timeout between the user drag input release and the promise resolving, but I was wondering if anyone else has run into this issue?
I'm wondering if there's a potential enhancement out there to clear unresolved events when
setUI()
or equivalent is called, so that you don't have a bangle input event that starts while one UI is loaded and resolves when another UI is loaded.EDIT: Another viable workaround might be to have submit operate on the 'touch' event instead. Might be a little cleaner than a setTimeout but less obvious to the reader.
EDIT: EDIT: Found this potentially relevant-but-not-precisely-identical github issue.
https://github.com/espruino/BangleApps/issues/2754#issuecomment-1547357991 - User submits their text input using a drag gesture (on release,
-
-
The impetus for me searching for a smart watch was to create a prosthetic device to treat the working memory portion of my ADHD symptoms.
The idea is to be able to type in what I want to be doing immediately when I decide to go do it. Then the watch will vibrate and remind me at set intervals (thirty seconds, one minute, two minutes, something configurable, maybe with incremental backoff) of that task.
For example, I might be standing in my bathroom upstairs and notice that I'm hungry, but between the time I say "I'll go make a bowl of cereal" and the time I arrive in the kitchen I am totally sidetracked by something else. Sometimes I don't even make it to the intended part of the house, and I won't remember that I need to eat for another hour or more.
I'm thinking if I can have something on my wrist that will let me IMMEDIATELY externalize my working memory then I can have a constant tactile reminder of my intention. That's why I'm emphasizing entry speed and de-emphasizing character breadth for my input, because I could type "brkfst" or "car" or "laund" and that would be sufficient.
There's more to the app than just that, I'm also planning to create a task queue system and a re-prioritization feature where you can put an incomplete task on the back burner if you actually need to switch gears. Other features bouncing around in brain as well but it has fallen into the background while I wait for the device to come in.
There are devices out there that do this (https://reminderwatch.com/) but most of them are at similar price points with significantly reduced flexibility, and many of them focus on repeating reminders that you set ahead of time. Kinda like they are aware of the problem they are trying to solve but not aware of the root cause of that problem.
-
Thanks for mentioning that. I was introduced to the ecosystem only days ago and did not find the existing keyboard libraries! Letting the user select their preferred input method is a great idea.
I may put my keyboard out there for others if I can distinguish it sufficiently from the existing ones. Right now it's similar to the multi-tap keyboard but with emphasis on speed via reduced character set.
Looking forward to getting a device in hand so I can do a better ergonomic comparison between what I've made and what's out there!
-
I think I'm missing something simple with an app I am writing, and my google / ctrl+f skills are failing me.
If I create an event-linked callback, like
Bangle.on('touch', (button, xy) => getTouchedKey(keys, xy, resolve));
Is there some way to clear that callback from triggering on touch? I tried making a call to
Bangle.on('touch', () => {});
but that seems to just add another callback to the event watcher.
Basically I am popping up a keyboard that responds to touch events, but when the keyboard promise resolves I want to return to a previous UI state. Instead I end up with an invisible keyboard over the previous UI.
Happy to either get an answer here or be directed to the appropriate documentation if it's out there!
EDIT: I may have found what I am looking for? In the documentation for Bangle.setUI there's a quote:
While you could use setWatch/etc manually, the benefit here is that you don't end up with multiple setWatch instances,
So maybe I need to just figure out how to do this with setUI and that will resolve my problem.
EDIT: Yes, that did it. I'd like to thank the community for bearing with me while I talk through my problems out loud, :D
For posterity:
Bangle.setUI({ mode: "custom", touch: (button, xy) => getTouchedKey(keys, xy, resolve) }); ... later... Bangle.setUI(undefined);
-
I'm [trying] to measure hand speed when you throw disk or ball,
If I am throwing a frisbee, the actual throw probably takes place over a quarter second or less. The acceleration due to the throw could be multiple orders of magnitude greater than gravity.
I have heard quotes that a frisbee throw can involve instantaneous force vectors of 150 times the force of gravity. If you just ignore any data point where the accelerometer is reading a vector with a magnitude less than 10 Gs, and then don't even bother to account for gravity, you will probably be able to end up with less than 5-10% error overall compared to if you did account for gravity (which also might not be perfectly accurate, but that's a different problem).
https://www.youtube.com/watch?v=x4wnbKYfPLs
On top of that, if you have a magnitude limit, you can throw for 30 minutes and end up with only like 10 seconds of actual data that you need to save.
Hey Folks, I am starting on a project that will involve my BangleJs2 and I am wondering if people out there with a little more bluetooth experience than myself might be able to help point me in the right big-picture direction.
I own a Nikon Camera with "built in" wifi that can only be activated by the proprietary snap bridge mobile app software. I can actually connect to bluetooth on my camera with other kinds of devices but the camera is expecting a certain kind of communication to be opened, so it immediately fails in its sort of little proprietary connection dance.
What I was hoping to do was to write a little utility to mimic the wifi startup signals that my phone blurts out when I try to connect to the camera with snap bridge, and to do that I was thinking maybe there would be a way I could eavesdrop on that conversation as it happens so I can understand what's going on a little better. The Bangle2 seemed like an easy platform to use to poke around in that area.
Ideally I would like to end up with a little software button on my bangleJS that I can press to turn wifi on on my D500 so I can use that wifi connection for other things.
I'm wondering if anyone has tried something like this - like the bluetooth mimicry / eavesdrop thing with Bangle before, or if I'm totally off my rocker if people had alternative suggestions for achieving what I am trying to achieve.
Like maybe I need to do it step by step and just have my bangle pretend to be my camera and see what my smartphone says, and then pretend to be my smartphone and see what my camera says, and do that back and forth until I figure out what's going on.
EDIT: It turns out that a later firmware version exposes this functionality right on my camera - rendering my bangle software button hyjinx obsolete / moot. I would delete this post but I actually don't know how, so here's a monument to my impulsive posting habits.