Home

Awesome

Build your IoT on the Raspberry Pi

I have bought the Raspberry Pi in the year 2012, almost at the time when the mini board came to the world. I have used it as media center by installing XMBC/OpenElec, NAS, and also work as one robot to post message to sina weibo and Twitter. But somehow I almost retired it, because it's bit slow and I have the new TV box based on Android, and it can meet my requirements for play video/TV Show. And I have bought the Xiaomi Router, it works good, and cover my NAS requirements.

But the time is changing, the Google has just release the Android Things for development Internet of Things with more convenient tools, SDK, IDE. And of couse the Raspberry Pi 3 has release in 2016, and from the spec, it is fast and have good performance to work as the daily development for fun.

So I buy the new one, and now I have many hardwares for play with

Car on Raspberry Pi

Currently, I am working on the smart car on Raspberry Pi, I build:

Tools

I have written some scripts to run/monitor my car. They are very import for understanding how it works

Android App

I have develop one Android App to control my car, it support

Android App Screenshots

Car Main Controller Car Controller Car Weather Status

Realtime Weather Station

I have already built one simple realtime weather station, to provider the PM2.5/Temperature/Himidity, please check

I will start to learning followings

Weather Station Demo

RealTime Weather Station

GPIO Python

Now it's simple to install the GPIO Module for Python

pip install RPi.GPIO

Refer http://www.cnblogs.com/rainduck/archive/2012/09/22/2694568.html

  1. Download Rpi.GPIO http://pypi.python.org/pypi/RPi.GPIO/
  2. sudo apt-get install python-dev
  tar xvzf RPi.GPIO-0.x.xx.tar.gz
  cd RPi.GPIO-0.x.xx
  sudo python setup.py install
  sudo easy_install -U RPIO
  sudo rpio -I

PMS5003T

Dump the binary data with od

The hex data will be like as the following format

#ttyAMA0:0042 004d 0014 0022 0033
#ttyUSB0:4d42 1400 2500 2f00

Debug the hex data

sudo od /dev/ttyAMA0
sudo od -Ax -tcx1 /dev/ttyAMA0
sudo xxd /dev/ttyAMA0

The hex data will be like

00 42
00 4d
00 1c
00 0a
00 0f
00 10
00 0a
00 0f
00 10
08 5e
02 6c
00 4b
00 05
00 e7
01 05
91 00
03 9f
1c 00
0a 00
0f 00
10 00

Run PMS5003T Script

Run the python script, and it will print the details

  cd pms5003t
  sudo ./g5.py

And the result will be like

Mon Feb 27 14:51:02 2017 pm2.5: 36 pm2.5(cf): 40 pm1.0: 26 pm10: 43 temp(c): 22.8 humi(%): 18.0 version: 145 error: 0
Mon Feb 27 14:51:04 2017 pm2.5: 36 pm2.5(cf): 41 pm1.0: 26 pm10: 44 temp(c): 22.7 humi(%): 17.9 version: 145 error: 0
Mon Feb 27 14:51:09 2017 pm2.5: 36 pm2.5(cf): 41 pm1.0: 26 pm10: 44 temp(c): 22.8 humi(%): 18.0 version: 145 error: 0
Mon Feb 27 14:51:15 2017 pm2.5: 36 pm2.5(cf): 41 pm1.0: 26 pm10: 43 temp(c): 22.7 humi(%): 17.9 version: 145 error: 0
Mon Feb 27 14:51:20 2017 pm2.5: 37 pm2.5(cf): 42 pm1.0: 26 pm10: 45 temp(c): 22.7 humi(%): 18.1 version: 145 error: 0
Mon Feb 27 14:51:26 2017 pm2.5: 38 pm2.5(cf): 44 pm1.0: 27 pm10: 46 temp(c): 22.7 humi(%): 18.0 version: 145 error: 0

Android Things

Android Things on Raspberry Pi 3

Add auto script to Raspberry Pi

Reference

 sudo systemctl --force --full edit car.service
 sudo systemctl enable --now car.service
 cat /etc/systemd/system/car.service
 systemctl status car.service
[Unit]
Description=Start my Smart Car
After=multi-user.target

[Service]
User=pjq
ExecStart=/home/pjq/rpi/tools/deploy_server.sh

[Install]

motion

commands tips

sudo apt install motion
sudo chown motion.root /var/log/motion/
sudo modprobe bcm2835-v4l2
sudo vim /etc/motion/motion.conf
sudo service motion restart
tail -f  /var/log/motion/motion.log

motion config

grep -v -E "#|^$" /etc/motion/motion.conf
daemon off
setup_mode off
; pid_file value
log_file /var/log/motion/motion.log
log_level 6
target_dir /var/lib/motion
videodevice /dev/video0
; vid_control_params value
; netcam_url value
; mmalcam_name value
; mmalcam_control_params value
width 640
height 480
framerate 15
text_left CAMERA1
text_right %Y-%m-%d\n%T-%q
emulate_motion off
threshold 1500
; noise_level 32
despeckle_filter EedDl
minimum_motion_frames 1
event_gap 60
pre_capture 3
post_capture 0
; on_event_start value
; on_event_end value
; on_movie_end value
picture_output off
picture_filename %Y%m%d%H%M%S-%q
movie_output on
movie_max_time 60
movie_quality 45
movie_codec mkv
movie_filename %t-%v-%Y%m%d%H%M%S
webcontrol_port 8080
webcontrol_localhost off
webcontrol_parms 0
stream_port 8081
stream_localhost off
; camera /usr/etc/motion/camera1.conf
; camera /usr/etc/motion/camera2.conf
; camera /usr/etc/motion/camera3.conf
; camera /usr/etc/motion/camera4.conf
; camera_dir /usr/etc/motion/conf.d