I2C temperature sensor Sensirion STS31 vs Mysentech MTS01Z - Page 1
Forum section: electronics / beginners

author: doru.cazan
author_rank: Contributor
timestamp: February 16, 2023, 06:33:55 pm
content: Hi Everyone,Working on a thermostat and (for now) I have 2 options for the temperature sensor STS31A-DIS from Sensirion (about $2.7 for 10 units at Digikey) or MTS01Z from Mysentech (about $0.8 at LCSC). These sensors are pin compatible, support I2C and have good precision; tested both on the prototype PCBs and both work fine (with a small change of the MCU code since the temperature representation is not the same). Due to the price difference I am inclined to use the MTS01Z sensor, however I am a bit concerned since I could not really find projects online and I am not sure how reliable it is...This is not a commercial product, it is a hobby (more or less since I intend to use it in my house when completed) project.Any thoughts are highly appreciated.Many thanks!(chinese)http://www.mysentech.com/gjdszwdxpmts01xl

author: doru.cazan
author_rank: Contributor
timestamp: May 31, 2023, 05:01:07 pm
content: QuoteHi Everyone, got the message above yesterday and thought that would be a good idea to add few details in case will be useful for someone else...Not very easy to navigate but the manufacturer of MTS01Z has more information on their website:http://www.mysentech.com/For this temperature sensor, the page to look for ishttp://www.mysentech.com/gjdszwdxpmts01xlThere are many .doc, .pdf and .rar files on this page, some containing very useful information.The main MCU I am using is limited so I wanted to save as many bytes (flash and ram) as possible. One thing to avoid was float math that I was not able to achieve with Sensirion STS31 due to the way the temperature is returned. With MTS01Z I am using this code where the I2C functions should be self explanatory except maybe 2nd param for start function: this 2nd param is the number of bytes to be read. Here is the relevant code, concatenated from different project files:Code:#define TEMPERATURE_VALUE_READ_INIT (int16_t)-32256 // -126 Celsius degrees#define TEMPERATURE_VALUE_READ_ERROR (int16_t)-32512 // -127 Celsius degrees#define SENSOR_I2C_ADDRESS_MTS01 0x44#define MTS01X_CMD_MEASURE 0xCC44#define MTS01X_MEAS_DUR_HPM 12#define MTS01X_MEAS_DUR_MPM 6#define MTS01X_MEAS_DUR_LPM 4#define MTS01X_MEAS_DUR MTS01X_MEAS_DUR_HPM// reads temperature, in Celsius degrees, multiplied by 256bool measure_temperature(int16_t *temperature){bool result;int32_t tresult;*temperature = TEMPERATURE_VALUE_READ_ERROR;result = I2C_start(SENSOR_I2C_ADDRESS, 0);if (result){result = I2C_write((MTS01X_CMD_MEASURE & 0xFF00) >> 8);}if (result){result = I2C_write((MTS01X_CMD_MEASURE & 0xFF));}if (result){_delay_us(I2C_END_DELAY_us);I2C_disable();_delay_ms(MTS01X_MEAS_DUR);result = I2C_start(SENSOR_I2C_ADDRESS, 3);if (result){uint8_t t_msb = I2C_read();uint8_t t_lsb = I2C_read();uint8_t t_crc = I2C_read();tresult = (t_msb << 8) | t_lsb;}}_delay_us(I2C_END_DELAY_us);I2C_disable();if (result){tresult = tresult + 10240;*temperature = (int16_t)(tresult);}return result;}Short notes:I needed to have the possibility to replace the temperature sensor hence some of the #defines, with similar code in the project for the STS31 (not listed here)I needed the temperature to be multiplied by multiplied by 256I2C function will be highly depended on the MCU that is used so will not include those hereDid not planned to use the device at temperatures below -100°CPlease let me know and will add details about the Mysentech sensor that maybe I missed.