[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.
User avatar
sebi
Posts: 30
Joined: Tue Mar 29, 2016 9:36 pm
Location: France

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

Post by sebi » Mon Sep 02, 2019 11:25 am

@rpr: based on the information at https://github.com/micropython/micropyt ... /ports/nrf there are two possibilities to connect the MicroPython REPL over bluetooth on a PC: NUS Console and WebBluetooth REPL.

@fanoush: Can I use those bluetooth serial interfaces to run the commands
BT+UPGB:1
BT+RESET
to set the bracelet in DFU mode when equipped with other than MicroPython firmwares?

I understood from what I read in the discussion channel https://gitter.im/nRF51822-Arduino-Mbed ... atch/Lobby that a way to reset the controller is to connect the USB +5V with Ground for a short period of time (I believe that the battery BMS can handle this shortcut easily). Do you confirm? If so, this is a good security trick if the program freezes.

I am looking forward to understanding why the SSD1306 is a bit different than usual and we need a write_cmd to fix it.
Last edited by sebi on Mon Sep 02, 2019 10:59 pm, edited 3 times in total.

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

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

Post by mcauser » Mon Sep 02, 2019 11:32 am

I’m guessing because it’s a 128x32, there is a different init command to set the row offset. Most other 128x32s are positioned half way down in the 128x64 buffer.

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 » Tue Sep 03, 2019 10:57 am

mcauser wrote:
Mon Sep 02, 2019 11:32 am
I’m guessing because it’s a 128x32, there is a different init command to set the row offset. Most other 128x32s are positioned half way down in the 128x64 buffer.
Yes, basically the line https://github.com/micropython/micropyt ... 306.py#L49 is wrong for DS-D6, it needs 0x12 even if it is 128x32. Also the default combination 0f 0xc0/0xc8 vs 0xa0/0xa1 produces mirrored output with micropython driver, see valid combinations here https://gist.github.com/fanoush/ce461c7 ... sd6-js-L60
for vertical mode (32x128) it would also need different framebuffer layout here https://github.com/micropython/micropyt ... 306.py#L35

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 » Tue Sep 03, 2019 11:02 am

rpr wrote:
Sun Sep 01, 2019 11:15 pm
I assume that your BLE REPL will provide a REPL. Can I connect to this from my laptop? Thanks.
Yes if your laptop and browser (e.g. Chrome) can do Bluetooth LE and Web Bluetooth, try https://aykevl.nl/apps/nus/ and click in right corner if you see it scanning for devices.

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 » Tue Sep 03, 2019 11:25 am

sebi wrote:
Mon Sep 02, 2019 11:25 am
there are two possibilities to connect the MicroPython REPL over bluetooth on a PC: NUS Console and WebBluetooth REPL.

@fanoush: Can I use those bluetooth serial interfaces to run the commands
BT+UPGB:1
BT+RESET
to set the bracelet in DFU mode when equipped with other than MicroPython firmwares?
probably not unless you change guids of read and write characteristics in that code, otherwise it is same so if you can change the source to use guids mentioned in https://github.com/fanoush/ds-d6/wiki/Bracelet-commands it should work (i.e. three lines on top here). The android app I linked there defaults to NUS console GUIDs too but can change them to Desay ones.
sebi wrote:
Mon Sep 02, 2019 11:25 am
I understood from what I read in the discussion channel https://gitter.im/nRF51822-Arduino-Mbed ... atch/Lobby that a way to reset the controller is to connect the USB +5V with Ground for a short period of time (I believe that the battery BMS can handle this shortcut easily). Do you confirm? If so, this is a good security trick if the program freezes.
Sadly no. USB is for charging, i.e. input. For this you need to open it and shortcut the battery contacts on the board. The one marked +/- here https://fccid.io/png.php?id=3414019&page=2 Those pins are accessible just with removed front glass. If you do it very briefly it should not damage battery but the voltage drop will reset CPU. There is also real reset pin under OLED, but for that you need to lift it.

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 Sep 04, 2019 8:07 am

Just a warning that recent build of micropython I have in one DS-D6 for few days doesn't respond on serial console now so be warned that this may happen. If this happens to you it should be enough to wait till battery is discharged if you don't want to open it. I guess I should get watchdog working. I really didn't use micropython extensively for more straight days - also because serial port drains the battery fast. Now I kept both 5V power and serial attached so it should work over days but the console doesn't respond now. Not sure why since I even didn't have bluetooth enabled or other code running so there should be basically nothing running except core micropython REPL loop. So just a warning that this is indeed experimental like said in README :-)

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

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

Post by sebi » Wed Sep 04, 2019 8:55 am

Thank you, those pieces of information were very instructive to me. I now understand better the purpose of the device/service/RX/TX GUIDs.
Depending on the service UUID a serial terminal over bluetooth can communicate to the board in data/console mode or AT command mode, right?
fanoush wrote:
Tue Sep 03, 2019 11:25 am
The android app I linked there defaults to NUS console GUIDs too but can change them to Desay ones.
I found AirTerminal https://apps.apple.com/us/app/airtermin ... 1296588408 a similar app for iOS than the one you mentioned for Android that allows to select the device/service/RX/TX UUIDs manually as well. I guess I will use it to run the BT+UPGB:1, BT+RESET commands in AT command mode if needed.

There is no AT command mode service coming with the Adafruit nRF52 Bootloader, right? Thus there is no other way than draining the battery to reset the board equipped with this bootloader (and no valid app) if sealed?
fanoush wrote:
Tue Sep 03, 2019 11:25 am
For this you need to open it and shortcut the battery contacts on the board.
It doesn't seem too difficult to open the bracelet and I will definitely do that.
However did you pursue your idea concerning the security trick to reset the board you mentioned on gitter: having one pin of the USB socket for reset + the other for half-duplex serial communication with the REPL?

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 Sep 04, 2019 11:10 am

sebi wrote:
Wed Sep 04, 2019 8:55 am
Is there an AT command mode service on the Adafruit nRF52 Bootloader? If not how to reset the board equipped with this bootloader if sealed?
This is not feature of bootloader. That needs to be part of application. That is the change I needed to add to micropython. See the diff - enter_xx_dfu methods in machine. This is actually quite fragile so that's why watchdog helps with the combination of the adafruit bootloader feature - waiting few seconds for serial DFU update after each reboot. With stock Desay or Nordic bootloader if the appllication is marked valid and has no working way to enter bootloader you cannot update it without opening and using SWD debugger.
sebi wrote:
Wed Sep 04, 2019 8:55 am
It doesn't seem too difficult to open the bracelet and I will definitely do that.
Yes, shoud be easy. Also minor scratches on body are not that critical since the band covers it (in case you'd still like to wear it after sealing it back). I did it with pocket knife around the crack to avoid scratching the front but atc1441 simply used big screwdriver near usb connector https://youtu.be/3gjmEdEDJ5A?t=1431
sebi wrote:
Wed Sep 04, 2019 8:55 am
However did you pursue your idea concerning the security trick to reset the board you mentioned on gitter: having one pin of the USB socket for reset + the other for half-duplex serial communication with the REPL?
No, sadly reset functionality cannot be changed to other pin, there is configuration documented here that the cpu loads after poweron automatically but the only valid value is 21 for nrf52832 :-) Also I was thinking about ways to trigger pin 21 reset by other pin via GPIOTE but that doesn't work too. So only watchdog works as a reset. Or draining battery - there is some battery protection circuit so the power is cut completely from nrf52 once battery goes below some level (like 3V) so this is safe and should not damage battery.

User avatar
sebi
Posts: 30
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 Sep 06, 2019 4:50 pm

Thank you @fanoush! Looking forward to receiving my DS-D6.
fanoush wrote:
Wed Sep 04, 2019 8:07 am
Just a warning that recent build of micropython I have in one DS-D6 for few days doesn't respond on serial console...
Hopefully a solution to this bug will be found.

Post Reply