Introduction:
For our final project, we want to build a wireless drawing device. The user uses a keypad or a mouse to draw on the TV through a wireless communication medium (RF - 433.92 MHz). The user should be able to move the drawing pointer to anywhere within the four border lines. One should also be able to draw or erase images on the TV screen.
In designing this project, we have two goals - a primary, which is realizable, and a secondary, which is feasible. Our realizable goal is to build a wireless keypad interface with the television. In this interface, we want the keypad to be able to draw and erase on the TV. When we accomplish our primary goal, we shall attempt to achieve our secondary goal: to build a wireless mouse having the same functionality as the keypad. Due to time constraints, we ended up only being able to complete the primary goal. We chose this project because we were inspired by wireless communication technology.
Before we begin our design, there are some issues that we need to be be considered. There are two major parts to this wireless drawing device - a TV side and a keypad side. Therefore, there are two microcontrollers used: one for the TV side and one for the keypad side. The user interface (keypad side) of our drawing device consists of three buttons, left, right, and middle buttons, and a keypad or a mouse chassis. There is also a drawing pointer of size one pixel to ascertain where the drawing will occur on the TV. Drawing FunctionsThere are three things that must be done in order to draw properly on the TV screen. The first is the drawing pointer movement. The pointer should be able to move up, down, left, right, and diagonally in all directions. The second thing is to draw on the TV screen. One needs to press the left button to draw wherever the drawing pointer is. Lastly, one needs to be able to erase the TV screen. One must press the right mouse button to erase wherever the mouse pointer is. If one presses the middle button, it will clear the TV screen and reset the drawing pointer to the center of the screen. Wireless CommunicationThe connection is made via Universal Asynchronous Receiver and Transmitter (UART). We based our design on the Atmel Mega163 data sheet. On the keypad side, the microcontroller sends directional and button press signals to the transmitter via the TxD pin (PORTD.1), which is in turn received by the receiver on the TV side. These received signals go into the RxD pin (PORTD.0). Also, the transmitter sends data at 433.92MHz. It has a maximum data rate to 4800bits/sec. We calculate the baud rate by using the formula given in the data sheet, UBR = fck/16(UBR+1), where fck is the crystal clock frequency. This UBR equation can be found in table 27 in the data sheet. For a 8MHz crystal, UBR = 103 will give a baud rate of 4800. In order to get optimal transmission and reception, one needs to make the antenna approximately the size of one-quarter the wavelength of the transmitted signals. In our case, the wavelength is approximately 70 centimeters, and one-quarter of that is about 17 centimeters. Basic SetupOur drawing device consists of three functions. The first function is the movement the drawing device. For a keypad, one can press keys 1 through 9 for directions. Examples of these directions are 1 is move up and left, and 6 is move right. On the TV screen, the drawing pointer will move in the corresponding directions. The second function is to draw and erase on the TV depending whether the left or right button is pressed. Lastly, we need to encode the button presses and directional movements into a signal and send the encoded signal to the television side via the transmitter-receiver pair. On the TV side, we then need to decode the received signal in order to show the graphic on the TV screen. The basic hardware connection is shown below: |
Materials used:
- 2 Atmel Mega 163
- 1 keypad
- 3 buttons
- 1 transmitter: RCT-433-AS from Radiotronix
- 1 receiver: RCT-433-RP from Radiotronix
- 1 TV
- 4 AA batteries
- Two 0.1uF,and two 27pF capacitors
- Two 0.01uF,and two 4.7uF capacitors
- Two 330, two 1k, one 160, and one 75 Ohm resistors
- One 3-terminal Positive Regulator: LM340
- One operational amplifier: LMC7111
Hardware Design
The hardware design for this project is slightly tricky. The hardest and most time-consuming part of this design was getting all the hardware parts to communicate properly with each other. Constructing the keypad side microcontroller design, an off-board microcontroller, was interesting.
We followed the diagram given on the Build your AVR Starter Kit page. We place one 27pF capacitor to pin 12 (XTAL2) and one to pin 13 (XTAL1) with a 8MHz crystal between those two pins. We place a 160 ohm resistor at pin 9 (reset') to pull the reset' to high to prevent constant resetting. Usually, reset' does not require a pullup, but with the RF transmissions, there is added RF distortion on the chip, which requires the pullup at reset'.
After many tries with different resistor values, we found that a 160 Ohm resistor gave the best result at pulling up reset'. This does cause a decent amount of current to be sucked from the battery source, but when we tried using a 10k Ohm resistor, there was still constant reseting. To program the chip Pins 6 to 11 are connected to SPROG3. Between Vcc and Gnd, there is a 0.1uF capacitor.
On the TV side, there were a few connections needed between the TV MCU and the TV-side hardware. Here are the port/pin connections for the TV side:
PORT D | PORTD.0 to Receive data pin |
PORT A | for TV Images PORTA.6 to video PORTA.5 to sync |
NOTE: We place an operational amplifier between the receiver data pin and PORTD.0 to amplify the received signal. We amplified the signal from 3.8V to 4.6V.
On the keypad side, there is more hardware used. We use four AA batteries as our power supply for the keypad off-board MCU. We also use a voltage regulator to keep the voltage constant at 5V. The connection of the regulator to the board is shown in the diagram below.
The input pin is connected to the positive side off the battery and the output pin is the 5V power supply of the board.
The keypad port/pin connections are listed below:
PORT B | PORTB.0 to button 1PORTB.1 to button 2 PORTB.2 to button 3 |
PORT C | to Keypad |
PORT D | PORTD.1 to transmitter data pin |
Keypad and TV are connected as used in labs 5 and 3, respectively.
Transmitter and receiver connections to their respective MCU's are shown below:
Our software design can be divided into two different components.
Keypad Side
On the keypad side, we need to be able to detect whether the push buttons are pressed or not, and which one is pressed. These are taken care of in our "check_button" function by our state machine. The state diagram can be found in the Appendix page. Additionally, we need to find the direction that the drawing pointer is moving. Below is a table that shows how each key press gets mapped into up, down, left, and right. This encoding scheme is done in our "encode_direct" function, which takes in four directions from the keypad. Our "get_direct" function determines which keypad directions are pressed. This state machine's state diagram can also be found in the appendix page.
Key Press | Up | Down | Right | Left |
1 | 1 | 0 | 0 | 1 |
2 | 1 | 0 | 0 | 0 |
3 | 1 | 0 | 1 | 0 |
4 | 0 | 0 | 0 | 1 |
5 | 0 | 0 | 0 | 0 |
6 | 0 | 0 | 1 | 0 |
7 | 0 | 1 | 0 | 1 |
8 | 0 | 1 | 0 | 0 |
9 | 0 | 1 | 1 | 0 |
We use timer1 for the directional movement and timer2 for checking button presses. Both timers are run at 2ms.
Like we described on the High level design page, we use UART to transmit signals. We set the UART control register to Transmit Enable by setting UCRSB = 0x08. We also need to set the baud rate to 4800 by making UBR = 103. And we set UDR = data_to_be_transferred when we want to transmit data.
TV Side
On the TV side, we need to take care of the actual drawing. On reset or when the board first initializes, the television screen draws four lines, one on each edge of the screen, to signify the borders of the screen's drawing region. It also places the drawing pointer at the center of the drawing region. Using some code that we had implemented in laboratory three for the TV drawing, we got our television to display images. We want our drawing device to draw anywhere within the four border lines. We only use timer1 and run it at full speed on the TV side. Timer1 is interrupted after 509 timer ticks to make each frame exactly 1/60 of a second.
We use the "video_line" function to draw the border lines, "video_pt" function to draw any other images, and "video_set" function to determine whether a pixel is drawn on the screen or not. Each of these functions can be found in the laboratory three code and on the Video Generation with AVR microcontroller page.
During the vertical blanking (from line 231 to 262), We need to decode the received signal to determine what we want and where we want to draw on the television. We need to decode the drawing pointer direction and button presses for draw, erase, and clear screen. One can draw on the TV when the left button is pressed and erase when the right button is pressed. Pressing the middle button will clear the screen.
As described in the High level design page, we also use UART to receive signals. On the reception side, we set the UART control register to Receive Enable by setting UCRSB = 0x10. We also need to set the baud rate to 4800 by making UBR = 103. We set the received_data = UDR.
RESULTS:
After much debugging and tweaking, we finally got our project to work as we specified. All the hardware testing and debugging took a great amount of time. Our wireless drawing device is able to transmit and receive data and draw anywhere on the TV. We did not get to implement it so that it will work like a mouse.
One thing that is worth mentioning here is that we had to make sure that the antennae for both the transmitter and receiver were fully extended in order get best transmission and reception results. In fact, in testing our range, we could draw on the television from anywhere in the laboratory, which is about 15 meters. We were also able to walk out of the laboratory, all the way to the water fountain outside all the labs' area, and still draw on the television; that is about 20 meters. As long as there is not much RF interference, our range and reception are pretty good.
We could draw rather quickly - no measurable delay between movement direction and resulting television image. Our drawing mechanism was also rather accurate. When trying to draw, what we wanted to draw appeared as the image on the television.
Below is a picture of our entire setup working - transmission, reception, and images being drawn on the television. On the oscilloscope, one can see that the receiver is receiving what the transmitter transmitted. On the oscilloscope, the top line with the square waves is the transmitted signal. The bottom line is the received signal. One can see that they are identical with a slight delay of about 60us between transmission and reception.
Conclusion:
After more than four weeks of designing, debugging, and tweaking, we have a fully functional wireless drawing device. We are able to use a wireless keypad to draw on a television screen. This project would have been much more intensive harder had we needed to code all the television timing and blasting to the television code ourselves. We are under our budget limit for the project. We spent a total of $5.77 on the transmitter and receiver only. We got the regulator and op-amp from the lab
If we were to do this project again, we would have initially started with the keypad instead of trying to get the photosensors working. After getting the keypad wireless drawing to work, we would then implement the photosensors, so that the user can use our drawing device like a mouse to draw on the television.
Our project is a wireless design. We are not infringing on anyone's patents by building it, but had wireless mice not been around for so long, we may very well have broken some patent laws. Our wireless medium is RF with transmissions at about 433 MHz. Nothing in this project is too hazardess to one's health. Although, on occasion, the voltage regulator would get rather hot. When that occurred, we would merely disconnect the battery source to let it cool down. So, if this were a real marketable product, we would have to take care of that issue, as well as probably making it prettier to the eye.
When we were working with our RF, there was usually at least one other group using the same frequency as we. Therefore, we needed to share the bandwidth. Obviously, sending all sorts of RF signals around the small lab room will cause interference in each other's transmissions, so we would always need to talk to the other to make sure that when we were running our transmissions, they would not and vice versa. Everyone that we talked with in the labs always seem agreeable to these circumstances.
Our original primary goal was to get the photosensors working and have the wireless drawing occur via the use of a mouse-like device; however, it took us far too much time to try to figure out how an optical photosensor worked. We searched every hardware site that we could find and asked the TA's and the Professor if they knew of a schematic on the device, but we could not find one. Since we had no schematic on this optical photosensor (it was a part laying around in the lab), by the time we got the photosensor running properly, we still needed to get the optical encoder and directional movements working. We truly wanted to make a wireless mouse - one that looked like a mouse, and not a keypad, for this drawing device. we believed that we could feasibly do so. However, the time constraints just got us.
We had no working drawing device with about a week left, so we ported over to getting a wireless drawing keypad to work first, and then get back to trying to get the optical photosensors working if there was still time remaining. So, we ended up having only a wireless keypad drawing device.
Throughout the lab sessions and extra hour sessions, the TA's, especially Sean and Chris, and the Professor were exceptionally helpful. There were times when some minute thing would just not work or times when we were trying to figure out a best design for our circuits, and we would be stuck trying to debug a tiny bug in our circuit or our program. It did not matter which of those three that we would ask, but each would always be quite able to help us.
Schematic for the keypad side:
Schematic for the TV side:
Parts
- Surface Mount 433.92MHS SAW-Stabilized OOK Transmitter from Radiotronix: $2.24. The mechanical layout of the device is shown below.
- Low-Cost 433.92 Super-Regen ASK/OOK Receiver from Radiotronix: $3.53. The mechanical drawing and the pin-out diagrams can be found below.
- LM340/LM78XX Series 3-Terminal Positive Regulator from National Semiconductor: No cost. We got this from the lab. The diagram of the regular is shown below.
- LMC7111 Tiny CMOS Operational Amplifier from National semiconductor: No Cost. We got this from the lab. The connection diagram of the op-amp can be found below.
State Diagrams
- State diagram for button push:
- State diagram for keypad:
CODE: click to download
0 comments:
Post a Comment