Jump to content

Welcome, Guest!

Search the Community

Showing results for tags 'GPIO'.

More search options

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


  • Fruity Forums
    • News and Chat
    • New Members - Say Hello
    • Technical Support
    • Tips/Tricks/Guides/Resources
    • Project Logs!
    • International Fruity Forums


  • Raspberry Pi Linux Distributions
  • Guides
  • Raspberry Pi Emulation Software
  • Homebrew Software!


  • Beginners Guide To The Raspberry Pi
  • Raspberry Pi Tutorials / Guides / How-To's
  • Raspberry Pi Server Guides
  • Raspberry Pi OS Installation Guides

Find results in...

Find results that contain...

Date Created

  • Start


Last Updated

  • Start


Filter by number of...


  • Start





Website URL











Found 6 results

  1. Hello, I've got my first little baby before Christmas, now it has 2 more brothers :-) I stared with different tasks for it, including some personal VPN and file backup stuff. These nice machines use very little power so I can afford to keep some running all the time. My other interest is to use RPi for some weather monitoring and home automation. My first HW related play lead me to get a small LCD working. My choice was Electronic Assembly's DOG series. (EA-DOGL128-6) It's a cheap 128x64 LCD with SPI interface. The language of choice is Python. I decided to share this piece of code here, maybe it helps to someody. It's not a perfect nice piece of code but it just started to work :-) #! /usr/bin/env python import RPi.GPIO as GPIO from font import * import time import os DOG_MOSI = 23 # PIN 36 DOG_CLK = 25 # PIN 37 DOG_A0 = 22 # PIN 38 DOG_CS = 24 # PIN 40 DOG_RES = 17 # PIN 39 class DOGL(): "Class to handle communication with EA DOGL128-6 and some basic operations" def __init__( self, defaultFont=None, defaultSmallFont=None ): self.lcdInit() self.lcdCls() self.defaultFont=defaultFont self.defaultSmallFont=defaultSmallFont def lcdByte( self, d ): "Send a single byte to LCD. To be used by lcdCommand or lcdData" if type(d)==type('a'): d=ord(d) GPIO.output(DOG_CS, 0) #CS=0 for i in range(8): if d&128 > 0: GPIO.output(DOG_MOSI, 1) #MOSI=1 else: GPIO.output(DOG_MOSI, 0) #MOSI=0 d = d<<1 GPIO.output(DOG_CLK, 0) #SCK=0 #time.sleep(0.00001) GPIO.output(DOG_CLK, 1) #SCK=1 #time.sleep(0.001) GPIO.output(DOG_CS, 1) #CS=1 #time.sleep(0.01) def lcdCommand( self, d ): "Send a command byte to the LCD" GPIO.output(DOG_A0, 0) #A0=0 self.lcdByte(d) time.sleep(0.001) def lcdData( self, d ): "Send a data byte to the LCD" GPIO.output(DOG_A0, 1) #RS=1 self.lcdByte(d) def lcdDataSeq( self, t ): "Send a data sequence to the LCD stored in a list, tuple or string" for i in t: self.lcdData(i) def lcdCommandSeq( self, t ): "Send a command sequence to the LCD stored in a list, tuple or string" for i in t: self.lcdCommand(i) def lcdInit( self ): "GPIO and LCD initialization" # Initialize GPIO GPIO.setmode(GPIO.BCM) GPIO.setup(DOG_CS, GPIO.OUT) GPIO.setup(DOG_CLK, GPIO.OUT) GPIO.setup(DOG_MOSI, GPIO.OUT) GPIO.setup(DOG_A0, GPIO.OUT) GPIO.setup(DOG_RES, GPIO.OUT) # Reset display GPIO.output(DOG_RES, 0) time.sleep(0.01) GPIO.output(DOG_RES, 1) time.sleep(0.01) # Send init sequence init_seq = [ 0x40, 0xA1, 0xC0, 0xA6, 0xA2, 0x2F, 0xF8, 0x00, 0x27, 0x81, 0x10, 0xAC, 0x00, 0xAF ] self.lcdCommandSeq(init_seq) def lcdPos( self, page, col ): "Move the cursor to page and col" self.lcdCommand(0xB0 + page) self.lcdCommand(0x10 + ((col&0xf0)>>4) ) self.lcdCommand(0x00 + (col&0x0f) ) def lcdCls( self ): "Clear the entire screen" for i in range(8): self.lcdPos(i,0) self.lcdDataSeq([0x00]*128) def bigRect( self ): "Paint a 1px wide rectangle at the edges of the screen, clear the rest." self.lcdPos(0,0) line = [0xff] + [0x01]*126 + [0xff] self.lcdDataSeq(line) line = [0xff] + [0x00]*126 + [0xff] for i in range(6): self.lcdPos(i+1,0) self.lcdDataSeq(line) self.lcdPos(7,0) line = [0xff] + [0x80]*126 + [0xff] self.lcdDataSeq(line) def printSmallText( self, t, font=None ): "Prints a text to actual position with a 8 bit font" if font==None: font=self.defaultSmallFont for c in t: b = ord(c) if font.has_key(: self.lcdDataSeq(font[b][0]) else: self.lcdDataSeq(font[0x20][0]) def printText( self, t, page=0, col=0, font=None ): "Prints a text with a choosen font to the specified location." if font==None: font=self.defaultFont for i in range(font["data"][2]/8): self.lcdPos(page+i, col) for c in t: b = ord(c) if not font.has_key(: b = 0x20 self.lcdDataSeq(font[b][i]) os.environ["TZ"]='GMT-1' lcd=DOGL(defaultFont=terminal16, defaultSmallFont=terminal8) lcd.bigRect() while True: lcd.lcdPos(2,30) lcd.printSmallText(time.strftime('%Y-%m-%d',time.localtime())) lcd.lcdPos(4,30) lcd.printText(time.strftime('%H:%M:%S',time.localtime()), 4, 15) It looks like this on my desk: I wish you all a good time with these little toys :-)
  2. Hello @ all, i want to build a Home-Automation System an a little SCADA (IEC-104) on Raspberry. Greetings Frank
  3. Looking to get a Sainsmart relay board to help my Pi control my garage door opener via GPIO pins. Can anyone tell me what the difference between a 2-channel and 4-channel relay is? I would assume that I would be able to get away with just a 2 channel for this application? p.s. Should mention that I will also incorporate magnetic switch to check the state of the garage door as well. Thanks!
  4. Installing WiringPi To make use of the Raspberry Pi's gpio pins for hardware testing I nearly always use the wiringPi library to communitcate with the gpio pins. This set of libraries was designed by Gordon at <a href="https://projects.drogon.net/raspberry-pi/wiringpi/" target="_blank">Gordons Projects.</a> It offers an easy way to utilise the gpio outputs and inputs on the Raspberry Pi. To install, open a terminal window and type the following: git clone git://git.drogon.net/wiringPi Once downloaded, to build the libraries, type the following: cd wiringPi./build That's it! Easy peasy! Lets now see how it works. We first need to wire up an LED to our breadboard. See this diagram for instructions on how to do this. As you can see we have connected the LED to actual pin 11 on the Raspberry Pi. This, in wiringPi terms, is gpio 0. The LED is also connected to ground (GND) via a resistor. To power the LED all we do is set the pin as an output. Type the following into the terminal: gpio mode 0 out Then to light it up type: gpio write 0 1 The write command sends current to GPIO 0 (1=send power). To test that power is being sent (if LED doesn't light up) we can type: gpio read 0 If the answer is (1) we know that power is being sent through the pin. If the LED is not lit, just remove from the breadboard and change the orientation of the legs (turn it around). To turn it off simply type: gpio write 0 0 The write command stops current to GPIO 0 (0=stop power). Author drewibbo Category Raspberry Pi Tutorials / Guides / How-To's Submitted 04/26/2013 10:33 AM
  5. Thought I would share some of my Raspberry Pi tests. Rather than being project oriented, most of my tests have had an emphasis on specific sensors/devices and simple Python programs to demonstrate their functionality. This was mainly intended to be a personal log of my Raspberry Pi lab tests, but if anyone can benefit or wants to add their observations so much the better. Hardware: Raspberry Pi, Gertboard (not essential to test) and Parallax Motion Sensor #555-28027 (Radio Shack 276-135). While there are library modules (wiringPi and RPi.GPIO for example) available that handle interrupts, I took a more direct approach for this test and used the poll function in the GPIO facility in Linux. For the sake of clarity, I will first show using this method to check the state of a GPIO pin without the benefit of using an interrupt. Before running the program, a user interface must be created for GPIO25 by executing these statements from the prompt: sudo su echo 25 >/sys/class/gpio/export # create a user interface for GPIO25 echo in >/sys/class/gpio25/direction # configure GPIO25 as an input This creates a directory with several files representing the configuration and state of GPIO25. For example, the 'value' file will contain a '0' if GPIO is low or an '1' if GPIO is high. The 'direction' file contains 'in' after GPIO25 is created. We could set the contents of any of these files, but their default values are suitable for this next test. I am using the same Parallax motion sensor tested earlier, except BUF1 is jumpered to GPIO25 on my Gertboard. As before, the motion sensor outputs a high for 3 seconds when it senses motion. Otherwise its output remains at low. gpio25-read.py import time f = open('/sys/class/gpio/gpio25/value', 'r') # create a read file object while 1: f.seek(0) # reset pointer location in file to beginning motion = f.read(1) # read 1st byte of read file object if motion == '1': print('Warning! Motion Detected!') else: print('All is quiet...') time.sleep(1) The above program simply hangs in a loop and reads the pin every second. The downside of this approach is the cpu is given no time to do anything else. Before running the next program using interrupts, we make sure we have created a user interface for GPIO25 by executing these statements from the prompt: sudo su echo 25 >/sys/class/gpio/export # create a user interface for GPIO25 echo in >/sys/class/gpio25/direction # configure GPIO25 as an input echo both >/sys/class/gpio25/edge # configure GPIO25 to recognize both rising & falling transitions gpio25-interrupt.py import time import select import sys f = open('/sys/class/gpio/gpio25/value', 'r') # create a read file object myInterrupt = select.poll() # create a polling object myInterrupt.register(f, select.POLLPRI) # add read file object as a source to satisfy poll requests while 1: myInterrupt.poll() # wait for an interrupt f.seek(0) # reset pointer location in file to beginning motion = f.read(1) # read 1st byte of read file object if motion == '1': print('Warning! Motion Detected!') else: print('All is quiet...') With this method a user would be free to add code putting the cpu to work doing other functions, such as controlling other GPIO pins, performing caculations, etc.

About Us

Bringing you the latest Raspberry Pi news, tutorials and user forum.

The Fruity Computer

  • Create New...