วันจันทร์ที่ 8 ธันวาคม พ.ศ. 2557

Raspberry Pi connect TFT LCD with Python Library


Raspberry Pi connect TFT LCD 

with Python Library from Adafruit

Hardware
  1. Raspberry Pi Board ( we use raspberry pi model B )
  2. TFT LCD ( Adafruit  Chip Set ILI9341 or compatible)  we use 2.2" TFT LCD from Elec Freaks  



Feature:
  • TFT01_2.2 SP is a 2.2 "SPI TFT LCD Screen Module, 10pins interface, compatible LCD5110 interface. Not just a LCD break but include SD card (2GB),
  • The LCD in the TFT01 is ILI9341. It's a 240 * 320 (resolution), 2.2S inch TFT LCD screen.The LCD has a wide viewing angle, the contrast is also very suitable.
  • The display interface is serial, it just needs 5 wires (CS, RS, SCL, SDA, RST) for controlling.
  • Replace LCD5110, Support direct plug in ElecFreaks Joystick shield, EFCom, Key Pad Shield etc
  • SDcard use hardware SPI interface (CS / MOSI / MISO / SCK), Not solder pins.
Parameter:
  • SDO: Serial clock output
  • LED: 3.3V IO and Power Supply pin
  • SCL: Serial clock input
  • SDA / SDI: Serial data input
  • DC: Data / Command selection
  • RST: Reset, Low level active
  • CS: Chip Selection, Low level active
  • GND: Ground
  • VDD33: 3.3V Power Supply pin
  • UTFT Support

Wiring Diagram

Raspberry Pi ( Model B )
TFT LCD
Pin 3.3V 
Pin VCC
Pin GND 
Pin GND
GPIO18
Pin DC
GPIO23
Pin Reset
GPIO10 ( SPI0 MOSI )
Pin SDI(MOSI)
GPIO11 ( SPI0 SCLK )  
Pin SCK
GPIO08 ( SPI0 CE0 )
Pin CS



TFT LCD Pinout




Raspberry Pi Pinout






Software

use Python ILI9341 TFT LCD Library from Adafruit
https://github.com/adafruit/Adafruit_Python_ILI9341

Python Code image.py


import Image

import Adafruit_ILI9341 as TFT
import Adafruit_GPIO as GPIO
import Adafruit_GPIO.SPI as SPI


# Raspberry Pi configuration.
DC = 18
RST = 23
SPI_PORT = 0
SPI_DEVICE = 0

# BeagleBone Black configuration.
# DC = 'P9_15'
# RST = 'P9_12'
# SPI_PORT = 1
# SPI_DEVICE = 0

# Create TFT LCD display class.
disp = TFT.ILI9341(DC, rst=RST, spi=SPI.SpiDev(SPI_PORT, SPI_DEVICE, max_speed_hz=64000000))

# Initialize display.
disp.begin()

# Load an image.
print 'Loading image...'
image = Image.open('cat.jpg')

# Resize the image and rotate it so it's 240x320 pixels.
image = image.rotate(90).resize((240, 320))

# Draw the image on the display hardware.
print 'Drawing image'
disp.display(image)


Python Code shapes.py


import Image
import ImageDraw
import ImageFont

import Adafruit_ILI9341 as TFT
import Adafruit_GPIO as GPIO
import Adafruit_GPIO.SPI as SPI


# Raspberry Pi configuration.
DC = 18
RST = 23
SPI_PORT = 0
SPI_DEVICE = 0

# BeagleBone Black configuration.
# DC = 'P9_15'
# RST = 'P9_12'
# SPI_PORT = 1
# SPI_DEVICE = 0

# Create TFT LCD display class.
disp = TFT.ILI9341(DC, rst=RST, spi=SPI.SpiDev(SPI_PORT, SPI_DEVICE, max_speed_hz=64000000))

# Initialize display.
disp.begin()

# Clear the display to a red background.
# Can pass any tuple of red, green, blue values (from 0 to 255 each).
disp.clear((255, 0, 0))

# Alternatively can clear to a black screen by calling:
# disp.clear()

# Get a PIL Draw object to start drawing on the display buffer.
draw = disp.draw()

# Draw some shapes.
# Draw a blue ellipse with a green outline.
draw.ellipse((10, 10, 110, 80), outline=(0,255,0), fill=(0,0,255))

# Draw a purple rectangle with yellow outline.
draw.rectangle((10, 90, 110, 160), outline=(255,255,0), fill=(255,0,255))

# Draw a white X.
draw.line((10, 170, 110, 230), fill=(255,255,255))
draw.line((10, 230, 110, 170), fill=(255,255,255))

# Draw a cyan triangle with a black outline.
draw.polygon([(10, 275), (110, 240), (110, 310)], outline=(0,0,0), fill=(0,255,255))

# Load default font.
font = ImageFont.load_default()

# Alternatively load a TTF font.
# Some other nice fonts to try: http://www.dafont.com/bitmap.php
#font = ImageFont.truetype('Minecraftia.ttf', 16)

# Define a function to create rotated text.  Unfortunately PIL doesn't have good
# native support for rotated fonts, but this function can be used to make a
# text image and rotate it so it's easy to paste in the buffer.
def draw_rotated_text(image, text, position, angle, font, fill=(255,255,255)):
    # Get rendered font width and height.
    draw = ImageDraw.Draw(image)
    width, height = draw.textsize(text, font=font)
    # Create a new image with transparent background to store the text.
    textimage = Image.new('RGBA', (width, height), (0,0,0,0))
    # Render the text.
    textdraw = ImageDraw.Draw(textimage)
    textdraw.text((0,0), text, font=font, fill=fill)
    # Rotate the text image.
    rotated = textimage.rotate(angle, expand=1)
    # Paste the text into the image, using it as a mask for transparency.
    image.paste(rotated, position, rotated)

# Write two lines of white text on the buffer, rotated 90 degrees counter clockwise.
draw_rotated_text(disp.buffer, 'Hello World!', (150, 120), 90, font, fill=(255,255,255))
draw_rotated_text(disp.buffer, 'This is a line of text.', (170, 90), 90, font, fill=(255,255,255))

# Write buffer to display hardware, must be called to make things visible on the
# display!
disp.display()


Don't forget Disable blacklist 

blacklist file
 /etc/modprobe.d/raspi-blacklist.conf  
nano /etc/modprobe.d/raspi-blacklist.conf    
# blacklist spi and i2c by default (many users don't need them)  
#blacklist spi-bcm2708  
#blacklist i2c-bcm2708  


Reference
Adafruit 2.2” TFT connect BeagleBone Black ( or Raspberry Pi )

Adafruit Raspberry Pi TFT Python Library _ILI9341

2.2" TFT LCD from Elec Freaks

Wiring Diagram

Code form GitHub

Enable SPI for Raspberry Pi
http://www.brianhensley.net/2012/07/getting-spi-working-on-raspberry-pi.html


<< บทความต่อไป >>


My Website
email : info@softpowergroup.net   Tel .081-6452400

Raspberry Pi connect USB Wifi

Raspberry Pi connect USB Wifi



Hardware 
USB Wifi for Raspberry Pi (Chip Ralink RT5370)

 


Edit Network Setting ( use nano editor )

sudo nano /etc/network/interfaces


Add Your Network

auto lo
iface lo inet loopback
iface eth0 inet dhcp
allow-hotplug wlan0
auto wlan0
iface wlan0 inet dhcp
   wpa-ssid "Your Network SSID"
   wpa-psk "Your Password"

To save the file press Ctrl+O 
exit nano by pressing Ctrl+X


Reload Network

sudo service networking reload


Show your IP Address

ifconfig

wlan0 Link encap:Ethernet HWaddr 80:1f:02:aa:12:58
      inet addr:192.168.0.105 Bcast:192.168.1.255 Mask:255.255.255.0
      UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
      RX packets:154 errors:0 dropped:173 overruns:0 frame:0
      TX packets:65 errors:0 dropped:0 overruns:0 carrier:0
      collisions:0 txqueuelen:1000
      RX bytes:32399 (31.6 KiB) TX bytes:13036 (12.7 KiB)



For Raspberry Pi3

Open the wpa-supplicant configuration file in nano:
sudo nano /etc/wpa_supplicant/wpa_supplicant.conf
Go to the bottom of the file and add the following:

network={
        ssid="YOUR_NETWORK"
        psk="YOUR_PASSWORD"
        key_mgmt=WPA-PSK
}

<< บทความต่อไป >>


My Website
email : info@softpowergroup.net   Tel .081-6452400


วันศุกร์ที่ 5 ธันวาคม พ.ศ. 2557

Raspberry Pi Pinout




Raspberry Pi Pinout


Model B





Model B+



<< บทความต่อไป >>


My Website
http://softpowergroup.net/
email : info@softpowergroup.net   Tel .081-6452400
Google+  https://plus.google.com/+SoftpowergroupNetThailand/


วันพุธที่ 3 ธันวาคม พ.ศ. 2557

Raspberry Pi Hardware


Raspberry Pi Hardware


CPU 
Early in this chapter we touched upon ARM the British manufacturers of central processor unit (CPU) cores. The Raspberry Pi comes equipped with a 700 MHz, ARM1176JZF-S core part of the ARM 11 32-bit multi-processor core family.
The CPU is the main component of the Raspberry Pi, responsible for carrying out the instructions of a computer program via mathematical and logical operations. The Raspberry Pi is in good company using the ARM 11 series and has joined the ranks of the iPhone, Amazon Kindle, and Samsung Galaxy.

GPU
The graphics-processing unit (GPU) is a specialized chip designed to speed up the manipulation of image calculations.
In the case of our Raspberry Pi, it comes equipped with a Broadcom VideoCore IV capable of hardware accelerated playback and support for OpenGL.
This is especially useful if you want to run games or video via your Raspberry Pi, or work on 3D graphics in an open source application such as Blender.

RAM
The Raspberry Pi comes equipped with 256 MB of SDRAM on older versions of the model B and 512 MB on the newer revisions. This isn't a huge amount, and much less than you would expect on a PC, where RAM is available in gigabytes. However, for the type of applications we will be building, 256 MB or 512 MB of RAM will be more
than enough.

SD card port
The main storage mechanism of the Raspberry Pi is via the SD card port. The SD card will be where we install our operating system and will act as our basic hard disk. Of course, this storage can be expanded upon using the USB ports.

USB Ports
USB is one of the most common methods for connecting peripherals and storage devices to a computer. The Raspberry Pi comes equipped with two of them, allowing you to hook up a keyboard and mouse when you get started and a micro USB port for powering your device.

HDMI port
The High Definition Multi-media Interface ( HDMI ) port allows the Raspberry Pi to be hooked up to high definition televisions and monitors that support the technology. This provides an additional option to the composite RCA port for video and additionally supports audio.
Should you wish to stream video and audio from the web to your TV, this is the port you would want to use.

Ethernet port
The Ethernet port is the Raspberry Pi's main gateway to communicating with other devices and the Internet. You will be able to use the Ethernet port to plug your Raspberry Pi into a home router such as the one you currently use to access the Internet, or a network switch if you have one set up.

GPIO pins
The General Purpose Input/Output (GPIO) pins on the Raspberry Pi are the main way of connecting with other electronic boards such as the Arduino.
As the name suggests, the GPIO pins can accept input and output commands and thus can be programmed on the Raspberry Pi.

3.5mm analog audio jack
The 3.5mm analog audio jack allows you to connect headphones and speakers to the Raspberry Pi. This is especially useful for audio and media player based projects.

Composite RCA port
You are probably familiar with the composite cables used to hook up your DVD player to the TV. They usually come in the red, white, and yellow plug variety.
The Raspberry Pi has a port for attaching the yellow video cable from your TV to it, allowing you to use your TV as a monitor.

<< บทความต่อไป >>


My Website
email : info@softpowergroup.net   Tel .081-6452400