Trouble with digitalRead(A5) on Photon 2

previous topic name: Internal pull resistance on Argons vs Photon 2s


Hi,

I'm chasing a difference in behavoir on a project that was using Argons and migrated to Photon2s.

The board has signal conditioning for 24v and uses optocouplers which seem to not work properly on a Photon2 vs on Argon.

I wonder if the impedance of the GPIO on Photon2s has anything to do, so I wanted to check on the docs. Is this pull always there or is it active when one configures the input on PULLUP mode?

I see the Argon has pull up and pull down values. Does it mean both are active in INPUT mode or none?

And why would the Photon2 not list a pull up/down resistor value and just a pull value?

thanks!

EDIT: I'm using pinMode(A5, INPUT);

I also see this from the migration guide:

is that pull always present?

The pull value only applies if you are using INPUT_PULLUP or INPUT_PULLDOWN.

Nordic characterizes the values differently, presumably because the circuitry consists of a transistor that connects one of two resistors. However they have the same value, so they values are the same. Since they're the same Realtek just lists a single value.

2 Likes

@gusgonnet What does your circuit look like? The output of an opto-coupler needs some sort of pull-up typically, either internal in the MCU or an external resistor pull-up. The P2 value of 42kohm strikes me as a bit high for an opto-coupler, but it would likely work. The nRF value of 11-16kohm sounds more like a good range to me. That value can affect the speed at which you can detect on/off cycles in the opto-coupler, but normally you are not trying to use the opto at any kind of speed.

1 Like

Hey Brian, thanks for chipping in.
At the output of the optocoupler, on the collector, there is a 12k pullup to 3v3. This is then connected to the input A5 on the argon/photon2.
The emitter goes to GND.
I am not using the pull up/down of the Particle device.

I'll see if I can get permission to show an image of that part of the circuit here.

1 Like

That sounds like it should work great! (No need for an image--you described it perfectly.) I don't think your problem is in the pull-up or the input of Photon 2. That part is almost too simple to fail. You could test it by taking a small jumper wire from ground to A5 to simulate the opto triggering. No need to remove any components-you won't hurt it.

It could be on the LED side of the opto-coupler but that's pretty easy to check.

Another thing to check would be the power supply in general.

Another option is that this difference could have an impact:

Input high voltage 2.31v(Argon) vs 2.0v(photon2)
Input Low Voltage 1.09(Argon) vs 0.8v(photon2)

Maybe the optocoupler leaves the input at 0.9v or 1v and the argon has no trouble seeing this as LOW but the photon2 does? To be measured...

Funny fact: there is an LED controlled with an N-channel MOSFET on the collector too (collector=>gate MOSFET), and I would expect it to continue to work when I remove the particle device, but it goes off and nothing I do on the 24v input changes that. That I can't explain either.

I'm going to check the power supply as well...
Thanks!

The plot is thicking or I'm, like AI, hallucinating.

I'm running a bare minimum firmware (see below) that only reads inputs D4 and A5.

On both an Argon and Photon2, the inputs read 3v3 and 0.71v respectively on HIGH and LOW.

On the Argon both inputs read fine:

0000025025 [app] INFO: input1 D4=1, input2 A5=1
0000026026 [app] INFO: input1 D4=0, input2 A5=1
0000027027 [app] INFO: input1 D4=0, input2 A5=1
0000028028 [app] INFO: input1 D4=1, input2 A5=1
0000029029 [app] INFO: input1 D4=1, input2 A5=1
0000030030 [app] INFO: input1 D4=1, input2 A5=0
0000031031 [app] INFO: input1 D4=1, input2 A5=0
0000032032 [app] INFO: input1 D4=1, input2 A5=0
0000033033 [app] INFO: input1 D4=1, input2 A5=1

But on a Photon2, the firmware sees only input D4 changing, but NOT A5:

0000133101 [app] INFO: input1 D4=0, input2 A5=1
0000134102 [app] INFO: input1 D4=0, input2 A5=1
0000135103 [app] INFO: input1 D4=0, input2 A5=1
0000136104 [app] INFO: input1 D4=1, input2 A5=1
0000137105 [app] INFO: input1 D4=1, input2 A5=1
0000138106 [app] INFO: input1 D4=1, input2 A5=1
0000139107 [app] INFO: input1 D4=1, input2 A5=1

Note: this is not a problem about switching speeds since I am doing the on off manually with a wire.

What could be wrong here?
Thanks!


Firmware:

#include "Particle.h"
SYSTEM_MODE(AUTOMATIC);
SerialLogHandler logHandler(LOG_LEVEL_INFO);

void setup()
{
  pinMode(D4, INPUT);
  pinMode(A5, INPUT);  // trying D14 here did not make a difference
}

void loop()
{

  // read the input every second
  static unsigned long lastTime = 0;
  if (millis() - lastTime > 1000)
  {
    lastTime = millis();
    int input1 = digitalRead(D4);
    int input2 = digitalRead(A5);
    Log.info("input1 D4=%d, input2 A5=%d", input1, input2);
  }
}

1 Like

Just to be sure, you have a different board for the Argon and Photon 2, correct? The Photon 2 A5 pin is actually where the Argon A3 pin is, next to A2. The Photon 2 pin where A5 logically would be is S3 and is not an analog input.

1 Like

oh wow, how did I miss that? mystery solved - thank you folks!

I wish I had the neuralyzer from Men in Black to make you forget I've asked this... :camera_flash:

2 Likes

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.