Photon examples not up-to-date - read photo sensor


#1

The beginners examples https://docs.particle.io/tutorials/hardware-projects/hardware-examples/photon/ for the Photon don’t correspond to the photon kit circuit template I received. I’d like to find descriptions and examples for the actual kit I received for accurate explanations.

Attached is a photo of my Photon protoboard. The blinking LED side I’m okay with, even though different pins are used than in the online examples. But the photo sensor side seems too different from the example. It looks like pin A5 is used as the voltage source but the spec manual says A5 is one of the ADCs, which seems odd. Maybe it floats a voltage and works but it seems unconventional. Also, my kit has a phototransistor instead of photoresistor so the diagram is not helpful in orienting the leads, although I think I found the information somewhere else. Resistor values are different from the online examples too (actually, words are correct, schematic different).

If there are online examples that correspond to these kits that are being sent out I’d like to get a link to it so I can better program this kit. I can’t understand why the “getting started” examples are so far off, seems like a bad place to cause confusion.


#2

That’s no contradiction since A# pins can used just like any other GPIO pin for digital purposes too.
The ADC will only be attached when needed in an analogRead() call - that’s not unconventional.

But for the photo transistor vs. resistor problem, have you noticed the radio button in the hardware-examples?


When you select Transistor the text and images will change accordingly.

But sure enought, when the actual components don’t even fit the cardboard schematics coming in the same box. Maybe @bsatrom can comment on that.


#3

Thanks for flagging this, @ScruffR, and for the original comment @sb4. I agree that we could better align the hardware examples for our docs to match the out-of-box product. We’ve done this pretty effectively for the latest generation of hardware, but the same should be true for the Photon. I’ve filed an issue in our docs repo, and you can track the discussion here: https://github.com/particle-iot/docs/issues/1032


#4

The issue with pin A5 (ADC) for a voltage source is: where is that documented? How do you set the pin up? The example code doesn’t do it because the example is based on using 3V3 for the V+.

I would like to know more about using pin A5 as V+. Why was that chosen, given it is hard to understand, especially for newcomers.

I did eventually compare the Transistor vs. Resistor circuits - They are virtually the same although the transistor schematic shows a 10K resistor (the text says 220 ohm, another discrepancy) – but again, both examples use 3V3 pin for V+, not A5. The good thing is that A0 is consistent everywhere as the sensor read pin, so the code should work whether you know why or not.:slightly_smiling_face:


#5

If you look here
You’ll find this secion

Granted, that refers to the LED pin (D6) but as said above, A# pins behave exactly the same way (they just feature some extra capabilities ontop). So this would work for A5 as voltage source for the photo resistor too

const int vccPhotoTransistor = A5;
...
  pinMode(vccPhotoTransistor, OUTPUT);
  digitalWrite(vccPhotoTransistor, HIGH);

#6

Thanks for that info on A5 pin. I’m trying to find a functional description of “GPIO” to know what capabilities that includes and how to set them up. The Photon datasheet refers to GPIO but doesn’t state what that really means.

update I did find this in an ARM Cortex M3 manual, which helps explain a little more:

Each port bit of GPIOs can be individually configured by software
in several modes:
Input floating
Input pull-up
Input-pull-down
Analog
Output open-drain
Output push-pull
Alternate function push-pull
Alternate function open-drain

I’m not sure which one I’d pick for a voltage source – one of the Output modes I’d guess. Not sure what the code “pinMode(…, OUTPUT)” chooses for the mode.

I located the pinMode() doc, which at least states that “digitalWrite(HIGH)” will put 3.3 volts on the pin and I assume as a reasonably low impedance source so as to be useful.

Anyway, it seems that the example code might not work for the photosensor, because there is no initialization of the A5 pin. Perhaps by luck it is initialed to the correct mode and state. Otherwise, I can put in the code you suggest, much appreciated, or run a wire to 3V3.

Thanks,

-SB

P.S. I misspoke earlier about a schematic fix, the schematic for the phototransistor example still shows a 10K resistor.


#7

GPIO is a common term with microcontrollers and means General Purpose Input/Output.

OUTPUT is Output push-pull

How that? The code I provided above initialises the mode and level of the pin.
That was meant as a hint what needs adapting on the original sampe to have it work on A5.


#8

I’m with you ScruffR – your code solves the problem. I was just pointing out again the need to update the examples to match the kits being sent out. For fun, I confirmed the existing code doesn’t work on a Photon without your initialization. A lot of beginners might wonder what they did wrong and give up. Thanks again for the help. :grinning::+1: