2

I am total noob. I read that the pins 14 and 15 are input and output for UART. But what does it actually mean? Is it a purely data pin? If its a data pin does it not go high and low? If so how is it different from 18 which is the PCM output. I used that pin to turn an LED on (my first ever project). Can I use the code with pin 14 instead? Can someone explain me the conceptual difference please?

4

All of the GPIO pins can be configured for different purposes. At their simplest they can all act as general purpose input/output (hence the name). This means they can be set to act as an outputs, thus the pin can be driven LOW (0v) or HIGH (3.3v). It can also be configured as an input where an external circuit drives the pin LOW or HIGH and the pi can read this state.

Some of the GPIO pins also have a specific alternative function. These alternative functions are tied to special hardware in the cpu which is why only some pins have alternate functions. Typical alternative functions are UART (generally also called serial, but there are other types if serial communication), SPI, I2C and PWM.

UART is a bidirectional serial protocol, but can be used in a unidirectional way. It requires 1 pin for input (aka rx) and 1 pin for output (aka tx). This is why there are two pins labeled as UART.

Pin 18 on the raspberry pi is a PWM pin (I think you meant this rather than PCM?). PWM is another protocol that can be used to send simple data, it does this by rapidly switch the pin from HIGH to LOW very precisely and rapidly. The data is encoded in the width of the pulses, this is often used to tell servos which position to move to or motor controllers how fast to move. It is sometimes used to fake a voltage change such as in dimming LED. Due to the precise timing it need special hardware which is why only some pins have this function.

All pins can emulate the special hardware functions behind the special pins by toggling the pins on/off in the way the protocol describe. But doing so is often slower or results in more errors due to missed timings. This is especially hard under linux on the pi as it is not a real time OS so has no timing guarantees at all.

4

All GPIO pins can be either Input or Output, and many can have alternate functions. See Pinout for details of alternatives.

Depending on the Pi model, Pins 8/10 (BCM 14/15) are usually configured as UART. All GPIO pins are Input when first booted, except for the UART (the Pi3 also has these as input). This can be modified by Device Tree - set in /boot/config.txt.

Pins 3/5 have on-board pullup to 3.3V (to facilitate I²C) so, even though Input are not practically usable as inputs.

If you have Raspbian gpio readall should show the current state of all pins. (NOTE this is missing from some Raspbian, and can be deleted by updates, but can be installed with sudo apt-get install wiringpi if missing.)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.