Étape 8: Codage de votre Pi framboise
Vous devriez avoir déjà configuré votre Pi framboise, ayant accès à Internet de lui. Sinon, suivez ce guide, ou consultez ce billet de blog sur la configuration WiFi.
Lorsque vous êtes prêt, accéder à votre Pi framboise via un terminal (LxTerminal si vous accédez à votre Pi directement par l’intermédiaire de ce GUI), naviguez jusqu'à un dossier où vous souhaitez stocker ce projet et créez un nouveau fichier appelé « presence.py »
<p>$ sudo nano presence.py</p>
Maintenant, collez le code suivant :
import RPi.GPIO as GPIO ##GPIO libraryfrom ubidots import ApiClient ##Ubidots Library import time ##time library for delays GPIO.setmode(GPIO.BCM)##set up BCM as numbering system for inputs GPIO.setup(7,GPIO.IN)##Declaring GPIO7 as input for the sensortry: api=ApiClient("75617caf2933588b7fd0da531155d16035138535")##put your own apikey people= api.get_variable("53b9f8ff76254274effbbace")##put your own variable's id except: print "cant connect"##if this happens check your internet conection while(1): presence=GPIO.input(7)#)# saving the value of the sensor if(presence==0):##if presence is zero that means the other car is still there :( people.save_value({'value':presence})##sending value to ubidots time.sleep(1)##check every 5 seconds if the other car moves print "cero" if(presence): people.save_value({'value':presence})##the other car left so is empty now :) time.sleep(1) print "uno" GPIO.cleanup()##reset the status of the GPIO pins
Exécutez votre programme :
<p>$ sudo python presence.py</p>