Arduino Help?

3 views
Skip to first unread message

Melissa Ford

unread,
Mar 27, 2015, 12:44:25 PM3/27/15
to coderdojodc
Is there anyone who would have a moment to help us troubleshoot some arduino code?  The kids are trying to build this: (http://www.instructables.com/id/littleTea-robotic-tea-brewing/?ALLSTEPS)

And this is the code: https://github.com/imrehg/littleTea/blob/master/littleTea.ino

The problem we're having is that the tea bag dips up and down and never full removes itself from the cup.  What we want to have happen is that the servo turns, lowering the tea bag slowly into the water, and then 3 minutes later, the servo turns again, raising the tea bag out of the water. 

Any thoughts on how to change this code in order to get it to do what we want it to do?

Mel




Ben Kelly

unread,
Mar 27, 2015, 12:55:37 PM3/27/15
to Melissa Ford, coderdojodc
I suspect this line:

  int setVal = (offVal - onVal)/steps*i + onVal;

At:

  https://github.com/imrehg/littleTea/blob/master/littleTea.ino#L87

There are two potential problems here, I think.  (I'm assuming this is basically C.)

1) You may want an extra set of parens to make sure the logic is correct:

  int setVal = ((offVal - onVal)/steps)*i + onVal;

2) Since you are using int types (offVal - onVal)/steps is going to get truncated to an int.  If steps is larger than offVal - onVal, then you get zero before you have a chance to multiply by i.

You could avoid the rounding problem by doing the i multiply first:

  int setVal = onVal + (((offVal - onVal) * i) / steps);

Hope that helps.  Sorry if I'm completely off-base.

Ben

--
@CoderDojoDC
http://coderdojodc.com
---
You received this message because you are subscribed to the Google Groups "CoderDojoDC" group.
To unsubscribe from this group and stop receiving emails from it, send an email to coderdojodc...@googlegroups.com.
Visit this group at http://groups.google.com/group/coderdojodc.
For more options, visit https://groups.google.com/d/optout.

Melissa Ford

unread,
Mar 27, 2015, 1:36:29 PM3/27/15
to Ben Kelly, coderdojodc
Tried making that change, but it still doesn't work.

So here's the oddest part.  When I cut-and-paste that code exactly into a Mac desktop, it does exactly what it says it will do: it is still, dips the bag, and then removes the bag.  When I try the exact same code on a Mac laptop OR a Windows laptop, in both cases, the servo starts moving before I've uploaded the code into the arduino, and once I upload the code and run it, it doesn't behave as it does on the desktop.  It bobs up and down very quickly, dragging the tea bag in and out of the cup hundreds of times.

If we could take the desktop with us, this wouldn't be a problem, but since it isn't very portable... :-)

Anything else to try on the laptops to get this to work?

Erica S. Kane

unread,
Mar 27, 2015, 9:19:36 PM3/27/15
to Melissa Ford, coderdojodc

That change isn't enough, you will still get integer division. Cast or define the variables to floats or throw in a 1.0 multiply somewhere so you get the right output.

Erica

Reply all
Reply to author
Forward
0 new messages