1

I've been trying the past 6 hours to run a very simple LOOKING code. It just turns an LED hooked to pin 18 on and off... This is on a raspberry PI 4.

I've tried using different pins I've tried adding sudo sh -c "..." I've tried single vs. double quotes

When running the following code, I get the error sh: 1: echo: echo: I/O error

#!/bin/bash

sudo sh -c 'echo 18 > /sys/class/gpio/export'

sudo sh -c 'echo "out" > /sys/class/gpio/gpio18/direction'

while [ $COUNTER:-1t:10000 ]; do
    sudo sh -c 'echo 1 > /sys/class/gpio/gpio18/value'
    sleep 1
    sudo sh -c 'echo 0 > /sys/class/gpio/gpio18/value'
    sleep 1
done

sudo sh -c 'echo 18 > /sys/class/gpio/unexport'

And when I run the "non-sudo" version, I get the error ./Lab1EX4_1.sh: line 4: echo: write error: Device or resource busy

#!/bin/bash

echo "18" > /sys/class/gpio/export

echo "out" > /sys/class/gpio/gpio18/direction

while [ $COUNTER:-1t:10000 ]; do
    echo "1" > /sys/class/gpio/gpio18/value
    sleep 1
    echo "0" > /sys/class/gpio/gpio18/value
    sleep 1
done

echo "18" > /sys/class/gpio/unexport

This has got me so mad...

Thank you peeps! I just want a blinky light :D

1
  • 2
    Welcome to Stackexchange! You may get better feedback on the site dedicated to Raspberry Pis, raspberrypi.stackexchange.com. Commented Feb 25, 2021 at 3:31

1 Answer 1

1

SOLUTION!

Ok, the answer was to to first use pigpio and to test if my GPIO's were working...

download both http://abyz.me.uk/rpi/pigpio/ (press the underlined download link and the download)

Then get GPIO Pin test / gpiotest - http://abyz.me.uk/rpi/pigpio/examples.html - extract and run it once you've ran the command sudo pigpio and then run extracted gpiotest by executing the shell file

If the test ends instantly without much code on the command line, you passed!

Now that you know your gpio is not broken, it's time to "test" the software side of the gpio by updating all the wiringpi libraries

sudo apt update
sudo apt full-upgrade

Now, though I was trying to trigger pin 18 with the code in post #1, I actually wound up changing it to "24" because PIN 18 IS GPIO24. The name of the folder created in /sys/class/gpio was gpio18... aka NOT pin 18, So find a nice pinout before you rip your hair out!

Enjoy your blinky light!

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.