Archives mensuelles : août 2017

image_pdfimage_print

Raspberry pi zero w + lidar lite v3

RpiLidar
3.3VRed
GNDBlack
GPIO03 (SCL)I2C SCL (Green)
GPIO02 (SDA)I2C SDA (Blue)
import smbus
import time
bus=smbus.SMBus(1)
addr=0x62
 
while True:
    bus.write_byte_data(0x62,0x00, 0x04)   
    val_high=bus.read_byte_data(0x62,0x0f)   
    val_low=bus.read_byte_data(0x62,0x10)   
    dist_cm=val_high*256+val_low
    print `dist_cm` + " cm   "
    time.sleep(1)

Maj 22/12/2018

J’ai du réinstaller le Pi 0 W et le lidar ne fonctionnait plus. Faire :

https://github.com/raspberrypi/firmware/issues/828

  1. Download the old module here.
  2. Copy this file into /boot/overlays.
  3. In /boot/config.txt add the line dtoverlay=i2c1-bcm2708 at the end.

Raspberry pi Zero W + servo

Source : http://espace-raspberry-francais.fr/Composants/Controler-Servo-Moteur-Raspberry-Francais/

import RPi.GPIO as GPIO
import time
 
GPIO.setmode(GPIO.BCM)
GPIO.setup(17, GPIO.OUT)
GPIO.setwarnings(False)
 
ajoutAngle = 5
 
print("\n+----------/ ServoMoteur  Controlleur /----------+")
print("|                                                |")
print("| Le Servo doit etre branche au pin 11 / GPIO 17 |")
print("|                                                |")
print("+------------------------------------------------+\n")
 
print("Comment controler le Servo ?")
choix = input("1. Choisir un angle\n2. Faire tourner de 0 a 180\n")
 
if choix == 2 :
 
    nbrTour = input ("Entrez le nombre d'aller-retour que fera le Servo :\n")
 
    pwm=GPIO.PWM(17,100)
    pwm.start(5)
 
    angle1 = 0
    duty1 = float(angle1)/10 + ajoutAngle
 
    angle2=180
    duty2= float(angle2)/10 + ajoutAngle
 
    i = 0
 
    while i <= nbrTour:
         pwm.ChangeDutyCycle(duty1)
         time.sleep(0.8)
         pwm.ChangeDutyCycle(duty2)
         time.sleep(0.8)
         i = i+1
    GPIO.cleanup()
 
if choix == 1 :
    angle = input("Entrez l'angle souhaite :\n")
    duree = input("Entrez la duree durant laquelle le Servo devra tenir sa position : ( en secondes )\n")
 
    pwm=GPIO.PWM(17,100)
    pwm.start(5)
 
    angleChoisi = float(angle)/10 + ajoutAngle
    pwm.ChangeDutyCycle(angleChoisi)
    time.sleep(duree)
    GPIO.cleanup()

Raspberry pi zero W + MCP3002 (ADC)

Source : http://makesensors.botbook.com/

# pot.py - potentiometer with mcp3002
# (c) BotBook.com - Karvinen, Karvinen, Valtokari
import spidev # installation help in book and botbook_mcp3002.py	# <1>
import time
 
def readPotentiometer():
	spi = spidev.SpiDev()	# <2>
	spi.open(0, 0)	# <3>
	command = [1, 128, 0]	# <4>
	reply = spi.xfer2(command)	# <5>
	#Parse reply 10 bits from 24 bit package
	data = reply[1] & 31	# <6>
	data = data << 6	# <7>
	data = data + (reply[2] >> 2)	# <8>
	spi.close()	# <9>
	return data
 
def main():
	while True:
		potentiometer = readPotentiometer()	# <10>
		print("Current potentiometer value is %i " % potentiometer)
		time.sleep(0.5)	
 
if __name__ == "__main__":
	main()

 

Raspberry pi zero W + water pump

#!/usr/bin/python
# coding=utf-8
 
import RPi.GPIO as GPIO         ## Import GPIO Library
import time                     ## Import 'time' library (for 'sleep')
import os 
import commands,sys
 
outPin = 21                     
GPIO.setmode(GPIO.BCM)        ## Use BOARD pin numbering
GPIO.setup(outPin, GPIO.OUT)    ## Set pin 21 to OUTPUT
 
GPIO.output(outPin, 1)  ## Turn off LED
time.sleep(10)
GPIO.output(outPin, 0) 
GPIO.cleanup()

Save

Raspberry pi zero W + Soil Humidity Sensor

20170801_195806

20170801_195940

RPISensor
3.3V (pin 1)Vdd
GPIO2 (pin 3)D0
GND (pin 14)GND
#!/usr/bin/python
# coding=utf-8
 
import RPi.GPIO as GPIO ## Import GPIO Library
import time ## Import 'time' library (for 'sleep')
import os
import commands,sys
 
inPin = 2 
GPIO.setmode(GPIO.BCM) ## Use BOARD pin numbering
GPIO.setup(inPin, GPIO.IN) ## Set pin 2 to OUTPUT
 
value=GPIO.input(inPin)
print value
GPIO.cleanup()

 

Save

Save

Save

Save

Save

Save

Save

Save