Wireless Thermometer Clock

Today I want to talk about my experience in working with AVR microcontrollers.

Background
And so, the thing began with the moment of repair of the kitchen and bathroom.

Papa was engaged in the repair, and during the repair he decided to install a warm floor in the rooms. It was decided to install a heating cable as a heat source. Before the installation, cable tests were not carried out because one DS18b20 sensor was still added to the warm floor (yes, one is certainly not enough, but there were no complaints about a very accurate temperature measurement, and the price of the latter is $ 1), with a reserve for installation on the heating adjustment element heating, but as it turned out as a result, it is not so hot to regulate it. One more temperature sensor was brought out into the street.

The result was three signal wires from the DS18b20 sensors, well, three “+” and “-” each.

The whole thing was placed in the bedside table under the sink and recorded until better times (what I was going to do with them, I don’t know, since he almost did not encounter programming, the old school of radio engineering - only analog elements with the addition of integrated circuits).

After some time on the Internet, I noticed an interesting scarf called “ARDUINO”. At that time I graduated from the University in Radio Engineering, and while studying, they tried to tell us something about circuitry but not very successfully, for some reason things were better with digital technology and MK and some knowledge remained.

As a result, out of interest, an order was placed on the Chinese website for the cheapest copy of the “ARDUINO” board. And so began a close acquaintance of MK.
Initially, there were attempts to collect
3D cube
Then there was a seven-segment element, a watch on the MK + seven-segment element.

Next I tried
thermometer clock on the RTC DS1307 chip, MK and a seven-segment element
then it’s on the 128x64 pixels graphic LCD.

At first I tried to write on the standard Arduino IDE, but very quickly switched to Atmel Studio 6.0 (in connection with which the USBasp_H6 programmer was still purchased). The transition was also due to the need to change the frequency of the MK, since the DS1307 at 16 MHz refused to work (I did not manage to make friends the frequency of 1 MHz and the Arduino IDE). The USBasp_H6 programmer turned out by the way, since I successfully burned the MK that was bundled, and ordered 5 new “clean” ones without the Arduino bootloader.

Having played enough, it was decided to make a clock that, in addition to time, will show the temperature from the sensors that were installed on the floor, brought out to the street and the temperature inside the room.

Next were the torment of choosing a place to install the watch. There was no suitable place near the sink, the idea came to put them in the opposite corner (but slightly far away, also the doorway), after which the idea was not very bold to use a wireless method of transmitting information so that the issue of setting the clock would disappear. For sim rummaging through the Internet and in Chinese online stores a pair of wireless modules NRF24l01 was ordered. To get started, I collected everything on a breadboard and tried
transmit numbers.


The first problem was the size of the LCD display (64x128 pixels). As it turned out to draw something on it - takes up a lot of space. After that, I found out that 32Kb is not program memory, but non-volatile memory, and things got easier, I designed all the pictures in a separate file and wrote everything down in EEPROM.

As a result, I came out like this
the code.
#define F_CPU 1000000UL
#include 
#include 
#include 
#include 
#include "my_OWI_ds1820.h"
#include "SPI.h"
#include "nRF24L01.h"
#include "my_i2c_watch.h"
#include "KS0107.h"
void timer_init(void)
void button_init(void)
void get_data(void)		
void show_temp 
void show_time(void)
ISR (TIMER1_OVF_vect)
void noraml_mode(void)
void set_mode(void)
int main(void)
{
	button_init();//инициализация кнопок
	ds_init();//инициализация RTC
	KS0107_Init();//инициализация  LCD
	KS0107_Clrscr(0);//очистка LCD
	SPI_MasterInit();// SPI для радиомодуля
	nRF24L01_init(0b00000011);// инициализация  радиомодуля
	nrf24l01_RX_TX_mode(PRX);// режим приемника
	timer_init();//настройка таймера
	if((BUT_1&BUT_2)==0){ds_write(0,0);ds_write(1,0);ds_write(2,0);cond_1=0;cond_2=0;}//full reset 00:00:00
	sei();//прием данных с воздуха, смена информации на LCD - по таймеру
while(1){
if(BUT_1==1){cond_1=1;}//условие ненажатости
if(BUT_2==1){cond_2=1;}//условие ненажатости	
if (setmode==0){	//обычный режим
if(BUT_1==0){if(cond_1==1){cond_1=0;mode=26;}}	//показ температуры пола
if(BUT_2==0){if(cond_2==1){cond_2=0;mode=100;setmode=1;read_ds_data(&ds_time);convert(&ds_time);}}// переход в режим настройки setmode=1
noraml_mode();
}  //end if (setmode==0) 
else if(setmode==1){//режим настройки часов
set_mode();
	}//end if(setmode==1)
	}//end while(1)
}//end main


The code is not very clear, but there is something, that is.

Further, attempts began to write something for the transmitting side. It didn’t work out so smoothly - the crooked use of radio modules. I could only launch them to transmit 8 bits of information, so I had to beat the data
following code.
//измерить и послать с определенного пина
void mSend(char pin)
{
	int T=0;
	//int x;
	char code0,code1,code2;
	char pack[3]={0,0,0};
	switch (pin){
	case 4:
	T=temp_18b20_4();
	code0=0x10;
	code1=0x20;
	code2=0x30;
	break;
	case 3:
	T=temp_18b20_3();
	code0=0x40;
	code1=0x50;
	code2=0x60;
	break;
	case 2:
	T=temp_18b20_2();
	code0=0x70;
	code1=0x80;
	code2=0x90;
	break;
	}
pack[0]=((T>>8)&0x0F)|code0;
pack[1]=((T>>4)&0x0F)|code1;
pack[2]=(T&0x0F)|code2;
	for(char i=0;i<3;i++){
	nrf24l01_FLUSH_TX;//очищаем буфер передатчика
	nrf24l01_Sent_data_Ret(pack[i]);
	_delay_ms(100);
}}

That is, with this breakdown method during transmission, only 16 variables can be obtained that can be distinguished by the receiver.
Also, as you may have noticed, the DS18b20 sensor polling method is not very well organized, namely, a new function for the new sensor (but since Atmega328p was used and there were no problems with the place, this did not become a big problem), but alas, to sort it out I couldn’t manage to suspend several devices on one bus, just as I couldn’t change the values ​​of the macro indicating the pin on which the sensor hangs during the program.

Having received a more or less ready-made code, I started manufacturing boards (for the benefit of the board, they also tried to teach us how to do it while studying).
Was painted
circuit diagram for transmitter
image

on which the printed circuit board was created (by means of LUT)
image

When designing the transmitter board, there was a condition to make it not very large without special size requirements. Having made the board, having installed all the components in the right places, I checked for operability, and strangely enough it started the first time.
Transmitter Ready
image

When designing the receiver board, the obvious question was the watch case. Since I never saw a 3D printer live, it was decided to look for something in the shape of a rectangular parallelepiped. Therefore, the wall Ethernet socket was chosen for the role of the watch box (unfortunately, there are no initial photos). Not cunning
knife manipulation
image

the hole for the Ethernet ports became the size of an LCD screen. Since the internal structure of the box turned out to be specific, new requirements appeared for the shape and size of the board.
The internal structure of the box
image

Electrical schematic diagram of the receiver
image

Receiver circuit board
image

Etched board
image

The process of assembling the receiver turned out to be more complicated due to the large size and the presence of the DS1307 in the SO case (while soldering, I thought that those watches burned out several times), in addition, a small slip with dimensions appeared.
Having made the board, having installed all the components in the right places, I checked for operability, and for some reason the LCD did not show anything. But fortunately, it was only a lot of resistance on the resistor that was responsible for the contrast of the display.
Assembled Receiver Board
image

What should the finished device look like?
image
image
image

That's all. It remains only to make holes for the buttons, and to the extent possible, fix all the boards inside the box.
Information
The code is written in Atmel Studio 6.0. Programmed through SinaProg2.1.1. It was drawn in Splan70 and layout 6.0 (although I think it is obvious). Pictures for the LCD were made using LCDAssistant.

When creating the code, I actively used this resource . Libraries for working with all devices were taken from there.

Link to the full project on GitHub


Pros:
- configuration necessary in a particular case;
- training, editing hands;

Cons:
- expensive, in comparison with Chinese weather stations.
- For a long time, as for a person who does not have much knowledge in this topic.
- poor code optimization.

PS - if someone has experience in fully launching NRF24l01, please share.
UPD Fully Assembled Device
image

Also popular now: