Hi, i'm trying to build an aquarium controller which will control different parameters and display them on the LCD.
here's the modules i'm using:
16x2 i2c LCD
ds3231 (time)
UGN3503 (hall effect)
DS18b20 (temp)
a 433mhz receiver
and some relays
so what i wanna do is to check all parameters and display them as they changed state or not. so i need to update the information on the LCD every (x) seconds.
i figured out that the "delay" function is holding the whole process and i have to use "state machine" to operate the loop.
i just started learning Arduino and i know the "basics" but honestly i'm lost!
do i have to use a library for that to make things easier or not and if yes which library?
i'd really appreciate it if someone point me to where i have to start to learn how state machine works and how to implant it in my project.
State Machine is a fancy name for a simple process of using a variable to keep track of the changes in some system. For example
tap flowing
bath full
child in bath
child out of bath
floor wet
It is a different concept from the business of monitoring a sensor and updating the displayed value although it is possible that a particular sensor value (such as water depth) would mean that a system needs to move on to another state.
The functions delay() and delayMicroseconds() block the Arduino until they complete.
Have a look at how millis() is used to manage timing without blocking in Several Things at a Time.
I can’t think of anything more specific than you don’t need one. Why do you think you do need one?
A state machine is for running several processes seemingly at the same time. You requirements do not cover that at all. Unless you are not telling us the whole tail.
Grumpy_Mike:
I can’t think of anything more specific than you don’t need one. Why do you think you do need one?
A state machine is for running several processes seemingly at the same time. You requirements do not cover that at all. Unless you are not telling us the whole tail.
He just needs delay without delay() and probably a little new to this whole thing, or he has some other things he wants to do but not telling us. My money is on the "new to this whole thing" part. By the way "whole tail", is that a new type of bread, like whole grain? Man I'd love to have some of that.
No, the whole point of without delay is to implement a state machine.
By the way "whole tail", is that a new type of bread,
I think we might be suffering a language barrier here, while I am not adverse to a pun, I can’t see the connection between tail and bread? Unless it is a spelling joke, in which case being dyslexic most of those are lost on me.
thanks, can i use the ds3231 to keep track of time(seconds) passed instead of using milis()?
Grumpy_Mike:
I can’t think of anything more specific than you don’t need one. Why do you think you do need one?
A state machine is for running several processes seemingly at the same time. You requirements do not cover that at all. Unless you are not telling us the whole tail.
well there are several processes; check temperature every (x) seconds, 2 pumps state, hall effect sensor state, what time it is and do what at certain times, clear and update information on LCD if any of states changed...
RabbitTheDevil:
He just needs delay without delay() and probably a little new to this whole thing.
yes exactly. and TBH i just started with Arduino...
finite:
thanks, can i use the ds3231 to keep track of time(seconds) passed instead of using milis()?
well there are several processes; check temperature every (x) seconds, 2 pumps state, hall effect sensor state, what time it is and do what at certain times, clear and update information on LCD if any of states changed...
yes exactly. and TBH i just started with Arduino...
If you are not controlling anything on LCD, which means LCD is just there to show stuff, I'd handle this with a loop counter. Display one thing for like 50 or 100 loops, display another for whatever loop counts you want and so on. When the last display is over, just reset the counter and start over. Much much easier.
The basic Arduinos can do 16 million things in 1 second. Using the RTC for timing things is usually much too coarse. You want the display to respond to button pushes in 0.1 seconds or less, otherwise it is annoying and difficult to use.
Here is a simple state machine you can use now. Your DS18B20 temperature sensor(s) take 750ms to do a 12-bit temperature reading. This is way too long to wait if you have data coming in at 433MHz. So you must use the sensor library in asynchronous mode with the setWaitForConversion() function.
So the sensor (library) can now be in one of three states:
Doing nothing
Actively converting a temperature reading
Finished converting; waiting for you to ask what the temperature was.
Your state machine needs to keep track of these states. Every 5 seconds (or whatever period you pick which is longer than 750ms) you tell the sensors to start a conversion. While you are in state 2, you can actively ask the sensor "you done yet?" or you can just wait slightly longer than 750ms. Then you can ask for the temperature and go back to state 1 and wait for the next 5-second interval.
MorganS:
The basic Arduinos can do 16 million things in 1 second. Using the RTC for timing things is usually much too coarse. You want the display to respond to button pushes in 0.1 seconds or less, otherwise it is annoying and difficult to use.
Here is a simple state machine you can use now. Your DS18B20 temperature sensor(s) take 750ms to do a 12-bit temperature reading. This is way too long to wait if you have data coming in at 433MHz. So you must use the sensor library in asynchronous mode with the setWaitForConversion() function.
So the sensor (library) can now be in one of three states:
Doing nothing
Actively converting a temperature reading
Finished converting; waiting for you to ask what the temperature was.
Your state machine needs to keep track of these states. Every 5 seconds (or whatever period you pick which is longer than 750ms) you tell the sensors to start a conversion. While you are in state 2, you can actively ask the sensor "you done yet?" or you can just wait slightly longer than 750ms. Then you can ask for the temperature and go back to state 1 and wait for the next 5-second interval.
thanks for expanding the answer, do you suggest any article/tutorial for further reading? (i'm VERY new to this but i'm learning)
Grumpy_Mike:
I think we mean from here.
lol i bet you found hundred mistakes in my grammar because English is my third language "Grumpy Mike".
lol i bet you found hundred mistakes in my grammar as English my third language "Grumpy Mike".
No, it is quite concise.
That was not so much at mistake of grammar it had a very important error embedded in it. It implied that data was being received at the rate of 433 MHz, where it is actually only being received at the speed data is being modulated onto the 433MHz carrier. So it is defined by the baud rate of what ever is sending you the signal. If you are using the serial pins for that then any incoming data will be held in the serial buffer until you get round to looking at it.
If the DS18B20 temperature sensor takes 750ms to do a 12-bit temperature reading, then unless you program it correctly, a state machine will not help you. If you use a library, for example, it is likely that the library code will not return until the value is ready, making this just as blocking as if you did not use a state machine.
To use this in a state machine context, you would have to initiate a reading, and then return immediately. Then keep checking each millisecond to see if the conversion is complete, and when it is only then return with the answer, and mark the state machine as inactive.
A way to start, which you'll see recommended here from time to time is to take each component and write a sketch that uses it, showing your results using the Serial port. That way, you can learn how to use your parts in isolation. Then build your controller project by adding one piece at a time. Trying to do it all at once is a pretty sure guarantee of problems.
What are the various parts for? The clock, LCD and DS18B20 are fairly obvious (I think), I'm not so sure about the other pieces.
Grumpy_Mike:
, it is likely that the library code will not return until the value is ready,
If you use the first library that comes up in Google search then this is indeed the default behavior of the library. But you can tell it not to wait. Just setWaitForConversion(false); and it works without blocking.
"From" would have been better than "at." I'm typing on a phone here and fewer letters is easier.