Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gpio: Some functions are not working with the Arduino Uno nor the Arduino Nano #18228

Closed
valentinpi opened this issue Jun 17, 2022 · 7 comments
Closed

Comments

@valentinpi
Copy link

valentinpi commented Jun 17, 2022

Description

I cannot toggle LEDs or control my buzzers, because after initializing the proper ports and setting them the state of them never changes.

Steps to reproduce the issue

  1. Take an Arduino Uno or an Arduino Nano. (both v3, ATMEGA328P and ATMEGA328)
  2. Plug in the device via a USB cable.
  3. Create a small project with the following code and its makefile:
#include <led.h>
#include <periph/gpio.h>
#include <ztimer.h>

int main(void)
{
    const gpio_t LED_PIN = GPIO_PIN(1, 5);

    while (1) {
        printf("%d\n", gpio_read(LED_PIN));
        LED_TOGGLE(0);

        ztimer_sleep(ZTIMER_SEC, 1);
    }

    return 0;
}
APPLICATION = hello-world
RIOTBASE ?= $(CURDIR)/../..
DEVELHELP ?= 0
# See https://github.com/qmk/qmk_firmware/issues/17064
CFLAGS += -Wno-array-bounds

USEMODULE += periph_gpio
USEMODULE += ztimer
USEMODULE += ztimer_sec

QUIET ?= 1

include $(RIOTBASE)/Makefile.include
  1. Flash the firmware e.g. by (I used the hello-world example for this to test the GPIO):
BOARD=arduino-nano make -j clean all; avrdude -c arduino -b 115200 -p m328p -P /dev/ttyUSB0 -U flash:w:~/dev/RIOT/examples/hello-world/bin/arduino-nano/hello-world.hex; BOARD=arduino-nano make -j term

Expected results

The terminal window outputs zeros and ones in alternation, whilst die LED is blinking each second.

Actual results

The terminal window only outputs zeros and the LED stays off.

Versions

This also does not work with a small sound buzzer I bought today. The devices are not defect as I have connected them to current directly once and it worked. I suspect RIOT is not toggeling the GPIO ports.

System Information

... ~/d/RIOT (master)> make print-versions

Operating System Environment
----------------------------
         Operating System: "Arch Linux" 
                   Kernel: Linux 5.15.47-1-lts x86_64 unknown
             System shell: GNU bash, Version 5.1.16(1)-release (x86_64-pc-linux-gnu)
             make's shell: GNU bash, Version 5.1.16(1)-release (x86_64-pc-linux-gnu)

Installed compiler toolchains
-----------------------------
               native gcc: gcc (GCC) 12.1.0
        arm-none-eabi-gcc: arm-none-eabi-gcc (Arch Repository) 12.1.0
                  avr-gcc: avr-gcc (GCC) 12.1.0
         mips-mti-elf-gcc: missing
           msp430-elf-gcc: missing
       riscv-none-elf-gcc: missing
  riscv64-unknown-elf-gcc: missing
     riscv-none-embed-gcc: missing
     xtensa-esp32-elf-gcc: missing
   xtensa-esp8266-elf-gcc: missing
                    clang: clang version 13.0.1

Installed compiler libs
-----------------------
     arm-none-eabi-newlib: "4.2.0"
      mips-mti-elf-newlib: missing
        msp430-elf-newlib: missing
    riscv-none-elf-newlib: missing
riscv64-unknown-elf-newlib: missing
  riscv-none-embed-newlib: missing
  xtensa-esp32-elf-newlib: missing
xtensa-esp8266-elf-newlib: missing
                 avr-libc: "2.1.0" ("20220128")

Installed development tools
---------------------------
                   ccache: ccache version 4.6.1
                    cmake: cmake version 3.23.2
                 cppcheck: Cppcheck 2.8
                  doxygen: 1.9.3
                      git: git version 2.36.1
                     make: GNU Make 4.3
                  openocd: Open On-Chip Debugger 0.11.0
                   python: Python 3.10.5
                  python2: Python 2.7.18
                  python3: Python 3.10.5
                   flake8: 4.0.1 (mccabe: 0.7.0, pycodestyle: 2.8.0, pyflakes: 2.4.0) CPython 3.10.5 on
               coccinelle: spatch version 1.1.1 compiled with OCaml version 4.13.1

Additional Notes

  • To reproduce, one has to adjust the paths a bit or just put the codei n the hello-world example like I did.
  • I have mailed Hauke regarding the issue from above. Compilation is currently broken with the newest version of avr-gcc, but this is not RIOTs fault.
  • This might also be an avr-gcc issue, I am not sure.
  • I have only tested this with my personal boards, one Arduino Nano and one Arduino Uno. However, GPIO works flawlessly with the SAMR21-XPRO board.
@krzysztof-cabaj
Copy link
Contributor

Hi, try first initialize GPIO using init_gpio. See this link.

@valentinpi
Copy link
Author

valentinpi commented Jun 18, 2022

Hi! I tried that, it still does not work on my board. Also, I saw that it gets initialized automatically: https://github.com/RIOT-OS/RIOT/blob/master/drivers/periph_common/init_leds.c#L39.

EDIT: I correct myself, it only does given periph_init_led is used. But it still does not work for me.

@krzysztof-cabaj
Copy link
Contributor

Maybe as a workaround you could simply use gpio_toggle instead of LED_TOGGLE(0). I have Arduino UNO in my University and I will try to take it and looked where is a problem in the following week.

@valentinpi
Copy link
Author

I also tried initializing and toggeling manually. It's very strange, maybe I made some weird mistake in my setup? It would be nice if you could see if you are able to reproduce this.

@krzysztof-cabaj
Copy link
Contributor

Hi, I tested provided code at arduino-uno - indeed there are some problems with GPIO at this board. In current RIOT version (master) your code with LED_TOGGLE(0) and with gpio_toggle(LED_PIN)(instead LED_TOGGLE) did not work properly. Moreover, in this version of the RIOT code, program examples/blinky did not work, too. What is interesting, when I checked this program in older RIOT version (around end of January 2022) version with LED_TOGGLE(0) did not work but with gpio_toggle(LED_PIN) works.

Currently, no ideas on my end where is bug. I try to looked at this issue in the following week(s).

@valentinpi
Copy link
Author

valentinpi commented Jun 25, 2022

Hi, thanks for the effort. I will test the fix when I find some time and if it works, I will close this issue. I'm not closing yet since I see only the LED module has been changed, but there were some general GPIO problems the last time I used these boards. That's why I could not control my buzzer.

@valentinpi valentinpi changed the title Bug: GPIO actions not working with the Arduino Uno nor the Arduino Nano gpio: Some functions are not working with the Arduino Uno nor the Arduino Nano Jun 25, 2022
@valentinpi
Copy link
Author

Fixed with #18265.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants