Let's Make Robots!

Serial Comunication (wires and IR)

transmit data via wires or IR from and to an MCU (Picaxe)

 

(Notice: this walkthrough is going to be updated as i don't have time ATM to make videos and photos, so stay tuned!)

 

INTRODUCTION: 

Hi guys, here's what i learned about comunicating with Serial ports on my picaxe.

First of all, what can i do with this walktrough? Well, with serial comunication you will be able to transmit data from an mcu (picaxe) to another one. This could be useful if, for example, you want to make a remote with different buttons and want it to send different variables to the receiver, according to the button pressed.

But first i'd like to start with comunication with wires. The setup is pretty simple, all you need is a couple of wires. 

 

SERIAL COMMUNICATION WITH WIRES: 

What you have to do in this case is connect an output (any one) of the sender to the input(digital) of the receiver. You also have to make sure these two thing happen: (1) both grounds (of the two MCUs i mean) must be connected. This is because if electrons get sent from an MCU to another, they need to have a return path, in other words the circuit must be closed for the electrons to flow.  (2) the input of the receiver must be connected to the ground in series with a 10k resistor, else it will act as an antenna (won't say anything else about this since i don't know much).

Now to the coding!

SENDER:

        serout <outputpin>, <baudmode>, (<variable>) 

That's it? yes...  The output pin you are using goes into <outputpin> (wow i didn't know that!) the baudmode specifies the baud rate (i'd be glad if somebody more experienced than me could explain what it exactly is) and the polarity of the signal. For our type of connection we will be using iNverted (N) signals, while True outputs are used in conjunction with, say, a max232 chip. Just remember that not all speeds are available on every picaxe chip

RECEIVER:

        serin <inputpin>, <baudmode>, <variable> 

where <variable> is where the variable received will be stored. (i will add some more infos about the other features of the SERIN command later on)

 Remember that once the receiver bumps on the SERIN command, it will stop everything until it receives a variable, whereas when a program bumps on the SEROUT command, it will simply send out the code and get on with the program, even if that variable hasn't been received.

 

NOW IT'S INFRARED TIME!

well...it's quite the same. Only thing is that, of course, the two grounds won't have to be connected, as electrons won't be transmitted "over the air", they'll just enter the LED and get grounded, and that closes the circuit (simplified explanation)

The receiver will have the IR detector and demodulator connected to one of its inputs (connection depends on the type of receiver, however i'll be adding some schematics for a bunch of common TSOP sensors). The sender will have an IR led with its anode connected to a PWM port and its cathode to the ouput pin (which corresponds to the <outputpin>)

 Coding:

the receiver has the same code as written before.

SENDER:

     pwmout a,b,c

     serout <outputpin>, <baudmode>, (<variable>) 

where a, b and c are the fields which specify the pin used, the frequency and the duty cycle. This is needed because your IR sensors will work at a specific frequency, in other words they will only be detecting IR with a particular frequency (this of course depends on the receiver you are using. (for TSOPs the last two digits tell you the frequency in kHz they work at)

To make everything easier, just use PICAXE > Wizards > pwmout... your compiler. I am currently using 50% of duty cycle and it works fine for me. 

And this ends the walkthrough! Hope you found it useful.

 

 

 

 

 

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
i'll work on the tutorial as soon as i get back home. as for the 08, it just depends if it supports SERIN/SEROUT but i guess every picaxe does. If you are using 08m you can also go for IRIN/IROUT but i personally prefer doing it the SER way.

Thanks you Cap tuna! Hope there is more information to be added. Can this be used through different picaxe like 08m and 28X1? Thanks again for this walkthrough!

Good work Captain. I'll be trying this out soon. Thanks.

Top tip:

Regarding the <variable>: Sometimes you send a digit and you recieve a letter. Sometimes you send a string and you recieve it in another format. That is all I know about the problem.

Regarding the sollution, I know that sometimes you should use one of the below, and sometimes another, if you say get a letter when expecting a number:

b0
#b0
20
"20"

Also, if you get something you did not ecpext, it may be because you are using N where you should use T in <baudmode>, or the baudrate (that is the speed) does not match the hardware recieving.

Keep it up Captain Tuna!

Although I've been setting up Junior with both IR serial and Pic to Pic serial I haven't had the chance to test it yet. I think your tutorial can save me a few headaches.

As per Fritz's instruction above... Thank you Lord Tuna.

i have already setup the transistor style connection but haven't tried it yet. I was also thinking to decrease the duty cycle, would this be of help. Anyway, the transistor will definetly increase the range as more current will enter the LED. I am gonna add that later on.

 A question: how do you get to know which resistor to use (eg: you said 180 or 220)? Is it an approximate calculation or is it based on the amplification value of the transistor? 

When you're drawing the ma from pins on the proc, you have to be careful to not go over the limit of the actual proc. I think the axe can sink/source around 10ma. So you have a limit. With the transistor, you have less of a limit depending on the specs.

for the transistor using a

5 volt power source

voltage drop (forward voltage?)through led I've seen from 1.2-2v

R = (5V - 2V) / 0.02A (20ma)= 150 ohm (i use 180 so slightly less than 20ma)

Since I don't plan to use a high powered setup, and want to extend battery life, I'm looking at using lower values(or higher ohm values).

 <edited for clarification>

A bit more info on the connection for sending serial IR.

There are a couple of different ways to connect the ir led. The first way will limit your range as it connects 2 pins from the picaxe directly.

The first pin is of course the pwm pin(on an 08m pin 2) and a serial pin, (08m pin 0,1,4). The negative lead goes to the serial side while the postive lead goes to the pwm side. of course a 470 ohm resistor is in there as well. I was surprised to see this work, but it did.

  The second method which I prefer is to use an npn transistor like a 2n3904 or mps2222a. Collector is connected to the pwm pin, base is connected to the serial out pin, and the emitter is connected to the ir led in series with a 180 or 220 ohm res.

code is as cpt tuna noted.

 <edit> corrected transistor names and added other notes

I highly recommend this page for anyone interested in the serin while wanting to avoid the lock when using it on the lower end models. The higher end models have the timeout which is a great feature to have.

http://www.hippy.freeserve.co.uk/picaxesi.htm

This will also work with the serial ir, but one thing to note is that with the ir receiver, you will need to note the idle state in order to use the correct serin command variable for baud(2400_T/2400_N  setting).  From my exp with the recs, they've all run as idle high so you would need to use the _T modes.

Also for the transmitter while using the transistor method mentioned above, when attempting the interupt via a pulsout, you may want to switch the pwm to high as to not send a 38k modulated pulse. This could give erratic readings on serin(I'm still working on this issue in a project). 

Last last note, I'm pretty sure this would work to increase power if you make the transistors into a darlington pair though I have not tried this personally. 

tr1 emitter modulated output--> tr2 base.

Hey all,

Having just read the easy keyboard interfacing walkthrough, i'm wondering about which would provide a better interface, serial or keyboard. I was planning on mounting a keyboard on my bot, but would using serial data work better?

Personally, give me serial interface every time. You can hook up a PDA, for example, and use it as a keyboard, or an external high-level scripting device. I haven't used a keyboard in any project since I discovered the MAX 232.

I have to assume that the Captain's finding about the 10K resistor requirement is correct FOR A PICAXE. As such my best guess is that the picaxe doesn't have a proper line level driver.