Obtain Time From GSM netwok using SIM900

Instead of using a Realtime Clock if the Project is already using a SIM 900 module then you can obtain correct Date and Time from the NTP Server GSM Network using the following commands.


OK If your response contains this, This string should tell you all is well


OK If your response contains this, This string should tell you all is well(Set SMS Text Mode )


OK If your response contains this, This string should tell you all is well(command is used to turn on the engineering mode to get detailed network information)


+CCLK: “16/01/12,07:33:42+00”
If the response is OK then you will get date and time in above format.
Date – YY/MM/DD format


SIM 900 Network Time


GPRS using SIM900 and AT Commands


Powerup the Sim900 module
connect it to the system through serial to USB or through FTDI cable.The TTl pins for FTDI is available near to the DB9 connector.

Open any serial Terminal porogram. In Linux i use GtkTerm. Select the correct port and set
Baudrate = 9600
parity = None
Bits = 8
Stop bits = 1
Flow Control = None

Screenshot from 2015-11-26 12:49:46


Screenshot from 2015-11-25 20:00:44


The AT Commands

I am posting the commands and its reply for better understanding. I am using an Airtel postpaid sim card.
Make sure you have enough balance on Sim card.

First Command


OK If your response contains this, This string should tell you all is well

This is to check if SIM is unlocked.


+CPIN: READY If your response contains this, then it means SIM is unlocked and ready

This checks if SIM is registered or not


+CREG: 0,1 This string in the response indicates SIM is registered

Check if GPRS is attached or not


+CGATT: 1 A response containing this string indicates GPRS is attached

Reset the IP session if any


SHUT OK This string in the response represents all IP sessions shutdown.

Check if the IP stack is initialized


STATE: IP INITIAL This string in the response indicates IP stack is initialized

single connection mode,if AT+CIPMUX=1 multi connection mode


OK This string indicates single connection mode set successfully at SIM 900

This sets the PDP context parameters such as PDP type (IP, IPV6, PPP, X.25 etc), APN, data compression, header compression etc.


OK If your response contains this, This string should tell you all is well

you need to know the APN, username and password for your service provider
For Airtel


OK If your response contains this, This string should tell you all is well

Bring up the wireless. The response to this might take some time


OK indicates wireless is up

Get the local IP address


aa.bb.xx.yy If previous command is successful, you should an IP address in the response

comamnd returns the current connection status


STATE:IP STATUS if not this, some thing is wrong

Start the connection, TCP, domain name, port

AT+CIPSTART= "TCP","flaskprint.herokuapp.com","80"

CONNECT OK This string in the response indicates TCP connection established

Request initiation of data sending


The response should be the string “>” to indicate, type your data to send
Type anything after the prompt
>This is the Test Data
Now use Ctrl+Z key combination to indicate end of data sending

You should get some response back from the server. Normally some error message. But you have established the connection

To close the connection


SHUT OK Indicates shutdown successful

Screenshot from 2015-11-25 20:12:47Screenshot from 2015-11-25 21:53:44Screenshot from 2015-11-25 20:51:29


For the ease of Copy Pasting retyping AT commands in sequence

AT+CIPSTART= "TCP","flaskprint.herokuapp.com","80"

Happy Hacking 🙂


Configuring the external Interrupt INT1 in PIC18F25k80 is tricky way. The data sheet also may confuse you well.

Screenshot from 2015-06-24 22:53:21

From the pinout pin 22 or RB1 has multiple functions (RB1/AN8/C1INB/P1B/CTDIN/INT1)

These are the things to be noticed while configuring RB1 as external interrupt

Screenshot from 2015-06-24 23:42:47

The RB1 acts also as analog pin to be exact AN8.From the summary of registers associated with PortB we may misunderstand that ANSEL9 is the pin associated with RB1 but that’s wrong. If you look at ANCON1 resister

Screenshot from 2015-06-24 23:48:45

Screenshot from 2015-06-24 23:49:00

This is the most tricky part in configuring external interrupt.The other configurations are pretty straight forward in INTCONbits.

    TRISBbits.TRISB1 = 1;  
    ANCON1bits.ANSEL8 = 0;
    INTCONbits.GIE = 1;
    INTCONbits.PEIE = 1;
    INTCON3bits.INT1IE = 1;
    INTCON2bits.INTEDG1 = 1;
    INTCON3bits.INT1IP = 1;
    INTCON2bits.RBPU = 0;

The above snippet configures INT1 as external interrupt which responds to a rising edge.

Microchip PIC midrange PIC18xx Unable to drive Port C pin 1 as a digital output

Last day i tried to program Microchip PIC midrange controller. To be precise the controller i used was PIC 18F25K80. I was using the C18 compiler. I was unable to drive the PORT C pins as digital, after googling for some time i found out the solution.

Screenshot from 2015-06-24 22:53:21

I tried setting the TRISbits,PORTbits and LATbits but was of no use

 TRISCbits.TRISC1 = 0;/* Port C pin 1 configured for output */
 PORTCbits.RC1 = 1;
 LATCbits.LATC1 = 1;

The answer was that Port C pins 0 and 1 are also used as the input and output to the secondary oscillator.The secondary oscillator had to be set for digital output setting the configuration bits using the #pragma directive

#pragma config SOSCSEL=DIG

By adding this the pin turned digital and blinked

Happy Hacking 🙂

Weekend Hack using python and CANMate

My weekend hack using our company’s(http://www.dthoughts.com) product CANMate (a high performance low cost CAN Analyzer) along with Python programming language.I wrote a python program to use CANMate in GNU/Linux and Windows which is freely vailable.I used Pythons Matplotlib library to plot the real time CAN message from a vehicle’s OBD port.

Happy Hacking 🙂

IMX Ltib common errors

These are the common errors you may encounter while building Ltib

  • Ltib Zlib not installed error

While building ltib it may report zlib packages are missing


The reason is zlib path is changed
Edit bin/Ltibutils.pm inside ltib folder in zlib section add one line

zlib => sub { my @f = (glob('/usr/lib/libz.so*'),
  • Failed building wget” undefined reference to `SSLv2_client_method’


To eliminate this error edit ltib/dist/lfs-5.1/wget/wget.spec file and add “–without-ssl” to ./configure section


After adding this you need to manually remove the wgest file from BUILD (/opt/freescale/ltib/usr/src/rpm/BUILD) directory then again compile

  • /opt/freescale/ltib/usr/src/rpm/BUILD/elftosb-12.09.01/common/stdafx.h:30:36: fatal error: /usr/include/sys/types.h: No such file or directory


The error is that there is no types.h usr/include/sys directory its in /usr/incude/i386-linux-gnu/sys

To fix this error

sudo ln -s i386-linux-gnu/sys sys
  • /usr/bin/ld: ElftosbAST.o: undefined reference to symbol ‘powf@@GLIBC_2.0’


To avoid this error you need to edit makefile.rules of elftosb-

cp /opt/freescale/pkgs/elftosb- ~/Desktop
tar -zxvf elftosb-
cd elftosb-
vim makefile.rules

Inside that file there is a line that reads

LIBS = -lstdc++

change it to

LIBS = -lstdc++ -lm

to add the standard math library to the build.


After editing compress the folder back to tar.gz and place it in pkgs folder

tar -zcvf elftosb- elftosb-
cp  ~/Desktop/elftosb- /opt/freescale/pkgs/elftosb-

Now delete the old file from BUILD folder.Else you will get an error saying delete that file.

rm -rf /opt/freescale/ltib/usr/src/rpm/BUILD/elftosb-

Happy Hacking 🙂

Burning IMX28 Ltib image to SD card and booting

After successful creation of bootable image as per previous post we need to do some hack in order to get the OS booted from the IMX28EVK board.

Most probably inside ypur Ltib folder there will be a scrpt named mk_mx28_sd .This is the utility used to burn the image to sdcard it will reduce us the difficulty of partitioning etc.he BSP includes the mk_mx28_sd shell script that makes it very easy to place the build output onto an SD/MMC card. The script will write the
selected boot stream, the rootfs.

The mk_mx28_sd script should always be run from the LTIB install directory. It knows how to find the boot stream files and rootfs from this
directory.Before running the script, you need to determine the device for your SD/MMC card. Find the device id of your SD card.

ls /dev/sd?

Try issuing the above command without inserting the SD card and with inserting the SD card then you will get the device id.The SD/MMC card will be the new /dev/sdX device in the output. Where X value changes as a,b,c etc.Once you already know your card’s device, updating the card contents with a new build image

cd ~/ltib
mk_mx28_sd /dev/sdX

If you dont have mk_mx28_sd in your ltib folder then download L2.6.35_10.12.01_SDK_scripts.tar.gz from Freescale site and extract it.

cp mk_hdr.sh ~/ltib  
cp mk_mx28_sd ~/ltib  
cd ~/ltib

Here you need to do a small change in order to make the script work

Edit mk_mx28_sd script and add the ‘u’ at line 177 then the o command after. This changes cylinders to sectors.

echo “o

echo “u

Once updated to create the SD card which is at /dev/sdX:

./mk_mx28_sd /dev/sdX  


Next, set the boot mode on the i.MX28 EVK board for MMC/SD on SSP0. The boot mode DIP switch settings are shown in the table below.

Screenshot from 2014-07-11 18:54:56

Then, insert the SD/MMC card into the SSP0 card socket. This is the rightmost socket on the bottom of the EVK board.

Finally, connect power to the board and press the Power button. You will see serial output over the debug UART if you have a terminal program

you will reach the login promt


Login using the username root

Happy Hacking 🙂