Pages: [1] 2   Go Down
Author Topic: Serial.print error  (Read 668 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 13
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

New Jersey
Offline Offline
Faraday Member
**
Karma: 48
Posts: 3389
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Offline Offline
Newbie
*
Karma: 0
Posts: 13
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 236
Posts: 24266
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

"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.

0
Offline Offline
God Member
*****
Karma: 39
Posts: 986
Get Bitlash: http://bitlash.net
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 13
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 236
Posts: 24266
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
I put "Serial.print" before "digital.Write"
But did you put a flush after the print?
Logged

"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.

0
Offline Offline
God Member
*****
Karma: 39
Posts: 986
Get Bitlash: http://bitlash.net
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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




Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 13
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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)smiley-wink 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
Logged

0
Offline Offline
God Member
*****
Karma: 39
Posts: 986
Get Bitlash: http://bitlash.net
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 13
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks, I will take a look
Logged

Global Moderator
Offline Offline
Brattain Member
*****
Karma: 452
Posts: 18694
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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?

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.

Please post all your code, not just tiny snippets.

Read this before posting a programming question
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 13
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 236
Posts: 24266
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

"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.

Offline Offline
Newbie
*
Karma: 0
Posts: 13
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

thank you for time took to respond to me  :-)

Logged

Pages: [1] 2   Go Up
Jump to: