HeadnotesMany equations and formulas look intimidating. However, when you hunt them down, they are definitely not! Just papertigers!
Now let's hunt the papertiger.
wiringPiSetup: Unable to open /dev/mem or /dev/gpiomem: Permission denied.
Aborting your program because if it can not access the GPIO
hardware then it most certianly won’t work
Try running with sudo?
sudo usermod -a -G gpio user_name % change the owner and group respectively sudo chown root.gpio /dev/gpiomem sudo chmod g+rw /dev/gpiomem
If the problem is still unsolved, try to deactivate your virtual enviroment if used. Otherwise, try to use
sudo chown root.gpio /dev/mem && sudo chmod g+rw /dev/mem
This both two commands have the same to do with each other.
sudo usermod -a -G target_group user_name sudo adduser user_name target_group
FootnotesThere are many excellent tutorials out there. Some tutorials are too intuitive and it's helpful, but you cannot get it straight on the math details. Some focused on dymestifying math. Some focused on code. I found the best tutorials that give you the conceptual ideas and are possible for implementation without being blind to the math details. Drop a comment if I failed. It would be really appreciable.
Lachlan Chen, "Raspberry Pi New User Cannot Access GPIO," in EarnFromScratch, 四月 24, 2019, https://www.earnfs.com/zh/html/1912.htm.
title=Raspberry Pi New User Cannot Access GPIO,
year=四月 24, 2019