Obsah

Raspberry PI GPIO

Raspbery PI B

cat /proc/cpuinfo 
processor	: 0
model name	: ARMv6-compatible processor rev 7 (v6l)
BogoMIPS	: 2.00
Features	: half thumb fastmult vfp edsp java tls 
CPU implementer	: 0x41
CPU architecture: 7
CPU variant	: 0x0
CPU part	: 0xb76
CPU revision	: 7

Hardware	: BCM2708
Revision	: 000f                   <---------- revize 2.0
Serial		: 00000000a2fe0aff

Raspberry PI zero W

Upozornění

Knihovny

apt-get install git-core gcc sudo
mkdir gpiotest
cd gpiotest
git clone git://git.drogon.net/wiringPi
cd wiringPi
./build
apt-get install python-rpi.gpio python3-rpi.gpio

Blikání LED

Python RPi.GPIO

import RPi.GPIO as GPIO
import time
 
GPIO.setmode(GPIO.BCM)
GPIO.setup(18, GPIO.OUT)
while True:
        GPIO.output(18, GPIO.HIGH)
        time.sleep(.5)
        GPIO.output(18, GPIO.LOW)
        time.sleep(.5)

Wiring

root@piAP:/tmp# gpio readall
 +-----+-----+---------+------+---+-Model B2-+---+------+---------+-----+-----+
 | BCM | wPi |   Name  | Mode | V | Physical | V | Mode | Name    | wPi | BCM |
 +-----+-----+---------+------+---+----++----+---+------+---------+-----+-----+
 |     |     |    3.3v |      |   |  1 || 2  |   |      | 5v      |     |     |
 |   2 |   8 |   SDA.1 |   IN | 1 |  3 || 4  |   |      | 5V      |     |     |
 |   3 |   9 |   SCL.1 |   IN | 1 |  5 || 6  |   |      | 0v      |     |     |
 |   4 |   7 | GPIO. 7 |   IN | 1 |  7 || 8  | 1 | ALT0 | TxD     | 15  | 14  |
 |     |     |      0v |      |   |  9 || 10 | 1 | ALT0 | RxD     | 16  | 15  |
 |  17 |   0 | GPIO. 0 |   IN | 0 | 11 || 12 | 0 | IN   | GPIO. 1 | 1   | 18  |
 |  27 |   2 | GPIO. 2 |   IN | 0 | 13 || 14 |   |      | 0v      |     |     |
 |  22 |   3 | GPIO. 3 |   IN | 0 | 15 || 16 | 0 | IN   | GPIO. 4 | 4   | 23  |
 |     |     |    3.3v |      |   | 17 || 18 | 0 | IN   | GPIO. 5 | 5   | 24  |
 |  10 |  12 |    MOSI |   IN | 0 | 19 || 20 |   |      | 0v      |     |     |
 |   9 |  13 |    MISO |   IN | 0 | 21 || 22 | 0 | IN   | GPIO. 6 | 6   | 25  |
 |  11 |  14 |    SCLK |   IN | 0 | 23 || 24 | 1 | IN   | CE0     | 10  | 8   |
 |     |     |      0v |      |   | 25 || 26 | 1 | IN   | CE1     | 11  | 7   |
 +-----+-----+---------+------+---+----++----+---+------+---------+-----+-----+
 |  28 |  17 | GPIO.17 |   IN | 0 | 51 || 52 | 0 | IN   | GPIO.18 | 18  | 29  |
 |  30 |  19 | GPIO.19 |   IN | 0 | 53 || 54 | 0 | IN   | GPIO.20 | 20  | 31  |
 +-----+-----+---------+------+---+----++----+---+------+---------+-----+-----+
 | BCM | wPi |   Name  | Mode | V | Physical | V | Mode | Name    | wPi | BCM |

C

#include <stdio.h>
#include <wiringPi.h>
 
#define LED     1  // pin 1 is BCM_GPIO 18.
 
int main (void)
{
  printf ("Raspberry Pi blink\n") ;
 
  wiringPiSetup () ;
  pinMode (LED, OUTPUT) ;
 
  for (;;)
  {
    digitalWrite (LED, HIGH) ;  // On
    delay (500) ;               // mS
    digitalWrite (LED, LOW) ;   // Off
    delay (500) ;
  }
  return 0 ;
}

Shell

PIN=1 # pin 1 is BCM_GPIO 18.
 
gpio mode $PIN out
 
while true; do
  gpio write $PIN 1
  sleep 0.5
  gpio write $PIN 0
  sleep 0.5
done

DHT22/AM2302

apt-get install pip
pip install adafruit_python_dht

Collecting adafruit_python_dht
  Downloading Adafruit_Python_DHT-1.1.2.tar.gz
    Complete output from command python setup.py egg_info:
    Could not detect if running on the Raspberry Pi or Beaglebone Black.  If this failure is unexpected, you can run again with --force-pi or --force-bbb parameter to force using the Raspberry Pi or Beaglebone Black respectively.
git clone https://github.com/adafruit/Adafruit_Python_DHT.git
cd Adafruit_Python_DHT/
python setup.py install
examples/AdafruitDHT.py 2302 4
Temp=21.8*  Humidity=73.1%

MP3/radio přehrávač

UART

/etc/initab
T0:23:respawn:/sbin/getty -L ttyAMA0115200 VT100
/boot/cmdline.txt 
dwc_otg.lpm_enable=0 console=ttyAMA0,115200 kgdboc=ttyAMA0,115200 console=tty1 root=/dev/mmcblk0p5 rootfstype=ext2 rootwait

SPI

Test-ADC_vyrez.py
def adc(chan, clock, mosi, miso, cs):
    if((chan < 0) or (chan > 7)):
        return -1
    GPIO.output(cs, True)           # preventivně
    GPIO.output(clock, False)
    GPIO.output(cs, False)          # aktivujeme slave
    cmd = chan
    cmd |= 0x18                     # nastavíme start bit + SGL bit
    cmd <<= 3
 
    for i in range(5):              # pošleme start, SGL, channel
        if(cmd & 0x80):
            GPIO.output(mosi, True)
        else:
            GPIO.output(mosi, False)
        cmd <<= 1
        GPIO.output(clock, True)
        GPIO.output(clock, False)
    result = 0
    for i in range(12):             # načteme mezeru (čas pro čtení hodnoty) + nulový bit + 10 bitů
        GPIO.output(clock, True)
        GPIO.output(clock, False)
        result <<= 1
        if(GPIO.input(miso)):
             result |= 0x1
    GPIO.output(cs, True)
    result >>= 
    return result 

433 Mhz