Hello! I have an Arduino, a LCD and a temp. sensor. When I'm plugging it in (laptop via USB or AC Adapter), the LCD shows 0 degrees. If it is connected to the laptop, after I open the Serial monitor, it is working perfect. If it is connected with the AC Adapter, it needs a reset button push before doing the measurement. What should I do to make it skip this? ![]()
Thanks!
beige22:
What should I do to make it skip this?
Have you tried hitting it ? That used to make my old record player skip.
You could perhaps show us your code...
Haha, no, I didn't try hitting it
I attached the code
temperatura_v2.ino (892 Bytes)
When you open the Serial monitor it causes your Arduino to reset - which is consistent with you saying you need to press the reset button.
However I don't see why that should be needed.
I note that it seems to be taking an average of 1000 temperature readings - isn't that rather excessive? Could it be causing an unwanted delay? What happens if you change it to 10 ?
...R
Robin2:
I note that it seems to be taking an average of 1000 temperature readings - isn't that rather excessive? Could it be causing an unwanted delay? What happens if you change it to 10 ?
Just tested: both 5 and 5000 readings cause the same behaviour. I do not understand it either and I'm thinking if I can go around that and "cheat" by trying to reset the Arduino through software. Is this a good approach or should I try something else?
Software reset is just a kludge that does not work well - ignore that option.
Let's try some step by step diagnosis.
What Arduino are you using and what LCD?
How are they connected?
Does the text in setup() show on the LCD without the need for pressing reset?
If it does I would temporarily rename loop() and create a new loop() function that just prints some message to the LCD every few seconds.
...R
Arduino Uno R3. LCD = RC1602B-BIW-CSX (datasheet: http://www.robofun.ro/docs/RC1602B-BIW-CSX.pdf). Connected through pins mentioned in the code and a breadboard. I use two 2.2k resistors to avoid using a pot. It shows both the text and the temperature, but it shows temperature as being 0.
If I'm reading your code correctly, you appear to be doing an analog read on pin 0. This pin is also used by the serial port, and is going to get some traffic during a reset, and also when you plug the USB cable in.
Try it on pin 2 and see if it's still doing it.
Ian.
beige22:
Arduino Uno R3. LCD = RC1602B-BIW-CSX
You did not answer the much more important question about whether the code in setup() displays on the screen without pressing reset.
Please answer all questions.
AFAIK analogRead() treats pin0 as A0, but it would be no harm to use A0 just to be certain. Pin2 is certainly not an option.
...R
ian332isport:
If I'm reading your code correctly, you appear to be doing an analog read on pin 0. This pin is also used by the serial port, and is going to get some traffic during a reset, and also when you plug the USB cable in.
analog pin 0 is not the same as digital pin 0 which is used by the serial port.
The pin numbering on Arduino is a mess.
Different functions use different numbering spaces.
digitalRead(), digitalWrite(), analogWrite() all take a digital pin number since they are all digital functions.
(Yes analogWrite() is a digital function)
analogRead() uses an analog pin number.
digital pin 0 and analog pin 0 are not the same pin.
So digitalRead(0) and analogRead(0) are looking at different pins.
To add to the confusion analogRead() can also take a digital pin number as long as it is above the analog pin numbers.
So digitalRead(A0) and analogRead(A0) look at the same pin because A0 is constant that is the equivalent digital pin number of analog pin 0. It is a pin number that is above the largest analog pin number so analogRead() will notice this and will try to convert it back to the proper analog pin number.
There is also some confusion and inconsistency of how this works on different platforms (arduino variants) as some platforms used an analog channel number for the argument to analogRead() and on some platforms there is not a one to one mapping between the analog channel and the analog pin number. i.e. analog pin 0 is not always analog channel 0.
So for example, if the variant is defined to use analog channels instead of analog pins and the analog channels and analog pins don't map to the same pin then when you use naked constant like 0 you will not get analog pin 0.
For simplicity/clarity and ensuring you are always reading the correct analog pin, it is better to use A0, A1, etc... rather than a naked 0, 1, etc.. for analogRead() since the An constants always map to the proper pin as labled on the Arduino board.
--- bill
Robin2:
You did not answer the much more important question about whether the code in setup() displays on the screen without pressing reset.Please answer all questions.
AFAIK analogRead() treats pin0 as A0, but it would be no harm to use A0 just to be certain. Pin2 is certainly not an option.
...R
Sorry, I was not too clear in my statement. Yes, it displays the text from setup(), and then it displays also the temperature and the "degrees C", but the temperature is not the correct one (it shows 0). If I press reset, it is showing the correct temp. The problem isn't the display, as it works fine, is the measurement that waits for a reset to start.
I'll also try to use the A0 instead of 0 and see what results I get.
bperrybap:
analog pin 0 is not the same as digital pin 0 which is used by the serial port.The pin numbering on Arduino is a mess.
Different functions use different numbering spaces.
digitalRead(), digitalWrite(), analogWrite() all take a digital pin number since they are all digital functions.
(Yes analogWrite() is a digital function)analogRead() uses an analog pin number.
digital pin 0 and analog pin 0 are not the same pin.
So digitalRead(0) and analogRead(0) are looking at different pins.
To add to the confusion analogRead() can also take a digital pin number as long as it is above the analog pin numbers.
So digitalRead(A0) and analogRead(A0) look at the same pin because A0 is constant that is the equivalent digital pin number of analog pin 0. It is a pin number that is above the largest analog pin number so analogRead() will notice this and will try to convert it back to the proper analog pin number.There is also some confusion and inconsistency of how this works on different platforms (arduino variants) as some platforms used an analog channel number for the argument to analogRead() and on some platforms there is not a one to one mapping between the analog channel and the analog pin number. i.e. analog pin 0 is not always analog channel 0.
So for example, if the variant is defined to use analog channels instead of analog pins and the analog channels and analog pins don't map to the same pin then when you use naked constant like 0 you will not get analog pin 0.For simplicity/clarity and ensuring you are always reading the correct analog pin, it is better to use A0, A1, etc... rather than a naked 0, 1, etc.. for analogRead() since the An constants always map to the proper pin as labled on the Arduino board.
--- bill
Hi Bill,
Thanks for clarifying that. I didn't realise this was the case.
Ian.
So I changed the pin from 0 to A0 and it still has the same problem, displaying temp = 0 until I press reset or start the serial monitor... ![]()
beige22:
So I changed the pin from 0 to A0 and it still has the same problem, displaying temp = 0 until I press reset or start the serial monitor...
Do you know if it just prints 0 once and then stops doing anything or is it printing 0 repeatedly?
Try changing loop() as I suggested in Reply #5
Or add to your code so it displays millis() / 1024 as well as the temperature - if the "seconds" display updates it will be a useful indicator. Post the revised code and tell us the results.
...R
It prints 0 repeatedly until I press restart or open the serial monitor. I added a humidity sensor and it is displaying right, everything is functional and doing its "job" but the temp sensor. It is the only one that is waiting... Actually it is not waiting because it is not displaying the initial value I set to temp_new, it is reading eronated that 0. I also tried to change the pin but nothing changed.
beige22:
I added a humidity sensor and it is displaying right, everything is functional and doing its "job" but the temp sensor.
Now he tells us ...
It's impossible to make sensible suggestions when you "hide" important information from us.
What else are you not telling us?
Where is the code with the working humidity sensor and the non-working temperature sensor?
...R
What is pin 7 being used for?
Did you modify the code as Robin suggested in reply #13 to ensure that the processor is still actually running vs stuck/crashed?
--- bill
Robin2:
Now he tells us ...It's impossible to make sensible suggestions when you "hide" important information from us.
What else are you not telling us?Where is the code with the working humidity sensor and the non-working temperature sensor?
...R
I added the sensor today, after I already mentioned the problem I faced and posted the code yesterday. Today I have the same problem I had before adding it, the only difference is that now I know now the processor is not sleeping. I can plug out the sensor, upload the old code again on Arduino and have the same problem...
bperrybap:
What is pin 7 being used for?Did you modify the code as Robin suggested in reply #13 to ensure that the processor is still actually running vs stuck/crashed?
--- bill
Pin 7 is used for LCD backlight. I did not modify the code as Robin suggested but I did modify it by adding the humidity sensor. This sensor works fine while the temperature sensor indicates 0 so I would say the processor is running.
beige22:
I added the sensor today, after I already mentioned the problem I faced and posted the code yesterday.
Well why do I have to ask questions before you tell us?
And the only code that I can see is in Reply #2 and it does not include the new sensor.
How about posting the latest code without always having to be asked.
I'm getting very tired of this.
If you think I am just wasting your time please say so. But before you do ask yourself this question "If he had that problem would he be able to solve it" (and if that sounds arrogant - too bad).
...R
I don't know what you are and what you are not able to solve, so asking myself that question is leading nowhere. I do not feel like you (or anyone) is wasting my time, but I do no understand your attitude towards me, given the fact that the additional sensor is giving us no information at all but the processor is running. As I mentioned above, let's suppose we are still at the point I firstly asked the question, with no humidity sensor, what solutions would we have? Changing pins? Done. Verifying the processor is not sleeping? Done.
Regarding the code, I have not updated it as I am mostly using Ubuntu for my college work and the Arduino IDE is on Windows, not a pleasure for me to interrupt everything and switch OS.
Please do not understand me wrong, I am new to the forum and I appreciate every and single reply of anyone that wants to help, but I don't like being treated like I had bad intentions.
temperatura_v2.ino (1.27 KB)