# Tiny 2040 on-board led C programming

**URL:** https://forums.pimoroni.com/t/tiny-2040-on-board-led-c-programming/22304
**Category:** Support
**Created:** [June 8, 2023, 6:57am UTC](https://forums.pimoroni.com/t/tiny-2040-on-board-led-c-programming/22304 "2023-06-08T06:57:28Z")
**Posts on this page:** 10
**Page:** 1

<div class="post-metadata">

### Author: ![daneksithethos](https://avatars.discourse-cdn.com/v4/letter/d/90ced4/32.png) [@daneksithethos](https://forums.pimoroni.com/u/daneksithethos)
#### Post date: [June 8, 2023, 6:57am UTC](https://forums.pimoroni.com/t/tiny-2040-on-board-led-c-programming/22304/1 "2023-06-08T06:57:28Z")

</div>

Hello, I am trying to write the blinke on-board led example for the Tiny 2040. I am using C programming language, and my code is built with CMake.

However NMake gives a LNK1181 error, and a U1077 errors (please note that I was able to make the led blink example work using this as a template [pico-examples/blink.c at master · raspberrypi/pico-examples · GitHub](https://github.com/raspberrypi/pico-examples/blob/master/blink/blink.c)).

I am wondering whether I have to create my own libraries for this project (it seems to me that the problem is in the code somewhere).

I am using this blink example as a template ([pico-examples/blink.c at master · raspberrypi/pico-examples · GitHub](https://github.com/raspberrypi/pico-examples/blob/master/blink/blink.c)).

And I am using this as a reference my include headers ([pico-sdk/pimoroni\_tiny2040.h at master · raspberrypi/pico-sdk · GitHub](https://github.com/raspberrypi/pico-sdk/blob/master/src/boards/include/boards/pimoroni_tiny2040.h)).

Please help me find guidance on how to make my project work ( I am reading this reference [C docs - get started, tutorials, reference. | Microsoft Learn](https://learn.microsoft.com/en-us/cpp/c-language/?view=msvc-170), but I guess I lack knowledge, because I did not find an answer to my question).

---

<div class="post-metadata">

### Author: ![alphanumeric](https://sea2.discourse-cdn.com/flex016/user_avatar/forums.pimoroni.com/alphanumeric/32/2729_2.png) [@alphanumeric](https://forums.pimoroni.com/u/alphanumeric)
#### Post date: [June 8, 2023, 8:46am UTC](https://forums.pimoroni.com/t/tiny-2040-on-board-led-c-programming/22304/2 "2023-06-08T08:46:57Z")

</div>

Just want to confirm, this is a Pimoroni Tiny2040?  
I ask because there is also a **Waveshare** RP2040 Tiny.

---

<div class="post-metadata">

### Author: ![ahnlak](https://sea2.discourse-cdn.com/flex016/user_avatar/forums.pimoroni.com/ahnlak/32/5610_2.png) [@ahnlak](https://forums.pimoroni.com/u/ahnlak)
#### Post date: [June 8, 2023, 11:51am UTC](https://forums.pimoroni.com/t/tiny-2040-on-board-led-c-programming/22304/3 "2023-06-08T11:51:16Z")

</div>

It’s a little hard to tell without seeing your project files; `LNK1181` is a “file not found” error from the linker, so at a guess I’d say your `CMakeLists.txt` file is probably off - the actual error message text will give you a better idea of exactly where the problem lies.

---

<div class="post-metadata">

### Author: ![daneksithethos](https://avatars.discourse-cdn.com/v4/letter/d/90ced4/32.png) [@daneksithethos](https://forums.pimoroni.com/u/daneksithethos)
#### Post date: [June 8, 2023, 5:14pm UTC](https://forums.pimoroni.com/t/tiny-2040-on-board-led-c-programming/22304/4 "2023-06-08T17:14:03Z")

</div>

Yes, it is Pimoroni Tiny 2040.

---

<div class="post-metadata">

### Author: ![daneksithethos](https://avatars.discourse-cdn.com/v4/letter/d/90ced4/32.png) [@daneksithethos](https://forums.pimoroni.com/u/daneksithethos)
#### Post date: [June 8, 2023, 5:28pm UTC](https://forums.pimoroni.com/t/tiny-2040-on-board-led-c-programming/22304/5 "2023-06-08T17:28:01Z")

</div>

Sorry, here are the details:

1. Code from tiny2040\_RGB\_blink.c

```auto
/**
 * Copyright (c) 2022 Raspberry Pi (Trading) Ltd.
 *
 * SPDX-License-Identifier: BSD-3-Clause
 */

#include "pico/stdlib.h"
#include <stdio.h>

#define _BOARDS_PIMORONI_TINY2040_H
#define PIMORONI_TINY2040_8MB

#define TINY2040_LED_R_PIN 18
#define TINY2040_LED_G_PIN 19
#define TINY2040_LED_B_PIN 20

int main(){
    
    const uint LED_PIN_R = TINY2040_LED_R_PIN;
    const uint LED_PIN_G = TINY2040_LED_G_PIN;
    const uint LED_PIN_B = TINY2040_LED_B_PIN;
    
    gpio_init(LED_PIN_R);
    gpio_init(LED_PIN_G); 
    gpio_init(LED_PIN_B);
    
    gpio_set_dir(LED_PIN_R, GPIO_OUT); 
    gpio_set_dir(LED_PIN_G, GPIO_OUT);
    gpio_set_dir(LED_PIN_B, GPIO_OUT);
    
    while (true) {
        gpio_put(LED_PIN_R, 1);
        sleep_ms(250);
        gpio_put(LED_PIN_R, 0);
        sleep_ms(250);
        gpio_put(LED_PIN_G, 1);
        sleep_ms(250);
        gpio_put(LED_PIN_G, 0);
        sleep_ms(250);
        gpio_put(LED_PIN_B, 1);
        sleep_ms(250);
        gpio_put(LED_PIN_B, 0);
        sleep_ms(250);
    }
    
}

```

1. CMakeLists.txt

```auto
cmake_minimum_required(VERSION 3.13)

#initialize pico-sdk from GIT
#(note this can come from environment, CMake cache etc.)
set(PICO_SDK_FETCH_FROM_GIT on)

#initialize the SDK based on PICO_SDK_PATH
#note: this must happen before the project()
set(PICO_SDK_PATH $ENV{PICO_SDK_PATH})
include(pico_sdk_import.cmake)

#include(pico_extras_import_optional.cmake)

project(tiny2040_RGB_blink C CXX ASM)
set(CMAKE_C_STANDARD 11)
set(CMAKE_CXX_STANDARD 17)

set(PICO_PICO_BLINK_PATH ${PROJECT_SOURCE_DIR})

#initialize the Raspberry Pi Pico SDK
pico_sdk_init()

//# add url via pico_set_program_url
//# example_auto_set_url(tiny2040_RGB_blink)

add_executable(tiny2040_RGB_blink
       tiny2040_RGB_blink.c
        )

//# pull in common dependencies
target_link_libraries(tiny2040_RGB_blink pico_stdlib)

//# create map/bin/hex file etc.
pico_add_extra_outputs(tiny2040_RGB_blink)

```

1. Output in Developer Command Prompt after executing ‘nmake’ command

```auto
[1%] Performing build step for 'ELF2UF2Build'
[100%] Built target elf2uf2
[2%] No install step for 'ELF2UF2Build'
[4%] Completed 'ELF2UF2Build'
[11%] Built target ELF2UF2Build
[13%] Building ASM object pico-sdk/src/rp2_common/boot_stage2/CMakeFiles/bs2_default.dir/compile_time_choice.S.obj
cl : Command line warning D9021 : no action performed
[14%] Linking ASM executable bs2_default.elf
Microsoft (R) Incremental Linker Version 14.35.32215.0
Copyright (C) Microsoft Corporation. All rights reserved.

/out:compile_time_choice.S.exe 
/out:bs2_default.elf 
CMakeFiles\bs2_default.dir\compile_time_choice.S.obj 
LINK : fatal error LNK1181: cannot open input file 'CMakeFiles\bs2_default.dir\compile_time_choice.S.obj'

```

Please note that there is also a NMake fatal error U1077 in the output (for some reason it did not write entire output to .txt file after executing nmake \> PATH/TO/OUTPUT.TXT).

---

<div class="post-metadata">

### Author: ![daneksithethos](https://avatars.discourse-cdn.com/v4/letter/d/90ced4/32.png) [@daneksithethos](https://forums.pimoroni.com/u/daneksithethos)
#### Post date: [June 8, 2023, 7:43pm UTC](https://forums.pimoroni.com/t/tiny-2040-on-board-led-c-programming/22304/6 "2023-06-08T19:43:48Z")

</div>

Strangely today after starting VSCode from Developer Comand Prompt (executing ‘code’ command) the project has been built successfully.

Unfortunately I cannot verify if my .uf2 file works as intended because my Tiny 2040 stopped working (does not respond to boot and reset) after I desoldered debug pin headers yesterday.

I would still appreciate any guidance regarding flaws in my project.

---

<div class="post-metadata">

### Author: ![hel](https://sea2.discourse-cdn.com/flex016/user_avatar/forums.pimoroni.com/hel/32/6075_2.png) [@hel](https://forums.pimoroni.com/u/hel)
#### Post date: [June 9, 2023, 8:41am UTC](https://forums.pimoroni.com/t/tiny-2040-on-board-led-c-programming/22304/7 "2023-06-09T08:41:47Z")

</div>

If you enclose code in triple backticks ( ``` ) it stops the forum trying to apply formatting to it and makes everything more readable - I’ve added them into the above post for you :)

---

<div class="post-metadata">

### Author: ![alphanumeric](https://sea2.discourse-cdn.com/flex016/user_avatar/forums.pimoroni.com/alphanumeric/32/2729_2.png) [@alphanumeric](https://forums.pimoroni.com/u/alphanumeric)
#### Post date: [June 9, 2023, 9:00am UTC](https://forums.pimoroni.com/t/tiny-2040-on-board-led-c-programming/22304/8 "2023-06-09T09:00:46Z")

</div>

If you click the **Preformatted Text** option, the \</\>, it sets it all up for you.

 ![Capture](https://us1.discourse-cdn.com/flex016/uploads/pimoroni/original/2X/9/9eba66d3b6fb0d5d3be149191bc79f3aa627d394.jpeg)

---

<div class="post-metadata">

### Author: ![daneksithethos](https://avatars.discourse-cdn.com/v4/letter/d/90ced4/32.png) [@daneksithethos](https://forums.pimoroni.com/u/daneksithethos)
#### Post date: [June 9, 2023, 3:53pm UTC](https://forums.pimoroni.com/t/tiny-2040-on-board-led-c-programming/22304/9 "2023-06-09T15:53:30Z")

</div>

Great, thank you hel!

---

<div class="post-metadata">

### Author: ![daneksithethos](https://avatars.discourse-cdn.com/v4/letter/d/90ced4/32.png) [@daneksithethos](https://forums.pimoroni.com/u/daneksithethos)
#### Post date: [June 9, 2023, 3:54pm UTC](https://forums.pimoroni.com/t/tiny-2040-on-board-led-c-programming/22304/10 "2023-06-09T15:54:08Z")

</div>

Thank you alphanumeric!
