Snake Rулит!    Artem. Live.
Primo      CV      Viator      Elektro      Foto      Scientia(news)
26.10.2008

USB DANCE PAD (atmega8 based)

1. Intro

This is a dance pad for dance game like Stepmania (www.stepmania.com), In The Groove (ITG) and some more. Basically, it is a square mat (90 x 90 cm) divided into squares 30x30 cm six of which are used as buttons.

1.1 Features

  • works via USB port w/o any extra drivers as a standard joystick
  • fully selfcalibrating
  • no moving parts or complex mechanical parts (seems to be very reliable)
  • indication of activity via LEDs according to the "pressed" buttons
  • two modes of operation: 6 button joystick and 2 button 2 axis (XY) joystick
  • reliable and sturdy surface which seems to be able to take a lot of beating
  • three part mechanical structure can be taken apart for storage and transportation (USB cable, electronics, sensor mat)

1.2 Analogs

I cannot say that I was searching very hard, but I have found some. However, all found devices were either with only 4 buttons, or w/o any indicators, or not for USB (for game port) or PIC based (which I don't want to learn yet). None had two modes of operation. None head schematic that proved to be really reliable.

2. Theory and technology

2.1 Sensor

This device is used on the capacitance detection method. Capacitive sensor basically changes capacitance when you touch it or come close enough to it. Microcontroller unit then just measures time to charge/discharge the sensor. Measured time is used to decide whether you touched the sensor.

My early experiments with capacitive sensing can be seen here:
http://www.youtube.com/watch?v=b71Vkq8dyf8
http://www.youtube.com/watch?v=-6Y7RgjfIPk

So, basically my scheme works like this: two pins of MCU are connected via resistor with really big resistance, MCU outputs 1 (HIGH) into the output pin and then counts time until it sees 1 (HIGH) on the input pin. If one puts a square piece of conductor with large enough area after the resistor the capacitance will rise. If human touches that area the capacitance will raise even more (average human capacitance is about 100pF). In my experiments the time without touching was about 2000 ticks and when I touched it the time was about 6000 ticks. Well, you don't need to touch the sensor. It is enough to just come close enough to affect it. So, the conductor and human may be separated by thin layer of non conductive material like wood, plastic, paper, paint. Though, the dielectric must not be too thick.

The main problem during preliminary testing and the in the first version of the dance pad was cross-talk between sensor lines. For example, widely used schematic, where one pin is used as input ping and 4 other pins connected to this input pin (or vice versa), has his flaw. In such schematic one pad affects all other pads, because they are connected. Sometime it goes so bad that it is impossible to distinguish which pad was stepped on. Also, it is hard or impossible to detect simultaneously pressed buttons.

Because of this I decided to go the straightest path I saw. I simply delegated two pins of MCU for each pad. Yes, it takes a lot of pins, but it is very reliable and I don't need all those MCU pins anyway.

In the first version of the dance pad, which I had to disassemble and throw away the pcb, i realized the importance of the right wire layout. It is very important that wires in the mat will not lay on each other and do not cross each other too much. Also, it is very important to have good connection between MCU modules and the mat with good wire isolation and without EM noise. The first version also had 4 build-in leds right in the mat itself and used IDC-14 connector (6 buttons+4 led+ GND = 11 pins used). Alas, wire packaging in IDC-14 proved to be bad enough to make the whole thing unworkable. Turning leds on/off interfered with capacitive sensing and wires were too close to each other so stepping on one pad turned on the other one. Passing GND among the sensing wires were not a good idea at all. So, in the end I moved the leds into the MCU module and change the connector to one row 8 pin 2.56mm connector.


Debugging and testing board (even before the first version of PCB).

2.2 USB

For the USB part I used very popular, simple to use and reliably code from AVR USB
http://www.obdev.at/products/avrusb/index.html
It allows creating low speed USB interface with components which cost pennies, which is more than enough for a joystick.

Specific USB joystick code is based on this project:
http://avrusb.wikidot.com/project:usbjoy

2.3 Nuts, bolts and glue

I used a lot of hot glue (thermoglue). It is hardly possible to build the thing that easy without it and still make it reliable. Whoever invented the thermoglue THANK YOU VERY MUCH!

Here is the photo of how it looks like:


The other thing I used for the assembly is liquid nails (it is a type of construction glue). It's a good thing too. Do web search on Google for "liquid nails" and you'll get the idea.

3. Schematic and brains

3.1 Schematic


MCU module


Pads connection

3.2 Components

- atmega8-16 (PDIP 28)

D1  - Zener diode, 3.6V
D2  - Zener diode, 3.6V
D3  - LED 5mm (button led)
D4  - LED 5mm (button led)
D5  - LED 5mm (button led)
D6  - LED 5mm (button led)
D7  - LED 5mm (button led)

C1  - ceramic capacitor 100 nF
C2  - ceramic capacitor 100 nF
C3  - ceramic capacitor 22pF
C4  - ceramic capacitor 22pF
C5  - elecrolitic polirized capacitor 10uF

R1  - resistor 0.25W, 2.2MOhm, but you can choose between 1.8-2.8 Mohm
R2  - resistor 0.25W, 2.2MOhm, but you can choose between 1.8-2.8 Mohm
R3  - resistor 0.25W, 2.2MOhm, but you can choose between 1.8-2.8 Mohm
R4  - resistor 0.25W, 2.2MOhm, but you can choose between 1.8-2.8 Mohm
R5  - resistor 0.25W, 2.2MOhm, but you can choose between 1.8-2.8 Mohm
R6  - resistor 0.25W, 2.2MOhm, but you can choose between 1.8-2.8 Mohm
R7  - resistor 0.25W, 220 Ohm
R8  - resistor 0.25W, 220 Ohm
R9  - resistor 0.25W, 220 Ohm
R10 - resistor 0.25W, 220 Ohm
R11 - resistor 0.25W, 220 Ohm
R12 - resistor 0.25W, 1 MOhm
R13 - resistor 0.25W, 68 Ohm
R14 - resistor 0.25W, 10 KOhm
R15 - resistor 0.25W, 1.5 KOhm
R16 - resistor 0.25W, 68 Ohm

Q1  - low profile (HC-49S) crystal with fundamental frequency of 16.000Mhz

PB1 - narrow button (normally open, like  TC-3121)

X1  - shrouded male IDC 10 socket for PCB (for programmer connection)
X3  - USB pcb mounted socket USBB-1J
X2  - 8 Pin angled male connector (like 6604PRA-08, you can take 10, 12... pins and break off only 8)
    - cable mounted 8 pin connector for X2, female, like 2226A-08 (don\t forget the metallic insert for it for fixing the cable lines)

case- some plastic casing 10 x 6 x 2.5 cm

If I mention some part number try to search google with it to find it and get the idea what I mean.

3.3 Comments

The button in the MCU module is used to switch mode of operation.

GND is output to the mat connector "just in case". It turned out that my apartment has no ground at all and my computer uses pump to cool the CPU which seems to generate a lot of EM noise. So, when the mat is near the computer (with 1 meter) it starts to behave strange and pressing button almost does not work. However, it helps, though not completely, if I connect a wire to GND and make a closed circle of it around the mat. So, I left the GND in the connector for such bad cases.

3.4 Construction

  1. Use you favorite way to make the PCB (I personally prefer tone transfer, but you can as well use photo method, do google search for "pcb tone transfer" if don't know any method). Make sure your copper clad laminate is of good quality. Bad laminate will result in torn off tracks near LEDs and the button.
  2. Mount and solder all the components to the PCB. LEDs must be a bit lower than the cover of the box you are using for the case. The MCU must be solder to the PCB without any socket. Socket will create extra capacitance which we do not need.
  3. Do air wires between points A-A, B-B and between 0-0,1-1,2-2,3-3,4-4 (those are marked near the MCU and go over it to the four LEDs)


  4. Connect you programmer and USB
  5. Check that the device is seen by the programmer. If so, compile the code (or take already made hex file) and upload it. If the board is not available to the programmer then identify and solve the problem or through away everything.
  6. Set the FUSES right! KEEP ATTENTION! MISTAKE AT THIS POINT CAN RUINE EVERYTHING! Remember, 0 mean PROGRAMMED and 1 is UNPROGRAMMED. If you made everything right then after you the set the fuses and start the device your windows must find a new USB device "USB DANCE PAD" and led must start to blink in circle.
  7. Open up control panel, choose game controllers (or whatever it is called in English). There you must see the device. Double click on it. You must see that it has 6 buttons.
  8. Check that it works fine. Touch the pins of the mat connector pin by pin (firmly with just one finger). The buttons in the control panel should light up one by one.

  9. Put the board into the case, mark the places for the USB connector, for the mat connector, places for holes in the cover for 5 LEDs and a very small hole (1-2mm) right above the button. The button is supposed to be pressed only by a long thin object like a needle or unbent paper clip. Do all the drilling and cutting.
  10. Put the board once again, fix it with hot glue. Make sure you fixed the USB connector VERY FIRMLY (put some hot glue on the sides of it). Also put some hot glue on the legs of the LEDs and the button because they are too high above the PCB and any extra force can pill the tracks off the board.
  11. Close and fix the cover. Test it once again. The brains are ready.


    I soldered the leds leds too highm, so i need to make by case really ugly. Be careful!

3.5 Downloads

Schematic (Eagle 5)
Schematic (PDF)
Pads chematic (Eagle)
Pads chematics (PDF)
PCB layout (Sprint Layout 5)
Sprint Layour Viewer (free)
PCB layout (PDF)
Component list and pin numbers
Precompiled HEX file
Complete AVR Studio project

4. Sensor mat

At first I first planned to use something I can roll up and put in a corner when unused.

However, after reading feedback on several forums about soft dance pads (which are most available on sale) I figured that they all have the same problem: they move when you move and they stick up and mess with your feet. So, I disbanded the soft mechanics part.

For the top I chose HDF (same stuff which back of a wardrobe is made) 3mm thick. I still could put the whole mat behind any wardrobe or a shelf or under a sofa/bed in a room.


In the first version the center square was 40x40 cm and the side buttons were 30x40. So, overall size was 1x1 meter. Test usage proved that the sizes were a bit wrong. Eventually, overall size was reduced to 90x90 cm and all squares were the same 30x30cm. My wife and I are 175 cm and 180 cm in height, so, if you are a lot lower or higher you should reconsider the sizes.

On the bottom size of HDF I put some liquid nails, put wires and glued usual cooking aluminum foil.



Of course, you should prepare all the wires (6 pieces) and foil (6 pieces) before you start to glue. I used a wire from twisted pair cat 5 cable (solid copper). I stripped about 15-20 cm of the wire. This stripped part is laid on the glue and foil is laid on top of the wire and the glue. I found that it is batter to form a large spiral of the stripped part.

Size of the foil for main buttons (left, right, forward, back) is 25x20 cm. The longer side is turned to the central square. The padding is 5cm from the central square and from the edge of the mat. Diagonal buttons are made a little smaller in order to avoid interference with the main buttons. The size of the foil for the diagonal button is 20x15 cm, padding is 5cm from the edge of the mat.

The next problem I (actually, my wife) encountered is loss of orientation. During gameplay one must look at the screen all the time. If you look down for a second you will skip one or more arrows for sure. However, it was impossible to understand that you still stand in the right position. Eventually neither her nor I could understand where are our feet relative to the buttons.

The solution was to attach (glue) strips of something 2mm thick on each side of the central square (outside of it) and also a 2mm thick bumps on each main button (bump can be any form but I chose to use an arrow form)

I used two layers of material which is used for light stopping curtains (it is a bit rubber like), but any material firm enough and thick enough can be used, I guess. I glued two layers with liquid nails.

Since, foot does not only step/jump motion, but also sliding motion I had to make this 2mm rise very smooth. This will also solve a problem with side force which can tear off the bump. It was solved easily by painting several layers of alkyd paint (used to paint cars).

Of course, the wires on the bottom must be covered. At first I tried 7mm foam pad used for laminate floors. It turned out to be too thick. Because of the thickness the jump energy were absorbed by the foam and it was like jumping on sand. Not good. The same material 4mm thick was just fine.

I guess, one can use another square of HDF on the bottom, but this would reduce reparability of the device and noise isolation. Your neighbors downstairs will appreciate the foam layer :)

All the bumps were glues with liquid nails on top of the HDF mat.

Painting was harder than expected. The plan was: pain the top with black glossy alkyd paint then paint the buttons using stencils with glossy red alkyd paint. However, one big spray can is not enough for the whole surface. I needed one and a half. I could not find red paint in big cans like I used for black paint, so, I had to but two of them. Besides I figured that I know nothing about proper painting and cannot really paint, because of that the stencils were not laid properly. At some places the paint sprayed beyond the stencil border, but all in all the result was okay.

BTW, it is nicer to make the stencil larger than the bump!

Here the step-by-step plan to construct the sensor mat:

  1. >Make a square 90x90cm of HDF
  2. Use pencil to draw 30x30 cm buttons on top AND on the bottom of the HDFmat.
  3. Prepare foil buttons: 4 pcs. of 25x20 cm and 2 pcs. of 15x20 cm.
  4. Measure, cut, strip wires. Place then where they should be and how they should be routed and make sure everything fits nicely. Leave 15cm of every wire beyond the mat for connection. Put them aside.
  5. Place each foil button where it should be with 5cm padding from the edge. Mark the corners on the HDF with a pencil. Take the foil off and put it aside.
  6. ONE-BY-ONE! Put some glue on one side of the marked area for foil and spread it thin and evenly. Put the wire how it should be. Put the foil on top and very gently stroke the foil (I used bear hand) to make it even. Make sure that it sticks good and every parts of it sits on glue.
  7. Use hot glue to glue the wires the way they should go (glue on all turns and in the middle of long runs).
  8. Cut wires, so they stick out from under the mat to 5-10 cm. Fix wires in the connector. The ping mapping is the connector (LOOK AT THE PCB, not a the schematic): 0 - right, 1 - back, 2- left, 3 - forward, 4 - forward-left, 5 - forward-right. Do not mess this up! Remember, you are working with the mat up side down and left will become right! Do not solder anything, just fix the fires in the connector.
  9. Connect the MCU module and check that everything works like it should by touching the foil pads with you hand. If it does not then figure out what's wrong or bring everything to garbage and write me a flame letter.
  10. Cut out a 90x90 cm square from foam pad. Roll it up.
  11. Slowly unrolling it glue every 10 cm with hot glue to the down side of the HDF mat. So, in the end you will get a grid of hot glue dots with 10x10 cm cells.
  12. Hot glue the sides thoroughly.
  13. Hot glue the wires to the mat near the connector.
  14. Hot glue the wire to the connector.

  15. Check one again that everything works. Fill ecstasy or tear the thing to pieces.


  16. Make the bump (the strips and the arrows)
  17. Glue the bump using the liquid nails. Make sure it holds tightly.
  18. Pack the connector into a plastic bag.
  19. Paint the whole upper surface with black (or whatever color you choose) alkyd paint. Do 2 or 3 layers of paint. Read the instructions for your pain spray can. Do not use silver pain or other kind of paint with metallic parts! It will constantly rub off and make everything silver around the mat including your feet.
  20. After the pain completely dries (about 24 hours) place the stencils on all the bumps and diagonal arrows (total 10 stencils: 4 strips, 6 arrows). I don't know how to properly fix them - use your imagination. I still have problems with it because I get space between stencils and the mat surface.
  21. Very thoroughly close the rest of the surface.
  22. Use fine sandpaper to sand a bit all the open surfaces, so the paint will attach better. Clean the sanded parts with wet fabric. Wait until it is dry.
  23. Paint 2-3 layers of another color alkyd paint. I recommend red, orange, light blue colors.


  24. Wait another 24 hours.
  25. Carefully take off the stencils and the cover. Clean with wet fabric.
  26. Connect everything and check that it still works. Fill the AWE!

5. If you are lazy

If are very lazy here are the things you can skip and do differently in order to complete the project faster and still be able to use it:

  1. Do not use HDF, use a sports mat (yoga mat)
  2. Make only 4 buttons (PCB is the same, just do not connect diagonal buttons)
  3. Do not mount and solder 4 directional LEDs and resistors for them. Do all tests on the computer with help of control panel.
  4. Do not paint anything at all.
  5. Do not glue any bumps.
  6. Do not make the connector and do not solder connector on the PCB. Just solder the wires from the mat to the pcb.

6. User guide

You must not stand on the mat and do not place anything on it when you turn it on. The mat should be located approximately where it will be used.

After you turn it on you will see the power led light up and autocalibration will start.

If the device is in 6 button joystick mode the directional LEDs will light and turn off in circular fashion.

If the device in 2 buttons joystick with 2 axis mode then the LEDs will light in pairs (left-right, forward-back).

Calibration takes about 10-15 seconds. After that all directional LEDs will turn off. Now you can use the device.

To switch mode you must free the mat (nothing must be on top of it), press the mode switch button with a needle or unbent paper clip for 1 second and release. After that the device will disconnect itself from USB, reconfigure, reconnect itself to USB again in new mode and start autocalibration again.

In 2 buttons + 2 axis mode the number of buttons you see in the control panel for this joystick will not change, but only button 1 and 2 (which will be the diagonal ones) will work. When you press left, right, forward, back the position of the joystick will changes. When you pres left-right or forward-back simultaneously the joystick will center on that axis.

The last set mode is remembered in EEPROM of the MCU and will be used when you turn on the device next time.

One of the features of capacitive sensing is that there is always a distance when detection is not steady. It means that if your hand or foot is kept at that distance the device will constantly change its mind whether you stepped on the button or not. In my tests this distance was about 5mm and it does not interfere with the operation in a game, but you should know this.

Static electricity can badly affect mat operation in some very rare circumstances. It happened only once, when I reverse connected the mat connector the MCU module and than static built up on the bottom of the mat. It did not work properly without any visible reason. It might be as well be related to the absence of ground in my apartment or the induction of the cooling pump in the computer. Anyway, the fix was easy. I connected the mat property and stroked the bottom of the mat with a wet hand (water) and turned it off and on again. It worked perfectly again.

Also, pay attention how you step on the back button. Capacitive sensing needs some reasonable area to be touched to detect a touch. However, some people just stand one toe tip or several fingertips on the back button. This is not enough. You must at least stand you foot fingers and toe FLAT on the button. Even better is to turn you body a bit and stand the full foot on the button.

You can also play other games in 2 buttons 2 axis mode because game will detect a normal joystick. Try classics like Arkanoid or Tetris. It is fun!

Playing ITG on this dance pad:

Comments

2008-10-29 15:13:01 Alexandr (Omsk, Russia)

Cool device !


2009-04-06 20:06:52 sean ()

I saw your work on objdev, I would like to ask a few question about converting to the 88 if you have the time.

here is my project posting.

http://forums.obdev.at/viewtopic.php?f=8&t=2360&start=0


2009-04-06 21:46:13 Artem Kuchin (Moscow, Russia)

I was never able to migrate this project to atemga88. I have wasted two days on this issue and just devided to leave the atmega8 as it was.
My part is easily migrated but AVR USB just does not work on 88. I tried and I failed. Maybe some other time.


2009-04-16 02:14:36 Adrian (Chicago, United States)

The two websites you mentioned earlier in this project description are unreachable, for whatever reason(s). Your design looks simple, effective, and accessible, as compared to the alternative methods I found for this end result (capacitive DDR pad). I would really like to try out your design, but my coding skills are abysmal. I'm very much near the beginning of my journey into microcontroller-based electronics.

If you have copies of the code files mentioned, could we perhaps arrange an email or http://www.drop.io session?

I'm specifically referring to <http://www.obdev.at/products/avrusb/index.html> and <http://avrusb.wikidot.com/project:usbjoy>.

Best Regards,

Adrian


2009-04-16 10:04:30 Artem Kuchin (Moscow, Russia)

That's crazy how site die all the time. Well, anyhow. Obdev will be back soon i am sure (it's a pretty big site with a lot of projects, they seem to have server problems). But if you download my complete AVR Studio project you'll get everything needed. It has the joystrick and the usb code inside from the mentioned projects.


2009-04-18 13:40:42 Emil Bergstr&#246;m (Bobacken, Sweden)

Hi.

i am currently building your ddr pad as a school project but i have had some problems with setting the fusebits, can you please direct me to any webpage where i can learn how to set the fusebits right cuz i have already locked myself out from 1 atmega8 and i don't want to do it agian ^^. or maby you can help me through either email or skype with directions on how to do it.

please respond to

emil.bergstrom1@gmail.com

Sincerly
Emil Bergström.


2009-04-19 00:43:13 Artem Kuchin (Moscow, Russia)

Hi!

I will reply here and by email too.

1) Be careful! This thing (DDR) might not work at all if used under EL lamps (especially with not grounded control gear) which create pretty high voltage difference between ceiling and floor. You would need to ground your self to make it work.

2) You need to read the datasheet for Atmega8. Fuses are covered there very well.

3) If you need to recover you atmega you could spend some time on this:
http://www.youtube.com/watch?v=t6WIYvb5dos
http://www.artem.ru/cgi-bin/news?c=v&id=739 (use google language tool to translate it)


2009-06-03 02:01:36 Sam ()

I'm confused how this works. I might not have been reading this correctly, but you have a sheet of foil connected to a wire with paint on top. How does this detect your weight when you step on it? Other buttons I've seen have 3 layers: foil, paper with holes in it, foil. When you press the button the two foil sheets make contact and current is allowed to flow through it. (This current is the signal sent to your electronics.) Could you explain how your system works with a single sheet of foil?

Thanks!


2009-06-19 17:21:51 Artem Kuchin (Moscow, Russia)

It does not detect weight. It detects CAPACITY. I mean electric capacity.
IT is all written in paragraph "2.1 Sensor" above.


2009-08-12 18:58:34 sean (sanforf, usa)

love the project, all links are dead, I'd love to see if an how you did force feed back. I'm trying to get this working with my ps2 adapter project, and can't find a single example on the next for force feed back with hid. I also can't find contact info, so I will leave mine.
S _ K _ U _ N _ X at Y a h o o dot c o m


2009-08-12 19:37:50 sean (sanforf, usa)

^^, ahh links working now, BTW I was able to get the 8 to 88. It was not easy...


2009-09-01 10:22:38 Abbas ()

Nice job, but how can write program in Delphi to communicate with the AVR for USB communication?


2009-10-14 22:23:15 Artem Kuchin (Moscow, Russia)

I was not able to make it work on 88 and i stopped struggling since i have plenty of 8s :) But i still am interested in knowing how to do it.

As for delphi and any other language. This project is done aas standard joystick so it need no custom software. If you with to do you own usb
protocol then you shoud go for usblib - this is useland usb lib on Un*x and windows. Search google.


2009-12-27 02:14:04 jose blanco (boise, usa)

why don't you make a step by step on programming the atmega 8 for this?, so far i've been not able to write the program to the micro, I don't know why, I've read about fuses and all that, but I don't know how to do that, please I need help on this subject... what do i need for programming the atmega 8? I mean what kind of programmer (a schematic would be great) and what software to use with?, how to set the fuses... I'd really appreciate your help thank you..


2010-01-10 17:20:11 unknown ()

does not work for me. detected as a dance pad, but don't blink led: "After you turn it on you will see the power LED light up and Autocalibration will start." and not responding to touch


2010-01-29 16:50:04 Artem Kuchin (Moscow, Russia)

jose blanco:

Well, this project is aimed at people who already know how to work with MCUs, sorry, but i am not going to teach the basics here, Just not enought time
for such things. However, i am planning to redo the whole project so it will be more reliable. When (if) i do it i will be able to provide preprogrammes chips and ready made pcbs. If it happens it will be no earlier than april.

unknown:

Well, since it is detected then mcu seems to be programmed and working fine. Maybe something is wrong with pcb. I can't tell. test all the treks and components.


2010-03-01 02:25:31 T'ps (, Czech)

I have same problem like unknown ...


Leave a comment

Name:
City: Country:
Comment:

Enter code "5592" -

Please, be poilite! All messages are moderated anyway.
Entered data will be stored in a cookie for future use. HTML is not used.

(C)1999-2008 Artem Kuchin (Moscow, Russia)

If you use any information from this site you MUST put a direct link to this site!
Author can deny free usage of any material to anyone without explanation. All information on this site is protected by international and national copyright laws.
Contact: artem@artem.ru