Not a day without sports - 2: reprogramming a Chinese bracelet

For people involved in sports, a frequent companion for jogging or riding is a smartphone with various applications. With a bicycle it’s easier, you can fix a smartphone, for example, on the steering wheel and watch the data from the sensors. But what if you are running or skiing? You can fix the smart on your hand, for this there are special covers (including swivel ones). But this is inconvenient and sometimes cumbersome. In addition, the Russian hero does not go directly.

There are various articles on the Internet in which enthusiasts make their smart watches. Self-made or printed case. Make the filling. But there are a lot of ready-made devices on aliexpress. For example, as in the photo below. If you believe the description, then it’s a direct super device: it measures heart rate, pressure, calories and something else.


Let's open and see what's inside.



And in fact
. . Random() . , , , .


The brain of this bracelet is a PHY6202 chip from a manufacturer from the Middle Kingdom Fengjia Microelectronics. Inside it has a Cortex-M0 and a standard set of peripherals. Memory: 512kB Flash, 138kB SRAM and 128kB ROM. ROM contains a BLE stack and a UART bootloader, as programmable chip through UART. The Chinese comrades carefully brought out contacts for UART. To switch to UART mode, the bootloader needs to pull the TM output to a high level and reset the chip.

The utilities and SDKs for the PHY6202 (as well as for his older brother PHY6212) can be found here .

The chip programming utility PhyPlusKit is provided directly. The documentation has a list of commands: erase, write, etc. Details in the document PHY62XX_UART_FlashWrite_Protocol at the link above (in Chinese). Honestly, the list of commands is not complete. PhyPlusKit uses another rdreg command (read any register).

Let's get started. We disassemble, solder the necessary contacts to the UART-USB adapter and go .

The SDK contains many examples. In itself, in my opinion, it is crooked and damp. Sometimes you have to edit the source, because they are not designed for “external” use only. Here is the battery level metering function from Battery Service. Why is she there at all incomprehensible.

static uint8 battMeasure( void )
{
  uint8 percent;
  percent = 95;
  return percent;
} 

Not an SDK, but one solid example.
The pinout of the bracelet is:
1) accelerometerSDA P32
SCL P33
2) LCDSDA P25
SCL P31
RS P00
Reset P01
CS P02
LED P34
3)P03
4)P20
5) USB Vin ( USB)P15
6) VbatP14/AIO3
7) Green LED ( )P23
The display is standard (full on aliexpress) on the ST7735 with a resolution of 80 * 160. Powered by SPI. There are ready-made libraries for it, but it's better to make your own light version, for your font size and your own characters. The display is color, but this is not very relevant on the street, as low contrast (sadly remembered the transflective displays from Siemens phones). Yes, and tinted glass. We will use white color to display text, it is best seen.

The touch button is made on a Tontec TTP233D-HA6 chip.

The accelerometer is unknown, but the scan of the I2C bus showed that it uses registers like all ST accelerometers. Most of all it is similar to LIS2DH12. It seems that all control registers correspond.

To display our information on the bracelet, we need our own BLE-service for data transfer. Something like SPP . Additionally, you can add Battery Service and firmware update via BLE.

As a basis for the project, we take an example of firmware for updating OTA and remake it to our needs. Add a service for the battery. To transfer data, you can use an example of implementing a custom service from the SDK. It uses one service FF01 and in it one characteristic FF02.

Spoiler
SDK GPIO 0, . . , . , pull-up pull-down ( 100 ) . . 40 , «» pull-down, 15 ( ).

We fasten the working services:

  1. interrupt handling by touch button. In addition to turning on the screen and turning on / off the bracelet itself, we will make single and double tap recognition with the transmission of a command through our FF02 characteristic.
  2. output of data received from a smartphone through the same characteristic to the display.
  3. short inclusion of a vibromotor for drawing attention.
  4. using the accelerometer, turning on the screen with a sharp wave of the hand (it’s difficult to set up, because when you run, you wave your hands).

Ok, the bracelet is ready. We check through nRFConnect, it allows you to read and write the values ​​of the characteristics. On the screen, the pulse, time, distance and another timer (for example, to display the time lag or lead the graph, i.e. a kind of pacemaker, but this can only be obtained from your application).


Now we need to take the data somewhere to transmit it. I currently use the Strava app, although I like it less and less. Perhaps the easiest way to get running time from her and the distance (though with rounding to 100 m) from notifications in the status bar. To do this, you need to write an application with a service for listening to notifications. This is not difficult. But we will read the pulse directly from the BLE or ANT + belt. Well, since we have notifications from the bracelet about pressing buttons, we need to use them somewhere. For example, you can, by sending messages through BroadCastReceiver, pause Strava and restart it. And it is better to someday make your Strava with bells and whistles. The application requires rights to access the location (this is necessary to work with BLE) and rights to access notifications.

It remains to verify the case. Unfortunately, the winter ended in February, so the cycle from the picture at the beginning of the article has already ended. But you can go for a run. The accelerometer often turns on the screen unnecessarily, maybe it should be turned off completely. A touch button can react to a drop that has fallen from the forehead.




And finally, the good news. The bracelet already from the factory supports OTA update through the PhyApp application (it lies in the same place as the SDK, originally in Chinese). Therefore, having ready-made firmware, even disassembling the bracelet is not required. Flash and use. To do this, you need to install the application, put the firmware in the “root” of the phone (HEX, not HEXF, since the latter contains the bootloader that we already have from the factory), connect to the bracelet and use the OTA button to upload the firmware to the bracelet. After flashing the bracelet will be turned off, to turn it on you need to hold the button for 2 seconds.

In general, watches and bracelets on the PHY62 can be easily converted to anything.

References:

  1. source codes and APK of an android application (it was written under Android 8.1, it seems to work under 9, it didn’t check under others);
  2. HEX firmware file via BLE, and HEXF - for firmware via UART (I don’t mind the source, but I need to understand that I can upload it by license agreement and who doesn’t write in this special) + PhyApp firmware application for firmware OTA.
  3. I bought a bracelet here , but I can’t guarantee that the filling will be the same, because a lot of the same in appearance, but with a different chip. There are kind of options with a larger screen, which also have PHY6202. In general, there are watches / bracelets with different chips (Phy +, Telink, and even nRF).


PS In general, it looks like the SDK for PHY62 was created based on the Texas Instruments SDK for their BLE chips.

All Articles