Kamis, 28 Oktober 2021

Raspi LCD 16x2

 import smbus
import time
 
# Define some device parameters
I2C_ADDR  = 0x27 # I2C device address
LCD_WIDTH = 16   # Maximum characters per line

# Define some device constants
LCD_CHR = 1 # Mode - Sending data
LCD_CMD = 0 # Mode - Sending command
LCD_LINE_1 = 0x80 # LCD RAM address for the 1st line
LCD_LINE_2 = 0xC0 # LCD RAM address for the 2nd line
LCD_LINE_3 = 0x94 # LCD RAM address for the 3rd line
LCD_LINE_4 = 0xD4 # LCD RAM address for the 4th line
LCD_BACKLIGHT  = 0x08  # On
#LCD_BACKLIGHT = 0x00  # Off
ENABLE = 0b00000100 # Enable bit
# Timing constants
E_PULSE = 0.0005
E_DELAY = 0.0005
#Open I2C interface
#bus = smbus.SMBus(0)  # Rev 1 Pi uses 0
bus = smbus.SMBus(1) # Rev 2 Pi uses 1

def lcd_init():
  # Initialise display
  lcd_byte(0x33,LCD_CMD) # 110011 Initialise
  lcd_byte(0x32,LCD_CMD) # 110010 Initialise
  lcd_byte(0x06,LCD_CMD) # 000110 Cursor move direction
  lcd_byte(0x0C,LCD_CMD) # 001100 Display On,Cursor Off, Blink Off 
  lcd_byte(0x28,LCD_CMD) # 101000 Data length, number of lines, font size
  lcd_byte(0x01,LCD_CMD) # 000001 Clear display
  time.sleep(E_DELAY)

def lcd_byte(bits, mode):
  # Send byte to data pins
  # bits = the data
  # mode = 1 for data
  #        0 for command
  bits_high = mode | (bits & 0xF0) | LCD_BACKLIGHT
  bits_low = mode | ((bits<<4) & 0xF0) | LCD_BACKLIGHT
  # High bits
  bus.write_byte(I2C_ADDR, bits_high)
  lcd_toggle_enable(bits_high)
  # Low bits
  bus.write_byte(I2C_ADDR, bits_low)
  lcd_toggle_enable(bits_low)

def lcd_toggle_enable(bits):
  # Toggle enable
  time.sleep(E_DELAY)
  bus.write_byte(I2C_ADDR, (bits | ENABLE))
  time.sleep(E_PULSE)
  bus.write_byte(I2C_ADDR,(bits & ~ENABLE))
  time.sleep(E_DELAY)

def lcd_string(message,line):
  # Send string to display
  message = message.ljust(LCD_WIDTH," ")
  lcd_byte(line, LCD_CMD)
  for i in range(LCD_WIDTH):
    lcd_byte(ord(message[i]),LCD_CHR)

def main():
  # Main program block
  # Initialise display
  lcd_init()
  while True:
    # Send some test
    lcd_string("RPiSpy         <",LCD_LINE_1)
    lcd_string("I2C LCD        <",LCD_LINE_2)
    time.sleep(3)
  
    # Send some more text
    lcd_string(">         RPiSpy",LCD_LINE_1)
    lcd_string(">        I2C LCD",LCD_LINE_2)
    time.sleep(3)
if __name__ == '__main__':
  try:
    main()
  except KeyboardInterrupt:
    pass
  finally:
    lcd_byte(0x01, LCD_CMD)

Raspi Insatall dan Koneksi Database New

UPDATE:

sudo apt-get update && sudo apt-get upgrade


RASPI INSATLL DATABASE SERVER:

sudo apt-get install python3-dev libmysqlclient-dev
sudo pip3 install mysqlclient

ATAU

sudo apt-get install python3-dev **default-libmysqlclient-dev**

sudo pip3 install mysqlclient


INSTALL PIP3

sudo python3-pip


INSTALL CV2

sudo apt update

sudo apt install python3-opencv


CONFIG CAMERA DLL

sudo raspi-config
df -h
sudo reboot


LCD:

 sudo raspi-config

 sudo apt-get install i2c-tools

 sudo apt-get install python-smbus

 i2cdetect -y 1

 

import MySQLdb
from time import sleep
db = MySQLdb.connect("localhost","root","","2021_deteksicitra")
cursor = db.cursor()
sql = "UPDATE `tb_pengujian`  set `status`='1',`rekapitulasi`='%s',`bobot`='%s',`kategori`='%s' where id_pengujian='%s'" % (rekapitulasi,bobot,kategori,idx)
#print(sql)
try:
cursor.execute(sql)
db.commit()
v=1
except:
db.rollback()
    db.close() 

while (True):
    ada=0
    db = MySQLdb.connect("localhost","root","","2021_deteksikentang")
    cursor = db.cursor()
    
    cursor.execute("SELECT `id_pengujian`, `nama_pengujian`, `gambar`,`status` FROM `tb_pengujian` where status='0' order by id_pengujian desc")
    for row in cursor.fetchall():
        ada=1
        id_pengujian=row[0]
        nama_pengujian=row[1]
        gambar=row[2]
        status=row[3]
        
        lokasi = PATH_UJI+gambar  
        print(lokasi)
        LoadCNN(lokasi,id_pengujian,rekapitulasi,bobot)
    time.sleep(1)
    db.close()

XRDP GUI Remote Control Raspi

 

1.Buat User baru yang memiliki password jika belum ada, misal

sudo adduser adi

sudo usermod adi -a -G pi,adm,dialout,cdrom,sudo,audio,video,plugdev,games,users,input,netdev,spi,i2c,gpio


2.Update Raspi, agar sehingga bisa kita remote jarak jauh secara FULL GUI

sudo apt update

sudo apt-get install raspberrypi-ui-mods xinit xserver-xorg

sudo reboot


3.Konfigurasi XRDP

sudo apt install xrdp 

systemctl show -p SubState --value xrdp

sudo adduser xrdp ssl-cert  


4.Jalankan RemoteControl Windows (ketik mstc)


5.Masukkan IP raspi (buat jadi satu jaringan ya...sama2 dalam router yang sama antara raspi dan laptop)