Address

Author Topic: Serial & NFC Controlled Candy Dispenser  (Read 2131 times)

Waterbury

  • FamiLAB Member
  • Sr. Member
  • *
  • Posts: 347
  • You can do it. We can help!
    • View Profile
Serial & NFC Controlled Candy Dispenser
« on: February 14, 2013, 05:01:16 PM »
For the February 8th-10th, 2013 Hackathon, I purchased a very generic, electric proximity-controlled candy dispenser for $7 from Goodwill. The intent was to reverse engineer it, and to control the dispense mechanism via the ATTiny4313s provided for the event. The goal was to provide members candy based on an NFC/RFID read, or via direct serial control. Perhaps even having a game that automatically dispenses candy as a reward.

I NEEDED the 4313 to communicate over serial for my purposes. After a lot of toolchain issues and hackery I was able to get the 4313 to work on the Arduino IDE by pretending to be a 2313, which is a 4313...with half the flash. The 4313 has it's internal fuses configured with an 8MHz internal clock with an 8x divider. This causes it actually run at 1MHz. This causes the UART not to work right. Also, the Arduino IDE didn't know how to change the fuses. After researching the hell out of the issue, I manually forced AVRDude to disable the divider, but serial was still messing up.

Surprise, the 8MHz crystals in the 4313s aren't stable, or something... Whelp, I managed to get the chip to work with an 16MHz EXT crystal! or so I thought... The execution would fail at the same iteration, every time. Recompiling would cause it to fail at a different iteration, consistently. The chip wasn't RANDOMLY failing, it was failing at a specific operation. Reading into the issue suggested that GCC was compiling an unsupported opcode into the hex as the makefile was configured wrong, and the configurations were off...ENOUGH, I had ENOUGH. After a lot of headaches, and screaming I decided to use a an ATMega328 instead.
« Last Edit: February 15, 2013, 02:43:27 AM by Waterbury »
"The American, by nature, is optimistic. He is experimental, an inventor and a builder who builds best when called upon to build greatly." ~ John F. Kennedy

Waterbury

  • FamiLAB Member
  • Sr. Member
  • *
  • Posts: 347
  • You can do it. We can help!
    • View Profile
Re: Serial & NFC Controlled Candy Dispenser
« Reply #1 on: February 14, 2013, 05:03:45 PM »
For the machine, I had to find a way to control the motor directly, and to detect hand-motion without triggering the motor. The hand motion detection is provided by a close proximity IR-Detector/Ir-Emitter pair of LEDs. After looking on a scope, it appeared that the IR-Emitter emits pulsed light, and the IR-Detector in turn expects the same pulse width reflected back. This is very common in IR proximity detection circuits, as if it only detected a change in IR illumination, almost any change in an ambient light source could trigger it. I considered simulating the IR-Emitting Pulse Width, but that would have taken a lot of work, and I knew there had to be an easier and better way.

I quickly found that shorting the IR-Emitter signal with the IR-Detector signal would count as a "trigger," but it was very crude. Also, the Proximity Detector circuit was still connected, and as I wanted to be able to restrict access to the machine, having the proximity detector still in loop defeated my control. I at one point cut the IR-Detection signal from the IR-detector, but this permanently broke proximity detector, and I wanted to retain it.

I started running into the reverse problem as before, detecting the Proximity detection rather than simulating it. I quickly found that I would have to build a circuit and code quite a bit to do the work that the existing circuit already did.

The IC in control of the machine was an 8-pinned SMD component with it's labeling sanded off (no surprise) so I didn't know what to expect. I started tapping into the pins seeing if any would change when the machine was triggered. I found a pin that did, and it was connected to an NPN Transistor that would connect GND to the motor. I was finally on to something. I knew I could tap this pin for proximity detection, but didn't want to remove the motor from the circuit as I figured the chip was some kind of motor driving board. NOPE, I was giving it too much credit for Chinese engineered crap.




More to come..  :)
"The American, by nature, is optimistic. He is experimental, an inventor and a builder who builds best when called upon to build greatly." ~ John F. Kennedy

johnbentcope

  • FamiLAB Member
  • Hero Member
  • *
  • Posts: 584
  • I make technology into art and art into porridge.
    • View Profile
    • JohnBentCope
Re: Serial & NFC Controlled Candy Dispenser
« Reply #2 on: February 16, 2013, 03:35:21 AM »
Very cool man! Can't wait to see more!
I like colors.

bethjaneway

  • FamiLAB Member
  • Sr. Member
  • *
  • Posts: 331
    • View Profile
Serial & NFC Controlled Candy Dispenser
« Reply #3 on: February 16, 2013, 10:55:14 AM »
Nice. That's like this miniature ski gondola someone asked me to repair for their train set, the motor was supposed to reverse direction and stopped doing it.  Inside was a circuit board with a 16-pin chip, a couple of transistors, several resistors, various other stuff. I looked at it and realized the only thing switching the direction... was a mechanical gear/ switch :p. After checking the motor's specs to make sure it could handle the full input voltage, I just ditched the circuit.
Note: To improve mood, administer chocolate.

Simply7

  • FamiLAB Member
  • Hero Member
  • *
  • Posts: 547
    • View Profile
Re: Serial & NFC Controlled Candy Dispenser
« Reply #4 on: February 16, 2013, 01:53:29 PM »
This is way cool. Looks like we now have a way to feed the cyborgs at Familab.

I guess the cyborg club has a new motto "get chipped or starve"

PockyBum522

  • Pocky
  • Sr. Member
  • ****
  • Posts: 440
  • Oh alcohol, I still drink to your health~
    • View Profile
Re: Serial & NFC Controlled Candy Dispenser
« Reply #5 on: February 17, 2013, 10:36:08 PM »
We need a sign that says "Please don't feed the cyborgs"


Now if you want to give us beer, that's an entirely different story.

Waterbury

  • FamiLAB Member
  • Sr. Member
  • *
  • Posts: 347
  • You can do it. We can help!
    • View Profile
Re: Serial & NFC Controlled Candy Dispenser
« Reply #6 on: March 14, 2013, 01:11:12 AM »
I'll have to be light on the software details, as I used a lot of dirty hacks, but it's alive! I connected an Adafruit NFC board, and it will dispense candy when approved cards are swiped.

I connected an RGB LED, and when a known card is scanned it will fade a green light in and out until you hold you hand out to collect your candy.

https://www.youtube.com/watch?v=vYsnHYsFmPw
« Last Edit: March 14, 2013, 01:13:09 AM by Waterbury »
"The American, by nature, is optimistic. He is experimental, an inventor and a builder who builds best when called upon to build greatly." ~ John F. Kennedy