Makerspace Live! - Pi/Arduino Blink Transcript

Makerspace Live! - Pi/Arduino Blink

A Transcript

REFERENCES:


Transcript:
     Will: "Hello Makers!
Today on Makercraft Live we're going to make some LEDs blink!
Blinking LEDs on and off is a common introductory task when learning about microcontrollers.
We will be performing the same blinking LED example on both an Arduino nano and a Raspberry Pi 4 in order to show that although there are fundamental differences between these microcomputers they may also be used to produce similar results. We will also walk through the very basics of setting up a Raspberry Pi.
We may occasionally venture into topics which are outside of the scope of this tutorial but we will try to keep it simple.
Be sure to visit our Facebook and other social media and be sure to come in once we are again open to the public.

Here's the stuff you're going to need:

  1. A Raspberry Pi: any edition should work fine for our tasks. I have a Raspberry Pi 4 here inside this acrylic case
  2. A MicroSD card: for the Raspbery PI operating system to live on.
  3. A way to populate the SD card with data: here I have an all-in-one Card reader
  4. Raspberry PI setup: You need a monitor which can use HDMI, a Keyboard, optionally a mouse, an adequate power supply for your raspberry pi, and the an HDMI cable to connect to your monitor. Often if you buy a raspberry pi as part of a kit much of these needed accessories will come in the kit. 
  5. Arduino: Here I have an Arduino Nano but any should do fine. We will be using the USB to power our Arduino today.
  6. An LED: to make go blinky, here we have a Red one.
  7. A resistor: to reduce the current draw of the LED
  8. The means to hook everything together: Jumper cables and a breadboard for myself today. I recommend these for ease of use.


Here we have a set up which shows the very basic principles at hand for our tutorial.
We have a breadboard, an LED, a resistor, and some wires connecting things together.
This is the basic LED circuit: Wires to provide electricity and a resistor in series with the LED to regulate the power provided to the LED.
Without the resistor, the LED will quickly burn itself out.
We can light up the LED with a battery like so!
However, This is a somewhat inconvenient way of making a blinking light. Lets put a switch in line with the LED and permanently attach the Battery.
Now when we press on the Button for the switch, it controls the flow of electricity to the LED.
This is better, but not as nice as it could be.
We could get a computer to blink this LED for us! So that is what we will do next! We will use our microcontrollers to act as the switch in our circuit here, as well as be the battery.
All the Microcontrollers will be doing today is connecting and disconnecting an electrical connection, acting like a switch.
Lets go set up our computers!

The first thing we're going to do is install the Raspberry Pi operating system.
Plug your MicroSD card into your computer however you see fit.
And we will go to the raspberry Pi website which can be found at Raspberrypi.org.
We will navigate to the downloads section under the software section which is where we will find this Raspberry Pi Imager for Windows.
We will go ahead and download it and install it.
and launch it.
Today we're going to install Raspbian and select the SD card and hit Write.

Now we're going to switch on the Raspberry Pi and the first thing we will see are some test displays.
This is the first time we've powered the Pi on with this SD card.
This is a screen which is telling me its going to reset.
Its going to do its own thing for a bit here.
It will boot and reboot. And we'll just get to hang out!
How are you doing?
Hope you're doing well!
Patience is a virtue.
Alright, so here we are on the desktop. And I think I zoom in a bit here.
This is the initial set up here.
We live in the United States...
and Near Los Angeles...
we will use an American keyboard and the English language!
Here I would recommend that you change the default password but for our purposes today I will not.
This is a video option...
and here you connect to your wi-fi network...
and type in your password.
and the first thing it will do is ask you if you want to update your raspberry Pi. I am going to skip this today but I recommend that you go ahead and update everything because you might as well.
its all set up and it just wants to reset again and we'll be done!

Now that Raspbian is installed we're back on the windows computer because its much easier to record the desktop from here.
So today we're going to be using the Rapsberry Pi's GPIO to blink the LED on and off.
GPIO stands for General Purpose Input/Output which is an array of electrical connections whose state can be controlled with a computer program. 
Here we can see what some of these pins actually do. 
These red pins and yellow pins are just power pins, they cannot be controlled and just provide 5v or 3.3v.
These black pins here are the ground pins which allow you to complete circuits between these powered pins or these controllable pins.
These remaining pins are the controllable pins.
Today we will be using the Python programming language to control them.
You'll notice that these pins have numbers on them...
these are the GPIO pin numbers! 
However there are several different naming schemes which apply to these pins. There are several different numbers that can refer to the same pin. 
For example, this pin is both pin 8 and GPIO 14.
Its important to notice that you might have to tell your program which naming scheme you're using.
Lets look at which naming scheme we're using in our Python program!

Here we have our Python program.
This top bit here is a setup, which establishes the conditions in which our program will run.
This line will import the GPIO library into our program.
A library is a set of code that can be called into a program and allows you to use commands which are not native to the program allowing you to save time and effort.
This Library allows us to control the GPIO.
We will also import the sleep function from the time libary.
This allows our program to stall out and wait before performing the next task.
This next chunk sets up our GPIO.
This line is for housekeeping, it stops the program from sending us errors we don't need to see right now.
This next line tells our program which naming scheme we will be using to describe our pins. The BOARD here means we are using the BOARD naming scheme which means we will be using Pin 8 Shown here.
This next line initializes the pin to be used by our program. This line kind of ropes the pin into our program and lets us control it. 
We can see here that we are grabbing pin 8, telling it it is an output or it will be making its connection high or low voltage and it should start out low voltage or off.
This section of the program that actually kind of does stuff.
Here we have a while loop.
So, [WHILE] the statement which follows While is true, loop through the following program lines.
The statement after [WHILE] is the true statement, however and True is always true so this program will loop forever or until we stop it.
This line is GPIO.OUTPUT, and it says turn pin 8 to high. (or on)
This line says wait one second.
This line turns pin 8 to low or off.
This line says wait one second.
And its going to do this forever or until we turn the program off.
So lets go see this program on the screen of our Raspberry pi and run it to see if it will blink!

So here we have the ground pin, it will go to the negative side of the LED.
And here we have the next wire, it will go to pin 8 and then to the positive side of the LED.

Here is the same screen, so lets stare at it for a second.
We have to save the program before we can run it, so lets save it as Pitest.py as .py is the file type for python progams.
so lets save it and run it and check it out. 
Its blinking, Pretty cool.

So now that we've got the LED blinking on the Raspberry Pi, lets get it blinking on the Arduino!
Lets navigate to Arduino.cc where we will find the software we need!
Looking under the software and downloads page, we will find the Arduino IDE which is a set of software that will help us program our Arduino.
It will especially help us upload our program to the Arduino.
So lets go ahead and install this.
So now that it's installed, lets launch the program.
It just so happens that the thing that we're trying to do on the Arduino is one of their example sketches.
A sketch is Arduino talk for a program that we would upload to the Arduino for it to run.
Lets take a moment to highlight one of the key differences between Arduino and Raspberry Pi.
They both have GPIO, sort of.
But an Arduino is just a GPIO with just enough brains to sit here and run one progam (or sketch) over and over again.
Here we have the set up like before. 
And here we have a section of our program called the loop. This will loop over and over.
The Raspberry Pi is really more meant to be interactable. It will sit and wait for you. It has a mouse and keyboard and a monitor. You can interact with it and change it while its running. 
The Raspberry Pi is also like a regular desktop in that you can move files to and from it pretty easily.
The Arduino is different.
If you want to change what its doing you have to unplug it and plug it back into your computer and upload a new program into it.

So this is the example sketch, but we will have to change some things about it before we can get started.
This example blinks the onboard LED on and off, but we want it to blink an external LED like we did with the Raspberry Pi.
So lets change what we need to and then we will go over the program.

Here in the Setup section we establish the conditions we need for our program to work like we want.
This line assigns our pin number to a variable. This can be helpful if we change pins.
This line ropes our pin into our program. We're telling the program that we're using PIN6 and we're going to use it as an output.
Here we have the loop. This section will run over and over again.
Unlike with the Python program, we dont need to give conditions for this loop. We could but here its just the nature of this section of the program to loop, so we will just use it this way.
DigitalWrite here tells our pin to change its state, we're saying Pin 6 go high or turn on.
Here we DELAY for 1000 miliseconds or one second.
Here we're using DigitalWrite again to turn this pin off or turn it low.
and Here we delay again.

Lets now set up out IDE to be able to send the programs to the Arduino Board.
We need to tell the Arduino IDE what kind of Arduino Board we have.
This is pretty important.
Here under board we will select Arduino Nano. 
Lets look a little bit at these other options.
Here we have processor, sometimes you have to select a different processor.
Often times with Arduino, Where you buy the product from will have information you need to plug into the IDE to get it to work with your Arduino.
In particular on Amazon there will be a comment, review, or question that will usually have this information in it. This can be inconvenient, but it is nice that people are so helpful.
This port selection is important. Usually when you plug your Arduino in the com port that it is connected to will pop up on this list which is the easiest way to know which com port your board is connected to.

Lets give it a shot.

Oop, we got an Error. I forgot to declare what kind of variable OurPin was. Now I have told the IDE that I want it to be an interger and added semicolons to the lines to end them.

Lets hit compile....
oop!

Back again, here we've switched the processor to "Old Bootloader" and this time it uploaded just fine.

We should be good!"
Blinky-Blinky

Keep makin' it happen,
- Will

Comments

Popular posts from this blog

Montana Mask - Makerspace Live!

Matcha Sugar Cookies Transcript/Recipe