[MM32 eMiniBoard Review] + Green Plant Monitor
[Copy link]
This post was last edited by jinglixixi on 2020-12-8 13:28
Initially, the plan was to use digital sensors to design a device with home environment detection and prompt functions, but the millisecond and microsecond delay functions it relies on were not available, making it difficult to achieve, so the design goal was changed to a green plant monitor.
This green plant monitor is different from the digital sensors used for home environment detection. It uses analog sensors and therefore relies on the cooperation of A/D converters.
The design concept of the green plant monitor is:
The soil moisture sensor is used to obtain physical signals, which are converted into digital quantities through A/D for identification and processing. In addition, in order to provide intuitive prompts, a green plant pattern is displayed on the color OLED screen. When the humidity is insufficient, the pattern will tend to brown according to the humidity value; when the humidity is too high, it will tend to dark green according to the humidity value.
Figure 1 Low humidity status indication
To achieve the functional goals of the design, it mainly relies on the support of the following contents:
1. Pattern processing
After selecting the interface pattern, it needs to be processed accordingly. There are three goals:
1) Due to the size of the OLED screen, the pattern size can only be compressed to 80*80 pixels;
2) To facilitate subsequent processing, change the background color of the pattern to pure black;
3) Use tool software to transform the pattern data into an array and store it in a *.h file for reading to reproduce the pattern.
Figure 2 Green plant pattern
Figure 3 Color change effect without background processing
The display function of the pattern is:
void LCD_ShowPicture(u16 x1,u16 y1,u16 x2,u16 y2)
{
int i;
LCD_Address_Set(x1,y1,x2,y2);
for(i=0;i<6400;i++) // 80*80*2=6400*2
{
LCD_WR_DATA8(gImage_hb[i*2]);
LCD_WR_DATA8(gImage_hb[i*2+1]);
}
}
2. Extraction of Chinese character fonts
In order to facilitate the function prompts, the corresponding Chinese character fonts should be used in the design of the interface. The font extraction is completed by PCtoLCD2002, as shown in Figure 4.
Figure 4: Font extraction
The corresponding Chinese character display function is:
void LCD_ShowChinese(u16 x,u16 y,u8 index,u8 size,u16 color)
{
u8 i,j;
u8 *temp,size1;
if(size==16){temp=Hzk16;}
if(size==32){temp=Hzk32;}
LCD_Address_Set(x,y,x+size-1,y+size-1);
size1=size*size/8;
temp+=index*size1;
for(j=0;j<size1;j++)
{
for(i=0;i<8;i++)
{
if((*temp&(1<<i))!=0)
{
LCD_WR_DATA(color);
}
else
{
LCD_WR_DATA(BACK_COLOR);
}
}
temp++;
}
}
3. Humidity status detection
Humidity detection is based on the soil moisture detection module, and its interface is shown in Figure 5 .
Figure 5 Module interface
Figure 6 Soil moisture detection module
The channel for collecting soil moisture is ADC1_ CH_4 , the pin it occupies is PA4 , and its corresponding configuration functions are:
void ADC1PinConfigWithParameter(void)
{
ADCxAssignPin(GPIOA, GPIO_Pin_4);
}
void ADC1ChannelConfigWithParameter(void)
{
ADC_TypeDef* ADCn;
ADCn = ADC1;
ADCxChannelEnable(ADCn, ADC_Channel_4);
}
4. Icon color change
By extracting the color value of the palette, we can know that the color value of the pattern is roughly #27BB2C , that is : 00100 111 101110 11 0010 1 100 .
In order to intuitively indicate the impact of humidity on green plants, it is designed with a pattern color change processing function, the method is as follows:
The color of the pattern is adjusted according to the detected humidity value. When the soil is dry, the R value is increased to make the color tend to be withered yellow; when the soil humidity is too high, the G value is reduced to make the color darker.
Figure 7 Extracting color values
The procedure for pattern color processing is:
void LCD_Picturechange(u16 x1,u16 y1,u16 x2,u16 y2, u8 c1, u8 c2)
{
int i;
LCD_Address_Set(x1,y1,x2,y2);
for(i=0;i<6400;i++) // 80*80*2=6400*2
{
if(gImage_hb[i*2]>0)
{
if(F==1)
{
LCD_WR_DATA8(gImage_hb[i*2]+c1);
LCD_WR_DATA8(gImage_hb[i*2+1] +c2);
}
if(F==2)
{
LCD_WR_DATA8(gImage_hb[i*2]-c1);
LCD_WR_DATA8(gImage_hb[i*2+1] -c2);
}
else
{
LCD_WR_DATA8(gImage_hb[i*2]);
LCD_WR_DATA8(gImage_hb[i*2+1]);
}
}
}
The main program to realize A/D data acquisition is:
s32 main(void)
{
DELAY_Init();
ADC1SingleChannelInit();
APP_OLED_Init();
OLED_BLK_Set();
Lcd_Init();
LCD_Clear(BLACK);
BACK_COLOR=BLACK;
LCD_ShowPicture(0,0,79,79);
LCD_ShowChinese(70,10,0,16,RED);
LCD_ShowChinese(86,10,1,16,RED);
LCD_ShowChinese(102,10,2,16,RED);
LCD_ShowChinese(118,10,3,16,RED);
LCD_ShowChinese(134,10,4,16,RED);
LCD_ShowNum(96,40,LCD_W,3,YELLOW);
while(1)
{
ADCVAL = Get_Adc_Average(5);
F=0;
if(ADCVAL>sx)
{
K=(ADCVAL-sx)/R;
c1=R_c* K;
c2=0;
F=1;
}
if(ADCVAL<xx)
{
K=(xx-ADCVAL)/G;
c1=G_c* K;
c2=B_c* K;
F=2;
}
LCD_Picturechange(0,79,0,79,c1,c2);
DELAY_Ms(100);
}
}
|