Hi Support,
With the tutorial for C# I can see the LED on the Verdin board is blinking with an easier GPIO and a blink LED, I started with the easy one. 

C# Hello World Blinky on i.MX 8 with TorizonCore Embedded Linux with Visual Studio Code
I appreciate you sharing that, and I was wondering how I could do it in C.
The tutorial below is super fast and I don’t know how he copied past gpiod.h
Any help you can give me would be greatly appreciated.

Visual Studio C/C++ Debugging Made Easy for Embedded Linux with Torizon Extension
Could you please share the source c file and libraries?
Best regards,
Mehrdad
Hi @alex.tx ,
Thanks for taking the time to send that.
I did not catch you about the introduction. I am not as professional as you in catching everything in one word.
In the tutorial for headers, the instructor copied and pasted 1 in a millisecond. @ time : 2:24
Why is everything so fast?
And how can I find the gpiod.h file with 1402 lines?
Thanks for your time.
Best regards,
Mehrdad
Hi @Mehrdad ,
What IDE do you intend to develop? The C# video shows development on VSCode, whereas the C++ video is an introduction on debugging on Visual Studio 2019, a different IDE.
The C++ video was meant to showcase the general workflow when using the extension, and not to be a tutorial on blinking LEDs, that’s why the code part is sped up.
That being said, if you want to reproduce the C++ code in the video you can create a new C/C++ project (a Makefile-based Project) in VSCode following the instructions here: C/C++ Development and Debugging on TorizonCore Using Visual Studio Code | Toradex Developer Center. Copy the main.cpp
from the video to your project.
The code uses the libgpiod
library, so you need to add these configuration options in your project:
-
devpackages
: libgpiod-dev:#%platform.debian-arch%#
-
extrapackages
: libgpiod2
-
devices
: /dev/gpiochipX
, where X
is the GPIO bank number you want to enable
Include -lgpiod
to your Makefile. gpiod.h
is just the header file of libgpiod, and if you added the configuration options above it should be enough to replace
#include "gpiod.h"
by
#include <gpiod.h>
in your main.cpp
. The instructor on the video chose to copy the header file locally, but it should work either way.
Do not forget to change the bank and line variables to the GPIO you want to enable. Keep in mind that in some SoMs the bank number libgpiod
sees is n-1
from the datasheet e.g. if you see GPIO 1 23 in the datasheet it could be bank 1 line 23, or bank 0 line 23.
Everything I said here can be found in more details in the articles @alex.tx and I referenced.
Hope this helps you.
Best regards,
Lucas Akira
1 Like
Dear @lucas_a.tx ,
Thank you very much. The right way was shown to me by YOU.
Also, I am not an expert, but I found gpiod.h on github, but I wasn’t sure about it, since it has 1775 lines and was different from the tutorial.
You sent it the same one. YOU have resolved one of my concerns. hurrrrrah.
I am using Visual Studio Code and as you know, for a beginner like me, SPI was too challenging, so I started with GPIO and then SPI, anyway, I’ll do whatever you said to me to do and I’ll try to blink the led 
Thanks a million and have a wonderful time.
Best regards,
Mehrdad
Hi @lucas_a.tx ,
I’m working on it. I was wondering if when I run and print the hello world, everything is okay, but if I add commands like [gpiod_chip_open_by_number] the functions in the gpiod.h, it faces an error and I need to add configuration to the page launch.json.
the error image
just I think I needed to change “stopAtEntry”: false? or add anything?
Thanks,
Mehrdad
Hi @Mehrdad ,
Is the content of Blink.h the same as gpiod.h? If libgpiod-dev
was added to devpackages
you don’t need a copy of the libgpiod header file alongside your Blink.c file.
libgpiod-dev
already installs gpiod.h
to the standard directories inside the dev container, so you can delete Blink.h
and instead add:
#include <gpiod.h>
To your .c file.
So Blink.c
should be something similar to this:
#include <stdio.h>
#include <unistd.h>
#include <gpiod.h>
int main()
{
struct gpiod_chip *output_chip;
struct gpiod_line *output_line;
int line_value = 0;
int bank = 4;
int line = 26;
output_chip = gpiod_chip_open_by_number(bank);
output_line = gpiod_chip_get_line(output_chip, line);
gpiod_line_request_output(output_line, "blink",
GPIOD_LINE_ACTIVE_STATE_LOW);
while (1) {
line_value = !line_value;
gpiod_line_set_value(output_line, line_value);
sleep(1);
printf("Setting pin to %d\n", line_value);
}
return EXIT_SUCCESS;
}
I was wondering if when I run and print the hello world, everything is okay, but if I add commands like [gpiod_chip_open_by_number] the functions in the gpiod.h, it faces an error and I need to add configuration to the page launch.json.
I think I know what’s going on: you probably didn’t include -lgpiod
to your Makefile. It should be something like this:
OBJ = Blink.o
%.o : %.c $(DEPS)
$(CC) -c -o $@ $< $(CFLAGS)
Blink: $(OBJ)
$(CC) -o $@ $^ $(CFLAGS) -lgpiod
install: Blink
mkdir -p $(WORKDIR)
cp Blink $(WORKDIR)/
clean:
rm -f *.o
rm -f Blink
just I think I needed to change “stopAtEntry”: false? or add anything?
stopAtEntry just tells VSCode to whether or not stop at the entry point of your application when debugging. It shouldn’t be related to your issue and you don’t need to alter anything in launch.json
.
Try doing the above and see if you can compile and deploy your program to the module.
Best regards,
Lucas Akira
Hi @Mehrdad !
Do you have news regarding this topic?
Best regards,
Henrique