Jefenlie YCONGPaul Rodolf P. Castor
Published © MIT

Exploring the Spark-1 (RT-Thread) LCD Interface

This project explores the built-in LCD capabilities of the RT-Spark (Spark-1) development board.

BeginnerFull instructions provided1 hour28
Exploring the Spark-1 (RT-Thread) LCD Interface

Things used in this project

Hardware components

RT-Spark (Spark-1) RT-Thread Development Board
×1
Resistor 10k ohm
Resistor 10k ohm
×1
Resistor 220 ohm
Resistor 220 ohm
×1
Breadboard (generic)
Breadboard (generic)
×1
LED (generic)
LED (generic)
×1
Jumper wires (generic)
Jumper wires (generic)
×1
PTS 645 Series Switch
C&K Switches PTS 645 Series Switch
×1

Software apps and online services

Github: RT-Thread-Studio / SDK-BSP-STM32f407-Spark
RT-Thread STM32CubeIDE (V1.19.0)

Story

Read more

Schematics

Schematics

STM32F407ZGT6 LQFP144 Pinout

LCD Pins Location

5 Switches, 3 LEDs

This setup has already been initialized in “Code 4.”

STM32F407ZGT6 MCU Peripherals

Code

CODE

C/C++
// Code 0:
////////////////////////////////////////////////////////////////////////////////
/* USER CODE BEGIN 0 */
uint8_t switch_Up() { //Used by LCD and REDLED
	return HAL_GPIO_ReadPin(GPIOG, GPIO_PIN_0) == GPIO_PIN_RESET;
}

uint8_t switch_Down() { //Used by LCD and BLUELED
	return HAL_GPIO_ReadPin(GPIOG, GPIO_PIN_1) == GPIO_PIN_RESET;
}

uint8_t switch_Center() { //Used by LCD and GREENLED
	return HAL_GPIO_ReadPin(GPIOG, GPIO_PIN_6) == GPIO_PIN_RESET;
}

uint8_t switch_Left() { //Used solely by LCD
	return HAL_GPIO_ReadPin(GPIOG, GPIO_PIN_2) == GPIO_PIN_RESET;
}

uint8_t switch_Right() { //Used solely by LCD
	return HAL_GPIO_ReadPin(GPIOG, GPIO_PIN_5) == GPIO_PIN_RESET;
}



void RGBLED_Config(uint8_t red, uint8_t green , uint8_t blue) { //leds_set()
	HAL_GPIO_WritePin(GPIOA, GPIO_PIN_2, !red);
	HAL_GPIO_WritePin(GPIOA, GPIO_PIN_3, !green);
	HAL_GPIO_WritePin(GPIOA, GPIO_PIN_0, !blue);
}

void ToggleLEDS() { //light_leds()
	RGBLED_Config(switch_Up(), switch_Center(), switch_Down());
}

void print_switches() {
	if(switch_Up()) {
		lcd_show_string(0, 0, 16, "Button Up is Pressed    ");
	} else if(switch_Down()) {
		lcd_show_string(0, 0, 16, "Button Down is Pressed  ");
	} else if(switch_Left()) {
		lcd_show_string(0, 0, 16, "Button Left is Pressed  ");
	} else if(switch_Right()) {
		lcd_show_string(0, 0, 16, "Button Right is Pressed ");
	} else if(switch_Center()) {
		lcd_show_string(0, 0, 16, "Button Center is Pressed");
	}
}
/* USER CODE END 0 */
////////////////////////////////////////////////////////////////////////////////





//Main:
////////////////////////////////////////////////////////////////////////////////
/* USER CODE BEGIN 2 */
MY_GPIO_Init(); // Your Custom MX_GPIO_Init function to Initialize pins
MY_LEDS_Init(); // Your Custom MY_GPIO_Init function to Initialize built-in LED pins

drv_lcd_hw_init(); // Turns on Back-light, resets the LCD configuration, and initializes the LCD
lcd_clear(BLACK); // Clears everything shown, and changes the background color to white
lcd_set_color(BLACK, WHITE); // Set text color to white, and text background color to black
lcd_show_string(0, 0, 16, "Hello World!"); // Shows "Hello!" to the screen, configured at (x-axis(239max), y-axis(239 max), textsize)
/* USER CODE END 2 */
////////////////////////////////////////////////////////////////////////////////








//Main Loop:
////////////////////////////////////////////////////////////////////////////////
while (1)
{
  /* USER CODE END WHILE */

  /* USER CODE BEGIN 3 */
  print_switches();
  ToggleLEDS();
  HAL_Delay(500);
}
/* USER CODE END 3 */
////////////////////////////////////////////////////////////////////////////////
















//Code 4:
////////////////////////////////////////////////////////////////////////////////
/* USER CODE BEGIN 4 */
void MY_GPIO_Init(void) { //switches_init()
  GPIO_InitTypeDef GPIO_InitStruct = {0};
  
  //__HAL_RCC_GPIOG_CLK_ENABLE(); //Not needed because it is already enable from the MX_GPIO_Init function
  
  // 0 = BtnUp, 1 = BtnDown, 6 = BtnCenter, 2 = BtnLeft, 5 = Right
  GPIO_InitStruct.Pin = GPIO_PIN_0 | GPIO_PIN_1 | GPIO_PIN_6 | GPIO_PIN_2 | GPIO_PIN_5;
  GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
  GPIO_InitStruct.Pull = GPIO_PULLUP;
  HAL_GPIO_Init(GPIOG, &GPIO_InitStruct);
}
  
void MY_LEDS_Init(void) { //leds_init()
  GPIO_InitTypeDef GPIO_InitStruct = {0};
  
  __HAL_RCC_GPIOA_CLK_ENABLE();
  
  // Set as Active-Low, means it is on at 0V, and off at high volts
  HAL_GPIO_WritePin(GPIOA, GPIO_PIN_2, GPIO_PIN_SET);
  HAL_GPIO_WritePin(GPIOA, GPIO_PIN_3, GPIO_PIN_SET);
  HAL_GPIO_WritePin(GPIOA, GPIO_PIN_0, GPIO_PIN_SET);
  
  // 2 = REDLED, 3 = GREENLED, 0 = BLUELED
  GPIO_InitStruct.Pin = GPIO_PIN_2 | GPIO_PIN_3 | GPIO_PIN_0;
  GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_OD;
  GPIO_InitStruct.Pull = GPIO_NOPULL;
  GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
  HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
  
  RGBLED_Config(0, 0, 0);
}
/* USER CODE END 4 */
////////////////////////////////////////////////////////////////////////////////

RT THREAD BUILT IN LCD

Credits

Jefenlie YCONG
4 projects • 0 followers
Paul Rodolf P. Castor
57 projects • 9 followers

Comments