Automatically set GPIO 18 to PWM on boot

General GBZ-related chat goes here. Share ideas, tips and tricks, or ask questions that don't fit into the hardware/software help forums.
Post Reply
Jimanez11
Posts: 11
Joined: Sun May 08, 2016 3:02 pm

Automatically set GPIO 18 to PWM on boot

Post by Jimanez11 » Tue May 24, 2016 2:07 pm

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!

User avatar
wermy
Site Admin
Posts: 1346
Joined: Tue May 03, 2016 8:51 pm
Has thanked: 620 times
Been thanked: 1322 times
Contact:

Re: Automatically set GPIO 18 to PWM on boot

Post by wermy » Tue May 24, 2016 2:16 pm

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.
ImageImageImageImage

Jimanez11
Posts: 11
Joined: Sun May 08, 2016 3:02 pm

Re: Automatically set GPIO 18 to PWM on boot

Post by Jimanez11 » Tue May 24, 2016 2:44 pm

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.

Jimanez11
Posts: 11
Joined: Sun May 08, 2016 3:02 pm

Re: Automatically set GPIO 18 to PWM on boot

Post by Jimanez11 » Tue May 24, 2016 5:33 pm

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?

tindalos
Posts: 5
Joined: Sat May 14, 2016 6:38 pm
Been thanked: 9 times

Re: Automatically set GPIO 18 to PWM on boot

Post by tindalos » Tue May 24, 2016 9:29 pm

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

User avatar
wermy
Site Admin
Posts: 1346
Joined: Tue May 03, 2016 8:51 pm
Has thanked: 620 times
Been thanked: 1322 times
Contact:

Re: Automatically set GPIO 18 to PWM on boot

Post by wermy » Tue May 24, 2016 10:14 pm

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?
ImageImageImageImage

Jimanez11
Posts: 11
Joined: Sun May 08, 2016 3:02 pm

Re: Automatically set GPIO 18 to PWM on boot

Post by Jimanez11 » Wed May 25, 2016 7:40 am

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!

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest