GGshow reloaded GGshow reloaded

April 11, 2016

RPi RF Transmitter & Radio Controlled Sockets

Playing with my new toy – Pi-mote Control starter kit with 2 sockets.

Sample code – turn on all plugs for 5 seconds.

import RPi.GPIO as GPIO
from time import sleep
GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(False)

GPIO.setup(17,GPIO.OUT)
GPIO.setup(22,GPIO.OUT)
GPIO.setup(23,GPIO.OUT)
GPIO.setup(27,GPIO.OUT)
GPIO.setup(24,GPIO.OUT)
GPIO.setup(25,GPIO.OUT)

GPIO.output(17,True)
GPIO.output(22,True)
GPIO.output(23,False)
GPIO.output(27,True)
sleep(0.1)
GPIO.output(25,True)
sleep(0.25)
GPIO.output(25,False)

sleep(5)

GPIO.output(17,True)
GPIO.output(22,True)
GPIO.output(23,False)
GPIO.output(27,False)
sleep(0.1)
GPIO.output(25,True)
sleep(0.25)
GPIO.output(25,False)

Complicated? There is an easier way, by using Energenie library.

Installing Energenie library

For Python 3

sudo apt-get install python3-pip
sudo pip-3.2 install energenie

For Python 2

sudo apt-get install python-pip
sudo pip install energenie

* pip is a package management system used to install and manage software packages written in Python.

Sample code – turn on all plugs for 5 seconds

from energenie import switch_on, switch_off
from time import sleep
switch_on()
sleep(5)
switch_off()

It is much easier now, doesn’t it?

Updated: 11/9/2016
To control each switch separately, hold down the green button on one switch for 10-15 seconds, send channel 1 on command, hold down the green button on the other switch for 10-15 seconds, send channel 2 on command.
Now I can switch on/off the plug separately.

from energenie import switch_on, switch_off
from time import sleep
switch_on(1)
sleep(3);
switch_off(1)
sleep(3);
switch_on(2)
sleep(3);
switch_off(2)

Now I’ll be able to automatically turn on my radio every morning to wake me up, or remotely turn on my rice cooker before I arrive at home 😉

Reference
Controlling electrical sockets with Energenie Pi-mote – Raspberry Pi
Energenie Documentation
Energenie Python library source code

March 31, 2016

RPi 5 inch HDMI LCD

Bought a 5″ HDMI LCD screen for my Raspberry Pi, but it wasn’t working until I made some changes at /boot/config.txt file to force 800×480 screen resolution, edit /boot/config.txt and modify these lines:

hdmi_force_hotplug=1
hdmi_group=2
hdmi_mode=87
hdmi_cvt 800 480 60 6 0 0 0

Raspberry Pi 5inch HDMI LCD

 

Optionally to enable support of MJPEG, VP6, VP8, Ogg Theora & Ogg Vorbis, add these lines:

start_file=start_x.elf
fixup_file=fixup_x.elf
Filed under: Internet of Things (IoT),Linux,Raspberry Pi — Tags: , , , , — GG @ 2:08 pm

February 27, 2016

RPi camera

Enabling camera on your RPi

  • sudo raspi-config
    

Terminal commands

  • To take a picture
    raspistill -o filename.jpg
    
  • To play a recorded h264 video
    omxplayer filename.h264
    
  • To record a slow motion video (10 seconds, resolution 640×480 pixels, 90 frames per second)
    raspivid -w 640 -h 480 -fps 90 -t 10000 -o filename.h264

Installing Python API for RPi camera

  • sudo apt-get install python-picamera python3-picamera python-rpi.gpio
    

Python code samples

  • Preview and capture a photo
    import time
    import picamera
    with picamera.PiCamera() as camera:
        camera.start_preview()
        time.sleep(10)
        camera.capture('filename.jpg')
        camera.stop_preview()
    
  • Capturing multiple photos
    import time
    import picamera
    with picamera.PiCamera() as camera:
        i = 0
        while True:
            camera.start_preview()
            time.sleep(1)
            camera.capture(str(i)+(".jpg"))
            i += 1
            time.sleep(5)
    
  • Capturing photo when push switch pressed
    * connect a push switch to GPIO2 & GND
    * use current timestamp as filename
    * save JPG when push switch pressed

    from time import gmtime, strftime, sleep
    import picamera
    import RPI.GPIO as GPIO
    GPIO.setmode(GPIO.BCM)
    button=2
    GPIO.setup(button,GPIO.IN,pull_up_down=PIO.PUD_UP)
    while True:
        with picamera.PiCamera() as camera:
            camera.resolution = 1920,1080
            GPIO.wait_for_edge(button, GPIO.FALLING)
            camera.start_preview()
            sleep(2)
            camera.capture(strftime("%Y%m%d%H%M%S",gmtime())+'.jpg')
            camera.stop_preview()
    

    A photo posted by @le_g_end on

    #raspberrypi #camera & #pushswitch

    A video posted by @le_g_end on

  • Recording a 10 seconds video
    from time import sleep
    import picamera
    with picamera.PiCamera() as camera:
        camera.start_recording('filename.h264')
        sleep(10)
        camera.stop_recording()
    
    
  • Video recording and playback
    import os
    while True:
        os.system("raspivid -w 640 -h 480 -fps 90 -t 10000 -o filename.h264")
        os.system("omxplayer filename.h264")
    

Reference

RPi Chapter 1

Preparation

  1. Download Raspbian and install it on SD card.
  2. Login using default username: pi, and password: raspberry
  3. Run Xserver
    startx
    
  4. Update and cleanup
    sudo apt-get update
    sudo apt-get upgrade
    sudo apt-get clean
    
  5. Installing packages
    sudo apt-get install {package}
    

April 25, 2015

My first contact with Raspberry Pi

My new toys = berry + bread, lol

Raspberry Pi, solderless breadboard, HDMI, jumper, LED, switch, MicroSD...

Attended Raspberry Pi workshop today, learned Raspbian, Python programming, solderless breadboard, 7 segment numeric LED display…

One step further in exploration, one step closer to invention.

Filed under: Raspberry Pi — Tags: , , , , , — GG @ 5:03 pm

© 2024 GGSHOW | Powered by WordPress