Hardware Reference
In-Depth Information
4. Let's review the Python script used to operate the weather display. We will import
the serial port, pywapi , and ime (for delay) modules for the project:
#!/usr/bin/env python
import serial
import glob
import pprint
import pywapi
from time import sleep
We will determine and establish connection to the serial port. The scan()
function identifies all the serial ports available on the Raspberry Pi:
# Establish serial port communication
def scan():
return glob.glob('/dev/ttyS*') + glob.glob('/dev/
ttyUSB*')+ glob.glob('/dev/ttyACM*')
sport_data = scan()
for name in scan():
serialport = serial.Serial(name,9600)
sleep(5)
serialport.write(bytes("A",'ascii'))
sleep(1)
response = serialport.read()
if(response==b'A'):
sport = name
serialport.close()
break
seport = serial.Serial(sport,9600,timeout=45)
5. Once the serial ports have been ideniied, we test them by sending a byte A and
await a response. When a response with the byte A is received, we idenify and save
the serial port. Ater ideniicaion, we will establish a connecion with the Arduino.
6. In this project, we are using the NOAA website to obtain the weather data. We have
to idenify the city's weather code to obtain the current locaion's weather staion
code. This could be simply obtained by entering the zip code on their website. For
example, the weather staion code for Chicago is KORD .
 
Search WWH ::




Custom Search