[EN] Arduino: LGT8F328P

This article discusses how to use Arduino with the LGT8F328P microcontroller, a microcontroller similar to the Atmel AVR atmega328P used on the Arduino Uno and Arduino Nano family, but with additional capabilities such as higher speed and has a higher resolution for converting analog signals and having a digital-to-analog converter as well, so this article will start from properties, board installation and example of using the features of this microcontroller.

(Figure. 1 LGT8F328P QFP32L)


LGT8F328P is an 8-bit RISC architecture microcontroller produced by LogicGreen Technology Co., LTD with 131 instruction sets, most of which are completed in just a clock cycle. The features are as follows:

  • There are 32 8-bit registers (R0, .., R31).
  • The memory of LGT8F328P has 32KB Flash and 2KB SRAM.
  • Two 8-bit Timer/Counter that can be run separately in Prescaler or Compare mode.
  • Two 16-bit Timer/Counters that can be run separately in Prescaler, Compare and Capture modes.
  • There are 9 PWM channels.
  • There is an ADC (Analog-to-Digital Converter) with a resolution of 12 bits.
  • There is a DAC (Digital-to-Analog Converter) with 8-bit resolution.
  • There is a programmable WDT (Watch-dog timer).
  • Support
    • USART
    • SPI
    • I2C
    • TWI
  • EZPROM for internal storage which can be scaled by sharing space with Flash ROM as in the following table.

Figure 2 is the board that uses the LGT8F328P, the QFP32L body, the back, and the arrangement of the pins is as shown in the 3rd and 4th pictures.

(Figure. 2 Top of the board)
(Figure. 3 Bottom of the board)
(Figure. 4 Pins arrangement)

The USB interface is based on Holtek‘s HT42B534 chip, which is a UART/USB converter, supports USB2.0 communication standards, achieves a maximum baud rate of 3Mbps, and operates in the 3.3VDC to 5.5VDC voltage range. Operating in Windows, Android, MacOS and Linux (we use Linux Mint 20.1 as shown in Figure 5), allowing programming to work with a variety of operating systems.

(Figure. 5 Our computer’s spec)

Board installation

The board can be installed in two ways: using JSON and downloading the file in a folder Arduino/hardware.

Installing with JSON

Installing the Arduino IDE to recognize the board LFT8F386P is done by going to the menu File/Preferences as shown in figure 6 and the window as shown in figure 7 will be displayed.

(Figure. 6 File/Preferences menu)
(Figure. 7 Preferences window)

From Figure 7, click on the icon on the right of Additional Boards Manager URLs, a window for inserting board inventory items will appear as shown in Figure 8. Add the following items: After that close the window to return to the program screen.

  • https://raw.githubusercontent.com/dbuezas/lgt8fx/master/package_lgt8fx_index.json
(Figure. 8 List of repositories we used)

Go into the Tools menu, select Board: xxx (depending on which board was previously selected), and select the sub-item Boards Manager … as shown in figure 9 to select to install the board list, type LGT to search as shown in figure 10 and install it after that closes the window

(Figure. 9 Board Manager… menu)
ภาพที่ (Figure. 10 Required lgt8fx’s library)

Finally, select the board list as LGT8F328 as shown in figure 11, and set the port with the frequency that can be selected up to 32MHz as shown in figure 12.

(Figure. 11 Tools/Board:xxx/Logic Green Arduino AVR Compatible Boards/LGT8F328 menu)
(Figure. 12 Setting the clock frequency.)

Install by pasting board data files

This method requires access to download files from https://github.com/LGTMCU/Larduino_HSP by clicking Code/Download ZIP as shown in Figure 12.

(Figure. 12 download files from github)

When you get a compressed file as shown in Figure 13, extract the file by right-clicking on the file to extract it as shown in Figure 14.

Figure. 13 Downloaded file)
(Figure. 14 File extraction)

When the file is decompressed, you will get a folder as shown in figure 15. Go into the folder and you will find a list of hardware folders as shown in figure 16. Copy the LGT folder (Picture 17) in the hardware folder and paste it into Arduino/hardware. In the Windows and macOS operating system, the folder is located in Documents/Arduino/hardware, in Linux depends on the installation if installed from repo it will be located in Documents/Arduino/hardware But if downloaded and installed by yourself, it will be at ~/Arduino/hardware.

(Figure. 15 Folder from zip file)
(Figure. 16 list of folder and files in Larduino_HSP-master)
(Figure. 17 LGT folder we need to move to Arduino/hardware)

Board selection is done by open Tools/Bord:Previously selected item/Arduino AVR Boards (in sketchbook) and then select LGT8F328P-LQFP32 MiniEVB as shown in figure 18. After that, you will get a list of board information as shown in figure 19.

(Figure. 18 Choose LGT8F328P-LQFO32 MiniEVB)
(Figure. 19 Available LGT8F328P-LQFP32 MiniEVB)

Example Code

Example 1

An example program to read ADC values from pin A0 can be written as follows.

#include <Arduino.h>
#define pinADC A0
void setup() {
  pinMode( pinADC, INPUT );

void loop() {
  int aValue = analogRead( pinADC );
  float approxVDC = 3.3*(aValue/1024.0);
  Serial.print("ADC value = ");
  Serial.print(" approximate V = ");

Example 2

The next example is the cosine wave output as shown in Figures 20 and 21.

#include <Arduino.h>
#include <math.h>

#define pi 3.141592654

void setup() {
  pinMode(4, ANALOG);     // D4 
  analogReference(INTERNAL4V096);   //Internal reference source 4.096V 

void loop() {
 for(float i=0;i<(2*pi); i+=0.01) {
  float rad=pi*i;    
  float cosValue = cos(rad);
  long intCosValue = cosValue*300;
  byte dacValue = map(intCosValue,-300,300,0,255);
  analogWrite(4, dacValue);
(Figure. 20 The test board is connected to the graph display board.)
(Figure. 21 Graph from the example)

Example 3

The example code for detecting Prime Number from 2 to 2000, the result is as shown in Figure 22, and when tested with Arduino Uno, the result is as shown in Figure 23. In figure 24 is of Arduino Mega256, however, when looking at the result when using Micropython of ESP8266 in Figure 25, it can be seen that it works fairly quickly. Figures 26 and 27 are the results of ESP8266 written in Arduino with STM32F103C8. However, esp8266 and stm32f103c8 are 32-bit microcontrollers, so they should not be compared seriously with 8-bit microcontroller

#include <Arduino.h>
#include <math.h>

bool isPrimeNumber(uint16_t x) {
  uint16_t i;
  for (i = 2; i < x; i++) {
    if (x % i == 0) {
      return false;
  if (i == x)
    return true;
  return false;

int counter = 0;
uint32_t t0, t1;
void testPrimeNumber(uint16_t maxN) {
t0 = millis();
  for (uint16_t n = 2; n < maxN; n++) {
    if (isPrimeNumber(n)) {
  t1 = millis();

void setup() {
  Serial.print("Found ");
  Serial.print(counter, DEC);
  Serial.print(" in ");
  Serial.print(int(fabs(t1 - t0)), DEC);
  Serial.println(" milliseconds.");

void loop() {
(Figure. 22 Results for finding Prime Number with LGT8F328P)
(Figure. 23 Results for finding Prime Number with Arduino Uno)
(Figure. 24 Result from Arduino Mega256)
(Figure. 25 Result from esp8266’s Micropython)
(Figure. 26 result from esp8266)
(Figure. 27 result from STM32F103C8)


Based on our team’s experiments, the LGT8F328P is fully compatible with the Arduino IDE, running slightly faster than the Atmel 328P at the same clock (usually running at clock_div_2), but at a lower cost, with support for more granular ADCs and a can create 8-bit DAC, which is enough for a board to control devices by communicating with more complex boards such as the ESP8266 as a command via I2C bus and using ESP8266 as IoT communication, etc. Finally, have fun with programming, and feel free to leave comments below.


  1. Ralph Bacon
  3. dbuezas

(C) 2020-2021, By Jarut Busarathid and Danai Jedsadathitikul
Updated 2021-10-09

Leave a Reply

Your email address will not be published. Required fields are marked *