Analog I/O

analogRead(pin)

Example:

function setup() {
  pinMode(A33, INPUT);
}

function readNTC(pin) {
  let ntcNominalT = 25; // Nominal temperature
  let ntcNominalR = 10e3; // Resistance at 25°C
  let ntcBCoeff = 3950; // usually 3000-4000
  let seriesResistor = 10e3; // The other resistor

  // Analog reference is not the same as system voltage
  let vSys = 3.3;
  let vIn = analogRead(pin);

  // Compute NTC resistance connected with series resistor
  let R = (vIn * seriesResistor) / (vSys - vIn);

  // Compute temperature using Steinhart-Hart equation
  let steinhart =
    log(R / ntcNominalR) / ntcBCoeff + 1.0 / (ntcNominalT + 273.15);
  return 1.0 / steinhart - 273.15;
}

function loop() {
  print("temp=", readNTC(A33));
}

Reads an analog voltage of the given pin and returns the read value in millivolts.

Not all pins are capable of reporting analog values. The possible values for pin are:

Pin Alias Description
33 A33 ADC1_CH5 / GPIO33
36 A36 ADC1_CH0 / GPIO36