Let's Make Robots!

serial communication on picaxe

i have been looking to do something with the easy radio module (forgive me if i do not use the correct terminology) but i have know idea how to use the serxxd, sertxd, serout and serin commands the explanations on the picaxe website wern't very useful . so do i just tell it to send out a random number ( with which command?) and then on the recieving end say if (again, i don't know which command) = then the same random number, then do what i want it to do. wouldn't that mean i have to put 

if this = this do this

if this = this do this

if this = this do this

if this = this do this

loads of times depending on what i want it to do and it would constantly be having to wait for the first command

what i said might not of made a lot of sense but i just really dont understand

thanks :)

 

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

I think I understand what you're getting at.

SEROUT and SERIN allow you to do serial communications through a pin you choose. SERRXD and SERTXD are similar but they use the serial out/in programming pins only. You probably want SEROUT and SERIN.

You setup SERIN on the receiving end. When you run the command It will wait (unless you have a chip that can use the timeout feature) until it receives data on the serial connection. Make sure to match the baud rates between the chips.

Random numbers are tricky and the best way to go about it depends on the chip you have.It's recommended to take a value from a timer and use it to generate a "random" value with the RANDOMIZE command.

IF/THEN statements will get the job done but if you have a lot of values to check it will take some time to go through, especially if the true statement is at the end. If you aren't cramped for memory I recommend the SELECT CASE method instead. It sorts through things faster but it's a terrible memory hog.

 edit - I just saw you're trying to get it to work with a wireless module. That will take a little more work. I described a PICAXE-to-PICAXE serial setup above which is a good place to start if you haven't done that yet.

I would break this down a bit more...

First off, Jax covered a bunch of it. One thing to note is the fact that when you use the Serin command, the code will camp on that command until it receives something. There are ways around this but again, lets keep this simple. Next, I would skip the random business as well --more complication. Instead, I would transmit a simple, single character for your first tests. On your transmitting picaxe, write a code to SEROUT "A" every couple seconds. Now, on your receiving picaxe, I would do this:

Loopy-loop:

variable = serin, yadda yadda
if variable = "A" then blink a led for 1 second
goto loopy-loop

And that's it and about as simple as you can get. This will eliminate a bunch of "other stuff" that could go wrong and will get you to where you need to be. I should also stress that eventually you should move on to the hserin command instead --it is FAR more useful, won't lock up your code and will receive in the background while the rest of your code trucks along. 

thanks for all the information. i'm sorry about saying "random" number jax all i really meant was just pick a number and then see if that number is recieved. i will try to understand everything so i know how to use these commands before i try any thing wireless

:)