Stepper Shield Lemonade Stand

Post here about your Arduino projects, get help - for Adafruit customers!

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
User avatar
adafruit_support_bill
 
Posts: 88091
Joined: Sat Feb 07, 2009 10:11 am

Re: Stepper Shield Lemonade Stand

Post by adafruit_support_bill »

Assuming that your switches are active-LOW:

Code: Select all

bool plain = digitalRead(plainSwitch) == LOW;
bool basic = digitalRead(basicSwitch) == LOW;
bool deluxe = digitalRead(deluxeSwitch) == LOW;

if (plain )
{
   // do plain 
}
else if (basic )
{
   // do basic 
}
else if (deluxe )
{
   // do deluxe 
}

User avatar
AlaskaJeff
 
Posts: 37
Joined: Sat Jan 11, 2014 1:29 am

Re: Stepper Shield Lemonade Stand

Post by AlaskaJeff »

Making the Plain, Basic, Deluxe protocols if fine, but it will only let me do them as three separate 'if' blocks. When I make the basic and deluxe blocks under 'else if's, then I get a error " 'else' without a previous 'if' " even though the first block (the plain) is under an 'if' .

Thanks

User avatar
adafruit_support_bill
 
Posts: 88091
Joined: Sat Feb 07, 2009 10:11 am

Re: Stepper Shield Lemonade Stand

Post by adafruit_support_bill »

Can you post the code you are using?

User avatar
AlaskaJeff
 
Posts: 37
Joined: Sat Jan 11, 2014 1:29 am

Re: Stepper Shield Lemonade Stand

Post by AlaskaJeff »

Code: Select all

  #include <Wire.h>
  #include <Adafruit_MotorShield.h>
  #include "utility/Adafruit_PWMServoDriver.h"
 
 
  
    
    
Adafruit_MotorShield AFMStop(0x60);// Default address- no jmpers.
Adafruit_MotorShield AFMSbot(0x61); // Rightmost jumper closed Adafruit_MotorShield AFMStop(0x60); 
Adafruit_StepperMotor *myStepper1 = AFMStop.getStepper(200,1);
Adafruit_StepperMotor *myStepper2 = AFMStop.getStepper(200,2);
Adafruit_StepperMotor *myStepper3 = AFMSbot.getStepper(200,1);
Adafruit_StepperMotor *myStepper4 = AFMSbot.getStepper(200,2);

int greenLed = 1;
int redLed = 2;
int basicSwitch = 3;
int plainSwitch = 4;
int deluxeSwitch = 5;
int fillSensor = 6;
int fillRelay = 7;
int blueLaser = 8;
int greenLaser = 9;
int rightLight = 10;
int middleLight = 11;
int leftLight = 12;
int redLaser= 13;
  void setup ()
  {

  AFMSbot.begin(); // Start the bottom shield
  AFMStop.begin(); // Start the top shield

  Serial.begin(9600); // 

  myStepper1->setSpeed(30); //sensor speed
  myStepper2->setSpeed(100); //conveyor speed
  myStepper3->setSpeed(200); //laser horizontal
  myStepper4->setSpeed(50); //laser vertical speed
    Serial.begin(9600); // set up Serial library at 9600 bps Serial.println("Stepper test!");
  pinMode(greenLed,OUTPUT); //green "OK" LED
  pinMode(redLed,OUTPUT); //red "underway" LED
  pinMode(basicSwitch,INPUT_PULLUP); //select basic lemonade
  pinMode(plainSwitch,INPUT_PULLUP); //select the basic laser
  pinMode(deluxeSwitch,INPUT_PULLUP); //select deluxe laser
  pinMode(fillSensor,INPUT_PULLUP); // the fill sensor 
  pinMode(fillRelay,OUTPUT);//the valve filling the cup- relay #1
  pinMode(blueLaser,OUTPUT);//the blue laser relay- relay #2
  pinMode(greenLaser,OUTPUT);//the green laser- relay #3
  pinMode(redLaser,OUTPUT);//the red laser- relay #4

  }
void loop()

{
  bool plain = digitalRead(basicSwitch) == LOW; // the right switch for plain lemonade
  
  bool basic = digitalRead(basicSwitch) == LOW; // the middle switch for basic laser treatment
  
  bool deluxe = digitalRead(deluxeSwitch) == LOW; // the right switch for deluxe laser treatment
  
  digitalWrite(greenLed,HIGH); //turns the green light on
  digitalWrite(fillRelay,HIGH); //keeps the fill relay OFF
  digitalWrite(blueLaser,HIGH); //keeps the blue laser relay OFF- this is LOW=ON relay
  digitalWrite(greenLaser,HIGH); //keeps the green laser relay OFF-this is LOW=ON relay
  digitalWrite(redLaser,HIGH); //keeps the red laser relay OFF-this is LOW=ON relay

  
  
  if (plain); //This runs plain lemonade without laser treatment. What loser wants that? Lasers are the WAY.
  {
    digitalWrite(greenLed,LOW);// turns the green "ready" light off
    digitalWrite(redLed,HIGH);// turns the red "underway" light on
    digitalWrite(rightLight,HIGH); // turns on the right switchlight- this is the white adafruit MOM switch
  
  myStepper2->step(2000, BACKWARD, DOUBLE);//move conveyor to the fill position
  myStepper1->step(55, FORWARD, MICROSTEP);//put in the fill sensor
  
  
    while (fillSensor == HIGH)//fillSensor has an internal pullup and remains high untill the (-) hits the lemonade
    {
      digitalWrite(fillRelay,LOW); // keeps the fill valve opened untill fillsensor goes LOW
    }
  
  digitalWrite(fillRelay,HIGH);//closes the fill valve
  
  myStepper1->step(55, BACKWARD, MICROSTEP);// moves the sensor out of the lemonade
  
  delay(500);
  
  myStepper2->step(2000 , FORWARD, DOUBLE);// moves drink back to the start
  digitalWrite(greenLed,HIGH); //resets the ready green light
  digitalWrite(redLed,LOW);// stops the red 'underway' light
  digitalWrite(rightLight,LOW);// turns the right light off
    
  }
  
  else if ( basic );
  {
     //the basic protocol
  }
  
  else if ( deluxe );
  {
    //the deluxe thing
  }
  
}
  }
Last edited by adafruit_support_bill on Fri May 30, 2014 6:28 am, edited 1 time in total.
Reason: fixed code tags

User avatar
adafruit_support_bill
 
Posts: 88091
Joined: Sat Feb 07, 2009 10:11 am

Re: Stepper Shield Lemonade Stand

Post by adafruit_support_bill »

Code: Select all

  if (plain); 
The semicolon is a statement terminator. That 'if' statement ends at that semicolon and the code in the brackets following it will execute unconditionally.

Eliminate the semicolons and let the curly brackets {} define the scope of the ifs and else ifs.

Code: Select all

if (plain )
{
   // do plain 
}
else if (basic )
{
   // do basic 
}
else if (deluxe )
{
   // do deluxe 
}

User avatar
AlaskaJeff
 
Posts: 37
Joined: Sat Jan 11, 2014 1:29 am

Re: Stepper Shield Lemonade Stand

Post by AlaskaJeff »

Removing the ;'s worked well.

I have one last (hopefully) problem. I wanted to bundle the laser cannon shots, which has the rapid fire of two lasers, into a function. That is at the end of the snippet here. It states the function definition isn't allowed before "{". Changing them hasn't helped.

Code: Select all

void loop()
{
lasercannon(7,delayperiod);// the first cannon shot
}
  
  
  
  myStepper2->step(500,FORWARD,DOUBLE);//move halfway back.
  digitalWrite(blueLaser,LOW);
  delay(1000);
  digitalWrite(blueLaser,HIGH);
  
  digitalWrite(greenLaser,LOW);
  delay(1000);
  digitalWrite(greenLaser,HIGH);
  digitalWrite(blueLaser,LOW);
  delay(1000);
  digitalWrite(blueLaser,HIGH);
  myStepper2->step(1000,FORWARD,DOUBLE); //return cup to the beginning
  
     digitalWrite(greenLed,HIGH);
     digitalWrite(redLed,LOW);
     digitalWrite(middleLight,LOW);
  
  }


}
void lasercannon(int numShots, int d)
{
  for(int i=0; i < numShots; i++)
  digitalWrite(greenLaser, LOW);
  delay(d);
  digitalWrite(greenLaser,HIGH);
  delay(d);
  digitalWrite(blueLaser,LOW);
  delay(d);
  digitalWrite(blueLaser,HIGH);
  delay(d);
  
}
Last edited by adafruit_support_bill on Fri May 30, 2014 11:46 am, edited 1 time in total.
Reason: fixed code tags

User avatar
adafruit_support_bill
 
Posts: 88091
Joined: Sat Feb 07, 2009 10:11 am

Re: Stepper Shield Lemonade Stand

Post by adafruit_support_bill »

Code: Select all

void loop()
{
lasercannon(7,delayperiod);// the first cannon shot
}
That is your complete loop function. It's scope is defined by the brackets: { }
Everything after that closing bracket is just hanging in the wind.

You need to make sure that your brackets are always balanced. For every '{', you must have a '}'.

User avatar
AlaskaJeff
 
Posts: 37
Joined: Sat Jan 11, 2014 1:29 am

Re: Stepper Shield Lemonade Stand

Post by AlaskaJeff »

Thanks. Sorry for my lameness, but this is new. I try very hard to read elsewhere prior to asking you. The service you provide to back up the Adafruit products is amazing, I appreciate it, recognize it costs money for you to provide it, and think someone is crazy to buy stuff where this sort of help isn't available. I'm a loyal groupie.

User avatar
adafruit_support_bill
 
Posts: 88091
Joined: Sat Feb 07, 2009 10:11 am

Re: Stepper Shield Lemonade Stand

Post by adafruit_support_bill »

We are happy to support your research into laser treated lemonade!

User avatar
AlaskaJeff
 
Posts: 37
Joined: Sat Jan 11, 2014 1:29 am

Re: Stepper Shield Lemonade Stand

Post by AlaskaJeff »

greenlaser.jpg
greenlaser.jpg (61.85 KiB) Viewed 521 times
The lasers, steppers and MOM switches work great. The only stumbling point left is making the loop work that controls the fill valve. There are two electrodes that descend into the cup, and when the lemonade hits them, in theory, the contact is closed between fillSensor and ground, taking fillSensor ==LOW. This is supposed to stop the filling valve. I have tried using pull up or pull down resistors, and using both a 'while ' and 'do while' loop. The fill valve never opens. Is my ' do while' loop bad?

I know the valve works. The valve is open when fillRelay==LOW

Code: Select all

  #include <Wire.h>
  #include <Adafruit_MotorShield.h>
  #include "utility/Adafruit_PWMServoDriver.h"
 
 
  
    
    
Adafruit_MotorShield AFMStop(0x60);// Default address- no jmpers.
Adafruit_MotorShield AFMSbot(0x61); // Rightmost jumper closed Adafruit_MotorShield AFMStop(0x60); 
Adafruit_StepperMotor *myStepper1 = AFMStop.getStepper(200,1);
Adafruit_StepperMotor *myStepper2 = AFMStop.getStepper(200,2);
Adafruit_StepperMotor *myStepper3 = AFMSbot.getStepper(200,1);
Adafruit_StepperMotor *myStepper4 = AFMSbot.getStepper(200,2);

int greenLed = 1;
int redLed = 2;
int basicSwitch = 4;
int plainSwitch = 3;
int deluxeSwitch = 5;
int fillSensor = 6;
int fillRelay = 7;
int blueLaser = 8;
int greenLaser = 9;
int rightLight = 10;
int middleLight = 11;
int leftLight = 12;
int redLaser= 13;
int delayPeriod = 1000;
  void setup ()
  {

  AFMSbot.begin(); // Start the bottom shield
  AFMStop.begin(); // Start the top shield

  Serial.begin(9600); // 

  myStepper1->setSpeed(30); //sensor speed
  myStepper2->setSpeed(100); //conveyor speed
  myStepper3->setSpeed(200); //laser horizontal
  myStepper4->setSpeed(50); //laser vertical speed
    Serial.begin(9600); // set up Serial library at 9600 bps Serial.println("Stepper test!");
  pinMode(greenLed,OUTPUT); //green "OK" LED
  pinMode(redLed,OUTPUT); //red "underway" LED
  pinMode(basicSwitch,INPUT_PULLUP); //select basic lemonade
  pinMode(plainSwitch,INPUT_PULLUP); //select the basic laser
  pinMode(deluxeSwitch,INPUT_PULLUP); //select deluxe laser
  pinMode(fillSensor,INPUT_PULLUP); // the fill sensor 
  pinMode(fillRelay,OUTPUT);//the valve filling the cup- relay #1
  pinMode(blueLaser,OUTPUT);//the blue laser relay- relay #2
  pinMode(greenLaser,OUTPUT);//the green laser- relay #3
  pinMode(redLaser,OUTPUT);//the red laser- relay #4
  pinMode(rightLight,OUTPUT); //the right switch light
  pinMode(middleLight, OUTPUT);//the middle switch light
  pinMode(leftLight,OUTPUT);//the left switch light
  }
  
  //relay #1 is fillRelay, relay #2 is greenLaser, relay #3 is blueLaser, relay# 4 is redLaser. 
  
void loop()

{
  bool plain = digitalRead(plainSwitch) == LOW; // the right switch for plain lemonade
  
  bool basic = digitalRead(basicSwitch) == LOW; // the middle switch for basic laser treatment
  
  bool deluxe = digitalRead(deluxeSwitch) == LOW; // the right switch for deluxe laser treatment
  
  digitalWrite(greenLed,HIGH); //turns the green light on
  digitalWrite(fillRelay,HIGH); //keeps the fill relay OFF
  digitalWrite(blueLaser,HIGH); //keeps the blue laser relay OFF- this is LOW=ON relay
  digitalWrite(greenLaser,HIGH); //keeps the green laser relay OFF-this is LOW=ON relay
  digitalWrite(redLaser,HIGH); //keeps the red laser relay OFF-this is LOW=ON relay 
  digitalWrite(redLed ,LOW);//keeps red led low
  
  
  if (plain)  //This runs plain lemonade without laser treatment. What loser wants that? Lasers are the WAY.
  {
    digitalWrite(greenLed,LOW);// turns the green "ready" light off
    digitalWrite(redLed,HIGH);// turns the red "underway" light on
    digitalWrite(rightLight,HIGH); // turns on the right switchlight- this is the white adafruit MOM switch
  
  myStepper2->step(2000, BACKWARD, DOUBLE);//move conveyor to the fill position
  myStepper1->step(55, FORWARD, MICROSTEP);//put in the fill sensor
   
  do
  {
    digitalWrite(fillRelay,LOW);// fillsensor using internal pull up
    
  }
    while (fillSensor == HIGH);
    
  digitalWrite(fillRelay,HIGH);//closes the fill valve
  
  myStepper1->step(55, BACKWARD, MICROSTEP);// moves the sensor out of the lemonade
  
  delay(500);
  
  myStepper2->step(2000 , FORWARD, DOUBLE);// moves drink back to the start
  digitalWrite(greenLed,HIGH); //resets the ready green light
  digitalWrite(redLed,LOW);// stops the red 'underway' light
  digitalWrite(rightLight,LOW);// turns the right light off
    
  }
  
  else if ( basic) ...
Last edited by adafruit_support_bill on Tue Jun 03, 2014 6:42 am, edited 1 time in total.
Reason: please use the </> button when submitting code. press </>, then paste your code between the [code] [/code] tags.

User avatar
adafruit_support_bill
 
Posts: 88091
Joined: Sat Feb 07, 2009 10:11 am

Re: Stepper Shield Lemonade Stand

Post by adafruit_support_bill »

Code: Select all

  do
  {
    digitalWrite(fillRelay,LOW);// fillsensor using internal pull up
    
  }
    while (fillSensor == HIGH);
You need to read 'fillSensor' in your loop. Otherwise, it will never change.

User avatar
AlaskaJeff
 
Posts: 37
Joined: Sat Jan 11, 2014 1:29 am

Re: Stepper Shield Lemonade Stand

Post by AlaskaJeff »

The valve works- I triggered it with a digitalWrite and delay.

I confirmed the electrodes have the 5v from the internal pullup.

I've placed a digitalRead(fillSensor) in every configuration, and still can't make a 'while,' 'do while' or 'if' function to open the valve while the sensor electrodes are untouched my the lemonade.

Other things to try?

User avatar
adafruit_support_bill
 
Posts: 88091
Joined: Sat Feb 07, 2009 10:11 am

Re: Stepper Shield Lemonade Stand

Post by adafruit_support_bill »

Is your valve normally open or normally closed. i.e. Do you need to energize it to open or energize it to close?

Add some Serial.println() diagnostics at the major decision points in your code, then watch the output in the serial monitor. That will give you a better picture of what the code is actually measuring and doing.

User avatar
AlaskaJeff
 
Posts: 37
Joined: Sat Jan 11, 2014 1:29 am

Re: Stepper Shield Lemonade Stand

Post by AlaskaJeff »

All systems are a go. We eventually got the electrode working with an Analog read. That's sort of cool because we can alter the sensitivity of the sensor. I don't get why it works with analog, but not digital, but don't have time to figure it out.

Code: Select all

else if ( basic) //this runs the basic laser treatmnet
  {
    
    digitalWrite(greenLed,LOW);// turns the green "ready" light off
    digitalWrite(redLed,HIGH);// turns the red "underway" light on
    digitalWrite(middleLight,HIGH); // turns on the middle switchlight- this is the blue adafruit MOM switch
  myStepper3->step(190,FORWARD,MICROSTEP);//rotate the laser horizontal over the track
  myStepper2->step(2000, BACKWARD, DOUBLE);//move conveyor to the fill position
  myStepper1->step(55, FORWARD, MICROSTEP);//put in the fill sensor
  
  
    analogRead(fillSensor);
  sensorValue=analogRead(fillSensor) ;
  while (sensorValue <voltCut)
  {
    analogRead(fillSensor);
    sensorValue=analogRead(fillSensor);
    digitalWrite(redLaser,LOW);
    digitalWrite(fillRelay,LOW);
    Serial.println(sensorValue);
  }
  
  digitalWrite(fillRelay,HIGH);//closes the fill valve
  digitalWrite(redLaser,HIGH);//turns the red laser off
... etc etc

So I'm placing an order, and I'd like to monitor sensorValue, since it varies a fair amount. Can I have the Serial.print go directly to your two wire LCD thing? I can monitor it on a laptop, but that isn't as cool as an LCD, and when you're into Laser Treated Lemonade, it all about coolness. Now that we have the basic function conquered, we're going to try to incorporate our Wave Shield too.

User avatar
adafruit_support_bill
 
Posts: 88091
Joined: Sat Feb 07, 2009 10:11 am

Re: Stepper Shield Lemonade Stand

Post by adafruit_support_bill »

Can I have the Serial.print go directly to your two wire LCD thing?
Do you mean the shield, or one of the LCD display backpacks? Either way it can be done - It just requires a different library.
and when you're into Laser Treated Lemonade, it all about coolness.
Agreed!

Locked
Please be positive and constructive with your questions and comments.

Return to “Arduino”