Using the serial port

I just notices something. You shouldn’t use a speed argument in hservo for the first hservo command you use. That could cause your servos to freak out intially because there is no previous position for hservo to calculate the intervening position steps.

Also in your code you make out=5 and then dec out so you should see a “5”. Not sure where you are getting a 52 in that code.

Also you are using compile time directives(#IF) instead of runtime commands(IF) with a variable. This is not going to do what you expect. Change all the #IF,#ELSE,#ENDIF to if,else and endif.

Also I recommend you chaneg the if statments from:

if inputdata = dec 2

to

if inputdata = “2”

It may work out to be the same thing but you are runing extra code to convert the number 2 into a “2” string using the dec modifier in your if then statements.

Also you don’t really need that last inputdata=0 because as soon as you jump back to main you run a serin that will wait until it receives some character which is going to change inputdata = to whatever that characters value is.

Thank you so much, it was the compile time ifs, i thought they were run time
thanks you all for putting up with my stupid questions lol

I would just like to get something cleared up about the RTS and DTR pins.
ive started to write my python application to send the data and it is not working.

I have this code to deal with those pins

ser.DTRlogic = False ser.RTSlogic = False
is there a way i can test to make sure these pins are in the correct state?

Look at the pins with a multimeter? wire up an LED and a resistor and use that?

Alan KM6VV

I guess i should of been more specific, should it be 0v with the multimetter?

I’m pretty sure you want to set them to reset the chip and then clear then to let it run but the simple solution is to look at the ATN pin on the module when your code gets to those lines(ie step through your C# program). On a multimeter the ATN pin should be low when the chip is running and high when in reset.

I still cant get my code to work. Its really getting frustrating cause I do not know where the problem is. I hope there’s somebody that can help with the python code.

import serial
import time

ser = serial.Serial(0)
ser.DTRlogic = True
ser.RTSlogic = True
ser.open()
time.sleep(30)
print "check"
ser.DTRlogic = False
ser.RTSlogic = False 
print ser.portstr
time.sleep(30)

print "going"
ser.write("3")
#print (ser.read())
#print (ser.read())
ser.close()

any ideas and help would be greatly appreciated

When you open your comport are you opening it with flow control disabled? If you don’t specifically do this you may be opening it with hardware flow control which is going to mess with your RTS and DTR lines.

I suggest you disconnect the pc serial connection from the board and then connect the pc tx and rx serial lines together. Then send an ascii string and see if it is received by your program. If this works, then there maybe something going on on your board like a mismatched baud rate.