+++ title = "sensor watch" date = 2022-11-14 template = "article-sw.html" +++ ## preamble some time back I was browsing [Crowd Supply](https://www.crowdsupply.com/) when I came across [the Sensor Watch project](https://www.crowdsupply.com/oddly-specific-objects/sensor-watch) by [Joey Castillo](https://github.com/joeycastillo). I had wanted some kind of "hackable" watch for a while, and had looked at things like [Watchy](https://www.crowdsupply.com/sqfmi/watchy), but this project hit the sweet spot for me. I love my existing F91-W, and this project was a good combination of open source with community software support. one key feature that was important to me is battery life - the Sensor Watch battery life in an average usage scenario is so long that [Joey's is still going strong](https://twitter.com/josecastillo/status/1590066358351298560)! I was excited to pick one up and start messing around with it, but the first issue I came across was availability - the delivery date for Crowd Supply orders was summer 2023 (I think they ended upbeing delivered sooner than this, not sure). on top of this, shipping and import fees made it pretty prohibitively expensive. I've always found this to be an issue with Crowd Supply as someone based in the UK, even some things designed in the UK are very expensive from Crowd Supply as they are assembled in/shipped from the US. so I decided to build one myself! of course, this is more expensive than just buying it, but this was a learning experience and [knowledge is power](https://www.reddit.com/r/AskReddit/comments/dxosj/what_word_or_phrase_did_you_totally_misunderstand/c13pbyc/)! ## component acquisition the first challenge was acquiring all the necessary parts to actually build one. I downloaded [the PCB files](https://github.com/joeycastillo/Sensor-Watch/tree/main/PCB/Main%20Boards) and generated a [BOM](https://en.wikipedia.org/wiki/Bill_of_materials) to figure out exactly what I needed to acquire. I'm sure in ordinary times this would be easy enough, but the current state of some electronics/silicon supply chains had other things to say. some parts are of course still easy to come across, e.g. 10pF 0402 caps and 10k 0603 resistors; most of the components of the Sensor Watch are this kind of commonplace part. what quickly became clear from some scouring of the internet was that my main problem was going to be two parts: the [ATSAML22J18A-MUT](https://www.microchip.com/en-us/product/ATSAML22J18A)(the processor driving the Sensor Watch), and the [FH19C-9S-0.5SH(10)](https://www.hirose.com/en/product/series/FH19C__FH19SC) (the connector used to attach the extra sensor boards). ### ATSAML22J18A-MUT the former of these was a fairly well discussed shortage that had been ongoing for a while. it was [the driving force of the Sensor Watch Crowd Supply delay](https://www.crowdsupply.com/oddly-specific-objects/sensor-watch/updates/blue-boards-shipping-check-your-address-green-boards-delayed-and-other-news-of-the-watch). I spent quite a lot of time searching around the internet, looking at various sites on the English-speaking and Chinese-speaking web. sadly this part was clearly in very short supply, and prices could get pretty insane from vendors that did have some stock. I received quotes for unit prices that include the following (USD/GBP): $79.35, $6.56, $13.61, $6.83 (MOQ 4000), £6.45. I guess some people are desperate enough to pay $79.35 :(. I spent so long looking for them that they ended up randomly coming back in stock on [MicrochipDirect](https://www.microchipdirect.com/). as of the time of writing this article, [they are again out of stock](https://www.microchipdirect.com/product/ATSAML22J18A-MUT). the unit price I bought them for was £3.92, shipping and handling was ~£12. ### FH19C-9S-0.5SH(10) this part was out of stock everywhere I initially looked (the usual contenders for parts). I searched around in a similar manner as the ATSAML22J18A-MUT, and found some similarly wild pricing. I ended up purchasing a small quantity at a unit price of £0.44 from a website called [dacikeys](http://archive.today/2022.11.13-230943/https://www.dacikeys.net/). yes, the site is actually called this. yes, the unit price is cheaper than digikey and mouser. yes, I actually received all of my order, consisting of working parts. I was definitely shocked that this happened, but sometimes bravery pays off I guess. I still can't endorse this shop. ### PCB and stencil for the PCB I opted to go with [JLCPCB](https://jlcpcb.com/). I simply uploaded the relevant gerbers, and adjusted the necessary settings. notably, [the thickness should be 0.6mm](https://github.com/joeycastillo/Sensor-Watch/issues/14#issuecomment-922974276">) - this does narrow the choice of manufacturer (for example, OSH Park doesn't go this thin). I haven't yet ordered any sensor board PCBs, but [PCBWay](https://www.pcbway.com/) seems to be *the* option there. The PCB turned out great, although the silkscreen is a little hard to read at this size due to lack of sharpness: {{ image(path="images/sensor-watch/pcb.jpg", alt="a closeup of a green sensor watch PCB") }} ## assembly I decided to assemble myself. partially because the logistics of paying for assembly when I had to source parts from many different providers seemed like a headache, partially because I thought it would be a fun challenge and learning experience! a few things were necessary to solder the components to this PCB. I'm sure someone talented could hand solder this with an iron, but I can name a lot of things I'd rather do than try to do that (especially the [QFN](https://en.wikipedia.org/wiki/Flat_no-leads_package) SAML) - and that list includes unpleasant things. I opted to go with [hotplate soldering](http://www.flyelectric.org.uk/hot_plate.htm), which is a cheaper way to access the ease of reflow soldering. for a PCB like the Sensor Watch, where almost all the components are on one side, it's ideal. the hotplate I have is the ever-popular [MHP30](https://www.miniware.com.cn/product/mhp30-mini-hot-plate-preheater/), which I run [IronOS](https://github.com/Ralim/IronOS) on. I highly recommend it, it's great! my soldering iron is the iconic [Pinecil](https://pine64.com/product/pinecil-smart-mini-portable-soldering-iron/) (not the [fancy new V2](https://www.pine64.org/2022/07/28/july-update-a-pinecil-evolved/) though :[) which also runs IronOS. nice! ### process the assembly process is as follows: - apply solder paste to the PCB with the stencil. make sure the stencil is really flush and justkind of squeegee it on with a plastic card. I used tape to hold it in place. then carefully removed the stencil, avoiding smudging the paste in doing so. - place components on the PCB. this was by far the most painful part of the whole process. a steady hand is not something I was blessed with, and some of these parts are really small. I used a microscope from Amazon for this, the ample manouverable lighting was a big help. a lot of time and patience is required, but it's very first time doable with no prior experience! simply go through the parts one by one, or by area of the board - whatever you prefer. then pick up the respective part with some fine tweezers, and slowly put in place on the solder paste. thankfully, the paste will lightly stick the component in place once you've done this (it is not knock-proof though!). - carefully (really!) place the PCB onto the hotplate and heat up. keep on until everything seems to be melted, and the components have hopefully been pulled into place. that's the top side done! let it cool down, then move on to the bottom. - time for some hand soldering. the button is pretty small, and very fiddly to do. I found you don't need too much precision, but you have to be really careful with your iron as the plastic button will melt if you touch it. once that's in place, it's just a matter of [removing the buzzer connector from your old PCB and soldering it onto the back of the Sensor Watch PCB.](https://youtu.be/Zr0pKeC2VFU?t=185) this will feel blissfully easy after the button! you also have to place the battery clip, but no soldering needed here :). one area I found particularly difficult was the area with the oscillator crystal and the two 0402 capacitors, C7 and C8. things are a bit cramped here, so extra care was needed: {{ image(path="images/sensor-watch/c7c8.jpg", alt="a closeup of a green sensor watch PCB, with an area circled. the area contains some small, and closely grouped copper pads") }} ## software at this point the watch was assembled with all components in place. did it work? at this stage, no idea. hopefully yes, and I could progress to the more familiar world of embedded software. ### bootloader the next necessary step is to flash the bootloader, so that we can put the firmware in place. unfortunately this requires a little more real-world action. we need to access the SWD points on the board to write the bootloader. ideally you could do this with some kind of [pogo pin](https://en.wikipedia.org/wiki/Pogo_pin) jig - and if you were doing any number exceeding about 5 I'm sure this would be worth the time. however, I decided to just solder some jump wires (stripped on one end, solid tip female on the other) to the points on the board. they're all close, but it's easy enough to do (albeit ugly). then I connected these to my [Adafruit Trinket M0](https://www.adafruit.com/product/1501) (PyRuler would also work).the pin mapping is as follows: SWD=0, SWC=1, RST=3, V+=3V, GND=GND. I used the [flasher from the sensor watch repo to flash the bootloader](https://github.com/joeycastillo/Sensor-Watch/blob/main/utils/flash_watch_pyruler/flash_watch_pyruler.ino). note that you could build the bootloader yourself first and put the generated binary into bootloader.h - the source is located [here](https://github.com/joeycastillo/uf2-samdx1). personally, I just used the prebuilt version from the repo. I had to change part of the Adafruit DAP library and add the SAM L22 DID to get this to work, [I provided the diff of this change](https://github.com/joeycastillo/Sensor-Watch/issues/83#issuecomment-1229353899) in a Sensor Watch GitHub issue (I just now am remembering I promised to upstream this, oops!). mercifully, I got the red blinky LED, and all was good! I unsoldered the wires from the board, and tried to clean up most of the solder blob to keep the board fairly flat. ### movement now the bootloader is in place, the main firmware can be installed! [the community firmware, Movement](https://www.sensorwatch.net/docs/movement/)is great, so this is what I installed. there are a bunch of different useful faces available, and more functionality is always being added. flashing firmware was easy: I plugged the PCB into the end of a USB Micro B cable (plugged on the other end into my computer) and double tapped the reset button (I find this has to be done quite quickly, using my fingernail was the trick to doing this reliably on such a small button). done successfully, the LED on the board pulses and a new drive labelled "WATCHBOOT" appears on the computer. now a built UF2 firmware file can just be dragged onto the device to flash, thanks to the bootloader flashed earlier. for the initial test, I just used a [prebuilt image](https://www.sensorwatch.net/docs/firmware/prebuilt/) to check everything was working. I flashed this, and the LED pulsed and turned off, signalling success. from here I just assembled the watch with the Sensor Watch PCB, and it worked! I verified LED and buzzer function by playing around with various functionality. success! ## developing on movement one face I found particularly cool was the [TOTP face](https://github.com/joeycastillo/Sensor-Watch/blob/main/movement/watch_faces/complication/totp_face.c). I use [TOTP](https://en.wikipedia.org/wiki/Time-based_one-time_password) [2FA](https://en.wikipedia.org/wiki/Multi-factor_authentication) on various accounts, so having access to the codes on my wrist at all times was really appealing. at the time, the TOTP face only supported one key - so I decided to improve it. thankfully, Sensor Watch has an emulator for development. without this, development would be pretty tiresome with the flashing and reassembling of the watch getting tiring if you needed to iterate on some code and test it on the watch. the emulator runs inside the browser and uses [Emscripten](https://en.wikipedia.org/wiki/Emscripten). [some minimal instructions on how to build this is available on the README](https://github.com/joeycastillo/Sensor-Watch#using-the-movement-framework). this allowed me to extend the TOTP face easily and allow for multiple keys. [my PR was merged](https://github.com/joeycastillo/Sensor-Watch/pull/84), and the functionality is now available for anyone to use. the keys are added at compile time, so they are baked into the firmware on flashing. for my purposes this is fine, as I never really change them. however, with the recent addition of a [LittleFS](https://os.mbed.com/blog/entry/littlefs-high-integrity-embedded-fs/) filesystem, the community have added [a version of the face which stores the keys on the filesystem](https://github.com/joeycastillo/Sensor-Watch/blob/main/movement/watch_faces/complication/totp_face_lfs.c). awesome! some more details on using Sensor Watch for TOTP is available [on this blog post](https://blog.singleton.io/posts/2022-10-17-otp-on-wrist/) ([HN discussion, if you dare](https://news.ycombinator.com/item?id=33243434)). it's even running my code :)! ## epilogue some summary thoughts: - shoutout to Joey Castillo. for creating the Sensor Watch as a beautifully open source project (the fact I could independently make my own is what it's all about!). for being [so helpful and kind](https://github.com/joeycastillo/Sensor-Watch/issues/83) when I asked for help. for having such a positive attitude towards those in the community who are using Sensor Watch to learn about all kinds of things (seriously, check out the [Oddly Specific Objects Discord](https://discord.gg/NtMVTBNca7) to see how much this guy is giving to the community). - sometimes it's worth just trying things that are difficult. this is my first time successfully doing and small-scale soldering of this kind, and it worked out great with some patience. having the motivation from making something I thought was really cool was an important factor here I think. - if you have a Sensor Watch (or are planning to!) please go ahead and [contribute to movement](https://github.com/joeycastillo/Sensor-Watch) if you have a cool idea. I'm sure some reviews would be helpful to spot any issues on existing PRs before a maintainer gets to them to save some time. - the one issue I've had with using my Sensor Watch for TOTP is clock accuracy. the clock drifts over time, so I have to set the time once or twice a week to keep it nice and accurate for the TOTP functionality to be nice to use. but a community member is working on this, and it's going to get a lot better. check out the Discord channel to see some seriously cool engineering going into this calibration effort. {{ image(path="images/sensor-watch/watch1.jpg", alt="a shot of a yellow and black assembled sensor watch, lying horizontally on a surface") }} {{ image(path="images/sensor-watch/watch2.jpg", alt="a shot of a yellow and black assembled sensor watch, lying vertically on a surface") }} {{ image(path="images/sensor-watch/wrist.jpg", alt="a shot of a yellow and black assembled sensor watch, on the author's wrist") }}