0

With a very simple connection of an LED (which can withstand 5V) to ground and to a pin on my Galileo gen2, I can never output a non-zero voltage from the pin via analogWrite, regardless of whether the pin is digital or analog (although PWM digital works)

The LED is in the correct bias and I'm calling pinMode(pin, OUTPUT) before attempting to call analogWrite(pin, 255) (or any 2nd parameter in-between), even though it's not even necessary.
The LED glows if I call digitalWrite(pin, HIGH) on both analog and digital pins, but does not glow at all for analogWrite(pin, 255) with the same configuration and pins, nor does it for any 2nd param in [0, 255]. This holds for whether the call is attempted in loop() or setup().

The only possible way I can get the LED to receive any power from analogWrite is through a digital PWM pin, but I know the other digital pins can still produce square-waves with timers and the analog pins should certainly be able to use PWM.

(So far, I've been to scared of short-circuits to connect the analogWrite output straight into an analog input to read the voltage)

Is there something I don't understand about the underlying board, or am I experiencing some strange malfunction?

Thanks,
Tyson

Anti Earth
  • 145
  • 1
  • 2
  • 12

3 Answers3

1

On most boards, the standard implementation of Arduino's analogWrite() will only ever produce PWM, and only on a specific set of (digital) pins. These are usually pins 3, 5, 6, 9, 10, and 11, although it's slightly different on some boards.

The only official board which has 'true' analog output is the Due (pins DAC0 and DAC1).

If you want any other behaviour (such as outputting PWM on non-standard pins), you'll either need to modify the Arduino implementation, or directly manipulate the microcontroller's special registers. Note though that modifying the chip's configuration could cause other standard Arduino functions not to work as expected.

Peter Bloomfield
  • 10,982
  • 9
  • 48
  • 87
0

I am not sure where you are getting your LEDs but the ones I purchase do not survive 5 volts. You need to put a resistor in series with then, something in the 220 to 510 ohm range. When you get some resistors test your LEDs you may have damaged them as well. A good indication of this if there color if obviously off and or dim. If the timers are set up correctly the digitalwrite will set the PWM value, somewhere from 8 to 16 bits depending on the Arduino and timer used. This PWM output will appear to control the brightness of the LED. It does this by simply turning it on and off at a speed the eyes cannot follow. the longer it is on the brighter it is. Hopefully this will help you get your arms around the circuit.

Gil
  • 1,863
  • 9
  • 17
0

I don't believe Galileo has a D/A converter, which is what it sounds like you're expecting. In the Arduino 'eco-system', analogWrite() sets a PWM duty cycle - that's kinda-sorta somewhat like an analog output, but not really. You could add external circuitry to low-pass filter the PWM and produce some sort of proportional DC but it might be a good trick get it clean enough for whatever you plan to put downstream.

JRobert
  • 15,407
  • 3
  • 24
  • 51