Go Down

Topic: More PWM pins (Read 378 times) previous topic - next topic

Langoni

Dear all,

I am trying to mount an AS3935 lightning sensor on an arduino MEGA board following the code described in GitHub:

https://github.com/PlayingWithFusion/PWFusion_AS3935_I2C/blob/master/Examples/as3935_lightning_i2c_nocal/as3935_lightning_i2c_nocal.ino

However I already have some sensors installed that occupy all the PWM inputs so that I can not use pins 2 and 9 as required by the scheme proposed in GitHub. I wonder if I can use communication pins or analog pins available on the board or if there is any way to multiplex the PWM pins.

Thanks for any help...

Cesar

Paul__B

Sorry, there are no such thing as "PWM inputs".  Please have another go at explaining your problem.

You need to enumerate all the sensors and output devices you wish to attach to your Mega.

Langoni

Sorry, let me try simplify;
If I have no more PWM pins available, can I use others pins like communications pins for example. This will work?

Thanks,

Cesar

pert

Neither of these pins require PWM functionality. It's only by chance that they happened to both be PWM pins on your Mega.

You can use any pin you like instead of pin 9. Just be sure to update this line of the sketch accordingly:
Code: [Select]
#define SI_PIN               9
The attachInterrupt() documentation lists the pins you can use instead of pin 2: 2, 3, 18, 19, 20, 21.

Unfortunately, the sketch was poorly written so you will need to update two lines of code according to the pin you chose:
Code: [Select]
#define IRQ_PIN              2        // digital pins 2 and 3 are available for interrupt capability
Note that the comment assumes you're using an Uno (or other ATmega328P-based Arduino), the Mega allows you to use the other pins I listed as well.

and you need to change line 118 from:
Code: [Select]
  attachInterrupt(0, AS3935_ISR, RISING);
to:
Code: [Select]
  attachInterrupt(digitalPinToInterrupt(IRQ_PIN), AS3935_ISR, RISING);

Langoni

At first thank you for the explanation.

If I understood correctly, the matter here is not the PWM functionality, but the interrupt capability. So, for this situation I can use any pin instead pin 9. However for pin 2, I need to take one of the list: 3,18,19,20,21
It occurs that, I have only 18 and 19 available which in principle will work to replace pin 2. However, I am using another sensor that occupies one of the Tx and Rx pairs, with Serial1.Begin();. My concern is that using Serial1.Begin(); may disturbe  interrupt capable of pins 18 and 19. Is this reasoning correct or not?

I really appreciate your help.

Thank you,

Cesar

pert

If I understood correctly, the matter here is not the PWM functionality, but the interrupt capability.
For the IRQ_PIN, yes. For the SI_PIN, you don't need PWM or interrupt capability. Any pin will work.

I am using another sensor that occupies one of the Tx and Rx pairs, with Serial1.Begin();. My concern is that using Serial1.Begin(); may disturbe  interrupt capable of pins 18 and 19. Is this reasoning correct or not?
I don't know the answer to that question (maybe someone else will), but I would certainly try to avoid using pin 18 when Serial1 was in use, even if I only needed pin 19 for incoming communication from the sensor. There are two more hardware serial ports on the Mega (Serial2, Serial3). Can you use one of those instead of Serial1?

Wawa

However, I am using another sensor that occupies one of the Tx and Rx pairs, with Serial1.Begin();. My concern is that using Serial1.Begin(); may disturbe  interrupt capable of pins 18 and 19.
A Mega has three spare serial pairs.
Just move that other device to pin 16/17.
And change

Serial1.Begin();
to
Serial2.Begin();

Leo..

Langoni

Thank you all for the coolaboration.
It's working correctly

Cesar

pert

You're welcome. I'm glad to hear it's working now. Enjoy!
Per

Go Up