If you want a clear and practical guide to programming the ATtiny3217 Curiosity Nano, this ATtiny3217 CNANO tutorial walks you step-by-step through using the onboard LED and push button. You will learn how to set up the ATtiny3217 CNANO board, write simple programs, and test them using the MPLAB X IDE with the XC8, and avr-gcc toolchains.
Table of Contents
- What This ATtiny3217 CNANO Tutorial Covers
- Understanding the ATtiny3217 CNANO Board
- Setting Up MPLAB X IDE With ATtiny3217
- ATtiny3217 CNANO Tutorial LED Blink Example (XC8 Toolchain)
- ATtiny3217 CNANO Tutorial LED Blink Example (avr-gcc Toolchain)
- ATtiny3217 CNANO Tutorial Push Button Example (XC8 Toolchain)
- ATtiny3217 CNANO Tutorial Push Button Example (avr-gcc Toolchain)
- Tips for the ATtiny3217 CNANO Tutorial
- Did You Know?
- Frequently Asked Questions About the ATtiny3217 CNANO Tutorial
- How is the ATtiny3217 CNANO board powered?
- Do I need drivers for the ATtiny3217 Curiosity Nano?
- Can I use the ATtiny3217 with both XC8 and avr-gcc?
- Which pin controls the onboard LED?
- How do I enable the push button?
- Can these examples be used for external buttons or LEDs?
- Is the clock accurate enough for delays?
- Conclusion
What This ATtiny3217 CNANO Tutorial Covers
In this ATtiny3217 CNANO tutorial, you will learn how the onboard hardware works, how to compile ATtiny3217 code examples, and how to run both LED and push-button programs using different toolchains.
This tutorial focuses on:
- Understanding the ATtiny3217 CNANO board layout
- Using the MPLAB X IDE with the ATtiny3217
- Building XC8 ATtiny3217 example code
- Compiling avr-gcc ATtiny3217 programs
- Running an ATtiny3217 LED blink example
- Testing an ATtiny3217 push button example
Understanding the ATtiny3217 CNANO Board
The ATtiny3217 CNANO board is a compact development platform with onboard debugging, a USB interface, and essential I/O hardware. It houses a ATtiny3217 AVR microcontroller. As can be seen in the image of the board below, the push button switch and user LED are near the end of the board. Key onboard components include:
| Feature | Description |
|---|---|
| LED0 | Connected to PA3 |
| SW0 Push Button | Connected to PB7 with internal pull-up |
| Debugger | Onboard nEDBG |
| USB Interface | Direct programming and serial debugging |
| MCU | ATtiny3217 (tinyAVR 1-series) |
The ATtiny3217 Curiosity Nano is ideal for learning GPIO handling due to its accessible onboard peripherals.


The LED on the ATtiny3217-CNANO board is wired with its anode connected to the positive supply rail and its cathode connected to the microcontroller through a current-limiting resistor. This configuration means the LED is active low. Driving the pin low creates a voltage drop across the LED and its resistor, allowing current to flow and turning it on.
Driving the pin high removes the voltage difference, stopping current flow and switching the LED off. Because of this wiring arrangement, beginners often notice that LED control appears inverted compared to the more common active-high configuration found on many development boards.
The push button is connected differently. It includes a series resistor that limits current into the microcontroller pin, ensuring safe operation when the pin changes state. However, the button does not include a pull-up or pull-down resistor on the board, so the input would otherwise float and produce unpredictable readings. To ensure a stable logic level, the firmware must enable the internal pull-up resistor on the corresponding pin. With the pull-up active, an open switch produces a logic high because the pin is held at the supply level through the pull-up. Pressing the switch creates a low-resistance path to ground, overriding the pull-up and producing a logic low. This arrangement provides reliable button detection using only a single external component on the board.
Setting Up MPLAB X IDE With ATtiny3217
To build and flash firmware, you can use MPLAB X IDE with ATtiny3217 and the XC8 compiler.
Basic setup steps:
- Install MPLAB X IDE and XC8. Follow our article How to Install MPLAB X IDE for AVR Development to do this, which includes instructions on how to install the avr-gcc toolchain.
- Plug the ATtiny3217 Curiosity Nano into a spare USB port of the host computer.
- Create a new standalone project for the ATtiny3217. See our article Easily Create Your First MPLAB Project: Step-by-Step Guide for instructions on creating a new AVR project in the MPLAB X IDE.
- Select the Curiosity Nano as the debugger/tool.
This workflow is ideal for users who want a full GUI experience and Microchip’s native programming environment.
After creating a new project, use any of the code examples that follow. The first two ATtiny3217 code examples show how to blink the on-board LED using the XC8 toolchain, and then the AVR-GCC toolchain. Following these examples is a push button example that uses the XC8 toolchain, followed by a push button example that uses the AVR-GCC toolchain.
ATtiny3217 CNANO Tutorial LED Blink Example (XC8 Toolchain)
This ATtiny3217 LED blink example demonstrates a simple GPIO output using the XC8 toolchain. The LED is attached to pin PA3 if the ATtiny3217. At the start of the program, pin PA3 is set up as an output pin to drive the LED. Code in the while(1) loop continually switches the LED on and off with a delay in order to blink or flash the LED.
/*
* File: main.c
* Author: Warwick Smith (https://avr8.com/)
*
* Blink C program for the ATtiny3217-CNANO board using the XC8 toolchain
*
* Blinks LED0 on pin PA3 of the ATtiny3217 curiosity nano board
*
* Created on 05 December 2025, 5:40 PM
*/
#define F_CPU (3300000UL)
#include <xc.h>
#include <util/delay.h>
void main(void) {
PORTA.DIRSET = PIN3_bm; // LED0 on pin PA3
while(1) {
PORTA.OUTCLR = PIN3_bm; // Switch LED on
_delay_ms(500); // Delay 500 ms
PORTA.OUTSET = PIN3_bm; // Switch LED off
_delay_ms(500); // Delay 500 ms
}
}
ATtiny3217 CNANO Tutorial LED Blink Example (avr-gcc Toolchain)
For users working with MPLAB X IDE or any other IDE with the AVR-GCC toolchain, this avr-gcc ATtiny3217 version provides the same behavior as the previous example. It blinks the LED at a slow rate that is visible to the human eye, as with the previous example.
/*
* File: main.c
* Author: Warwick Smith (https://avr8.com/)
*
* Blink C program for the ATtiny3217-CNANO board using the avr-gcc toolchain
*
* Blinks LED0 on pin PA3 of the ATtiny3217 curiosity nano board
*
* Created on 05 December 2025, 5:53 PM
*/
#define F_CPU 3300000UL
#include <avr/io.h>
#include <util/delay.h>
int main(void) {
PORTA.DIRSET = PIN3_bm; // LED0 on pin PA3
while (1) {
PORTA.OUTCLR = PIN3_bm; // Switch LED on
_delay_ms(500); // Delay 500 ms
PORTA.OUTSET = PIN3_bm; // Switch LED off
_delay_ms(500); // Delay 500 ms
}
}ATtiny3217 CNANO Tutorial Push Button Example (XC8 Toolchain)
This is the first of the ATtiny3217 push button example programs. It shows how to read the push button on pin PB7 of the ATtiny3217 and switch LED0 on pin PA3 of the microcontroller.
The internal pull-up resistor on pin PB7 must be switched on, as there is no external pull-up on the board. Because a pull-up is used, the switch test code detects the open switch as a logic 1 or high. The LED is connected in a current sinking configuration. This means that pin PA3 is switched low to switch the LED on, and high to switch the LED off.
/*
* File: main.c
* Author: Warwick Smith
*
* Push button C program for the ATtiny3217-CNANO board using the XC8 toolchain.
*
* Reads the state of the push button switch (SW0) on pin PB7.
* Switches the LED on pin PA3 when the switch is operated.
* By default, the LED is on. Push the switch to turn the LED off.
*
* Created on 05 December 2025, 18:04 PM
*/
#define F_CPU (3300000UL)
#include <xc.h>
void main(void) {
PORTA.DIRSET = PIN3_bm; // LED on pin PA3, set as output
PORTB.PIN7CTRL |= PORT_PULLUPEN_bm; // Switch internal PB7 pull-up on
PORTB.DIRCLR = PIN7_bm; // Switch on pin PB7, set as input
while(1) {
if (VPORTB.IN & PIN7_bm) { // Check if switch is open
// Switch is open
PORTA.OUTCLR = PIN3_bm; // Switch LED on
}
else {
// Switch is closed
PORTA.OUTSET = PIN3_bm; // Switch LED off
}
}
}
ATtiny3217 CNANO Tutorial Push Button Example (avr-gcc Toolchain)
Here is the avr-gcc equivalent version of the previous code. It is almost identical, except for the included header file.
/*
* File: main.c
* Author: Warwick Smith
*
* Push button C program for the ATtiny3217-CNANO board using the GCC toolchain.
*
* Reads the state of the push button switch (SW0) on pin PB7.
* Switches the LED on pin PA3 when the switch is operated.
* By default, the LED is on. Push the switch to turn the LED off.
*
* Created on 05 December 2025, 18:12 PM
*/
#define F_CPU 3300000UL
#include <avr/io.h>
void main(void) {
PORTA.DIRSET = PIN3_bm; // LED on pin PA3, set as output
PORTB.PIN7CTRL |= PORT_PULLUPEN_bm; // Switch internal PB7 pull-up on
PORTB.DIRCLR = PIN7_bm; // Switch on pin PB7, set as input
while(1) {
if (VPORTB.IN & PIN7_bm) { // Check if switch is open
// Switch is open
PORTA.OUTCLR = PIN3_bm; // Switch LED on
}
else {
// Switch is closed
PORTA.OUTSET = PIN3_bm; // Switch LED off
}
}
}
These ATtiny3217 code examples provide a complete introduction to basic I/O using both toolchains.
Tips for the ATtiny3217 CNANO Tutorial
- Use MPLAB X IDE for simpler debugging and programming.
- Ensure the clock frequency macro matches your configuration.
- When reading inputs, always enable the internal pull-up unless using external circuits.
- Use short delay periods during initial testing for easier observation.
- Keep wiring minimal—the ATtiny3217 CNANO board already provides onboard peripherals.
Did You Know?
- The ATtiny3217 belongs to the tinyAVR 1-series, introducing a new and simplified peripheral architecture.
- The VPORT system allows faster I/O access compared to classic AVR devices.
- Curiosity Nano boards share a common debugger, making it easy to move between different AVR devices.
- Many early ATtiny tutorials use older devices; the ATtiny3217 offers multiple improvements such as advanced timers and event routing.
Frequently Asked Questions About the ATtiny3217 CNANO Tutorial
How is the ATtiny3217 CNANO board powered?
It is powered directly from the USB port. No external power supply is required for basic projects.
Do I need drivers for the ATtiny3217 Curiosity Nano?
Most systems recognize the board automatically. MPLAB X IDE installs any required USB components.
Can I use the ATtiny3217 with both XC8 and avr-gcc?
Yes. This tutorial includes both XC8 and avr-gcc ATtiny3217 examples, and both produce nearly identical results.
Which pin controls the onboard LED?
LED0 is on PA3. All examples in this ATtiny3217 CNANO tutorial use that pin.
How do I enable the push button?
The push button is on PB7 and requires enabling the internal pull-up.
Can these examples be used for external buttons or LEDs?
Yes. The logic is identical; only the pins change.
Is the clock accurate enough for delays?
For general projects, yes. For precise timing, consider enabling the calibrated oscillator.
Conclusion
This ATtiny3217 CNANO tutorial introduced the essential steps needed to program the ATtiny3217 Curiosity Nano using both XC8 and avr-gcc. By exploring LED control and button input, you now have the foundation needed to build more advanced projects. These ATtiny3217 code examples demonstrate the simplicity and flexibility of the board, helping you continue your development journey with confidence.