Sunday, June 23, 2019

Dual Color LED on Rasberry Pi - Lou Person - STEM - Girls Who Code

Go to page 28 of the manual http://gwc.daisyware.com/manual.pdf which will discuss what the Dual-Color LED does.
When you are done, the project will look like this:


First, since this is the first project, you will need to connect the ribbon cable to the Rasberry Pi and the T-Cobbler.  Reference the manual page 10.  See 38 Breadboard, 39 T-Cobber and 40 40-pin Ribbon Cable for T-Cobbler.  Be very careful you don't bend the pins in the T-Cobbler.  Also, be very careful of the Ribbon Cable, the ribbon is a bunch of 40 cables attached together, if you bend the ribbon, you could break one of the small cables.


Second, connect the Cobbler to the Rasberry Pi using the Ribbon, as shown below.  Make sure the first row of pins on the Cobbler lines up to the first row on the top of the Breadboard.  Don't bend the pins!



Fourth, now wire the project.  Page 29 will show how the wiring should be done. Note that the diagram shows a purple, green and black wire.  Our kit includes a 3 pin anti-reverse cable which is yellow, red and black.  So, the picture on page 29, the purple wire illustrated is the yellow wire in reality, the green wire illustrated is the red wire in reality and the black wire illustrated (grd) is the black wire in reality.  Page 29 will show how it should be wired (see below).  Note that there is an R, G and GND on the sensor.  The yellow wire will connect to GPIO17.  Take the pin of the yellow wire and insert it into the left hole in the GPI017 row.  The red wire will connect to GPIO18.  Thake the pin of the red wire and insert it into the right hole in the GPIO18 row.  The black wire will connect into the third group along the right edge, top right most hole as shown below.  Finally, connect the 4 wires as shown exactly below in the picture, also described here:
1) The top most, right most hole should have a black wire which connects to the right (second) hole in the gnd row.
2) The top most, second from right most hole, should have a red wire which connects to the right (second) hole on the 5V0 row.
3) The top most, left most hole should have a red wire which connects to the left (second) hole in the 3V3 row.
4) The top most, second from left most hole, should have a black wire which connects to the left (second) hole in the GND row.




Here is what is should look like when done (page 31) (note the gnd wire is not shown per instructions below and a white wire was used instead of a red).


Fifth, run the code and flash your light!
On the bottom of page 29 of the manual, under "For Python Users", enter the two commands.
First, enter this command and hit enter:
cd /home/pi/SunFounder_SensorKit_for_RPi2/Python/
Second, enter this command and hit enter making your LED flash
sudo python 01_dule_color_led.py

By Lou Person


Install Sensor libraries on Rasberry Pi - Lou Person - STEM - Girls Who Code


In this post, we will install the libraries (blocks of software code) that you will reference in the python code in the lessons later.  You should have received a copy of "Sensor Kit V2.0 for Rasberry Pi B+".  If you don't have it, or want to read it online, please go here: http://gwc.daisyware.com/manual.pdf We will refer to this as "the manual" from now on.

First, open a terminal on the Rasberry Pi to install the libraries.  Go to page 13 of the manual to see "How to Open a Terminal".  Stop on the bottom of Page 16, we will use Putty later.

Second, go to page 23 of the manual to "Install Libraries".  You will install Wiring Pi.  We will be using GitHub and Linux commands to install libraries.  It's easy, don't worry!
Read step 1, you will enter this command: git clone git://git.drogon.net/wiringPi
Read step 2, you will enter these commands.  Type (or copy and paste) these command one at a time, pressing enter each time, the manual will provide more details:
cd wiringPi 
git pull origin 
./build 
Read step 3 and run the tests.

Third, go to page 25 and look at Method 2.
Change directory to /home/pi by typing this command and pressing enter:
cd /home/pi/ 
Now that you are in this directory, download the code from GitHub.  Type (or copy and paste) the command below and hit enter after:
git clone https://github.com/sunfounder/SunFounder_SensorKit_for_RPi2 

Now that everything is installed, you are going to wire your first sensor and run the python program you just installed to make the LED turn different colors!






Tuesday, June 18, 2019

Setting up Rasberry Pi - Lou Person - STEM - Girls Who Code




Thanks to Girls Who Code for the grant, we were able to purchase the following Rasberry Pi 3 with Sensor kit from Stack Social: https://stacksocial.com/sales/37-sensors-starter-kit-for-raspberry-pi-pi-3b-included-2

If you want to follow these posts, you can order the same one.

As of this blog post, we are using the most current model, which is Raspberry Pi 3 Model B+

When you open the box, be careful to remove just the Rasberry Pi in the small box.  It comes with a small Micro SD Card so be careful you find it right away.

STEP 1:
Follow along here: https://projects.raspberrypi.org/en/projects/raspberry-pi-setting-up/2  This guide explains the cable you will need to connect to a monitor, a USB Keyboard and USB Mouse.  Also, a power cord is needed.  You can use a USB Cable with a square power adapter for the wall.  You will need a micro USB cable such as this one: https://www.amazon.com/dp/B0711PVX6Z/ref=cm_sw_em_r_mt_dp_U_KOycDbH61B4PQ

STEP 2:
Next, follow along here to setup the SD RAM Card (these were setup for you if you are in the club.  If you are in the club, you can skip this step): 
The tricky part here for me was the SD Card is a Micro SD format.  I had to get an adapter so I could insert it into a SD Reader on my computer.  You can also get a USB Adapter if you only have USB ports.  
Here is an adapter for USB, this is what most of you will need:

Here is the adapter I got so it would fit into the SD Reader slot on my computer: 

Continue following the instructions for downloading NOOBS, Formatting the SD Card, Extracting and Copying the files to the SD Card.  https://projects.raspberrypi.org/en/projects/raspberry-pi-setting-up/3

STEP 3:
Now that you have the files copied to the SD Card, insert it into the Rasberry Pi and install the Mouse, Keyboard, Power and Monitor:

STEP 4:


In the next lesson, we will connect the sensor board, install the libraries, install the python code and program a LED to change colors!





Saturday, June 1, 2019

Girls Who Code Weather Station - Lou Person - STEM - Python - AWS

In this lesson we are going to build a weather station.  The project will consist of a simple web form that takes as input the name of the city.  It will then pass it to a script which will take the name of the city and lookup the weather for that city.  We will use an API (Application Programming Interface) from OpenWeatherMap.org in our script to get the Weather data.  An API is a secure way to access a programming, securely, that exists somewhere else and was written by someone else.  An API is a way to pass input and get output from a program written by another person or team.

First, create an html form and save it in the html folder through FTP.  Name it formweatheryourname.html (don't forget to change yourname to what your name really is).  Also, don't forget to change the name of the script to formweatheryourname.py in the same way.

Here is the form:
<form action="/cgi-bin/formweatherlou.py" method="post">
    City: <input type="text" name="city">
    <input type="submit" value="go">
    </form>

Next, change to the cgi-bin folder.  Create the formweatheryourname.py script (change the name to your name).  Here is the code:

#!/bin/python
#import modules to use API
import requests, json
# Import modules for CGI handling
import cgi, cgitb
# Required header that tells the browser how to render the text.
print("Content-Type: text/plain\n\n")  # here text -- not html

# Python program to find current
# weather details of any city
# using openweathermap api

# import required modules
import requests, json
form = cgi.FieldStorage()
city_name = form.getvalue('city')

# Enter your API key here
api_key = "868114e4f2aef8df7211bc655077f6ee"

# base_url variable to store url
base_url = "http://api.openweathermap.org/data/2.5/weather?"

# Give city name
#city_name = input("Enter city name : ")
#city_name = "Delhi"

# complete_url variable to store
# complete url address
complete_url = base_url + "appid=" + api_key + "&q=" + city_name

# get method of requests module
# return response object
response = requests.get(complete_url)

# json method of response object
# convert json format data into
# python format data
x = response.json()

# Now x contains list of nested dictionaries
# Check the value of "cod" key is equal to
# "404", means city is found otherwise,
# city is not found
if x["cod"] != "404":

    # store the value of "main"
    # key in variable y
    y = x["main"]

    # store the value corresponding
    # to the "temp" key of y
    current_temperature = y["temp"]

    # store the value corresponding
    # to the "pressure" key of y
    current_pressure = y["pressure"]

    # store the value corresponding
    # to the "humidity" key of y
    current_humidiy = y["humidity"]

    # store the value of "weather"
    # key in variable z
    z = x["weather"]

    # store the value corresponding
    # to the "description" key at
    # the 0th index of z
    weather_description = z[0]["description"]

    # print following values
    print(" Temperature (in kelvin unit) = " +
                    str(current_temperature) +
          "\n atmospheric pressure (in hPa unit) = " +
                    str(current_pressure) +
          "\n humidity (in percentage) = " +
                    str(current_humidiy) +
          "\n description = " +
                    str(weather_description))

else:
    print(" City Not Found ")



Girls Who Code Weather Station - by Lou Person - STEM - Python - AWS

In this lesson we are going to build a weather station.  The project will consist of a simple web form that takes as input the name of the city.  It will then pass it to a script which will take the name of the city and lookup the weather for that city.  We will use an API (Application Programming Interface) from OpenWeatherMap.org in our script to get the Weather data.  An API is a secure way to access a programming, securely, that exists somewhere else and was written by someone else.  An API is a way to pass input and get output from a program written by another person or team.

First, create an html form and save it in the html folder through FTP.  Name it formweatheryourname.html (don't forget to change yourname to what your name really is).  Also, don't forget to change the name of the script to formweatheryourname.py in the same way.

Here is the form:
<form action="/cgi-bin/formweatherlou.py" method="post">
    City: <input type="text" name="city">
    </form>

Next, change to the cgi-bin folder.  Create the formweatheryourname.py script (change the name to your name).  Here is the code:

#!/bin/python
#import modules to use API
import requests, json
# Import modules for CGI handling
import cgi, cgitb
# Required header that tells the browser how to render the text.
print("Content-Type: text/plain\n\n")  # here text -- not html

# Python program to find current
# weather details of any city
# using openweathermap api

# import required modules
import requests, json
form = cgi.FieldStorage()
city_name = form.getvalue('city')

# Enter your API key here
api_key = "868114e4f2aef8df7211bc655077f6ee"

# base_url variable to store url
base_url = "http://api.openweathermap.org/data/2.5/weather?"

# Give city name
#city_name = input("Enter city name : ")
#city_name = "Delhi"

# complete_url variable to store
# complete url address
complete_url = base_url + "appid=" + api_key + "&q=" + city_name

# get method of requests module
# return response object
response = requests.get(complete_url)

# json method of response object
# convert json format data into
# python format data
x = response.json()

# Now x contains list of nested dictionaries
# Check the value of "cod" key is equal to
# "404", means city is found otherwise,
# city is not found
if x["cod"] != "404":

    # store the value of "main"
    # key in variable y
    y = x["main"]

    # store the value corresponding
    # to the "temp" key of y
    current_temperature = y["temp"]

    # store the value corresponding
    # to the "pressure" key of y
    current_pressure = y["pressure"]

    # store the value corresponding
    # to the "humidity" key of y
    current_humidiy = y["humidity"]

    # store the value of "weather"
    # key in variable z
    z = x["weather"]

    # store the value corresponding
    # to the "description" key at
    # the 0th index of z
    weather_description = z[0]["description"]

    # print following values
    print(" Temperature (in kelvin unit) = " +
                    str(current_temperature) +
          "\n atmospheric pressure (in hPa unit) = " +
                    str(current_pressure) +
          "\n humidity (in percentage) = " +
                    str(current_humidiy) +
          "\n description = " +
                    str(weather_description))

else:
    print(" City Not Found ")