第一色导航

第一色导航

This is default featured slide 1 title

第一色导航Go to Blogger edit html and find these sentences.Now replace these sentences with your own descriptions.

This is default featured slide 2 title

Go to Blogger edit html and find these sentences.Now replace these sentences with your own descriptions.

This is default featured slide 3 title

Go to Blogger edit html and find these sentences.Now replace these sentences with your own descriptions.

This is default featured slide 4 title

Go to Blogger edit html and find these sentences.Now replace these sentences with your own descriptions.

This is default featured slide 5 title

Go to Blogger edit html and find these sentences.Now replace these sentences with your own descriptions.

Sunday, September 14, 2014

Tilt Sensing Bracelet using Arduino [Full Tutorial]



Picture of Tilt Sensing Bracelet

3343930231_ec4d54947b.jpg

3344765654_8c850c94c8.jpg
3344013845_0e866cee8e.jpg
A bracelet decorated with six conductive fabric petals and a thread of beads with a metal bead at the end, makes for a simple six point tilt detection. It is also designed so that the metal bead will make contact with two petals if it lies in between. and then of course it will make no contact when it is in the air due to throw or tipped upside-down.

This was really fun to make and the best part about it was that it worked straight away, with no mistakes made on my part. It is simple, but takes some patience to accomplish. The application really only visualized the input, I have not thought of any further uses for this. Yet.

The feedback bracelet is connected to the tilt bracelet directly via wire, but this could also be wireless. When the bead makes contact with a conductive petal it closes the circuit for the corresponding LED, which turns it on. Check out instructables dot come for more and how to make your own!

Video with Feedback Bracelet


Video with computer visualisation


第一色导航


Picture of Materials and Tools
MATERIALS:
also see http://cnmat.berkeley.edu/resource/conductive_thread
also see http://cnmat.berkeley.edu/resource/stretch_conductive_fabric
  • Fusible interfacing from local fabric store or
also see http://www.shoppellon.com
TOOLS:
- Fabric scissors
- Sewing needle
- Iron
- Fabric pen that disappears over time
- Pen and paper
- Ruler
- Soldering station (iron, helping hands, solder)
- Knife for cutting perfboard
- File for filing edges
- Wire cutters and strippers
- Pliers

第一色导航


Picture of Stencil and Preparation

3344008029_73cf875ca1.jpg
3344781794_90f2782745.jpg

3343936995_a1660ab22e.jpg
3344766664_cdfaa87801.jpg
3344060077_6c2f64d147.jpg
Print out the stencil (see illustration) and trace it to a piece of neoprene. Trace the flower petal pattern to stretch conductive fabric that has fusible interfacing adhered to one side. Cut out the neoprene and conductive fabric pieces.
Punch the poppers into the neoprene as shown in illustration. Make sure the active sides are facing the right ways. You could also use Velcro as a fastener.

第一色导航


Picture of Fusing and Poppers

3344781794_90f2782745.jpg
Lay the conductive fabric petals onto the neoprene and fuse them together with an iron. Make sure the edges of the conductive fabric are clean and there are no electrical connections between individual petals.

Step 4: Soldering

Cut a piece of perfboard 8 x 10 holes big. With the conductive strips running the longer length. File the edges. Bend the legs of your eight female headers if you don t have any ready bent ones. Solder them to one of the ends of the perfboard. This is going to be a series of pull-up resistors going from each input to the ground. To understand the reason for having pull-up resistors, follow this link >>
http://cnmat.berkeley.edu/recipe/how_and_why_add_pull_and_pull_down_resistors_microcontroller_i_o_

Solder the 10 or 20K resistors to the board as shown in illustration. The red line represents the VCC and the outer line where all the resistors accumulate represents the GND. The rest are your six digital inputs.
Clip the ends of your wires. I like to use a nail clipper.

Solder the ribbon cable to a row of 8 male headers. This will plug into the bracelet. On the other end, make sure to separate the VCC and GND wires and solder these to two connected male headers. These will connect to the 5V and GND of the Arduino. Solder the rest of the wires to a row of six male headers. These will go into your analog or digital inputs, depending on your code. I chose to plug them into my analog inputs because I already had the code for reading them running on my board. But it wouldn t take more than 5 minutes to change them to digital.

Step 5: Sewing

Before sewing the conductive connections we need to sew the perfboard into place with some non-conductive stitches and placing the circuit board underneath the neoprene strip.

There is not much space for the conductive stitches, so plan carefully (follow the illustration) and make double double sure that you don t cross any of the conductive threads inside the neoprene. Bad connections like this are a real pain to figure out and a lot of work to undo.

Sew from the hole marked red in the illustration to the center of the floral pattern and thread it through some beads before attaching a metal bead or small pendant on the end.

Sew from each of the other 6 holes of the perfboard into the neoprene and to the individual conductive petals. Stitch the thread to the petals with a few stitches and then cut the conductive thread without making a knot.
The ends of the knots at the perfboard fray like crazy, and a simple way to take care of this is to just cover them with some stretchy fabric glue, this isolates them against each other.

Step 6: Read Input


Picture of Read Input

3344850856_588d352065.jpg
3344773686_71fcfcda0e.jpg

3343941649_9e059ce37d.jpg
3343939011_31bb3a1df3.jpg
For Arduino microcontroller code and Processing visualization code please look here >> http://www.kobakant.at/DIY/?cat=347

Plug the headers into the right places and wear the bracelet. If all goes well you should be reading the inputs from the bracelet. Press the spacebar to enter the visualization mode and pressgto return to the graph mode.

Let me know if there are any complications. And enjoy!

Turn your Arduino into a Magnetic Card Reader! [Full Tutorial]



Picture of Turn your Arduino into a Magnetic Card Reader!

magcard-2.jpg
magcard-reader-top.jpg
Everyone has used a magnetic card reader, I believe. I mean, who carries cash these days? They're not difficult to get your hands on, either, and during a trip to my favorite local electronics shop, I found a bin full of these guys. So....of course, I picked one up and brought it home to see what sort of stuff I could do with it and an AVR.

This instructable will show you how to connect a Magtek magnetic card reader to an AVR or Arduino/clone and read data from the first track of card. Buckle your seats; magnetic card readers have a high bit rate!

Step 1: The Equipment List


Picture of The Equipment List

magcard-ra-header.jpg
Here are a few things you'll need to get started.
  • Magnetic card reader (Mine is a Magetk 90mm dual-head reader.$5.00)
  • AVR, Arduino, or clone (ATmega328p ~ $4.30 from Mouser.com
  • solderless breadboard
  • some wire
  • maybe a header if you like that sorta thing.
  • something to read your serial port.I use AVR Terminal from BattleDroids.net
That's all you should need to get started.Depending on the magcard reader you end up getting, you may have to modify these instructions, and most assuredly the code, to work with your specific reader.However, the code I've written should get you pretty far, I hope.

Step 2: Self-clocking Magnetic Card Readers


Picture of Self-clocking Magnetic Card Readers

magcard-reader2.jpg

magcard-setup1.jpg
magcard-setup-final.jpg
Magnetic card readers are "self-clocking," meaning that they provide a clock called a strobe, against which the connected microcontroller can sync. This is a boon. It means you don't have to worry about looking for a clocking signal and timing the signal to center directly on the clock pulse, and no bothersome oscillating into the sweet spot of the clock signal. This make sense when you think about card swipes: everyone swipes at a different pace, some slower, some faster than others. Self-clocking allows even my sweet grandma the ability to use her card without breaking her wrist. Reminds me of having to change the setting for her that determines how much time is valid between clicks to register a double-click....

This card reader's data is valid 1.0 us before the strobe is put onto the line, so there's no worry about delaying to get yourself into the "bit time." For a dual head reader such as the one I'm using, there are two data tracks available to read. In this 'ible, I'm going to show reading from the primary first track to get you started.

There are five connections you will need to make (four if you don't mind giving up more fine tuned control for fewer I/O ports being used). Check out the picture below. The red wire goes to +5V while the black wire goes to ground. The green wire is /CARD_PRESENT; the yellow wire is /STROBE, and the white wire is /DATA1. The forward slash ( / ) means that the data is inverted. A low signal (ie 0) is read as a one, or high. The other connectors are brown for /STROBE2 and orange for /DATA2. We won't be using these.

If you want, you can forget about /CARD_PRESENT. This data line goes low after about 17 head flux rotations to indicate that a card is present (instead of, say, random noise causing your reader to send bogus data) and is used to validate that the data you're getting is card data and not junk. You can skip this connection if you check for the start sentinel on the data stream. More on that later.

As you can see below, I used a right angle male header connected to a bread board and connected my reader to that. I connected /STROBE to PIND2 (digital pin 2 on an Arduino), /CARD_PRESENT to PIND3 (for illustration purposes), and /DATA1 to PIND4. Make sure you enable pullups on these pins so your pins don't float. I also traded out my Arduino for a Bare Bones AVR because I like the way it fits into the breadboard.

Step 3: Magnetic Card Basics


Picture of Magnetic Card Basics
The primary functions that you'll need to do to read a magnetic card are:
1. Detect when the card has been swiped
2. Read the stream of data
3. Detect when the card has gone
4. Process the data
5. Display the data

First, I'll introduce you to some magnetic card basics that you'll need to know when you start writing your own code.

Magnetic Card Standards

Magnetic cards are standardized by the ISO in the following documents:

7810 Physical characteristics of credit card size document
7811-1 Embossing
7811-2 Magnetic stripe - low coercivity
7811-3 Location of embossed characters
7811-4 Location of tracks 1 & 2
7811-5 Location of track 3
7811-6 Magnetic stripe - high coercivity
7813 Financial transaction cards

As you can see, financial cards are specified in a separate document and often have different formats than, say, your grocery card or international calling card. You will have to program for these differences. I just had a credit card and insurance card handy, so I programmed for these types (which both happen to be format B).

Card Formats

There are several different formats for magnetic cards. Format A and B are common, with B being the most common I've seen, and which is supported in this code. Formats C through M are reserved by the ISO, I believe, while N through ?? are reserved for institutional custom use.

Track 1
For financial cards, the first track is recorded at 210 bits per inch and is the first 0.110" of the card from the top. The data is encoded as "card data" as 7-bits per character. That's 6-bits for the character and a bit for parity. There are ~ 79 alphanumeric characters on track 1.
The physical ordering is backwards. That is, data is  but it's written backwards on the card (and hence, will be read by your firmware) as . The parity is odd.

The card data format looks like this:
[SS] [FC] [Primary Account #] [FS] [Name] [FS] [Additional data] [FS][ES][LRC]where:SS Start sentinelFC Format codeFS Field separatorES End sentinelLRC Longitudinal Redundancy Check character

Track one SS = '%', FC = one of the formats (going to be B a lot of times), FS is often '', ES is '?' and the LRC character is commonly '<' although it's not specified in the standards. Besides being written on the card backward, the data has an odd parity bit and is 0x20 from ASCII. We'll handle this when we process the data.

Track 2 
Track two is 0.110" wide and starts 0.110 from the top of the card. It's recording density is 75 bits per inch. The data is 5-bits per character and consists of around 40 numeric symbols only. You shouldn't encounter any letters on this track.

The card data format should follow this structure:
[SS] [primary account #] [FS] [additional data | discretionary data] [ES] [LRC]
The SS for track two is the semicolon: ';' and the FS is '='

With this holy knowledge under your belt, continue on to the next steps to see code implementing the procedure outlined above.


Step 4: Detect When a Card is Swiped


Picture of Detect When a Card is Swiped
1. Detect when a card has been swiped
Formally, one would check the /CARD_PRESENT pin to see if it's dropped low. Fortunately, this isn't really necessary. We'll check for valid card later. Alternately, you could read your strobe pin to see when strobes have been put onto the pin, however, this will net you lots of clocking zero's. The reader will send about 60-70 leading zero's to let you know that data is about to be presented. However, we're going to use the nature of binary data to determine when to start recording bits.The start sentinel (SS) for track one is the percentage sign (%). It's binary value is 0010 0101 which means it will be stored (and read) as 1010 001 (it's 7-bits so the 8th bit isn't transmitted). Now, the astute reader will notice that even though the data is backwards it doesn't match the binary ASCII value. That's because it's 0x20 off of hex. The % symbol is 0x25 and 0100 0101 is 0x05. Card data has 0x20 subtracted from the value. That one hanging out there in the high nibble is the odd parity bit. It's put there so that there are an odd number of "1"s in the value.
So because we know that a valid card will always start with this start sentinel, and because the parity bit is a 1, then when we detect the first HIGH to LOW transition on the data pin, then we know we have just started to receive the start sentinel from a card. Now, this isn't always going to be true, and a foolproof plan would be to check the /CARD_PRESENT card to see if it's gone LOW in addition.
The simplest way to detect the start of the SS, is to create an external interrupt triggered on the falling edge of the /STROBE. The data is valid 1.0 us before the falling edge, so when you've sampled the falling edge, then you know you can read the /DATA1 pin and get a valid value. Here's the code to create your external interrupt triggered on a falling edge.
voidInitInterrupt(void){// Setup interruptBSET(EIMSK,INT0); // external interrupt maskBSET(EICRA,ISC01);// falling edgeBCLR(EICRA,ISC00);// falling edgeBSET(SREG,7); // I-bit in SREG}
In my common.h that I include in all my programs, the definitions of BSET and BCLR can be found. Refer to that file should you have any questions about how to set bits.Now, when the interrupt is triggered, we want to sample the /DATA1 (in my code defined as CARD_DATA) and set a bit in a general purpose IO register. If we're on the 7th bit, save off the register as a character in our global buffer. I use a GPIOR0 register because it's spiffy fast access.The pseudo code is something like this:
Stop 16-bit timerClear timerIf DATA is LOWSet BIT=1 in REGISTERDecrement BITSet flag so we don't skip any more 0'selse DATA is HIGHSet BIT=0 in REGISTER Decrement BITIf BIT is 0Add byte to bufferIncrement indexReset BIT
If you are asking yourself why decrement instead of increment, remember that the data is backwards, so instead of recording the bits as we get them from LSB to MSB, we save them from MSB to LSB so we don't have to reverse the bits later when processing the data. If you really wanted, you could also add 0x20 hex here, but since it's about 5us on these strobes, I'm keeping the processing in this interrupt service routine to a minimum.
ISR(INT0_vect){ StopTimer(); ClearTimer(); if ( !BCHK(PIND,CARD_DATA1) ) // inverse low = 1 {BSET(GPIOR0,bit);--bit;bDataPresent = 1; } else if (bDataPresent) {BCLR(GPIOR0,bit);--bit; } if (bit < 0) {buff[idx] = (char)GPIOR0;++idx;bit = 6; } StartTimer();}
If you're wondering what the timing business is about, that's covered in the step in determining when the card has left the reader.

Step 5: Read the Stream of Data

Read the stream of data


Well, I've already shown you how to read the data, as it's part of the Interrupt Service Routine for our falling edge external interrupt.An alternative method would be to set a flag in the ISR, and in the main loop poll the flag and read the data that way, but I believe the way I've presented it is cleaner.Be your own judge and write yours however your MCU will allow it.

That being said, let's move on to finding out how to detect when the card pulls an Elvis and has left the building.

Step 6: Detect the Card Leaving the Reader


Picture of Detect the Card Leaving the Reader

Detect when a card has gone


Formally, one would sample the /CARD_PRESENT pin to see if it's gone HIGH again, but we don't need no steenkin' /CARD_PRESENT taking up another I/O port. This is where those timers come in.

Every time the interrupt is called because we've detected a falling edge on /STROBE, we stop a timer, clear the timer value and start reading. When we've finished reading we start the timer again. Repeat ad nauseum, or until the timer reaches a certain value. That means that the last interrupt has been called and no more data has come in, so we assume that's it and start processing the data we've collected.

For timers, we use TIMER1, ie the 16-bit timer. I'm using a 16 Mhz resonator externally to my AVR. If you're using an arduino, then you probably are, too. So, I've chosen a prescaler value of 1024 which means every (16,000,000 / 1024) times the timer will increment. That is to say, it will 'tick' 15,625 times a second. The /CARD_PRESENT will go HIGH indicating the card has left the reader about 150ms after the last data bit. Knowing this, I just decided to check about every 1/4 of a second. That would look something like this:
( ((F_CPU) / PRESCALER) / 4 )
which turns out to be around 3900. So, when the timer counter TCNT1 reaches 3900, then I know it's been about 300ms and I can pretty safely conclude that the card has left the reader. Easy.

#define PRESCALER1024#define CHECK_TIME ( (F_CPU / PRESCALER) / 4 )// 250 ms#define StartTimer() BSET(TCCR1B,CS10), BSET(TCCR1B,CS12) // 1024 prescaler#define StopTimer()BCLR(TCCR1B,CS10), BCLR(TCCR1B,CS12)#define ClearTimer() (TCNT1 = 0)

You've seen in the ISR where the timer is started, stopped, and cleared on each interrupt. Now, in the main loop we just check to see if the timer counter has reached our target value, and if so, start the data processing.

for (;;){ if( TCNT1 >= CHECK_TIME) { StopTimer();ClearTimer();ProcessData();ReadData(); idx = 0;bit = 6;bDataPresent = 0;memset(&buff,0,MAX_BUFF_SZ1); } }

Now it's safe to process the data.

Step 7: Process the Data


Picture of Process the Data

Process the data


The processing phase consists of:
  • checking for a valid SS
  • checking parity
  • converting to ASCII
  • checking for a valid ES
  • checking LRC
Here, I don't bother with checking parity, as I just set that bit to zero.I also don't calculate the LRC for this little tutorial.That would be something that a more fully realized firmware might want to do.

Here's the code to process the data doing the above steps (sans the previously mentioned). Find it in the image below.It's commented and pretty self-explanatory.A special note on parity and ASCII:
I simply clear the parity bit (7th bit...ie a 1 with 6 zeros behind it) and to convert from "card data" you must add 0x20 to the value.That's about it.

Step 8: Display the Data


Picture of Display the Data

ReadData.jpg

Display the data

The display goes to a terminal program I wrote specifically for connecting to an AVR via RS232 or USB.The program is called AVR Terminal.The ReadData() method is pretty ugly and you're encouraged to find a cleaner solution than the one I came up with.

There's also an output of the function in AVR Terminal.The output is first of a health insurance card, and the second is of a VISA card.Click the [i] in the upper left corner of the picture and choose original or large image to see it better.

Step 9: Code Download and Wrapup

In this instructable I've discussed some basics of magnetic card readers and shown you some code to get you started in the right direction in reading data from magnetic cards.There's plenty more work that could be done, such as reading and decoding the 2nd track, calculating the LRC and calculating the odd parity on each byte.

The full source code is available for download below.It was written in AVR Studio 4.17.

I hope you enjoyed this instructable and, as always, I look forward to any comments or suggestions that you may have.

Happy coding and AVR'ing!
MagCardReader.

Ardu-pong! the Arduino based pong console [Full Tutorial]



Picture of Ardu-pong! the Arduino based pong console
A while back the instructables robot made a post on Facebook about some guys who played pong on an Arduino (http://wayneandlayne.com/projects/video-game-shield/games/#pong)
but after looking around, i saw that everyone who did this was only worried about making it work. and often resulted as a very hard to use system with only potentiometers to use as controllers. so in my attempt at this, i decided that it needs to be much more polished if it is ever to be something of use. so heres how i did it:

UPDATE! ive managed to shink it down into an entire atari themed mint tin! check it out here


Step 1: Get the stuff.

so to do this, we are going to need a couple of things.
first off, we obviously need an Arduino, we are also going to need an atari joystick, a rs232 socket, a rca jack,  1Kohm resistor and a 330 ohm resistor, a switch for power, and something to cram all the guts into , i decided to use a busted digital tv receiver as my enclosure 

Step 2: Hack the enclosure.


Picture of hack the enclosure.
now take your chosen enclosure and take it apart and remove all the circuit boards and junk you otherwise will not need, then mount your Arduino against the backside of the enclosure and drill a hole large enough for a usb cable to fit through, then cut out a hole for the serial port to be mounted through.

Step 3: Install the rca jack.


Picture of install the rca jack.

100_0561.JPG
before we install the rca jack we need to freeform the following circuit off of the pins of the rca jack .
then we can drill a hole in the back of the enclosure for the rca jack to come through and then glue it in place.


Step 4: Wire the serial port


Picture of wire the serial port
now we have to wire the serial port to the pins on the arduino so we can get input from the joystick.
so using the following pinout, connect the following to the corresponding pins on the Arduino


pin1 up, to Arduino pin 7
pin2 dn, to Arduino pin 6
pin6 fire,to Arduino pin 2


Step 5: Wire the rca jack


Picture of wire the rca jack
this is pretty simple just connect the 1kohm resistor lead to pin9 and the 330kohm resistor lead to pin8

Step 6: Software


Picture of Software
now we need to download and install the tvout library for the Arduino sdk here
 
and once you have done that i have modded a version of pong for the arduino to take our input from the joystick you can get right from this instructable.

btw thanks pete

Step 7: Congratulations!!! your done (almost).


Picture of congratulations!!! your done (almost).
now just install your power switch anywhere you'd like and wire it to control the power to the arduino, im not going to explain this, if you've gotten this far Im pretty shure you can handle it.

then assemble the enclosure, plug in the controller, upload the code, and plug it into the tv. if it worked you'll see somethin like this :