Indoor Weather Station at STM32L-DISCOVERY

Since childhood, he dreamed of a room thermometer, a hygrometer and a barometer (the lessons of natural history and biology were not in vain). I even bought a wall-mounted version with Soviet-style switchgear, such as this:

But by mistake I was hung on the door leaf and after a while having become unusable, from constant shaking, began to show the same value. The psychrometer scared with its appearance. Yes, and recording evidence every day is a stupid undertaking. Mechanical systems were buried completely with the advent of controllers.

I watched various debug boards for a long time. On the advice of a friend, I bought a STM32L-Discovery debug board from ST, a detailed description here. It sounded tempting that this is an ARM on the core of the Cortex-M3. The heart of the board is STM32L152RBT6. The board also has an on-board programmer and ST-Link debugger and a six-segment LCD display. Do-it-yourself weather station

posts , Thermometer on SHT21 and the presence of STM32L-Discovery inspired the project. Having mastered Keil a bit, instead of loading the example on board, I downloaded another example of the Temperature project - and voila, the thermometer is ready. The microcontroller can measure Vref. It also has its own chip temperature sensor.

Everything would be fine, but this sensor shows the temperature of the crystal, I decided to add a DS18B20 temperature sensor, and it would be nice to master one-wire interface. It turned out that to add something, you first need to get rid of the regular LCD screen, with its 6 characters it occupies almost all the available processor ports.

In the bins of the motherland, an old LCD screen assembled on Hitachi controllers (8 lines of 25 characters each) was

littered. The HIH3610 digital humidity sensor was mentioned in the above article, but the HCH1000 capacitive humidity sensor and HSF1000 barometric sensor were purchased.

So organized the tasks of connecting equipment:
1. Connecting and programming the LCD screen;
2. Connecting and receiving data from RTL;
2. Connecting a digital temperature sensor DS18B20 and reading data from it via one-wire bus;
3. Connecting the HCH1000 capacitive sensor and receiving data;
4. Connecting the HSF1000 piezoelectric sensor and receiving data;

Here is such a device came out:

Connecting and programming the LCD screen

The copy that fell into my hands turned out to be so old that no documentation was found from it. On it were 4 chips HD44102CH and 2 HD44102, and 4 discrete microcircuits the description of which I could not find.
The Reference manual on the HD44102 was found, and there were 8 legs of 4 microchips interconnected and connected to the connector - this is how D0-D7 was found, the power was found by discrete microchips. There were signals RW, E, CS, R / S. In youtub the HLM9301 LCD module was found that looked very similar to my LCD, the Italian on the forum gave a pinout that coincided with the a priori I collected:
1 GND; 2 VCC;
3 contraste (generalmente terminal medio de potenciometro de 10k colocado entre vcc y gnd) 4 NC (no conectado);
5 NC; 6 CS1;
7 CS2; 8 CS3;
9 NC; 10 E;
11 R / W 12 R / S (DATA / INSTRUCTION)
13 D0; 14 D1;
15 D2; 16 D3
17 D4; 18 D5;
19 D6; 20 D7.
But when giving commands the matrix did not show signs of life.
After a long, no less than the previous, search on the Internet, it turned out that the old graphic screens needed a negative voltage for brightness. The DC-DC P6AU0505 converter was turned on, and a precision 200kΩ variable resistor was installed between the brightness output and -5.
Teams from HD44102 came up. The library of work with HLM9301 was written. On the forums, the guys claimed that with Arduino everything worked right away with the standard GLCD library.

The video shows the read data from the internal RTC and thermometer.

Connect and receive data from RTL

The initialization of RTC is as follows:
RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC1 | RCC_APB2Periph_SYSCFG, ENABLE);
RCC_LSEConfig(RCC_LSE_ON); //do not touch LSE to prevent RTC calendar reset
while (RCC_GetFlagStatus(RCC_FLAG_LSERDY) == RESET) {}

Problem: RTC was also reset during reset. The code snippet taken from the demo did something with the LSE - this also reset RTC.
Reading data:
RTC_DateTypeDef RTCDateStr;
RTC_TimeTypeDef RTCTimeStr;
RTC_GetTime(RTC_Format_BIN, &RTCTimeStr);
RTC_GetDate(RTC_Format_BIN, &RTCDateStr);
sprintf(strDisp, "%02d/%02d/%02d %02d:%02d:%02d", RTCDateStr.RTC_Year, RTCDateStr.RTC_Month, RTCDateStr.RTC_Date, RTCTimeStr.RTC_Hours, RTCTimeStr.RTC_Minutes, RTCTimeStr.RTC_Seconds);

Then two new “or” tasks turned out: turn on the ionistor in the microcircuit’s power circuit and switch to “sleep mode” when the supply voltage drops, or attach an external RTC. I think to try both methods ...

DS18B20 Digital Temperature Sensor Connection

Thanks to the articles Stm32 + 1-wire + DMA (continued) and Stm32 + 1-wire + DMA , the onewire.c library was added, but for the STM32L152 processor, port initialization looks a little different:
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_40MHz;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_PuPd  = GPIO_PuPd_UP;
GPIO_Init(GPIOA, &GPIO_InitStructure);          
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3;
GPIO_Init(GPIOA, &GPIO_InitStructure);          

The connection diagram is taken from the datasheet:

Using the article “Search for devices” , the ability to connect several devices to the one-wire bus was added. The resolution of the DS18B20 when reading all 12 bits is 0.0625 degrees Celsius.

Connecting the HCH1000 Capacitive Sensor

You can measure capacitance in different ways, the simplest method is to charge and monitor the voltage drop, taking the time to calculate the capacitance, or evaluate the capacitance by the resistance to alternating current. Honeywell kindly provided a datasheet in which the sensor was the reference value in the generator at 555. I resorted to the last method by assembling a simple generator: It

was not difficult to calculate the frequency. The STM32L152 has several timers that can work in the PWM signal capture mode. Details here .
The difference turned out, as in the case of one-wire port configuration:
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1;                               
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_PuPd  = GPIO_PuPd_UP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_40MHz;
GPIO_Init(GPIOA, &GPIO_InitStructure);

Otherwise, everything in the text in the interrupt subtracts the values ​​of the counters, we get the length of the period, multiplied by the coefficient is the capacity, from the capacity according to the graphs of the sensor we switched to humidity.

HSF1000 piezoelectric sensor connection

I connected the sensor to Vref, GND and to the ADC input. Experience has shown that the accuracy of a 12-bit ADC was not enough to evaluate a useful signal. Connecting the AD8555 instrumentation amplifier in a standard way to the sensor bore fruit. The gain of 10 times was enough to raise the signal level to 0.7V.

Here is the main screen of the device

values ​​on the lines:
1. date time from internal RTL;
2. duty cycle and signal period from the generator, as well as the number of one-wire devices found;
3. humidity sensor capacity and humidity;
4. one-wire identifier;
5. temperature value;
6. voltage value;
7. value of crystal temperature;
8. pressure value.

Project sources here

Also popular now: