You Are Here: Home » AVR ATmega Projects » Sensor - Transducer - Detector Projects » Electr-O-Sketch Using Atmega 32

Electr-O-Sketch Using Atmega 32




Introduction

We created a project in which a user could control the movement of an Etch A Sketch using a typical serial mouse.

Electr-O-Sketch Using Atmega 32

The public was introduced to the EAS in 1960 and since then it has stayed virtually the same.  This nostalgic toy is recognized by many generations and we decided to put a new spin on the device.  Most Americans are familiar with the two knob design which allows a user to control the movement of a stylus by turning each knob.  The left knob controls horizontal motion and the right knob moves the stylus vertically.  Turning both knobs at the same time causes the stylus to draw out a diagonal line.  We decided to mount a stepper motor on each knob and control those with the Atmel Mega 32.  By connecting a serial mouse to the microcontroller and using our line drawing algorithm, we could move the stylus directly by moving the mouse.  The ability to record movements and play them back is available for creating more interesting designs.

In designing this project, we decided to create something that was a mix of mechanical and electrical components and would ultimately be fun to use.  Using an EAS would be a throwback to our childhood but adding the mouse also revitalized the toy.  Many students who saw us working with the EAS were immediately interested in what we were doing because it is such a popular childhood toy.  Though the control of an EAS with a mouse is not necessarily a practical project, we thought it would be a good way for us to practice our engineering skills and would be something entertaining to do.

High Level Design

The source for this idea was an old 476 project that utilized 2 stepper motors on an EAS to draw pictures that were received from a computer via a serial connection.  We wanted to work off of this idea, but let the immediate user create the picture with ease.  A simple block diagram of the design is provided.

There were only a few tradeoffs that we ran into.  The one major one being the choice of a stepper motor driver IC over that of several H-bridge resistor networks.  The resistor network would simply add more complexity and a possible point of failure.  By using the IC from Motorola we were able to simply output a few digital signals from the MCU and move the motors in any direction we want.

A small tradeoff in software was the use of automatic changing of the step size.  Originally the step size was set via a button on the STK500, but once we realized that we could change this automatically with the amount of mouse movement, this was eliminated.  The user is then not in direct control of the step size, but rather the software will do this for him/her.

We decided that it would be best to use a serial rather than a PS2 mouse in our project because of the simplicity of interface.  For our purposes, the serial mouse would suffice and because the crux of the project was the actual control of the stepper motors, we decided not to worry about the PS2.  PS2 is a synchronous bidirectional protocol which is much more complex than the serial mouse.  However, in order for us to interface with a Microsoft serial mouse, it was crucial to understand the serial mouse protocol.  First, it has a baud rate 1200 which is actually so slow that it is undocumented in the Atmel Mega 32 datasheet.  We had to calculate the proper values for the USART register to read the data in at the correct rate.  The mouse then sends data packets in groups of three bytes each with a single stop bit.  To separate the packets, the first byte has a 1 in the second most significant bit whereas the other two bytes have a 0 in that location.  The mouse transmits data each time it changes states, updating up to 40 times a second.  Each packet contains information for the buttons and for how much the mouse moved in the x and y direction relative to its last position.  Each directional movement is a byte in length and is in twos complement.

The layout of the transmitted information is as follows, where X7..0 and Y7..0 are the change in the respective direction since the last update.  LB and RB are the left and right mouse buttons, which are active high.

 

D7

D6




D5

D4

D3

D2

D1

D0

1

1

LB

RB

Y7

Y6

X7

X6

2

1

0

X5

X4

X3

X2

X1

X0

3

1

0

Y5

Y4

Y3

Y2

Y1

Y0

This originally posed a problem for us since we thought that the mouse would not be powered by the STK500 serial port.  To work around this we decided to power the mouse from Vdd off the STK500 and run the TX line from the mouse directly into PORTD.  This ended up not working since the output from the mouse is TTL serial and the Atmel will not recognize this.  The serial port on the STK500 has some circuitry before connecting the input to the Atmel so that the signal is modified to correctly meet the specs of the Atmel USART input.  To use the serial port and Vdd from the board, we setup a jumper on a whiteboard to give the correct voltages to the mouse and then output the mouse TX line directly into the RS232 port on the STK500.

The EAS name is a trademark of The Ohio Art Company as is the configuration of their product.  We understand and respect the fact that it is trademarked and also a childrens product.  In this project we are attempting to simply create an interesting control for such a beloved product and in no way would attempt to harm the image of the toy or company.

We also recognize the patents for the EAS and our serial mouse held by The Ohio Art Company and Microsoft respectively.

This project was created solely for academic use in Cornell Universitys ECE 476 course and was not intended for profit.

Design

The line drawing algorithm that was used was a variation of the Bresenham algorithm, since our design needed to use a plotting type function.  The stepper motors need to turn in such a way as to connect 2 points in the xy-plane.  This is very similar to that of connecting 2 points on a pen plotter or 2 pixels on a computer screen for basic graphics.

The only way a individual knob on the EAS can move is one step of the stepper motor in either direction, this corresponds to one pixel movement at a time.  So the line can now be drawn from a single point either up, down, left, right or diagonal one pixel.  This can be accomplished by moving one motor in either direction, or both motors in a direction to achieve a diagonal.  Now that we can have a slope of 1, the task of creating the appearance of different slopes was tackled.  To do this the EAS starts at the beginning point and finds the slope to the desired end point and tests if its greater than 1 and determines where to move one pixel.  After this move is completed the start point is now the current location and the slope to the end point is re-evaluated in a loop until the end point is reached.  The code to complete this can be made much simpler and quicker by adding in shifts and several variables to track the change with each movement.

 

To step the motors a Motorola MC3479P integrated circuit was used.  This IC enables simple control of the MCU over the bipolar stepper motors.  Since switching currents in the coils via an H-bridge or other methods was not desired and more difficult, the IC was used for quick, robust control.  The main inputs to the IC are the step clock, step direction and the step size.  The IC will output the correct signals to the motor once a rising edge of the step clock is seen.  The step direction, clockwise or counter-clockwise, and step size, half or full step, have an effect on the signals from the IC at this rising edge.  There is a certain setup and hold time for these signals before the step clock.  To take this into account the outputs from the MCU to the IC were run on a TIMER0 run state machine.  TIMER0 was set to go off every 0.25ms, or 250us, and thereby going through the state machine at a desirable speed.

The initial state sets all of the outputs to be 0, which holds the motors in the current position, and waits for a flag to signal that it is time to step the motors.  The next state simply decides whether the slope is more or less than 1 and then sends the state machine to the correct path.  The direction bits are then set on the appropriate state followed by a state which sets and holds the step clock high on the calculated motors input.  The state machine then runs until the end point of the line is reached.

Timing for the step clock was figured out from the number of mouse inputs that were received in a second.  Since there are a possible 40 mouse updates per second, this meant that for maximum resolution all of the stepping for a current mouse movement had to be completed in 25ms.  By experimentation, it was found that the stepper motors would not have the required torque to move the EAS knobs when the stepping frequency was above 500 Hz.  To keep the frequency below this, the maximum number of steps in a given mouse update was set to 10, and from there the hold time of the step clock could be calculated to allow the state machine to achieve accurate timing.

One of the problems we encountered in the final testing phase of the project was that the EAS lacked the precision we were hoping to achieve.  Fine details were distorted or missing because of stepping problems.  The original configuration of our code was designed so that a mouse while moving quickly would still be correctly drawn on the EAS.  To do so required us to make long, quick steps so that the drawn line would be complete by the next update from the mouse (1/40 sec later).  However this rush to cover large distances did not correctly interpolate fine details.  Ideally, when the user desires fine detail, the motors could take more time and have shorter steps causing the picture to appear less discrete.  We then modified the code to allow the user to switch between a fast, full step mode and a slow, half step mode.  Following this, we realized that when a user is concerned with fine detail, he would be moving the mouse slowly, thus the original concern for not completing the line before the next update would be nonexistent.  Current software checks the speed of the mouse and adjusts the step size to fit accordingly.  Using a half step at the same clock rate, causes the motors to only draw half of the possible distance but gives twice the resolution.  Switching between the two speeds may sound alarming, but it is not noticeable to the user.  Hence newest code can switch automatically for the user to allow him to draw both fine details and large movements.

Electr-O-Sketch Using Atmega 32

The reset position function is designed to center the stylus in the middle of the EAS from starting anywhere on the board.  However without any feedback, the microcontroller would not know where the stylus is at any point in time.  This is caused by slippage in the knobs and random positioning during startup.  We quickly discovered a phenomenon of the EAS that allowed simplification in software.  The EAS knobs can be turned even when the stylus has reached the edge of the drawing surface and amazingly will move back on screen as soon as the knob is turned in the opposite direction.  Our state machine works by moving the mouse down hundreds of steps, so that the stylus ends up at the bottom of the screen.  It then is moved left hundreds of steps so that it will end in the bottom left corner.  The motors proceed to turn back to the right and then up a set amount of steps so that the stylus ends in the center of the screen.  Thus the EAS can be centered without the use of any feedback.

 Parts list:

Part Description Part # Quantity Price Total Supplier
      
Stepper motors (Bipolar)

163395CL

2

$4.95

$9.90

Jameco
Etch A Sketch

1

$0.00

$0.00

Old parts
Serial Mouse

1

$0.00

$0.00

Old parts
Aluminum coupler

161998

4

$1.09

$4.36

Jameco
Rubber coupler

162000

2

$1.29

$2.58

Jameco
Atmel Mega 32

1

$8.00

$8.00

 
Breadboard

1

$5.00

$5.00

 
Stepper motor drivers (Motorola IC)

MC3479P

2

$3.38

$6.76

Digikey
RS232 male connector

2

$0.30

$0.60

Clark Stockroom
0.040″ sheet aluminum & screws

1

$0.00

$0.00

FSAE Lab
12V Power Supply 

1

$0.00

$0.00

Old parts
    Total

$37.20

For more detail: Electr-O-Sketch

Leave a Comment

You must be logged in to post a comment.

Read previous post:
Leaves of ancient carnivorous plants found in Baltic amber

(Phys.org)—A team of researchers affiliated with several institutions in Germany has discovered samples of two types of carnivorous plants that...

Close
Scroll to top