Hey all,
I’ve been trying to figure out how to set and read the GPIO pins using the C SDK. So far, I haven’t been able to get any of them to show any output when I attach a voltimeter. Can anyone tell me what I’m doing wrong? Here’s what I’ve written so far:
/*
Build by running the following commands:
PICO_SDK_PATH=/home/larry/Projects/pico-sdk/ cmake -S . -B build -DPICO_BOARD=pico
cmake --build build --target hello_world
*/
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "pico/stdlib.h"
#include "hardware/gpio.h"
#include "hardware/clocks.h"
#include "i2ckbd.h"
#include "lcdspi.h"
#include "psram_spi.h"
#include "pwm_sound.h"
int main() {
set_sys_clock_khz(133000, true);
stdio_init_all();
init_i2c_kbd();
lcd_init();
lcd_clear();
lcd_print_string("Testing GPIO pins\n");
uint gpio = 1;
bool value = 1;
char* message = malloc (100 * sizeof (char));
gpio_set_dir (1, GPIO_OUT);
gpio_set_dir (2, GPIO_OUT);
gpio_set_dir (3, GPIO_OUT);
gpio_set_dir (4, GPIO_OUT);
while (1) {
sleep_ms(2000);
sprintf (message, "Testing GPIO pins sending value out %u\n", (uint) value);
lcd_print_string(message);
gpio_put (1, value);
gpio_put (2, value);
gpio_put (3, value);
gpio_put (4, value);
value = !value;
}
return 0;
}
The program displays the Testing message and appears to toggle between sending a 1 and a 0 signal to the various IO pins once every two seconds, but my voltimeter does not display any output.
The rest of the program (the build environment etc can be found in my demo repo in Codeberg - llee454/picocalc-test: A demonstration project showing how to compile, build, and flash C programs for the PicoCalc. - Codeberg.org.
Thanks!
- L
