📜 ⬆️ ⬇️

Arduino in a snack machine

This post is a continuation of the story about filling vending machines with simple and affordable electronics based on Arduino. And really - the possibilities of the platform are endless! And so, the second machine is a snack machine selling chips / water / chocolates / etc.




')
The main thing is to start! The desire to buy a machine appeared after bringing to mind the first machine with coffee. Many visitors wanted to chew something along with delicious coffee.

In the open spaces of the network and thematic forums spent all his free time. Based on the ads for the sale of used snack machines, I was already preparing to save a considerable amount (about 100 thousand rubles for a simple device).
And here it is happiness - there was an advertisement for the sale of a machine with a simple filling (previously sold magazines and newspapers) for 20 thousand rubles! Word for word, caused private traders to deliver around the city. 250 kilograms of iron were loaded in three.

So. The first month of owning the device - its filling is recognized thoroughly, it is included in the network and is being tested. It turns out earlier it was quite a normal snack machine, only under the order his brains were turned over for the sale of 2 items per shelf (and 2 motors per item). Just taking and connecting additional gearboxes - the situation has not changed - the brains were completely reflashed, and he could not sell more goods. Having phoned a company that made an “upgrade,” I learned the amount of putting in order - about 10 thousand rubles only for updating the controller software. By the way, the Atmel Mega-168 chip was on the board, which is a bit like a good Arduino. But alas, in order to solve it independently, and even more so to understand the work with the periphery, you would have to kill a lot more time.

Making brains machine yourself


After removing all the electronics from the machine, he dragged her home. Having called and checked the work of the gearboxes, he began to draw a scheme for connecting the Arduino and the entire periphery.
The first test assembly worked on the Arduino Nano (freeduino), and was quite able to turn on the motor of the issuance according to any algorithm.

In parallel, the layout of the goods on the shelves was drawn. I rummaged through the entire Internet in search of examples, searched for snack machines in the city shopping center (I took pictures of the location and quantity of goods on the shelves), and drew a diagram for my machine. It turned out the standard 4 products on the first two shelves (wide packs of chips / crackers). One shelf for 8 products (candy bars, cookies). And a shelf for water bottles (7 products).

The first task is to learn how to turn on / off the engines for the issuance of goods


The engine, or rather the motor with the gearbox, is activated by the usual power supply of 12V. On the shaft of the gearbox is a mikrik, which responds to a full turn. A steel spring is also connected to the shaft, in the turns of which the product is folded. With full circulation, the product moves to the edge and the very first "snickers" falls into the issuing box.

With the layout of the goods, it was possible to understand how many motors will produce goods. 23 engine. A scheme was implemented with three shift registers 74HC595 connected in series. But in the first test, or rather when the machine was turned on, the registers danced as they wanted and as a result, all the engines spun randomly for a second. Now, looking at the implementation scheme, I see that I missed the valve control pin - when, without this pin, the outputs did not react to the transmitted data. But that was it ... I just had to take the Arduino Mega, plus bipolar transistors to control the motors. It turns out that there are 23 Arduino outputs for the issuance of goods. On the one hand, this seems to be overkill, but on the other - a necessity. Perhaps in the next version I will try the shift registers again.



In the photo from top to bottom: Arduino Mega in a plastic case, a prototype board with transistors and connectors for connecting, a prototype board with connectors for a keyboard, product selection and a display.

The second task is to connect the keyboard





At first this task seemed to me the most difficult. But having disassembled the keyboard, I saw that there is no controller there and the usual matrix scheme is used - columns and lines. I entered it in a simple way - different power is supplied to 6 lines (from 5V to 0.5, through resistors). And with 3 speakers, the voltage is read through the analog inputs. Total, having involved only 3 entrances, we can read buttons of the keyboard 6x3.

The third task is to connect the display.





The board has four 8-segment LED displays, a LED driver that works just like a shift register. Using the example of working with a regular register and datasheet driver, I successfully wrote a function that clocked the driver, gave out bits in order. Plus two additional LEDs, which are also included through the same register.

What was my surprise when this display has earned! This is not just copying the finished function and launching it on the controller - it is something else. And the LED display in reality looks cooler than the LCD display. During the tests I ran a second counter on it at night, I just ran a running point. Moreover, the symbols are not generated by the shift register, but by their program — the register simply transfers the bits that need to be lit. An array of all numbers, some letters (for the word Err), plus a cash deposit symbol (equal sign) was added to the program.

The fourth task is receiving cash





This photo shows: a bill acceptor, a payment module, a coin acceptor with tubes for coins, a cash drawer and a bunch of wires - this is a geek machine, as it should be :)

The machine already had a bill acceptor and coin acceptor with the function of issuing change. They work on the MDB protocol, which is quite difficult to implement, although the protocol is also in 1993. In fact, this is a normal Serial-protocol, but with some qualification - 8 data bits + parity bit, which indicates the direction of transmission, and not parity. In the SoftwareSerial library in Arduino, you could do the logic for yourself, but another factor surfaced - the delay between the command and the response should not exceed 5ms, otherwise it is regarded as timeout. It was necessary to communicate with payments in real time, and most likely to use for this interruption.
Nights on the passage with the debugger com-ports to nothing lead.
But the solution was found - a third-party C-MDB module from our compatriots from Ukraine. The module is simply excellent - it works with payments under this protocol and in the usual com-port gives the necessary data (from the characteristics of the payments, to the type of the received coin / bill and the status of the boxes with money).

The last task is to put it all together.


After analyzing everything, it was decided to add a regular system unit to this automaton based on Linux CentOS. Fortunately, there is a lot of space inside the machine under the shelves, both for storing goods and for the system unit. What functions are assigned to this computer:



How is all this connected


Arduino via USB via a standard output connected to the system unit. In normal mode, a com-port appears, in which Arduino writes logs and receives responses from the daemon (price request).

The C-MDB module via the standard com-port of the system manager sends information about the money to the daemon, which already transfers only the information about the deposited money to the Arduino.

The engines, keyboard, and display are connected to the Arduino and are controlled only by it. By the way, now a kind of master-device is exactly Arduino. She decides on the issuance of goods, requests a price from the computer, controls the display on the display and turns the engines. In the next version, I want to transfer all the logic to the system unit (to the daemon), while the Arduino leaves only executive functions, because sometimes I had to go with a laptop to fix the buggy of the machine. And for SSH to fix the demon in PHP is much easier.

And the web interface is just fire! Real-time sales are shown, the balance of money in boxes, information on the balance of goods after purchase, logs of operations and messages. I wanted to see a webcam in the same place, but it won't start with me. Suddenly, who can help with the solution: ID 0c45: 608f Microdia PC Camera (SN9C103 + OV7630), when trying to take a picture (cat / dev / video) - kernel: usb 3-2: Initialization failed again. I will retry on next open ()

The daemon is written in pure PHP, which monitors the com-port of the payment module and communicates with it, recording all the information in the log. And the USB-COM port listens to the Arduino - it writes logs and responds to the price request. Along the way, he keeps a record of goods sold in MySQL, and after a successful sale, he also sends an E-mail to a personal box (it's nice to see dozens of sales per day).

The output of the audio card included speakers. I wanted to record sound zamanuhi and pristavalki to people (quiet and communicating place in the organization). Plus connected the motion sensor to the Arduino, which responds to the passage of a person nearby. I thought about turning on the set-top box on the motion sensor, but I haven’t written down the phrases yet. Although the effect seems amazing!

One year of operation of the machine - the results


What I want to say - Arduino is not only a simpler and cheaper way to make brains with an iron box, but also a great opportunity to do it yourself! Yes, there were childish mistakes when inattention did not allow the machine to start (for example, the power went down and the engine did not have enough strength to tighten the Coca-Cola), but in order to be given the opportunity to pass all these tests.

Having opened the web interface now, I can say that during this time there were 1355 sales. Yes, I confess - and I myself often buy Coca-Cola from myself - even if it is more expensive, but it is more pleasant :) In terms of amounts - the machine has fully paid for itself and all the time invested. And brings only profit and joy!

And now about the plans!

After 2 days, the installation will come for the sale of carbonated drinks (exactly the same as in bars, only without taps). Installing it on top of the coffee machine, connecting the controls to the brains of this machine - you get two paired machines with a single payment system, a single management and unlimited possibilities! And also the very ideas when the price of coffee can be reduced on a schedule (for example, from 09 to 11 am), issue bar codes (collect 5 bar codes and get any coffee for free), a convenient way to pour coffee with "your own" (for example on ibutton tablets or smart cards), payment by SMS and much more!

And finally, I would like to say that automatic machines are cool! Cool not only from the developer, but also the user - convenient and fast! Let him can deceive, but he will not do it on purpose (the light blinked and that's it, your credit disappeared on the screen). The automatic machine is a round-the-clock sales and complete trust in him of his money and goods. He will not steal, will not shortcut his owner, will send E-mail about the successful sale or error day and night, and can treat him with a free drink.

In the comments I would be glad to hear what other functions you can add to such machines.

Source: https://habr.com/ru/post/143756/


All Articles