I Need Help With Breadboard wiring




am i wiring this up correctly. i assume im not as its not working how it is intended to work. the code is on the attiny and the led should light up when i press the button and transmit a signal over the coil. but when press the button nothing happens. please help me its for a college project (im demoing a magspoof)

This is my code that i was kindly helped with on here and i changed the pin outs to work with attiny (i think i did it right)

/*
   MagSpoof - "wireless" magnetic stripe/credit card emulator

   by Samy Kamkar

   http://samy.pl/magspoof/

   - Allows you to store all of your credit cards and magstripes in one device
   - Works on traditional magstripe readers wirelessly (no NFC/RFID required)
   - Can disable Chip-and-PIN (code not included)
   - Correctly predicts Amex credit card numbers + expirations from previous card number (code not included)
   - Supports all three magnetic stripe tracks, and even supports Track 1+2 simultaneously
   - Easy to build using Arduino or ATtiny

*/

#include <avr/sleep.h>

const byte PIN_A = 0;
const byte PIN_B = 1;
const byte ENABLE_PIN = 3;  // also green LED
const byte SWAP_PIN = 4; // unused
const byte BUTTON_PIN = 2;
const unsigned CLOCK_US = 200;

const int BETWEEN_ZERO = 53; // 53 zeros between track1 & 2

const int TRACKS = 2;

// consts get stored in flash as we don't adjust them
const char* tracks[] =
{
  "%B123456781234567^LASTNAME/FIRST^YYMMSSSDDDDDDDDDDDDDDDDDDDDDDDDD?\0", // Track 1
  ";123456781234567=YYMMSSSDDDDDDDDDDDDDD?\0" // Track 2
};

char revTrack[41];

const int sublen[] =
{
  32, 48, 48
};
const int bitlen[] =
{
  7, 5, 5
};

unsigned int curTrack = 0;
int dir;

void setup()
{
  pinMode(PIN_A, OUTPUT);
  pinMode(PIN_B, OUTPUT);
  pinMode(ENABLE_PIN, OUTPUT);
  pinMode(BUTTON_PIN, INPUT_PULLUP);

  // blink to show we started up
  blink(ENABLE_PIN, 200, 3);

  // store reverse track 2 to play later
  storeRevTrack(2);
}

void blink(int pin, int msdelay, int times)
{
  for (int i = 0; i < times; i++)
  {
    digitalWrite(pin, HIGH);
    delay(msdelay);
    digitalWrite(pin, LOW);
    delay(msdelay);
  }
}

// send a single bit out
void playBit(int sendBit)
{
  dir ^= 1;
  digitalWrite(PIN_A, dir);
  digitalWrite(PIN_B, !dir);
  delayMicroseconds(CLOCK_US);

  if (sendBit)
  {
    dir ^= 1;
    digitalWrite(PIN_A, dir);
    digitalWrite(PIN_B, !dir);
  }
  delayMicroseconds(CLOCK_US);

}

// when reversing
void reverseTrack(int track)
{
  int i = 0;
  track--; // index 0
  dir = 0;

  while (revTrack[i++] != '\0');
  i--;
  while (i--)
    for (int j = bitlen[track] - 1; j >= 0; j--)
      playBit((revTrack[i] >> j) & 1);
}

// plays out a full track, calculating CRCs and LRC
void playTrack(int track)
{
  int tmp, crc, lrc = 0;
  track--; // index 0
  dir = 0;

  // enable H-bridge and LED
  digitalWrite(ENABLE_PIN, HIGH);

  // First put out a bunch of leading zeros.
  for (int i = 0; i < 25; i++)
    playBit(0);

  //
  for (int i = 0; tracks[track][i] != '\0'; i++)
  {
    crc = 1;
    tmp = tracks[track][i] - sublen[track];

    for (int j = 0; j < bitlen[track] - 1; j++)
    {
      crc ^= tmp & 1;
      lrc ^= (tmp & 1) << j;
      playBit(tmp & 1);
      tmp >>= 1;
    }
    playBit(crc);
  }

  // finish calculating and send last "byte" (LRC)
  tmp = lrc;
  crc = 1;
  for (int j = 0; j < bitlen[track] - 1; j++)
  {
    crc ^= tmp & 1;
    playBit(tmp & 1);
    tmp >>= 1;
  }
  playBit(crc);

  // if track 1, play 2nd track in reverse (like swiping back?)
  if (track == 0)
  {
    // if track 1, also play track 2 in reverse
    // zeros in between
    for (int i = 0; i < BETWEEN_ZERO; i++)
      playBit(0);

    // send second track in reverse
    reverseTrack(2);
  }

  // finish with 0's
  for (int i = 0; i < 5 * 5; i++)
    playBit(0);

  digitalWrite(PIN_A, LOW);
  digitalWrite(PIN_B, LOW);
  digitalWrite(ENABLE_PIN, LOW);

}


// stores track for reverse usage later
void storeRevTrack(int track)
{
  int i, tmp, crc, lrc = 0;
  track--; // index 0
  dir = 0;

  for (i = 0; tracks[track][i] != '\0'; i++)
  {
    crc = 1;
    tmp = tracks[track][i] - sublen[track];

    for (int j = 0; j < bitlen[track] - 1; j++)
    {
      crc ^= tmp & 1;
      lrc ^= (tmp & 1) << j;
      tmp & 1 ?
      (revTrack[i] |= 1 << j) :
      (revTrack[i] &= ~(1 << j));
      tmp >>= 1;
    }
    crc ?
    (revTrack[i] |= 1 << 4) :
    (revTrack[i] &= ~(1 << 4));
  }

  // finish calculating and send last "byte" (LRC)
  tmp = lrc;
  crc = 1;
  for (int j = 0; j < bitlen[track] - 1; j++)
  {
    crc ^= tmp & 1;
    tmp & 1 ?
    (revTrack[i] |= 1 << j) :
    (revTrack[i] &= ~(1 << j));
    tmp >>= 1;
  }
  crc ?
  (revTrack[i] |= 1 << 4) :
  (revTrack[i] &= ~(1 << 4));

  i++;
  revTrack[i] = '\0';
}

void sleep()
{
  set_sleep_mode(SLEEP_MODE_PWR_DOWN);    // replaces above statement

  sleep_enable();                         // Sets the Sleep Enable bit in the MCUCR Register (SE BIT)
  sei();                                  // Enable interrupts
  sleep_cpu();                            // sleep

  cli();                                  // Disable interrupts
  sleep_disable();                        // Clear SE bit
  sei();                                  // Enable interrupts
}


void loop()
{
  sleep();

  noInterrupts();
  while (digitalRead(BUTTON_PIN) == LOW);
  delay(50);
  while (digitalRead(BUTTON_PIN) == LOW);
  
  playTrack(1 + (curTrack++ % 2));
  
  delay(400);

  interrupts();
}

Got to shovel snow now, but:

  • The L293D cannot work at 3V7V (plus this is a poor choice as it has a lot of voltage drop)

im runing of 5v from the gpio on my arduino uno currently. and okay ill look at alternatives

http://samy.pl/magspoof/

Disconnect the lead to pin 1 of the l293d and also Vcc to the l293d

Now test the circuit with a simple blink sketch

So your schematic is not correct. We have a saying in computing GIGO.

What will happen when the coil tries to draw current from that pin?

If that is literally true, there is a good chance of burning up the GPIO pin.

Please re-post all your images inline, as explained here:

Also a complete schematic, the one you posted is only a sub circuit.

Additionally, you posted in a category that explicitly excludes hardware problems. Please send a moderator request to move it.

no the schematic is not correct i just coppied samys schematic for the purpose of showing it im using the 5v and ground on the ardunio to power the breadboard.

if im honest this is the first time ive tried anything like this with the arduino other than a simple traffic light sketch. im a total noob.

and in answer to your question im not sure what would happen when the coil tried to draw current from that pin possibly break something???

Please fix the general problems with your posts before we continue...

it didnt allow me to have more than 1 photo in my thread thats why i had to upload them with the links i can upload them seperatly in comments if thats okay?? like ive said im a total noob and just looking for some help

The forum introductory guide is specifically designed for that kind of person.

The forum blocks come off as soon as you use the forum even a little bit, like reading some threads...

Did you try just pasting the images into the posts? With copy and paste?

no i didnt i used the upload button at the top next to where you put the code

I've tidied this up a bit, apologies if I've deleted something I should have left in place.

@systemtdx ,
You might just want an answer but to get an answer certain things are asked for so that the volunteers trying to help you have the information they need in order to give you the answer you want, so, please, provide the required information and I am sure someone will help. We know you are new, folk want to help, but they can't help without certain information. The help is free, please respect the people giving it.

To post images etc you need trust level 1, you can get there by:

  • Entering at least 5 topics
  • Reading at least 30 posts
  • Spend a total of 10 minutes reading posts

Users at trust level 1 can…

  • Use all core Discourse functions; all new user restrictions are removed
  • Send PMs
  • Upload images and attachments

[Edit, I've checked, you are now at trust level 1, you should be able to upload images etc]

I thank you.

ANS: the 5V supply will be overloaded and the voltage will drop.
A LiPo can provide big current without dropping.

then see if the ATTiny can flash the LED

i see that makes sence now. and im guessing i need to program a blink sketch onto the tiny to see if it works? or am i keeping the code i have on there and seeing if the button makes the led light up?

Yes, do that.

Problem, bread board power rail split:


Solution, bread board power rail split:

mine is not split in the middle and i did have them jumpped to connect both grounds and +

the blink sketch is not working have i fried the attiny :confused:

void setup() {
  // initialize digital pin LED_BUILTIN as an output.
  pinMode(0, OUTPUT);
}

// the loop function runs over and over again forever
void loop() {
  digitalWrite(0, HIGH);  // turn the LED on (HIGH is the voltage level)
  delay(1000);                      // wait for a second
  digitalWrite(0, LOW);   // turn the LED off by making the voltage LOW
  delay(1000);                      // wait for a second
}

im using the blink example in the ide and ive set it to pin 0 and connected it all up with an led i know works. i programmed it with the arduino as isp as thats the only way i have of programming it (i followed a youtube video ATTiny85 Program Using Arduino UNO - YouTube ) and the led does not blink at all have i fired the attiny

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.