output signal

Hello
I am outputing in 2 pins: pin_9 and pin_8, when pin_12 is set to HIGH.

When I output in pin_9 only, signal behaves well (image_1 attached)
but when I try to output in pin_8 after pin_9, the signal doesn't come neat (seems like it comes with noise) (image_2 attached)

The upper windows in the images is the signal that activates the arduino in pin_12
the bottom window is the output in pin_9.
I am sensing only the pin_9, so I think I should see the signal as in image_1
and after when I change the sensor to pin_8, I should see a similar signal but 1 microsecond delayed.

Do you know why it happens? why the signal is like that (in image_2) when I try to output in one pin after another?

Note also that the "void loop" runs only once because I stop sensing the signal after 5 milliseconds.

If the code helps:

int trigger = 12;
int pin_number=9;
int time_delay=1; // delay in microseconds

void setup(){

pinMode(9, OUTPUT);
pinMode(8, OUTPUT);
}

void loop(){

if(digitalRead(trigger) == HIGH)
{

activate(pin_number); //activate pin_9
pin_number=8;
activate(pin_number); //activate pin_8

delayMicroseconds(5000); // to clear the signal
}
}

// function to activate the pin
void activate(int x){
digitalWrite(x, HIGH); //set pin_number to HIGH
delayMicroseconds(time_delay);
digitalWrite(x, LOW); //set pin_number to LOW
}

pin_number is a global that starts at 9. On the first pass through loop, it decrements to 8. On the next pass, it decrements to 7. On the next pass, it decrements to 6. Why?

No man :slight_smile:
as I said, I'm running the loop only once
I delay for 5 milliseconds, and then I stop the program setting off the external signal to pin_12

so what happens is the pin_9 going high and low, pin_8 going high and low, and then finish

thanks for answer

No, you're not explaining yourself very well.
A schematic maybe?

After 5 ms you are not writing the low value because that is in the else. If the HIGH signal in pin 12 persists more than 5 ms then you will be using bad pin numbers as they have decremented.

as I said, I'm running the loop only once

How are you limiting loop() to running only once? I see nothing that makes that happen.

ok I modified the code, but still does the same thing
that else has no interefence with the images I posted

what I do is:
set pin_9 to HIGH for 1microseconds, then set it to LOW
set pin_8 HIGH for 1 microsecond, then set it to LOW
delay for 5 milliseconds
because I record the signal for only 5 milliseconds, then if I put that delay, the program ends running after finishing the loop
so there is only 1 loop, it is not necessary to be in the code, because I control the trigger from outside
and even if I am wrong and the loop keeps going, it doesn't matter because I record only for 5 milliseconds, so what comes after has no influence

thank you

hey guys, I tried now just initialize the pin_8
without activate it, like:

activate(pin_numer);
pin_numer=8;
delayMicroseconds(5000);
...etc

and the result is the same as in the image_2
so I think it has something to do with the initialization pin_number=8;

any clue ? why is arduino behaving like that? (I already tried another arduino, the result is the same)

That's call crosstalk.

Are you on a breadboard?

not in a breadboard, but I tried after in a breadboard and it happens the same

ok I modified the code, but still does the same thing

So post the modified code. At this stage we have no idea about what errors there are still in it.

is already modified, above, in the first post
thank you

I guess I figured it out, I removed the initialization "pin_number=8;"
and just put "activate( 8 );" after the "activate(pin_numer)" (that is after the activation of pin_9)

image_3 attached
1st window is the signal that triggers into the pin_12
2nd is the signal sensed in pin_9
3rd is the signal sensed in pin_8

the result came better, but still weird:
why does the pin_8 outputing near 5V and in the pin_9 near (below) 4V ?
why when I put a pin going LOW, it does not go to 0V immediately, but goes first through -3V or -4V ??

thanks for help

What is connected to those pins?

wires/cables that connect to a NI for signal actuation/sensing

NI?

another question:
do you thing using the analog outputs would solve that problem of the distortions ?

thanks

yes, is a machine for actuation/sensing, doesn't matter

do you thing using the analog outputs would solve that problem of the distortions ?

No.
Analogue outputs are actually PWM outputs.