RoadTest: STWIN SensorTile Wireless Node Dev Kit
Author: saicheong
Creation date:
Evaluation Type: Development Boards & Tools
Did you receive all parts the manufacturer stated would be included in the package?: True
What other parts do you consider comparable to this product?:
What were the biggest problems encountered?: The WIFI kit is optional so no review about this
Detailed Review:
The STWIN sensorTile is a tidy compact cubic have STM32 MPU attached with several of ST's sensors chips selected for IoT purpose, designed communicate wirelessly though the Bluetooth Low Power or optional WIFI, the package also supplied with a small LiPO and the plastic enclosure, make it easy for develop and test for portable mobile applications.
The kits come with SDK with essence STM32 libraries, additional with sensors and bluetooth drivers, the reference firmware allow connect to Android/IOS ST BLE Sensor APP out of box for exploring the sensor data, logging or review of the Predictive and check the battery level, both of them are Open source 3-Clause BSD license, mean you can modification and apply to yourself project freely.
In this road tests, at beginning, will brief review out-of-box hardware and softwares ST provided, study the MLC core, and future develop a TaiChi (Chinese version of Yoga) gesture recognising device, which is a wearable activies recorder for calorie burning tracking, we implement a IOS companion app to collect and save from Bluetooth LE toIOS HealthKit, thanks of ISM330DHCX machine learning core, the recognising directly working by the sensors chips by the machine learning core and wake up the STM32 by interrupt, as a result minimum the power consumption. The firmware and sources codes can be download at the end.
The STWIN SensorTile delivered with a plastic tray, have a pleasing symmetry placement on four conners.
Upper Left is the main board, Upper Right is the STLINK-V3MINI Debugger/Programer,
the Lower Left is the plastic box and mounting screws, a small LiPO battery on Lower Right.
The development kit require two USB ports once for programming, another for main board (or external 5V power supply supply to main board).
The battery is optional connected to the BATT connector and the Battery will be changed when USB/5V power supply supplied.
The programmer connect to the main board by the provided 14-pin flat cable, the STM32CubeProgrammer used for erase and write of firmware, the STM32CubeIDE is for develop and debug, both support MacOS and Multi-platform can be free download on ST website.
https://www.st.com/en/development-tools/stm32cubeide.html
The FP-IND-PREDMNT1 is function pack which included all of sensors and mic drivers, bluetooth middleware make it is a great starting points for a new project.
For developing Android/IOS cohesive APP, ST provided full set of open sources for their reference design APP and the protocol, make developer easy to learn and involve their creative.
https://github.com/STMicroelectronics/STBlueMS_iOS
The UNICO is ST MEMS software kits for ISM330DHCX, which help developer working for the Machine Learning Core.
The MLC designed rapidly implementation for conditions monitoring and classified of sensors data by machine learning, typical such alert of malfunction or detect suddenly impaction. For evaluation purpose, we use a set of hobby stepping motor continues rotate for emulate the motor movement, a simple task for identifying the Normal/Failure status.
The methodology of machine learning is collect set of sensor's data on different circumstances, specified those and feed those data to the software tools. The tools read it and process it by some algorithms, review the accuracy, learn it, optimum it and rerun this process to improve the model. After repeat to serve times, we get the final model, which is a set of decision trees that MLC used for predict or classified the type of situation.
The Machine Learning Core embedded on ISM330DHCX only for apply (using) the model for prediction tasks. Sure the sensor IC is not powerful enough for train and build the model. Our model is trained by the UNICO and import the C configuration array to our project.
Therefore, we need capture the data from the SensorTile to our computer for sampling.
Simply attached the SensorTile Box on one conner of the Stepping motor, a Arduino device control of Stepping motor speed.
As current UNICO do not support of direct communication with SensorTile. A function is built for print the sensors on UART console every 38ms.
static voidMotionMLTrainingData(void){ MOTION_SENSOR_Axes_t ACC_Value; MOTION_SENSOR_Axes_t GYR_Value; MOTION_SENSOR_Axes_t MAG_Value; /* Read the Acc values */ if(TargetBoardFeatures.AccSensorIsInit) { MOTION_SENSOR_GetAxes(ACCELERO_INSTANCE, MOTION_ACCELERO, &ACC_Value); } else { ACC_Value.x = ACC_Value.y = ACC_Value.z =0; } /* Read the Magneto values */ if(TargetBoardFeatures.MagSensorIsInit) { MOTION_SENSOR_GetAxes(MAGNETO_INSTANCE, MOTION_MAGNETO, &MAG_Value); } else { MAG_Value.x = MAG_Value.y = MAG_Value.z =0; } /* Read the Gyro values */ if(TargetBoardFeatures.GyroSensorIsInit) { MOTION_SENSOR_GetAxes(GYRO_INSTANCE,MOTION_GYRO, &GYR_Value); } else { GYR_Value.x = GYR_Value.y = GYR_Value.z =0; } PREDMNT1_PRINTF("%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d\r\n",ACC_Value.x,ACC_Value.y,ACC_Value.z,GYR_Value.x,GYR_Value.y,GYR_Value.z,MAG_Value.x,MAG_Value.y,MAG_Value.z);, }
The output pattern match of UNICO MLC data pattern, so we just capture it on a USB serial terminal (such as MacOS: screen), add the specified header, and save the txt file for every situation, like below:
STEVAL-MKI210V1K (ISM330DHCX) | ||||||||
A_X [mg] | A_Y [mg] | A_Z [mg] | G_X [dps] | G_Y [dps] | G_Z [dps] | |||
495 | 456 | 751 | 9345 | -11016 | 1133 | 426 | 165 | 267 |
495 | 456 | 751 | 9345 | -11016 | 1133 | 426 | 165 | 267 |
468 | 525 | 789 | 12302 | -17915 | -848 | 423 | 163 | 264 |
468 | 525 | 789 | 12302 | -17915 | -848 | 423 | 163 | 264 |
468 | 525 | 789 | 12302 | -17915 | -848 | 423 | 163 | 264 |
.....
The ISM330DHCX support attached external magnetometer sensors though AUX pins and use the data on the MLC. However, the SensorTile Magnetometer is direct connected to the STM32, make the magnetometer data is not available apply to MLC and should omit the external sensor on configuration.
Load the txt data for each condition, label and import the data. Click Configuration and select Acc+Gyro, select mean, variance and max for ACC_X,ACC_Y_ACC_Z,GY_X,GY_Y,GY_Z, click next for default and finally output of .ucf
The C code generation under option used for convert ucf to standard C config.h file, this header content a config[] array for MLC config and the decision tree algorithm. Copy this file to our project include directory.
When initiating , we load the config[] for initialising the sensor and inject the algorithm for the MLC core:
int n = sizeof(config)/sizeof(config[0]); // Load config data for ML engine for(int i=0;i<n;i++){ ISM330DHCX_Write_Reg( MotionCompObj[ISM330DHCX_0], config[i].address , config[i].data ); }
We also enable the MLC1 Interrupt so that the MLC will interrupt the MCU when status predicted.
stmdev_ctx_t* ctx = &(((ISM330DHCX_Object_t *)MotionCompObj[ISM330DHCX_0])->Ctx); ism330dhcx_pin_int2_route_t intRoute; ism330dhcx_pin_int2_route_get(ctx,&intRoute); intRoute->mlc_int2.int2_mlc1 = status; if (!ism330dhcx_pin_int2_route_set(ctx,intRoute) && !ism330dhcx_int_notification_set(ctx, ISM330DHCX_BASE_PULSED_EMB_LATCHED)){ PREDMNT1_PRINTF("theEnabled MLC1 interrupt\r\n"); }
We capture the interrupt event from M_INT2_0_PIN (GPIO_PIN_4) and obtain the result from Machine Learning Core, finally print out on USB UART output.
Testing BootLoaderCompliance: Version 2.0.0 BL Version Ok MagicNum OK MaxSize 0xfc000 OTAStartAdd OK OTADoneAdd OK BootLoader Compliant with FOTA procedure Enabled MLC1 interrupt M_INT2_0_PIN MLC: 0 - 0x00 M_INT2_0_PIN M_INT2_0_PIN MLC: 1 - 0x04 M_INT2_0_PIN
The 0x00 or 0x04 is the result value read from MLC, in this example, 0x00 mean Normal run and 0x04 is error of stepping motor, which is corresponding on UNICO setting.
Thank for the Machine Learning Core and the interrupt, the MCU is free and able to sleep for reduce overall system power consumption, however the MLC is suitable for relative simple machine learning tasks which is not good for too many decision trees or nodes because of limited resources. Carefully considering only include necessary inputs features to optimum the final output to avoid overfitting or bulk nodes.
Next step, we will turn the Sensor.Tile to a wearable heath smart device.
This cube is flexible for established a smarts device start from ST extended open sources SDK. We future implemented a Tai Chi gesture recogniser and integrate to the iOS HeathKit become a calorie tracking, which is a wearable wrist gesture device like Apple Watch but only for dedicated task and relative lower cost.
A simple companion APP developed for received our custom Bluetooth LE packets, translate and record each workout to HealthKit and display the corresponding data on the dynamic list. Either foreground and background, the App will collect and transfer data to HealthKit, and will auto recovery our APP when killed by system due to low memory. However, due to the iOS restriction, disconnected and loss the background monitoring when user force close the APP explicitly (i.e under App Switcher and swipe the running App upwards). In this case, if the bluetooth disconnected and buffer with data waiting to send, the device will broadcast iBeacon's which is a specify identity format advertising though Bluetooth LE.
When the device and iPhone nearby, a notification will be push to encourage the user launch the APP as soon as possible. This APP required any iPhone that support IOS13 (no support IPAD because no HealthKit ) and we use SwiftUI for the dynamic list as well as click it to erase it. In additional, private authorised should be gained from the iPhone Owner.
More Information about iBeacon and HeathKit can be reference of Apple development:
https://developer.apple.com/documentation/healthkit
iBeacon
https://developer.apple.com/ibeacon/
A good youtube video by Leia's https://www.taiflow.com/ is showing what Tai Chi is and the very easy beginning.
The Tai Chi is similar to Yoga, originated as a local religion meditation activities in Ancient Chinese. The theory is everything with an anti-force (just some as Newton third law), when our body movement together with a force come back and we need learn to conscious, balance and harmony of both. As currently, this become a heath spiritual practices, normally the Tai Chi is less harder and slower that Yoga and good for elderly. People classically practice on outdoor such in parks or open air mountain views because feeling naturally is a part of training but never mind it also suitable practice it indoor.
We attached a string as a bands and attached to right hand and record the training data by doing the action showed on this youtube video :
https://www.youtube.com/watch?v=cEOS2zoyQw4
0. 0x00 Rest - normal stand up and no activities (with slightly hand movement)
1. 0x04 Flow - 1.30-2.08
2. 0x08 Updown - 2.12-3.00
3. 0x12 Open 3.07-3.38
4. 0x16 Push 3.40-4.15
5. 0x20 Circle 4.25-4.48
Our model able to identify five types of TaiChi gestures, together with the 0x00 Rest for user stop detection.
Import the training sample data in UNICO, carefully select the configuration and get the final config array.
Firstly, our project started based on the sample FP-IND-PREDMNT1 function pack, which already implemented bluetooth stack, on top of that we change the DeviceID and add new custom services and Characteristic.
Under sensor_service.c function setConnectable(void), we change the DeviceID from 0x02 to 0x92 representative our new device.
uint8_t manuf_data[26] = { 2,0x0A,0x00 /* 0 dBm */, // Trasmission Power //8,0x09,NAME_BLUEMS, // Complete Name 8,0x09,NodeName[1],NodeName[2],NodeName[3],NodeName[4],NodeName[5],NodeName[6],NodeName[7], // Complete Name 13,0xFF,0x01/*SKD version */, 0x92, /* Changed default Sensor.tile DeviceID 0x02 to 0x92 for TaiChi Device */ 0x00, /* AudioSync+AudioData */ 0xE0, /* ACC + Gyro + Mag + Environmental + Battery Info */ 0x00, /* FFT Amplitude */ ... 0x00, 0x00, /* BLE MAC stop */ };
Under main.c Init_BluNRG_Custom_Services(void), we added a new custom Service by implement Add_TaiCHi_servW2ST_Service()
static void Init_BlueNRG_Custom_Services(void) { int ret; ... ret = Add_TaiChi_ServW2ST_Service(); if(ret == BLE_STATUS_SUCCESS) { PREDMNT1_PRINTF("Config TaiChi Char added successfully\r\n"); } else { PREDMNT1_PRINTF("\r\nError while adding Config TaiChi Char\n"); } }
It similar of typical custom service initiation process, as a new set of UUID assigned.
#define COPY_TAICHI_W2ST_SERVICE_UUID(uuid_struct) COPY_UUID_128(uuid_struct,0x00,0x00,0x00,0x00,0x00,0x0D,0x11,0xe1,0x9a,0xb4,0x00,0x02,0xa5,0xd5,0xc5,0x1b) #define COPY_TAICHI_W2ST_CHAR_UUID(uuid_struct) COPY_UUID_128(uuid_struct,0x00,0x00,0x00,0x01,0x00,0x0D,0x11,0xe1,0xac,0x36,0x00,0x02,0xa5,0xd5,0xc5,0x1b)
We assigned UUID -000D- for our taichi services and 0001- for our taichi Characteristic.
We also added a AttributeModified_CB for response gatt attribute change like other done.
static voidTaiChi_AttributeModified_CB(uint8_t *att_data);
Similar of the experiment for stepping motor, our TaiChi APP triggered from MLC1 interrupt and call function getMotionMLData, the tasks are:
The buffer data is waiting for send to IOS device though Bluetooth LE, the default size of buffer is 10, if more than that size, earliest data will dismiss.
SendTaiChiData run on main loop for send out the buffer data to bluetooth. It reconstruct the data for the bluetooth payload, startdate and enddate transfer to UINT16 seconds from current time to avoid time synchronising issue and reduce the payload sizes.
At the end TaiChi_Update(Buff) send out the bluetooth packet.
To minimum the number of packet, each packet is able to send up to four sets of TaiChi gesture data.
{ /* Check have data waiting to send*/ if (!taiChiResultPos) return; if(W2ST_CHECK_CONNECTION(W2ST_CONNECT_TAICHI)) { uint8_t buff[4+W2ST_TAICHI_MAX_BUFF_LEN*6]; uint32_t timestamp = HAL_GetTick(); STORE_LE_16(buff,timestamp>>3); // num of items have been send in this event, max 4 uint16_t num_send = taiChiResultPos>4?4:taiChiResultPos; STORE_LE_16(buff+2,num_send); int i=0; for(;i<num_send;i++){ STORE_LE_16(buff+4+i*6,BufftaiChiResult[i]->type); // Start and End time are the seconds before current timestamp uint16_t start = (timestamp-BufftaiChiResult[i]->start)/1000; uint16_t end = (timestamp-BufftaiChiResult[i]->end)/1000; STORE_LE_16(buff+6+i*6,start); STORE_LE_16(buff+8+i*6,end); free(BufftaiChiResult[i]) } do if(i<taiChiResultPos) BufftaiChiResult[i-num_send]=BufftaiChiResult[i]; else BufftaiChiResult[i-num_send]=NULL; while(++i<BUFF_TAICHIRESULT_SIZE); taiChiResultPos -= num_send; TaiChi_Update(buff); }
Good power management is obviously important for IoT devices, especially many IoT is battery-powered. A great developer should enthusiasm of tweak the power consumption for maximum of battery and the Earth life.
The Slave_Conn_Interval_Min and Slave_Conn_Interval_Max is the value that peripheral (our device) provided to the Host (iOS Core bluetooth) for the suggestion of connection interval. The apple default is 30ms, lower value obtained lower latency and faster speed but require more power, we changed min to 450, and max to 950ms for balance of speed and power. (This only suggestion and may ignore by iOS)
https://developer.apple.com/library/archive/qa/qa1931/_index.html
ret = aci_gap_set_discoverable(ADV_IND, 0x00, 0x00, RANDOM_ADDR, NO_WHITE_LIST_USE, sizeof(local_name), local_name, 0, NULL, 0x0168, 0x02D0);
The System clock have been calm down from 120mhz to 60mhz and change VoltageScalling from BOOST mode to SCALE1.
void SystemClock_Config(void) { ... if (HAL_PWREx_ControlVoltageScaling(PWR_REGULATOR_VOLTAGE_SCALE1) != HAL_OK) { Error_Handler(); } ... RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV2;
When the system idle, push the System to LowPowerRunMode and switch to Low power sleep mode (CPU stopped, and peripherals frequency slow) for additional power reduced.
When the gesture detected, the Machine Learning Core interrupt will be triggered and the System wake up instantly. The bluetooth IRQ also able to trigger the system, so would be wake up when bluetooth disconnected.
HAL_SuspendTick(); HAL_PWREx_EnableLowPowerRunMode(); HAL_PWR_EnterSLEEPMode(PWR_LOWPOWERREGULATOR_ON,PWR_SLEEPENTRY_WFI); HAL_PWREx_DisableLowPowerRunMode(); HAL_ResumeTick();
We also future switch off irrelative GPIO and sensors for future power saving.
By measured the power consumtion using external 5V power supply, the overall power consumption is about 40ma by stock firmware, and our tweak achieved around 23-30ma. Curiosity is by theory the CPU only draw few uA at Low power sleep mode and all other parts is ultra-low power so that the overall current should down to few ma, I suspect the problem come from power and charger IC (SBTC02) or the LDO may draw up some constant power.
The battery performance is approximate drop about 3% for every hour by using the stocked battery (when the battery under 60%). Be notice that the battery level on reference firmware is inaccuracy especially when the battery low or near full, it is because the developing kit is for general battery and the battery level only calculate by a linear regression. For rigorous, implement a look-up table for specified each type of battery.
The kits stocked with 100ma maximum charging speed, which is too slow for real application (can be change Iset resistor for faster charging speed).
iBeacon
The APP will run background and continue connecting and receive the packets from the device, however the APP will lose connection after the user force close the APP explicitly.
In order to encourage the user relaunch of our companion APP to receive the data.We involved the iBeacon advertising so that a notification will display on the iPhone when new data waiting and within the bluetooth range. (The user may switch off this function)
The user can click the TAICHI notifications to launch the APP directly.
The iBeacon have been based on Bluetooth LE, therefore it is possible implementing on top of our bluetooth stack.
Modify inside of Init_BlueNRG_Stack, add GAP_BROADCASTER_ROLE as iBeacon require Broadcaster role.
ret = aci_gap_init(GAP_PERIPHERAL_ROLE | GAP_BROADCASTER_ROLE, 0, 0x07, &service_handle, &dev_name_char_handle, &appearance_char_handle);
Based on Apple specification, the iBeacon broadcast frequency is fixed 100ms interval, in order to iBeacon and discoverable simultaneously, we will switch two mode alternatively every 50ms, so that IOS APP is able to connect the devices instantly when the notification appear on iPhone.
if (!connected && HAL_GetTick()%100 < 50){ // Only broadcast iBeacon when Buff have data waiting to send if (!isBeacon && taiChiResultPos){ setBeacon(); isBeacon=TRUE; } }else{ if (isBeacon){ setConnectable(); isBeacon=FALSE; } }
The setBeacon broadcast the advertising based on the Apple requirement.
0-8 bytes is fixed and specified by Apple, we distinguish ourselves by a unique proximity UUID, Major/Minor all set to 00 ignore it, and set bytes 29 measured power to 0xC6 follow by procedure measured RSSI at a 1 meter distance between the box and iPhone. This value is provided for iOS for distance optimisation.
void setBeacon(void) { /*Set iBeacon avertising packet based on Apple Proximity beacon specification 2.1 */ uint8_t beacon[31] = {0x02,0x01,0x06,0x1A,0xFF,0x4C,0x00,0x02,0x15, 0x00,0x02,0x00,0x00,0x00,0x0d,0x11,0xe1,0xac,0x36,0x00,0x02,0xa5,0xd5,0xc5,0x1b, //custom UUID 0x00,0x00,0x00,0x00,0xc6,0x00}; /* switch off connectable */ aci_gap_set_non_discoverable(); /* switch off scanable */ hci_le_set_scan_enable(0x0,0x0); /*Set advertising parameters for non connectable avertising */ tBleStatus ret = hci_le_set_advertising_parameters(0xA0,0xA0,ADV_NONCONN_IND,0x01,0x01,NULL,0x07,0x00); /* set beacon advertising data */ ret = hci_le_set_advertising_data(0x1E,beacon); /* enable beacon advertise */ ret = hci_le_set_advertise_enable(0x01); }
Full specification of iBeacon can be download on Apple developer site once you accept the license agreement.
Finally we built an iOS Companion APP which is a linker between the HealthKit and our Sensor Box though bluetooth LE, the ST BlueSDK is free at https://github.com/STMicroelectronics/BlueSTSDK_iOS/tree/fefe6de688277bd7d4021d54e60662954b4d0a1a.
The BlueSDK run on top of Apple Core Bluetooth to provide a higher abstract layer for bluetooth LE data exchange.
This APP with a dynamic list showed the taichi workout that HealthKit stored. The APP involve SwitchUI and HealthKit so it is exclusive for any iPhone (no HealthKit in IPAD) on iOS 13 or above. The device name and connection status showed on bottom (debug only), Top is a dynamic list showed the Taichi type (by icon), start and end time, and the calorie (only for demo purpose and may not accuracy for medical use).
The data is all storage under HealthKit locally on the phone, the TaiChi APP is not storage any user sensitive data, write and read access should authorised when the APP first startup.
User is able to track their Tai Chi data on the Apple Health directly and enjoy system level collaborative and security.
The detail of implementation is out of scope of this RoadTest and welcome to future reference on our Git.
Notice that, all custom service and characteristic need explicit and added to the node before connection. iBeacon UUID also required to match our device setting.
ST https://www.st.com/en/embedded-software/bluest-sdk.html#overview provide detail manual for the SDK.
The STWIN SensorTile development kit is a small cube that integrated a range of sensors and mics for wireless industrial node and IoT applications. This kit out of boards provided Android/IOS APP for the reference firmware, in additional, ST also provided open sources software package and libraries for flexible development. This also supplied with a battery and a enclosure make it ideally build of tremendous mobile and portable applications.
Thanks for ISM330DHCX accelerometer and gyroscope with Machine Learning Core embedded, developer can involve trained model for sensors conditional classified and analysis within a single sensor chip, as low latency, power friendly and robustness from the dedicated hardware. It also enhance the security and avoid exploit because the sensitive sensors data processed within a single sensor IC to avoid exposure to external interface or micro-controller. Our TaiChi gesture recognising is fully utilised of the MLC core, it hide all sensor data and only the result value the MCU known.
However, as the WIFI module is optional and not included on the package, so that i am no opportunity to test it. It also lack of connector for common development modules such as Pmod or Mikro make it hard to connect additional testing modules. The battery connector is face down, so that if any issue on development status, the system may halt fully, for solve require remove the mounting screw and take out the battery.
Wide range of high quality ST sensors and mics
Included Li-Po battery and enclosure
ST provided enrich and open-sources development tools
No expandable for common development interfaces (like Pmod or Mikro)
Current version of UNICO no direct support for this kit
Battery charging speed too slow for real product (stock max 100ma, need change Iset Resistor for faster charging)
The sources code for this road test available on:
https://github.com/sicreative/ST_TaiChi
Thanks element14 and ST provide this opportunity for testing this extraordinarily product.
Top Comments
It definitely harder that Arduino or Raspberry as those with more support from community, easy of understand and huge abstract resources available. However you don't need too much programming knowledge…