hello guys,
i am trying to make a Serial communication between 2 arduinos
so what i need to do is this : having a push button connected to the first arduino and both arduino are connected via RX and TX
so when i click the button, a led will goes on, and if i click it again it will goes off
my problem is in the debouncing, i need to know how to make the debouncing with that ?
here are my codes so far :
yes your right i tried it, but i don't get how to send a serial command i mean here how to do it, if you see my codes which i added to the original codes, i tried to create a variable and according to that variable, i sent a char 0 or 1 and on the RX arduino, if it is a 0 turn led off and if it is 1 turn it on so how can i do it if my codes didn't work ?
firashelou:
the code works fine with one arduino not 2, untill i changed :
Despite your inability or unwillingness to properly explain the issue, I think I have an idea of what is going wrong. It sounds like you want to use the switch as a toggle. In other words, you want to press and release once, and the LED turns on. Then, another press and release and the switch turns off. I'm guessing right now, it turns the LED on when you press the switch and turns it off when you release it? This section of the code is the issue:
You're turning the LED on when it transitions from LOW to HIGH, or when the switch is pressed down.
You're turning the LED off when it transitions from HIGH to LOW, or when the switch is released.
You need to keep track of the current state of the LED. When a transition occurs (either HIGH to LOW or LOW to HIGH, not both), change the current state, and send an update. Alternatively, you can offload the "toggling" to the receiving Arduino and have the sender just send a single, uniform byte whenever the transition occurs.
Probably because you are writing to the Serial buffer faster than it can send out. Try moving the send code into the signal edge if statement. If that doesn't work, post the FULL code.
Arrch:
Probably because you are writing to the Serial buffer faster than it can send out. Try moving the send code into the signal edge if statement. If that doesn't work, post the FULL code.
about the serial buffer, for both arduino the baud rate is 9600 if that's what you mean ?
ok i did it now the TX led is flashing when i press
firashelou:
about the serial buffer, for both arduino the baud rate is 9600 if that's what you mean ?
No. loop() runs really fast. It could run hundreds of times between each Serial byte being sent. What happens when you dump 100 balls per second into a large bin while only 1 ball per second is being removed? It overflows. It you dump 500 red balls into the bin before dumping 500 green balls, you're going to be waiting nearly 7 minutes after you've dumped your green balls in before a green ball is actually removed. Now think of the red/green as '1'/'0'.
ok i did it now the TX led is flashing when i press
firashelou:
about the serial buffer, for both arduino the baud rate is 9600 if that's what you mean ?
No. loop() runs really fast. It could run hundreds of times between each Serial byte being sent. What happens when you dump 100 balls per second into a large bin while only 1 ball per second is being removed? It overflows. It you dump 500 red balls into the bin before dumping 500 green balls, you're going to be waiting nearly 7 minutes after you've dumped your green balls in before a green ball is actually removed. Now think of the red/green as '1'/'0'.
ok i did it now the TX led is flashing when i press
So the sender looks like it's working.
what's the solution then ? a delayMicroseconds(2) for example ?
You're putting in quite some time, but so far you keep on running into problems with your project.
Now you have 2 problems at the same time, gave up on one and are trying to do the same thing in an other way.
OK for me, but this looks to me like you aren't learning a lot at the moment.
You have shown to not understand the blink without delay principle yet.
Part of that can be very well used for debouncing, but of course only if you understand what's going on.
You also stated that debouncing works for one, but not for 2 Arduino's that are connected through serial (is what in read).
Are you trying to do a remote debounce ?
If so, what's the point of that ?
I'd advice you to work through some more of the examples that were delivered with the IDE.
Only after understanding those you can use them.
And if you're going to use a sketch you found somewhere but need help understanding what it does, tell about what you think it is doing instead of telling the sketch must be wrong.
As for your last problem:
If you want to upload a sketch, temporary disconnect any serial connections, because that is what is used for upload.
The other connection might work like a parasite and mess up the upload.
MAS3:
You're putting in quite some time, but so far you keep on running into problems with your project.
Now you have 2 problems at the same time, gave up on one and are trying to do the same thing in an other way.
OK for me, but this looks to me like you aren't learning a lot at the moment.
You have shown to not understand the blink without delay principle yet.
Part of that can be very well used for debouncing, but of course only if you understand what's going on.
You also stated that debouncing works for one, but not for 2 Arduino's that are connected through serial (is what in read).
Are you trying to do a remote debounce ?
If so, what's the point of that ?
I'd advice you to work through some more of the examples that were delivered with the IDE.
Only after understanding those you can use them.
And if you're going to use a sketch you found somewhere but need help understanding what it does, tell about what you think it is doing instead of telling the sketch must be wrong.
As for your last problem:
If you want to upload a sketch, temporary disconnect any serial connections, because that is what is used for upload.
The other connection might work like a parasite and mess up the upload.
ok thanks yes right i must disconnect the other one,
well i can say i learned and understood my deboucing sketch which i was working on, there was a part which i didn't get before but after this post not just solved the problem but i understood that part