Tuesday, January 27, 2015

DHT11 + python connected to GPIO Android app



http://odroid.com/dokuwiki/doku.php?id=en:odroidoduinoone

DHT11 Sensor (Humidity / Temperature sensor)
http://www.micro4you.com/files/sensor/DHT11.pdf

Connections are (V)oltage, (S)ignal, (G)round

DHT11
 <package>
|  |  |  |
VS  G

For project hooked to digital pin 3 on Arduino Uno

Download dht.cpp and dht.h from below link and copy them into “~/sketchbook/libraries/dht”.
http://playground.arduino.cc/Main/DHTLib

#include <LiquidCrystal.h>
    #include <dht.h>
    /*******************************************************
    This program will test the LCD panel, the buttons
    and the Humidity/Temperature sensor
    Version : 0.1
    Date : 20-Oct-2013
    By Hardkernel
    ********************************************************/
    // for Digital Humidity and Temperature sensor (DHT11)
    dht DHT;
    #define DHT11_PIN 3
    // Global variables
    unsigned long elapsed_time;
    // select the pins used on the LCD panel
    LiquidCrystal lcd(8, 9, 4, 5, 6, 7);
     
    // define some values used by the panel and buttons
    int lcd_key     = 0;
    int adc_key_in  = 0;
    #define btnRIGHT  0
    #define btnUP     1
    #define btnDOWN   2
    #define btnLEFT   3
    #define btnSELECT 4
    #define btnNONE   5
     
    // read the buttons
    int read_LCD_buttons()
    {
     adc_key_in = analogRead(0);      // read the value from the sensor
     // my buttons when read are centered at these valies: 0, 144, 329, 504, 741
     // we add approx 50 to those values and check to see if we are close
     if (adc_key_in > 1000) return btnNONE; // We make this the 1st option for speed reasons since it will be the most likely result
     if (adc_key_in < 50)   return btnRIGHT; 
     if (adc_key_in < 195)  return btnUP;
     if (adc_key_in < 380)  return btnDOWN;
     if (adc_key_in < 555)  return btnLEFT;
     if (adc_key_in < 790)  return btnSELECT;   
     return btnNONE;  // when all others fail, return this...
    }
     
    void setup()
    {
         // initialize serial communication at 115200 bits per second:
         Serial.begin(115200); 
         lcd.begin(16, 2);              // start the LCD library
         lcd.setCursor(0,0);
         lcd.print(" Hello, ODUINO! "); // print a simple message
         //         1234567890123456
         delay(1500); // Splash for 1.5 second
         Serial.println("ODUINO TEST PROGRAM ");
         Serial.println();
         Serial.println("Type,\tstatus,\tHumidity (%),\tTemperature (C)");
         elapsed_time = millis()/1000; // Returns the number of milliseconds since the Arduino board began running the current program.
    }
   
    void loop()
    {
         lcd.setCursor(0,1);            // move to the begining of the second line     
         lcd.print("KEY :");     
         lcd.setCursor(6,1);            // move to the begining of the second line
         lcd_key = read_LCD_buttons();  // read the buttons
         switch (lcd_key)               // depending on which button was pushed, we perform an action
         {
           case btnRIGHT:
             {
             lcd.print("RIGHT ");
             Serial.println("RIGHT ");
             break;
             }
           case btnLEFT:
             {
             lcd.print("LEFT   ");
             Serial.println("LEFT ");     
             break;
             }
           case btnUP:
             {
             lcd.print("UP    ");
             Serial.println("UP ");     
             break;
             }
           case btnDOWN:
             {
             lcd.print("DOWN  ");
             Serial.println("DOWN ");     
             break;
             }
           case btnSELECT:
             {
             lcd.print("SELECT");
             Serial.println("SELECT ");     
             break;
             }
             case btnNONE:
             {
             lcd.print("NONE  ");
             break;
             }
         }
         // Read & Display the humidity / temperature data every 1 second (approx.)
         if(elapsed_time != millis()/1000)
         {
                elapsed_time = millis()/1000;
                Serial.print("DHT11, \t");
                int chk = DHT.read11(DHT11_PIN);
                switch (chk)
                {
                  case DHTLIB_OK: 
                              Serial.print("OK,\t");
                              break;
                  case DHTLIB_ERROR_CHECKSUM:
                              Serial.print("Checksum error,\t");
                              break;
                  case DHTLIB_ERROR_TIMEOUT:
                              Serial.print("Time out error,\t");
                              break;
                  default:
                              Serial.print("Unknown error,\t");
                              break;
                }
                // DISPLAY DATA
                Serial.print(DHT.humidity,0);
                Serial.print(",\t");
                Serial.println(DHT.temperature,0);
               
                lcd.setCursor(0,0);            // move cursor to second line "1" and 9 spaces over
                lcd.print("HUMI:");
                lcd.print((int)(DHT.humidity));
                lcd.print("%");
                lcd.print(" TEM:");
                lcd.print((int)(DHT.temperature));
                lcd.print("C");
         }
         delay(50); // delay 50 msec.
    }


Saturday, January 10, 2015

network thruput w/o third party tool

bandwidth monitor for Linux/Unix/OSX/BSD: systems without installing 3rd party tool:

watch -n1 "ifconfig eth0 | grep 'RX'"

Wednesday, November 12, 2014

Raspberry Pi Video capture


http://www.raspberrypi-spy.co.uk/2014/11/how-to-create-a-raspberry-pi-video-capture-unit-part-1/

https://bitbucket.org/MattHawkinsUK/rpispy-video-capture-unit

License for copying

How To Create A Raspberry Pi Video Capture Unit – Part 1

One hundred and fifty posts later I decided I should really complete a project I’ve been thinking about ever since I got my first Pi. That is a simple video capture unit that would be able to record video, in a loop, with the minimum amount of hardware and setting up.

I wanted a standard setup I could quickly deploy around the house, garden, car or bike. The software needed to be easy to setup so I could use it at short notice. I also wanted it to be basic enough that someone else could use it as a basis for their own Pi camera projects.
This sort of idea isn’t exactly unusual and there are plenty of Pi based camera projects out there but I wanted something I was happy with and did exactly what I needed without any fancy features. Re-inventing the wheel can be fun despite what other people might tell you!

Requirements

My requirements were something along these lines :
  • Easy and quick to configure
  • Basic Python script that is easy to follow
  • Ability to define number and duration of video files to store
  • Minimise hardware items
  • Minimise wiring, soldering and construction time
  • Provide a method to stop recording and correctly shutdown Pi
  • Provide a quick method to attach to a tripod
  • Provide a method to review footage on a PC
Although there are plenty of additional features I could have added I wanted to keep this simple. So you won’t see WiFi, Bluetooth or any web connectivity in this version.
Here is a photo of my finished system :
RPiSpy Video Capture Unit

Hardware

The hardware I used is listed below :
  • Raspberry Pi (Model B)
  • Cyntech standard case
  • 8GB SanDisk SD card
  • 32GB Kingston Flash Drive
  • Camera module
  • 8mm metal washer
  • 3D printed tripod mount
  • RAVPower RP-PB13 14000mAh USB power bank
RPiSpy Video Capture UnitI needed 1 switch and 1 LED so used an already assembled BerryClip add-on board. This was a quick way of giving me an LED and Switch without me needing to do any additional wiring. You can easily complete this project with your own LED, switch and resistors wired up to the appropriate GPIO pins. In order to fit everything in the case I need to drill holes to accommodate the LEDs, buzzer and camera. The switch was recessed but still usable.
Sticky pads were used to secure the camera in place. The metal washer was glued in place on the outside to allow cheap magnetic lenses to be attached if required.

Tripod Mounting

In this project I used the Cyntech case as it is good value, easy to modify and has a nice Raspberry Pi logo on it. My friend Graham 3D printed me a plastic insert which held a metal nut compatible with my tripod. This beautifully simple modification makes the whole unit easy to mount in a fixed position without having to balance it on piles of books.

Usage

When the Pi is powered up a cron job is started which looks for a network connection. If there is no network the main Python script is run. I didn’t want the script to start when connected to a network as this is when I wanted to download video without the camera being active.
The main script reads the configuration file and starts recording a video file. The files can be saved onto the SD card or a USB flash drive. When the pre-set duration is reached the file is closed and a new one is started. If the total number of video files reaches a pre-set limit then the oldest one is deleted. The device can continue recording over-writing files as required.
The configuration file let’s you set the total number of files to keep, the duration of each file as well as camera properties such as frame rate and resolution.
When you are finished you can hold down the button to quit the script and shutdown the operating system. The power can then be removed.

RAVPower RP-PB13 14000mAh Power BankPower

Around the house it is easy enough to use mains power but when I want to use the unit on the car or bike I just use my Ravpower RP-PB13 14000mAh USB power bank. I’ve had this battery for a while now and it has been in fairly regular use in my household.

Car Mounting

With a windscreen mount from eBay it’s easy to create a simple dash cam!
Dash Cam Windscreen Mount
Here are some additional photos :
Part 2 details the installation and setup procedure if you are interested in creating your own version.
How To Create A Raspberry Pi Video Capture Unit – Part 2

How To Create A Raspberry Pi Video Capture Unit – Part 2

Following on from Part 1 I’ll explain how you can install the Python software and get your own Video Capture Unit up and running.

You don’t need to build your unit in exactly the same way as mine but as a minimum you need :
  • Raspberry Pi
  • SD card with Raspbian
  • Camera module
  • 5V power supply
  • 1 LED attached to GPIO4 via current limiting resistor (ie 330 ohm)
  • 1 Switch attached to GPIO7 with 10K pull-down to ground
If you want to be able to easily transfer video files to a PC you might also want to use a :
  • USB Flash Drive (8GB+)
The setup might be spread over a desk or installed in raspberry pi case. The choice is yours.
RPiSpy Video Capture Unit

Software

The software is available from the RPiSpy Video Capture Unit BitBucket repository and consists of the following main files :
  • config.py
  • cron.py
  • instructions.txt
  • prepare_mp4.bat
  • prepare_mp4.sh
  • vcu.py
config.py
This file contain the user defined settings used by vcu.py. It allows the user to adjust various parameters. If “/boot/vcu_config.py” exists it is copied over this config file. The vcu_config.py can be used to edit settings on a Windows PC which can see the /boot/ partition on the SD card.
cron.py
This script is run when the Pi boots. It looks for a network connection and only runs vcu.py if it doesn’t find one. This allows the Pi to boot normally when you have connected it to your network to copy video files.
instructions.txt
Summary of these installation instructions for reference.
prepare_mp4.bat
This script provides an easy way to convert the recorded h264 files to MP4 files. It may take a while to convert depending on the total duration of the videos. It uses MP4Box and is meant to run via Windows.
prepare_mp4.sh
This script provides an easy way to convert the recorded h264 files to MP4 files. It may take a while to convert depending on the total duration of the videos. It uses MP4Box and is meant to run on the Pi itself.
vcu.py
This is the main Python script which does most of the work. It is called from cron.py when the Pi boots.

Installation

First prepare a fresh SD card with Raspbian. Use a recent download from the official RaspberryPi.org site. Why Raspbian? I use it for everything!
Power up the Pi and login. You will now be in the home directory. Expand the file system and Enable the Pi Camera using the config tool :
sudo raspi-config
Ensure you’ve got the latest firmware using :
sudo rpi-update
Create a new directory and navigate into it :
mkdir rpispy_vcu
cd rpispy_vcu
Now we can download the archive file from BitBucket using :
wget https://bitbucket.org/MattHawkinsUK/rpispy-video-capture-unit/get/master.tar.gz
If you type ls you should see the master.tar.gz file sitting in the current directory. Use the following command to extract the files from the archive :
tar -xvf master.tar.gz --strip 1
Typing ls should show you a list of the files :
You can remove the archive now using :
rm master.tar.gz
The Python scripts control the Raspberry Pi Camera Module using the Picamera module. This is installed by default on the latest version of Raspbian.
Then finally install MP4Box (aka gpac) which can be used to convert the h264 files recorded by the camera to slightly more usable MP4 files :
sudo apt-get -y install gpac

Config File Setup (optional)

If you want to be able to edit the config file in Windows you will need to place a copy in the /boot/ directory. You can do that using :
sudo cp config.py /boot/vcu_config.py
When the cron.py script runs at boot time it will check if there is a vcu_config.py file in /boot/. If there is it copies it over config.py. The main script would then run and use the new settings.

USB Flash Drive Setup

In order to save our video files to a removable drive we need to get the Pi to automatically mount the USB flash drive. This is a fairly easy process and is described in my How To Mount A USB Flash Disk On The Raspberry Pi tutorial. Follow the tutorial so that your drive is mounted as “/media/usb”.
If you don’t want to use a USB flash drive and you want to store videos on your SD card you will need to make a directory :
mkdir ~/rpispy_vcu/videos
and set the VIDEO_PATH parameter in the config.py file to point to ‘/home/pi/rpispy_vcu/videos/’. Don’t forget to update /boot/vcu_config.py if you are using that file.

Autorun On Boot Setup

To run the script automatically when the Pi boots you can use ‘cron’. To edit it we use the command :
sudo crontab -e
Using your cursor keys scroll to the bottom and add the following line :
@reboot python /home/pi/rpispy_vcu/cron.py &
Make sure you get this line correct as the script will fail to run on boot if there are any mistakes. Note that it ends in an ampersand symbol.
To save these changes click “CTRL-X”, then “Y” and finally “Return”. You should now be back at the command prompt.

First Run

RPiSpy Video Capture UnitShutdown your Pi and remove the power. Disconnect your network cable. Reconnect the power and boot the Pi. The Pi will boot and you will hear the buzzer sound once. The camera is now recording!
When you want to stop recording hold down the button until you hear a double beep from the buzzer. The Pi will shutdown. Wait 10 seconds before removing the power cable.
In part 3 I will cover converting the resulting video files into MP4 files which makes them easier to play in a media player or editing application.
How To Create A Raspberry Pi Video Capture Unit – Part 3


How To Create A Raspberry Pi Video Capture Unit – Part 3

In Part 1 and Part 2 of this set of articles I explained how I made a simple video recording device with the Raspberry Pi, a camera module and a plastic case. It’s simple enough to be mounted wherever you need a video camera.

In this final part I will explain how I extract the resulting video files from the unit and convert them to MP4 files. This makes them easier to play on other devices and media software.

Converting The Files Directly On The Pi

To convert the files using the Pi you can use the “prepare_mp4.sh” script. Plug the Pi into a network and power it up. We do not want the Pi to start recording video but the main script will not run if a network connection is detected.
The script uses MP4Box to do the conversion. If you haven’t installed it previously you can do so using :
sudo apt-get install gpac
Now you can navigate to the location where your video files are and check a copy of the script is present. Run the “prepare_mp4.sh” script using :
./prepare_mp4.sh
It may take a while but the h264 files in the directory will be converted to MP4. You will need to make sure there is sufficient space available to do this as you will end up with a h264 and MP4 file for each clip.
Once the script has finished you can transfer the resulting video files via SSH or FTP to another computer.

Converting On A Windows PC

My preferred method is to write the video to a USB drive. This can then be plugged into a PC and the “prepare_mp4.bat” script will then convert the h264 files and give you a set of MP4s. In order to use this method you will need to :
Your MP4 files will be prepared and saved in the “d:\temp” directory. You can use a different directory but you will need to update the batch file appropriately.
Your video capture unit is now ready for another adventure!
Dash Cam Windscreen Mount

Example Video Footage

Here is a two minute compilation I created from footage I filmed while the camera was attached to my windscreen :
The camera resolution was set to 1280×720 although the YouTube video was exported as 1920×1080. The video isn’t very exciting but shows how the camera deals with the varying daytime lighting conditions it comes across.
This entry was posted in Camera Module, Python and tagged , , , . Bookmark the permalink.

Friday, October 17, 2014

Running Ubuntu on a Chromebook or other such gizmo


From Ian Morrison.

https://plus.google.com/109451178006683865932/posts/UBQw1wNs8He

here is a bit of the post:

As an alternative to my post about Linux on RK3288 devices (see https://plus.google.com/+IanMORRISON/posts/16UGHZjyRQU) you might instead want to try Linux through a chroot environment.

You will still need an RK3288 device that is rooted, a terminal emulator installed and an SD card loaded with the RFS from the previous post.

Then you will need to download the script to run the chroot command from https://drive.google.com/file/d/0B99O3A0dDe67cHZWQlBkOUIyWnM

To enter the chroot environment, in a terminal window first 'su' and then simply type:
sh chroot.sh

Video showing install

http://youtu.be/_xsqrQw1kbs




Wednesday, October 15, 2014

hints for setting up raspian. NFS Timezone keyboard


here are some notes about changes on a fresh raspian setup.

Raspian is set to UK keyboard.

sudo dpkg-reconfigure keyboard-configuration

Raspian is set to UTC

change on internationalization on raspi-config menu.

To mount nfs, rpcbindd is not running: 

 
# /etc/init.d/rpcbind start
After that started nfslock,
#/etc/init.d/nfslock and tried to remount the nfs share and all went fine.
apt-get -y install nfs-kernel-server nfs-common portmap

 
then proceed with mounts.
 
TODO:  change mountall.sh so that cifs mount stanzas have settings that can be modified to be usual local.  On raspian, main id is "pi".