fan
Posts: 17
Joined: Sat Jun 11, 2016 10:39 am

Easiest programming language for controlling gpio pins

Sun Jun 12, 2016 12:10 pm

I got a pi and I want to start having fun with gpio pins, but there is one problem I am so lost in all of these programming languages. I know a little of c (printf,scanf,do,while,if....) but I am so lost righ now. Can you guys link me some tutorial and give me some tips. Basically all I want is to control (power) some LED diodes , transistor and releys with that program. My goal is to make a program that runs by itself (turning gpio pins on every few hours).


User avatar
joan
Posts: 14473
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: Easiest programming language for controlling gpio pins

Sun Jun 12, 2016 1:12 pm

http://elinux.org/RPi_GPIO_Code_Samples

My feeling is that a Python based solution may be your easiest.

User avatar
flatmax
Posts: 336
Joined: Thu May 26, 2016 10:36 pm

Re: Easiest programming language for controlling gpio pins

Sun Jun 12, 2016 1:38 pm

The absolute simplest way to alter gpio pins ... at least for first exploration is just in a terminal ... like so ... will send 1 and 0 to gpio11 ...
open a terminal and change to super user with sudo -i and then :
echo 11 > /sys/class/gpio/export
echo out > /sys/class/gpio/gpio11/direction
echo 1 > /sys/class/gpio/gpio11/value
echo 0 > /sys/class/gpio/gpio11/value

Matt
Check the Ultra 2 sound card - use our shop instead of Amazon Europe (Amazon USA is live).
Sound card for the Raspberry Pi with inbuilt microphone : www.audioinjector.net
Audio Inector Octo multitrack GPIO sound card

derekiwi
Posts: 13
Joined: Tue May 31, 2016 9:04 am

Re: Easiest programming language for controlling gpio pins

Sun Jun 12, 2016 2:34 pm

Hi Flatmax,

I am also a total newbie to Pi, Linux etc. I started with RPi.GPIO, and it is easy to use and learn. I was going to attach a sample for you but the forum does not let me, so pasted in below.. Currently having a look at wiringPi - seems just as easy and documentation is better. But I would start with RPi.GPIO.

RPi.GPIO should be installed on your Raspberry already if you are using Rasbian and have the latest version. Otherwise ....
https://sourceforge.net/p/raspberry-gpi ... i/install/ (note that you do not need Mercurial)

http://wiringpi.com/

Cheers, Derek

#!/usr/bin/env python
#
import time
import sys
import RPi.GPIO as GPIO
#
# gpio may still open from last session if abnormally exited
GPIO.setwarnings(False)
#
# set to defining by header pins, instead of BCM
GPIO.setmode(GPIO.BOARD)
#
print ("System Setup.")
print (GPIO.RPI_INFO)
#
# set up gpio ehader pin 35 (BCM and GPIO 19) as output
TestPin = 35
GPIO.setup (TestPin, GPIO.OUT)
#
print ("Main loop start....")
#
#############################
# Main loop
#############################
#
try:
while True:
# toggle the pin each loop
GPIO.output(TestPin, True)
time.sleep(0.25)
GPIO.output(TestPin, False)
time.sleep(0.25)
#
# press Ctl-c to exit
except KeyboardInterrupt:
GPIO.cleanup()
print ("Cleaned up. Bye.")
sys.exit(0)
#
##############################

User avatar
kusti8
Posts: 3439
Joined: Sat Dec 21, 2013 5:29 pm
Location: USA

Re: Easiest programming language for controlling gpio pins

Sun Jun 12, 2016 2:35 pm

derekiwi wrote:Hi Flatmax,

I am also a total newbie to Pi, Linux etc. I started with RPi.GPIO, and it is easy to use and learn. I was going to attach a sample for you but the forum does not let me, so pasted in below.. Currently having a look at wiringPi - seems just as easy and documentation is better. But I would start with RPi.GPIO.

RPi.GPIO should be installed on your Raspberry already if you are using Rasbian and have the latest version. Otherwise ....
https://sourceforge.net/p/raspberry-gpi ... i/install/ (note that you do not need Mercurial)

http://wiringpi.com/

Cheers, Derek

Code: Select all

#!/usr/bin/env python
# 
import time
import sys
import RPi.GPIO as GPIO
#
# gpio may still open from last session if abnormally exited
GPIO.setwarnings(False)
#
# set to defining by header pins, instead of BCM
GPIO.setmode(GPIO.BOARD)
#
print ("System Setup.")
print (GPIO.RPI_INFO)
#
# set up gpio ehader pin 35 (BCM and GPIO 19) as output
TestPin = 35
GPIO.setup (TestPin, GPIO.OUT)
#
print ("Main loop start....")
#
#############################
# Main loop
#############################
#
try:
    while True:
        # toggle the pin each loop
        GPIO.output(TestPin, True)
        time.sleep(0.25)
        GPIO.output(TestPin, False)
        time.sleep(0.25)
#
# press Ctl-c to exit
except KeyboardInterrupt:
    GPIO.cleanup()
    print ("Cleaned up. Bye.")
    sys.exit(0)
#
Put your code in code brackets, so that indentation is kept. Fixed for you.
There are 10 types of people: those who understand binary and those who don't.

timrowledge
Posts: 1290
Joined: Mon Oct 29, 2012 8:12 pm
Location: Vancouver Island
Contact: Website

Re: Easiest programming language for controlling gpio pins

Sun Jun 12, 2016 3:16 pm

Scratch. It's already loaded, it has examples, there is documentation.
Making Smalltalk on ARM since 1986; making your Scratch better since 2012

User avatar
recantha2
Posts: 287
Joined: Wed Nov 14, 2012 9:34 am
Location: Potton, Bedfordshire
Contact: Website Facebook Twitter

Re: Easiest programming language for controlling gpio pins

Sun Jun 12, 2016 7:14 pm

Python, using the GPIO Zero library would seem to be appropriate.

from gpiozero import LED

red = LED(4)
red.on()
--
Michael Horne - @recantha
Raspberry Pi blog - http://www.recantha.co.uk/blog

Cambridge Raspberry Jam
Website: http://camjam.me
Facebook: https://www.facebook.com/cambridgeraspberryjam
Follow the Cambridge Raspberry Jam on Twitter - @cambridgejam

User avatar
R61zt
Posts: 64
Joined: Fri Feb 01, 2013 3:55 pm

Re: Easiest programming language for controlling gpio pins

Sun Jun 12, 2016 8:22 pm

I'd recommend python for what you are doing.

User avatar
ben_nuttall
Raspberry Pi Foundation Employee & Forum Moderator
Raspberry Pi Foundation Employee & Forum Moderator
Posts: 231
Joined: Sun Aug 19, 2012 11:19 am
Location: Cambridge, UK
Contact: Website

Re: Easiest programming language for controlling gpio pins

Mon Jun 13, 2016 10:49 am

recantha2 wrote:Python, using the GPIO Zero library would seem to be appropriate.

from gpiozero import LED

red = LED(4)
red.on()
GPIO Zero was designed to be the easiest way of programming GPIO devices. It's pre-installed with Raspbian and easy to get started. Just open IDLE (preferably Python 3) and type commands like the above!

See the GPIO Zero documentation for more information, particularly the recipes page for lots of examples of everyday project starter code.

Also see the Foundation's Physical computing with Python resource
Community Manager - Raspberry Pi Foundation
Author of GPIO Zero and creator of piwheels

fan
Posts: 17
Joined: Sat Jun 11, 2016 10:39 am

Re: Easiest programming language for controlling gpio pins

Mon Jun 13, 2016 4:48 pm

Thanks guys for your help , without you I wouldn't know what to do. I will try gpio zero and then move to pyton or some c solution. Thanks

Return to “Beginners”