The story began when a Chinese company named
Hoperf sent me their new
pressure sensors to test. The article describes the main characteristics of the sensors, features, tests and, most importantly, their results in the form of graphs and verbal descriptions of them. At the end of the article, the drivers for these sensors are laid out, as much as possible abstracted from the hardware.

From left to right: HP206C, HP203B and BMP085 from Bosch for comparison (also participates in tests).
Content:
- Test circuit
- Main characteristics
- Internal registers
- I2C protocol
- Tests and results
- Driver
- findings
1. Test circuit
For the tests was collected scheme:
')

It consists of:
- LPC Xpresso debug board with LPC1769 target microcontroller on board, with ARM Cortex-M3 core. However, any 8-bit AVR could easily cope with this task, just the boardboards were busy;
- HP203B and HP206C are connected to I2C0, and BMP085 to I2C1. This was done not because the solder was empty, but because the addresses are the same;
- the screen from Nokia 3310, so purely to display the current information of one of the sensors;
- UART-USB adapter on the CP2102 to display information in the PC;
2. Main features
The table below presents the main characteristics of sensors from datasheets, for comparison.
Characteristic | HP203B | HP206C | BMP085 |
Measured pressure range, mbar | 300 - 1200 | 700 - 1100 | 300 - 1100 |
Absolute accuracy, mbar (at best / worst) | ± 1.5 / ± 3.0 | ± 1.5 / ± 3.0 | ± 2.5 / ± 4.0 |
Relative accuracy, mbar (at best / worst) | ± 0.5 / ± 1.5 | ± 0.6 / ± 1.5 | ± 0.2 / ± 0.5 |
Maximum resolution, mbar / m (pressure / height) | 0.01 / 0.1 | 0.01 / 0.01 | 0.01 / - |
Measured temperature range, ° | -20 - 60 | -20 - 60 | 0 - 65 |
Absolute accuracy, ° (at best / worst) | ± 0.3 / ± 1.0 | ± 0.3 / ± 1.5 | ± 0.5 / ± 2.0 |
Maximum resolution, ° | 0.01 | 0.01 | 0.1 |
Average current consumption (1 sample / s), µA (min / max) | 2.4 / 91.8 | 2.2 / 85.2 | 3/12 |
What are the main differences between these sensors?
HP206C is water-proof, which means it can work in rain / snow / fog, as part of some weather station or as an altimeter on a quadcopter. Its height resolution is also greater than the rest.
HP203B is smaller, has a larger range of measured pressures. With him even in the mountains. Therefore, it is ideal as an altimeter, in mobile devices. These two sensors give the result in human form, not only for temperature and pressure, but also for height, which reduces the load on the processor. The algorithm for calculating the height is directly patented. They also have internal registers to configure. As for
BMP085 , it seems to me that he has outlived his own. It has more disadvantages than advantages. The data comes out raw, which you need to cheat, just like height. Moreover, the algorithm is not the easiest, and even with errors in the datasheet. But according to the test results, he is probably in second place.
In the program plan, the
HP203B and
HP206C are the same, with the exception of the device address on the I2C bus. The
HP203B can be changed by hardware, depending on the level on the leg of the CSB. The command system is very simple. There are only 10 of them:
- SOFT_RST - soft reset (overwrites all settings);
- ADC_CVT (010, 3-bit OSR, 2-bit CHNL) - request for conversion, where:
- OSR - oversampling;
- CHNL - temperature or temperature and pressure;
- READ_PT - read temperature and pressure;
- READ_AT - read temperature and altitude;
- READ_P - read only pressure;
- READ_A — read height only;
- READ_T - read only temperature;
- ANA_CAL - internal calibration of the device (used when there is a sharp change in environmental conditions, it is performed when turned on);
- READ_REG (10, 6-bit register address) - write data to the internal register at;
- WRITE_REG (11, 6-bit register address) - read data from the internal register with the address;
The value of
OSR says how many samples will be averaged. The more, the more accurate the result, but more conversion time and power consumption.
3. Internal registers
Internal registers allow you to adjust the lower / upper limits of temperature / pressure / altitude and enable / disable interrupts for these events, as well as for temperature / pressure / altitude conversion completion events. There is a bit that sets the output format: raw / non-raw (human). What to do with the raw data and how to process them is not specified in the datasheet. Here are all the registers:

- ALT_OFF — relative height shift in cm;
- PA_H / M / L_TH , respectively, the highest, middle and lowest pressure limits (1 bit = 0.02 mbar);
- T_H / M / L_TH , respectively, the highest, middle, and lowest temperature limits;
- INT_EN - enable / disable the corresponding interrupt;
- INT_CFG - output of the corresponding interrupt to INT0 or INT1 pin;
- PA_MODE - 0 - pressure event, 1 - height;
- INT_SRC - flags that indicate the status of interrupts (read only), where:
- PA_RDY - pressure or height ready for reading;
- T_RDY - temperature is ready for reading;
- PA_TRAV — pressure or height passed the middle boundary;
- T_TRAV - the temperature has passed the average limit;
- PA_WIN - pressure or height exceeded the threshold of the specified window;
- T_WIN - the temperature has gone beyond the threshold of the specified window;
- INT_DIR - details of the threshold event:
- T / P_WIN_DIR - 0 temperature (pressure) below, 1 - above the specified window;
- T / P_TRAV_DIR - 0 temperature (pressure) crossed the average threshold from top to bottom, 1 - from bottom to top;
- PARA is a register in which only one bit of CMPS_EN is responsible for the format: 0 - raw data, 1 - compensated (human);
Looking at these registers, we can conclude that these sensors are simply made for quadcopters. Indeed, it is possible to set a height threshold, above / below which the apparatus will not rise, pressure below which the lift force will not suffice, the temperature at which icing can occur. No need to think about what this all works before.
4. I2C protocol
The communication protocol is standard I2C and is as simple as two and two. In total there are 4 types of teams for all occasions. Consider them:
- type 1:

Used to send a command to a device. For example, the start of temperature conversion.
- type 2:

Used to write the internal register of the device, for example, to record the offset offset.
- type 3:

Used to read the register from the device. For example, to read the state flags register.
- type 4:

Used to read 3 or 6 bytes in a row. Used to read temperature value (3 bytes) or pressure and height (6 bytes).
Well, the explanations, which, without that, I think, are clear:
5. Tests and results
Tests were very simple. Once a second, the data was read from the sensors and transmitted to the PC via the UART. On the PC, in Matlab, an m-file is launched, which simply displays the temperature / pressure / altitude value for each of the sensors in the form of graphs, with reference to time. The
HP203B and
HP206C sensors converted pressure with maximum accuracy (
OSR = 4096 ), exactly like
BMP085 (
oss = 3 ).
Lonely
HP203B lying in a room on the table. Explanations right on the chart.

The most interesting thing is that while I was sleeping, from 2 to 7 the temperature changed only by 0.15 ° C. One has only to sit next to him, the radiation from the body immediately makes itself felt. Small peaks on the top chart are connected with these (left / left).

We launch two sensors
HP203B and
HP206C . Both lie side by side in the same conditions:

The noise level immediately catches the eye, which is noticeably less in the
HP206C . But the difference in indications for special connoisseurs of pink:

Connecting
BMP085 :

We carry the
HP206C out of the window, the other two are on the windowsill. The window is closed.

The temperature fluctuations of
HP206C are related to the sun, which in the afternoon reaches my window, and the trees. Then just a couple of graphs with normal behavior:











And now abnormal behavior.

Enlarged fragment of a single
HP203B . Median filter or Kalman does not hurt.

What happened to
HP206C at 6 am remains a mystery to me. Here again something with
HP206C :

Here in general, damn it, take that:

There is a similar behavior:

Again strange behavior:

And now about the interesting:

A sharp jump in temperature and pressure is associated with the passage of the atmospheric front. For the average man this is a sharp rise in the wind and rain with a thunderstorm. But an enlarged fragment, where the parameters of the environment have changed little. For noise comparison:

It can be seen that it is least of all in
HP206C ,
BMP085 goes almost in step, the worst in
HP203B . Well, the last test. In it, I just raised and lowered the whole thing within the room. Heights: bed-ceiling-floor-ceiling-bed. Due to the lower noise level of the
HP206C, the picture looks better. Temperature differences are also funny. Above is really warmer:

On all graphs, with the exception of abnormal behavior, a correlation is noticeable between all 3 sensors. The difference in readings is approximately 1.5 hPa, maximum 2 hPa, which fits into the stated absolute error of each. It is difficult to say whose testimony is the most truthful. To do this, you must have a reference mercury barometer. Everyone can estimate the variance or own noise of each of the sensors, which also correlate with the stated indicators. As for the strange behavior, they always concerned only
HP206C and the only reason for this was that it was outside. But in order to check this, you need to swap the sensors and take measurements. I did not do this.
6. Driver
Since the target device was
ARM with the
Cortex-M3 core, the project was written using
CMSIS and
drivers . However, I met the same I2C bus driver not only for NXP, but also for STM32, which makes it possible to say that they exist on all Cortex-M * cores for each processor family. Below are links to GitHub, where C libraries are laid out for the sensors examined. * .h file for each is the same. The differences are only in * .c files and they are related to the hardware capability of changing the device address on the I2C bus in
HP203B . The code is the most commented. In each * .c file you will find the functions:
- write1byte - send 1 byte (type 1);
- write2byte - send 2 bytes (type 2);
- read1byte - count 1 byte (type 3);
- read3byte - count 3 bytes (type 4);
- read6byte - count 6 bytes (type 4);
These functions are device-dependent. If you use a different kernel or I2C driver, you only need to organize these functions in your own way, if only they perform their task (work out the I2C package) according to the
type and transfer
protocol . The following function initializes a structure that fully defines the I2C package:
static void HP203B_TrasferCfgInit(void) { if(CSB_GPIO->FIOPIN & (1<<CSB_PIN)) TransferCfg.sl_addr7bit = 0x76;
The main thing in it is the address of the device on the bus and the number of transmitted / received bytes. We define this quantity in the above described functions. For the
HP203B sensor
it is possible to select 2 addresses:
0x76 or
0x77 . For
HP206C, it is always
0x76 , as for
BMP085 , however. Further, in the
HP203B_Init function
, we determine the level on the
CSB leg and, depending on our choice, the address fits automatically.
HP203BHP206C7. Conclusions
These pressure sensors are not very bad and will find their niche in the application. So
HP206C is waterproof and dustproof, which allows it to be openly used in weather stations, for example.
The HP203B has a larger dynamic range and smaller dimensions, which allows it to be embedded in mobile devices as an altimeter for climbers, for example. Both sensors are just perfect for quadrocopters, as they have hardware interrupts to go beyond customizable windows for altitude, pressure, and temperature. A nice feature is the human type of output, which does not require additional processor costs. The stated 10 cm difference is unlikely to be registered, except to go through the moving average for a sufficient number of values obtained. We should also talk about technical support. The site contains
codes for working with these sensors for PIC, apparently, and even with assembler inserts, which completely discourages the desire to understand them. Datashit is also very raw. I did not even find in what form the data for pressure come out. Intuitively, it was clear that in mbar or hPa in our, but there is not a word in the documentation. There is also no information on how to process the raw data. I think that the product will be developed, and with it the quality of documentation will be improved. But despite this, I really liked the sensors, maybe my next weather station will be using them.