├── setgame ├── .gitignore ├── test.jpg ├── test2.jpg ├── main.py └── setgameLib.py ├── README.md ├── arduino ├── car │ ├── .gitignore │ ├── keypress.pyc │ ├── runTF.sh │ ├── platformio.ini │ ├── runCar.py │ ├── lib │ │ └── readme.txt │ ├── keypress.py │ ├── .travis.yml │ ├── keypress2.py │ └── src │ │ └── main.cpp ├── test │ ├── .gitignore │ ├── platformio.ini │ ├── src │ │ └── main.cpp │ ├── lib │ │ └── readme.txt │ ├── .travis.yml │ └── success.log ├── ir_test │ ├── .gitignore │ ├── read.py │ ├── platformio.ini │ ├── keymap.log │ ├── src │ │ └── main.cpp │ ├── lib │ │ └── readme.txt │ └── .travis.yml ├── tools │ ├── sertest.py │ └── keypress.py └── readSerial.py ├── .gitignore ├── camera ├── camera.sh ├── cronjobs.txt └── genlapse.sh ├── gpio ├── motor.py ├── led.py ├── led2.py └── servo.py ├── .tmux.conf └── cheatsheet.txt /setgame/.gitignore: -------------------------------------------------------------------------------- 1 | images 2 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Raspberry Pi projects 2 | -------------------------------------------------------------------------------- /arduino/car/.gitignore: -------------------------------------------------------------------------------- 1 | .pioenvs 2 | .piolibdeps 3 | -------------------------------------------------------------------------------- /arduino/test/.gitignore: -------------------------------------------------------------------------------- 1 | .pioenvs 2 | .piolibdeps 3 | -------------------------------------------------------------------------------- /arduino/ir_test/.gitignore: -------------------------------------------------------------------------------- 1 | .pioenvs 2 | .piolibdeps 3 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | camera/out.log 2 | camera/pics/ 3 | camera/videos/ 4 | -------------------------------------------------------------------------------- /setgame/test.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Zippen-Huang/rpi-master-Arduino-TensorFlow/HEAD/setgame/test.jpg -------------------------------------------------------------------------------- /setgame/test2.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Zippen-Huang/rpi-master-Arduino-TensorFlow/HEAD/setgame/test2.jpg -------------------------------------------------------------------------------- /camera/camera.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | DATE=$(date +"%Y-%m-%d_%H%M") 3 | raspistill -o /home/pi/rpi/camera/pics/$DATE.jpg 4 | -------------------------------------------------------------------------------- /arduino/car/keypress.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Zippen-Huang/rpi-master-Arduino-TensorFlow/HEAD/arduino/car/keypress.pyc -------------------------------------------------------------------------------- /arduino/car/runTF.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | cd ~/tensorflow 3 | tensorflow/contrib/pi_examples/camera/gen/bin/camera | xargs -n1 flite -t 4 | -------------------------------------------------------------------------------- /camera/cronjobs.txt: -------------------------------------------------------------------------------- 1 | * * * * * /home/pi/rpi/camera/camera.sh 2>&1 2 | 50 23 * * * /home/pi/rpi/camera/genlapse.sh -r > /home/pi/rpi/camera/out.log 2>&1 3 | -------------------------------------------------------------------------------- /arduino/tools/sertest.py: -------------------------------------------------------------------------------- 1 | import serial 2 | port=1 3 | ser = serial.Serial('/dev/ttyACM'+str(port), 9600) 4 | ser.write('3') 5 | #while 1 : 6 | # ser.readline() 7 | -------------------------------------------------------------------------------- /gpio/motor.py: -------------------------------------------------------------------------------- 1 | from gpiozero import Motor 2 | from gpiozero import LED 3 | led = LED(2) 4 | motor = Motor(20, 21) 5 | while True: 6 | led.on() 7 | motor.forward() 8 | -------------------------------------------------------------------------------- /arduino/readSerial.py: -------------------------------------------------------------------------------- 1 | import serial,os 2 | 3 | port = os.popen('ls /dev/ttyACM*').read()[:-1] 4 | baud = 115200 5 | ser = serial.Serial(port, baud) 6 | 7 | while True: 8 | print ser.readline() 9 | -------------------------------------------------------------------------------- /arduino/ir_test/read.py: -------------------------------------------------------------------------------- 1 | import serial,os 2 | 3 | port=os.popen('ls /dev/ttyACM*').read()[:-1] 4 | ser = serial.Serial(port, 115200) 5 | 6 | while True: 7 | line = ser.readline()#.decode('utf-8') 8 | print line 9 | -------------------------------------------------------------------------------- /gpio/led.py: -------------------------------------------------------------------------------- 1 | from gpiozero import LED 2 | from time import sleep 3 | 4 | led = LED(17) 5 | 6 | while True: 7 | print "start cycle" 8 | led.on() 9 | sleep(1) 10 | led.off() 11 | sleep(1) 12 | -------------------------------------------------------------------------------- /gpio/led2.py: -------------------------------------------------------------------------------- 1 | from gpiozero import LED, Button 2 | from signal import pause 3 | 4 | led = LED(17) 5 | button = Button(2) 6 | 7 | button.when_pressed = led.on 8 | button.when_released = led.off 9 | 10 | pause() 11 | -------------------------------------------------------------------------------- /gpio/servo.py: -------------------------------------------------------------------------------- 1 | from gpiozero import Servo 2 | from time import sleep 3 | 4 | servo = Servo(17) 5 | while True: 6 | servo.min() 7 | sleep(1) 8 | servo.mid() 9 | sleep(1) 10 | servo.max() 11 | sleep(1) 12 | -------------------------------------------------------------------------------- /setgame/main.py: -------------------------------------------------------------------------------- 1 | import cv2 2 | import numpy as np 3 | from setgameLib import * 4 | trainSet = ['train/'+str(i)+'.jpg' for i in range(9)] 5 | 6 | trainCards = train(trainSet) 7 | 8 | print "training complete" 9 | 10 | res=[] 11 | for i, card in enumerate(train(['test.jpg'])): 12 | cv2.imwrite('test'+str(i)+'.jpg',card) 13 | r=[] 14 | for trainCard in trainCards: 15 | r.append(imgdiff(card,trainCard)) 16 | res.append(r[:]) 17 | -------------------------------------------------------------------------------- /arduino/test/platformio.ini: -------------------------------------------------------------------------------- 1 | ; PlatformIO Project Configuration File 2 | ; 3 | ; Build options: build flags, source filter 4 | ; Upload options: custom upload port, speed and extra flags 5 | ; Library options: dependencies, extra library storages 6 | ; Advanced options: extra scripting 7 | ; 8 | ; Please visit documentation for the other options and examples 9 | ; http://docs.platformio.org/page/projectconf.html 10 | 11 | [env:uno] 12 | platform = atmelavr 13 | board = uno 14 | framework = arduino 15 | ;upload_port = /dev/tty* 16 | -------------------------------------------------------------------------------- /arduino/car/platformio.ini: -------------------------------------------------------------------------------- 1 | ; PlatformIO Project Configuration File 2 | ; 3 | ; Build options: build flags, source filter 4 | ; Upload options: custom upload port, speed and extra flags 5 | ; Library options: dependencies, extra library storages 6 | ; Advanced options: extra scripting 7 | ; 8 | ; Please visit documentation for the other options and examples 9 | ; http://docs.platformio.org/page/projectconf.html 10 | 11 | [env:uno] 12 | platform = atmelavr 13 | board = uno 14 | framework = arduino 15 | lib_deps = 16 | https://github.com/bengtmartensson/Infrared4Arduino 17 | -------------------------------------------------------------------------------- /arduino/ir_test/platformio.ini: -------------------------------------------------------------------------------- 1 | ; PlatformIO Project Configuration File 2 | ; 3 | ; Build options: build flags, source filter 4 | ; Upload options: custom upload port, speed and extra flags 5 | ; Library options: dependencies, extra library storages 6 | ; Advanced options: extra scripting 7 | ; 8 | ; Please visit documentation for the other options and examples 9 | ; http://docs.platformio.org/page/projectconf.html 10 | 11 | [env:uno] 12 | platform = atmelavr 13 | board = uno 14 | framework = arduino 15 | ; build_flags = -std=gnu++11 16 | lib_deps = 17 | https://github.com/bengtmartensson/Infrared4Arduino 18 | -------------------------------------------------------------------------------- /arduino/car/runCar.py: -------------------------------------------------------------------------------- 1 | import serial,os 2 | import readchar 3 | import keypress 4 | 5 | port=os.popen('ls /dev/ttyACM*').read()[:-1] 6 | ser = serial.Serial(port, 9600) 7 | kp=keypress.KeyPress() 8 | 9 | fnHalt = lambda:ser.write('H') 10 | fnForward = lambda:ser.write('F') 11 | fnBackward = lambda:ser.write('B') 12 | fnTurnLeft = lambda:ser.write('L') 13 | fnTurnRight = lambda:ser.write('R') 14 | fnServoUp = lambda:ser.write('U') 15 | fnServoDown = lambda:ser.write('D') 16 | 17 | keyMap = {\ 18 | 'w':fnForward,\ 19 | 'x':fnBackward,\ 20 | 'a':fnTurnLeft,\ 21 | 'd':fnTurnRight,\ 22 | 'j':fnServoUp,\ 23 | 'k':fnServoDown,\ 24 | 's':fnHalt} 25 | 26 | kp.registerQuitKey('q') 27 | kp.registerHandlers(keyMap) 28 | kp.start() 29 | -------------------------------------------------------------------------------- /arduino/ir_test/keymap.log: -------------------------------------------------------------------------------- 1 | 2 | #define KEY_REPEAT "NEC1 ditto" 3 | #define KEY_POWER "NEC1 0 69" 4 | #define KEY_MODE "NEC1 0 70" 5 | #define KEY_MUTE "NEC1 0 71" 6 | #define KEY_PLAY "NEC1 0 68" 7 | #define KEY_BACK "NEC1 0 64" 8 | #define KEY_FWD "NEC1 0 67" 9 | #define KEY_EQ "NEC1 0 7" 10 | #define KEY_MINUS "NEC1 0 21" 11 | #define KEY_PLUS "NEC1 0 9" 12 | #define KEY_ZERO "NEC1 0 22" 13 | #define KEY_SHUFFLE "NEC1 0 25" 14 | #define KEY_USD "NEC1 0 13" 15 | #define KEY_ONE "NEC1 0 12" 16 | #define KEY_TWO "NEC1 0 24" 17 | #define KEY_THREE "NEC1 0 94" 18 | #define KEY_FOUR "NEC1 0 8" 19 | #define KEY_FIVE "NEC1 0 28" 20 | #define KEY_SIX "NEC1 0 90" 21 | #define KEY_SEVEN "NEC1 0 66" 22 | #define KEY_EIGHT "NEC1 0 82" 23 | #define KEY_NINE "NEC1 0 74" 24 | -------------------------------------------------------------------------------- /.tmux.conf: -------------------------------------------------------------------------------- 1 | # remap prefix from 'C-b' to 'C-a' 2 | unbind C-b 3 | set-option -g prefix C-a 4 | bind-key C-a send-prefix 5 | 6 | # split panes using | and - 7 | bind | split-window -h 8 | bind - split-window -v 9 | unbind '"' 10 | unbind % 11 | 12 | # switch panes using Alt-arrow without prefix 13 | bind -n M-Left select-pane -L 14 | bind -n M-Right select-pane -R 15 | bind -n M-Up select-pane -U 16 | bind -n M-Down select-pane -D 17 | 18 | # Enable mouse control (clickable windows, panes, resizable panes) 19 | set -g mouse-select-window on 20 | set -g mouse-select-pane on 21 | set -g mouse-resize-pane on 22 | setw -g mode-mouse on 23 | 24 | setw -g mode-keys vi 25 | bind -t vi-copy 'v' begin-selection 26 | bind -t vi-copy 'y' copy-selection 27 | 28 | bind-key r source-file ~/.tmux.conf \; display-message "~/.tmux.conf reloaded" 29 | 30 | set -s escape-time 0 31 | -------------------------------------------------------------------------------- /camera/genlapse.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | export PATH=/usr/local/bin:/usr/bin:/bin 3 | cd /home/pi/rpi/camera/pics 4 | ls *.jpg > stills.txt 5 | DATE=$(date +"%Y-%m-%d") 6 | echo "========== Start mencoder ==========" 7 | mencoder -nosound -ovc lavc -lavcopts vcodec=mpeg4:aspect=16/9:vbitrate=8000000 -vf scale=1920:1080 -o $DATE.avi -mf type=jpeg:fps=24 mf://@stills.txt 8 | echo "========== mencoder finished, start MP4Box ==========" 9 | MP4Box -add $DATE.avi ../videos/$DATE.mp4 10 | echo "========== MP4Box finishes ==========" 11 | rm $DATE.avi 12 | if [ ! -z "$1" ]; 13 | then 14 | if [ $1 = "-r" ]; 15 | then 16 | rm *.jpg 17 | echo "========== raw images removed ==========" 18 | else 19 | echo "========== wrong arg, only support: -r ==========" 20 | fi 21 | else 22 | echo "========== raw images NOT removed. set -r if need to remove ==========" 23 | fi 24 | cd .. 25 | -------------------------------------------------------------------------------- /arduino/test/src/main.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Blink 3 | * Turns on an LED on for one second, 4 | * then off for one second, repeatedly. 5 | */ 6 | #include "Arduino.h" 7 | 8 | void setup() 9 | { 10 | // initialize LED digital pin as an output. 11 | pinMode(LED_BUILTIN, OUTPUT); 12 | Serial.begin(9600); 13 | } 14 | 15 | void blink() 16 | { 17 | // turn the LED on (HIGH is the voltage level) 18 | digitalWrite(LED_BUILTIN, HIGH); 19 | // wait for a second 20 | delay(100); 21 | // turn the LED off by making the voltage LOW 22 | digitalWrite(LED_BUILTIN, LOW); 23 | // wait for a second 24 | delay(100); 25 | } 26 | 27 | void light(int n){ 28 | for (int i = 0; i < n; i++) { 29 | blink(); 30 | } 31 | } 32 | 33 | void loop() 34 | { 35 | if (Serial.available()) { 36 | int num = Serial.read()-'0'; 37 | light(num); 38 | } 39 | delay(500); 40 | } 41 | 42 | 43 | -------------------------------------------------------------------------------- /arduino/ir_test/src/main.cpp: -------------------------------------------------------------------------------- 1 | // This sketch uses the IrReceiveSampler to receive a signal, and tries to 2 | // decode it as a NEC1 signal 3 | 4 | #include 5 | #include 6 | 7 | #define RECEIVE_PIN 8 8 | #define BUFFERSIZE 200U 9 | #define BAUD 115200 10 | 11 | IrReceiver *receiver; 12 | 13 | void setup() { 14 | Serial.begin(BAUD); 15 | receiver = IrReceiverSampler::newIrReceiverSampler(BUFFERSIZE, RECEIVE_PIN); 16 | } 17 | 18 | void loop() { 19 | receiver->receive(); 20 | 21 | if (receiver->isEmpty()) 22 | // Serial.println(F("timeout")); 23 | {} 24 | else { 25 | Nec1Decoder decoder(*receiver); 26 | if (decoder.isValid()){ 27 | const char * strDec = decoder.getDecode(); 28 | Serial.println(strDec); 29 | // decoder.printDecode(Serial); 30 | } 31 | else 32 | // Serial.println(F("No decode")); 33 | {} 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /arduino/car/lib/readme.txt: -------------------------------------------------------------------------------- 1 | 2 | This directory is intended for the project specific (private) libraries. 3 | PlatformIO will compile them to static libraries and link to executable file. 4 | 5 | The source code of each library should be placed in separate directory, like 6 | "lib/private_lib/[here are source files]". 7 | 8 | For example, see how can be organized `Foo` and `Bar` libraries: 9 | 10 | |--lib 11 | | |--Bar 12 | | | |--docs 13 | | | |--examples 14 | | | |--src 15 | | | |- Bar.c 16 | | | |- Bar.h 17 | | |--Foo 18 | | | |- Foo.c 19 | | | |- Foo.h 20 | | |- readme.txt --> THIS FILE 21 | |- platformio.ini 22 | |--src 23 | |- main.c 24 | 25 | Then in `src/main.c` you should use: 26 | 27 | #include 28 | #include 29 | 30 | // rest H/C/CPP code 31 | 32 | PlatformIO will find your libraries automatically, configure preprocessor's 33 | include paths and build them. 34 | 35 | More information about PlatformIO Library Dependency Finder 36 | - http://docs.platformio.org/page/librarymanager/ldf.html 37 | -------------------------------------------------------------------------------- /arduino/test/lib/readme.txt: -------------------------------------------------------------------------------- 1 | 2 | This directory is intended for the project specific (private) libraries. 3 | PlatformIO will compile them to static libraries and link to executable file. 4 | 5 | The source code of each library should be placed in separate directory, like 6 | "lib/private_lib/[here are source files]". 7 | 8 | For example, see how can be organized `Foo` and `Bar` libraries: 9 | 10 | |--lib 11 | | |--Bar 12 | | | |--docs 13 | | | |--examples 14 | | | |--src 15 | | | |- Bar.c 16 | | | |- Bar.h 17 | | |--Foo 18 | | | |- Foo.c 19 | | | |- Foo.h 20 | | |- readme.txt --> THIS FILE 21 | |- platformio.ini 22 | |--src 23 | |- main.c 24 | 25 | Then in `src/main.c` you should use: 26 | 27 | #include 28 | #include 29 | 30 | // rest H/C/CPP code 31 | 32 | PlatformIO will find your libraries automatically, configure preprocessor's 33 | include paths and build them. 34 | 35 | More information about PlatformIO Library Dependency Finder 36 | - http://docs.platformio.org/page/librarymanager/ldf.html 37 | -------------------------------------------------------------------------------- /arduino/ir_test/lib/readme.txt: -------------------------------------------------------------------------------- 1 | 2 | This directory is intended for the project specific (private) libraries. 3 | PlatformIO will compile them to static libraries and link to executable file. 4 | 5 | The source code of each library should be placed in separate directory, like 6 | "lib/private_lib/[here are source files]". 7 | 8 | For example, see how can be organized `Foo` and `Bar` libraries: 9 | 10 | |--lib 11 | | |--Bar 12 | | | |--docs 13 | | | |--examples 14 | | | |--src 15 | | | |- Bar.c 16 | | | |- Bar.h 17 | | |--Foo 18 | | | |- Foo.c 19 | | | |- Foo.h 20 | | |- readme.txt --> THIS FILE 21 | |- platformio.ini 22 | |--src 23 | |- main.c 24 | 25 | Then in `src/main.c` you should use: 26 | 27 | #include 28 | #include 29 | 30 | // rest H/C/CPP code 31 | 32 | PlatformIO will find your libraries automatically, configure preprocessor's 33 | include paths and build them. 34 | 35 | More information about PlatformIO Library Dependency Finder 36 | - http://docs.platformio.org/page/librarymanager/ldf.html 37 | -------------------------------------------------------------------------------- /arduino/tools/keypress.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | #https://rosettacode.org/wiki/Keyboard_input/Keypress_check#Python 3 | 4 | import __future__ 5 | import sys 6 | if sys.version_info.major < 3: 7 | import thread as _thread 8 | else: 9 | import _thread 10 | import time 11 | 12 | 13 | try: 14 | from msvcrt import getch # try to import Windows version 15 | except ImportError: 16 | print "no msvcrt" 17 | def getch(): # define non-Windows version 18 | import tty, termios 19 | fd = sys.stdin.fileno() 20 | old_settings = termios.tcgetattr(fd) 21 | try: 22 | tty.setraw(sys.stdin.fileno()) 23 | ch = sys.stdin.read(1) 24 | finally: 25 | termios.tcsetattr(fd, termios.TCSADRAIN, old_settings) 26 | return ch 27 | 28 | char = None 29 | 30 | def keypress(): 31 | global char 32 | char = getch() 33 | 34 | _thread.start_new_thread(keypress, ()) 35 | 36 | while True: 37 | if char is not None: 38 | print ("Key pressed is " + char.decode('utf-8')) 39 | break 40 | -------------------------------------------------------------------------------- /arduino/car/keypress.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | #https://rosettacode.org/wiki/Keyboard_input/Keypress_check#Python 3 | 4 | import sys 5 | import time 6 | 7 | class KeyPress: 8 | def __init__(self): 9 | def getch(): # define non-Windows version 10 | import tty, termios 11 | fd = sys.stdin.fileno() 12 | old_settings = termios.tcgetattr(fd) 13 | try: 14 | tty.setraw(sys.stdin.fileno()) 15 | ch = sys.stdin.read(1) 16 | finally: 17 | termios.tcsetattr(fd, termios.TCSADRAIN, old_settings) 18 | return ch 19 | self._getch = getch 20 | self._char = None 21 | self._quitKey = None 22 | self._handlersMap = {} 23 | 24 | def registerHandlers(self,hMap): 25 | self._handlersMap = hMap; 26 | 27 | def registerQuitKey(self,char): 28 | self._quitKey = char 29 | 30 | def start(self): 31 | while True: 32 | self._char = self._getch() 33 | if self._char == self._quitKey: 34 | print "QUIT!" 35 | return 36 | if self._char in self._handlersMap: 37 | self._handlersMap[self._char]() 38 | -------------------------------------------------------------------------------- /arduino/car/.travis.yml: -------------------------------------------------------------------------------- 1 | # Continuous Integration (CI) is the practice, in software 2 | # engineering, of merging all developer working copies with a shared mainline 3 | # several times a day < http://docs.platformio.org/page/ci/index.html > 4 | # 5 | # Documentation: 6 | # 7 | # * Travis CI Embedded Builds with PlatformIO 8 | # < https://docs.travis-ci.com/user/integration/platformio/ > 9 | # 10 | # * PlatformIO integration with Travis CI 11 | # < http://docs.platformio.org/page/ci/travis.html > 12 | # 13 | # * User Guide for `platformio ci` command 14 | # < http://docs.platformio.org/page/userguide/cmd_ci.html > 15 | # 16 | # 17 | # Please choice one of the following templates (proposed below) and uncomment 18 | # it (remove "# " before each line) or use own configuration according to the 19 | # Travis CI documentation (see above). 20 | # 21 | 22 | 23 | # 24 | # Template #1: General project. Test it using existing `platformio.ini`. 25 | # 26 | 27 | # language: python 28 | # python: 29 | # - "2.7" 30 | # 31 | # sudo: false 32 | # cache: 33 | # directories: 34 | # - "~/.platformio" 35 | # 36 | # install: 37 | # - pip install -U platformio 38 | # 39 | # script: 40 | # - platformio run 41 | 42 | 43 | # 44 | # Template #2: The project is intended to by used as a library with examples 45 | # 46 | 47 | # language: python 48 | # python: 49 | # - "2.7" 50 | # 51 | # sudo: false 52 | # cache: 53 | # directories: 54 | # - "~/.platformio" 55 | # 56 | # env: 57 | # - PLATFORMIO_CI_SRC=path/to/test/file.c 58 | # - PLATFORMIO_CI_SRC=examples/file.ino 59 | # - PLATFORMIO_CI_SRC=path/to/test/directory 60 | # 61 | # install: 62 | # - pip install -U platformio 63 | # 64 | # script: 65 | # - platformio ci --lib="." --board=ID_1 --board=ID_2 --board=ID_N 66 | -------------------------------------------------------------------------------- /arduino/test/.travis.yml: -------------------------------------------------------------------------------- 1 | # Continuous Integration (CI) is the practice, in software 2 | # engineering, of merging all developer working copies with a shared mainline 3 | # several times a day < http://docs.platformio.org/page/ci/index.html > 4 | # 5 | # Documentation: 6 | # 7 | # * Travis CI Embedded Builds with PlatformIO 8 | # < https://docs.travis-ci.com/user/integration/platformio/ > 9 | # 10 | # * PlatformIO integration with Travis CI 11 | # < http://docs.platformio.org/page/ci/travis.html > 12 | # 13 | # * User Guide for `platformio ci` command 14 | # < http://docs.platformio.org/page/userguide/cmd_ci.html > 15 | # 16 | # 17 | # Please choice one of the following templates (proposed below) and uncomment 18 | # it (remove "# " before each line) or use own configuration according to the 19 | # Travis CI documentation (see above). 20 | # 21 | 22 | 23 | # 24 | # Template #1: General project. Test it using existing `platformio.ini`. 25 | # 26 | 27 | # language: python 28 | # python: 29 | # - "2.7" 30 | # 31 | # sudo: false 32 | # cache: 33 | # directories: 34 | # - "~/.platformio" 35 | # 36 | # install: 37 | # - pip install -U platformio 38 | # 39 | # script: 40 | # - platformio run 41 | 42 | 43 | # 44 | # Template #2: The project is intended to by used as a library with examples 45 | # 46 | 47 | # language: python 48 | # python: 49 | # - "2.7" 50 | # 51 | # sudo: false 52 | # cache: 53 | # directories: 54 | # - "~/.platformio" 55 | # 56 | # env: 57 | # - PLATFORMIO_CI_SRC=path/to/test/file.c 58 | # - PLATFORMIO_CI_SRC=examples/file.ino 59 | # - PLATFORMIO_CI_SRC=path/to/test/directory 60 | # 61 | # install: 62 | # - pip install -U platformio 63 | # 64 | # script: 65 | # - platformio ci --lib="." --board=ID_1 --board=ID_2 --board=ID_N 66 | -------------------------------------------------------------------------------- /arduino/ir_test/.travis.yml: -------------------------------------------------------------------------------- 1 | # Continuous Integration (CI) is the practice, in software 2 | # engineering, of merging all developer working copies with a shared mainline 3 | # several times a day < http://docs.platformio.org/page/ci/index.html > 4 | # 5 | # Documentation: 6 | # 7 | # * Travis CI Embedded Builds with PlatformIO 8 | # < https://docs.travis-ci.com/user/integration/platformio/ > 9 | # 10 | # * PlatformIO integration with Travis CI 11 | # < http://docs.platformio.org/page/ci/travis.html > 12 | # 13 | # * User Guide for `platformio ci` command 14 | # < http://docs.platformio.org/page/userguide/cmd_ci.html > 15 | # 16 | # 17 | # Please choice one of the following templates (proposed below) and uncomment 18 | # it (remove "# " before each line) or use own configuration according to the 19 | # Travis CI documentation (see above). 20 | # 21 | 22 | 23 | # 24 | # Template #1: General project. Test it using existing `platformio.ini`. 25 | # 26 | 27 | # language: python 28 | # python: 29 | # - "2.7" 30 | # 31 | # sudo: false 32 | # cache: 33 | # directories: 34 | # - "~/.platformio" 35 | # 36 | # install: 37 | # - pip install -U platformio 38 | # 39 | # script: 40 | # - platformio run 41 | 42 | 43 | # 44 | # Template #2: The project is intended to by used as a library with examples 45 | # 46 | 47 | # language: python 48 | # python: 49 | # - "2.7" 50 | # 51 | # sudo: false 52 | # cache: 53 | # directories: 54 | # - "~/.platformio" 55 | # 56 | # env: 57 | # - PLATFORMIO_CI_SRC=path/to/test/file.c 58 | # - PLATFORMIO_CI_SRC=examples/file.ino 59 | # - PLATFORMIO_CI_SRC=path/to/test/directory 60 | # 61 | # install: 62 | # - pip install -U platformio 63 | # 64 | # script: 65 | # - platformio ci --lib="." --board=ID_1 --board=ID_2 --board=ID_N 66 | -------------------------------------------------------------------------------- /arduino/test/success.log: -------------------------------------------------------------------------------- 1 | pi@raspberrypi:~/rpi/arduino/test $ platformio run --target upload 2 | [Sat Jan 7 21:01:55 2017] Processing uno (platform: atmelavr, upload_port: /dev/tty*, board: uno, framework: arduino) 3 | ---------------------------------------------------------------------------------------------------------------------- 4 | Verbose mode can be enabled via `-v, --verbose` option 5 | Collected 27 compatible libraries 6 | Looking for dependencies... 7 | Project does not have dependencies 8 | Linking .pioenvs/uno/firmware.elf 9 | Checking program size 10 | text data bss dec hex filename 11 | 928 0 9 937 3a9 .pioenvs/uno/firmware.elf 12 | Building .pioenvs/uno/firmware.hex 13 | Looking for upload port... 14 | Auto-detected: /dev/ttyACM0 15 | Uploading .pioenvs/uno/firmware.hex 16 | 17 | avrdude: AVR device initialized and ready to accept instructions 18 | 19 | Reading | ################################################## | 100% 0.00s 20 | 21 | avrdude: Device signature = 0x1e950f (probably m328p) 22 | avrdude: reading input file ".pioenvs/uno/firmware.hex" 23 | avrdude: writing flash (928 bytes): 24 | 25 | Writing | ################################################## | 100% 0.20s 26 | 27 | avrdude: 928 bytes of flash written 28 | avrdude: verifying flash memory against .pioenvs/uno/firmware.hex: 29 | avrdude: load data flash data from input file .pioenvs/uno/firmware.hex: 30 | avrdude: input file .pioenvs/uno/firmware.hex contains 928 bytes 31 | avrdude: reading on-chip flash data: 32 | 33 | Reading | ################################################## | 100% 0.15s 34 | 35 | avrdude: verifying ... 36 | avrdude: 928 bytes of flash verified 37 | 38 | avrdude: safemode: Fuses OK (E:00, H:00, L:00) 39 | 40 | avrdude done. Thank you. 41 | 42 | ============================================ [SUCCESS] Took 4.45 seconds ============================================ 43 | 44 | -------------------------------------------------------------------------------- /arduino/car/keypress2.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | #https://rosettacode.org/wiki/Keyboard_input/Keypress_check#Python 3 | 4 | import sys 5 | import threading 6 | import time 7 | 8 | class KeyPress: 9 | def __init__(self): 10 | def getch(): # define non-Windows version 11 | import tty, termios 12 | fd = sys.stdin.fileno() 13 | old_settings = termios.tcgetattr(fd) 14 | try: 15 | tty.setraw(sys.stdin.fileno()) 16 | ch = sys.stdin.read(1) 17 | finally: 18 | termios.tcsetattr(fd, termios.TCSADRAIN, old_settings) 19 | return ch 20 | self._getch = getch 21 | self._char = None 22 | self._quitKey = None 23 | self._defaultHandler = lambda : None 24 | self._handlersMap = {} 25 | self._isOn = True 26 | self._isMoving = False 27 | 28 | def registerHandlers(self,hMap): 29 | self._handlersMap = hMap; 30 | 31 | def registerDefaultHandler(self,handler): 32 | self._defaultHandler = handler 33 | 34 | def registerQuitKey(self,char): 35 | self._quitKey = char 36 | 37 | def run(self): 38 | # each cycle in while loop uses 0.1 sec, whithout the explicit sleep() 39 | while self._isOn: 40 | self._char=None 41 | self._char=self._getch() 42 | time.sleep(0.1) 43 | print "THRED STOPPED" 44 | 45 | # return False if quit is pressed 46 | def runHandler(self,key): 47 | if key in self._handlersMap: 48 | self._handlersMap[self._char]() 49 | self._isMoving = True 50 | return True 51 | elif self._char == self._quitKey: 52 | assert self._quitKey is not None 53 | self._isOn = False 54 | return False 55 | else: 56 | return True 57 | 58 | def start(self): 59 | self._thread = threading.Thread(target=self.run) 60 | self._thread.daemon = True 61 | self._thread.start() 62 | lastkey = None 63 | lastkeytime = time.time() 64 | while True: 65 | thistime = time.time() 66 | if self._char is not None: 67 | if not self._isMoving or self._char != lastkey: 68 | if not self.runHandler(self._char): 69 | # wait for thread to stop: 70 | time.sleep(0.5) 71 | return 72 | lastkey = self._char 73 | lastkeytime = thistime 74 | elif thistime-lastkeytime < 0.1: 75 | continue 76 | else: 77 | self._defaultHandler() 78 | self._isMoving = False 79 | 80 | -------------------------------------------------------------------------------- /arduino/car/src/main.cpp: -------------------------------------------------------------------------------- 1 | #include "Arduino.h" 2 | #include 3 | #include 4 | #include 5 | 6 | #define EN1 5//control right motor speed 7 | #define EN2 6//control left motor speed 8 | #define IN1 4//control right motor direction 9 | #define IN2 7//control left motor direction 10 | #define SERVO_PIN 10 11 | #define IR_PIN 8 12 | #define BUFFERSIZE 200U 13 | #define FORW 1//forward 14 | #define BACK 0//backward 15 | #define SPEED 255//0-255 16 | #define SERVOANGLE 5//servo angle change per key press 17 | 18 | #define KEY_REPEAT "NEC1 ditto" 19 | #define KEY_POWER "NEC1 0 69" 20 | #define KEY_MODE "NEC1 0 70" 21 | #define KEY_MUTE "NEC1 0 71" 22 | #define KEY_PLAY "NEC1 0 68" 23 | #define KEY_BACK "NEC1 0 64" 24 | #define KEY_FWD "NEC1 0 67" 25 | #define KEY_EQ "NEC1 0 7" 26 | #define KEY_MINUS "NEC1 0 21" 27 | #define KEY_PLUS "NEC1 0 9" 28 | #define KEY_ZERO "NEC1 0 22" 29 | #define KEY_SHUFFLE "NEC1 0 25" 30 | #define KEY_USD "NEC1 0 13" 31 | #define KEY_ONE "NEC1 0 12" 32 | #define KEY_TWO "NEC1 0 24" 33 | #define KEY_THREE "NEC1 0 94" 34 | #define KEY_FOUR "NEC1 0 8" 35 | #define KEY_FIVE "NEC1 0 28" 36 | #define KEY_SIX "NEC1 0 90" 37 | #define KEY_SEVEN "NEC1 0 66" 38 | #define KEY_EIGHT "NEC1 0 82" 39 | #define KEY_NINE "NEC1 0 74" 40 | 41 | Servo myservo; 42 | int angle; 43 | 44 | void MotorControl(int M1_DIR,int M1_EN,int M2_DIR,int M2_EN) 45 | { 46 | //M1 47 | if(M1_DIR==FORW)//Motor 1 direction 48 | digitalWrite(IN1,HIGH); 49 | else 50 | digitalWrite(IN1,LOW); 51 | if(M1_EN==0)//Motor 1 speed 52 | analogWrite(EN1,LOW);//stop 53 | else 54 | analogWrite(EN1,M1_EN);//analog value of speed 55 | //M2 56 | if(M2_DIR==FORW) 57 | digitalWrite(IN2,HIGH); 58 | else 59 | digitalWrite(IN2,LOW); 60 | if(M2_EN==0) 61 | analogWrite(EN2,LOW); 62 | else 63 | analogWrite(EN2,M2_EN); 64 | } 65 | 66 | IrReceiver *receiver; 67 | const char *lastKey; 68 | 69 | void setup() 70 | { 71 | pinMode(EN1, OUTPUT); 72 | pinMode(EN2, OUTPUT); 73 | pinMode(IN1, OUTPUT); 74 | pinMode(IN2, OUTPUT); 75 | myservo.attach(SERVO_PIN); 76 | receiver = IrReceiverSampler::newIrReceiverSampler 77 | (BUFFERSIZE, IR_PIN, false, 50, 500); 78 | } 79 | 80 | void loop() 81 | { 82 | receiver->receive(); 83 | if (receiver->isEmpty()) 84 | MotorControl(FORW,0,FORW,0); 85 | else { 86 | Nec1Decoder decoder(*receiver); 87 | const char * thisKey = decoder.getDecode(); 88 | if (!strcmp(thisKey,KEY_REPEAT)) 89 | thisKey = lastKey; 90 | else if (!strcmp(thisKey,KEY_BACK)) 91 | MotorControl(FORW,0,FORW,0); 92 | else if (!strcmp(thisKey,KEY_MODE)) 93 | MotorControl(FORW,SPEED,FORW,SPEED); 94 | else if (!strcmp(thisKey,KEY_MINUS)) 95 | MotorControl(BACK,SPEED,BACK,SPEED); 96 | else if (!strcmp(thisKey,KEY_PLAY)) 97 | MotorControl(BACK,SPEED,FORW,SPEED); 98 | else if (!strcmp(thisKey,KEY_FWD)) 99 | MotorControl(FORW,SPEED,BACK,SPEED); 100 | else if (!strcmp(thisKey,KEY_POWER)){ 101 | angle = myservo.read(); 102 | myservo.write(min(angle + SERVOANGLE,180)); 103 | } 104 | else if (!strcmp(thisKey,KEY_MUTE)){ 105 | angle = myservo.read(); 106 | myservo.write(max(angle - SERVOANGLE,0)); 107 | } 108 | lastKey = thisKey; 109 | } 110 | } 111 | -------------------------------------------------------------------------------- /setgame/setgameLib.py: -------------------------------------------------------------------------------- 1 | # library for setgame 2 | import cv2 3 | import numpy as np 4 | 5 | # Adjust card orientation 6 | def rectify(hIn): 7 | hIn = hIn.reshape((4,2)) 8 | hOut = np.zeros((4,2),dtype = np.float32) 9 | add = hIn.sum(1) 10 | hOut[0] = hIn[np.argmin(add)] 11 | hOut[2] = hIn[np.argmax(add)] 12 | diff = np.diff(hIn,axis = 1) 13 | hOut[1] = hIn[np.argmin(diff)] 14 | hOut[3] = hIn[np.argmax(diff)] 15 | return hOut 16 | 17 | # rotate card by 90 degree 18 | def rotate(hIn): 19 | hOut = np.zeros((4,2),dtype = np.float32) 20 | hOut[0] = hIn[1] 21 | hOut[1] = hIn[2] 22 | hOut[2] = hIn[3] 23 | hOut[3] = hIn[0] 24 | return hOut 25 | 26 | # calc lenth square between two points 27 | def lenSq(pt1,pt2): 28 | x=pt2[0]-pt1[0] 29 | y=pt2[1]-pt1[1] 30 | return x*x+y*y 31 | 32 | # cut edge on all four sides - slow 33 | def cutEdge(imgIn, pixel): 34 | (lenth,width,depth) = imgIn.shape 35 | imgOut = np.zeros((lenth-pixel*2,width-pixel*2,depth)) 36 | for i in range(lenth-pixel*2): 37 | for j in range(width-pixel*2): 38 | for k in range(depth): 39 | imgOut[i,j,k] = imgIn[i+pixel,j+pixel,k] 40 | return imgOut 41 | 42 | # Image Matching 43 | def preprocess(img): 44 | gray = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY) 45 | blur = cv2.GaussianBlur(gray,(5,5),0) 46 | thresh = cv2.adaptiveThreshold(blur,255,1,1,11,1) 47 | return thresh 48 | 49 | def imgdiff(imgGBR1,imgGBR2): 50 | diffAll = 0 51 | for i in range(3): # channel BGR 52 | img1 = cv2.GaussianBlur(imgGBR1[:,:,i],(5,5),0) 53 | img2 = cv2.GaussianBlur(imgGBR2[:,:,i],(5,5),0) 54 | diff = cv2.absdiff(img1,img2) 55 | blur = cv2.GaussianBlur(diff,(5,5),0) 56 | #flag, thresh = cv2.threshold(blur, 200, 255, cv2.THRESH_BINARY) 57 | #diffAll += np.sum(blur) 58 | diffStd = np.std(blur) 59 | diffAll += diffStd * diffStd 60 | return diffAll 61 | 62 | def find_closest_card(training,img): 63 | features = preprocess(img) 64 | return sorted(training.values(), key=lambda x:imgdiff(x,features))[0][0] 65 | 66 | # return list of images (cards) in given image file 67 | def getCards(imgfile): 68 | im = cv2.imread(imgfile) 69 | gray = cv2.cvtColor(im,cv2.COLOR_BGR2GRAY) 70 | flag, thresh = cv2.threshold(gray, 120, 255, cv2.THRESH_BINARY) 71 | im2, contours, hierarchy = \ 72 | cv2.findContours(thresh,cv2.RETR_TREE,cv2.CHAIN_APPROX_SIMPLE) 73 | contours = sorted(contours, key=cv2.contourArea, reverse=True) 74 | lastArea = cv2.contourArea(contours[0]) 75 | resCards=[] 76 | for i,card in enumerate(contours): 77 | peri = cv2.arcLength(card,True) 78 | approx = cv2.approxPolyDP(card,0.02*peri,True) 79 | if approx.shape!=(4,1,2): 80 | continue 81 | rect = rectify(approx) 82 | if lenSq(rect[1],rect[0])>peri*peri/16: 83 | rect=rotate(rect) 84 | newArea = cv2.contourArea(card) 85 | if newArea&1 | less 24 | ls *.jpg > stills.txt 25 | mencoder -nosound -ovc lavc -lavcopts vcodec=mpeg4:aspect=16/9:vbitrate=8000000 -vf scale=1920:1080 -o timelapse.avi -mf type=jpeg:fps=24 mf://@stills.txt 26 | omxplayer 2016-12-25.mp4 27 | log to b@B remember password, at client: cat .ssh/id_rsa.pub | ssh b@B 'cat >> .ssh/authorized_keys' 28 | df -h 29 | du -h 30 | 31 | arduino in command line: platformio 32 | http://blog.cudmore.io/post/2016/02/13/Programming-an-arduino-with-platformio/ 33 | compile platformio: pio run 34 | upload to arduino: pio run --target upload 35 | 36 | tight vnc: 37 | on rpi, run: tightvncserver 38 | on mac, Finder -> Go -> Connect to Server: vnc://raspberrypi.local:5901 39 | 40 | about serial port on rpi: 41 | http://www.hobbytronics.co.uk/raspberry-pi-serial-port 42 | in /etc/inittab, comment out: 43 | T0:23:respawn:/sbin/getty -L ttyAMA0 115200 vt100 44 | 45 | platformio third party lib: 46 | http://platformio.org/lib/show/937/Infrared/examples 47 | IR lib: 48 | http://platformio.org/lib/show/937/Infrared/examples 49 | lib url: https://github.com/bengtmartensson/Infrared4Arduino 50 | 51 | initialize platform: 52 | pio init -b uno 53 | compile: pio run 54 | upload: pio run --target upload 55 | 56 | Another command line tool for Arduino: 57 | http://inotool.org/quickstart 58 | ino build -cppflags="-std=c++0x" 59 | 60 | live stream 61 | https://blog.miguelgrinberg.com/post/stream-video-from-the-raspberry-pi-camera-to-web-browsers-even-on-ios-and-android 62 | manually install imagemagic: https://www.imagemagick.org/script/install-source.php 63 | 64 | # install mencoder: 65 | wget http://www.mplayerhq.hu/MPlayer/releases/mplayer-export-snapshot.tar.bz2 66 | tar xavf mplayer-export-snapshot.tar.bz2 67 | cd mplayer-export-2016-03-26/ 68 | 69 | ./configure 70 | < ... wait a long time here ...> 71 | sudo make install 72 | 73 | # install MP4Box: 74 | sudo apt-get install gpac 75 | which MP4Box 76 | 77 | #send mail 78 | sudo apt-get install ssmtp 79 | #add following to /etc/ssmtp/ssmtp.conf: 80 | root=me@gmail.com 81 | mailhub=smtp.gmail.com:587 82 | hostname=raspberrypi 83 | FromLineOverride=YES 84 | AuthUser=me@gmail.com 85 | AuthPass=mypass 86 | UseSTARTTLS=YES 87 | #add following to /etc/ssmtp/ 88 | root:me@gmail.com:mail.google.com:587 89 | #add following to /etc/rc.local: 90 | ifconfig | mail -s "raspi inconfig" zhaozhichen@gmail.com 91 | 92 | #dropbox uploader 93 | https://github.com/andreafabrizi/Dropbox-Uploader 94 | 95 | #email ifconfig on startup 96 | @reboot /bin/sleep 60; /home/pi/rpi/sendIP.sh 2>&1 97 | 98 | #youtube stream: 99 | v1, avconv (not working on rpi zero) http://www.makeuseof.com/tag/live-stream-youtube-raspberry-pi/ 100 | v2 ,ffmpeg: https://www.digikey.com/en/maker/blogs/streaming-live-to-youtube-and-facebook-using-raspberry-pi-camera/969a7932d47d42a79ba72c81da4d9b66 101 | Instructions to install ffmpeg: 102 | https://www.bitpi.co/2015/08/19/how-to-compile-ffmpeg-on-a-raspberry-pi/ 103 | or 104 | https://www.assetbank.co.uk/support/documentation/install/ffmpeg-debian-squeeze/ffmpeg-debian-jessie/ 105 | You may fail libfaac, instructions: http://raspberrypi.stackexchange.com/questions/10250/how-do-i-install-libfaac-dev-on-raspi 106 | 107 | --------------------------------------------------------------------------------