fanoush
Posts: 459
Joined: Mon Feb 27, 2012 2:37 pm

Espruino on $9.99 fitness tracker

Thu Jan 17, 2019 9:17 am

Hi,

this is not strictly raspberry pi related (even if I did all the stuff on my Pi 3 and Pi3 or Zero W can easily connect to it) I just think people here might be interested in it. In past half year I've been searching for cheap hackable fitness tracker/smart watch and my drawer is full of $6-$11 bluetooth fitness trackers with various chinese chipsets with no datasheets or SDKs available but I finally found one that is cheap, still easy to buy and perfectly hackable with good open source support for the hardware.

It is the DS-D6 fitness tracker/watch - device based on Nordic nRF52832 chipset (Cortex M4, 64KB RAM, 512KB flash) with Bluetooth LE, 128x32 OLED, and two reconfigurable GPIOs on USB charging connector by default used as serial console. It is relatively easy to open and seal back without visible damage if you really need to.

I have managed to reverse engineer the hardware and the update procedure and build currrent Espruino for it. It is now possible to update the watch over serial port with custom firmware without opening it and possibly also restore original fitness app back.

Espruino is cool javascript interpreter with easy development environment and is a very good fit for nRF52832 (even their official boards/devices are based on this chip). You can either program directly via interactive console on the watch over serial or bluetooth or you can use browser based IDE again with device connected over serial or Bluetooth LE. For performance critical parts it can even use inline C or assembler however it is quite usable even without it.

The project link is https://github.com/fanoush/ds-d6 and https://github.com/fanoush/ds-d6/wiki/Hardware and the update procedure is described here https://github.com/fanoush/ds-d6/wiki/DFU-update some photos are here https://github.com/fanoush/ds-d6/tree/master/photos

I got it from Gearbest (for $7.99 when it was on sale, but mostly it is for $9.99) but you can also find it elsewhere.

You can use it as reprogrammable smart watch and wear it, or simply use it as cheap BLE device with rechargeable battery, display, button, accelerometer, vibration motor and GPIOs. Espruino has good support for Bluetooth LE and the watch can act both as server and client (Peripheral, Central roles) so you could even connect multiple watches together. Also the power management is good, it can last over week on single charge (depends on usage).

Due to extra GPIOs/serial console on usb connector it can also provide wireless connectivity and brain to other attached devices.

There are lot of other projects to port custom code to various fitness trackers based on nRF52832 or older nRF51822 (Cortex M0, 16KB ram, 256KB flash) but so far I didn't found one that works with device you can still buy and which allows updating with custom firmware without opening it. Also while older nRF51822 chip is good for coding in C the newer chip is good enough for high level coding without too much compromises and Espruino is very easy to code interactively and do stuff quickly.

Currently I have the Espruino working with all builtin hardware available and have basic code that shows time when you touch the button. Also the KX023 accelerometer is nice, it can e.g. detect automatically taps and double taps from various axes and just fire interrupt and call my javascript with this event so it can be used as additional 'buttons'.
Last edited by fanoush on Tue Jul 30, 2019 6:01 am, edited 1 time in total.

Heater
Posts: 12960
Joined: Tue Jul 17, 2012 3:02 pm

Re: Espruino on $9.99 fitness tracker

Thu Jan 17, 2019 1:33 pm

That is great to hear. I have been a fan of Espruino since it was launched. So much easier than Micro Python.

Whilst we are here you may be interested in Espruino for RISC V processors: Espruino on RISC-V Silicon - SiFive FE310 : https://www.youtube.com/watch?v=54e5rqyNXqw&t=7s

That is almost on some kind of topic here given that the Raspberry Pi Foundation is now a paid up silver member of the RISC V foundation.

fanoush
Posts: 459
Joined: Mon Feb 27, 2012 2:37 pm

Re: Espruino on $9.99 fitness tracker

Fri Jan 18, 2019 9:32 am

Heater wrote:
Thu Jan 17, 2019 1:33 pm
That is great to hear. I have been a fan of Espruino since it was launched. So much easier than Micro Python.
Well it is event based so there is no main loop where you need to check everything and call stuff yourself. This may bother someone. On the other hand when you don't have multiple threads it is easier and more natural to just hook stuff to various events and it gets all called automagically at the right time with no need for threads.
The tricky bit with such event based system is when you need to do stuff with delays, then you either need to interleave it with nested setTimeout chains which gets hard to read quickly

Code: Select all

dostuffA();
delay(200);
dostuffB();
becomes

Code: Select all

dostuffA();
setTimeout({
dostuffB();
},200);
or you can use Javascript ES6 Promises which Espruino supports but it looks more complicated than simply do stuff in sequence with delay calls. Otherwise I really like it a lot.
Heater wrote:
Thu Jan 17, 2019 1:33 pm
Whilst we are here you may be interested in Espruino for RISC V processors: Espruino on RISC-V Silicon - SiFive FE310 : https://www.youtube.com/watch?v=54e5rqyNXqw&t=7s
Wow, that is quite new, the .143 build he shows is few days old :-)


BTW as for these fitness trackers it was interesting to find out how many BLE SOCs are there and how quickly Chinese cloners and manufacturers are innovating for lowest price. I have three different ID115 trackers cloning original ID115 which had Nordic nRF51822 and each is using different chip and different android app while visually looking almost the same. Then there is one called ID115plus (so they just 'cloned' successful name possibly to appear in ebay searches for ID115) which looks completely different and has color display and is otherwise quite good (sadly it uses chipset with SDK that is hard to get) and recently I got clone of this clone for 6.99 which is still quite good and looks almost identical and yet it uses different android app and the communication with it is completely different while the watch application look same on screen.
Also even the more established manufacturers are using different chips in different models of very similar trackers while the resulting firmware looks identical and uses same android app. I was hit by this Lenovo HX06 which looks identical to DS-D6 in almost all aspects but still it is Dialog chip with quite different architecture and not Nordic so they had to develop same firmware twice.

So it is quite tricky to buy something repeatedly over months which is still the same thing :-) This DS-D6 on GearBest from specific seller is sold at least since summer 2018 and so far it is still the same thing as pictured on FCC ID photos. So that's why I am letting people know now since in few months my work will probably be obsolete. But it is fun and I learned a lot :-)

fanoush
Posts: 459
Joined: Mon Feb 27, 2012 2:37 pm

Re: Espruino on $9.99 fitness tracker

Thu May 30, 2019 8:40 am

Just to let you know that this fitness tracker is still sold, now even for $7.99 only (or $6.99 with promo code) and lot of progress was done:

- there is now easy android bluetooth flasher so no TTL serial adapter is needed to update it
- update procedure of bootloader and softdevice works so there are almost no limits what you can run
- now there is port of adafruit bootloader that allows to use adafruit arduino nrf52 core or latest micropython

for more info see https://github.com/fanoush/ds-d6

Heater
Posts: 12960
Joined: Tue Jul 17, 2012 3:02 pm

Re: Espruino on $9.99 fitness tracker

Thu May 30, 2019 4:25 pm

fanoush,

That is cool. I never imagined I would ever want to buy a smart watch or any kind of fitness tracker. But you have made this irresistable.

I was thinking about your comments re: the JS event loop:
Well it is event based so there is no main loop where you need to check everything and call stuff yourself. This may bother someone.
Being even based is an great simplification. I could only bother someone that has not realized that yet.
The tricky bit with such event based system is when you need to do stuff with delays, then you either need to interleave it with nested setTimeout chains which gets hard to read quickly
Not really. Depending in what one is trying to do code like your example can be written with a state machine. Something like:

Code: Select all

setInterval (function () {
    switch (state) {
        case0:
            doStuffA()
            state = state + 1
            break
        case1:
            doStuffB()
            state = someOtherState..
        case2:
            ...
    }
}, 100)
That might look longer and more complex but state machines are a great way to organize code that handles the logic of events in any language.

I hate promises, but that is just me. I manage to avoid long chains of nested anything without them.

I see a lot of questions come to the forum from people that have got some endless loop doing stuff with delays in Python working. Then they get some other such loop working. Then they are stuck, they come here asking how to do both of those loops in one program. Then they get thrown to the weeds with advice about threads and such...

All in all, it's easier to handle multiple asynchronous events with the JS event driven model. Which is why JS was so successful in the browser handling mouse, keyboard, network, timers, etc.

Anyway, great work there!

fanoush
Posts: 459
Joined: Mon Feb 27, 2012 2:37 pm

Re: Espruino on $9.99 fitness tracker

Fri May 31, 2019 8:22 am

Heater wrote:
Thu May 30, 2019 4:25 pm
That is cool. I never imagined I would ever want to buy a smart watch or any kind of fitness tracker. But you have made this irresistable.
DS-D6 is curently cheapest but there are a bit more choices now. Few days ago Banggood had a deal with Lenovo HX03W for $9.99 (still B/W OLED but wider), this one works too as it is same OEM manufacturer. Also the color HX03F would possibly work (untested so far). And we have few other tips for possible candidates by two other OEMs. Lot of others are unsuitable because they often use signed firmware images so the device cannot be updated without taking apart.
Heater wrote:
Thu May 30, 2019 4:25 pm
I hate promises, but that is just me. I manage to avoid long chains of nested anything without them.

I see a lot of questions come to the forum from people that have got some endless loop doing stuff with delays in Python working. Then they get some other such loop working. Then they are stuck, they come here asking how to do both of those loops in one program. Then they get thrown to the weeds with advice about threads and such...

All in all, it's easier to handle multiple asynchronous events with the JS event driven model.
Yes, I like event based system better too. I immediately hit this issue in unexpected way when porting micropython and found out that the interacive console is available only after you main code is completely finished and exits. With espruino the console is available all the time unless you run busy loop somewhere so you can modify running system and add stuff at runtime gradually. This way of doing things is not possible with micropython even if the REPL console feature is there.

fanoush
Posts: 459
Joined: Mon Feb 27, 2012 2:37 pm

Re: Espruino on $9.99 fitness tracker

Tue Jul 30, 2019 5:51 am

Just a heads up that this DS-D6 is for $4.99 now. And with free shipping if you take more than one. Over half a year it went steadily down dollar by dollar but how much lower this could go? Now it is already lower than 10 qty unit price for nrf52832 chip at digikey :-)

Return to “Off topic discussion”