Hello, I am thinking about doing a project, where I can transmit morse code from one arduino, with the output a laser, and across the room, have another arduino with a photoresistor. The second arduino can read the delays and print in the serial port, Dash; Dot; Dot; Dash; according to what it is sensing.
I have got the tranmitting code, but I am having some trouble with the recieving code, and thought that you could help me out. i am thinking that the recieving code would use the button library, to read the morse code, but I am not sure, so can you please help me??
Here is the transmitting code:
int pin = 13;
dot(); dot(); dot();
dash(); dash(); dash();
dot(); dot(); dot();
What is the relationship between a photoresistor and a button that would lead you to think that the receiving code would use the button library?
To make things easier I think you should use the international format for correct morse:
- A Dash is equal to three dots.
- The Space between parts of the same letter is = 1 Dot.
- The Space between two letters is = 3 Dots.
- The Space between two words is = 7 Dots.
If you stick to this you will find decoding much easier :o
What you need to do is to write the receiver code for what is called a USART (universal software receiver/transmitter). A USART is just a UART that's implemented in software. So you need to read up on how a UART receiver works.
Clue: No established UART speeds are within 6.25% (=1/16) of each other.
Basically, the receiver must sample the incoming signal at 16 times the bit rate. In your case, the bit rate is one over the duration of a Morse dot. So if your dot lasts 200 ms (5 Hz), you must sample eighty times a second. With that sampling rate, the receiver can reliably determine on/off transitions even with slightly noisy input. It's somewhat like debouncing a mechanical switch.
If the receiver can sample at higher rates, a little cleverness can also allow it to determine the baud rate by measuring the duration of an incoming start bit.
Try to google "Arduino + laser modem" this will give you a link to someone who did something along the same line, just serial over laser instead of morse.
First develop your transmitting and receiving software just using a digital output pin for the transmitter board wired to a digital input pin for the receiver board. Remember to also wire a ground connection between the two boards.
After you get all the bugs out and the software is working like you want then you can work on the laser receiver components. I don't think a simple photoresistor will be enough as you want to end up with a valid high or low logic voltage, not a analog variable voltage that a photoresistor will give you. I suspect you will require a phototransistor and a Schmidt trigger gate, but there may be other methods.
A USART is just a UART that's implemented in software.
Nice try, but incorrect! The 'S' does not stand for 'software'. The implementation (software vs hardware) has nothing to do with it.
USART = Universal Synchronous Asynchronous Receiver Transmitter
UART = Universal Asynchronous Receiver Transmitter
A UART cannot inherently perform 'Synchronous' serial communication.
Thank you for the correction. It's been many a year since I've had to work with 16550's and the like.
You mean you don't remember the 8250's?
simple photoresistor will be enough as you want to end up with a valid high or low logic voltage, not a analog variable voltage that a photoresistor will give you.
It depends on how you wire up the photo transistor. If you put the load in the emitter then yes you will get an analogue output. But if you put the load in the collector you will also get the gain of transistor comping into play and you get a much more digital response. Yes there is always a transition area but it is not very large.
In all other respects I would agree with you. I first did a Morse code to video converter in 1974, it was my first embedded micro processor project although they didn't use the words embedded at the time.
Morse code is very slow and not a very precise way of letting two machines communicate with each other. If it is for the "show" then this is fine but as a practical thing I would avoid it.