[DS-D6] build for cheap DS-D6 nrf52 fitness tracker

Discussion and questions about boards that can run MicroPython but don't have a dedicated forum.
Target audience: Everyone interested in running MicroPython on other hardware.
fanoush
Posts: 10
Joined: Fri Feb 01, 2019 2:59 pm

[DS-D6] build for cheap DS-D6 nrf52 fitness tracker

Post by fanoush » Thu May 30, 2019 8:15 am

Hello,

just to let you know that there is this very cheap (<$8) nrf52832 based DS-D6 fitness tracker that can easily run custom firmware including micropython. It can be updated without taking apart and has 2 GPIOs available on USB data pins (e.g. for UART or I2C).

I made experimental build of micropython that seems to work however I focus more on Espruino so if you are core micropython fan feel free to get few of them and improve it :-)

For more info check
https://github.com/fanoush/ds-d6
https://github.com/fanoush/ds-d6/tree/m ... icropython

User avatar
mcauser
Posts: 507
Joined: Mon Jun 15, 2015 8:03 am

Re: [DS-D6] build for cheap DS-D6 nrf52 fitness tracker

Post by mcauser » Wed Aug 21, 2019 2:42 am

Nice work @fanoush!
I ordered 2x from GearBest. That promo code "MPOWDS-D6" saved me a few extra bucks. Thanks for that!

fanoush
Posts: 10
Joined: Fri Feb 01, 2019 2:59 pm

Re: [DS-D6] build for cheap DS-D6 nrf52 fitness tracker

Post by fanoush » Wed Aug 21, 2019 6:42 am

Yes, looks like no matter what is current price the code brings it down to $5.99. Also they had 'super deal' twice where the price was $4.99, one such deal was two days ago.

As for state of nrf52 micropython port there are few missing features that would improve it a lot IMO
- switching between rs232 and bluetooth serial at runtime
- ability to close and reopen serial - it draws 0.5mA when opened, so the battery last day or two instead of weeks
- direct memory access to NRF registers - could solve the issue with serial too as reconfiguring rx,tx pins dynamically could turn off the power draw when serial is not used

I guess those are relatively easy to add however it has lower priority for me than Espruino coding or low level bootloader stuff to get HX03W and F07 to same state as DS-D6. F07 is color one (~$17 on aliexpress), HX03W is better DS-D6 - has 128x64 OLED instead of 128x32 (normally in ~$19 range, banggood had deal for $9.99, just now it has deal for $14.99). Both are nrf52832 and have unsigned firmware so can be updated without taking apart.

User avatar
sebi
Posts: 48
Joined: Tue Mar 29, 2016 9:36 pm
Location: France

Re: [DS-D6] build for cheap DS-D6 nrf52 fitness tracker

Post by sebi » Fri Aug 30, 2019 2:20 am

Thx @fanoush for this very nice work!
It allows me to experiment with a Nordic chip for a very low price.
I didn't find on your Github a fork of the official MicroPython with the modifications you made to adapt the nrf port to the DS-D6.
Could you share such a piece of code? This would allow me to understand a bit more the adaptations you made.

fanoush
Posts: 10
Joined: Fri Feb 01, 2019 2:59 pm

Re: [DS-D6] build for cheap DS-D6 nrf52 fitness tracker

Post by fanoush » Fri Aug 30, 2019 8:45 am

There is a diff in micropython folder here https://github.com/fanoush/ds-d6/blob/m ... ython.diff
I only added methods to go back to adafruit bootloader to do update over serial or bluetooth. Then there is just board definition with pins and linker script with flash areas (by default micropython does not expect bootloader in flash). It was simple to get just the REPL console working.

There is also other guy who was interested a bit more in it who actually tried the ssd1306 driver to show something on the display and it worked, see demo here https://youtu.be/NpPivahKKpM?t=1424 (sadly it is in Czech)

User avatar
sebi
Posts: 48
Joined: Tue Mar 29, 2016 9:36 pm
Location: France

Re: [DS-D6] build for cheap DS-D6 nrf52 fitness tracker

Post by sebi » Fri Aug 30, 2019 8:49 pm

Thank you for those explanations.
I had a look at the modifications you made and it was really instructive.
I used your diff file to compile the latest MicroPython version for the dsd6 nrf port.

As I don't have an android device I won't be able to run D6Flasher easily and I will certainly use a serial connection to perform DFU. Did I understand right: Adafruit-nrfutil is for Python3 whereas Nordic nrfutil 0.5.3 works with Python2, but both provide the same features?

Adafruit bootloader embeds SoftDevice S132 6.1.1 which is required to run MicroPython. Does this bootloader come together with adafruit-nrfutil?

PS: The video was interesting indeed: thanks to the pins you have identified for the hardware he is able to play with the screen and run the motor using simple MPY commands :)

fanoush
Posts: 10
Joined: Fri Feb 01, 2019 2:59 pm

Re: [DS-D6] build for cheap DS-D6 nrf52 fitness tracker

Post by fanoush » Sat Aug 31, 2019 9:55 pm

adafruit-nrfutil work with both python3 and 2, they just cannot coexist in same python version with nrfutil (which needs python2).
Yes adafruit-nrfutil is almost same as nrfutil 0.5.3, It was primarily done for adafruit bootloader but works also with SDK11 based Desay bootloader in DS-D6. So you need just that one tool, the only difference is that Desay bootloader needs serial speed 38400 while adafruit bootloader uses 115200 and so this is default speed for adafruit-nrfutil too (unlike nrfutil).

When installing just beware that you first need to update bootloader to fixed one e.g this one and only then update to adafruit one. It may be a bit tricky if you currently have bootloader with moving arrows since that one is a bit unstable over serial and may disconnect in the middle or report success while not updating it. In that case just retry the same update twice to verify bootloader was really installed and arrows are not moving on second update. If you already have bootloader with no animation (it is random which one you get) then it should work better. But still you can run it twice just to be sure before you continue with adafruit bootloader.

However I'm afraid you may not manage without bluetooth, I just tried and the adafruit bootolader defaults to bluetooth. You can force it to serial from micropython later but first time it is over bluetooth, sorry. Well actually it always tries serial first for 3 seconds on each reboot but you would need to be really quick and have command line with micropython package prepared and run it right after adafruit bootloader update. Or you can rebuild the bootloader from source and change it, the diff is there too.

User avatar
sebi
Posts: 48
Joined: Tue Mar 29, 2016 9:36 pm
Location: France

Re: [DS-D6] build for cheap DS-D6 nrf52 fitness tracker

Post by sebi » Sun Sep 01, 2019 12:48 pm

they just cannot coexist in same python version with nrfutil
What about in two python virtual environments?

In the wiki you wrote:
To put device to DFU mode just try to run the serial procedure and it will probably switch to bootloader automatically but will timeout so you need to retry.
Does it mean that to update the bootloader with the one with no animation I can use the serial DFU procedure?

To modify the Adafruit bootolader so that it defaults to serial update, I can modify the file Adafruit_nRF52_Bootloader/src/main.c with either
  • #define DFU_SERIAL_STARTUP_INTERVAL 3600000 // Big number
    or
  • _ota_dfu = 0; // instead of _ota_dfu = _ota_dfu || !serial_only_dfu;
right?

I saw a picture on your GitHub where you show how to wire a SWD probe. Can I use the ST-LINK V2 probe to flash the firmware?

Thx!!

fanoush
Posts: 10
Joined: Fri Feb 01, 2019 2:59 pm

Re: [DS-D6] build for cheap DS-D6 nrf52 fitness tracker

Post by fanoush » Sun Sep 01, 2019 5:06 pm

sebi wrote:
Sun Sep 01, 2019 12:48 pm
they just cannot coexist in same python version with nrfutil
What about in two python virtual environments?
possibly. They both need same dependencies of different version, if you install one with pip, the other will stop working due to wrong version of something.
sebi wrote:
Sun Sep 01, 2019 12:48 pm
Does it mean that to update the bootloader with the one with no animation I can use the serial DFU procedure?
Yes, you just run adafruit-nrfutils with different zip files like this

Code: Select all

pi@raspberrypi:~ $ adafruit-nrfutil dfu serial -b 38400 -pkg DS-D6-desay-bootloader-noanim-fix.zip -p /dev/ttyUSB0 
Upgrading target on /dev/ttyUSB0 with DFU package /home/pi/DS-D6-desay-bootloader-noanim-fix.zip. Flow control is disabled, Dual bank, Touch disabled
########################################
##
Activating new firmware
Device programmed.
pi@raspberrypi:~ $ adafruit-nrfutil dfu serial -b 38400 -pkg DS-D6-desay-bootloader-noanim-fix.zip -p /dev/ttyUSB0 
Upgrading target on /dev/ttyUSB0 with DFU package /home/pi/DS-D6-desay-bootloader-noanim-fix.zip. Flow control is disabled, Dual bank, Touch disabled
########################################
##
Activating new firmware
Device programmed.
pi@raspberrypi:~ $ adafruit-nrfutil dfu serial -b 38400 -pkg DS-D6-adafruit-bootloader-sd132v611.zip -p /dev/ttyUSB0 
Upgrading target on /dev/ttyUSB0 with DFU package /home/pi/DS-D6-adafruit-bootloader-sd132v611.zip. Flow control is disabled, Dual bank, Touch disabled
########################################
########################################
########################################
########################################
########################################
########################################
########################################
########################################
#######
Activating new firmware
Device programmed.
And now if you had this prepared (with no 38400 speed) it would work too in the 3 second timeout

Code: Select all

pi@raspberrypi:~ $ adafruit-nrfutil dfu serial -pkg dsd6-micropython-190901.zip -p /dev/ttyUSB0 
Upgrading target on /dev/ttyUSB0 with DFU package /home/pi/dsd6-micropython-190901.zip. Flow control is disabled, Dual bank, Touch disabled
########################################
########################################
########################################
########################################
########################################
########################################
########################################
###################################
Activating new firmware
Device programmed.

sebi wrote:
Sun Sep 01, 2019 12:48 pm
To modify the Adafruit bootolader so that it defaults to serial update, I can modify
Not the timeout. This is after each reboot. Typically if there is valid application flashed, nordic bootloader will switch to it immediately. Only if there is no valid app or you force it via some flags, it will stay in DFU mode. This adafruit bootloader is different, it will try serial DFU for 3 seconds always after each reboot no matter what. This helps if your code is broken and restarts in a loop or when you use watchdog. Only then after this times out it decides what to do next according to normal rules - start the app or stay in some DFU mode (serial or bluetooth) because of flags.

So change the flags, not the initial timeout. maybe reversing it would work like this
serial_only_dfu = serial_only_dfu || !_ota_dfu ;
instead of
_ota_dfu = _ota_dfu || !serial_only_dfu;
sebi wrote:
Sun Sep 01, 2019 12:48 pm
I saw a picture on your GitHub where you show how to wire a SWD probe. Can I use the ST-LINK V2 probe to flash the firmware?
Yes, definitely. It is easy with openocd. Sooner or later you will need it unless you are very careful which is not fun. it is now for $4.99 so get few more and open at least one to test everything.

BTW I just built current tree and have the display working. I needed to enable framebuffer

Code: Select all

#define MICROPY_PY_FRAMEBUF         (1)
in ports/nrf/mpconfigport.h

and then put drivers/display/ssd1306.py into freeze folder and build with
make BOARD=dsd6 SD=s132 FROZEN_MPY_DIR=freeze

It needs some changes to work optimally but even the default code will work with some additional commands send via write_cmd to fix it. I will put it to github or gists

rpr
Posts: 99
Joined: Sat Oct 27, 2018 5:17 pm

Re: [DS-D6] build for cheap DS-D6 nrf52 fitness tracker

Post by rpr » Sun Sep 01, 2019 11:15 pm

Fanoush,

This looks fantastic. Thanks for all your work.

I received my watch but have not uploaded any new micropython firmware yet. Prior to doing that, I want to make sure I do the steps correctly by reading through all of your github docs, so I don't brick it ;)

Just an (idiotic) question before I get started: I assume that your BLE REPL will provide a REPL. Can I connect to this from my laptop? Thanks.

Post Reply