Raspberry Pi projects. Make a switch Control volume Measuring temperature Measuring light Output PWM Blink LEDs Remote- control car Installing VNC

Similar documents
J. La Favre Controlling Servos with Raspberry Pi November 27, 2017

Circuit Breaker trip detection and intimation via WiFi using Raspberry Pi.

Pibrella Fairground Ride. This lesson follows on from the Pelican Crossing lesson

可程式計數陣列 (PCA) 功能使用方法. 可程式計數陣列功能使用方法 Application Note 1 適用產品 :SM59D04G2,SM59D03G2

CamJam EduKit Robotics Worksheet Nine Obstacle Avoidance camjam.me/edukit

Moto1. 28BYJ-48 Stepper Motor. Ausgabe Copyright by Joy-IT 1

CamJam EduKit Robotics Worksheet Six Distance Sensor camjam.me/edukit

Project Kit Project Guide

Adafruit's Raspberry Pi Lesson 8. Using a Servo Motor

ZIO Python API. Tutorial. 1.1, May 2009

Dedan Kimathi University of technology. Department of Electrical and Electronic Engineering. EEE2406: Instrumentation. Lab 2

Total Hours Registration through Website or for further details please visit (Refer Upcoming Events Section)

國立交通大學 電子研究所 碩士論文 多電荷幫浦系統及可切換級數負電壓產生器之設計及生醫晶片應用

LEVEL A: SCOPE AND SEQUENCE

Adafruit 16 Channel Servo Driver with Raspberry Pi

MULTILAYER HIGH CURRENT/HIGH FREQUENCY FERRITE CHIP BEAD

Python Programming For Arduino

#5802 使用者研究 Design and Research on User Experience

Smart Solar Oven. A Senior Project. presented to the. Faculty of the Computer Engineering Department

Multimeter 3 1/2經濟款數位電錶 MT User s Manual 2nd Edition, Copyright by Prokit s Industries Co., Ltd.

行政院國家科學委員會專題研究計畫成果報告

電機驅動方案產品介紹 廣閎科技 2016 May. 25 inergy 大比特研讨会资料区 :

Quick Start Guide. TWR-SHIELD Shield Adapter Module for the Tower System TOWER SYSTEM

Low Cost PC Power/Clone PC market Replace Passive PFC with Active PFC Single Range (230Vac only) Power (70% market)

Adafruit 16-Channel PWM/Servo HAT & Bonnet for Raspberry Pi

書報討論報告 應用雙感測觸覺感測器於手術系統 之接觸力感測

Understanding the Arduino to LabVIEW Interface

Digital Small Array Microphone Module (DSAM module: FM-M KS1)

J. La Favre Using Arduino with Raspberry Pi February 7, 2018

For this exercise, you will need a partner, an Arduino kit (in the plastic tub), and a laptop with the Arduino programming environment.

Musical Genre Classification

EE-110 Introduction to Engineering & Laboratory Experience Saeid Rahimi, Ph.D. Labs Introduction to Arduino

LEDs and Sensors Part 2: Analog to Digital

Lecture 4: Basic Electronics. Lecture 4 Brief Introduction to Electronics and the Arduino

ESE 350 Microcontroller Laboratory Lab 5: Sensor-Actuator Lab

Arduino An Introduction

Motor Driver HAT User Manual

RN-21. Class 1 Bluetooth Module. Applications. Features. Description. Block Diagram. DS-RN21-V2 3/25/2010

Web-Enabled Speaker and Equalizer Final Project Report December 9, 2016 E155 Josh Lam and Tommy Berrueta

國立交通大學 資訊科學與工程研究所碩士論文 多天線傳送系統干擾抑制及路徑衰減補償之可適性封包檢測. Adaptive Packet Acquisition with Interference and Time-Variant Path Loss in MIMO-OFDM Systems


Unit 6: Movies. Film Genre ( 可加 film 或 movie) Adjectives. Vocabulary. animation. action. drama. comedy. crime. romance. horror

Hardware Platforms and Sensors

Adafruit 16-Channel PWM/Servo HAT for Raspberry Pi

Adafruit 16-Channel Servo Driver with Arduino

Training Schedule. Robotic System Design using Arduino Platform

PWM CONTROL USING ARDUINO. Learn to Control DC Motor Speed and LED Brightness

凱思隆科技股份有限公司 公司與產品簡介. KeithLink Technology Co., Ltd. TEL: FAX:

Power Challenges for IoT devices

HAW-Arduino. Sensors and Arduino F. Schubert HAW - Arduino 1

9/Working with Webcams

SPECIFICATION FOR APPROVAL

ORDER FORM 3A - Booth Packages Rental 訂購表格 3A - 攤位裝修設計租用

Electronics Design Laboratory Lecture #10. ECEN 2270 Electronics Design Laboratory

Digital Guitar Effects Box

NT-8540 / NT-8560 / NT-8580 Laser Distance Measurer

Rev. No. History Issue Date Remark 0.1 Initial issue Mar 24, 2008 Preliminary

Fading a RGB LED on BeagleBone Black

DASL 120 Introduction to Microcontrollers

Module: Arduino as Signal Generator

Make: Sensors. Tero Karvinen, Kimmo Karvinen, and Ville Valtokari. (Hi MAKER MEDIA SEBASTOPOL. CA

SECTION 機械標示 MECHANICAL IDENTIFICATION

INA169 Breakout Board Hookup Guide

課程名稱 : 電子學 (2) 授課教師 : 楊武智 期 :96 學年度第 2 學期

BA 商品多樣化 商品多樣性的介紹 可以和感應器和指示燈等各種元件連接的端子台模組 有 點型 ( 輸入 ) 點型 ( 輸入 輸出 ) 0 點型 ( 輸入 輸出 ) 等種類 可以不經由繼電器轉接而可以和空氣閥和電磁閥等直接連接的 00mA 開關型式 配備可簡單進行動作確認的 LED 指示燈 DIN 軌

Signal Integrity for PCB Design

Assembly Manual for VFO Board 2 August 2018

Lesson 3: Arduino. Goals

BASIC Stamp I Application Notes

DESIGN OF AN UNMANNED GROUND VEHICLE CAPABLE OF AUTONOMOUS NAVIGATION

MABEL, PiTone and Allstar for the Yaesu Fusion DR-1X Repeater

Using the VM1010 Wake-on-Sound Microphone and ZeroPower Listening TM Technology

Multi-Sensor Integration and Fusion using PSoC

Internet of Things Student STEM Project Jackson High School. Lesson 3: Arduino Solar Tracker

1. Introduction to Analog I/O

BYOE: Affordable and Portable Laboratory Kit for Controls Courses

INTRODUCTION to MICRO-CONTROLLERS

Virtual Reality 虛擬實境

Part (A) Using the Potentiometer and the ADC* Part (B) LEDs and Stepper Motors with Interrupts* Part (D) Breadboard PIC Running a Stepper Motor

3-Channel Constant Current LED Driver UCS1903

ME 333 Assignment 7 and 8 PI Control of LED/Phototransistor Pair. Overview

EEE3410 Microcontroller Applications Department of Electrical Engineering. Lecture 10. Analogue Interfacing. Vocational Training Council, Hong Kong.

Attribution Thank you to Arduino and SparkFun for open source access to reference materials.

Mechatronics Engineering and Automation Faculty of Engineering, Ain Shams University MCT-151, Spring 2015 Lab-4: Electric Actuators

Megamark Arduino Library Documentation

BCT channel 256 level brightness LED Drivers

D80 を使用したオペレーション GSL システム周波数特性 アンプコントローラー設定. Arc 及びLine 設定ラインアレイスピーカーを2 から7 までの傾斜角度に湾曲したアレイセクションで使用する場合 Arcモードを用います Lineモード

Adafruit 16-Channel Servo Driver with Arduino

Monitoring Temperature using LM35 and Arduino UNO

Welcome Show how to create disco lighting and control multi-coloured NeoPixels using a Raspberry Pi.

BLE 4.0 Module ZBModule User Manual 1 / 15

RF4432 wireless transceiver module

ARDUINO / GENUINO. start as professional

Computational Crafting with Arduino. Christopher Michaud Marist School ECEP Programs, Georgia Tech

Gravity: 12-Bit I2C DAC Module SKU: DFR0552

PART 1: DESCRIPTION OF THE DIGITAL CONTROL SYSTEM

Large Signal Behavior of Micro-speakers. by Wolfgang Klippel, KLIPPEL GmbH ISEAT 2013

Objective of the lesson

Micropython on ESP8266 Workshop Documentation

CSR Bluetooth Modules SBC05-AT. Specification. Version July-11

Transcription:

Raspberry Pi projects Make a switch Control volume Measuring temperature Measuring light Output PWM Blink LEDs Remote- control car Installing VNC

Raspberry Pi 的 GPIO 只能接收及送出數位的訊號, 類比訊號就要做轉換成數位訊號才能輸入 其中一個選擇是 Arduino, 這是一個應用很廣的數位板 ( 大致能做的事如下表所示 ), 有很多的使用者 類似的還有 Gertboard 及 piface, 而這兩個都是為 Raspberry Pi 設計的產品

TesLng gpio pins: $gpio mode 0 out $gpio write 0 1

More usages of Raspberry Pi Adopted from Using adafruit MCP+Gpio to control volume hsp://www.adafruit.com/ hsps://projects.drogon.net/raspberry- pi/ www.raspberrypi.org

Transistor 9014 as a switch E B C 0V Din +V GND

Using MCP3008 to control volume Parts: tripotenlal meter, mcp3008, speaker

Review of gpio pins:

MCP3008 : analog to digital converter Analog input 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 MCP3008 pins 9~16 are : VDD VREF AGND CLK DOUT DIN CS/SHDN DGND GPIO pins 3.3V 3.3V GND #18 #23 #24 #25 GND A D

Ciruit layout

Python script for the volume control The script is fairly simple. Half of the code (the readadc funclon) is a funclon that will 'talk' to the MCP3008 chip using four digital pins to 'bit bang' the SPI interface (this is because not all Raspberry Pi's have the hardware SPI funclon) The MCP3008 is a 10- bit ADC. That means it will read a value from 0 to 1023 (2^^10 = 1024 values) where 0 is the same and 'ground' and '1023' is the same as '3.3 volts'. We don't convert the number to voltage although its easy to do that by mullplying the number by (3.3 / 1023).

We check to see if the pot was turned more than 5 counts - this keeps us from being too 'jisery' and resehng the volume too oien. The raw analog count number is then converted into a volume percentage of 0%- 100%. When the trimpot is turned up or down it will print the volume level to STDOUT and adjust the audio level of the playing file by telling the mixer to adjust the volume.

#!/usr/bin/env python import Lme import os import RPi.GPIO as GPIO GPIO.setmode(GPIO.BCM) DEBUG = 1 # read SPI data from MCP3008 chip, 8 possible adc's (0 thru 7) def readadc(adcnum, clockpin, mosipin, misopin, cspin): if ((adcnum > 7) or (adcnum < 0)): return - 1 GPIO.output(cspin, True)

commandout = adcnum commandout = 0x18 # start bit + single- ended bit commandout <<= 3 # we only need to send 5 bits here for i in range(5): if (commandout & 0x80): GPIO.output(mosipin, True) else: GPIO.output(mosipin, False) commandout <<= 1 GPIO.output(clockpin, True) GPIO.output(clockpin, False) adcout = 0 # read in one empty bit, one null bit and 10 ADC bits for i in range(12): GPIO.output(clockpin, True) GPIO.output(clockpin, False) adcout <<= 1 if (GPIO.input(misopin)): adcout = 0x1

GPIO.output(cspin, True) adcout >>= 1 # first bit is 'null' so drop it return adcout # change these as desired - they're the pins connected from the # SPI port on the ADC to the Cobbler SPICLK = 18 SPIMISO = 23 SPIMOSI = 24 SPICS = 25 # set up the SPI interface pins GPIO.setup(SPIMOSI, GPIO.OUT) GPIO.setup(SPIMISO, GPIO.IN) GPIO.setup(SPICLK, GPIO.OUT) GPIO.setup(SPICS, GPIO.OUT) # 10k trim pot connected to adc #0 potenlometer_adc = 0;

ast_read = 0 # this keeps track of the last potenoometer value tolerance = 5 # to keep from being jiqery we'll only change # volume when the pot has moved more than 5 'counts' while True: # we'll assume that the pot didn't move trim_pot_changed = False # read the analog pin trim_pot = readadc(potenlometer_adc, SPICLK, SPIMOSI, SPIMISO, SPICS) # how much has it changed since the last read? pot_adjust = abs(trim_pot - last_read) if DEBUG: print "trim_pot:", trim_pot print "pot_adjust:", pot_adjust print "last_read", last_read if ( pot_adjust > tolerance ): trim_pot_changed = True

if ( pot_adjust > tolerance ): trim_pot_changed = True if DEBUG: print "trim_pot_changed", trim_pot_changed if ( trim_pot_changed ): set_volume = trim_pot / 10.24 # convert 10bit adc0 (0-1024) trim pot read into 0-100 volume level set_volume = round(set_volume) # round out decimal value set_volume = int(set_volume) # cast volume as integer print 'Volume = {volume}%'.format(volume = set_volume) set_vol_cmd = 'sudo amixer cset numid=1 - - {volume}% > /dev/null'.format(volume = set_volume) os.system(set_vol_cmd) # set volume if DEBUG: print "set_volume", set_volume print "tri_pot_changed", set_volume # save the potenoometer reading for the next loop last_read = trim_pot # hang out and do nothing for a half second Lme.sleep(0.5)

Analogue Sensors On The Raspberry Parts: Raspberry Pi MCP3008 8 channel ADC Light dependent resistor (LDR) TMP36 temperature sensor 10 Kohm resistor source from: Pi Using An MCP3008 hsp://www.raspberrypi- spy.co.uk/2013/10/analogue- sensors- on- the- raspberry- pi- using- an- mcp3008/

a photo of test circuit on a small piece of breadboard :

Python Scripts Codes Part- 1, read raw data from mcp3008 #!/usr/bin/python import spidev import Lme import os # Open SPI bus spi = spidev.spidev() spi.open(0,0) # FuncLon to read SPI data from MCP3008 chip # Channel must be an integer 0-7 def ReadChannel(channel): adc = spi.xfer2([1,(8+channel)<<4,0]) data = ((adc[1]&3) << 8) + adc[2] return data

Codes part- 2, convert data from mcp3008 to voltages # FuncLon to convert data to voltage level, # rounded to specified number of decimal places. def ConvertVolts(data,places): volts = (data * 3.3) / 1023 volts = round(volts,places) return volts

Code part- 3 coverts voltages to temperatures # FuncLon to calculate temperature from # TMP36 data, rounded to specified # number of decimal places. def ConvertTemp(data,places): # ADC Value # (approx) Temp Volts # 0-50 0.00 # 78-25 0.25 # 155 0 0.50 # 233 25 0.75 # 310 50 1.00 # 465 100 1.50 # 775 200 2.50 # 1023 280 3.30 temp = ((data * 330)/1023)- 50 temp = round(temp,places) return temp

CollecLng, calculalng and print- out # Define sensor channels light_channel = 0 temp_channel = 1 # Define delay between readings delay = 5 while True: # Read the light sensor data light_level = ReadChannel(light_channel) light_volts = ConvertVolts(light_level,2) # Read the temperature sensor data temp_level = ReadChannel(temp_channel) temp_volts = ConvertVolts(temp_level,2) temp = ConvertTemp(temp_level,2) # Print out results print "- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - " print("light: {} ({}V)".format(light_level,light_volts)) print("temp : {} ({}V) {} deg C".format(temp_level,temp_volts,temp)) # Wait before repealng loop Lme.sleep(delay)

Using PWM in RPi.GPIO To create a PWM instance: p = GPIO.PWM(channel, frequency) To start PWM: p.start(dc) # where dc is the duty cycle (0.0 <= dc <= 100.0) To change the frequency: p.changefrequency(freq) # where freq is the new frequency in Hz To change the duty cycle: p.changedutycycle(dc) # where 0.0 <= dc <= 100.0 To stop PWM: p.stop() Note that PWM will also stop if the instance variable 'p goes out of scope

An example to blink an LED once every two seconds import RPi.GPIO as GPIO GPIO.setmode(GPIO.BOARD) GPIO.setup(12, GPIO.OUT) p = GPIO.PWM(12, 0.5) p.start(1) input('press return to stop:') # use raw_input for Python 2 p.stop() GPIO.cleanup()

An example to brighten/dim an LED: import Lme import RPi.GPIO as GPIO GPIO.setmode(GPIO.BOARD) GPIO.setup(12, GPIO.OUT) p = GPIO.PWM(12, 50) # channel=12 frequency=50hz p.start(0) try: while 1: for dc in range(0, 101, 5): p.changedutycycle(dc) Lme.sleep(0.1) for dc in range(100, - 1, - 5): p.changedutycycle(dc) Lme.sleep(0.1) except KeyboardInterrupt: pass p.stop() GPIO.cleanup()

Remote- control car Parts: 2 server motor, Raspberry pi with Adafruit assembled cobbler breakout and cables, basery for motors,

Python program import RPi.GPIO as GPIO #from Lme import sleep #from raspirobotboard import * import pygame import sys from pygame.locals import * pygame.init() screen = pygame.display.set_mode((160,120)) pygame.display.set_caplon('rp') pygame.mouse.set_visible(0) GPIO.setmode(GPIO.BCM) GPIO.setup(25,GPIO.OUT) GPIO.setup(24,GPIO.OUT) p1 = GPIO.PWM(25,50) p2 = GPIO.PWM(24,50)

while True: for event in pygame.event.get(): if pygame.key.get_pressed()[k_up]: print('u') p1.start(1) p2.start(10) if pygame.key.get_pressed()[k_down]: print('d') p1.start(10) p2.start(1) if pygame.key.get_pressed()[k_right]: print('r') p1.start(6) p2.start(7.4) if pygame.key.get_pressed()[k_left]: print('l') p1.start(8) p2.start(7.4) if pygame.key.get_pressed()[k_s]: print('s') p1.start(7.1) p2.start(7.4) if pygame.key.get_pressed()[k_q]: print('q') p1.stop() p2.stop() GPIO.cleanup()

Server motor with power and signal conneclons D

Installing VNC on raspberry pi hsp://learn.adafruit.com/adafruit- raspberry- pi- lesson- 7- remote- control- with- vnc/ installing- vnc