Professional Documents
Culture Documents
Anemometer With Raspberry Pi
Anemometer With Raspberry Pi
The GPIO Connection is super simple, anemometer has 2 cables, one would connect to ground
and the other to Pin 3 (the GPIO02), no matter what cable where. We base ourselves we have a
Raspberry Pi with Raspbian installed and enabled GPIO (sudo Raspi-config…).
Now everyone who is interested modify it as you, If you want to spend the meters per
second to kilometers per hour and put the result in a MySQL database, add the line
around 60 Something like:
1 ...
viento_kmph = actual_windspeed_msec * 3.6 # Convertir metros por segundo a
2
kilometros hora
3 print viento_kmph
4 if vuelta == 30: # Así cada 30 segundos lo mete en BD
5 vuelta = 0
db =
6
MySQLdb.connect("DIRECCION_IP_MYSQL","USUARIO","CONTRASEÑA","BASE_DATOS")
7 cursor = db.cursor()
cursor.execute("""INSERT INTO viento (velocidad) VALUES (%s) """,(
8
viento_kmph))
9 db.commit()
10 else:
11 vuelta = vuelta + 1
12 ...
Not forgetting to add at the beginning 'import MySQLdb’ to load modules Python MySQL
(sudo apt-get install python-mysqldb if you do not have them installed). And every 30
bring us seconds on the wind speed chart our MySQL DB, is a table goofy 2 fields, one
speed and another date is automatically completed, if you need this would be the code
to create the table in this same example: