Serial transmission and when to initialise it

Hello!

I am trying to figure out how to transmit data from one atmega to another one via IR. Oh btw i am using arduino language.

First thing i though of was setting the serial communication by using serial.begin in the setup function. I tried that and i noticed that the LED connected to the TX pin on the arduino lights up as soon as i give power to the atmega. This is not really what i wanted, cause i'd like to have the LED off when not in use.

My project involves an user pressing a button to send serial data to the other atmega. Do i have to initialize the serial command only when the button is pressed and deinitialise it when the button is released in order to keep the LED off when not in use? Does the serial.begin take long to set? (...because i want the serial data to be sent exactly when the button is pressed, not 1 or even half a second later)

 

Thank you!

low = 1 perhaps?

I know nothing about atmega/arduino, but I do know that some serial protocols use the low voltage for 1 and high for 0. I would imagine a serial output that is not in use is effectively emitting 0’s all the time. Which would translate to a emitting LED in your case.

Maybe you need a second output pin as an “enable” function, plus a bit of electronics to switch your LED circuit on/off depending on that pin.

I don’t get why a serial

I don’t get why a serial output not in use would mean an emitting LED. Actually i forgot to tell you that the anode of the LED is connected to the TX pin and the cathode to GND.

I think i’ll follow your advice, i’ll place a seocnd pin (actually third, the second one will be for PWM). Or else i could also connect the anode of the LED to V+ and the cathode to the TX pin in order to reverse the “no-transmission=high led” and make it “no-transmission=low led”

The UART on the Arduino is

The UART on the Arduino is low active. The TX pin should be on high level, when not in use.

Sending /receiving serial data over IR isn’t as easy than you may think. I know that the asuro robot uses IR for communication. Here is the schematic that’s been used.

ir_interface.jpg

 

The trick is to use a PWM output (PB3 in this case) with a 36kHz 50% duty cycle signal to modulate the TX signal (PD1) on the IR LED. The receiver is a simple IR receiver IC, connected to the RX pin (PD0). Without this trick, you will only receive garbidge. A maximum baudrate of 2400 is possible.

 

 

yea that’s somehow i am

yea that’s somehow i am doing it but instead for the transmission i use two FETs because when the project will be complete they will have to deliver some 1A to the LED. It’s kind of similar to picaxe after all, only thing is the “low active” transmission. Thanks for the info!

noobish electronics question: is there a way i can reverse the fact that the tx is high when not transmitting and make it low instead? (i could use P channels instead of N channels…but are there other ways?)

Just having an led on the TX

Just having an led on the TX pin wont work very well. Even modulating it a little isnt an ideal solution. There are chips that have specific protocols designed for IR transmission to make sure no data is lost. Society of robots as a tutorial on the topic:

http://www.societyofrobots.com/electronics_irda_tutorial.shtml

 

When you use the hardware

When you use the hardware UART, there is no way to invert the signal, except you do it externally. With a software UART you can do what you want, because you program it bit for bit. But keep in mind, that the receiver also need to understand the inverted signal.

 

Thanks. I think i’ll go for

Thanks. I think i’ll go for P channels then, so that i’ll have the LED on when the signal goes low. In fact the severino, which is an arduino clone, has the tx LED activated by a pnp transistor.

 

EDIT: i don’t have P channel mosfets in my house :frowning: too bad. But i just had an idea, i am gonna make a NOR gate! http://hyperphysics.phy-astr.gsu.edu/HBASE/Electronic/trangate.html :open_mouth:

the point is that i WANT
the point is that i WANT data to be lost… hehe :=) sounds quite strange i know. The fact is that i am building a lasertag “weapon” which “fires” digital, infrared, bullets and they don’t always have to be THAT precise, and losing data would come in quite handy as it would mean that a bullet just passed near you without hitting (this would then play a sound to warn the player). Afaik IRDA handle most of the things themselves like handshaking and all that but…I want to do that myself so, at least for now, i’ll just stick to modulated IR leds. Thanks for the info.

I’m not sure I understand
I’m not sure I understand the issue, a tv remote works fine by enabling the signal to send by pressing a button. I assume the same thing is in mind for fireing the ir signal. press the trigger, send the signal. so when you are ready to send the signal, turn the ir on, then send the data. then go low again when done. Am I missing something in your question? this is what you want. There are no special tricks to this except maybing doing the carrier frequency(ex 38khz).

My problem was that i was
My problem was that i was used to the picaxe-way of transmitting serial data. The picaxe serial pin stays low if you don’t give it anything to transmit, whereas the arduino, once you initialise the serial mode (something the picaxe didn’t have), makes the TX pin go high when not in use. That’s all. The solution will be to use either a NOR gate (the two inputs are the serial one and the PWM having a frequency of 38KHz) or just inverting the serial pin with a NOT gate so that by default (non-transmitting) it will stay low.