Latest Entries »


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.




VIDEO Demo :


Relay module boards play an important role in Home automation projects. Generally we connect the load ( fan,light,etc…) to be controlled through the Relay contacts . While is the relay is controlled ON/OFF , IN TURN the load is controlled through the relay contacts.

Different types of relay modules are available .

In this post we explore the best Relay module suitable to use with Raspberry PI.



Relay modules are available in 12v & 5v .The best one for RPI is 5V Relay Module with Opto coupler drive.

This type of relay boards have opto coupler & NPN transistor to control the relays. Each relay is controlled by an opto+transistor combInation.



When a LOW is applied to INPUT , say IN1 , the photo diode inside optocoupler conducts which in turn activates the photo transistor inside the opto.

The NPN TRANSISTOR after the opto coupler is triggered which in turn switches ON the relay.




On board a Jumper is provided between JD_VCC & Vcc .While the jumper is ON & Vcc is provided with 5v , the board operates normally. When LOW is at input , the relay is ON. The problem arises when connected to RPI whose GPIO pins are at 3.3v level.

When a HIGH is applied from RPI , THERE WILL BE POTENTIAL DIFFERENCE OF 5V – 3.3V = 1.7V which causes the board relay to chatter or malfunction.

So while using with Raspberry PI always remove the jumper & provide 5V to JD_VCC   & 3.3V to Vcc.

Both these voltages can be directly connected from the RPI itself. No separate power source required for Relay board. In RPI 3.3V is capable of only 50 milli amp sourcing current.

This 3.3v is connected to Vcc of Relay board which drives only the photo diode of opto coupler.So  a small current is enough.

The 5V rail of RPI is capable of sourcing much more current. It depends on the power adapter used for RPI less the current consumed by the RPI itself . 500MilliAmps can be easily sourced at this 5v point of RPI.

Let us now connect PI with 4 channel relay board.


JD_VCC              5v

VCC                  3.3V

IN1                   Pin 32

GND                 GND

Ethernet cable is connected between PC & RPI,&  PI is accessed from PC through SSH client PUTTY

Refer my previous blog on how to access PI from PC




LOG IN using default user name pi &password raspberry

To test python commands start the python interpreter by typing command


By default, Raspbian Stretch version  uses Python 2. However, versions 2 and 3 come installed by default. We just have to make 1 minor change so that the Pi uses Python 3 whenever we type python into a terminal.

In a terminal window, enter the following command:

nano ~/.bashrc

Scroll down to the bottom, and add the following command to the file:

alias python=’/usr/bin/python3′

Exit out of nano by pressing ctrl+x, press the y key when prompted if you want to save the file, and press the enter key.

you can  run the contents of the .bashrc script by entering:

source ~/.bashrc

Now check the version of Python

python –version

Just type in python to get the INTERPRETER  symbol >>>

Now you can test python commands one by one.




First import RPi.GPIO module

import RPi.GPIO as GPIO

Functions are called Modules in Python. Note the casing of letters used RP in capitals & i in small case .We also use alias name GPIO , so that further in code you just need to mention GPIO instad of RPi.GPIO

To specify which pin configuration you are using type


There are two ways of numbering the IO pins on a Raspberry Pi within RPi.GPIO. The first is using the BOARD numbering system. This refers to the pin numbers on the P1 header of the Raspberry Pi board. The advantage of using this numbering system is that your hardware will always work, regardless of the board revision of the RPi. You will not need to rewire your connector or change your code.

The second numbering system is the BCM numbers. This is a lower level way of working – it refers to the channel numbers on the Broadcom SOC. You have to always work with a diagram of which channel number goes to which pin on the RPi board. Your script could break between revisions of Raspberry Pi boards.

To detect which pin numbering system has been set (for example, by another Python module):

mode = GPIO.getmode()

The mode will be GPIO.BOARD, GPIO.BCM or None


Physical pin 32 is set as OUTPUT using


Pin 32 is initially made HIGH so that relay is OFF


To make the Relay ON , set pin 32 to LOW


At the end any program, it is good practice to clean up any resources you might have used.

To clean up at the end of your script:


Note that GPIO.cleanup() also clears the pin numbering system in use.

Now let us connect other Relay inputs to RPI

PIN 36 to IN2

PIN 38 to IN3

PIN 40 toIN4

Open NANO editor by typing

sudo nano

Feed in the following code.

Note the usage of Indentation for try block.

You can press TAB key to introduce blank space indentation whichis equal to braces in PYTHON.



import RPi.GPIO as GPIO
import time






# main loop

      print "First Reay ON"
     print "Second Relay ON"
     print "Third Relay ON"
     print "Fourth Relay ON"
    print "Good bye!"

except  KeyboardInterrupt:




Press CTRL+X  to quit & press Y to save the file.

To execute the file


The Relays will be switched ON one by one & finally all Relays will be OFF , according to code.




The single channel relay boards are  different. Some boards have OPTO Coupler & some

do not have opto.

    r1                r2

The board with opto is HIGH enabled. A HIGH is required at IN to switch ON relay.

The board without OPTO is LOW enabled . A LOW is applied at IN to switch ON Relay.

Jumper is not seen on these single relay boards.

Always use 3.3v to Vcc in these single channel relay boards.



This post is on interfacing GSM with Raspberry PI 3  B or B+.

UART is commonly used on the Pi as a convenient way to control it over the GPIO, or access the kernel boot messages from the serial console (enabled by default).

It can also be used as a way to interface GSM / GPS /Arduino / ESP8266, etc with your Pi.

Be careful with logic-levels between the devices , for example the Pi is 3.3v and the GSM is 5v.




In the previous versions of PI GPIO Serial port is mapped to /dev/ttyAMA0

(COM1 equivalent is found on pins 14 and 15 of the GPIO header and is called /dev/ttyAMA0  )

But in PI 3 B or B+ this hardware port has been utilized for the BLUETOOTH Functionality.

/dev/ttyAMA0 is a hardware , high performance serial port (uart) & used for the Bluetooth

A second port is partly software /dev/ttyS0 & is assigned to GPIO Serial port.

So , the ports on a Raspberry Pi 3  are


/dev/ttyAMA0 -> Bluetooth
/dev/ttyS0 -> GPIO serial port   (referred to as the “mini uart”).


Thus on a Raspberry Pi 3 serial0 will point to GPIO pins 14 and 15 and use the “mini-uart” ( /dev/ttyS0).

On older Raspberry Pi’s  it will point to the hardware UART and /dev/ttyAMA0.

Image A


To start with write the  RASPBIAN image OS on a class 10 memory card using ETCHER



Use the SD card on RPI 3 & log in

To know the Serial ports enabled  , type in

cd /dev   & then  ls –l


Image 2

You can see only the ttyAMA0 is enabled & not the  mini uart  ttyS0

Image B

The GPIO serial port is disabled by default. In order to enable it, edit config.txt:

$ sudo nano /boot/config.txt

and add the line (at the bottom):


Reboot for the changes to take effect.

Image 5


Image 7


Image 8

Restart the Putty SSH

Now check the   cd /dev  ,  ls –l    again

You can see both the ports enabled. Note that this can be done through raspi-config also.

Image 3

Let us connect the GSM with PI now.



The logic levels of PI are at 3.3 volts & it is risky to connect directly with a 5v level GSM pin.

The Tx pin (pin 8 , GPIO14) of PI can be directly connected to Rx of GSM. As GSM accepts 3.3volt level as high , this connection is straight without level shifting.

However the Rx pin (pin 10, GPIO 15) of PI cannot be connected directly to Tx of GSM.

A simple level shifter using a signal diode 1N4148 &  a 10k resistor is used in between as shown below



When the level at GSM Tx is LOW , the diode is forward biased & the Rx of PI gets LOW.

When the level at GSM Tx is HIGH ,the diode is Reverse biased & the 3.3v is available at Rx of PI through the resistor.

A separate power source 12v 1 amp is required for GSM , and the GND pins of PI & GSM are made common.

Be cautious while connecting with PI pins , as any wrong connection will render the PI defective.

After powering the GSM wait for the network. The network LED blinks fast initially  & after getting Network it blinks slowly.

You can also call to the SIM number used on the GSM to get a ring back tone.

Now the set upis ready.

Let us install  a Serial monitor called picocom on PI to test the AT commands.


Image 4

Start the picocom with baud rate 9600 & at portttyS0

picocom –baud 9600 /dev/ttyS0

Note the double hyphen before baud .

Image 9

You get Terminal Ready

after which you can type in AT to get an OK response.

If you cannot seewhat you type,or if no response then check the GSM for network &also check the port name you’ve typed.

It must be /dev/ttyS0 .      S is capital letter & then zero.

Now you can make a call using ATDxxxxx; command , terminate a call using ATH

Send SMS using AT+CMGF=1 , & test other AT commands


Image 11


Now let us use PYTHON to make a call.

Open a file named using

sudo nano


Image 12

Type in following code & then CTRL+X , to exit & Yes to save.

Image 13

While using AT command inside Python code , notice the usage of carriage return

\r  after each command    like ATDxxx; \r

To execute the file


You can see the number being called & then hangs up using ATH command.

Image 16

Now let us create a python code for sending SMS.

Notice the usage of  double quotes for sending AT commands

Also, note that single quotes used if the AT command needs to send double quotes

as in AT+CMGS command

Image 14


To execute type in


You can see the sms being sent to the phone number used in code.

Image 17

Support VIDEO :




In my previous post I’ve explained the method  of connecting Raspberry PI with  Laptop through Ethernet.

At times , the PI is not recognized , or unable to contact over SSH in this method.

Let us see the DIRECT NETWORK LINK method In this post which is 100% reliable.Cons is that network internet is not shared.But this is not an issue , as PI3 is WIFI capable through which you can connect to internet.



To start with , place the SD card ( class 10 type recommended ) with Raspbian OS on to a Card Reader


Image 1


The card will be shown as boot drive.Open it.

Under View , un tick the option “ File Name Extension”


Image 2

Now Right click on empty space & create a new text document.

Rename it to ssh & save it.

Now a file named ssh is created without any file extension

When the card is now used on RPI, on first boot the OS will look out for the ssh file name.If it finds one , it enables secure shell & then delete the file named ssh.

This is how SSH is enabled in a Headless mode operation of RPI.

Image 3

Place the SD card on to PI & power it up.

Now Open Network& Sharing center on your Windows PC.

Image 4


Connect the Ethernet port of RPI to the Ethernet port of your PC using a STRAIGHT RJ45 Cable.

An Unidentified Network is created for the Ethernet adapter where PI is connected .


Image 7


Click on the Network connection type ,( here mine is WIFI.)

Click properties




Under SHARING Tab un tick the options so that Network sharing is DISABLED.




Click on the ETHERNET connection & then Properties on next window.

Double click Internet Protocol 4 & ensure that DHCP is enabled i.e, Obtain IP address automatically is selected.

Image 8


For a network link to work between two computers they need to be using the same address range.
The allowable address range is determined by the subnet mask.  means all octets in addresses should be same except for the last two in the IP address,otherwise they will be filtered.

Most PCs connected directly to another computer will allocate an IP address in the range 169.254.x.x ( with subnet mask of

For RPI to be able to communicate through the direct link it needs to have a fixed IP address in the same address range 169.254.x.x

We can set this in the cmdline.txt file

To know the IP allotted to the ETHERNET adapter

Open Command Prompt ,CMD

Type in ipconfig /all

Image 9

Scroll down to find the IP under Ethernet adapter.

Here it is

which is the Gateway IP of Ethernet adapter.Any device connected to this port should have the IP in range 169.254.192.x

As we’ve connected the PI to Ethernet adapter  let us assign the IP toPI as

Note that the last octet can be anything up to 255.

Image 10

The static IP to PI is assigned as follows :

Switch off power to PI ,remove SD card & place it on a card reader.

Open cmdline file found in the SD card

Image 11

Move to the End of file.

Please note that you must not hit Enter .

Just at the end type in


Image 12


Image 13

Save the file .Remove SD card from card reader & plug it to PI & power it up.

Let us use the free SSH Client PUTTY  to log intoPI.

Open PUTTY &  under Session , type in the IP address

Ensure that SSH is selected.


Image 14


Click open

Now you get the LOG IN window of PI

login as pi & password : raspberry


Image 15

Now ,let us see how to log in Graphical user interface.

For this a XMING X Server is required.

Download XMING from here

Install XMING & start the server.

Image 16


Image 19

Open Putty & as done previously enter the IP address

Under SSH click X11

& then Tick mark Enable X11 forwarding.


Image 17

Click Open to get the login window of PI.

To get Graphical interface , type in


Image 18

Now you get the graphical screen

To get internet access :

Under  SYSTEM TOOLS  click LXTerminal

Image 20

Type in

sudo raspi-config

Image 21


Select Network Options

Image 22

Select WI FI

Image 23

Then enter  SSID of your WIFI to connect with


Image 24


Provide the password for thee SSID

Image 25



Image 26

Now you get the internet accesswhich can be tested by

sudo apt-get update.


Image 27





Installing USBASP drivers on Windows 8 or 10 is bit tricky. As these versions of Windows require DEVICE DRIVER VERIFICATION , they do not allow unsigned drivers like libusb.

For programming 8051 or AVR you need this driver.

You can install by following methods :

1. Disabling Windows driver enforcement on boot up. Follow this link

This method requires SHIFT+ RESTART of Windows to enter advanced troubleshooting where we disable signature verification .After this you can install the libusb driver.

But in some laptops , this method fails on next Windows update.


2. Install libusb drivers using ZADIG application.

Zadig is meant to install a libusb compatible driver, for a device that does not yet have such a driver installed.

With the application running, you should see your USB device appear in the dropdown list

(click on the dropdown to see all devices).
You can also plug your USB device after Zadig is running, as the list is refreshed automatically. Its recommended to leave only the device you want to install a driver for, and unplug any other USB device.


You can also select the driver you want to install,( between WinUSB/ libusb-win32/libusb0 / libusbK )

Once you are satisfied with the selection and device description, simply click the Install Driver Button.

Caution :

If you select the wrong device,  Zadig will  replace its driver.

The responsibility is entirely yours try to pay attention to the device you select .Don’t just  press the install button on the first device you see,

If wrong driver is replaced , then some of your USB devices like wireless mouse may not work.


3. Best & Easy method

The USBASP windows driver was previously based on  libusb-win32. The certificate on the base drivers have expired and the library has now been superseded by libusbK.


Following is the procedure to install protostack USBASP driver.

At first when you connect the USBASP hardware to PC & open the Device Manager you see an exclamation mark against USBASP indicating that drivers not installed.


Image 2

If you open the PROGISP application ( to load HEX file on to8051) ,you see the PRG ISP icon greyed out ,as the programmer is not yet detected.

Image 1


Download the new USBASP driver from

This driver should work with version of Windows XP right through to 8.1 and the version 10 . (both 32 and 64 bit editions).

Because the driver is signed, there should be no need to disable driver certificate enforcement or use Zadig.

Unzip the downloaded folder.

Click on Install Driver application

Image 4


Image 5


Image 6

Once the driver is installed , under Device Manager you can see USABASP under

libusbK Usb devices

Image 7

Now ,open the PROGISP application to see the device ready.

Image 8


SIM808 is all in one module with GSM , GPRS,GPS & BLUETOOTH.SIM808 is advanced compared to SIM908.

SIM808 has GNSS receiver which enables easy GPS FIX.

In this post we explore how to parse GPS data ( without using TNYGPS library) & send it through inbuilt GSM

SIM 808 has 2 antenna sockets one  for GSM  & other for GPS. A stub antenna is used for GSM & a magnetic external patch antenna is used for GPS.

Do not interchange these 2 antennae. The antenna socket nearest to SIM808 chip is for GPS.



Connection between Arduino UNO & SIM808 is simple.

Gnd to Gnd

Tx of SIM808 to Rx of Arduino (soft serial digital pin 7)

Rx of SIM808 toTx of Arduino (soft serial digital pin 8)

A separate power adapter of 12v 2amp is required for SIM808 board.

Insert valid SIM on to the slot at the  back of SIM808 board

Power on & notice the NETWORK LED .It blinks fast initially & when it gets network it blinks slowly ,once per second.




We’ll use a serial to usb cable to monitor SIM808 serial port. We can also test AT commands through this port ,before uploading Arduino code.

Connect the cable to PC & note the COM port allotted under Device Manager .

Another COM port is allotted to Arduino board.Note this also.


Before uploading code on to Arduino , let us check the AT commands.

For this open a PUTTY Terminal & select SERIAL.

Feed in the COM port of the USB-RS232 cable &baud rate as 9600. & click open.

Image 1


Type in AT ,the SIM808 module responds with OK.

ATD is the command to dial a number

AT+CMGF=1 , AT+CMGS=”phone no.” are for sending SMS.

All GSM related commands are similar to that of SIM800 or SIM900.

Some cases of empty SMS delivery is reported .i.e you receive SMS on mobile but has got no message.

To solve this problem set the following parameter.


This has to be done before you set the module to Text mode using AT_CMGF=1

Image 2

GPS related AT Commands are similar to that of SIM 908.



AT+CGPSPWR=1 sets the GPS engine ON


AT+CGSINF=0 returns a single NMEA sentence of GPS.

AT+CGPSSTATUS?   returns the Status of GPS whether it has got FIX or not.

If GPS has not received FIX , the NMEA sentence will read all  0 s

Relocate the GPS antenna & wait for some time to get a FIX. If the GPS antenna faces open SKY you get a FIX within seconds.

Image 3

Once GPS gets a FIX , AT+CGPSINF=0 returns a valid NMEA sentence.

AT+CGPSINF=32  returns a single GPRMC sentence


Image 4


Now let us see the SIM808 specific GPS commands

SIM808 has inbuilt GNSS receiver

AT+CGNSPWR=1  turns on the GNSS power

AT+CGNSSEQ=”RMC”  parses the NMEA sentence related to GPRMC

Now issuing the command AT_CGNSINF returns a valid NMEA  GPRMC sentence



Image 5


Now let us upload the code that parses RMC data &sends SMS with google maps link


Arduino code Download :



#include <SoftwareSerial.h>
SoftwareSerial sim808(7,8);

char phone_no[] = “xxxxxxx”; // replace with your phone no.
String data[5];
#define DEBUG true
String state,timegps,latitude,longitude;

void setup() {

sim808.print(“AT+CSMP=17,167,0,0”);  // set this parameter if empty SMS received



void loop() {
if (state !=0) {
Serial.println(“State  :”+state);
Serial.println(“Time  :”+timegps);
Serial.println(“Latitude  :”+latitude);
Serial.println(“Longitude  :”+longitude);



sim808.print (longitude);
sim808.println((char)26); // End AT command with a ^Z, ASCII code 26

} else {
Serial.println(“GPS Initializing…”);

void sendTabData(String command , const int timeout , boolean debug){

long int time = millis();
int i = 0;

while((time+timeout) > millis()){
char c =;
if (c != ‘,’) {
data[i] +=c;
} else {
if (i == 5) {
goto exitL;
if (debug) {
state = data[1];
timegps = data[2];
latitude = data[3];
longitude =data[4];
String sendData (String command , const int timeout ,boolean debug){
String response = “”;
long int time = millis();
int i = 0;

while ( (time+timeout ) > millis()){
while (sim808.available()){
char c =;
response +=c;
if (debug) {
return response;


Following is the serial port monitor screenshot.

Once the command AT+CGNSINF is issued ,it returns a valid RMC sentence.

The latitude,longitude is then parsed

SMS is then sent with parsed data appended to google maps link.

Image 7


Pleae note Code is written to send SMS every 20 secs.







In this post let us explore the GPS Module built on UBLOX Neo series & then parse the data to send SMS with google maps link.

Arduino UNO is used to control the GPS module.

The GPS module used here has provision for connecting an external magnetic patch antenna.This enable the GPS to get FIX  within seconds even while testing indoor.

To test the GPS we need an USB to TTL  module.Or we can use our Arduino itself with a small hack.

Connect the RST pin of Arduino to GND.This will bypass the bootloader of Arduino & we can use the serial IC of Arduino to communicate with GPS.

Connect Tx of GPS to TX of Arduino & Gnd toGnd.

Note that the connection is STRAIGHT here & not reverse .Remember this connection will be reverse while we actually upload code to Arduino & use it in regular mode.

We can power the GPS module from Arduino itself. Connect 5v of Arduino to 5v of GPS.

Wait for some time for the GPS to get FIX. Once a FIX is received a green LED flashes on the GPS board indicating that GPS is ready with data flow.


Connect the USB of Arduinot o PC & open the DEVICE MANAGER to note the COM port allotted.

Open the Arduino IDE & select the PORT allotted.

Image 8


Image 9

Open the SERIALMONITOR to see the FLOW of NMEA sentences

We’re interested  in GPRMC which is the recommended minimum data for gps

There is an interesting link where we can decode the GPRMC sentence & understand the contents

Copy & paste a GPRMC sentence in this site to decode the contents.



If you notice a V  in GPRMC sentence ,it means GPS has not yet got a FIX. Relocate the antenna & wait for some time to receive a FIX & V changes to A .

Now the RMC sentence has all  the  data latitude,longitude,time,speed,altitude,etc..

Image 4



Image 10


Copy a portion of the data flow & paste it on to a Notepad.

Save it as text file with a name.


Image 11


To visualize the data , go to this link

Click on Choose file & select the notepad file saved.

Select the Output Format as GOOGLE MAPS  & click MAPIT.

Image 12

You can see the location on Map.

Image 13


Now your GPS is working.Let us go for a practical demo with Arduino.

To parse the data there are libraries that make life easier.

One such library is TINYGPS++ from Arduiniana

Download the library ,unzip it.

Image 14

Rename it to TinyGPSPlus & copy paste to Arduino –> Libraries.

Image 15

Open the Arduino IDE to see a list of examples against TinyGPS++

Select the FULLEXAMPLE  code.

Image 16

Here Softwareserial is used & digital pins 4 is defined as RX , 3 as Tx

Connect the Tx of GPS to  Rx of Arduino (digital pin 4)

Gnd toGnd.

As we only receive data from GPS , a single connection is enough. Tx of GPS toRx of Arduino

Image 17


Now upload the code & open the Serial monitor on baud 115200.

No data is received

Image 19

This is because of BAUD RATE mismatch.

Change the GPS Baud (not the serial baud)  to 9600 & then upload.


Image 20


Now you get data which is displayed neatly on serial monitor.

Image 21

In the next example we shall parse the GPS data & send SMS as google maps link using a GSM.

For this we use the previous version of library TINYGPS .


Image 22

Download the library & install it.

Here we use SIM900 GSM .A separate power source of 12v 1amp is required for GSM.

Connection between Arduino & GPS :


Tx of GPS connected to Rx of Arduino


Gnd to Gnd

5v of Arduino to 5v of GPS.


Connection between Arduino & GSM


Gnd to Gnd

Tx of GSM to Rx (soft serial pin 7) of Arduino

Rx of GSM to Tx (soft serial pin 8) of Arduino




Download the code from here


In this code we make use of older version of TINYGPS library to parse the latitude,longitude data,


Image 23

The data parsed is then appended to google maps link&sent as SMS .

Every 20 seconds an SMS is sent.You can modify the code so that you get SMS only when you call to the GSM.


Image 24


Upload the code & get the SMS on themobile no. you provided in the code.

Touch on the SMS link to see the location of GPS.


IMG_20180421_170826         IMG_20180421_170829






ESP8266 WEMOS D1 With I2C Serial LCD

WemosD1 R1 board is now  the most preferred IOT WIFI Board .As the hardware resembles Arduino , it is most sought out  board for any IOT project , than NODEMCU.

To add a display I prefer to use the SERIAL LCD WITH I2C BACKPACK  .

The serial LCD is built on PCF8574 &  works on I2C Bus ,thus requires only 2 wires SCL & SDA apart from the power pins.

The LCD works on 5V & it can be sourced from D1 board itself.



For more detailed information on this Serial LCD you can read my previous blog here :


The connection between D1 board & LCD is simple .

Wemos D1      LCD

5v           —–  Vcc

Gnd        —- Gnd

SCL  D15  (GPIO5)  —    SCL

SDA  D14   (GPIO4)   — SDA

To start with download the latest Library from this link :

From Arduino IDE  Sketch –> Include library –> Add ZIP Library

Browse to the location of the downloaded ZIP file & select it

Image 2

Now the Library for Serial LCD is installed.

Image 3


Under Tools selectthe board as WEMOS D1 R1 , upload speed as 115200, port is the one allotted  in Device manager &programmer USBASP.

Image 4

Read this previous blog post of getting started with D1 board, on how to install Arduino core using Boards Manager


Now we need to know the I2C Address of the LCD board connected to D1.

For this upload the following Scanner sketch.


Image 5


Once uploaded,Open the serial monitor with 9600 baud setting.

The I2C HEX Address of the device is displayed .Here it is 0x27 .

Note that this address varies according to the manufacturer and the jumper solder on A0 A1 A2 pins on the backpack pcb.


Image 6

Now open the first example lcd_test.

In this example 2 header files are used

One is the Wire.h ,which is the I2C library that is built in already with IDE.

Second  is the LiquidCrystal_I2C.h which we installed initially.

Then we create an instance  lcd with parameters I2C Address  , EN , RW , RS , D4,D5,D6,D7

I2C address is the ine we got from the scanner code –0x27

EN,RW,RS are the pins of I2C board connected to LCD Enable ,Read/Write & Register Select respectively.

D4 to D7 are Data pins


Image 3

lcd,begin(16,2) initializes the 16 x 2 LCD

Then we set the backlight ON for the LCD

lcd.home()moves the cursor to Home position

lcd.print(“,,,,”) prints the message on 1st row.

lcd.setCursor(0,1) moves the cursor to second line.


Image 7


Upload the code to see the result on LCD.

The Contrast to LCD can be adjusted by the preset on the back.




Here is the second example which prints the message typed on the Serial monitor.


Image 8


Image 9



WEMOS D1 is a WIFI development board based on ESP8266 12E. The functioning is similar to that of NODEMCU , except that the hardware is built resembling Arduino UNO.

The D1 board can be configured to work on Arduino environment using BOARDS MANAGER.

So,its not necessary to use a separate Arduino board , the D1 itself can be programmed on Arduino IDE.This is handy in using with IOT projects. Further many Arduino SHIELDs are compatible with the D1 board.

Different versions of D1 boards are available in the market    R1  ,  R2  , MINI

As the name implies D1 Mini is a smaller version

R1 , R2 boards look like Arduino UNO board ,but version is not printed on board. On some boards WEMOS D1is printed , as the ESP12 chip is manufactured by WEMOS.

In some other boards it is printed just D1 ,where the ESP12 chip is that of AI Thinker.

As the ESP12 chip has only one ANALOG pin , on board there is only A0 & other analog pins are dummy .

Image 2

Image 3   Image 4

Use a MicroUSB cable to connect D1 with PC. Make sure that the cable is capable of handling both Data & power (some of the mobile cables can handle  only power & not data) .

Open the DEVICE MANAGER & note the COM PORT allotted to the module.

As the serial chip used on D1 is CH340 , you need to install the corresponding drivers.

Image 1



Following is the pin configuration of R2 typeD1 Module.Note the changes in GPIO Pin position.


Open the Arduino IDE &  select this COM port.

From TOOLS  —>  BOARDS  —> BOARDS MANAGER install the package for ESP8266.

Prior to this , you need to provide the link from where the Boards manager will look for the package.

To do this copy the following Link

Go to FILE  –> PREFERENCES on Arduino IDE

Paste the link against the Additional Boards Manager URLs ,seen at the bottom of preferences screen & click OK.

Image 1.1



Search for ESP8266

Now you will find the package from ESP8266 Community.

Select the latest version from drop down & install it.

It takes a while & requires internet connection.

Image 2.1

Once the package is installed ,you can see the list of  boards under TOOLS –> BOARDS

Select the board as WEMOS D1 R1.

Select UPLOAD speed as 115200 &Programmer as USBASP

Image 3.1

Now open the  File –> Examples –> Basics –> BLINK sketch

No need to modify the sketch ,as we’re going to blink the built in LED (on the ESP chip , there is another LED on board which is mapped to pin14)

Click on UPLOAD


On some PCs you get a compile error ,stating that the file is being used by another process.

On some forums ,it is mentioned that the board is Duplicate .Its not the case, the reason is that some Antivirus program like McAfee does not allow the compilation process.

Open the Antivirus dashboard & TURN OFF the REAL TIME SCANNING for some time



You can also configure the Antivirus settings for an EXCEPTION to Arduino programs.

Now Upload the sketch.


Once the code is uploaded, you can see the built in LED blinking on the chip

Next code is a WIFI scanner which scans for nearby SSIDs & display the names of WIFInetworks with RSSI signal power &encryption mode.

For this we include the Header file ESP8266WiFi.h

This is installed along with the Boards Manager & is a very powerful library.

You can get more information on this library from here :

Many useful Functions are there for this WiFi library.

WiFi.mode (WIFI_STA); 

The mode function of library is used to set the D1 board in STATION mode.


scanNetworks function scans for nearby SSIDs & the result is an integer (number of surrounding WiFis) which is stored in a variable n

Then we print the SSID name,RSSI signal strength ( the lower the negative dB the stronger the signal), & Encryption mode (a * indicates SSID is password protected)


// D1 ESP8266 WiFi scanner

# include  “ESP8266WiFi.h”

void  setup () {

Serial . begin ( 9600 );
// set WiFi to station mode and disconnect from previous connection
WiFi.mode (WIFI_STA) ;
WiFi.disconnect ();
delay ( 100 );

void  loop () {
Serial . println ( “Start Scanning ..” );
// scan for nearby WiFi SSIDs & save their number into n
int n = WiFi.scanNetworks ();
// in case no Network found , print info
if (n == 0 ) {
Serial . println ( “No SSIDs nearby seen…” );

else   {
Serial . print (n);
Serial . println ( “WiFi network SSIDs nearby ….” );
// list all WiFi networks nearby
// name, signal strength and security method
for ( int i = 0 ; i <n; ++ i)
Serial . print (i + 1 );
Serial . print ( “:” );
Serial . print ( WiFi.SSID(i));
Serial . print ( “(” );
Serial .print ( WiFi.RSSI(i));
Serial . print ( “)” );
Serial . println (( WiFi.encryptionType (i) == ENC_TYPE_NONE)?”” : “*” );
delay ( 10 );
// Exit
Serial . println ( “” );
// pause for 15 seconds before new scan
delay ( 15000 );




Support VIDEO: