Nuvoton Solution Sharing: IoT Development Based on NUC472 Development Board and Connected to Gizwits
[Copy link]
【Xudong Solution Sharing】Gizwits Cloud Function Board Control Based on NUC472 Development Board
The NUC472 development board is equipped with an Arduino interface. If the interface is used in conjunction with the Gizwits function board, the functions of the development board can be effectively expanded. Currently, there are two core baseboards that support the Gizwits function board, one based on STM32F103 and the other based on ATMEGA328. Using the NUC472 development board to support the Gizwits function board can add a core baseboard that supports it.
As for the Gizwits function board, it provides RGB_LED, small motor, infrared sensor, small button, temperature and humidity sensor, WIFI module and OLED interface, as shown in Figure 1. Here we only introduce the use of RGB_LED, small motor, infrared sensor, small button and OLED interface.
In addition, with the on-chip RTC, UART, A/D and other resources, it also realizes functions such as RTC electronic clock, serial communication and A/D acquisition.
Figure 1 Gizwits Cloud function board
To program the Gizwits function board, it mainly involves building the relationship between the pins, setting the input/output function of the GPIO port and defining the high and low level output statements, reading and judging the input level, simulating the pulse signal and timing, etc.
For ease of understanding, we will proceed in order from simple to complex.
1. Small motor
A small DC motor is provided on the function board, and its interface circuit is shown in Figure 2. It is driven by L9110, and when different voltage levels are applied to both ends of IA and IB, the forward and reverse rotation of the motor can be controlled.
Figure 2 Motor circuit
The connection relationship between the motor and NUC472 is:
The initialization function of the small motor is:
- 1.void MODER_init(void)
- 2.{
- 3. GPIO_SetMode(PC, BIT11, GPIO_MODE_OUTPUT);//IA
- 4. GPIO_SetMode(PC, BIT10, GPIO_MODE_OUTPUT);//IB
- 5. PC10 = 0;
- 6. PC11 = 0;
- 7.}
Use the following high and low level output statements to make the motor rotate, and swap the high and low levels to achieve reverse rotation.
PC11 = 1; //output high level
PC10 = 0; //output low level
2. Small buttons
The corresponding functions can be controlled by using the small buttons on the board. The circuit is shown in Figure 3.
Figure 3 Button circuit
The connection relationship between the button and NUC472 is:
The button initialization function is:
- 1.void KEY_init(void)
- 2.{ // K1、K2
- 3.GPIO_SetMode(PA, BIT10, GPIO_MODE_INPUT); //KEY1
- 4.GPIO_SetMode(PA, BIT9, GPIO_MODE_INPUT); //KEY2
- }
The statement for the K2 key to control the motor rotation is as follows:
- PC10 = 0;
- if (PA9 != 1) //K2
- {
- PC10 = 1; // MANNERS
- }
- else
- {
- PC10 = 0;
- }
3. Infrared sensor
The onboard infrared sensor is used for obstacle avoidance control, and its circuit is shown in Figure 4.
Figure 4 Infrared sensing circuit
The circuit works as follows: at one end of the TCRT5000 is a diode that can emit infrared light, and at the other end is a receiver. In the absence of shielding, the circuit is turned on by irradiation and outputs a low level at the AOUT end. In the LM393 circuit, it acts as a comparator between AOUT and the potentiometer setting potential to produce the effect of a threshold switch. When IR_OUT is low, LED2 is lit, otherwise it is extinguished. The induction switch can be activated by collecting the state of IR_OUT.
The connection relationship between IR_OUT and NUC472 is:
The initialization function of IR_OUT is:
- void IR_init(void)
- {
- GPIO_SetMode(PF, BIT9, GPIO_MODE_INPUT); //IR-OUT
- }
The statements to control the forward and reverse rotation of the motor with IR are as follows:
- if (PF9 != 1)
- {
- PC11 = 1;
- PC10 = 0;
- }
- else
- {
- PC11 = 0;
- PC10 = 1;
- }
4.RGB_LED
Usually, RGB_LED does not require a driver circuit, so it is very simple to use. It only needs to output high and low levels to control whether it is lit or not. However, on the function board of Gizwits, P9813 is used to drive and control RGB_LED. Its interface circuit is shown in Figure 5.
Figure 5 RGB_LED interface circuit
What is so special about using P9813? Its main purpose is to transmit control signals in serial mode and control the brightness of RGB. Usually, this needs to be achieved through PWM. In the process of signal transmission, 32 pulse signals are used to transmit control data to P9813, and then the RGB pins output it to control RGB_LED.
The connection relationship between P9813 and NUC472 is:
- A0-PE1
- SCL- PD10
- SDA-PD12
The initialization function of RGB_LED is:
- 1.void RGB_init(void)
- 2.{
- 3.GPIO_SetMode(PD, BIT12, GPIO_MODE_OUTPUT);//SDA
- 4.GPIO_SetMode(PD, BIT10, GPIO_MODE_OUTPUT);//SCL
- 5.GPIO_SetMode(PE, BIT1, GPIO_MODE_OUTPUT); //A0
- 6.PE1 = 0;
- 7.}
The control function of RGB_LED is as follows:
- 1.void RGB_Write_Data(uint8_t R,uint8_t G,uint8_t B)
- 2.{
- 3.uint32_t RGB_Data = 0;
- 4.uint8_t i;
- 5.RGB_Data |= 0xC0000000;
- 6.RGB_Data |= ((uint32_t)((~B) & 0xc0)) << 22;
- 7.RGB_Data |= ((uint32_t)((~G) & 0xc0)) << 20;
- 8.RGB_Data |= ((uint32_t)((~R) & 0xc0)) << 18;
- 9.RGB_Data |= ((uint32_t)B) << 16;
- 10.RGB_Data |= ((uint32_t)G) << 8;
- 11.RGB_Data |= R;
- 12.for (i=0;i<32;i++)
- 13.{
- 14. if((RGB_Data & 0x80000000) != 0)
- 15. {
- 16. SDA_1;
- 17. }
- 18. else
- 19. {
- 20. SDA_0;
- 21. }
- 22. RGB_Data <<= 1;
- 23. SCL_0;
- 24. SCL_0;
- 25. SCL_1;
- 26. SCL_1;
- 27. }
- 28. SDA_0;
- 29. for (i=0;i<32;i++)
- 30. {
- 31. SCL_0;
- 32. SCL_0;
- 33. SCL_1;
- 34. SCL_1;
- 35. }
- 36.}
[color=rgb(51, 102, 153) !important]
The program to realize the breathing light is:
- uint8_t i=0;
- RGB_init();
- PE1 = 1;
- RGB_Write_Data(0x00,0x00,0x00);
- for (i=0;i<125;i++)
- {
- RGB_Write_Data(0x00,0x00,i);
- delay_1ms(20);
- }
- for (i=125;i>0;i--)
- {
- RGB_Write_Data(0x00,0x00,i);
- delay_1ms(20);
- }
- for (i=0;i<125;i++)
- {
- RGB_Write_Data(0x00,0x00,i);
- delay_1ms(20);
- }
- for (i=125;i>0;i--)
- {
- RGB_Write_Data(0x00,0x00,i);
- delay_1ms(20);
- }
[color=rgb(51, 102, 153) !important]
The procedure to implement the color ring is as follows:
- while(1)
- {
- RGB_Write_Data(120,0x00,0x00);
- RGB_del(5);
- RGB_Write_Data(0x00,120,0x00);
- RGB_del(5);
- RGB_Write_Data(0x00,0x00,120);
- RGB_del(5);
- RGB_Write_Data(120,120,0x00);
- RGB_del(5);
- RGB_Write_Data(0x00,120,120);
- RGB_del(5);
- RGB_Write_Data(120,0x00,120);
- RGB_del(5);
- RGB_Write_Data(120,120,120);
- RGB_del(5);
- RGB_Write_Data(0x00,0x00,0x00);
- RGB_del(5);
- }
[color=rgb(51, 102, 153) !important]
The display effect of RGB_LED is shown in Figure 6.
Figure 6 RGB_LED display effect
The statement to use the infrared sensor as a sensor prompter is as follows:
- if (PF9 != 1) // IR
- {
- RGB_Write_Data(120,0x00,0x00);
- }
- else
- {
- RGB_Write_Data(0x00,120,0x00);
- }
[color=rgb(51, 102, 153) !important]
The effect of realizing the induction prompt is shown in FIG7 .
Figure 7 Unblocked state
5.OLED interface
The function board provides an OLED interface, which is suitable for the SPI interface demonstration screen. Its pin assignment is shown in Figure 8. Since the LCD5110 screen is widely used, this interface is used here to implement the display of the LCD5110 screen. Since the interfaces of the two are not completely consistent, they need to be slightly modified. The specific method is to connect the GND and NC pins to provide a chip select signal for the SCE pin of the LCD5110. Other pins only need to modify the pin definitions.
Figure 8 OLED interface
The connection relationship between LCD5110 screen and NUC472 is:
CS---GND
RST---PD2
D/C---PD0
SDIN--PD3
SCLK--PD6
LED+--PD7
The definition statements for the high and low levels of the output of each pin of LCD5110 are as follows:
#defineSetLCD_RST_High() PD2 = 1;
#defineSetLCD_RST_Low() PD2 = 0;
#defineSetLCD_DC_High() PD0 = 1;
#defineSetLCD_DC_Low() PD0 = 0;
#defineSetLCD_SDIN_High() PD3 = 1;
#defineSetLCD_SDIN_Low() PD3 = 0;
#defineSetLCD_SCLK_High() PD6 = 1;
#defineSetLCD_SCLK_Low() PD6 = 0;
The pin configuration function of LCD5110 is as follows:
- 1.void GPIO_Configuration(void)
- 2.{
- 3. GPIO_SetMode(PD, BIT0, GPIO_MODE_OUTPUT);
- 4. GPIO_SetMode(PD, BIT2, GPIO_MODE_OUTPUT);
- 5. GPIO_SetMode(PD, BIT3, GPIO_MODE_OUTPUT);
- 6. GPIO_SetMode(PD, BIT6, GPIO_MODE_OUTPUT);
- 7. GPIO_SetMode(PD, BIT7, GPIO_MODE_OUTPUT);
- 8. }
[color=rgb(51, 102, 153) !important]
The initialization function is:
- 1.void LCD_init(void)
- 2.{
- 3. SetLCD_RST_Low();
- 4. delay_1us();
- 5. SetLCD_RST_High();
- 6. delay_1us();
- 7. delay_1us();
- 8. LCD_write_CMD(0x21);
- 9. LCD_write_CMD(0xc0);
- 10. LCD_write_CMD(0x06);
- 11. LCD_write_CMD(0x13);
- 12. LCD_write_CMD(0x20);
- 13. LCD_Clear();
- 14. LCD_write_CMD(0x0c);
- 15.}
[color=rgb(51, 102, 153) !important]
The main function is:
- 1.int main(void)
- 2.{
- 3. GPIO_Configuration();
- 4. PD7 = 1;
- 5. LCD_Init();
- 6. LCD_Clear();
- 7. LCD_write_english_string(2,0,"NUC472 +");
- 8. LCD_write_hanzi(2,3,6);
- 9. LCD_write_hanzi(14,3,7);
- 10. LCD_write_hanzi(26,3,8);
- 11. LCD_write_hanzi(38,3,9);
- 12. LCD_write_hanzi(50,3,10);
- 13. LCD_write_hanzi(62,3,11);
- }
[color=rgb(51, 102, 153) !important]
The other functions driving the LCD110 screen display basically do not need to be changed, and the display effect after running is shown in Figure 9.
Figure 9 LCD5110 screen display effect
Since there is relatively little information about NUC472, this article only explores the application of the NUC472 development board with the Gizwits Cloud function board as the topic. Relatively speaking, NUC472 is relatively easy to use.
|