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 ")



Saturday, May 4, 2019

Girls Who Code For Loop by Lou Person

The for loop is code that will loop through a site of numbers or characters.  Starting with the last program you created last ( http://blog.louperson.com/2019/04/lou-person-stem-girls-who-code-select.html ), add the following code to the program and upload it to the cgi-bin directory:

for x in range(10):
    print(x)

What happens after you process the form that calls this program? 

Next, after you print x, print a <br> so each number prints on a different line.

When you are done with that, work with a partner to build an IF statement to determine if the number is even or odd and print even or odd next to the number.

Hint: You'll want to use the % operator (which is not division, it is called the modulo operator % which will return 0 if even and 1 if odd.

Why are you modulo by 2?

Here is information on operators: https://www.w3schools.com/python/python_operators.asp

Here is a hint:

if x % 2 == 0:                  
        print("even")           
if x % 2 == 1:              
        print("odd")

Also, experiment with the for loop, here is more information: https://www.w3schools.com/python/python_for_loops.asp

Saturday, April 27, 2019

Lou Person STEM Girls Who Code Select and Decide

In this lesson we will use the select input type of our form.  This let's us select a value from a picklist so the script will have the same value each time.  With the text field, the user can type whatever they want and the script will print it back.  With the select input type, the value is already entered in the html.

Name the html form formyou.html where you is your name.  After you upload it, access it here: http://gwc.daisyware.com/formyou2.html
When you create the html file, you'll notice a reference to the script in the cgi-bin directory.  Change the name of the script to formyou2.py where you is your name

Here is the form for the html directory.  You'll name this file formyou2.html

<!--change where it says form.py to formyou.py where you is your name, e.g. formlou2.py-->
<form action="/cgi-bin/formlou2.py" method="post">
    FirstName: <input type="text" name="first_name">
    LastName: <input type="text" name="last_name">
    <select name="mood">
        <option value="happy">Happy</option>
        <option value="funny">Funny</option>
        <option value="tired">Tired</option>
        <option value="hungry">Hungry</option>
      </select>
    <input type="submit" value="go">
    </form>

Here is the code for the cgi-bin directory.  You'll name the file formyou2.py, e.g. formlou2.py.  Make sure to change you in formyou.py to your name.  Notice that we have a new variable called my_mood.  This is the value that the user selected in the html form using the select input type.  You'll also notice two variables called hungry_fix and tired_fix.  They each have a suggestion for the user on what to do about their mood.  Add others, such as happy_fix and funny_fix to your script after you get the base script working.  You can also add more options in the select field in the html form.  Then notice that we have an "if" statement.  The if statement looks at the mood the user selected and then prints the suggestion based on the mood.

#!/bin/python
# Import modules for CGI handling
import cgi, cgitb
# Create instance of FieldStorage
form = cgi.FieldStorage()
# Get data from fields
hungry_fix="Go to the deli"
tired_fix="Take a nap"
first_name = form.getvalue('first_name')
last_name = form.getvalue('last_name')
my_mood = form.getvalue('mood')
print("Content-type:text/html")
print
print("")
print("")
print("")
print(" Hello %s %s" % (first_name, last_name))
print("<br>")
if my_mood=="hungry":
    print hungry_fix
if my_mood=="tired":
    print tired_fix
print("")
print("")

Friday, April 12, 2019

Girls Who Code Lou Person Process Input Form

In this lesson, we will create a form in HTML which will submit the data to a script in Python to be processed.  You will create 2 files.  The first file will be the form and it will be in html.  The second file will be a python script which will go in the cgi-bin directory.

Name the html form formyou.html where you is your name.  After you upload it, access it here: http://gwc.daisyware.com/formyou.html
When you create the html file, you'll notice a reference to the script in the cgi-bin directory.  Change the name of the script to formyou.py where you is your name

Here is the form for the the html directory.  You'll name this file formyou.html

<!--change where it says form.py to formyou.py where you is your name, e.g. formlou.py-->
<form action="/cgi-bin/form.py" method="post">
FirstName: <input type="text" name="first_name">
LastName: <input type="text" name="last_name">
<input type="submit" value="go">
</form>

Here is the code for the cgi-bin directory.  You'll name the file formyou.py, e.g. formlou.py.  Make sure to change you in formyou.py to your name.

#!/bin/python
# Import modules for CGI handling
import cgi, cgitb
# Create instance of FieldStorage
form = cgi.FieldStorage()
# Get data from fields
first_name = form.getvalue('first_name')
last_name = form.getvalue('last_name')
print("Content-type:text/html")
print
print("")
print("")
print("Hello")
print("")
print(" Hello %s %s" % (first_name, last_name))
print("<br>")
print(first_name, last_name)
print("")
print("")

Friday, March 29, 2019

Girls Who Code Dynamic HTML Lesson - Lou Person

This lesson will show you how to create a simple dynamic HTML page.  A dynamic HTML page is a web page that is generated by a program running on the server.  A static HTML page is a web page that is a flat file.

First, create your file.  give it your name and enter .py at the end, as an example lou.py
The py at the end of the file name indicates it is a python file.

Insert the following into your file, exactly as it appears.  Copy and paste everything between ##start## and ##end## but do not includes ##start## and ##end## only what's between them.

##start##
#!/bin/python

# Required header that tells the browser how to render the text.

print("Content-Type: text/html\n\n")

# Print a simple message to the display window.

print("<h1>Hello, World!</h1>\n")
##end##

Go to Filezilla.  This time, you will be uploading the file to cgi-bin not html.  When you login, click on cgi-bin.  The server is gwc.daisyware.com.  It should look like this:

Now that the file is uploaded, you can access it as follows: http://gwc.daisyware.com/lou.py 
(Change the name to your name.  Replace the name of the file with the name you used).

Next, we are going to create another file to add two variables together and display the results.
First, create another file with your name and the number 2, e.g. lou2.py
Enter the following in the file (everything between ##start## and ##end##(

##start##
#!/bin/python

# Required header that tells the browser how to render the text.
print("Content-Type: text/html\n\n")  

# Print a simple message to the display window.
print("<h1>Hello, World!<h1>\n")
var1=2
var2=3
var3=var1 + var2
print("<h1>The value is: \n")
print(var3)
print("</h1>\n")

##end##

Upload the file to the cgi-bin directory using Filezilla and access it as follows: http://gwc.daisyware.com/cgi-bin/lou2.py 
(Change the name to your name.  Replace the name of the file with the name you used).