Raspberry Pi

iot stem linux raspberry pi
Created on 2017-09-19 Last Modified 2018-08-30


Basic setting

Auto-start

Use sudo crontab -e to set autostart programme

@reboot python /home/pi/MyScript.py &

This tells Cron that every boot (or reboot or start-up) we want to run Python with the script MyScript.py. The “&” at the end of the line means the command is run in the background and it won’t stop the system booting up as before.

To kill the job

ps aux | grep /home/pi/MyScript.py

sudo kill pid_show_in_ps

Python library

Pin

pin pin2

Examples

Links

Some Projects

Some thoughts

“Blinking LED” is just like writing an “hello world” programme in physical computing.

Sensors

sensors

import RPi.GPIO as GPIO
import time
GPIO.setwarnings(False)
GPIO.setmode(GPIO.BCM)
GPIO.setup(11, GPIO.IN)         #Read output from PIR motion sensor
GPIO.setup(18, GPIO.OUT)         #LED output pin
while True:
       i=GPIO.input(11)
       if i==0:                 #When output from motion sensor is LOW
             print "No intruders",i
             GPIO.output(18, 0)  #Turn OFF LED
             time.sleep(0.1)
       elif i==1:               #When output from motion sensor is HIGH
             print "Intruder detected",i
             GPIO.output(18, 1)  #Turn ON LED
             time.sleep(0.1)

Others

Using Raspberry Pi to control servo

Sensor HAT

ADC (Analog to Digital Convertor)

Reference


comments powered by Disqus