PDA

View Full Version : Problem in sending command from VB6 to PIC18F458



nurul07
- 12th June 2011, 19:07
hii.. i'm new to VB6 and PIC.. i have problem to send data from VB6 to PIC.. actually my project is to measure current temperature and control on/off valve using zigbee module..

The problem is when i click command button in VB6, the PIC doesn't receive the signal. I'm not sure on the coding in VB and PIC. Is it correct to send a character in VB6 to PIC? Can PIC receive a character?

I'm using Zigbee module which transmit data wirelessly from PC to PIC..Is it possible for VB to give command to PIC? i mean wirelessly transmit the command from VB to PIC..

My VB coding:
Private Sub Command1_Click()
MSComm1.Output = ??
End Sub

can anyone give example on the coding..plz help me..

mister_e
- 12th June 2011, 19:12
Check out this link
http://rentron.com/VisualBasic.htm

Frankly... you shouldn't consider VB6 in 2011. VB.NET (2005, 2008, 2010) is by far better.

nurul07
- 12th June 2011, 19:31
i never use vb.net before..but if i use the software, is it possible to send command using zigbee (wireless) from PC to PIC..i've tried so many times using vb6 but the PIC seems like not receive the signal..the measured temperature can be displayed on the vb6 program but when i add the click button in vb6 to give command to PIC, my sensor doesn't do the measuring temperature..how to solve this problem?

mister_e
- 12th June 2011, 19:44
OK no problem, VB6 is still workable and if you already know it, then let's try to find your problem.

What I suggest is to start small, I mean get rid of the ZigBee thing for now and just try to send some data from your PC to your PIC. Once you prove the hardware & software is OK, then add some pleasure to it.

Couple of things to check:
Is the Baudrate properly set on both side
Use a scope and see if there's any signal going from the PC to the PIC
debug further on that. Try the example on the previous link on RENTRON website.

We can have a look on your code, just paste it here.. PC and PIC side. Also tell us which PIC you're using and post your schematic. The more info info you give, the best.

Another cool thing to debug serial communication is called a Serial Port Sniffer. HHD soft one's my favourite.
http://www.hhdsoftware.com/serial-monitor

Pretty sure I've already posted something like that here... will try to find it.

mister_e
- 12th June 2011, 19:58
You should be all set with those

http://www.picbasic.co.uk/forum/showthread.php?t=5481

http://www.picbasic.co.uk/forum/showthread.php?t=1833

nurul07
- 13th June 2011, 02:00
Thank you mister_e..
I've set both baud rate=9600.

This is my PIC coding:
unsigned long temp_res;
unsigned long h;
void NumtoChar(char a)
{
unsigned char digit[3];
digit[0]=a/100;
digit[0]+=0x30;
a=a%100 ;
digit[1]=a/10;
digit[1]+=0x30;
digit[2]=a%10;
digit[2]+=0x30;
Soft_UART_Write(digit[0]);
Soft_UART_Write(digit[1]);
soft_UART_Write('.');
Soft_UART_Write(digit[2]);
}
void main()
{
Soft_UART_Init(PORTC, 7, 6, 9600, 0);
ADCON1 = 0x81;
TRISA = 0xFF;
TRISB = 0X00;
TRISC = 0X00;
TRISD = 0X00;
while(1)
{
temp_res = ADC_Read(0) >> 2 ;
delay_ms(300);
PORTB = temp_res ;
h = temp_res*1.3;
NumtoChar(h);
ADRESH = 0;
ADRESL = 0;
}
}

This is my VB coding:
Option Explicit
Dim ipt As String

Private Sub Command1_Click()
MSComm1.Output = "M"
End Sub

Private Sub Form_Unload(cancel As Integer)
If MsgBox("Are you sure you want to quit?", _
vbYesNo + vbQuestion, _
"Exit") = vbNo Then
cancel = 1
Else
End If
End Sub

Private Sub Form_Load()
MSComm1.CommPort = 3
MSComm1.PortOpen = True
End Sub

Private Sub Timer1_Timer()
ipt = MSComm1.Input
ipt = Right(ipt, 4)
Text1.Text = ipt
End Sub


The pic coding works and the temperature measured can be displayed on VB. But the VB coding above i add command button to send a character. I should add in the pic coding too right? I'm not good at coding. When i add receive coding in pic it doesn't works. The vb can receive temperature from pic, meaning they can communicate. Just the problem is the pic can't receive from vb. how to send the command from vb to pic?

mister_e
- 13th June 2011, 02:25
Did you tried the last code example over there?
http://www.mikroe.com/esupport/index.php?_m=knowledgebase&_a=viewarticle&kbarticleid=148#soft_uart_read

However I would suggest
http://www.mikroe.com/esupport/index.php?_m=knowledgebase&_a=viewarticle&kbarticleid=157

I would also suggest you to post on MikroElektronika forum, here it's for Melabs PicBasic Pro Compiler :(

The VB side should work.

joseph Degorio
- 13th June 2011, 16:51
Hi,
Basically you can use comm port(COM1) to talk to your module but it is also applicable to usb(just need serial to usb convert) here is a link that might help set up to wrte to communication port using VB http://www.bitwisemag.com/copy/vb/vb1.html
then read input data using picbasic command(see peek and poke, you can search in this forum).

regards,
joseph

joseph Degorio
- 13th June 2011, 17:20
I'm sorry, my mistake you can use "serout" to read specific pin to read.