ESP32-C3 OLED/The screw terminal base/15. A first build on the screw terminal base
The screw terminal base · 15 of 17

A first build on the screw terminal base

A potentiometer needs three wires, and all three are on the right block: 3V, GND, and a signal terminal between them. Wire it to GPIO 1 and read it, and you have tested the screws, the supply and one analog pin.

Three wires on one block

A potentiometer is a track with a contact that slides along it. The two ends of the track go to the supply and to ground, and the sliding contact, the wiper, is at some fraction of the supply between them. Read that fraction on an analog pin and the knob becomes a number.

On this base the three terminals are on the right block: 3V, GND, and between them a signal terminal. GPIO 1 is the terminal printed 1, second from the top, and it is one of the pins with an ADC behind it. Nothing on the board uses GPIO 1.

Three wires on the right block
analogRead(1) ≈ 2048
Knob position50 %
Wiper voltage
1.65 V
analogRead(1), about
2048
The wiper is 50 % of the way up the track, so the pin sees 50 % of 3.3 V. The reading follows the knob, roughly in a line. The line is a picture of the idea: a real reading bends near both ends and wanders by a few counts.

The wire from 3V goes to one end of the track, the wire from GND to the other, and the wiper goes to 1. Which end is which only decides which way the knob counts: swap the two ends and the reading falls as you turn it up.

Put the wires in properly

For each wire, back the screw out until you can see the clamp open, put bare copper under it with no insulation inside the clamp, tighten until the wire will not move, and tug it. Do all three before power goes on, and look along the block for a strand that has strayed towards the next terminal. 3V, GND and 5V sit side by side on this block, and a strand between them is a short across the supply.

Seat the board before the cable goes in. Seating it is a one-label check, and the sketch below is the same whichever way round you get it.

Upload and read

Choose ESP32C3 Dev Module, set USB CDC On Boot to Enabled, and upload. Open the Serial Monitor at 115200. With the knob at one end the number is near 0, at the other near 4095, and it follows the knob between.

The number is a count, not a voltage. Roughly, it is the fraction of the supply times 4095, and a real reading bends near both ends and moves by a few counts with the radio idle. To turn it into volts, the calibrated reading is a later article's job.

The code

screw_pot.ino

Reads a potentiometer wired to the terminal printed 1 and prints the number twice a second. Turn the knob and the number follows it.

/*  Lonely Binary ESP32-C3 OLED screw terminal base
    Read a potentiometer on GPIO 1.

    Wiring, all on the right-hand block:
      pot end A   -> terminal 3V
      pot wiper   -> terminal 1   (GPIO 1)
      pot end B   -> terminal GND

    Arduino IDE, Tools menu:
      Board:            ESP32C3 Dev Module
      USB CDC On Boot:  Enabled
      Flash Size:       4MB (32Mb)
    No library needed.                                   */

const int POT = 1;

void setup() {
  Serial.begin(115200);
  delay(1500);              // let the USB port enrol
  Serial.println("Potentiometer on GPIO 1");
}

void loop() {
  int raw = analogRead(POT);
  Serial.printf("raw %4d\n", raw);
  delay(500);
}

GPIO 1 is one of the five pins with an ADC behind them, and the right block has it next to the supply. analogRead returns 0 to 4095 on this chip by default, so the printed number is a 12-bit reading. The pin is only read, never driven.

When it does not work

The reading never moves

The wiper wire is in the wrong terminal, or in the right one with the screw closed on its insulation. Check that the wire goes under the terminal printed 1, that bare copper is in the clamp, and that it does not move when tugged. A pin with nothing on it floats and drifts, so a reading that wanders but does not follow the knob means the wiper is not connected.

The reading sticks at 0 or at 4095

One end of the track is in the wrong terminal, or both ends are in the same one. With 3V and GND each at their own end, turning the knob sweeps the reading between the extremes. If it sits at the top, the wiper is on 3V; if at 0, it is on GND.

The Serial Monitor shows nothing

USB CDC On Boot is set to Disabled, which is the usual cause on this board. Set it to Enabled, upload again, and reopen the monitor at 115200. The sketch runs and prints into nothing otherwise.

The board resets when the knob is at one end

A wire has slipped between 3V and GND, or the two ends of the track are on the wrong two terminals so the track is across the supply with the wiper bridging them. Take power off, check the three terminals against the figure, and check no strand of one wire reaches the next terminal.

A second module on the left block has no ground

The left block has no power on it. Take its supply and ground from the 3V and GND terminals on the right block, by a wire each across the board, or through a small breadboard.

Where this goes next

A battery you can read the level of, using the divider and the jumper on this same base.

Battery level, on the screen →

Edit this page — content/books/c3oled/screw-first-build.mdx

Community

Questions about this product

See what other owners have asked, and read their solutions.

This page covers several products. Choose yours to see the right discussions.

Discuss this article

Ask about this page. The answer stays here, on the page it belongs to, for whoever hits the same wall next.

Browse Modules and blocks on the forum →