Kamis, 09 Februari 2017

raspberry PI Fingerprint


https://www.sparkfun.com/products/11792
https://github.com/the-AjK/GT-511C3
https://www.raspberrypi.org/forums/viewtopic.php?f=36&t=84572
http://devnotes.fabioluiz.de/spring-boot-libfprint
http://sergeplay.blogspot.co.id/2016/01/cheap-usb-fingerprint-reader-from.html

sudo apt-get install libfprint


#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>

#include <libfprint/fprint.h>

struct fp_dscv_dev *discover_device(struct fp_dscv_dev **discovered_devs)
{
   struct fp_dscv_dev *ddev = discovered_devs[0];
   struct fp_driver *drv;
   if (!ddev)
      return NULL;
 
   drv = fp_dscv_dev_get_driver(ddev);
   printf("Found device claimed by %s driver\n", fp_driver_get_full_name(drv));
   return ddev;
}

struct fp_print_data *enroll(struct fp_dev *dev) {
   struct fp_print_data *enrolled_print = NULL;
   int r;

   printf("You will need to successfully scan your finger %d times to "
      "complete the process.\n", fp_dev_get_nr_enroll_stages(dev));

   do {
      struct fp_img *img = NULL;
 
      sleep(1);
      printf("\nScan your finger now.\n");

      r = fp_enroll_finger_img(dev, &enrolled_print, &img);
      if (img) {
         fp_img_save_to_file(img, "enrolled.pgm");
         printf("Wrote scanned image to enrolled.pgm\n");
         fp_img_free(img);
      }
      if (r < 0) {
         printf("Enroll failed with error %d\n", r);
         return NULL;
      }

      switch (r) {
      case FP_ENROLL_COMPLETE:
         printf("Enroll complete!\n");
         break;
      case FP_ENROLL_FAIL:
         printf("Enroll failed, something wen't wrong :(\n");
         return NULL;
      case FP_ENROLL_PASS:
         printf("Enroll stage passed. Yay!\n");
         break;
      case FP_ENROLL_RETRY:
         printf("Didn't quite catch that. Please try again.\n");
         break;
      case FP_ENROLL_RETRY_TOO_SHORT:
         printf("Your swipe was too short, please try again.\n");
         break;
      case FP_ENROLL_RETRY_CENTER_FINGER:
         printf("Didn't catch that, please center your finger on the "
            "sensor and try again.\n");
         break;
      case FP_ENROLL_RETRY_REMOVE_FINGER:
         printf("Scan failed, please remove your finger and then try "
            "again.\n");
         break;
      }
   } while (r != FP_ENROLL_COMPLETE);

   if (!enrolled_print) {
      fprintf(stderr, "Enroll complete but no print?\n");
      return NULL;
   }

   printf("Enrollment completed!\n\n");
   return enrolled_print;
}

int main(void)
{
   int r = 1;
   struct fp_dscv_dev *ddev;
   struct fp_dscv_dev **discovered_devs;
   struct fp_dev *dev;
   struct fp_print_data *data;

   printf("This program will enroll your right index finger, "
      "unconditionally overwriting any right-index print that was enrolled "
      "previously. If you want to continue, press enter, otherwise hit "
      "Ctrl+C\n");
   getchar();

   r = fp_init();
   if (r < 0) {
      fprintf(stderr, "Failed to initialize libfprint\n");
      exit(1);
   }
   fp_set_debug(3);

   discovered_devs = fp_discover_devs();
   if (!discovered_devs) {
      fprintf(stderr, "Could not discover devices\n");
      goto out;
   }

   ddev = discover_device(discovered_devs);
   if (!ddev) {
      fprintf(stderr, "No devices detected.\n");
      goto out;
   }

   dev = fp_dev_open(ddev);
   fp_dscv_devs_free(discovered_devs);
   if (!dev) {
      fprintf(stderr, "Could not open device.\n");
      goto out;
   }

   printf("Opened device. It's now time to enroll your finger.\n\n");
   data = enroll(dev);
   if (!data)
      goto out_close;

   r = fp_print_data_save(data, RIGHT_INDEX);
   if (r < 0)
      fprintf(stderr, "Data save failed, code %d\n", r);

   fp_print_data_free(data);
out_close:
   fp_dev_close(dev);
out:
   fp_exit();
   return r;
}

===========

Cheap USB fingerprint reader (from Laptop) works with Raspberry Pi

sudo apt-get install libpam-fprintd

And then testing:

> sudo fprintd-enroll 
Using device /net/reactivated/Fprint/Device/0
Enrolling right-index-finger finger.
Enroll result: enroll-stage-passed
Enroll result: enroll-stage-passed
Enroll result: enroll-completed

> sudo fprintd-verify
Using device /net/reactivated/Fprint/Device/0
Listing enrolled fingers:
 - #0: right-index-finger
Verify result: verify-match (done)


Minggu, 15 Januari 2017

Raspberry PI to Arduino Uno Serial GPIO

python code
import serial

ser = serial.Serial('/dev/ttyACM0',9600)
s = [0,1]
while True:
read_serial=ser.readline()
s[0] = str(int (ser.readline(),16))
print s[0]
print read_serial

arduino code:
char dataString[50] = {0};
int a =0; 

void setup() {
Serial.begin(9600);              //Starting serial communication
}
  
void loop() {
  a++;                          // a value increase every loop
  sprintf(dataString,"%02X",a); // convert a value to hexa 
  Serial.println(dataString);   // send the data
  delay(1000);                  // give the loop some break
}





One way to connect the Raspberry Pi and Arduino is by connecting the GPIO on the Raspberry Pi and the Serial Pins on the Arduino.
Because there is a voltage difference between the two device on these interface, a voltage divider or logic level converter would be required.
Check my article about connecting the two using I2C if you haven’t already seen it. Before we start, we need to set up the Raspberry Pi so it’s ready for serial communication.

Raspberry Pi Serial GPIO Configuration

0. if you have not seen my article on how to remote access your Raspberry Pi, take a look here:
1. In order to use the Raspberry Pi’s serial port, we need to disable getty (the program that displays login screen) by find this line in file /etc/inittab
T0:23:respawn:/sbin/getty -L ttyAMA0 115200 vt100
And comment it out by adding # in front of it
#T0:23:respawn:/sbin/getty -L ttyAMA0 115200 vt100
2. To prevents the Raspberry Pi from sending out data to the serial ports when it boots, go to file /boot/cmdline.txt and find the line and remove it
console=ttyAMA0,115200 kgdboc=ttyAMA0,115200
3. reboot the Raspberry Pi using this command: sudo reboot
4. Now, Install minicom
sudo apt-get install minicom
And that’s the end of the software configuration.

Connect Serial Pins and GPIO with a Voltage Level Converter

Load this program on your Arduino first:
[sourcecode language=”cpp”]
byte number = 0;
void setup(){
Serial.begin(9600);
}
void loop(){
if (Serial.available()) {
number = Serial.read();
Serial.print(“character recieved: “);
Serial.println(number, DEC);
}
}
[/sourcecode]
Then connect your Arduino, Raspberry Pi and Logic Level Converter like this:

arduino-raspberry-pi-serial-gpio-connect-schematics
This is how the wires are connected.
arduino-raspberry-pi-serial-gpio-connect-wiring
And this is the GPIO pins on the Raspberry Pi. Make sure you connect the correct pin otherwise you might damage your Pi.
GPIOs

A Simple Example with Minicom

Now to connect to the Arduino via serial port using this command in putty or terminal
minicom -b 9600 -o -D /dev/ttyAMA0
When you type a character into the console, it will received by the Arduino, and it will send the corresponding ASCII code back. Check here for ASCII Table. And there it is, the Raspberry Pi is talking to the Arduino over GPIO serial port.
arduino-raspberry-pi-serial-gpio-connect-minicom
To exit, press CTRL + A release then press Q

Example with Python Program

Using Python programming language, you can make Raspberry Pi do many fascinating stuff with the Arduino when they are connected. Install Py-Serial first:
sudo apt-get install python-serial
Here’s a simple application that sends the string ‘testing’ over the GPIO serial interface
[sourcecode language=”python”]
import serial
ser = serial.Serial(‘/dev/ttyAMA0’, 9600, timeout=1)
ser.open()
ser.write(“testing”)
try:
while 1:
response = ser.readline()
print response
except KeyboardInterrupt:
ser.close()
[/sourcecode]
Raspberry Pi and Arduino Connected Over Serial GPIO python-serial-program-output
To exit, press CTRL + C

Connect Raspberry Pi and Arduino with a Voltage Divider

Apart from replacing the Login Level Converter with a voltage divider, the way it works is the same as above. Anyway, I will show you a different example to demonstrate this. A voltage divider is basically just two resistors.
There is something you should be aware of before we continue. The RX pin on the Arduino is held at 5 Volts even when it is not initialized. The reason could be that the Arduino is flashed from the Arduino IDE through these pins when you program it, and there are weak external pull-ups to keep the lines to 5 Volts at other times. So this method might be risky. I recommend using a proper level converter, if you insist on doing it this way, try adding a resistor in series to the RX pin, and never connect the Raspberry Pi to Arduino RX pin before you flash the program to Arduino, otherwise you may end up with a damaged Pi!
arduino-raspberry-pi-serial-gpio-connect-schematics
The Arduino serial pin is held at 5 volts and Raspberry Pi’s at 3.3 volts. Therefore a voltage divider would be required, it’s basically just two resistors.
arduino-raspberry-pi-serial-connect-schematics
Here is the program you need to write to the Arduino board.
[sourcecode language=”cpp”]
void setup() {
Serial.begin(9600);
}
void loop() {
if (Serial.available() > 0) {
int incoming = Serial.read();
Serial.print(“character recieved: “)
Serial.print(incoming, DEC);
}
}
[/sourcecode]
Now you can connect directly from your computer to the Raspberry Pi on the tty-device of the Arduino, just like we described above. (type below into your putty)
minicom -b 9600 -o -D /dev/ttyAMA0
And as you type in characters in the console, you should see something like this:
arduino-raspberry-pi-serial-gpio-connect-minicom
And that’s the end of this Raspberry Pi and Arduino article. There are other ways of connecting, if you don’t already know, you can also use a Micro USB cable. Check out this post: https://oscarliang.com/connect-raspberry-pi-and-arduino-usb-cable/
Reff:
http://www.instructables.com/id/Raspberry-Pi-Arduino-Serial-Communication/?ALLSTEPS
http://www.seeed.cc/project_detail.html?id=168

FInishing Code:


import serial

import MySQLdb
from time import gmtime, strftime
from random import randint


db = MySQLdb.connect("localhost","root","123456","monitoring" )
cursor = db.cursor()

def mtrim(s):
    if s.endswith(" "): s = s[:-1]
    if s.startswith(" "): s = s[1:]
    return s



read_serial0=""
ser = serial.Serial('/dev/ttyACM0',9600)
s = [0,1]
while True:
 read_serial=ser.readline()
 print read_serial
 read_serial=mtrim(read_serial)

 if len(read_serial) >6:
     if read_serial!=read_serial0:
         c=read_serial.split("#")
         read_serial0=read_serial
         I=c[0]
         V=c[1]
         W=c[2]
         P=c[3]
         Q=c[4]
         R=c[5]
         S=c[6]
         
         print "I=",I
         print "V=",V
         print "P=",W
         print "1=",P
         print "2=",Q
         print "3=",R
         print "4=",S

         tgl=strftime("%Y-%m-%d", gmtime())
         jam=strftime("%H:%M:%S", gmtime())

         sql = 'INSERT INTO `tb_history` ( `tanggal`, `jam`, `arus`, `tegangan`, `daya`,`L1`,`L2`,`L3`,`L4`) VALUES ("%s", "%s", "%s","%s","%s", "%s", "%s", "%s", "%s")' % (tgl, jam, I,V,W,P,Q,R,S)
         try:
           cursor.execute(sql)
           db.commit()
         except:
           db.rollback()
          
     
         print"+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"





#$sudo -i
#cd /home/pi/Desktop/py
#python Help.py

#ls /dev/tty*

Kamis, 17 November 2016

Raspberry PI Gagal Update DI Awal

 Jika Kita baru pertama kali menginstall Raspbian akan terjadi error seperti gambar diatas ini. Pada Dasarnya Raspberry PI ini sama saja dengan Error pada Linux lainnya terutama Turunan Debian, karena Raspi saya ini menggunakan OS Raspbian yang turunannya dari debian Jessie. jadi masalah atau penyebab errornya seperti gambar diatas adalah bukan di file sources.list nya sendiri, tapi masalahnya ada di DNS nya sendiri.

  Jadi, cara fixnya adalah dengan cara menambahkan DNS Google pada file /etc/network/interfaces. Berikut ini adalah tutorialnya:

1. Masukan perintah ini pada terminal :
sudo nano /etc/network/interfaces
2. lalu masukan DNS google pada interfaces network nya ( wlan0 atau eth0), sya menggunakan wlan0.
dns-nameservers 8.8.8.8 8.8.4.4
Seperti gambar di bawah ini 




3. Selanjutnya silahkan restart Raspberry PI nya dengan syntax :
sudo reboot

NB : Tested pada Raspberry PI 3 Model B (Raspbian Jessie)


Reff:
http://www.kutulinux.com/2016/10/fix-error-update-di-raspberry-pi-pada.html

Mengaktifkan Sinyal HDMI untuk TV

Pada dasarnya ketika kita melakukan atau menghubungkan raspberry kita ke TV, Monitor bahkan laptop, butuh beberapa konfigurasi dasar agar bisa muncul tampilan raspberry PI kita. Biasanya seperti pengalaman saya, ketika kbel HDMI di input ke DVI HDMI TV, tidak terdeteksi bahkan keluar pesan "No Signal Display" maksudnya tidak ada sinyal atau sinyalnya terlalu kecil untuk di deteksi pada TV atau monitor kita. 

  Pada dasarnya Raspberry Pi tidak memiliki BIOS seperti pada PC atau komputer pada umumnya. Hal ini dikarenakan raspberry PI adalah sebuah platform yang sudah tertanam pada boardnya. Biasanya untuk konfigurasinya sendiri pada sistemnya bisanya dilakukan dengan cara mengedit dan disimpan dalam sebuah file teks opsional bernama config.txt. File Ini dibaca oleh GPU sebelum CPU ARM dan Linux yang dijalankan, karena file ini harus terletak pada boot partisi kartu SD Card Kita, bersama bootcode.bin dan start.elf
  Sesudah kita melakukan pengeditan, perubahan yang kita buat hanya akan berlaku setelah kita melakukan reboot pada Raspberry PI. pada tutorial ini saya akan membahas bagaimana konfigurasi dari Script /boot/config.txt pada raspberry PI untuk HDMI to HDMI. Oke langsung saja kita bahas bahagaimana konfigurasinya sendiri.


1. Hal yang pertama adalah kita harus membuka file /boot/config.txt di laptop kita dengan cara memasukan SD card ke card reader dan dihubungkan ke laptop kita lewat slot USB port pada Laptop.


2. Selanjutnya, kita mencari baris atau text bawah ini untuk mengaktifkan sinyal HDMI :
# hdmi_force_hotplug =1
lalu  hilangkan tanda pagar ( " # " ), agar tidak dianggap Comment oleh shell. seperti di bawah ini 
hdmi_force_hotplug =1
  Untuk Pengaturan yang bernilai 1 adalah mengaktifkan sinyal hotplug ke HDMI, sehingga tampak bahwa tampilan HDMI terpasang. Dengan kata lain, mode keluaran HDMI akan digunakan, bahkan jika ada monitor HDMI terdeteksi diraspberry sendiri. 

3. Selanjutnya, kita save dan pasangkan kembali SD card pada slot Raspberry kita dan kita jalankan raspberry nya.

NB : Testing Pada Raspberry 3 model B


Reff: http://www.kutulinux.com/2016/10/mengaktifkan-sinyal-hdmi-untuk-tv.html

WEBIOPI Revisi

WebIOPi-0.7.1
Patch for Raspberry B+, Pi2, and Pi3

WebIOPi adalah aplikasi open source yang dibuat untuk mengontrol GPIO melalui web browser atau Via Internet. Aplikasi ini merupakan framework untuk bahasa pemrograman python yang didalamnya sudah berjalan WebServer Apache.


caranya install versi terbarunya adalah sbb:

$ wget http://sourceforge.net/projects/webiopi/files/WebIOPi-0.7.1.tar.gz
$ tar xvzf WebIOPi-0.7.1.tar.gz
$ cd WebIOPi-0.7.1
$ wget https://raw.githubusercontent.com/doublebind/raspi/master/webiopi-pi2bplus.patch
$ patch -p1 -i webiopi-pi2bplus.patch
$ sudo ./setup.sh

Selanjutknay mengaktifkan service webiopi (NOOBS >1.4.2)

$ cd /etc/systemd/system/
$ sudo wget https://raw.githubusercontent.com/doublebind/raspi/master/webiopi.service
$ sudo systemctl start webiopi
$ sudo systemctl enable webiopi

RUN:

Port defaultnya adalah : 8000, buka browser jalankan: 192.168.0.100:8000


username default: webiopi password:raspberry






Raspberry FTP Server

FTP Server Installation

We are close to having all the things for a good web server. Now we need to install FTP. I used ProFTPD for FTP.
sudo apt-get install proftpd
This will ask you to choose init.d or standalone, choose any one of them but I used standalone for this tutorial.
Next, we are going to change the config of proftpd.
sudo nano /etc/proftpd/proftpd.conf
You need to change the following lines. The ServerName should be the IP of your Raspberry Pi. Here we used 192.168.1.88. Yours can be different.
Server Name "192.168.1.88"
Uncomment the # in front of DefaultRoot text. This is a good practice.
# Use this to jail all users in their homes
 DefaultRoot
Next, we restart proftpd service
sudo service proftpd restart
To make sure that FTP service runs automatically at startup, enter the following code
update-rc.d proftpd defaults
Now we need to add a user for FTP. I am using “real” as the username. You can choose anything you like.
sudo useradd real
Set password the user with the following command
sudo passwd real
Assign the “/var/www/html/” directory to the user. This is the directory where the files will need to be added and the user will see this directory when they login using FTP client.Ignore message that says the directory already exists
sudo usermod -m -d /var/www/html real
Run the following commands to give permissions to the user on the html folder.
cd /var/www
sudo chown real:real -R html
FTP setup is done at this point. However, I found it is easier for me to do one extra step to avoid permissions. I edited apache2.conf file to make Apache use the user and group that we created.
sudo nano /etc/apache2/apache2.conf
Look for the following line and add # in front of User and Group lines. After editing, it should look like the following
# These need to be set in /etc/apache2/envvars
# User ${APACHE_RUN_USER}
# Group ${APACHE_RUN_GROUP}
User real
Group real