BakedPotato
Posts: 4
Joined: Thu Feb 01, 2018 2:28 pm

Automatic bartender

Thu Feb 01, 2018 3:33 pm

Hi guys.
First of all I´m studen of Information and network technologies (I know basics of electronic, Java, C++ and Arduino)
I need help with my project "Automatic Bartender". I need to control 2 stepper motors (exactly 3 but 2 of them are connected together) via phone.

- I have Arduino Uno with Motor Shield and bluetooth HM-10, my idea was to connect it to mobile and control motors through console of bluetooth App but It´s not working for me.

- My second idea was to use Raspberry Pi 3, but there are many question about it.
1. Probably it´ll be very complicated to connect Arduino with HM-10 to Raspberry so
2. I think it will be better to connect motors to Raspberry but is it even possible ? I just need to connect pins for controling the motors, for external power I can use 8xAA batteries or ATX source from old PC (there are all needed voltages such as 12V; 5V; 3,3V) which will power Raspberry and motors separetly, because I don´t want to overheat Raspberry.
3. If I´ll connect motors to Raspberry then I´ll need to control them via WiFi, make some server, then website with buttons which will control motors and create any drink I will select.
4. And my biggest problem is how to create code which will control motors. I know how to create website with HTML and CSS for design of buttons but that´s all :/

- So any ideas what should I do ? Btw everything it´s working I can make drink but just via PC, changing the code of Arduino but I want to make more than just one drink.
Attachments
IMG_20180201_155125.jpg
IMG_20180201_155125.jpg (136.51 KiB) Viewed 1182 times
IMG_20180201_153507_HHT.jpg
IMG_20180201_153507_HHT.jpg (127.67 KiB) Viewed 1182 times

User avatar
OutoftheBOTS
Posts: 709
Joined: Tue Aug 01, 2017 10:06 am

Re: Automatic bartender

Thu Feb 01, 2018 8:37 pm

OK to connect motors to RPi it is the same design as Ardunio, you will need a motor control board (h-bridge with controller).

Google "Raspberry Pi motor control board"

For simplicity I would look for an I2C type motor controller that is stack-able as this will make life much simpler for a beginner.

BakedPotato
Posts: 4
Joined: Thu Feb 01, 2018 2:28 pm

Re: Automatic bartender

Thu Feb 01, 2018 10:50 pm

So there isn´t any option of using what I have or I just more difficult ?
Can You send my some example of that motor shield ? And why I2C type ?

MrGreg
Posts: 66
Joined: Sun Jun 10, 2012 7:25 pm

Re: Automatic bartender

Fri Feb 02, 2018 12:33 am

I think you can use what you have already got. (might be a bit too easy though?....And no RPI)
Firstly your Arduino needs to be a genuine or near perfect clone running at 16Mhz. There are many clones that only run at 12Mhz which cause all sorts of problems and wont work properly.

Load GRBL onto the Arduino (Uno)
See
https://github.com/gnea/grbl/releases
Connect a bluetooth adapter to the Arduino

Go to GooglePlay and search for Gcode sender for GRBL ( there are many) for your phone
You may need to do a bit to get that working and talking properly with the bluetooth adapter & Arduino/GRBL

Your "Drink" recepies would consist of a few lines of Gcode in a file. As many as you like, sent from your phone.

You might want to modify the code to make it more interesting?

BakedPotato
Posts: 4
Joined: Thu Feb 01, 2018 2:28 pm

Re: Automatic bartender

Fri Feb 02, 2018 9:08 am

I need some "special" code for it ? I mean in Arduino

PiGraham
Posts: 3526
Joined: Fri Jun 07, 2013 12:37 pm
Location: Waterlooville

Re: Automatic bartender

Fri Feb 02, 2018 9:44 am

BakedPotato wrote:
Thu Feb 01, 2018 3:33 pm
Hi guys.
First of all I´m studen of Information and network technologies (I know basics of electronic, Java, C++ and Arduino)
I need help with my project "Automatic Bartender". I need to control 2 stepper motors (exactly 3 but 2 of them are connected together) via phone.

- I have Arduino Uno with Motor Shield and bluetooth HM-10, my idea was to connect it to mobile and control motors through console of bluetooth App but It´s not working for me.
That seems a good way to go. Maybe you should visit an Arfuino forum and get help with specific problems. I don't think changing to a Pi will help.
You will need to give details of your components and connections, code etc and say exactly whatworks and what goes wrong. Otherwise you are just asking domeone to do your project for you.

BakedPotato
Posts: 4
Joined: Thu Feb 01, 2018 2:28 pm

Re: Automatic bartender

Sat Feb 03, 2018 8:43 am

So for the components:
- 3 Motors: Nema 17 Stepper Motors (Model 17HS4401)
- Arduino: Arduino Uno R3, Motor Shield L293D
- Bluetooth: Bluetooth module HM-10 BLE (Model CC2541)
- Raspberry: Raspberry Pi 3 (Model B V1.2)
- Display: I2C 16x1 Display
- Other: Bunch of cables, resistors, breadboard, siwtch, some tape

What´s working ? Basically I can create whatever drink You want but every time I need to change the code. Raspberrry is working but I m newbie about it :D
What´s not working ? Bluetooth communication with Phone (Xiaomi Mi6), I can connect and pair but if I´ll send "50" which should move motor 50 step, does nothing

For the code, I can create code for the drink, it´s just couple commands where you must define how many steps, backward/forward and type of movement. But I want to change easily drink not by changing the code.
Second code is for bluetooth/serial communication, it´s not mine because I don´t really understand it, especially how BT communication works. All I know is that You should type in Serial Monitor(Bluetooth App) commands like 50, 10, 01, where 50 is distance to move, 10 is time to dispense and 01 is how many times to repeat.

Code: Select all

//The below is for the contact switch

const int  buttonPin = 2;    // the pin that the pushbutton is attached to

int buttonPushCounter = 0;   // counter for the number of button presses
int buttonState = 0;         // current state of the button
int lastButtonState = 0;     // previous state of the button


//----------------------

//The below is for the stepper motors

#include <AFMotor.h>

AF_Stepper motor1(48, 1);
AF_Stepper motor2(48, 2);


//---------------------

//The below are for running the machine:
int raftFound = false;


void setup() {

// for the contact switch 

  // initialize the button pin as a input:
  pinMode(buttonPin, INPUT);
  // initialize serial communication:
  Serial.begin(9600);
  
//--------------------------------

//  For the stepper motors

  motor1.setSpeed(600);
   motor2.setSpeed(600);

//--------------------------------

}

void loop() {
  delay(1000);
  //Lets find the location of the float:-
  
  // read the pushbutton input pin:
  buttonState = digitalRead(buttonPin);

  //move the stepper until the contact switch is triggered
  while(buttonState == LOW && raftFound == false){
   motor1.step(10, FORWARD, SINGLE); 
   buttonState = digitalRead(buttonPin);
  }

 raftFound = true;
    // Delay a little bit to calm the arduino down.
    delay(300);

//Move to first pump
  motor1.step(50, BACKWARD, SINGLE);
    motor1.release();
  delay(500);
      motor2.step(2000, BACKWARD, DOUBLE);
      delay(2000);
     motor2.step(2000, FORWARD, DOUBLE);
     motor2.release();
      delay(500);
  motor1.step(700, BACKWARD, SINGLE);
  motor1.release();
    delay(500);
      motor2.step(2200, BACKWARD, DOUBLE);
      delay(5000);
      motor2.step(2200, FORWARD, DOUBLE);
      motor2.release();
      delay(500);
      delay(999000);

}

Code: Select all

 #include <AFMotor.h>

int numberCollector;  // to build the number from serial
byte serialNumber = 0;  // to store the ASCI number from serial
int opticCount = 6;  // how many optic stations there are - you also need to update line 7
int parameterCount = 3; //number of seeting to be stored in array for each optic
int parameterSize = 2; //the required number of digit for each parameter being sent

int drinkMatrix[6][3] = {
  };

//The below is for the contact switch.

const int  buttonPin = 2;    // the pin that the pushbutton is attached to
int buttonState = 0;         // current state of the button
int lastButtonState = 0;     // previous state of the button

//----------------------

//The below is for the stepper motors

AF_Stepper motor1(48, 1);
AF_Stepper motor2(48, 2);

//---------------------

//The below are for running the machine:

int raftFound = false;
int drinkRequested = false;

//---------------------

void setup() {

// for the contact switch 

  // initialize the button pin as a input:
  pinMode(buttonPin, INPUT);
  // initialize serial communication:
  Serial.begin(9600);
  
//--------------------------------

//  For the stepper motors

  motor1.setSpeed(600);
   motor2.setSpeed(600);

//--------------------------------

}

void loop(){ 
  
//Lets find the location of the float:
if (raftFound == false){
  Serial.println("Raft location not known yet");
  delay(1000);
  Serial.print("Looking for the raft...");
  buttonState = digitalRead(buttonPin); // read the pushbutton input pin:
//move the stepper until the contact switch is triggered
  while(buttonState == LOW && raftFound == false){
    motor1.step(10, FORWARD, INTERLEAVE); 
    buttonState = digitalRead(buttonPin);
  }
 raftFound = true;
 Serial.println("ahh! There it is. :)");
 motor1.release();
 delay(700); // Delay a little bit to calm everything down
} 


//working through the dispensing instructions until drink is complete and paddle is at last optic position:
if (drinkRequested == true){  
  for (int optic = 0; optic < opticCount; optic++) { //Move to pump 
motor1.step((drinkMatrix[optic][0] * 10), BACKWARD, DOUBLE); //move the paddle according to instruciton, x10 to allow us to compress serial data transfer length
motor1.release(); // let the motor's magnets relax
//dispense what is required then resume moving to the next position:
while(drinkMatrix[optic][2] > 0 && raftFound == true){
    delay(500);
        motor2.step(2100, BACKWARD, DOUBLE);
        delay((drinkMatrix[optic][1]) * 100);
       motor2.step(2100, FORWARD, DOUBLE);
       motor2.release();
       drinkMatrix[optic][2] = drinkMatrix[optic][2]-1;
       delay(500); 
    }
  }

//Drink complete  
  Serial.println("Drinks ready, enjoy.");
  drinkRequested = false;
  raftFound=false;
}

 while(drinkRequested == false){
 delay(200);

   if (Serial.available()) {
    for (int optic = 0; optic < opticCount; optic++){
      for (int parameter = 0; parameter < parameterCount; parameter++){     
        for (int parameterMeasure = 0; parameterMeasure < parameterSize; parameterMeasure++){
          if (Serial.available()) {
            serialNumber = Serial.read(); /* load the number from serial buffer */
            serialNumber = serialNumber - 48; /* convert number to text number */
            numberCollector = numberCollector * 10 + serialNumber; /*store and build the number*/
          } else {
            delay(250);
            serialNumber = Serial.read(); /* load the number from serial buffer */
            serialNumber = serialNumber - 48; /* convert number to text number */
            numberCollector = numberCollector * 10 + serialNumber; /*store and build the number*/     
          }
        }
       drinkMatrix[optic][parameter] = numberCollector;   /* store the value in the array  */
       numberCollector =  0;   /* Prepare variable for next number  */
       serialNumber = Serial.read(); /* to clear the comma from the buffer */
      }
      }
    CheckArray();
    Serial.println("Done loading");
    drinkRequested = true;
    }
    
 }
    
}


void CheckArray(){
//print out the array to check it:
for(int i = 0; i < opticCount; i++) {
  for(int j = 0; j < 3; j++) {
    Serial.print(drinkMatrix[i][j]);
    Serial.print(",");
  }
  Serial.println();
  }
}

MrGreg
Posts: 66
Joined: Sun Jun 10, 2012 7:25 pm

Re: Automatic bartender

Sat Feb 03, 2018 7:33 pm

I don´t really understand it, especially how BT communication works.
I guess you better get aquainted with Arduino Bluetooth comms then......

This might help

http://www.martyncurrey.com/

Return to “Automation, sensing and robotics”