📜 ⬆️ ⬇️

Nalivator-9000: robot barman on Raspberry Pi and Go



A couple of years ago, I came across a Kickstarter project on Bartendro . I liked the idea, and I decided that the ideal application for my newly acquired Raspberry Pi was found. I figured out what details would be needed, and proceeded to the DIY implementation of the robot barman. Briefly tell what came out of it.

Hardware


The main element of the whole structure, of course - the pumps. In the original Bartendro project, proprietary peristaltic pumps are used (by the way, the entire project is available in github ).

A peristaltic pump is a pump that pushes its contents through the tube, as if a tube of paste were squeezing out. Accordingly, one end is dropped into the bottle, and the other into the glass. Gifka with Wikipedia with the principle of action:
')
image

Similar to the original Bartendro pumps available on Aliexpress . Practice has shown that they are good in operation, because they remove the front panel with a tube - it is very convenient to wash after a feast.

The Raspberry Pi has GPIO connectors on the board. By means of them, signals “1” or “0”, 3.3V and 0V are sent or received, respectively. The specification for the pump indicates that its operating voltage is 12V, and the “crimson” 3.3V will not be enough here. Therefore, to work you will need another power supply, and you can control it using a transistor switch. The final scheme looks like this:

To select a transistor, it is necessary that the collector-emitter voltage and the maximum collector current be at least 1.5–2 times higher than necessary. I chose the BDX33B , its collector-emitter voltage is 80V, and the maximum collector current is 10A, which is enough for a pump with a starting current of 2A and a voltage of 12V. In order to open the transistor, on the base you need to get no more than 2.5V. We consider the divider in some online calculator - we get R1 = 150 Ohm, R2 = 300 Ohm.

As a whistle player, I added three LEDs connected to three other GPIO pins, which will designate a running motor, as well as will be needed when visualizing a speech synthesizer. At the GPIO outputs, you can hang a maximum load of 15 mA per pin, or 50 mA in total. Therefore, I connect the LEDs through the resistors of 300 Ohms, the current in this case will be ~ 4 mA per pin.

Now you can go to the nearest radio parts store and try to collect.

Software


Raspberry Pi is generally a rather slow thing - for example, Django, on which I originally wanted to make a web application, runs a few minutes. Therefore, I decided to abandon it in favor of something lightweight, namely Go. It compiles quickly, cross-compiling under linux-arm on my PC takes about 20 seconds. At the output we get a small size binary, which is statically assembled and carries all dependencies inside. It can be immediately rsync-ohm copied to a raspberry pi and checked. Very convenient for such small applications. Cross-compilation options for linux-arm look like this:

GOOS=linux GOARCH=arm GOARM=6 go build 

Different versions of Raspberry Pi have different versions of ARM. You can find out your version in / proc / cpuinfo

Since the pumps do not have any volume sensors poured in, but the throughput is known, the volume can be monitored through the running time of the pump. Empirically, I found out - to pour 100 milliliters, you need to keep the pump on for 30 seconds. It turns out you need to write an application that, on command, turns on the pumps for a certain time in turn. In this implementation, it is implied that Plymvator is able to make only one cocktail, that is, he has only one button - “Pour”.

I made a config that describes the connected pumps and the cocktail that needs to be poured.

The format is
 { "cname": "", "pumps": [ { "name": "Tequila", "pump_pin": 17, "led_pin": 23, "duration": 17 }, { "name": "Juice", "pump_pin": 22, "led_pin": 25, "duration": 49 }, { "name": "Grenadine", "pump_pin": 27, "led_pin": 24, "duration": 7 } ] } 


This config reads the Livator at startup, and understands which pin needs to be turned on for how long. To work with GPIO, I used the go-rpigpio library :

The code is very simple
  for _, v := range CurrentPumps.Pumps { log.Printf("Nalivaem %s ;duration = %v; GPIO = %v", v.Name, v.Duration, v.Pump_pin) //pump pin open p, err := rpi.OpenPin(v.Pump_pin, rpi.OUT) if err != nil { panic(err) } defer p.Close() //led pin open l, l_err := rpi.OpenPin(v.Led_pin, rpi.OUT) if l_err != nil { log.Printf("LED - Can't set LED pin to output") } defer l.Close() // pump on p.Write(rpi.HIGH) //led on l.Write(rpi.HIGH) time.Sleep(time.Second * time.Duration(v.Duration)) // pump off p.Write(rpi.LOW) //led off l.Write(rpi.LOW) } } 


All code in github - github.com/fote/nalivator9000

It remains to add a web interface and you're done. As for the case, I did not bother and placed everything in the Ikeev box. At this point, I realized that the designer will not leave me. In general, over the appearance is still worth the work.

When the time came for testing, I invited friends to do load testing, but before they arrived, I realized that the web interface is not very convenient - it is not accessible from the Internet, and to connect to a password protected wi-fi network, enter the IP address in the browser ... too complicated. Then I added a telegram-bot, which waits for him to write the name of the cocktail and pours it. I will not describe how to create a bot, because There are already a lot of good articles on this topic, including for Golang.

I also decided to add speech synthesis using Yandex SpeechKit . The API of this service is very simple, and the license agreement allows you to use it for free for non-commercial purposes. Before sending a message from a telegram bot, I run the phrase through SpeechKit, in response I receive a .wav file and play it through a speaker connected via a 3.5mm-jack.

Conclusion


The testing of the Innovator was successful - the testers were satisfied and left many features.

Finally, the video work:



For your health!

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


All Articles