mars 23

RadioPi

But: transformer un vieux poste radio a lampes HS des années 60/70 récupéré en vide grenier en poste mp3 avec un raspberry Pi.

Au niveau Matériel :
– un vieux poste radio a lampes HS des années 60/70
– un Raspberry Pi
– un ampli 2.1 20W
– 3 HP 5W
– un Afficheur 128×128 pixels
– deux encodeurs rotatifs
– un disque dur SSD avec adaptateur USB
– horloge RTC en I2C
– bande de led RGB
– deux alimentations 220v/5V  ( une pour la partie Audio , l’autre pour la partie “numérique” 5A) et conneteur alimentation et interrupteur M/A
– un ventilateur 5V avec grille
– un disque dur SSD ( dans mon cas un 120Go)

ou trouvez les divers éléments :
1 x Raspberry Pi
2 x 3-inch-Full-Range-Speaker-4ohm-5W
1 x 4-Pouces Haut-Parleur-4-Ohm-15-W graves
1x Ampli 2.1 20W 5V
2 x Encodeur rotatif
1 x Horloge I2C 
2 x alimentation 220v -5v 3A
2 x câble USB
1 x câble réseau
1 x ventilateur 5v+1 x grille 60mm
1 x interrupteur + 1 x connecteur alimentation

 

Au niveau logiciel :
– Raspbian lite dernière version
– daemon mpd
– python3
– scripts divers ( gestion des encodeurs rotatif en émulation clavier UP,DOWN,LEFT,RIGHT,ENTER,PLAUY/PAUSE).

 

Photos de la transformation :

bon j’avoue en étant électronicien / informaticien , je déteste la partie “mécanique” ( boitier et autre ) , c’est donc mon beau-frère qui s’occupe de cette partie en plus ayant son Fablab perso il a tous les outils nécessaire

pour remplacer la lampe de “l’Œil magique” un afficheur 1.44” SPI  de 128×128 pixels qui permettra d’afficher divers menu et aussi la pochette de la piste en cours a base de st7735 / ili9163

 

câblage des GPIO ( provisoire)

Name Usage Board Usage Name
3.3V RTC.VCC 01 | | 02 LED.VCC 5V
GPIO02 RTC.SDA 03 | | 04 LCD.VCC 5V
GPIO03 RTC.SCL 05 | | 06 GND
GPIO04 07 | | 08 U_TXD GPIO14
GND RTC.GND 09 | | 10 U_RXD GPIO15
GPIO17 ENC1.B 11 | | 12 SPI1_CE0 GPIO18
GPIO27 ENC1.A 13 | | 14 LCD.GND GND
GPIO22 ENC1.SW 15 | | 16 LCD.LED GPIO23
3.3V 17 | | 18 LCD.A0 GPIO24
GPIO10 LCD.SDA 19 | | 20 GND
GPIO09 21 | | 22 LCD.RST GPIO25
GPIO11 LCD.SCK 23 | | 24 LCD.CS GPIO08
GND ENC1.GND 25 | | 26 GPIO07
ID_SD0 * 27 | | 28 * ID_SC1
GPIO05 ENC2.A 29 | | 30 FAN.GND GND
GPIO06 ENC2.B 31 | | 32 FAN.PWM GPIO12
GPIO13 ENC2.SW 33 | | 34 LED.GND GND
GPIO19 SPI1_MISO 35 | | 36 GPIO16
GPIO26 37 | | 38 LED.DI GPIO20
GND ENC2.GND 39 | | 40 SPI1_SCLK GPIO21

installation logicielle , j’ai décidé de me passer de carte SD sur le Raspberry et booter directement sur le SSD ( voir  article frambroise 314 )

j’ai fait 3 partions sur le hdd (/dev/sda1 vfat 100M , /dev/sda2 ext4 8Go , /dev/sda3  ext4 le reste du disque pour stockage des fichiers audios )
mon /etc/fstab

proc            /proc           proc    defaults          0       0
PARTUUID=0c9f0562-01  /boot           vfat    defaults          0       2
PARTUUID=0c9f0562-02  /               ext4    defaults,noatime  0       1
PARTUUID=0c9f0562-03  /var/lib/mpd    ext4    defaults,noatime  0       1

une fois raspbian lite installé et le raspberry pi en route on commence a installer les paquets nécessaire :

sudo apt install python3-pygame python-pygame python-spidev python3-spidev
sudo apt install mpd python-pip python3-pip
sudo apt install evtest telnet samba lame flac faad vorbis-tools 
sudo apt install mc alsa-utils libmpdclient-dev cython

pip install python-uinput
pip install python-mpd2
pip3 install python-mpd2

fichier a créer / modifier

  • /etc/modprobe.d/fbtft.conf
options fbtft_device name=fb_ili9163 gpios=reset:25,dc:24,led:23 speed=40000000 rotate=90 bgr=1 custom=1 fps=60
  • /etc/modules-load.d/fbtft.conf
spi-bcm2835
fbtft_device
  • /etc/modules-load.d/RotaryKey.conf
uinput

logiciels a installer /compiler , je met tous dans /opt/scripts

cd /opt
mkdir scripts
cd /opt/scripts
  • Automatic library-wide shuffle for mpd ( gestion playlist aléatoire )
git clone https://github.com/joshkunz/ashuffle.git
cd ashuffle/
make
sudo make install
  • mpd Album Art
git clone https://github.com/jameh/mpd-album-art.git
cd mpd-album-art
sudo python3 setup.py install
  • gestion du clavier virtuel depuis les 2 encodeurs rotatifs
    • /opt/scripts/RadioKey.py ( script pour gerer le “clavier”) pour l’instant un seul encodeur géré UP,DOWN,ENTER
      #!/usr/bin/env python
      import RPi.GPIO as GPIO
      import uinput
      from time import sleep
      
      # version PCB
      pin_a1 = 37 #GPIO  13
      pin_b1 = 35 #GPIO  19
      pin_sw1= 33 #GPIO  26
      pin_a2 = 36 #GPIO  16
      pin_b2 = 38 #GPIO  20
      pin_sw2= 40 #GPIO  21
      
      GPIO.setmode(GPIO.BOARD)
      GPIO.setup(pin_a1,  GPIO.IN, pull_up_down=GPIO.PUD_UP)
      GPIO.setup(pin_b1,  GPIO.IN, pull_up_down=GPIO.PUD_UP)
      GPIO.setup(pin_sw1, GPIO.IN, pull_up_down=GPIO.PUD_UP)
      GPIO.setup(pin_a2,  GPIO.IN, pull_up_down=GPIO.PUD_UP)
      GPIO.setup(pin_b2,  GPIO.IN, pull_up_down=GPIO.PUD_UP)
      GPIO.setup(pin_sw2, GPIO.IN, pull_up_down=GPIO.PUD_UP)
      
      device = uinput.Device([uinput.KEY_UP, uinput.KEY_DOWN,uinput.KEY_ENTER,uinput.KEY_PLAYPAUSE,uinput.KEY_LEFT,uinput.KEY_RIGHT])
      seq_a1 = seq_b1 = seq_sw1=0
      seq_a2 = seq_b2 = seq_sw2=0
      
      def on_Sw(pin):
          sw = GPIO.input(pin_sw2)
          if sw == 0:
              device.emit_click(uinput.KEY_ENTER)
          sw = GPIO.input(pin_sw1)
          if sw == 0:
              device.emit_click(uinput.KEY_PLAYPAUSE)
      
      def on_edge1(pin):
          global seq_a1, seq_b1
          a1 = GPIO.input(pin_a1)
          b1 = GPIO.input(pin_b1)
          seq_a1 = ((seq_a1 << 1) | a1) & 0b1111
          seq_b1 = ((seq_b1 << 1) | b1) & 0b1111
          if seq_a1 == 0b0011 and seq_b1 == 0b1001:
              device.emit_click(uinput.KEY_UP)
          elif seq_a1 == 0b1001 and seq_b1 == 0b0011:
              device.emit_click(uinput.KEY_DOWN)
      
      def on_edge2(pin):
          global seq_a2, seq_b2
          a2 = GPIO.input(pin_a2)
          b2 = GPIO.input(pin_b2)
          seq_a2 = ((seq_a2 << 1) | a2) & 0b1111
          seq_b2 = ((seq_b2 << 1) | b2) & 0b1111
          if seq_a2 == 0b0011 and seq_b2 == 0b1001:
              device.emit_click(uinput.KEY_LEFT)
          elif seq_a2 == 0b1001 and seq_b2 == 0b0011:
              device.emit_click(uinput.KEY_RIGHT)
      
      GPIO.add_event_detect(pin_a1,  GPIO.BOTH, callback=on_edge1)
      GPIO.add_event_detect(pin_b1,  GPIO.BOTH, callback=on_edge1)
      GPIO.add_event_detect(pin_a2,  GPIO.BOTH, callback=on_edge2)
      GPIO.add_event_detect(pin_b2,  GPIO.BOTH, callback=on_edge2)
      GPIO.add_event_detect(pin_sw1, GPIO.BOTH, callback=on_Sw)
      GPIO.add_event_detect(pin_sw2, GPIO.BOTH, callback=on_Sw)
      
      try:
          while True:
              sleep(300)
      except KeyboardInterrupt:
          GPIO.cleanup()
      

       

    • Service RadioKey ( deamon clavier ) : /etc/systemd/system/RadioKey.service
      [Unit]
      Description=Python start + foreground + keyboard input.
      Requires=multi-user.target
      After=multi-user.target rc-local.service
      AllowIsolate=yes
      
      [Service]
      Type=simple
      ExecStart=/usr/bin/python /opt/scripts/RadioKey.py
      
      [Install]
      WantedBy=multi-user.target
    • activation du service
      systemctl daemon-reload
      service RadioKey start
      
    • test du clavier virtuel
  • script au démarrage qui affiche l’IP du pi sur l’afficheur 128×128 ( /opt/scripts/ip.py) pendant 10 secondes
    #!/usr/bin/env python
    import os
    import sys
    import time
    import pygame
    import socket
    
    def get_ip_address():
     ip_address = '';
     s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
     try:
         s.connect(("8.8.8.8",80))
         ip_address = s.getsockname()[0]
         s.close()
         return ip_address
     except socket.error, msg:
         return "0.0.0.0"
    os.environ["SDL_FBDEV"] = "/dev/fb1"
    os.environ['SDL_VIDEODRIVER']="fbcon"
    mapMask= pygame.image.load("/home/pi/mask.png")
    
    def displaytext(text,size,line,color,clearscreen):
        if clearscreen:
            screen.fill((255,0,0))
    
        font = pygame.font.Font(None,size)
        text = font.render(text,0,color)
        rotated = pygame.transform.rotate(text,0)
        textpos = rotated.get_rect()
        textpos.centerx = 64
        textpos.centery = 64
        screen.blit(rotated,textpos)
    
    def main():
        global screen
        pygame.init()
        pygame.mouse.set_visible(0)
        size = width,height = 128,128
        screen = pygame.display.set_mode(size)
        str=get_ip_address() 
        displaytext( str,26,1,(255,255,255),True)
        screen.blit(mapMask, (0,0))
        pygame.display.flip()
        time.sleep(10)
        pygame.quit()
        exit()
    if __name__ == '__main__':
        main()
    
  • interface web pour playlist (https://www.ympd.org/ )
    cd /opt/scripts
    wget https://www.ympd.org/downloads/ympd-1.2.3-armhf.tar.bz2
    tar -xvf ympd-1.2.3-armhf.tar.bz2
    sudo ./ympd --webport 80
  • partage dossier réseau ( /etc/samba/smb.conf )
    #======================= Global Settings =======================
    [global]
       workgroup = WORKGROUP
       dns proxy = no
       log file = /var/log/samba/log.%m
       max log size = 1000
       syslog = 0
       panic action = /usr/share/samba/panic-action %d
       server role = standalone server
       passdb backend = tdbsam
       obey pam restrictions = yes
       unix password sync = yes
       passwd program = /usr/bin/passwd %u
       passwd chat = *Enter\snew\s*\spassword:* %n\n *Retype\snew\s*\spassword:* %n\n *password\supdated\ssuccessfully* .
       pam password change = yes
       map to guest = bad user
       usershare allow guests = yes
    
    #======================= Share Definitions =======================
    [home]
       browseable = yes
       create mask = 0700
       directory mask = 0700
       guest ok = yes
       path = /home/pi
       force user =  pi
       force group = pi
       read only = No
    
    [scripts]
       browseable = yes
       create mask = 0700
       directory mask = 0700
       guest ok = yes
       path = /opt/scripts
       force user =  pi
       force group = pi
       read only = No
    
    [Media]
       browseable = yes
       create mask = 0700
       directory mask = 0700
       guest ok = yes
       path = /var/lib/mpd/
       force user =  mpd
       force group = audio
       read only = No
    
    

     

  • gestion de led RGB ws2812 , pour cela on va activer le 2eme port SPI ( raspberry pi 3
    dans /boot/config.txt ajouter/modifier

    spidev.bufsiz=32768
    dtoverlay=spi1-1cs
    

    ensuite on vas ajouter py-spidev et  ws2812-spi

    sudo apt install python-spidev python3-spidev
    
    cd /opt/scripts
    git clone https://github.com/doceme/py-spidev.git
    cd py-spidev
    make
    make install
    
    cd /opt/scripts
    git clone https://github.com/joosteto/ws2812-spi.git
    cd ws2812-spi
    

    en fonction du Pi utilisé il faut modifier le fichier ws2812.py , dans def write2812_numpy4(spi,data): commenter toutes les lignes spi.xfer  et de-commenter celle ci : spi.xfer(tx.tolist(), int(4/.55e-6))
    ensuite

    sudo python setup.py install

    on vas tester le bandeau :

    cd /opt/scripts
    nano loop.py

    dans mon cas il y auras 20 led RGB ws2812 donc :

    import spidev
    import ws2812
    import time
    import getopt
    
    def test_loop(spi, nLED=8, intensity=20):
        stepTime=0.1
        iStep=0
        while True:
            d=[[0,0,0]]*nLED
            d[iStep%nLED]=[intensity]*3
            ws2812.write2812(spi, d)
            iStep=(iStep+1)%nLED
            time.sleep(stepTime)
    
    if __name__=="__main__":
        spi = spidev.SpiDev()
        spi.open(1,0)
    
        test_loop(spi, nLED=20)
    

    puis python loop.py

  • (en cours de dev …….)  gestion du bandeau lumineux en fonction de la musique ( basé sur https://github.com/nvbn/soundlights)
    cd /opt/scripts
    git clone https://github.com/nvbn/soundlights.git
    ./autogen.sh
    ./configure
    make
    sudo make install
    création du fichier de config : nano /opt/scripts/config.led :
    [general]
    mode = normal
    framerate = 60
    bars = 20
    
    [input]
    method = fifo
    source = /tmp/mpd.fifo
    
    [output]
    method =raw
    channels = stereo
    bit_format = 8bit
    
    [eq]
    1=2
    2=2
    3=1
    4=1
    5=0.5
    

    fichier /opt/scripts/soundlights.py

    import sys
    import time
    import spidev
    import ws2812
    
    COLORS_COUNT = 255
    nLED=20
    spi = spidev.SpiDev() 
    spi.open(1,0)
    d=[(0,0,0)]*nLED
    ws2812.write2812(spi, d)
    
    def _get_spaced_colors(n):
        max_value = 4144959
        interval = int(max_value / n)
        colors = [hex(i)[2:].zfill(6) for i in range(0, max_value, interval)]
        return [ (int(i[:2], 16), int(i[2:4], 16), int(i[4:], 16)) for i in colors]
    
    def _handle_stdin(colors,d):
        while True:
            try:
                ws2812.write2812(spi, colors)
            except Exception as e:
                print e
    
    if __name__ == '__main__':
        _handle_stdin(_get_spaced_colors(COLORS_COUNT),d)
    

    puis on teste en lançant :

    cava -p config.led | python soundlights.py

     

  • version alpha partie affichage covertArt piste en cours et passer piste suivante/précédente
    #!/usr/bin/python3
    # -*- coding: utf-8 -*-
    import pygame
    import math
    import os
    import time
    import sys
    import mpd_album_art
    from mpd import (MPDClient, CommandError)
    
    # ecran TFT en /dev/fb1
    os.putenv("SDL_VIDEODRIVER", "fbcon")
    os.environ["SDL_FBDEV"] = "/dev/fb1"
    
    # pour daemon mpd
    HOST = 'localhost'
    PORT = '6600'
    CON_ID = {'host':HOST, 'port':PORT}
    def mpdConnect(client, con_id):
        try:
            client.connect(**con_id)
        except:
            return False
        return True
    
    #maj covertArt
    def update_folder(client,pygame,window):
        status = client.status()
        now_playing = client.currentsong()
        print ('file    : ' + now_playing.get('file'))
    # chercher coverart et lien vers "/home/pi/.covers/current"
        grabber = mpd_album_art.Grabber(
            save_dir="/home/pi/.covers", 
            library_dir="/var/lib/mpd/music"
            )
        grabber.get_local_art(now_playing)
    # maj affichage
        mapImg = pygame.image.load("/home/pi/.covers/current")
        mapImg = pygame.transform.scale(mapImg, (128, 128))
        mapMask= pygame.image.load("/home/pi/mask.png") # masque pour faire la forme de "l’œil magique"
        window.blit(mapImg, (0,0)) #<<will not blit
        window.blit(mapMask, (0,0))
        pygame.display.update() # solution: you forgot this...
    
    def main():
    # on se connecte au daemon mpd
        client = MPDClient()
        if mpdConnect(client, CON_ID):
            print('Got connected!')
        else:
            print('fail to connect MPD server.')
            sys.exit(1)
        elapsed=0.00
    # init pygame /  afficheur
        pygame.display.init()
        pygame.mouse.set_visible(0)
        window = pygame.display.set_mode((128, 128))
        pygame.event.clear()
        window.fill((0,0,0))
    # affiche coverArt piste en cours
        update_folder(client,pygame,window)
        while True:
            status = client.status()
    #  test si temp_lecture < temp_lecture precedent pour detecter nouvelle piste
            if (elapsed < float(status.get('elapsed', 0))): # non , meme piste rien a faire
                elapsed=float(status.get('elapsed', 0))
            else:                                           # oui , nouvelle piste raz temp_lecture et maj covertArt
                elapsed=float(status.get('elapsed', 0))
    #            print ( status.get('elapsed', 0))
                now_playing = client.currentsong()
                update_folder(client,pygame,window)
                #print ('file    : ' + now_playing.get('file'))
            time.sleep(1)
    
    	# check si piste 
            event = pygame.event.poll() #wait()
    # regarde si evemnent clavier (encodeur rotatif)
            if event.type==pygame.KEYDOWN:
                if event.key==pygame.K_RETURN: # pour l'instant arret soft , a terme play/pause
                    pygame.quit()
                    client.disconnect()
                    sys.exit(0)
                if event.key==pygame.K_UP: # piste suivante
                    client.next()
                    pygame.event.clear()
    		#time.sleep(1)
                    elapsed=0
                    update_folder(client,pygame,window)
                if event.key==pygame.K_DOWN: # piste precedente
                    client.previous()
                    pygame.event.clear()
    		#time.sleep(1)
                    elapsed=0
                    update_folder(client,pygame,window)
    
    if __name__ == "__main__":
        main()
    

     

pour l’instant partie “mécanique” finis à 90¨% , et partie Electronique / dev finis a 70%

lorsque le soft seras terminé a 100% , je mettrais dispo les sources de tous les fichiers/scripts utilisés

la suite bientôt ……..

Articles qui m’on servis pour développer
https://github.com/petervflocke/rotaryencoder_rpi
https://www.instructables.com/id/PWM-Regulated-Fan-Based-on-CPU-Temperature-for-Ras/
https://www.pihomeserver.fr/2014/03/08/raspberry-pi-home-server-ajouter-une-horloge-rtc-ds1307-sur-le-bus-i2c/
http://blog.gegg.us/2017/01/setting-up-a-gpio-button-keyboard-on-a-raspberry-pi/
https://blog.oddbit.com/2019/01/19/pipower-a-raspberry-pi-ups/https://github.com/joshkunz/ashuffle
https://github.com/joosteto/ws2812-spi
https://github.com/nvbn/soundlights

 

Catégorie : Hardware, Software | Commentaires fermés sur RadioPi
août 12

Serveur Tvheadend avec stockage ( Partie 1 – installation tvheadend et epg )

  • Objectif : faire un serveur de diffusion / stockage des chaines TNT
  • Materiel :
    • Un Raspberry PI2 ou PI3
    • un disque dur USB ( dans mon cas un WD PiDrive 314 Go )
    • un ou plusieurs adaptateur TNT USB ( dans mon cas 3 x R820T DVB-T => ebay)
    • et si plusieurs adaptateur TNT , un Répartiteur Adaptateur Antenne
    • un boitier avec alimentation 5V , mini 3A ( interne ou externe selon boitier )
  • Logiciels :
    • la dernière version de raspbian-lite
    • tvheadend
    • samba

== Préparation du Raspberry pi

  • installer dernière version raspbian lite
    avec raspi-config :

    • passer langue français , timezone Europe …..
    • changer mot de passer user : pi
  • autoriser root ssh :
    • dans /etc/ssh/sshd_config
      • remplacer : PermitRootLogin without-password
      • par : PermitRootLogin yes
  • dans /boot/cmdline.txt ajouter
    • logo.nologo loglevel=3
  • dans /boot/config.txt ajouter :
    • disable_splash=1
    • max_usb_current=1
  • mise a jour système :
$sudo apt-get clean && sudo apt-get autoclean && sudo apt-get update
$sudo apt-get dist-upgrade -y && sudo apt-get upgrade -y
$sudo apt-get install firmware-linux-nonfree firmware-linux-free -y
  • Installation des firmwares supplémentaires des récepteurs TNT :
$wget http://www.linuxtv.org/downloads/firmware/dvb-firmwares.tar.bz2
$mkdir FW
$cd FW
$tar xjvf ../dvb-firmwares.tar.bz2
$sudo cp * /lib/firmware
  • ajout des paquets pour compiler tvheadend et utilitaires divers:
$sudo apt-get install build-essential git pkg-config libssl-dev bzip2 wget python-rpi.gpio\
libavahi-client-dev zlib1g-dev libavcodec-dev libavutil-dev libavformat-dev libswscale-dev\
libcurl4-gnutls-dev liburiparser-dev debhelper cmake dvb-apps libpcre3-dev ffmpeg locate -y
$git clone https://github.com/tvheadend/tvheadend.git -b release/4.0
$cd tvheadend
$./configure
$AUTOBUILD_CONFIGURE_EXTRA=--disable-libav_static ./Autobuild.sh
  • puis installation :
$cd ..
$sudo dpkg -i tvheadend_4.0.10_armhf.deb
  • changement dur port http par defaut 9981 :
    $sudo nano /etc/default/tvheadend

    remplacer TVH_HTTP_PORT=”” par TVH_HTTP_PORT=”80″

  • puis relancer tvheadend :
$sudo service tvheadend restart
  • installation de la version 4.2 ou si vous voulez pas compiler a partir des sources
$echo "deb https://dl.bintray.com/mpmc/deb raspbianjessie stable-4.2" | sudo tee -a /etc/apt/sources.list

puis :

$sudo apt-get update
$sudo sudo apt-get install tvheadend
  • gestion de l’EPG , se connecter avec le user hts
$sudo -u hts /bin/bash
$sudo apt-get install xmltv
$/usr/bin/tv_grab_fr_kazer --configure

et entrez votre Userash ( creation du compte sur https://www.kazer.org/ )

  • Installation afficheur 320×240 TFT SPI ( a base de ili9341) , câblage de l’afficheur :
    TFT Screen Raspberry Pin
     VCC 3.3V #1
    GND GND #9
    CS GPIO8 #24
    RESET GPIO23 #22
    DC\RS GPIO24 #18
    SD1\MOSI GPIO10 #19
    SCK GPIO11 #23
    LED GPIO18 #12
    SD0\MISO GPIO9 #21

    on edite le fichier config.txt pour ajouter la gestion de l’afficheur au démarrage

    $sudo nano /boot/config.txt

    et on rajoute :

    dtoverlay=rpi-display 
    dtparam=rotate=90 
    dtparam=speed=16000000

    ( rotate=90 a adapter selon position afficheur ) .On edite aussi cmdline.txt

    $sudo nano /boot/cmdline.txt

    et on ajoute en fin de ligne :

    fbcon=map:10

    on reboote et normalement l’afficheur fonctionne , si ne marche pas bien vérifier le câblage et que c’est bien un ili9341
    Pour tester  le rétro-éclairage (1:OFF , 0:ON) : ( pour plus d’info voir : https://github.com/notro/fbtft/wiki/Backlight )

    $echo 1 | sudo tee /sys/class/backlight/*/bl_power
    $echo 0 | sudo tee /sys/class/backlight/*/bl_power

     

  • Installation de samba et HDD USB ( en cours ………)
  • ………….
  • …………………
Catégorie : Hardware, Software | Commentaires fermés sur Serveur Tvheadend avec stockage ( Partie 1 – installation tvheadend et epg )
août 15

Bus CAN

Création d’un carte avec horloge en temps réel (I2C ) et contrôleur de bus CAN (SPI)  , avec connecteur pour port série / I2c et SPI utilisable .

photo du proto ( les cartes viennent d’arriver de chez seeedstudio , vais commencer a en monter une )
PI-canPI-can2

La suite quand j’aurais finis de monter et tester la carte et développé le soft qui vas avec ( deja dispo fichier au format sketchup )

Catégorie : Hardware, Software | Commentaires fermés sur Bus CAN
août 1

Shutdown Raspberry PI par gpio

Encore un petit manque dans le monde du raspberry pi , un bouton arrêt ( propre , pas en coupant  a la sauvage l’alimentation du PI ).
besoin d’avoir python et rpi.gpio installé , un boutton poussoir (dans cet exemple cablé entre le GPIO17  et gnd )

 

installation de rpi.gpio
1- Paquets debian :

apt-get install  python-rpi.gpio

2- install depuis sources :

wget https://pypi.python.org/packages/source/R/RPi.GPIO/RPi.GPIO-0.6.3.tar.gz

tar -xvf RPi.GPIO-0.6.3.tar.gz

cd RPi.GPIO-0.6.3

sudo python setup.py install

cd ~
sudo rm -rf RPi.GPIO-0.*

script pour attendre appuie sur le bouton et lancer shutdown lorsque l’on appuie sur le bouton  : pishutdown.py =>

#!/usr/bin/python
# Import the modules to send commands to the system and access GPIO pins
import RPi.GPIO as gpio
import os
#set up GPIO using BCM numbering
gpio.setmode(gpio.BCM)
#Set up pin 7 as an input
gpio.setup(17, gpio.IN, pull_up_down = gpio.PUD_UP)
# Set up an interrupt to look for pressed button
gpio.wait_for_edge(17, gpio.FALLING)
# Shutdown
os.system('shutdown now -h')

script qui va se lancer au demérrage du PI : pishutdown.sh =>

#!/bin/sh
cd /
cd home/tools
python pishutdown.py
cd /

puis chmod +x pishutdown.sh

on édite le fichier /etc/rc.local

/home/tools/pishutdown.sh &

a rajouter avant la ligne exit 0 , a adapter selon l’endroit ou vous copiez les 2 fichiers ( pishutdown.py , pishutdown.sh) et du gpio utilisé .

Catégorie : Hardware, Software | Commentaires fermés sur Shutdown Raspberry PI par gpio
juillet 14

RTC et TFT 1.8″ SPI ( 128×160)

Nouveau projet , ajouter une horloge RTC et un ecran TFT 1.8″ (128×160) Attention petite Erreur sur le typon de la Rev 1.0 , Rev 1.1 en cours

– Schéma au format Eagle : Rev 1.0

– Fichier Gerber : Rev 1.0

– Vue 3D (Sketchup) : (en cours de Dev…)

– Installer l’image de base voir ‘Image de Base Raspberry PI’

– Activer l’horloge RTC DS1307 :

Editer /etc/modules et rajouter :

rtc_ds1307

Lancer i2cdetect -y 0 et i2cdetect -y 1 , pour savoir sur quel Bus se trouve l’horloge I2C ( adr 68) , puis Editer  /etc/rc.local

echo ds1307 0x68 > /sys/class/i2c-adapter/i2c-0/new_device
sudo hwclock -s

ou

echo ds1307 0x68 > /sys/class/i2c-adapter/i2c-1/new_device
sudo hwclock -s

Vérifier l’heure/date du Raspberry en tapant: date , Pour assigner la date/heure courante a la RTC tapez : hwclock -w .

Pour vérifier tapez date et ensuite hwclock -r , a 1 sec près on devrait avoir la même date/heure

– activer les modules pour afficheurs TFT en fonction de son afficheur ( voir https://github.com/notro/fbtft/wiki) , en éditant /etc/modules :

# 1.8" 160x128
fbtft_device name=sainsmart18 rotate=90

# 2.2" 320x240
fbtft_device custom name=fb_ili9341  gpios=reset:25,dc:24,led:18 speed=16000000 rotate=90 bgr=1

Définir l’afficheur TFT par défaut  , Editez le fichier /boot/cmdline.txt et ajouter a la fin de la ligne : fbcon=map:10 fbcon=font:ProFont6x11

Editez /etc/inittab

#1:2345:respawn:/sbin/getty --noclear 38400 tty1
1:2345:respawn:/bin/login -f root tty1 </dev/tty1 >/dev/tty1 2>&1

remplacer root par votre utilisateur

pour tester l’afficheur copiez un fichier JPG dans /home et lancer

fbi /dev/fb1 -T 1 -noverbose -a /home/mon_fichier.jpg

l’image devrait s’afficher .Rebooter le système et après quelque secondes , l’afficheur vas fonctionner

 

[fbalbum url=https://www.facebook.com/media/set/?set=a.735748826484147.1073741846.459447040780995&amp;type=3]

Catégorie : Hardware | Commentaires fermés sur RTC et TFT 1.8″ SPI ( 128×160)
juillet 12

Pikeyd : Pi GPIO keyboard daemon i2c MCP3017

– Schéma au format Eagle Rev 1.0 16 touches , Rev 1.0 32 touches

– Fichier Gerber V16 touches , V32 touches

– Vue 3D (Sketchup) : pikey16 et pikey32

– cablage
cablage_16E cablage_32E

– Installer l’image de base voir ‘Image de Base Raspberry PI’

– sources du daemon pikeyd sur : https://github.com/mmoller2k/pikeyd

– lancement automatique du daemon (dans mon cas le daemon est situé dans /home/pikey) , editer le fichier ~/.bashrc

if [ -z "$SSH_CONNECTION" ]; then
/home/pikey/pikeyd -d
fi

– examples de configuration ( a copier dans ~/.pikeyd.conf ou /etc/pikeyd.conf)

fichier de configuration pour 16 touches ( version avec 1 seul mcp23017 )

# MCP23017 has two 8-bit banks
# interrupt GPIO4
XIO_A           4/0x20/MCP23017A
XIO_B           4/0x20/MCP23017B
# port A
KEY_LEFT        XIO_A:0
KEY_RIGHT       XIO_A:1
KEY_UP          XIO_A:2
KEY_DOWN        XIO_A:3
KEY_W           XIO_A:4
KEY_A           XIO_A:5
KEY_S           XIO_A:6
KEY_D           XIO_A:7
# port B
KEY_1           XIO_B:0
KEY_2           XIO_B:1
KEY_3           XIO_B:2
KEY_4           XIO_B:3
KEY_5           XIO_B:4
KEY_6           XIO_B:5
KEY_7           XIO_B:6
KEY_8           XIO_B:7

fichier configuration pour 2×16 touches ( version avec 2 mcp23017 )

# MCP23017 has two 8-bit banks
# interrupt GPIO4
XIO_A1          4/0x20/MCP23017A
XIO_B1          4/0x20/MCP23017B
XIO_A2          4/0x21/MCP23017A
XIO_B2          4/0x21/MCP23017B
# port1 A
KEY_0           XIO_A1:0
KEY_1           XIO_A1:1
KEY_2           XIO_A1:2
KEY_3           XIO_A1:3
KEY_4           XIO_A1:4
KEY_5           XIO_A1:5
KEY_6           XIO_A1:6
KEY_7           XIO_A1:7
# port1 B
KEY_8           XIO_B1:0
KEY_9           XIO_B1:1
KEY_0           XIO_B1:2
KEY_A           XIO_B1:3
KEY_B           XIO_B1:4
KEY_C           XIO_B1:5
KEY_D           XIO_B1:6
KEY_E           XIO_B1:7
# port2 A
KEY_F           XIO_A2:0
KEY_G           XIO_A2:1
KEY_H           XIO_A2:2
KEY_I           XIO_A2:3
KEY_J           XIO_A2:4
KEY_K           XIO_A2:5
KEY_L           XIO_A2:6
KEY_M           XIO_A2:7
# port2 B
KEY_N           XIO_B2:0
KEY_O           XIO_B2:1
KEY_P           XIO_B2:2
KEY_Q           XIO_B2:3
KEY_R           XIO_B2:4
KEY_S           XIO_B2:5
KEY_T           XIO_B2:6
KEY_ESC         XIO_B2:7

– Photos : Version 16 touches

PIKEY_16_001PIKEYD_16_002

Version 32 touches
PIKEYD_32_001PIKEYD32_PI

Catégorie : Hardware | Commentaires fermés sur Pikeyd : Pi GPIO keyboard daemon i2c MCP3017