Last active
February 2, 2022 21:58
-
-
Save Lauszus/5193fe308655c44ea59e3f05dce24749 to your computer and use it in GitHub Desktop.
Examples of setting the drive strength of a Raspberry Pi GPIO PAD using either pigpio or WiringPi
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// gcc -Wall -O3 -pthread -o set_drive_strength pigpio.c -lpigpio | |
#include <stdlib.h> | |
#include <pigpio.h> | |
int main(int argc, char *argv[]) { | |
if (gpioInitialise() < 0) return 1; | |
int strength_ma = argc > 1 ? atoi(argv[1]) : 8; | |
// Set the PAD drive strength | |
if (gpioSetPad(0, strength_ma) < 0) return 1; // GPIO 0-27 | |
if (gpioSetPad(1, strength_ma) < 0) return 1; // GPIO 28-45 | |
if (gpioSetPad(2, strength_ma) < 0) return 1; // GPIO 46-53 | |
gpioTerminate(); | |
return 0; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// gcc -Wall -O3 -pthread -o set_drive_strength wiringpi.c -lwiringPi | |
#include <stdlib.h> | |
#include <wiringPi.h> | |
int main(int argc, char *argv[]) { | |
if (wiringPiSetup() < 0) return 1; | |
int strength_ma = argc > 1 ? atoi(argv[1]) : 8; | |
// 1-16 -> 0-7 | |
int pad_strength = strength_ma; | |
pad_strength += 1; | |
pad_strength /= 2; | |
pad_strength -= 1; | |
// Set the PAD drive strength | |
setPadDrive(0, pad_strength & 7); // GPIO 0-27 | |
setPadDrive(1, pad_strength & 7); // GPIO 28-45 | |
setPadDrive(2, pad_strength & 7); // GPIO 46-53 | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment