วันเสาร์ที่ 18 กรกฎาคม พ.ศ. 2558

VNC Server for Raspberry PI with dispmanx

You can remote console of raspberry pi with dispmanx


Install libvncserver-dev, gcc and g++ version 4.7

$ sudo apt-get install gcc-4.7 g++-4.7 libvncserver-dev

Update alternatives version of gcc and g++

$ sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.6 60 --slave /usr/bin/g++ g++ /usr/bin/g++-4.6

$ sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.7 40 --slave /usr/bin/g++ g++ /usr/bin/g++-4.7

Select gcc and g++ version to 4.7 (2)

$ sudo update-alternatives --config gcc
There are 2 choices for the alternative gcc (providing /usr/bin/gcc).

Selection Path Priority Status
------------------------------------------------------------
* 0 /usr/bin/gcc-4.6 60 auto mode
1 /usr/bin/gcc-4.6 60 manual mode
2 /usr/bin/gcc-4.7 40 manual mode

Press enter to keep the current choice[*], or type selection number: 2
update-alternatives: using /usr/bin/gcc-4.7 to provide /usr/bin/gcc (gcc) in manual mode
See on : https://github.com/Na1w/dispmanx_vnc

Clone source code of dispmanx.
$ git clone https://github.com/Na1w/dispmanx_vnc.git

Compile dispmanx.

$ cd dispmanx_vnc
$ make
After compile finish. It has dispmanx_vncserver file.
Copy this file to execute path. example /bin, /usr/local/bin, etc.


If you want to use X, modprobe  evdev first.

$ sudo modprobe evdev
See on : https://github.com/hanzelpeter/dispmanx_vnc


Start dispmanx vncserver

$ sudo dispmanx_vncserver
*** default port 5900

Stop dispmanx vncserver with Control + C Key.



Start dispmanx vncserver with password

$ sudo dispmanx_vncserver -P [password]

Change port number

$ sudo dispmanx_vncserver -p [port number]


Screen resolution config on /boot/config.txt

Example (1280x1024)
#HDMI force hotplug
hdmi_force_hotplug=1
# Group DMT
hdmi_group=2
# mode 35 - 1280x1024 60Hz
hdmi_mode=35
Reboot after save config.

Reference:

dispmanx_vnc
https://github.com/hanzelpeter/dispmanx_vnc

https://github.com/Na1w/dispmanx_vnc

Raspberry PI Document configuration config.txt
https://www.raspberrypi.org/documentation/configuration/config-txt.md

วันพฤหัสบดีที่ 16 กรกฎาคม พ.ศ. 2558

How to use VNC Server on Raspberry PI

If you want to remote to Raspbian with X Windows Desktop, you can use vnc server.

Install TightVNC Server.

$ sudo apt-get install tightvncserver

After install finished.

Start vncserver.

$ tightvncserver :<DISPLAY NUMBER>

Example: Start VNC Server on Display number 1 or port 5901 run with pi user.
$ tightvncserver :1

You will require a password to access your desktops.

Password: 
Verify: 

Would you like to enter a view-only password (y/n)? n


New 'X' desktop is raspberrypi:1


Creating default startup script /home/pi/.vnc/xstartup

Starting applications specified in /home/pi/.vnc/xstartup

Log file is /home/pi/.vnc/raspberrypi:1.log

On first time run script. Program will ask password for connect to VNC Server and ask view-only mode for this password.



After run tightvncserver. You can use TightVNC Viewer or VNC Client for remote to server.

Enter IP Address : Display number and Connect


Enter Password and OK

Connected to VNC Server


If you want to change vnc password for remote, use this command.
$ tightvncpasswd
Using password file /home/pi/.vnc/passwd
Password:
Verify:
Would you like to enter a view-only password (y/n)? n

VNC Password File save on /<User Directory>/.vnc/passwd


Stop VNC Server

$ tightvncserver -kill :<DISPLAY NUMBER>

Example : Stop VNC Server Display number 1

$ tightvncserver -kill :1

Screen resolution of VNC.
Start VNC Server with option.

$ tightvncserver -geometry <width>x<height> -depth <color depth>

Example

$ tightvncserver -geometry 1280x720 -depth 16 :1

Reference :

TightVNC
http://tightvnc.org/


วันอังคารที่ 7 กรกฎาคม พ.ศ. 2558

How to use DS3231 I2C Real Time Clock



Before use DS3231 I2C Real Time Clock. Enable I2C Interface.

On new kernel use Device Tree Overlays.

Edit on /boot/config.txt.

add new line

device_tree_param=i2c1=on
dtoverlay=i2c-rtc,ds3231

Reference : https://github.com/raspberrypi/firmware/tree/master/boot/overlays

Edit on /etc/modprobe.d/raspi-blacklist.conf

add # (comment) on line "blacklist i2c-bcm2708"

#blacklist i2c-bcm2708

Reboot Raspberry PI

sudo shutdown -r now

Re-Check I2C Interface software

$ dmesg | grep i2c
[    5.505513] bcm2708_i2c 20804000.i2c: BSC1 Controller at 0x20804000 (irq 79) (baudrate 100000)
[   11.969815] i2c /dev entries driver

$ lsmod
i2c_bcm2708             6244  0

If you found, software is enabled.


Install DS3231 I2C RTC to Raspberry PI



Test to get time from RTC Module.

$ sudo hwclock -r 
Tue 07 Jul 2015 05:20:09 PM ICT  -0.397656 seconds 

If you want to current time of Raspberry PI to RTC Module.

$ sudo hwclock -w

If you want to set time of RTC Module to Raspberry PI.

$ sudo hwclock -s

You can set time of RTC Module to Raspberry PI on startup.

Edit on file /etc/rc.local
Add line

/sbin/hwclock -s

before line "exit 0"


Reference :
Device Tree overlays of Raspberry PI Firmware
https://github.com/raspberrypi/firmware/tree/master/boot/overlays
Adding a hardware clock to Raspberry Pi (DS3231)
http://www.drewkeller.com/blog/adding-hardware-clock-raspberry-pi-ds3231
Adding a DS3231 Real Time Clock To The Raspberry Pi
http://www.raspberrypi-spy.co.uk/2015/05/adding-a-ds3231-real-time-clock-to-the-raspberry-pi/
Using an I2C Real Time Clock (RTC) with a Raspberry Pi
https://nicegear.co.nz/blog/using-an-i2c-real-time-clock-rtc-with-a-raspberry-pi/

How to use RFID-RC522 on Raspbian



Before use RFID-RC522. Enable SPI Interface (Device Tree Overlays)

On new kernel use Device Tree Overlays.

Edit on /boot/config.txt.

add new line

device_tree_param=spi=on
dtoverlay=spi-bcm2708


Edit on /etc/modprobe.d/raspi-blacklist.conf

add # (comment) on line "blacklist spi-bcm2708"

#blacklist spi-bcm2708

Reboot Raspberry PI

sudo shutdown -r now

Re-Check SPI Interface software

$ dmesg | grep spi
[    5.408904] bcm2708_spi 20204000.spi: master is unqueued, this is deprecated
[    5.659213] bcm2708_spi 20204000.spi: SPI Controller at 0x20204000 (irq 80)

$ lsmod
spi_bcm2708             6010  0

If you found, software is enabled.

Install Software for use RFID-RC522
Install python-dev

sudo apt-get install python-dev

Install SPI-Py (Hardware SPI as a C Extension for Python)

git clone https://github.com/lthiery/SPI-Py.git
cd SPI-Py
sudo python setup.py install

Install MFRC522-python

git clone https://github.com/mxgxw/MFRC522-python.git 
cd MFRC522-python 



Install Pins between Raspberry PI and RFID-RC522

RFID-RC522 Pin
 Raspberry PI Pin
Raspberry PI Pin name
SDA
  24
    GPIO8
SCK
  23
    GPIO11
MOSI
  19
    GPIO10
MISO
  21
    GPIO9
IRQ
  None
    None
GND
  Any
    Any Ground
RST
  22
    GPIO25
3.3V
  1
    3V3

You can test read card.
sudo python Read.py
Welcome to the MFRC522 data read example
Press Ctrl-C to stop.
If touch the card, it will display.

Welcome to the MFRC522 data read example
Press Ctrl-C to stop.
Card detected
Card read UID: XX,XX,XX,XX
Size: 8
Sector 8 [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
Ctrl+C for Stop.

And test write card.

$ sudo python Write.py
Card detected
Card read UID: XX,XX,XX,XX
Size: 8

Sector 8 looked like this:
Sector 8 [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]

Sector 8 will now be filled with 0xFF:
4 backdata &0x0F == 0x0A 10
Data written

It now looks like this:
Sector 8 [255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255]

Now we fill it with 0x00:
4 backdata &0x0F == 0x0A 10
Data written

It is now empty:
Sector 8 [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]

You can learning python code for use RFID read and write data.



and other python library : https://github.com/ondryaso/pi-rc522



Example Project for use NFC and Raspberry PI


  • Attendance system using Raspberry Pi and NFC Tag reader by Yim

http://www.instructables.com/id/Attendance-system-using-Raspberry-Pi-and-NFC-Tag-r/


Reference : 

Device Tree overlays of Raspberry PI Firmware
SPI-PY
MFRC522-python
MIFARE (MFRC522) datasheet
PI-RC522