Receiving numeric string from serial port

Tinker123

New Member
I'm building a project that requires the Picaxe to receive a numeric string from a serial port, the range is 0-500. I cannot find anything on how to do this.
I'm using 18M2, this is going to control an antenna for tracking satellites.
 

papaof2

Senior Member
"String", as in text characters? If you make the format consistent, such as always using 3 characters ("001", "056", "243") you could have built in error checking. Were there 3 characters? Was each between "0" and "9"? Then there's the conversion to numeric format for the PICAXE to be able to use the value of 318 - remember that your numbers require a word variable because bytes are 0-255 and you're values can be almost double that.
 

inglewoodpete

Senior Member
Have a close look at the syntax options available for the SerIn command - particularly with the "#" qualifier, which gives you the option to receive a string of digit characters "0", "1",...."9" (Eg 3 characters as the string "318", which is made up a 3 ASCII characters $33, $31, $38) and put them into a suitably sized register (a word in this case) as the decimal value 318 ($13E in hexadecimal)

Note that the M2 series of chips of PICAXEs could struggle to accept data arriving at baud rates faster than 4800 in many circumstances, unless each character is spaced slightly from the previous one to allow the PICAXE to process and save each character. You will have to experiment a little to see what the capabilities are with your particular situation.
 

westaust55

Moderator
Further to the advice by IWP, when using the # qualifier to input a value as a text string, to terminate the conversion you also need to send any non-digit character.
So a <cr> or even a letter such as “A” will result in completion of the value and storing the the defined variable.
 

Tinker123

New Member
Thanks, I'll try "#" .
I need it to accept the position for azimuth and elevation like degrees, it will be cross referenced in a table. The Picaxe will be at the antenna mount and will communicate with the computer via serial. I will send a position and the pedestal will move to that position, the drive has analog feedback, the pots have an A/D range of 0-500, that I will compare with the incoming data, I will then send updates to track the satellite. I actually have the hardware built and a simple program that allows me to manually pan and tilt it through the serial link, I just can’t get this large of number into it.
 
Top