Go Down

Topic: Serial.print error (Read 917 times) previous topic - next topic

thierry_b

I have the same idea, so I put "Serial.print" before "digital.Write" but it didn't change anything

AWOL

Quote
I put "Serial.print" before "digital.Write"

But did you put a flush after the print?
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

billroy

Putting Serial.write first won't matter -- because the output you send to Serial.write is buffered.  When you Serial.write, it buffers your output (presuming there's room) and starts up an interrupt-driven activity to print your output from the buffer, then returns to you immediately.  

So the hypothess is that your relay is firing during the printing, in the error case, causing the glitch.  The fact that it's just a few characters (=milliseconds) into the string is the giveaway.

You could use Serial.flush() to force all the characters to be transmitted before you turn the relay on, but the glitch is telling you your power suppy is not adequate or not adequately decoupled, and you should fix it properly or you will just be facing it in another form shortly down the road.

This is probably a good time to ask if you have the relay connected directly to the Arduino output pin, which is not usually a good idea because relays use too much power and cause glitches like this or worse (like frying your board).  

-br





thierry_b

Thank you for help.
It's a mini-kit relais. Pin 31 command the relais.
But relais seems to pose problems.
Another one :
2 temperature sensors are connected : BMP085 (BOSH) and DS18B20 (DALLAS)
Dallas sensor is plug into Pin 02 (Arduino Mega)
If this command is excecuted (float temperatureExt = sensors.getTempCByIndex(0);) Pin 31 becomes HIGH
It is very dissapointing.
I search what's wrong in my code..  Just 3 days I use arduino language :-)
Code for Dallas sensor comes directly from manufacturer.

Regards,

Thierry

billroy

If you have 31 pins, you must have a Mega.  The library may need adjustment for use on Mega - look in the library files for documentation, or search the forum here.

-br

Go Up