Advertisement
sohotcall

Raspberry Pi Notes

Sep 8th, 2018
310
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.91 KB | None | 0 0
  1. Installation
  2. ============
  3. Cek microSD card
  4. $ lsblk
  5.  
  6. Unmount
  7. $ umount /dev/sdb1
  8.  
  9. Install
  10. $ unzip -p 2018-04-18-raspbian-stretch.zip | dd bs=4M of=/dev/sdX status=progress conv=fsync
  11. $ sync
  12.  
  13. Now go to the SD card /boot
  14. $ cd /media/gungsukma/boot
  15.  
  16. $ touch ssh
  17. $ nano wpa_supplicant.conf
  18. ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
  19. network={
  20. ssid="YOUR_NETWORK_NAME"
  21. psk="YOUR_PASSWORD"
  22. key_mgmt=WPA-PSK
  23. }
  24.  
  25. Okay. Installation finished.
  26.  
  27. Setup
  28. - Ubah password, aktifkan WiFi
  29. - Aktifkan kamera, SSH, serial, remote GPIO
  30. - Pilih timezone, keyboard layout
  31. $ sudo raspi-config
  32. $ sudo apt-get update
  33. $ sudo apt-get upgrade
  34.  
  35.  
  36. GPIO
  37. ====
  38. old/new
  39. #1 3V3 #2 5V
  40. #3 0/2(SDA0/1) #4 5V
  41. #5 1/3(SCL0/1) #6 Gnd
  42. #7 4 #8 14(TX)
  43. #9 Gnd #10 15(RX)
  44. #11 17 #12 18
  45. #13 21/27 #14 Gnd
  46. #15 22 #16 23
  47. #17 3V3 #18 24
  48. #19 10(MOSI) #20 Gnd
  49. #21 9(MISO) #22 25
  50. #23 11(SCLK) #24 8
  51. #25 Gnd #26 7
  52.  
  53. $ sudo python
  54. > import RPi.GPIO as GPIO
  55. > GPIO.RPI_INFO
  56. > GPIO.RPI_INFO['P1_REVISION']
  57. > GPIO.VERSION
  58. > GPIO.setwarnings(False)
  59. > GPIO.setmode(GPIO.BCM)
  60. > GPIO.setup(23, GPIO.IN)
  61. > GPIO.setup(23, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
  62. > GPIO.setup(24, GPIO.IN, pull_up_down=GPIO.PUD_UP)
  63. > if GPIO.input(23) == 1:
  64. > pass
  65. > GPIO.wait_for_edge(23, GPIO.RISING)
  66. > GPIO.wait_for_edge(23, GPIO.FALLING)
  67. > GPIO.setup(23, GPIO.OUT, initial=GPIO.HIGH)
  68. > GPIO.output(23, GPIO.LOW)
  69. > GPIO.cleanup()
  70.  
  71.  
  72. Kamera
  73. ======
  74. Hidupkan kameranya
  75. $ sudo raspi-config
  76.  
  77. Tiga ribu milidetik menuju cheese
  78. $ raspistill -t 3000 -o test.jpg
  79. JPEG quality 10% ukuran VGA
  80. $ raspistill -w 640 -h 480 -n -t 100 -q 10 -e jpg -th none -o vga_100ms_jpg10.jpg
  81.  
  82. Biar punya /dev/video0
  83. $ sudo modprobe bcm2835-v4l2
  84. $ sudo nano /etc/modules
  85. tambahkan baris bcm2835-v4l2
  86.  
  87.  
  88. RPI-Clone
  89. =========
  90. $ wget https://github.com/billw2/rpi-clone/archive/master.zip
  91. $ unzip master.zip
  92. $ cd rpi-clone
  93. $ sudo cp rpi-clone rpi-clone-setup /usr/local/sbin
  94. $ sudo rpi-clone sdb
  95. $ sudo rpi-clone sdb -s new_hostname
  96.  
  97.  
  98. Save SD Card Life
  99. =================
  100. $ sudo nano /etc/fstab
  101. Tambahkan ini
  102. none /var/log tmpfs size=1M,noatime 0 0
  103. tmpfs /tmp tmpfs defaults,noatime,mode=1777,size=30m 0 0
  104. $ sudo dphys-swapfile swapoff
  105. $ sudo dphys-swapfile uninstall
  106. $ sudo update-rc.d dphys-swapfile remove
  107.  
  108.  
  109. Python Get CPU Temperature
  110. ==========================
  111. def getCPUtemperature():
  112. res = os.popen("vcgencmd measure_temp").readline()
  113. temp =(res.replace("temp=","").replace("'C\n",""))
  114. return int(float(temp))
  115.  
  116. Python Get Raspi Serial Number
  117. ==============================
  118. http://www.raspberrypi-spy.co.uk/2012/09/getting-your-raspberry-pi-serial-number-using-python/
  119. def getserial():
  120. # Extract serial from cpuinfo file
  121. cpuserial = "0000000000000000"
  122. try:
  123. f = open('/proc/cpuinfo','r')
  124. for line in f:
  125. if line[0:6]=='Serial':
  126. cpuserial = line[10:26]
  127. f.close()
  128. except:
  129. cpuserial = "ERROR000000000"
  130. return cpuserial
  131.  
  132.  
  133. HCSR04
  134. ======
  135. import RPi.GPIO as GPIO
  136. import time
  137. GPIO.setmode(GPIO.BCM)
  138.  
  139. GPIO_TRIGGER = 18
  140. GPIO_ECHO = 24
  141. GPIO.setup(GPIO_TRIGGER, GPIO.OUT)
  142. GPIO.setup(GPIO_ECHO, GPIO.IN)
  143.  
  144. def distance(): # centimeter
  145. GPIO.output(GPIO_TRIGGER, True)
  146. time.sleep(0.00001)
  147. GPIO.output(GPIO_TRIGGER, False)
  148.  
  149. while GPIO.input(GPIO_ECHO) == 0:
  150. pass
  151. StartTime = time.time()
  152. while GPIO.input(GPIO_ECHO) == 1:
  153. pass
  154. StopTime = time.time()
  155. distance = 34300 * (StopTime - StartTime) / 2
  156.  
  157. return distance
  158.  
  159.  
  160. WS2812B
  161. =======
  162. $ sudo apt-get install python-pip
  163. $ sudo pip install rpi_ws281x
  164. $ nano ws2812b.py
  165. import time
  166. from rpi_ws281x import x
  167. LED_COUNT = 12
  168. #GPIO18 (Pin#12)
  169. strip = Adafruit_NeoPixel(LED_COUNT, 18, 800000, 10, False, 255, 0)
  170. strip.begin()
  171. for i in range(strip.numPixels()):
  172. strip.setPixelColor(i, Color(255,255,255))
  173. strip.show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement