Why does serial.read stop working?

pylon:

I understand from your post that my state machine Hold0 is in a loop in loop() so serial.available() is able to keep being .... available... Probably what I need to do then is move EXEC(Hold0) out of the loop() and into setup(), but give it its own loop to read characters. What is the best way to do that? giving it a loop to allow reading multiple characters from serial?

No, you misunderstood me. The EXEC(Hold0) is not that wrong in the loop() but having only that state machine being called in the loop you must never call it's Finish() method. EXEC() is not being called once and then the state machine runs "itself" but it's designed to be called repeatedly, it's the working horse of the state machine. I got the impression from your code that you thought that you call EXEC(Strike) and then that state machine is running in a kind of "background" task/process, so you can end the Hold0 state machine. This is not the case. An Arduino doesn't have an operating system that is taking care of processes and background tasks. It does run through our program, the only exception are the interrupts but that's more a hardware thing.
Each of your state machines have only one state and that's where I think is your conceptional error.

Maybe you should describe what your whole program is expected to do.

Pylon,
If I don't finish the SM Hold0, then I can never use the serial string "next" anywhere else. That's not 100% horrible, but does limit my ability to change how I go through my states (see above response to Zoomkat) .

I was hoping to avoid being a double poster, but I can see that you need a bit more context.
I'm building a home brewing system, this system will be unique because of 4 key features:

  • Propane heated, using a servo to control propane flow (as opposed to electric or on/off control of gas)
  • Brew In A Bag, not 3 vessel
  • Support multiple mash steps
  • Read data from BeerXML files

The first one is unique in the world of home brewing as far as I can tell. Others have taken the idea and run with it - my friend tob77 made a version in Python for RasPi, http://www.homebrewtalk.com/f235/raspberry-pi-brew-controller-451059/
But I'm a bit unsure if Arduino can support the sheer number of 'if' statements that he's using to get his states.

If you don't know about beer brewing (and BIAB particularly) what you need to know is that beer is made by soaking grain in hot water of around 150F for some period of time. This has the effect of converting the starches in the malted grain into sugars and extracting those sugars from the grain. The enzyme activity that does this conversion is controlled by the temperature of the water. Too cold, no enzyme activity, too hot, you denature the enzymes. There is a sweet spot where you can convert the starches using alpha and beta amylase, but each of those works better at a specific temperature. Beta amylase works best at 130-150, and Alpha works best at 150-160.

So, to best control the profile of the beer, I want to control the mash profile - how many steps, what temperature, and for how long. That's what brings me to the state machine, because I want to have multiple mash states that aren't always going to be used. tob77's solution is to have a "beta rest" whether or not he uses that step. I don't want to have the step if not necessary.

Some steps in brewing will always be there, though. There is always a strike (initial water heating) step and there will always be a boil step.

I've got my arduino program working pretty well, except getting the recipe information out of beerXML and into some format that will change Setpoint and control time for each of the steps. Also, there need to be some alarms and steps that have nothing going on for time to add the grain to the strike water.

Attached is my full sketch for the automated BIAB, but it's missing the getRecipes() section, and that's what I want the state machine for. Of course, if it works well there, I could do the whole thing in state machines, then I don't need delay(), huzzah!

I hope that's clear. Let me know if not and I can clarify.

Thanks,
JR

automatedBIAB_v1.ino (7.73 KB)