Latest Entries »


Image 1Image 2

89s52  is widely used  IC in 8051 FAMILY.

It is programmed using ICSP with an external programmer USBASP (AVRDUDE).

89S52 has no BOOTLOADER , so it cannot be programmed through SERIAL Port.

W78E052DDG is 8051 compatible 8-bit controller from Nuvoton with 8K programmable flash memory in 40 Pin DIP package

This chip has separate dedicated 2K boot-loader memory, which makes this chip robust and very stable .It supports ISP program downloading from PC using RX-TX lines only.

Other specifications match exactly 89S52.

It contains an 8K-byte Flash EPROM , a 256-byte RAM; four 8-bit bi-directional (P0, P1, P2, P3) and bit-addressable I/O ports , an additional 4-bit I/O port P4; three 16-bit timer/counters ,  a hardware watchdog timer , and a serial port

The instruction set is fully compatible with the standard 8052. Note that the actual part number of the chip in the 40-pin DIP package is W78E052DDG


Because the Nuvoton W78E052D microcontroller comes with a UART boot-loader, it can directly be programmed from the serial (COM) port. You can use “Nuvoton ISP-ICP Utility software” to program the target MCU with the help of a  USB TO RS232 Cable

This cable has CH340 serial IC inside.

Driver for CH340 to be installed in PC , for COM port allotment.

Image 1

The same development of 89S52 can be used for Nuvotone  IC.

Image 2


Note that in this procedure, the MCU’s Reset (RST) pin is controlled by the programmer; hence, a power cycling should become necessary in most situations.

The microcontroller needs an oscillator for its clock generation, so an external 11.0592-MHz crystal with two 22-pF capacitors as shown in the hardware setup diagram is required.

Furthermore, the chip has no internal power-on-reset, so it is achieved externally through the Reset pin using a 10-uF capacitor or 0.1 uf and a 10K resistor.

Image 19

Details of programming from the official Nuvotone site :

For the 8051 MCU products with ISP function, there are two program memories: one is APROM and the other is LDROM. APROM contains the user’s application code for normal operation while LDROM contains the ISP code (cooperating with the ISP Programmer) for updating of APROM.

To use the ISP Programmer to update APROM, the ISP code should always reside in LDROM. If the ISP code disappears from LDROM because of accidentally being erased by a universal programmer, the ISP function will become always failed.

To recover the ISP function, please use a universal programmer to program the Nuvoton standard ISP code into LDROM, and have its CONFIG setting properly configured .

Why is the ISP code easily/accidentally erased by a universal programmer? Because the LDROM is also erased along with the APROM if the user uses a universal programmer to program APROM.

So, it is  strongly recommended  to use the ISP Programmer to program APROM in the beginning of getting the MCU sample with ISP code inside. Don’t use any universal programmer to program APROM unless the ISP function won’t be used.

The difference between ISP (In-System Programming) and ICP (In-Circuit Programming) is that ISP is implemented by software control of MCU itself while ICP is implemented by hardware control. So, before updating the MCU chip, ISP needs a software code (the ISP-code) pre-programmed in MCU’s LDROM to function as software control while ICP doesn’t need any software code pre-programmed.

During ISP operation, the 8051 MCU’s P3.1 behaves as ‘DTA’ (serial data). When ISP is not requested, P3.1 can function as its normal general purpose I/O pin as long as P3.1 conforms to the following requirements: * The state of P3.1 must be logic-1 before the MCU is just released from reset condition. * During the ISP operation, P3.1 cannot be pulled low by the other components connected to it.

Nuvotone Utility IDE is used to dump HEX file on to the Nuvotone Chip.

Download the utility here :


Image 3

Open the Utility

Select ISP BY COM PORT & SELECT THE COM PORT from the drop down menu.

Part no as W78E052D , items to be updated APROM.

Click on LOAD FILE button and browse to the location of the HEX file to load on the APROM Buffer.


Image 3


The creation of HEX file is similar to that of 89S52 using KEIL U-VISION software.

Open KEIL & create NEW Project.

Select Device for target as W79E052D ( selection of 89S52 also works).

Image 1


Image 2

Right click Target & under options for Target click on OUTPUT tab & put a tick mark against


Image 3


Right click SOURCE GROUP & click Add New item to Group.

Select C File & provide a name for the file.

Image 4


Now write your C code & click on BUILD or press F7 key.


Image 5


Image 6

Your HEX file is created under Objects folder.

Image 7


Image 8

Click on LOAD FILE in the NUVOTONE Utility & browse to the HEX file location to select it.

Image 9


Ensure that APROM is selected in the utility.

Image 10


Now click on UPDATE CHIP.

While you see the blue update bar at the bottom you must press the RESET button on the development board.

Image 11


If RESET button is not pressed , you get FAIL report.

Also note that the NUVOTONE Utility must be started in ADMIN mode.


Image 12



Image 14

Once you get the PASS report , you need to press the OK button.

This will execute the file loaded.

Image 15

There is also a P.M selection for multiple IC programming.

Tick mark this P.M & click on UPDATE CHIP.

You can program multiple chips in this mode ,

After RESET you can change the IC & program repeatedly.


Image 13






In the previous post we have seen the installation of PLATFORM IO on VS CODE.

While connecting the ESP32 to PC the PLATFORM IO detects AND ASSIGNS the COM port automatically.

To see the COM port click on DEVICES icon.

Refresh button can be pressed if new connection is made.


Image 36

If more than one COM port is listed , then you can select the COM port manually.

In this demo ,I ‘ve connected  another USB-TTL device with CP2102. To another USB port ESP32

is connected.

Image 37

Click the Refresh button under DEVICES  to view all the COM Ports.Here COM5 is allotted to ESP32 &

COM21 to USB-TTL device.

TO SELECT  COM port 5 Manually, open the platform.ino file.

Add this line at the end.


Save & upload code to see COM port 5 selected & used.


Image 40


Now let us see the solution for the error we encountered in previous post.

Under Arduino.h we received a Squiggle red line indicating error & Intellisense regarding Arduino core was not effective. Arduino.h file was not recognized.

Image 6



If you move the cursor over the Squiggles you see a balloon.Clicking on this shows some solution for the problem.But this was not successful.

Image 8

Finally I got the solution from Plaform IO forum.

Just DELETE the folder .vscode under Explorer.


Image 26

Right click .vscode folder & just DELETE it.





Now close the VS code & restart again .

The Squiggles are gone & new .vscode folder is automatically created.


Image 30

Now Intellisense regarding Arduino.h is working Fine

Image 35



Image 10



In previous posts we programmed ESP32 by Arduino IDE .This post is on a More powerful and advanced IDE

Platform IO installed over VISUAL STUDIO CODE .

VS CODE is a lightweight but powerful source code editor which is available for Windows, macOS and Linux.

VS Code is an advanced Text Editor on which we install PLATFORM IO EXTENSION and use it as IDE to program ESP32 .

The Platform IO is a Python based open source ecosystem for IoT development and a cross platform IDE with a unified debugger .

The PlatformIO supports many Platforms, Frameworks, Boards like Arduino, ESP32, ESP8266,STM32,NUCLEO and includes examples and libraries.

clip_image002         clip_image004          clip_image006

Instead of VS CODE , we can use ATOM Text editor .

But ATOM editor requires CLANG installation for Code completion facility.

Platform IO on VSCODE is the next generation IOT IDE which supports programming of a wide range of boards like Arduino, ESP32,STM32 & NUCLEO.



Visit this link for a detailed comparison between ATM & VS CODE Editors

VS CODE has advanced

Intelligent Code Completion , Smart Code Navigation & Code Formatting

Advanced Debugging tools like

Conditional Breakpoints , Expressions and Watchpoints

Memory Viewer , A hot restart of an active debugging session

As VS CODE offers key features, let us proceed with VS CODE installation.

Download the Windows installer suitable for your PC ( 32 or 64 bit).

Before starting the VSCODE installation, ensure that your PC has PYTHON.

Visit this link to download Python



Select the version 2.7.xx to install & not the 3.7.xx version.

2.7 version best supports Platform IO.







While installing Python , ensure that you enable ADD PYTHON.EXE to PATH & entire feature is installed on your local hard drive.





Finish the PYTHON installation & start with VS CODE installation.







clip_image008   clip_image010


Ensure to tick mark ADD TO PATH during installation.





clip_image014  clip_image016


Once the installation is over , click FINISH to launch VS CODE.

A dark IDE APPEARS  after a while.


TO the left side of IDE you see a list of control Icons.


Click on EXTENSIONS ICON  to visit the market place add on s.



A new search bar appears , where you type in PLATFORM IDE.

Select the PLATFORM IDE & click on the green INSTALL button.




Installation takes a while & finally the PLATFORM IO ICON appears.

The first initialization requires Internet connection and may take a while(need to install dependent toolchains, frameworks, SDKs).


At the bottom of IDE PLATFORM IO control Icons appear.







If you prefer a light skin , go to File –> Preferences & click on Color Theme.




From the list of Skins you can select a light skin .



You need to click on Platform IO Home button for the new skin to be effective.



At the center of IDE you can see some PLATFORM IO icons to add Libraries , Boards , Platforms& Devices

Under QUICK ACCESS list click on + New Project to create a new one.

You can also click on Project examples or Import Project to download one.


Provide a name to the project.

Against Board , search for ESP32 & select the correct board you’re using.Mine is DO IT ESP32 DEVKIT V1.

Against Framework select ARDUINO.

Click OK to create the Project.




Now under the left side Explorer window , the new Project (led_blink) appears


Locate the folder src , under which you find main.cpp file.

Click on it.



Here is where you write your code.

The code starts with #include <Arduino.h>

If you find a squiggle under line beneath it , then the path to header file is not defined.

The solution to this problem is explained in next post.

For now, proceed with the code.The squiggle indicates error & Intellisense regrading Arduino core will not show up.But you can complete typing the code & upload.Everything else works fine.



Let us blink the inbuilt LED on board ESP32 which is mapped to GPIO2.

While typing the code you can see the Code completion in action , which is handy while working on big projects.You need not remember the variables & functions declared.



Click on the tick mark at the bottom row of icons to Build or Compile the code.

Or you can directly click on ARROW button to upload the code.







While Upload is in progress PRESS & HOLD the BOOT button on ESP32 .



Once the code is uploaded , you can see the on board Blue LED blinking.

Now let us explore the Serial monitor capability of the IDE.

Under setup() add


The default baud rate is 9600.

Under loop() function Serial.println the message LED ON or LED off.

Upload the code & then click on the PLUG symbol seen at the bottom row of Icons.

Now the Serial monitor opens displaying the LED ON OFF message/


Image 25


To change the BAUD RATE , click on platformio.ini file under project files.

At the right side you see the platform,board & framework setting we selected while creating the project.


At the bottom add this line


where 115200 is the new Baud rate.



Now save the file & upload.

Open the Serial monitor (PLUG symbol) to see some garbage message printed.This is because the IDE Serial monitor baud rate has been changed to 115200, but in code we have initiated



Image 33


Click on main.cpp & replace 9600 with 115200.



Image 34



Save the file & upload again.

Open the Serial monitor to see the LED ON OFF message with new baud rate 115200..





In this post we shall see how PWM is implemented on ESP32 & used to fade an LED or control speed of a motor.

In Arduino or ESP8266 Nodemcu we used the analogWrite() function to achieve PWM.

But Analog Write function is not yet implemented in ESP32 Arduino version.

Instead a new Function called ledcWrite() is introduced.

As the analogWrite()  function is not yet available for the ESP32 , we will need to go to lower level functions.We will also have more control and flexibility in the PWM functionality, which is good.


Image 15

In this example let us fade the inbuilt LED onboard. It is mapped to GPIO2 pin.

We declare some variables to start with. GPIO2 pin is assigned to a byte variable led_pin as 2.

2 more integer variables used to store brightness & fadevalue.

Image 2

Inside SETUP first thing is , we need to attach a channel ( channels available from 0 to 15) to a GPIO pin  where we want the PWM signal to be generated.

Any GPIO pin can be used , but certain pins which are only INPUTS like GPIO 14,15,16 & 19 CANNOT BE ATTACHED.


GPIO OUTPUT capable pins can only be attached. The function used here is


In this example, we’ll get the signal in the led_Pin GPIO, that corresponds to GPIO 2 ( inbuilt LED). The channel that generates the signal is the ledChannel, that we assign  to channel 0. There are 16 PWM channels from 0 to 15 in ESP32 & one of them is attached to a GPIO pin.


Next , PWM characteristics are then defined using function


e.g ledSetup(0,12000,8);

Here the first parameter is the channel number  (channel 0 is used here)

2nd parameter is the PWM Frequency ,here it is 5000 ( 5kHz) which is idle to fade an LED

3rd parameter is resolution in bits .Upto 16 bits accepted. Here we use 8 bits , so the maximum analog value is 255 ( 0 to 255 = 256)

We’ll use 8-bit resolution, which means you can control the LED brightness using a value from 0 to 255.


Finally, to control the LED brightness using PWM, you use the following function:

ledcWrite(channel, dutycycle)

This function accepts 2 arguments a channel number & an analog value (duty cycle)

Note that we use the channel that is generating the signal, and not the GPIO

Although the duty cycle is  specified as a percentage, this function receives a value between 0 and another value different from 100.We can pass a value between 0 (wave always with a value of GND) and 1023 (wave always with a value of VCC for 8 bit resolution) for the duty cycle.



const byte led_pin = 2;

int brightness=0;

int fadevalue = 5;

void setup() {

ledcAttachPin (led_pin,0);

ledcSetup(0,5000,8); // channel 0, pwm freq 5 khz, Resolution 8 bits


void loop() {



if(brightness <=0 || brightness >= 255) {

fadevalue = -fadevalue;






Inside the loop we vary the duty cycle from 0 to 255 to increase brightness of LED gradually & when it reaches vaLue 255 , we decrease it thus fading down the LED.

Now upload the code.Press & Hold the Boot button for a smooth upload.

Once code is uploaded , you can see the inbuilt blue LED fading.


In the second example let us add a potentiometer ( 10k value) to GPIO4.

One end of pot is connected to +3.3v , the other end to GND.

Center pin of pot is connected to GPIO4.

LED connected to GPIO15 is faded according to pot variation.





Image 3





const byte led_pin = 15;

const byte pot_pin = 4;

void setup() {

ledcAttachPin (led_pin,0);

ledcSetup(0,5000,8); // channel 0, pwm freq 5 khz, Resolution 8 bits


void loop() {




Inside loop() function we use the ledcWrite() function , so that according to pot variation LED brightness varies.

With the same code uploaded , we can control the speed of a motor.



Potentiometer is connected to GPIO 4 as in 2nd example.

To control a motor we need L293 driver board.As the motor used is a BO motor of 6v we need a separate power source for L293. A 6v battery is used for L293 Board.




L293 board can control 2 DC motors & it sources 500ma current.For control of each motor 2 set of control pins are provided.

IN1,IN2,EN1 for 1st motor & IN2,IN3,EN2 for second motor.In this example we use only one motor.So the first set of control pins are used.

For forward control of motor IN1 is connected to LOW  , 0 , & IN2 is connected to HIGH  (1) .

A built in 5v regulator is on board L293. This 5v pin can be used as HIGH & GND pin is used as LOW.

Ensure that GND pin of L293, Negative of 6v battery & GND pin of ESP32 all are made common & connected together.

EN1 is the enable pin which can also be used by PWM to control speed.If this pin is pulled High , then the motor will rotate at fixed speed.To vary speed we connect this EN1 pin to PWM pin of ESP32

, which is GPIO15 in our example.





Now you can vary the potentiometer & control the speed of motor.






ESP32 has some useful inbuilt sensors like TOUCH SENSOR & HALL EFFECT SENSOR.

Temperature sensor is not yet implemented & not working in ESP32.

A total of 10 Touch sensors T0 to T9 are multiplexed with GPIO pins of ESP32.

Touch sensor T1 is mapped to GPIO0 , which is pulled low while uploading code, is NOT available for the user & a physical GPIO PIN is not available with ESP32 DEV KIT V1.

Other 9 touch sensors are available for the user.

Touch T0 is available at GPIO4 & multiplexed with AD2_0 . Similarly Touch T2 is mapped to GPIO2, multiplexed with AD2_2.

Check out the PIN Configuration as shown in image below.



Image 6


Let us test T0 touch sensor at GPIO4.

Just connect a male to male jumper wire at GPIO4 , which acts as our touch sensor.

Connect ESP32 to PC & note the COM port allotted.

Under Tools of Arduino IDE select the Board as ESP32 Dev Module & choose the right COM port.

Image 10


Under FILE –> Examples –> ESP32 –> Touch

Select the example sketch  TOUCHREAD.

Image 1


Image 8

This Sketch uses the touchRead() Function to read T0 sensor & prints the value on Serial monitor.

Upload the Sketch.

Press & hold the Boot button while you see connecting.. at the bottom of IDE.


Image 11


Image 12

Once the code is uploaded , open the Serial monitor of IDE

Select the Baud Rate as 115200

Random values are printed on serial monitor.

Touch the wire connected to GPIO4 (TOUCH SENSOR T0)

The value drops below 10 , when the wire pin is touched.

Image 13

Thus TOUCH SENSOR works as expected.

Image 3

Let us connect an LED  at GPIO15 through a resistor to Ground .

The male to male jumper wire acting as Touch sensor is at GPIO4.

Image 14

Modify the sketch accordingly.

Define the LED_PIN as 15  (GPIO15)

Under loop function we set a threshold value for T0 as 20. If the value drops below 20 then the LED is made ON , Otherwise OFF.

Image 001

Upload the sketch.

When you touch the sensor at T0 , the LED goes ON .

When T0 is not touched the LED is OFF.

Image 4


The next sensor is HALL EFFECT sensor which detects Magnetic field.

The Hall Effect sensor works on the principle of the Hall Effect of magnetic fields. The sensor will generate a voltage that indicates whether the sensor is in the proximity of a magnet or not.

From examples select the HallSensor sketch.

Image 2

This sketch uses hallRead() function & assigns the value to a variable, which is then printed on Serial monitor.

Image 002

Upload the sketch & open the Serial monitor.\

Set the baud rate to 9600. You can see some random values flowing in.Note that if the baud rate is not selected as 9600 , there will be no result seen.

Bring a magnet near  the ESP module .

You can see a value printed according to the strength of the magnetic field.


Image 5

If you reverse the poles of Magnet , you can see negative values.

Image 6

If you bring near a powerful magnet , then the result value will be higher.

Image 7

Instead of Serial monitor view , you can also see graphical representation.

Close the Serial monitor & then from under Tools select the Serial Plotter to see the graphical



Image 8

Video :


ESP32 #1 Arduino core installation



ESP32 module is built on 32 bit ESP-WROOM-32 & can be programmed with Arduino IDE. Old method of installing Arduino core is through GIT. New & simpler method is through BOARDS MANAGER.

My previous video on GIT installation is here.

If you had already followed this GIT procedure , then delete the folder espressif inside Arduino directory (generally the path is Documents/Arduino/hardware )

Find the espressif folder & delete it manually.

First time users can proceed directly further.

The ESP32 module is slightly bigger than the NodeMCU module .But much powerful than NodeMcu. ESP32 has more ADC pins, more UART pins ,PWM, communication protocols like CAN, IIC, SPI,

DAC Channels , 16MB FLASH ,512KB RAM , Bluetooth BLE & WIFI enabled.

ESP32 DEV KIT V1 is generally available in market and pin configuration slightly different from that of WEMOS or Adafruit make.


Two micro buttons are on board .One to the right of micro usb socket is the BOOT button.Generally while uploading any sketch on to ESP32 , YOU NEED TO PRESS & HOLD this BOOT button.

EN button acts as RESET button.

All GPIO pins are 3.3V LOGIC & not 5v ,please note.

Let us begin with Arduino core installation using the much simpler BOARDS MANAGER

Open the latest ARDUINO IDE.

Go to File —> Preferences

At the bottom you find the Additional Boards Manager URLs bos

Copy & paste the following link there.


Image 1

If you had already installed Arduino core for NodeMCU , you may find a link already here.Use a comma after the existing one & paste the new link. Click OK.

Go to Tools –> Boards & click on Boards Manager

A new window opens.

Type in ESP32 in the search window

Select esp32 by Espressif systems & click on INSTALL .

You need Internet connection for this installation which takes few minutes.


Image 2

Once the installation is completed you can see under File –> Examples –>ESP32 with some official example sketches.


Image 3

Now connect your ESP32 to PC & note the COM port allotted from the Device Manager.

For this you should have already installed the Silabs cp2102 driver.

As ESP32 USB functionality is provided by a CP2102IC  you need this driver installed.


Image 1

Under Tools , ensure that the Board is selected as

ESP32 DEV MODULE , upload speed & others left to default.

Correct COM port to be selected to which ESP32 is connected.

Image 2

Once the board & COM port are selected , open the BLINK sketch

Image 3

The built in LED on ESP32 is mapped to GPIO2.

Add this line before void setup()

#define LED_BUILTIN 2

We use only the GPIO pin number in code & not the word GPIO2


Image 5

Click on UPLOAD

Image 5

While the Compiling is over , you see Connecting….. at the bottom of IDE.

Now Press & Hold the BOOT button on the ESP32 board.

Image 6

The code is uploaded & you can see the onboard Blue LED blinking.

Image 7


VIDEO Support :




USBASP programmer is widely used to upload  .HEX file on to AVR / 8051 ICs.

On Windows 10 PC you may face some driver installation problems.Check out my previous blog on how to install drivers.

While connecting USBASP to 8051 development board , take care that GND pin matches GND of both boards.

No separate power source required for development board.It can source from USB itself.



Connect USBASP to PC .

Install driver from link below:

USBASP Driver :

Once driver is installed , under Device Manager USBASP appears.


Image 1


PROG ISP software IDE is used to upload HEX file on to 8051 IC.

Download link is below


No installation is required.Unzip the downloaded file and double click on PROGISP application.

On top you can see two blocks ,  PRG ISP &  USBASP

PRG ISP will be greyed out if programmer is not found on not connected.

USB ASP will be greyed out if driver is not installed.

Ensure that these two blocks are not greyed out.


Image 2

Select your IC from drop down menu. 89C52 or 89S52   , select the correct part no.

Click on Erase button.

If the usbasp device is ok , the erase will be performed.

Here Im getting the infamous CHIP ENABLE Error.


Image 3

This error persists even after , Programming power  adjusted using slider & Verify Signature tick mark  removed .

CHIP ENABLE error occurs if the IC is not placed correctly on ZIF socket of development board or if the wrong Chip  is selected.

If still the problem persists , then you need to upgrade FIRMWARE of USBASP.

For this we use ARDUINO UNO in ISP mode.




Connect UNO to PC & note the COM port allotted.

Open Arduino IDE .

From Tools select the board as Arduino UNO, Port as COM port allotted

Programmer is selected as ARDUINO AS ISP.


Image 4

Under File  –> Examples  –>  select  ARDUINOISP

Upload the sketch. Now Arduino is ready as ISP programmer.


Image 5


Now download the USBASP Firmware from the developers website

usbasp Firmware

Image 6

Download the .tar.gz file & unzip twice. Under bin –> firmare you can see the Atmega8 firmware file in .hex format.

Note the path where this file is saved.

To upload firmware we use AVRDUDES GUI application

Download it from link below and install it.



Connect Arduino with USBASP as follows :


5V        —>  Vcc

Gnd      —>  Gnd

10         —> RST

11      —>  MOSI

12       –>  MISO

13       —>  SCK


Connect USB of PC to ARDUINO  ( not to usbasp)

Arduino is Master and USBASP is slave



Select Programmer as ARDUINO

COM port as port allotted to Arduino

Baud rate 19200  ,if you try any other baud it shows time out error.

Bit clock –leave it blank

Target MCU select as ATMEGA8

Under FLASH click on …  and browse to select the firmware file  we downloaded earlier.

Fuses can be set as  Low Fuse  : 0xFF  , High Fuse : 0xE9,  select tick mark against SET FUSES.


Image 7

Now click on DETECT

I get an error saying signature 00000 , which means target is not detected.


Image 8


If you check the schematic of USBASP , a jumper JP2 is to be ON to enable self programming.

This jumper is between pins 1 & 16 (slave select pin) of USBASP IC.


As my USBASP is not having this jumper I soldered a 270E resistor between pins 1  &  16.







Target is detected & the signature of ATMEGA8 is 1E9307.


Image 10

Now on clicking PROGRAM button , the firmware is flashed successfully.

I just removed the resistor and tried uploading hex on to 8051 successfully.



Let us see the second method of upgrading firmware .

Here we use another working USBASP programmer instead of ARDUINO.

Connection is one to one

Vcc to vcc , Gnd to Gnd , MOSI toMOSI , MISO to MISO , RST to RST



On target USBASP a 270 E resistor soldered between pins 1 & 16.



PC is connected to  Master USBASP.


Select programmer as USBASP , port as USB , Baud as 19200

Bit clock will be automatically selected as 1.5MHz


Image 12

Click on Program to see the firmware upgraded successfully.

This method is slower than Arduino method.

Ignore any SCK clock error which occurs due to un success full bit clock setting.

Image 13

























NEX31     NEX21


VIDEO Support  :



Nextion is a  Human Machine Interface (HMI) programmable Touch Display.

Nextion includes a hardware part (a series of TFT boards) and a software part , NEXTION EDITOR.

The Nextion TFT board uses only one serial port to communicate. It lets users avoid the hassle of wiring. On board a 32 bit ARM processor is used STM32F030.

Nextion editor has mass components such as button, text, progress bar, slider, instrument panel etc. to enrich the interface design. Furthermore, the drag-and-drop function ensures that users spend less time in programming. With the help of this WYSIWYG editor, designing a GUI is a piece of cake.

BASIC & ENHANCED Models are available.

Basic models :

NX3224T028            NX4024T032      NX4832T035

Notes: NEXTION product numbering rules , eg. NX4024T032

40 -Horizontal resolution: 40=400
24 -Vertical resolution: 24=240

T  -Series model: T=Basic Model     K=Enhanced Model
032 -Display size:”032″ means 3.2 inch
R   -Touch screen type:N=non touch; R=resistive touch; C=capacitive touch

All basic models  are resistive touch screen display, 4M Flash, 3.5KByte RAM, 65k colors., except 3.5 inch model which has 16M Flash.

Before starting the project ,let us collect the essentials.






Image 6


Inkscape editor is required , if you need an image in your project. Using INKSCAPPE we can convert the image resolution to match that of Nextion display.

First , download theITEAD LIBRARY file  & unzip it. Copy the folder & paste it to C:/Program files/Arduino/Libraries

Rename the folder to Nextion.

Image 7

Open the Nextion folder & locate NexConfig file.

Right click and select Edit with Notepad++


Image 8

As the library is designed for ARDUINO MEGA , we need to do the following modifications in Configuration file , so that ARDUINO UNO can be used.

Image 9

Comment lines 27 & 32.

Change Serial2 to Serial at line 37.

Save the file,

Next , we download an image background for the project and use INKSCAPE to convert image to match our Nextion display which is 400 x 240 resolution.

You can download wanted imaged from

Huge collection of Both free and paid images are available for download.


Go to File –> Document Properties

Set the UNITS to PX (Pixel) ,Width as 400 & Height as 240 ( which matches our NEXTION Display Resolution),

Image 23

Close the Document properties. A new Canvas of size 400 x 240 is created .

Now click File –> Import and browse to the location of the downloaded image file & select it.


Image 24

The image is loaded on to Inkscape.You can see drag Handles on all sides of the image.

Use the handles to pull so that the image size fits inside the Canvas created,

Image 25

Click View –>  Zoom –> Selection

to Zoom the  picture.


Image 26


Now drag the handles so that the image fits exactly inside the 400 x 240 Canvas


Image 27

Click on File –> Save as and select the CAIRO PNG type to save the image.


Next proceed with the NEXTION EDITOR Installation.

Open NEXTION Editor.


Image 10

Click on File –> NEW & within a folder create  a new file , say ledonoff.

This will be stored as .HMI File.

On the next window select the model of NEXTION Display you have.

In my case it is 400 X 240 2.3 Inch.

Select the model & then click on DISPLAY

Image 11

Here select the orientation of display as 90 – HORIZONTAL

You can also select vertical if you have created vertical  image and  like to have vertical


Image 12

A canvas of size width 400 x  height 240 is created inside Display area of Nextion Editor.

Image 13

Now we have to generate a FONT file.


Select Height of Font & type of Font.

Provide a name for the file.

Image 14

Click Generate Font to see a .ZI font file created.Save that in the project foldet.

Finally click the “Add the Generated Font” message.

You can see the font file added to the FONTS Area.


Image 15

Next click on PICTURE tab . Then click the + symbol.

Image 16

Browse to the location of the image file ( 400 x 240) we created earlier using inkscape.

Select the image file , so that it is loaded inside the PICTURES area.

Image 17

Click on PICTURE under TOOLS area.

Then at the right side ATTRIBUTE Area you can see the id of the image as 1, object name as p0

Below that against pic , empty space iseen

Double click on the empty space against pic to see on a new window the picture selected .

Image 18

Select the picture seen on new window & click ok.

Image 19

Now the image fits inside the canvas created.

You can click on DEBUG to see if any error is generated.If any error seen then you have to create again the image exactly of size 400 x 240 using inkscape.

Image 20]


Next add 2 Buttons & a Text over the image by clicking on the elements under Tools area.


Image 22


Click on the first button and go to Attributes area.

Here you can see the id of the component as 2, object name objname as  bo.

Write down these attributes , which will be used in coding.

Scroll down to txt and change the name to LED ON.

You can also change the name of objname , but we leave it as b0 as generated.


Image 28

Same way click on second button and note the attributes  id 3 , objname  b1

Scroll down and select txt , change name to LED OFF.


Image 30

For the third element , just change the txt to STATUS.

You can drag the text element to make the text area bigger.

Image 31

Now click on first button LED ON.

In the EVENT Area click the TOUCH RELEASE EVENT & then put a tick mark

against Send Component ID

Image 32

Do this for the second button LED OFF , also.

Click the DEBUG button to start the simulator.

Now you can see the display created with buttons and Status text bar.

Click on the LED ON button.While you release the click, a HEX code is generated

inside the simulator return area.

65 00 02 00 FF FF FF

65 is the Touch Detection code

00 is page ID which is page 0 for our project.

02 Component ID which is 2  (LED ON button)

00 Button Release event

FF FF FF  End of Message

Image 34


Similarly click on LED OFF button.

While  released you see the following code

65 00 03 00 FF FF FF

Here you can see the 3rd hex code as 03 which is component id of LED OFF button.

This hex code is available at the serial port of display when the event occurs.

So we can easily read this code and decide on which button is operated.



Check out the full instruction  set wiki here :


Click on COMPILE button to generate the .TFT file.

This is the file to be uploaded on to the Nextion display.

To see the file generated go to File –> Open Build Folder

which opens a folder named BIANYI inside which you find the generated file.

Copy this file and paste inside your project folder.


Image 35


The .TFT file can be uploaded on to NEXTION display by 2 methods .

One is the USB – TTL method where we connect USB-TTL device to serial port of display.

5v to 5v , GND to Gnd , Tx to Rx , Rx to Tx

Connect the usb-ttl to PC and note the serial COM port allotted.

Click on UPLOAD button on the NEXTION Editor.

On the upload window select the COM port & set the Baud Rate to maximum , 115200.

As this method is slower , it is better to set high baud rate,

Click GO.

Image 39


Now you can see the file uploading info on screen and finally you can see your design on Nextion display.

Image 38


Image 40


The second method is SD card method.

Use a card reader to hold SD card and plug it to PC.

Select the SD card drive , right click to FORMAT.

Ensure that the SD card drive is selected, set the format to FAT 32,and click ok.

Once formatted , copy the .TFT file we compiled earlier,from BIANYI Folder to this SD card drive.

No other file should be in card.

Remove SD card and plug it on to Nextion Display.

Provide power to display.You can use the USB-TTL and connect only the 6v and GND.

The file gets loaded faster compared to other method.

Once completed , remove power and connect back power.

You can see the result on screen.


Now , let us connect Arduino with NEXTION display.

First connect 5v of Arduino to 5v of display.Then GND to GND.

The display goes on showing the designed screen.


Image 36

Upload the following code .

As we do not use Software serial in code , we have to upload code first and then connect

Tx of Arduino to Rx of Display, Rx of Arduino to Tx of Display.




#include <Nextion.h>

const int led = 13;

//Declare your Nextion objects , pageid, component id., component name

NexButton b0 = NexButton(0,2,”b0″);
NexButton b1 = NexButton(0,3,”b1″);
NexText t0 = NexText(0,4,”t0″);

//Register a button object to the touch event list

NexTouch *nex_listen_list[] = {

//Button b0 component popcallback function
// When ON button is Released the LED turns ON and the state text changes

void b0PopCallback(void *ptr){
t0.setText (“State:ON”);

//Button b1 component popcallback function
// When OFF button is released the LED turns OFF and the state text changes

void b1PopCallback(void *ptr){
t0.setText (“State:OFF”);
void setup(void) {
//Register the pop event callback function of the components




void loop() {


CODE walk through :

First we include the header file

#include <Nextion.h>
Then each component used is declared using NexButton function
We have 3 components bo,b1 & t0

bo component is defined as

NexButton b0 = NexButton(0,2,”b0″);

0 is the pageid , 2 is the component id & bo is the object name
Similarly other 2 components b1 & t0 are defined

Next we create a list array using NexTouch function for the Touchable components.
We have only 2 touchable components b0 & b1
The array list is created b0,b1 & NULL isadded finally.

Button b0 component popcallback function
When ON button is Released the LED turns ON and the state text changes

void b0PopCallback(void *ptr)

same way button b1 component popcallback function is declared.

Inside SET UP we attach the function created to corresponding Events.
When you click bo button boPopCallback function is called.
This is done by
Same way for b1 button.
Inside loop we repeatedly watch for the event trigger list.

The code and project files can be downloaded from here :–hmi-tft-lcd-nx4024t032.html

Connect an LED at pin 13 of Arduino through a resistor to GND.

Image 37

When you touch and release LED ON button , the LED is ON

When you touch and release LED OFF button , the LED goes OFF.

The STATUS is updated accordingly.



Video :



In the previous post we explored the ways of uploading code on to STM32 using UART1 & Serial Wire Interface.

Its also possible to upload code through USB port of STM32. By default Bluepill modules are not shipped with boot loader. To enable USB uploading we need to flash a bootloader.

This post is related to USB uploading on to an Arduino core Bluepill.

Firmware (.bin file) for bootloader can be flashed only through UART1 of STM32

USB-TTL module built on CP2102 is used for this purpose.

Connection details as below :

PA9 Tx   to Rx of USB-TTL

PA10 Rx  to  Tx of USB-TTL

5v to 5v , GND to GND



Plug in the USB-TTL module to PC after installing the CP2102 driver

A port will be allotted to the module.

On STM32 Bluepill shift the BOOT 0 jumper to 1 position & press Reset button.

Image 1

Before proceeding , collect the following Software tool , driver & .bin file

Image 2

Firmware .bin file can be downloaded from Roger Clark’s github. Ensure to download the bin file with suffix _pc13,bin  ,  as the built in LED of our module is mapped to PC13.

Image 3

Flasher tool can be downloaded from :


Image 5

Install the Flasher tool


Image 6

Note the install location of the tool & create a shortcut manually.


Image 4

Start the Flash Loader software.

The UART port is automatically detected .

Image 5

Click next.

If you get an Error saying No Response from Target , ensure that BOOT 0 jumper is placed on 1 position & start the flash loader again.


Image 2


Image 6

Now the Target is readable. Click Next.


Image 7

Target Device is automatically detected.Click Next.

Image 8


Select Download to Device & browse to location of .bin file.

Image 10


Now the   boot loader is installed successfully.

Image 10


Now replace the BOOT0 jumper back to 0 position & then remove

USB-TTL module.With power on position , the Boot  0 jumper must be set back to 0.

Connect the usb of STM32 to that of PC.

Image 14

Open Device manager.

Under Ports you may see an exclamation mark or just a USB serial device.

Related driver should be installed , so that it shows Maple Serial COM port.

You can download the driver here :

Just Double click the install_drivers batch file .


Now you can see Maple Serial COM port under Device Manager.

Image 11

Open the Arduino IDE.

Select Board as Generic STM32F103C Series.

Select Upload method as STM32duino bootloader.


Image 12


Select the Maple Port

Image 13


Now upload the blink sketch ( with LED_BUILTIN defined as PC13)

There is no need to shift BOOT0 jumper to upload code.Directly through USB you can do the upload.


With some PCs you may get upload done , but the USB port resets before starting to function with the newly uploaded code.


Image 14

This is caused by the faulty R10 value resistor seen back to the board.

Most PC USBs accept this pull up value.But sometimes you get the Reset error.


Image 16


The Blue Pill  has  design fault as it uses a 10k USB pull up resistor, but the USB spec requires 1.5k

You can remove the smd resistor R10 & replace with a 1.5k resistor.


Or simply solder a 1.8k resistor between PA12 & 3.3V , if you cannot handle SMD component.



The STM32 F1-series was the first group of STM32 microcontrollers based on the

ARM Cortex-M3 core and considered their mainstream ARM microcontrollers. The F1-series has evolved over time by increasing CPU speed, size of internal memory, variety of peripherals.

There are five F1 lines: Connectivity (STM32F105/107), Performance (STM32F103), USB Access (STM32F102), Access (STM32F101), Value (STM32F100).

In this post we shall explore the ways to implement Arduino core on to STM32 so that programming can be done through Arduino IDE itself.You can enjoy the speed of 32 bit microcontroller with ease of Arduino IDE programming.

STM32 is a 72 MHz processor. The full part number STM32F103C8T6  decodes to

C8 = 128 KB flash, 20 KB RAM, 48-pin LQFP:

STM32 F1xx development boards are available in wide range.Here we shall use a simple board which is also called BLUEPILL . A very efficient & economy module easily available.




Programming can be done in many ways.This post is related to using Arduino core.

As  seen in above picture , STM32 pill has 3 UARTs of which UART1 (PA9, PA10) is used to upload code.For this you need a USB-TTL module .Although the STM32 is 3.3v device many GPIO pins  (shown in yellow underline in above picture) are 5V tolerant. So you can use this USB-TTL *CP2102) module without any level shifter.

The other way to upload code is through SINGLE WIRE INTERFACE ModuleInterface (SWIM) .This uses only 2 wires SWCLK, SWDIO apart from power pins .You can see this as 4 separate header pins to the right end of module.You need a ST-LINK dongle or device to connect with the SWIM.

The ST-LINK/V2 is an in-circuit debugger/programmer for the STM8 and STM32 microcontrollers. The single wire interface module (SWIM)  interfaces facilitate the communication with any STM8 or STM32 microcontroller operating on an application board.



The bare STM32F103 board only comes with a default USART boot loader. Even though there is a USB port on the board, you cannot use it to program it because it does not have the relevant bootloader.

In the next post we shall see how to upload using USB.

For now connect the USB-TTL module to STM32 .

PA9  TX    —->   Rx of USB-TTL

PA10  RX   —->   Tx of USB-TTL

5V   —>  5V

GND  —>  GND

Plug in the USB-TTL module to USB of PC. CP2102 device driver is required so that PC allots a port number to the module.




Image 1

You can see 2 yellow jumpers on board.The bottom one is BOOT 1 & the top one is BOOT 0.

For programming you need to shift the BOOT 0 jumper to make High as shown in photo below.


Image 2


The setting of Jumpers specify  the source of code for the STM32.

In the default state of both being 0, the micro-controller uses its own flash memory bootloader (factory setting is none , there is no bootloader in fresh boards)

To program the micro using USART, you need to set BOOT0 as 1 and leave BOOT1 to 0. Move the first jumper and leave the second one.




Open the Arduino IDE .

Go to   File –> Preferences


Image 3


At the bottom of the preferences screen , copy & paste the following link


If you have some other link already here ( for e.g you might have installed for NodeMCU) , put a comma after the existing one & then paste the link

Image 4

Click OK.

Now under Tools —> Boards  select Boards Manager

Internet connection is required  to install board support chain link.

Type in STM32F1 & select STM32F1xx boards by stm32duino.


Image 6

Select the latest version & click install.

It takes some time to get installed.

Image 7

Now reopen the ARDUINO IDE.

Under Tools make the following settings:

Board : Generic STM32F103C Series

Variant : 20k ram 64k flash

Very important is Upload method which is SERIAL

Port : port no. alloted to USB-TTL

Progemmer : USBasp

Image 15


Open the Blink sketch

Add this before void setup

#define LED_BUILTIN PC13

Save the file.

Image 9


As seen in picture below , the built in LED on STM32 bluepill is mapped to PC13

Image 10


Click on Upload

Image 13



Image 3


Once the code is uploaded you can see the built in LED blinking accordingly.Now you can reset the BOOT 0 jumper back to 0 position & press Reset to start the freshly uploaded code.

For next upload you need to set the BOOT 0 to position 1 & press Reset button.

Let us see the second method to upload code through SWIM.

For this you need a ST LINK V2 dongle as shown in picture below :


Image 2




The pin details of STLINK is printed on the module itself.

Pin number starts from top , as shown below



Connect STLINK to STM32 as below :

Pin2 SWCLK   —>  DCLK of STM32

Pin4 SWDIO  —>  DIO of STM32

Pin6 GND  –>  GND

Pin 8   3.3V –>  3,3V



Before connecting ST LINK to PC , download & install the driver from below link

This USB driver (STSW-LINK009) is for ST-LINK/V2 and ST-LINK/V2-1 boards and derivatives (STM32 discovery boards, STM32 evaluation boards, STM32 Nucleo boards)


Image 11

Once the drivers are installed you see under Device Manager – > Universal Serial Bus Device

STM32 ST Link




Open the Arduino IDE

Select board as STM32F103C Series

Upload method to be selected as ST Link

Port will be greyed out ,as No selection of port required


Image 11


Note that there is no need to shift Jumper in this method of uploading.


Image 13

Just click on upload to see the inbuilt LED blinking.