Serial.print error

Hello,
Sorry for my bad English, I'm French and new arduino user.
In my program, I have this :

void DeclenchePyro () {
Serial.println ("Relais ON");
digitalWrite( relaisPin, HIGH );
}
---> It's write to pc terminal : Re`ais ON

If I put in a char, it's ok :

char stringFin [] = "Relais ON";
void DeclenchePyro () {
Serial.println (stringFin);
digitalWrite( relaisPin, HIGH ); }
It's write correct to terminal : Relais ON

I don't know why first function doens't work ????

Thanks

Thierry

Looks fine from that snippet. Is the issue repeatable? If so, post the whole sketch.

It was repeatable.
But I changed timing to call that function (20 sec instead of 60 sec) and the error didn't occur.
So I rechanged to 60 sec and no more error.
I don't understand pfffffffffffffff

Impossible to say for sure from a snippet, but it could be a memory overflow error so where, or a simple pointer write stomping on memory it shouldn't.
Post your code.

The problem is the serial output glitch, right?

I wonder if turning on the relay is glitching the power supply and causing the serial output to take a hit.

-br

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

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

But did you put a flush after the print?

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

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):wink: Pin 31 becomes HIGH
It is very dissapointing.
I search what's wrong in my code.. Just 3 days I use arduino language :slight_smile:
Code for Dallas sensor comes directly from manufacturer.

Regards,

Thierry

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

Thanks, I will take a look

thierry_b:
It's a mini-kit relais. Pin 31 command the relais.
But relais seems to pose problems.

What relay? Post a link please. Are you using a transistor to turn it on?

thierry_b:
It is very dissapointing.
I search what's wrong in my code.. Just 3 days I use arduino language :slight_smile:
Code for Dallas sensor comes directly from manufacturer.

Please post all your code, not just tiny snippets.

Read this before posting a programming question

I found my error.

int ledRougePin[] = {0, 52}; // LEDs rouges
...
void InitialisationCapteurOK (byte numeroCapteur) {
// allumer Vert
digitalWrite( ledRougePin[numeroCapteur], HIGH );
digitalWrite( ledVertPin[numeroCapteur], LOW );
digitalWrite( ledBleuPin[numeroCapteur], HIGH );
}
....

if (temperatureExt != 0) InitialisationCapteurOK(2); // Led état passe au vert

Error was InitialisationCapteurOK(2) no permit (just 0 or 1).
This error triggered relay pin 31. I don't know why but it does.

Thanks everybody

Thierry

See reply #3.
If you don't post code, don't expect answers.

code is long, so I don't want "polluate"

thank you for time took to respond to me :slight_smile:

Pollute all you like, pollueur/payeur doesn't apply here, but if you don't post code, you waste peoples time.

Ok, it is noted for next time.

Thierry