Author Options:

How do I control a Picaxe using Cocoa? Answered

I want to be able to control a servo connected to a picaxe connected to my computer through Cocoa. Looking through the manuals, it looks like If I want to control anything "dynamically" (dynamically meaning control it through the USB cable after the program has been downloaded to the board), I need to use a command like "serrxd," except I don't know how to use the command, the manual doesn't help, and I'm not even 100% sure that is the right command to be using. What command should I be using, and how do I implement it?

Note: I am using a picaxe 28X1



8 years ago

These are not difficult if you read the manual examples and experiment a bit.

All you need is a terminal prog to send the data from the PC. Hyper terminal is most often used.

Try the forum and search for the command names for further support.

Sertxd and Serrxd transmit data to and from the picaxe. As the command example in the manual shows you

SERTXD ({#}data,{#}data...)
- Data are variables/constants (0-255) which provide the data to be output.
Serial output via the serout programming pin (baud 4800, 8 data, no parity, 1

for b1 = 0 to 63 ; start a loop
sertxd(“The value of b1 is ”,#b1,13,10)
pause 1000
next b1 ; next loop

SERRXD (qualifier,qualifier...)
SERRXD (qualifier,qualifier...),{#}variable,{#}variable...
SERRXD {#}variable,{#}variable...

- Qualifiers are optional variables/constants (0-255) which must be received in
exact order before subsequent bytes can be received and stored in variables.
- Variable(s) receive the result(s) (0-255). Optional #’s are for inputting ASCII
decimal numbers into variables, rather than raw characters.
- Timeout is an optional variables/constants which sets the timeout period in
milliseconds (not available on M parts).
- Address is a label which specifies where to go if a timeout occurs.
Serial input via the serial input programming pin (at fixed baud rate 4800 (9600
on X2 parts), 8 data, no parity, 1 stop).

If you want a simpler command than use serin serout BUT these commands when actioned do not time out until they receive data and so can hang up the system if the expected message isn't received.

Sertxd and serrxd do have a time out .

You are sending data - servo position down the serial cable - USB link to your picaxe.

HOWEVER if you are happy to have the servo connected to the PC all the time you could just generate the required pulses and send them direct avoiding the need for the Picaxe. Although the Picaxe will do a lot of servo house keeping for you - ie sending the pulse at the appropriate repetition rate.


Answer 8 years ago

Seeing as how I found no way to connect my servo directly to my compute and no way to control it from there, I decided to go this route, because it looks easier.


8 years ago

The USB connection probably presents itself as a VCP, a virtual com port, to the computer. Basically, you have to provide some way to write to the port in your application code

This is a code class to access the serial port

I found it on here http://www.harmless.de