Page 1 of 1

Automatically set GPIO 18 to PWM on boot

Posted: Tue May 24, 2016 2:07 pm
by Jimanez11
Hey guys, so I am almost there but at the moment have to manually set GPIO18 to PWM every single time I start the system (gets kinda annoying). Can anyone point me in the right direction to add a command to the boot process? The only additional command I want to run on startup is "raspi-gpio set 18 a5". Have tried following the script for pwmaudio.sh listed in the Adafruit tutorial, but it does nothing when I switch the commands to the one above.

Also, if it isn't obvious already, I am a raspberry pi / linux noob, so please instruct as such.

Any help or guidance is appreciated!

Re: Automatically set GPIO 18 to PWM on boot

Posted: Tue May 24, 2016 2:16 pm
by wermy
Here you go: https://learn.adafruit.com/adding-basic ... o?view=all

They have a step-by-step for setting up a service that will make it set that up on boot every time.

Re: Automatically set GPIO 18 to PWM on boot

Posted: Tue May 24, 2016 2:44 pm
by Jimanez11
Hey Wermy! Thanks for such a quick response! I tried setting up the service per Adafruit's instructions and it doesn't seem to take for me. Have set up both the PWMAudio.sh file but changed the text to read:

#!/bin/bash

/usr/local/bin/raspi-gpio set 18 a5

Otherwise, everything else was kept the same. and then created the PWMAudio.service as well. When the system reboots and I run raspi-gpio get 18, the settings don't stick and it seems like the script isn't running. I will try again and hopefully I didn't make a spelling mistake (has been known to happen).

Thanks (for all of this, not just the quick response) and will keep you posted.

Re: Automatically set GPIO 18 to PWM on boot

Posted: Tue May 24, 2016 5:33 pm
by Jimanez11
So, went through the "Automate It" portion of the guide again and there is still no script running that changes the GPIO to pwm. any other ideas? Will this not work using raspi-gpio commands?

Re: Automatically set GPIO 18 to PWM on boot

Posted: Tue May 24, 2016 9:29 pm
by tindalos
You can also reconfigure the gpio pins via your /boot/config.txt. Add the following line then reboot and everything should be good:

Code: Select all

dtoverlay=pwm-2chan,pin=18,func=2,pin2=13,func2=4

Re: Automatically set GPIO 18 to PWM on boot

Posted: Tue May 24, 2016 10:14 pm
by wermy
tindalos wrote:You can also reconfigure the gpio pins via your /boot/config.txt. Add the following line then reboot and everything should be good:

Code: Select all

dtoverlay=pwm-2chan,pin=18,func=2,pin2=13,func2=4
Nice! That's much easier.
Jimanez11 wrote:So, went through the "Automate It" portion of the guide again and there is still no script running that changes the GPIO to pwm. any other ideas? Will this not work using raspi-gpio commands?
Sorry, just now saw this. Did @tindalos 's suggestion work for you?

Re: Automatically set GPIO 18 to PWM on boot

Posted: Wed May 25, 2016 7:40 am
by Jimanez11
Just had a chance to try this today and the fix @tindalos suggested worked like a charm! It was much easier adding in a line to the /boot/config.txt file than going through adafruits tutorial on creating and starting a service, especially for a non-linux user. Thanks to you both @wermy and @tindalos for helping out with this!