My Own COM Port GUI

June 9, 2010

I am going to  write about the GUI that I developed for sending data to my PIC development board. I used Liberty BASIC Gold version to develop this GUI.

You may download the demo version for free at http://www.libertybasic.com/. However, there are certain limits for the software and you have to register for a Gold version to enjoy all the features of the software.  The programming window of the software looks like the one shown in the picture below. There are tutorials available in the software which may be accessed as shown in the picture below. You may learn to open a GUI window, add buttons and consequently handle events upon button click  using the simple tutorials. These are  essential elements for our COM port recipe. When you are done with the tutorials,  you would be capable enough to design a small interface as shown in the picture below: Once you are done adding buttons, you must add a functionality to the buttons. For eg: I have added the close window option to Quit button. I am sending a string of information to my controller when I press either of the Forward, Reverse or Neutral buttons.

The algorithm for the same is as follows:

1) Open COM port

2) Send string

3) Close COM port.

Close button press event handle

Note: You have to close the event handles properly once you are done with handling the event of a button press or your code may end with bugs.

The algorithm at the PIC microcontroller end  to receive ASCII string from your computer is as follows:

1) Initialise ports and Set the Baud rate

2) If data received, read the data.

3) If string x is received, move forward

4)If string y is received, move reverse

5)If string z is received, move to neutral position

6) Go to step 2

Please note that I am trying to control a servo motor through serial port.  If you would like to know the operation of a servo motor, please refer to the following link.

I used the MikroC compiler to write the code for serial port communication and servo motor control.

unsigned short i;
void main()
{
TRISB = 0x00;
USART_init(19200);
while(1)
{ if (USART_Data_Ready())
{
i = USART_Read();
i = i-48;
if( i ==1)
{
PORTB = 1;
delay_us(1500);
PORTB = 0;
delay_ms(18);
delay_us(500);
delay_ms(1000);
}
else if(i==0)
{
PORTB = 1;
delay_us(1250);
PORTB = 0;
delay_ms(18);
delay_us(750);
delay_ms(1000);
}
else if(i==2)
{
PORTB = 1;
delay_us(1750);
PORTB = 0;
delay_ms(18);
delay_us(250);
delay_ms(1000);
}
else
{
}
}
}
}

Please note that the baud rate was 19200 bps, 1 stop bit, no parity, no hardware control and the number of bits transmitted was 8.

When you are done coding your PIC, you may create an exe file for your application as follows: You may download the GUI that I developed from the following location.

You may also have a look at my video of operating my servo motor through serial port.

Advertisements

The board has been populated and it is ready

February 8, 2010

PICdevelopment board

The board was populated successfully and most of the functional features of the board have turned out to be successful. I am yet to test one of the two voltage comparators available on the board.

The main features of the board include:

  1. PIC16F877A platform
  2. L293D module ( Can drive 2 geared DC motors or 1 stepper motor)
  3. ULN 2003A module for stepper motors
  4. Voltage comparator circuit for LDR based sensor module
  5. Voltage comparator circuit for IR LED – photodiode based sensor modules
  6. Analog Inputs
  7. Seven Segment Display * 4nos
  8. RS232 port
  9. LED outputs to test the comparators/voltage sensors
  10. 8 LEDs to test the outputs of the individual pins of the controller
  11. Plug and play option — Can test it with simple connecting wires across any pin of the microcontroller
  12. Power supply pins to power other add-on boards

Looking foward for your comments!


Functional Features of my development board

February 4, 2010

It had been a long time since the development board was manufactured. I was able to test some of the features of the board. I am done with the H bridge, RS232 communication and the A/D conversion. All were successful.

I realised the importance of input filters only when I blew up the microcontroller by connecting the 12V DC motor to the power supply that is not provided with input filters!

I tried pulse width modulation with my board and I have included  a video that shows the motor running at slow speed in opposite directions.

Interaction of the PIC with the PC using MikroC routines

The MikroC routines for the PIC microcontroller were handy to test my board. In the picture, I was able to send a data to my PIC and echo it back to the PC!

I am yet to program the correct sequence for energising the sequence of the stepper motor coils.


Mistakes that can be a learning experience

January 16, 2010

It is a general opinion that one must learn from his takes. Well, I had this medicine and it tastes bitter 🙂

Prototype of my first board

I had mentioned in my previous post about my efforts to develop a PIC development hardware. The efforts are on.

I took a print out of the copper layer using a pdf file. The pdf file reduced the pitch and altered the dimensions of the board.  Let’s hope for the best from the boards that have been ordered after correcting these errors.


Starting to program with your FreeDuino

November 16, 2009

For those who aren’t aware of Arduino boards, I am posting some basic information.

Arduino is an open source hardware provided with a Free IDE. The information about Arduino Boards are available at :

http://arduino.cc/

As a beginner, you might not be proficient in soldering circuits and debugging them.  It is better to purchase an Arduino board that is readily available in the market.

If you are from India, one of the vendors in India for the Arduino boards is :

http://bhasha.co.cc/product.php?id_product=56

They are based in Pune and they are quite helpful in shipping the material and assisting you with all the necessary information. Their sales team was quick enough to answer to my queries.

In my opinion, 600INR  is worth spending on this board.

You may download the IDE from :

http://arduino.cc/en/Main/Software

However, there are lots of constraints with this software like:

If you are using a low bandwidth connection, you may feel that the file size is quite large ( 80 MB).

It requires a Java run time engine ( that was not a problem for me at least ). Imagine a high school kid or a someone who is very new to computers and electronics trying to start with Arduino.  These minute details need some attention!

However, an Arduino is the best way to start your hobby.

When you power your board using a 9V adaptor, the Red LED on your board, starts blinking. It would have been loaded with the LED program already and it shows that your board is in a good condition.

When you launch the arduino.exe file, a screen appears before you as shown in the figure below:

Arduino

I found the IDE to be user friendly. When I started learning MPLab (PIC Microcontrollers) and AVR Studio ( AVR microcontrollers), they were complex enough to make me lose interest in learning them.

There are good examples available along with this IDE. You may access them as shown in the figure below:

Launching an application

This opens up a LED Blinking program in a new window.

LED blinking

The actual code for the program is available at the link highlighted in the picture.

 

int ledPin =  13;
The 13th pin is where your LED is connected. So it is assigned to a variable ledPin.
void setup()   {

pinMode(ledPin, OUTPUT);
}
The 13th Pin is configured as an output pin.
void loop() — This is where the body of the program is written.  
{
digitalWrite(ledPin, HIGH);
A signal “1”is sent to the 13th pin.
delay(1000);
There are code libraries which generate delay in milliseconds when you enter an integer value in the delay(integer) function. Here the delay is for 1000 ms.
digitalWrite(ledPin, LOW);
A signal “0”is sent to the 13th pin.
delay(1000);
A delay for another 1000 ms.
}
Hence your LED switches on and off every second.
Any code needs to be compiled before you run it. You can compile this code by clicking the button : Play
Now when your compiling is done,  a “Done compiling” message appears below your window.
Press “Ctrl+U”, The LED connected to your 13th pin starts blinking!

 


Reading Serial Port Data using VISA in Labview

September 10, 2009

I had been feeling so sleepy today that I wanted to try VISA (Virtual Instrumentation Software Architecture) to read the data from my PIC16F877A microcontroller using the LabVIEW software. Well I did it in a whopping 5 minutes!

Well, the data that is being read is shown in the snapshot below:

LAbview serial port communication

The number of bytes to be read is controlled by the user. However, the data that is being read is displayed in a marquee sequence.

For e.g: When you choose to read a 4 byte data, the fourth byte of data is replaced by a byte with a  shift towards the right when the latest byte of  data arrives at the first bit (left side).

So your data hello would be read as : h –> he –> hel —> and so on. I captured a snapshot when the indicator read ‘hello’ 😉

However, my reading process was interrupted by an error log created everytime. I added an error out constant which made things smooth!

Woohoo!

I shall try adding some features to this VI in future.


PIC serial communication

September 8, 2009

24 July 2009:

I am currently working on serial communication using PIC16F877A. More details to follow.

September 08 2009:

This shows how I procrastinate things. Finally, I achieved it. I have communicated to my PC using PIC16F877A. It took more than 48 hours to achieve this task!

Well! My two cents on serial communications is “Datasheet is your Bible!’

Never digress from the procedure mentioned in the datasheet!

In the rudimentary stages, I blindly followed the rules and I was able to send the letter ‘h’ to the hyper terminal. But I faced problems with the set baud rate of my microcontroller and it was sending some unknown characters to the terminal.

The frequency of my crystal oscillator was 11Mhz. Hence my Baud rate value would be 71 which was arrived at by using the formula given in the data sheet.

The screen shot of the letter h being received at the terminal is shown below!

First data from uC

I had to follow this procedure to declare an array containing the data ‘hello world’ which gives the satisfaction of winning a noble prize to any rookie.

The word ‘hello’ over the terminal  is shown below:

Hell from uCThe Pic 16F877A data sheet can be downloaded from the Microchip website!

The code used for serial port communication was:

#include<pic.h>

void delay(unsigned int n)

{

while(n- -);

}

unsigned char data[17]=” hello world ‘”;

int i;

void main()

{

TRISC = 0x80;

SYNC =0;

SPEN = 1;

TXIE = 1;

TX9 = 0;

BRGH = 1;

GIE = 1;

PEIE = 1;

RCIE = 0;

SPBRG = 71;

while(1)

{

TXEN=1;

}

}

void interrupt isr(void)

{

for(i=0; i<=6; i++)

{

TXREG = data[i];

delay(500);

}

}

Happy Programming!
#include<pic.h>
void delay(unsigned int n)
{
while(n–);
}
unsigned char data[17]=” hello world””;
int i;
void main()
{
TRISC = 0x80;
SYNC =0;
SPEN = 1;
TXIE = 1;
TX9 = 0;
BRGH = 1;
GIE = 1;
PEIE = 1;
RCIE = 0;
SPBRG = 71;
while(1)
{
TXEN=1;
}
}
void interrupt isr(void)
{
for(i=0; i<=6; i++)
{
TXREG = data[i];
delay(500);
}
}