Serialport(vb) to basic atom communication

look here for some answers to video

shrinkwrapvb.com/videocap.htm

ive been working on some simple things ,like a led that turns on when you press a button on the CP but i t still dosn’t work :frowning:

RND var word 
RNS var word
pan var word
tilt var word
l_on con p14
RND = 255 - RND
RNS = 255 - RNS
_L var bit
pan = RND
Tilt = RNS


main
  serin s_in ,2400,1000,stp,[RND ,RNS,_L]
if _L = 1 then 
gosub Lon
else
gosub loff
endif
tilt = (RNS * 3)
pan = ( RND * 3)
gosub servos
goto main 


servos:
 servo p0,pan
 servo p1,tilt
return

stp:
servo p0,0
servo p0 ,0
return


lon:
high p14
return

loff:
low 14
return

can you find out whats wrong?

It is always hard to say with so little information.

For example, do you actually get any information from the Serin?
My first guess is to wonder how well serin works with bit variables. I would probably change this to a byte.

Second I assume you have an LED wired to P14. Depending on how it is wired, does it work properly when you either set p14 or low?

For example you could put some code before main that loops 5 times, calls Lon pauses some time, call Loff pauses some time…

Then you would know if that part is working properly. Also you would know if the processor was reset…

oh, i forgot to put a pause in there, i will try that and see what happens :slight_smile:

and that byte variable is for somthing else, please do not pay attention to that, its for servos that im not using at the moment :astonished:

allright, i know now that the VB code is fine cause it dosn’t contain any Errors
so at least i know somthing is right,its the ba code thats wrong

[code]
RNS = 255 - RNS
_L var bit
pan = RND
Tilt = RNS

main
serin s_in ,2400,1000,stp,[RND ,RNS,_L]
if _L = 1 then
gosub Lon
else
gosub loff
endif
tilt = (RNS * 3)
pan = ( RND * 3)
gosub servos
goto main

servos:
servo p0,pan
servo p1,tilt
return

stp:
servo p0,0
servo p0 ,0
return

lon:
high p14
pause 2000
return

loff:
low 14
pause 2000
return[/code]

Just because it compiles without errors does not necessarily imply that it is correct. Afterall didn’t your BA code compile?

What you might want to do is to add some code before main that looks something like:

for pan = 0 to 2
    gosub Lon
    gosub Loff
Next

RNS = 255 - RNS
_L var bit
pan = RND
Tilt = RNS


main
    ...

Hi Wow7,

did you get the LEDs to flash?

not yet,but let me clarify, the two byte variables im not using for the project
but they are just there for somthing else,dont pay attention to the servo sommands either.

I understood. But I forgot to put in a previous post that you may want to change _L to byte.

I am not sure how well the serin command works with bit variables. It may work, but I don’t think that is what would be output from the VB side. So try to make sure that both are inputing and outputing the same number of bits over the serial port.

Also did you put in my suggested loop. If so did the LED blink on and off. If not you may have a problem with how your LED is hooked up.

Good Luck

no i havnt tryed it yet,but i will.
i also changed the led to that laser diode that i was selling a while ago
:confused:
i was also wondering if you could give me the code that you made for the brat software you made,that way i could see how it works?

I sent you a private message with the code…

Remember my code is for the Atom Pro…

This may or may not be relevant to this exact problem but is something I have run into…

If you are developing in Visual Basic 6 then you will be using MSComm as your serialport. This is okay for single byte communications.

If you are using VB.NET or any of the .NET family, the new serialport class implemented under version 2.0 framework is designed to send unicode not ASCII. In other words it will send 2 bytes for every character you send and will not send byte values above 127 (extended ASCII)

Microsoft says before opening the port use the following setting

serialport.Encoding = System.Text.Encoding.GetEncoding(28591)

This will allow ASCII eight bit and single byte transmission.

This particular nasty cost us 2 weeks development.

No,i am using VB (Visual Studio) 8.0 Pro.

Ok,i realy hope this works,
i finally think that the reason why i was having
a problem figuring this out is because i didn’t use a loop in the p-
rogram,

But basicly at the time,when i was trying to figure this out
i didn’t know what loops where :laughing:
yea i know,sounds stupid right.

any way,
i think this code i whipped together would work
perfectly fine,
but i still have to test it first,
wait,i forgot to tell you what it was for,
its for a pan and tilt:

Variables'{
	Exit var bit
	Tlt var word
	Pan var word
	Tlt_val var long
	Pan_val var long
'}
	


Variable_Values'{
	Exit = 0
	Tlt = 1500
	Pan = 1500
	Pan_val = 0
	Tlt_val = 0
'}


Center_Servos'{
	Pulsout p0,Tlt
	Pulsout p1,pan
'}



Main'{
'Loop the Program to Check for Data
'Every Milla Second
Pause 20
	Do
	Serin s_in,2400,1000,Center_servos,[Pan_Val,Tlt_Val]
    While Exit < 1 'If Exit is 1 then End the loop
End

Think that should work?

Not in VB.NET it won’t. Whatever that code is its not VB code.

It looks like some C based syntax…

Where did you get that?

This is for the basic atom,
only thing that the “}” and “{” are for is to represent blocks of code,
didn’t you see the Comment line there (’)

Very confusing, why the mention of this then…