Reading A0-A5 with analogRead() (0-1023) and PWM with analogWrite() (0-255), with their settings. More...
Functions | |
| analogReadResolution (bits) | |
| Sets the number of bits analogRead() returns. | |
| analogRead (pin) | |
| Reads an analogue pin. | |
| analogWriteResolution (bits) | |
| Sets the range analogWrite() takes. | |
| analogWriteFreq (hz) | |
| Sets the PWM frequency for analogWrite() on pins set up after this. | |
| analogWrite (pin, value) | |
| Puts a PWM signal on a pin: a fraction of the time high. | |
Variables | |
| str | A0 = "A0" |
| Analogue pin A0 (RP2040 ADC, 0-3.3 V). | |
| str | A1 = "A1" |
| Analogue pin A1 (RP2040 ADC, 0-3.3 V). | |
| str | A2 = "A2" |
| Analogue pin A2 (RP2040 ADC, 0-3.3 V). | |
| str | A3 = "A3" |
| Analogue pin A3 (MAX11635, 0-2.048 V). | |
| str | A4 = "A4" |
| Analogue pin A4 (MAX11635, 0-2.048 V). | |
| str | A5 = "A5" |
| Analogue pin A5 (MAX11635, 0-2.048 V). | |
Reading A0-A5 with analogRead() (0-1023) and PWM with analogWrite() (0-255), with their settings.
| analogReadResolution | ( | bits | ) |
Sets the number of bits analogRead() returns.
Below 12 bits, analogRead() drops the lowest bits of the reading; above 12 it adds zero bits, which widens the range but adds no detail.
| bits | 1-16. 10 (0-1023) at start-up; 12 (0-4095) is the ADCs' own resolution. |
| ValueError | bits is outside 1-16. |
| analogRead | ( | pin | ) |
Reads an analogue pin.
At 10 bits each step is 3.2 mV on A0-A2 and 2 mV on A3-A5, so the two groups give different numbers for the same voltage. Keep A3-A5 at or below 2.048 V. Averaging is set with analog_averaging() in phyduino.py.
| pin | A0-A5, or 0-5 for A0-A5. |
| ValueError | Not an analogue pin. |
| OSError | The external ADC did not respond (A3-A5). |
| analogWriteResolution | ( | bits | ) |
Sets the range analogWrite() takes.
For example 10 takes 0-1023, and 16 takes 0-65535.
| bits | 1-16. 8 (0-255) at start-up. |
| ValueError | bits is outside 1-16. |
| analogWriteFreq | ( | hz | ) |
Sets the PWM frequency for analogWrite() on pins set up after this.
Pins already on PWM keep their frequency. Pins next to each other on a PWM slice share one frequency (see pwm() in phyduino.py), so setting up one can change its neighbour's.
| hz | Frequency in Hz, 8 Hz and up. 1000 at start-up. |
| analogWrite | ( | pin, | |
| value ) |
Puts a PWM signal on a pin: a fraction of the time high.
Pairs of pins share a PWM output; see pwm() in phyduino.py. The signal runs at analogWriteFreq() (1000 Hz at start-up) and keeps going while your code runs, until another analogWrite(), digitalWrite() or pinMode() on the pin. A meter on the pin reads the average: 128 gives about 1.65 V.
| pin | Pin number (3 is D3) or name ("D3", "A0", LED_BUILTIN). |
| value | 0 (always low) to 255 (always high) at the default 8 bits; values outside the range are clamped. |
| ValueError | Unknown pin, an analogue-only pin (A3-A5), or the pin shares its PWM output with one already in use. |
| str A3 = "A3" |
Analogue pin A3 (MAX11635, 0-2.048 V).
Analogue only.
| str A4 = "A4" |
Analogue pin A4 (MAX11635, 0-2.048 V).
Analogue only.
| str A5 = "A5" |
Analogue pin A5 (MAX11635, 0-2.048 V).
Analogue only.