Notifications
Clear all

Dancing Tinkerbell for a pirate magician

82 Posts
6 Users
9 Likes
2,652 Views
Will
 Will
(@will)
Member
Joined: 3 years ago
Posts: 2533
 

@eliza 

If you're worried about a direct connection, how about using an opto-isolator ?

Anything seems possible when you don't know what you're talking about.


   
ReplyQuote
(@eliza)
Member
Joined: 2 years ago
Posts: 81
Topic starter  

@will I'm not worried about anything. I can't detect the signal, or perhaps the attachInterrupt (digitalPinToInterrupt(SHOWCARDPIN),ISR1,FALLING); statement needs to be changed. I tried FALLING and RISING. I believer this is a pin change interrupt ?? I believe that the output from the Nano should look, to the Mega, exactly the same as a button press, thus working button press code should work just like I took out a red button and replace it with a green button.

What is an opto-isolator and how would that work?

(PS, thanks for the unbelievably speedy reply)


   
ReplyQuote
Will
 Will
(@will)
Member
Joined: 3 years ago
Posts: 2533
 

@eliza 

I don't think you need another interrupt, surely one pass through the loop should be short enough to check the pin directly.

What an opto-isolator does is make sure that the power circuits on each side of the device stay separate, so you can have a 5V side and a 12V side. One side has an LED and, when powered, lights the LED which then triggers the other side to conduct. That way, the two circuits don't need a common ground.

Anything seems possible when you don't know what you're talking about.


   
ReplyQuote
(@eliza)
Member
Joined: 2 years ago
Posts: 81
Topic starter  

@will I looked up opto-isolator. This doesn't help. I'd still want the Mega to see the signal from the opto-isolator, as if it were a button push, and then generate the interrupt.


   
ReplyQuote
Ron
 Ron
(@zander)
Father of a miniature Wookie
Joined: 3 years ago
Posts: 6989
 

@eliza Is NANO 3.3V and MEGA 5V? If so the NANO HIGH will not trigger a MEGA HIGH, use a level shifter in between. I would use a diode to guarantee one way flow, the resistor isn't really needed.

First computer 1959. Retired from my own computer company 2004.
Hardware - Expert in 1401, and 360, fairly knowledge in PC plus numerous MPU's and MCU's
Major Languages - Machine language, 360 Macro Assembler, Intel Assembler, PL/I and PL1, Pascal, Basic, C plus numerous job control and scripting languages.
Sure you can learn to be a programmer, it will take the same amount of time for me to learn to be a Doctor.


   
ReplyQuote
Will
 Will
(@will)
Member
Joined: 3 years ago
Posts: 2533
 

@eliza 

Then why use an interrupt ? I warned you back on page 1 that ASK used an interrupt and suggested that you look for problems with that.

Just treat it as a button push WITHOUT using an interrupt. if you use (the same) 5V supply and a common ground, then just connect the pins directly and read the pin value directly with digitalRead instead of an interrupt.

Anything seems possible when you don't know what you're talking about.


   
ReplyQuote
(@eliza)
Member
Joined: 2 years ago
Posts: 81
Topic starter  

@will It is not the case that one pass through the loop is sufficient. I worked on this for many weeks. The "Make Tink Dance" routine can run up to 10 seconds and the user cannot possibly press the button at the exact moment when the loop would be reading the buttons from the main loop. The interrupt is necessary, and it works. The problem I am trying to solve is to simulate the (already working) button press, that will generate the (already working, necessary) hardware interrupt. I can generate the pulse on the Nano, when and where I want it. Then I put that voltage on the Mega pin, and I would expect it be be "just like" a button press. I know that the Nano pin goes HIGH as I can attach it to a LED and see it light up. The pin is HIGH for any length of time I choose. I made it a half second so as to be like a person pushing a button.


   
ReplyQuote
Will
 Will
(@will)
Member
Joined: 3 years ago
Posts: 2533
 

@eliza 

So you're saying that the NANO has to keep the pin set until the MEGA "catches up" and tells it that it's received the signal ?

Anything seems possible when you don't know what you're talking about.


   
ReplyQuote
(@eliza)
Member
Joined: 2 years ago
Posts: 81
Topic starter  

@will The interrupt is a hardware interrupt that does not fail with either the FastLED library, nor the ASK library. Why use the interrupt? Because I am running a function in the main loop and I want to detect button presses while the loop is running. Thus, I wrote hardware interrupt routines and bound them to pins and wired the buttons to the pins. So now, in my working program, the buttons generate the interrupts, and the state variable is defined, and when I reenter the loop, I can see that "someone pushed a button some time ago, and that set a new state, so do something differently this time through the loop."  This is a working design, and I have tested it, and it works, so there is no reason to doubt the wisdom of using an interrupt, because it works exactly as intended.

There is also no reason to discuss these (hardware) interrupts conflicting with the FastLED timer interrupt problem, because that problem is not occurring. My hardware interrupt button catches work perfectly well.

The FastLED.show() function breaks timer interrupts. Therefore, if the call to check the radio (timer driven)  is done on the machine that is using the FastLED library, it breaks. (FastLED + timer driven radio, Bad. FastLED + hardware interrupts, OK.)

So, I moved the radio read to a separate machine, and by golly, it works, because this machine, (a separate Nano) isn't using FastLED. Now, the problem I am trying to solve is:

How to simulate a button press on the Mega by putting a voltage on a pin that is coming from the Nano, to the Mega? I can get the HIGH on the output pin on the Nano, and it therefore is presumably going to the input pin on the Mega. (Just like a button press.) Why doesn't the Mega detect that voltage? 


   
ReplyQuote
Will
 Will
(@will)
Member
Joined: 3 years ago
Posts: 2533
 
Posted by: @eliza

How to simulate a button press on the Mega by putting a voltage on a pin that is coming from the Nano, to the Mega? I can get the HIGH on the output pin on the Nano, and it therefore is presumably going to the input pin on the Mega. (Just like a button press.) Why doesn't the Mega detect that voltage? 

That sounds like it should work. If they have a common ground and the NANO is 5V and its (OUTPUT) pin is connected directly to the MEGA (INPUT) pin (maybe with a diode as @zander suggested for safety) then the MEGA should see it as HIGH.

Anything seems possible when you don't know what you're talking about.


   
ReplyQuote
(@eliza)
Member
Joined: 2 years ago
Posts: 81
Topic starter  

@will No, I am not saying that the Nano has to keep the pin set until the Mega "catches up" I could keep the pin on the Nano high for as long or short as I want. I could keep it high for an hour or 1 milli. I'm just arbitrarily keeping it hot for 1/2 second, because a human button press could take about that long.

I already have a perfectly working system on the Mega, that catches any button press, of any duration, at any time. When that button is pressed, the voltage on the pin creates a hardware interrupt. (which is just what I want, and it works.)

What I want to do is create a "looks like someone pressed a button, but it is actually a voltage that came from another arduino" simulation of a button press. If I can get the Mega to see that the pin went HIGH, or detect the change from HIGH to LOW, or detect the change from LOW to HIGH, (which is what I think FALLING actually does) then I'm in business.


   
ReplyQuote
(@eliza)
Member
Joined: 2 years ago
Posts: 81
Topic starter  

@zander Thanks Zander! This might be it. I'll have a look at the Nano specs. I will also try with an Uno. (I think I already tried an Uno but can't remember.)


   
ReplyQuote
Will
 Will
(@will)
Member
Joined: 3 years ago
Posts: 2533
 
Posted by: @eliza

What I want to do is create a "looks like someone pressed a button, but it is actually a voltage that came from another arduino" simulation of a button press. If I can get the Mega to see that the pin went HIGH, or detect the change from HIGH to LOW, or detect the change from LOW to HIGH, (which is what I think FALLING actually does) then I'm in business.

Perhaps you should attach a pull down 10K resistor from the MEGA pin to GND on the mega to force it low so that the 5V signal from the NANO will force it to recognize a RISING edge.

Anything seems possible when you don't know what you're talking about.


   
Ron reacted
ReplyQuote
robotBuilder
(@robotbuilder)
Member
Joined: 5 years ago
Posts: 2043
 

@eliza 

I presume that the digital input doesn't need current, it needs voltage.

Although you can have a static voltage you can't have a change in voltage (going HIGH or LOW) without a current (flowing electrons). So you can for example store a charge of electrons in a capacitor but to fill or empty that store there will be a flow of electrons (current) to achieve it.

Voltage is a unit of measure of electrical pressure (like measuring your tyre pressure) while Ampere is a unit of measure of how many electron charges are flowing past (like gallons per minute). 

It will take some time to digest your other posts.

I only have a Mega and Arduinos so if it is an issue with the Nano I will not be able to test it.

 


   
ReplyQuote
Ron
 Ron
(@zander)
Father of a miniature Wookie
Joined: 3 years ago
Posts: 6989
 

@eliza @will There is some combination of INPUT_PULLUP or pullup/pulldown resistor that will work with the NANO but I have one of those gut feels that the NANO ground and MEGA ground will have to be connected. You are on the right track, but only one combination will work. Another hair on the back of my head thought, what about interrupts and what port they are on having an effect. I think @will solved one similar to that.

First computer 1959. Retired from my own computer company 2004.
Hardware - Expert in 1401, and 360, fairly knowledge in PC plus numerous MPU's and MCU's
Major Languages - Machine language, 360 Macro Assembler, Intel Assembler, PL/I and PL1, Pascal, Basic, C plus numerous job control and scripting languages.
Sure you can learn to be a programmer, it will take the same amount of time for me to learn to be a Doctor.


   
ReplyQuote
Page 5 / 6