This MSP430G2 LaunchPad GPIO tutorial teaches you how to use the input/output pins of the MSP430G2553 microcontroller that ships with the MSP430G2 LaunchPad, and how to declare them as digital inputs or digital outputs in the Energia IDE. GPIO (General Purpose Input Output) is the single most important peripheral on any microcontroller — every LED, button, sensor, relay, motor driver, LCD, and communication module you interface later in this series builds on what you learn here.
The MSP430G2553 provides two 8-bit ports — Port 1 and Port 2 — for a total of 16 GPIO pins. In this tutorial we will cover two complete examples: (1) blinking an external LED by using a GPIO pin as a digital output, and (2) reading a push button by using a GPIO pin as a digital input and using that input to control the LED. By the end, you will understand the pinMode(), digitalWrite(), and digitalRead() functions, the role of current-limiting resistors, and how pull-up resistors give a push button a clean logic level.

What You Will Learn
- How many GPIO pins the MSP430G2553 provides and how they are organized into Port 1 and Port 2
- Which pins are reserved for the external 32 kHz crystal oscillator and why
- The difference between digital input mode and digital output mode on an MSP430 GPIO pin
- How to use
pinMode()to configure a pin asINPUT,INPUT_PULLUP, orOUTPUT - How to use
digitalWrite()to drive a GPIO pin HIGH or LOW - How to use
digitalRead()to read the state of a digital input pin - The real current limits on MSP430G2 GPIO pins (and why you still need a series resistor)
- A complete LED blinking example with external LED on header pin 14 (P1.6)
- A complete push button example using pull-up wiring on header pin 5 (P1.3)
- How to troubleshoot common MSP430 GPIO issues (floating inputs, swapped pins, missing ground)
Prerequisites and Required Components
- MSP430G2 LaunchPad with the MSP430G2553 microcontroller in the socket
- Energia IDE installed and configured — if you haven’t done this yet, follow our MSP430G2 LaunchPad getting started tutorial first
- 1 × 5 mm LED (any color)
- 1 × 220 Ω resistor (current-limiting resistor for the LED)
- 1 × tactile push button
- 1 × 10 kΩ resistor (pull-up resistor for the push button)
- Breadboard and jumper wires
- USB cable to connect the LaunchPad to your computer
MSP430G2553 GPIO Pin Overview
MSP430-series microcontrollers typically organize their I/O as 8-bit ports numbered Port 1, Port 2, Port 3, and so on. The MSP430G2553 — the flagship chip bundled with the MSP430G2 LaunchPad — provides only two 8-bit ports: Port 1 and Port 2. As shown in the pinout diagram above, each port has 8 pins (P1.0–P1.7 and P2.0–P2.7), and each pin has multiple alternate functions (ADC input, timer output, UART, SPI, I2C) which we will cover in later tutorials. For now, we are only interested in the simplest use case: digital input and digital output.
As mentioned, the MSP430G2553 has two 8-bit ports, Port 1 and Port 2, for a total of 16 general-purpose pins. However, one small caveat: pins P2.6 and P2.7 are shared with the external 32 kHz crystal oscillator input. If your application uses the low-frequency crystal (for real-time clock applications, for example), those two pins become unavailable for GPIO use. The LaunchPad itself does not populate a crystal by default, so all 16 pins are available to you out of the box.
Electrical Characteristics of MSP430G2 GPIO Pins
- Operating voltage: 3.3 V on the LaunchPad (chip supports 1.8 V – 3.6 V)
- Logic HIGH: anything above ~2.1 V reads as HIGH
- Logic LOW: anything below ~0.9 V reads as LOW
- Maximum continuous current per pin: approximately 6 mA (sink or source) — significantly lower than AVR/Arduino chips (do not assume 40 mA)
- Maximum total current through VCC/GND pins: ~48 mA
- Internal pull-up/pull-down resistors: available on every GPIO pin via
INPUT_PULLUPin Energia
Because the MSP430G2 current limit is lower than what an Arduino can deliver, you should always use a current-limiting resistor when driving an LED directly from a pin — 220 Ω is a safe default for a typical 3.3 V LED circuit.
Digital Pins on the MSP430G2 LaunchPad
Every GPIO pin on the MSP430G2 LaunchPad can be configured as either an INPUT or an OUTPUT. Switching between modes is done with Energia’s pinMode() function, and it dramatically changes the electrical behavior of the pin:
- OUTPUT mode: the pin actively drives 3.3 V (HIGH) or 0 V (LOW) onto whatever is connected to it. Use this for LEDs, relays, motor drivers, buzzers, and any device the MCU needs to control.
- INPUT mode: the pin becomes high-impedance and reads whatever logic level the external circuit puts on it. Use this for push buttons, digital sensors, and logic signals coming from other ICs.
- INPUT_PULLUP mode: same as INPUT, but an internal ~47 kΩ pull-up resistor is enabled, so the pin reads HIGH by default and only goes LOW when something actively pulls it to ground (perfect for push buttons).
If you are not yet comfortable with Energia IDE, work through this tutorial first before continuing:
How to Declare an MSP430G2 LaunchPad Pin as an Input
The pinMode() function declares whether a GPIO pin is used as an input or an output. It takes two arguments: the pin number (use the Energia header pin number, not the P1.x/P2.x name) and the mode (INPUT, INPUT_PULLUP, or OUTPUT). For example, to declare header pin 2 (which is P1.0 on the MSP430G2553) as a digital input:
pinMode(2, INPUT);How to Declare an MSP430G2 LaunchPad Pin as an Output
To declare a GPIO pin as a digital output, call the same pinMode() function but pass OUTPUT as the second argument. For example, to configure header pin 3 (which is P1.1 on the MSP430G2553) as a digital output:
pinMode(3, OUTPUT);The same pattern works for any of the 16 GPIO pins on the MSP430G2553. Now let’s look at two complete, real examples — first using a GPIO pin as a digital output to blink an LED, and then using a GPIO pin as a digital input to read a push button.
LED Blinking Example with MSP430G2 LaunchPad
Let’s program the MSP430G2 LaunchPad to blink an external LED using the Energia IDE. The LaunchPad provides 16 GPIO pins, and any of them can drive an LED. For this example we use header pin 14 (which maps to P1.6 on the MSP430G2553) — this also happens to be the onboard green LED pin, which is convenient.
The pinMode() function initializes a GPIO pin as input or output. The first argument is the header pin number we want to configure; the second is either OUTPUT or INPUT:
pinMode(pin_number, OUTPUT);Pin configuration only needs to happen once, so we put it inside Energia’s setup() function. To actually control the output state we use digitalWrite(), which drives the pin HIGH (3.3 V) or LOW (0 V). Because we want the LED to blink continuously, digitalWrite() calls go inside the loop() function. For example, this line drives header pin 14 HIGH and turns the LED on:
digitalWrite(14, HIGH);And this line drives header pin 14 LOW and turns the LED off:
digitalWrite(14, LOW);LED Blinking Circuit Diagram
You need one LED and one 220 Ω current-limiting resistor. Wire the circuit as shown in the diagram below.

In this circuit we use header pin 14 of the MSP430G2 LaunchPad to drive the LED. Connect the anode (longer leg) of the LED to header pin 14 via the 220 Ω resistor, and the cathode (shorter leg) of the LED directly to GND. The resistor limits the current through the LED — essential because the MSP430G2’s maximum continuous pin current is around 6 mA (much lower than a typical Arduino’s 40 mA per pin). Driving a bare LED from an MSP430 pin without a series resistor can stress the pin and produce an overly bright, short-lived LED.
Complete LED Blinking Code for MSP430G2 LaunchPad
Let’s look at the complete sketch and walk through how it works. In Energia/C, any line starting with // is a single-line comment that the compiler ignores — comments exist purely for human readability. First, we assign a name to pin 14 so the rest of the code is more readable:
int ledpin = 14;Inside setup(), we initialize ledpin as an output:
pinMode(ledpin, OUTPUT);Inside the main loop(), we turn the LED on with:
digitalWrite(ledpin, HIGH);This applies 3.3 V to header pin 14, creating a voltage difference across the LED and lighting it up. Then we turn it off with:
digitalWrite(ledpin, LOW);This takes header pin 14 back to 0 V, turning the LED off. Between the on and off transitions we call delay(1000), which tells the MSP430 to pause for 1000 milliseconds (one second). During a delay() call the MSP430 does nothing else — for more sophisticated applications you would use timers or millis(), but delay() is perfect for our first example.
int ledpin = 14; // assign name "ledpin" to header pin 14
// the setup routine runs once when you press reset:
void setup()
{
// initialize the digital pin as an output
pinMode(ledpin, OUTPUT);
}
// the loop routine runs over and over again forever:
void loop()
{
digitalWrite(ledpin, HIGH); // turn the LED on (HIGH = 3.3 V)
delay(1000); // wait for a second
digitalWrite(ledpin, LOW); // turn the LED off (LOW = 0 V)
delay(1000); // wait for a second
}Push Button Example with MSP430G2 LaunchPad
Now that we can use a GPIO pin as a digital output, let’s use one as a digital input. In this example we wire an external push button to the MSP430G2 LaunchPad and use it to turn an LED on while the button is pressed. This combines both input and output modes in a single sketch — the foundation of any interactive embedded project.
To interface a push button with the MSP430G2, we need either a pull-up resistor or a pull-down resistor. The reason: a bare push button only connects or disconnects two points — it does not produce a voltage. Without a pull resistor, the GPIO input pin floats when the button is released and picks up random noise, causing unreliable readings.

Any GPIO pin can be wired to a push button. In this tutorial we use header pin 5 (P1.3 on the MSP430G2553) for the button, and header pin 14 (P1.6) for the LED.
Push Button Circuit Diagram
Wire the circuit according to the diagram below.

In this diagram, one terminal of the push button is connected to a 10 kΩ pull-up resistor, and the other side of the resistor goes to 3.3 V. The same button terminal also connects to header pin 5 of the MSP430G2 LaunchPad. The other terminal of the push button connects directly to GND.
A push button simply connects or disconnects two points in a circuit when you press it. When the push button is open (not pressed), there is no connection between the two legs — so header pin 5 is pulled up to 3.3 V through the pull-up resistor and reads as HIGH (logic 1). When the button is closed (pressed), the legs are connected together, which pulls header pin 5 down to 0 V (ground), and the pin reads as LOW (logic 0). In pull-up wiring the logic is inverted: released = HIGH, pressed = LOW. The LED, meanwhile, is wired to header pin 14 through a 220 Ω current-limiting resistor, exactly as in the previous example.
Tip: if you don’t want to wire an external pull-up resistor, you can use Energia’s built-in pull-up by calling pinMode(pushButton, INPUT_PULLUP) instead of pinMode(pushButton, INPUT). This enables the MSP430’s internal ~47 kΩ pull-up and lets you wire the button between the pin and GND with no external resistor.
Complete Push Button Code for MSP430G2 LaunchPad
In the first two lines of the sketch we assign friendly names — pushButton for header pin 5 and ledpin for header pin 14 — so the rest of the code reads naturally. A third integer variable, buttonState, stores the latest reading from the button. Inside setup() we configure the button pin as an input and the LED pin as an output.
Inside the loop() we introduce a new function: digitalRead(). It takes a single argument — the header pin to read — and returns either HIGH or LOW. We read the button state, store it in buttonState, and then use an if statement to light the LED only when the button is being pressed (button state = LOW in pull-up wiring).
int pushButton = 5; // header pin 5 (P1.3) has a push button attached
int ledpin = 14; // header pin 14 (P1.6) has an LED attached
int buttonState; // stores the latest push button reading (HIGH or LOW)
// the setup routine runs once when you press reset:
void setup()
{
pinMode(pushButton, INPUT); // make the push button pin an input
pinMode(ledpin, OUTPUT); // make the LED pin an output
}
void loop()
{
// read the input pin:
buttonState = digitalRead(pushButton);
if (buttonState == LOW) // button pressed (pull-up logic)
digitalWrite(ledpin, HIGH); // turn LED on
else
digitalWrite(ledpin, LOW); // turn LED off
}Click Upload to flash the sketch to the MSP430G2 LaunchPad. As soon as you press the push button, the LED turns on; release the button and the LED turns off. That’s the basic pattern of every interactive embedded project — read a digital input, branch based on its value, drive a digital output accordingly. GPIO pins scale far beyond LEDs and buttons: they are the foundation for seven-segment displays, LCDs, keypads, relays, motor drivers, and many more components we will cover in later tutorials.
Troubleshooting MSP430G2 GPIO Issues
- LED does not light up. Check the LED polarity — the longer leg (anode) must face the MSP430 pin through the resistor, the shorter leg (cathode) goes to GND. Try another LED; they are cheap and easy to damage.
- LED stays dimly on all the time. Either the pin is not configured as
OUTPUT, or the pin number inpinMode()anddigitalWrite()do not match. Verify withSerial.println(). - Push button always reads HIGH or always reads LOW. Floating input — the pull-up or pull-down resistor is missing or not connected. Either add a 10 kΩ external resistor to 3.3 V (or GND for pull-down) or use
INPUT_PULLUPinpinMode()to enable the internal pull-up. - Push button logic appears inverted. With pull-up wiring, pressing the button gives LOW (not HIGH). With pull-down wiring it’s the opposite. Match your
ifcondition to the wiring style you chose. - LED flickers randomly when you touch the button. Switch bouncing. Add a ~20 ms delay after detecting a button press, or debounce in software using
millis(). - Upload succeeds but nothing on the circuit changes. You uploaded to the wrong board (Tools → Board) or wrong COM port. Re-check both.
- Smoke or heat from the MSP430. You likely connected 5 V to a pin or forgot the current-limiting resistor. Disconnect immediately. The MSP430 is 3.3 V tolerant only.
Frequently Asked Questions
How many GPIO pins does the MSP430G2553 have?
The MSP430G2553 has 16 GPIO pins, divided into two 8-bit ports: Port 1 (P1.0–P1.7) and Port 2 (P2.0–P2.7). If you use an external 32 kHz crystal, pins P2.6 and P2.7 are reserved for XIN/XOUT and cannot be used as GPIO — but the LaunchPad does not populate a crystal by default, so all 16 pins are available.
How much current can an MSP430G2 GPIO pin drive?
Approximately 6 mA continuous per pin, with a total of around 48 mA across the whole chip. This is noticeably lower than Arduino / AVR chips (which can source ~20–40 mA per pin). Always use a current-limiting resistor with LEDs, and use a transistor or MOSFET driver for anything that needs more than a few mA — relays, high-brightness LEDs, motors, and so on.
What is the difference between INPUT and INPUT_PULLUP on the MSP430?
INPUT sets the pin to high impedance, with no internal pull. You must provide an external pull-up or pull-down resistor, otherwise the pin floats. INPUT_PULLUP sets the pin to high impedance but enables the MSP430’s internal ~47 kΩ pull-up resistor — convenient for push buttons because you can wire the button between the pin and GND with no external resistor. In INPUT_PULLUP mode, released = HIGH, pressed = LOW.
Which header pin number corresponds to which MSP430G2553 port pin?
See the complete header-pin-to-GPIO map in our MSP430G2 LaunchPad getting started tutorial. The common ones to remember: header pin 2 = P1.0 (red onboard LED), header pin 5 = P1.3 (onboard user button S2), header pin 14 = P1.6 (green onboard LED).
Can I use MSP430G2 GPIO pins with 5 V signals?
No. The MSP430G2 is a 3.3 V part and its GPIO pins are not 5 V tolerant. Applying 5 V to a GPIO pin — even briefly — can permanently damage it. If you need to interface with 5 V logic (for example, an Arduino or a 5 V sensor), use a level shifter or a simple voltage divider.
Do I need a resistor to connect an LED to an MSP430 pin?
Yes. Always use a current-limiting resistor (typically 220 Ω–1 kΩ) in series with the LED. Because the MSP430’s per-pin current limit is only around 6 mA, connecting an LED directly to a GPIO pin will exceed the pin’s safe operating area and can damage the microcontroller over time.
Conclusion
In this MSP430G2 LaunchPad GPIO tutorial you learned how to use the input/output pins of the MSP430G2553 microcontroller in the Energia IDE. You configured a GPIO pin as a digital output to blink an LED, configured another pin as a digital input to read a push button, and learned the three critical concepts behind GPIO: current limits, pull-up resistors, and the pinMode / digitalWrite / digitalRead function trio. Every later tutorial in this series — RGB LED, motion sensor, LCD, UART, ADC, PWM — builds directly on what you just did.
Related MSP430G2 LaunchPad Tutorials
- MSP430G2 LaunchPad Getting Started Tutorial with Energia IDE
- RGB LED Interfacing with MSP430G2 LaunchPad
- Motion Sensor Interfacing with MSP430G2 LaunchPad
- LCD Interfacing with MSP430 LaunchPad
- UART Serial Communication with MSP430 Microcontroller
- How to Use ADC of MSP430 Microcontroller
- Pulse Width Modulation using MSP430 LaunchPad – Control LED Brightness