How to Set Up Visual Studio Community 2019 for Windows 10

In this post, I’ll show you how to set up Visual Studio Community 2019 for Windows 10. This IDE will help us build C++ and Python programs. Our goal is to create a simple “Hello World” program in C++ and in Python.

Requirements

Here are the requirements:

  • Set up Visual Studio Community 2019 for Windows 10.
  • Create a simple “Hello World” program in C++ and in Python

Directions

Installation of Visual Studio Community 2019

Open a web browser.

Type “download visual studio community” into your favorite search engine.

visual-studio-community-setup-1

Click on the first result.

visual-studio-community-setup-2

Click to download Visual Studio Community.

Click the up arrow (^) and then click “Show in folder.”

visual-studio-community-setup-3

Right click on the file and click “Run as administrator.”

Click Yes.

Acknowledge the terms and conditions by clicking “Continue”.

visual-studio-community-setup-4

Wait for the Visual Studio Installer to do its thing.

visual-studio-community-setup-5

Select “Desktop Development with C++”. This is all you need to build C++ programs.

Select “Python development”. This is all you need to build Python programs.

visual-studio-community-setup-6

I also plan to develop for Raspberry Pi and do some data science, so I installed some extra workloads. This is optional if all you want to do is develop programs in C++ and Python:

  • Linux development with C++
  • Data science and analytical applications
visual-studio-community-setup-7

Choose the individual components that you want to install. It is OK to keep the default. Here is what else I selected:

  • Git for Windows
  • GitHub extension for Visual Studio
  • Class Designer (under Code Tools)
visual-studio-community-setup-8

You don’t need any of the .Net stuff.

Click “Install”. Go get a bite to eat or take a break. This will take a while.

visual-studio-community-setup-9

Once the install is complete, reboot your computer.

visual-studio-community-setup-10

Search for the program “Visual Studio 2019” on your computer, and then create a Desktop shortcut for it so that it is easier to find the next time around.

On the sign-in screen, sign in using your Microsoft account (or create one).

visual-studio-community-setup-11

Select “General”.

Creating the “Hello World!” Program in C++

Click “Create a new project”.

visual-studio-community-setup-12

Click “Empty Project” to start a new project.

visual-studio-community-setup-13

Configure your new project.

Right click on the project under the Solution Explorer. Go to Add -> New Item.

visual-studio-community-setup-14

Select C++ File (.cpp), and give the source code a name. Then click “Add”.

visual-studio-community-setup-15

Type in the code for your “Hello World!” program:

// This is a basic C++ program to display "Hello World!" 

// Header file for input output functions 
#include<iostream>  

using namespace std;

// main function: where the execution of program begins 
int main()
{
	// prints Hello World! to the console
	cout << "Hello World!";

	return 0;
}

Click the green button (Local Windows Debugger) to compile and run.

visual-studio-community-setup-16

You can also go to Build -> Build Solution. Then go to Debug -> Start Without Debugging.

That’s it! You should see the Hello World! message pop up.

visual-studio-community-setup-17

Running a Program in a Command Window

Solution Explorer (Right click the project name) -> Open Folder in File Explorer

Open the Debug folder.

visual-studio-community-setup-18

Select the hello_world.exe application.

visual-studio-community-setup-19

Hold down the Shift Key and right click to open a menu

Choose “Copy as path”.

Press Windows + R to open a command prompt window.

Type cmd.exe in the box.

visual-studio-community-setup-20

Click OK.

Right click to paste in the path.

visual-studio-community-setup-21

Press Enter to run.

visual-studio-community-setup-22

Creating the “Hello World!” Program in Python

Click “Create a new project”.

visual-studio-community-setup-23

Under “Language” select Python.

Select “Python Application”.

visual-studio-community-setup-24

Configure your new project. This time I checked “Place solution and project in the same directory”.

Click “Create”.

visual-studio-community-setup-25

Type in the code for your “Hello World!” program:

print("Hello World!")

Click the green button (“Attach”) to run.

That’s it! You should see the message pop up.

visual-studio-community-setup-26

To run via command line, go to the project folder and find the python file (hello_world.py in this case).

visual-studio-community-setup-27

Hold down the Shift Key and right click to open a menu.

Choose “Copy as path”.

Press Windows + R to open a command prompt window.

Right click to paste in the path.

visual-studio-community-setup-28

Press Enter to run. You might have to select the Python application you want to use to execute the file. You’ll only have to do this once.

The message should print to the terminal window. Congratulations! You are now ready to build C++ and Python programs!

visual-studio-community-setup-29

How to Read Input from a Push Button Switch on Raspberry Pi 3 Model B+

In this post, I’ll show you how to read input from a push button switch on Raspberry Pi 3 Model B+. This project shows you how to use the Raspberry Pi’s GPIO pins as an input (instead of an output) to receive information from the outside world.

Requirements

Here are the requirements:

  • Detect if a switch button is pressed.
  • When button is pressed, print “Button is pressed!”.
  • When button is not pressed, print “Button is not pressed!”.

You Will Need

push-button-2

The following components are used in this project. You will need:

Directions

Set up the Raspberry Pi

Set up the Raspberry Pi as explained in this video:

Wire the Push Button Switch to the Breadboard

push-button-3
push-button-4

Write the Program and Execute

Now we need to write a program in Python.

I have a folder in my Home Directory named robot. I get to this directory by opening up a terminal window in Raspberry Pi and typing:

cd robot

Now, we open up the Nano text editor to enable us to write the Python program. We name it push_button.py. Here is the terminal command:

nano push_button.py

We type in this python code:

import gpiozero  # We are using GPIO pins

button = gpiozero.Button(17) # GPIO17 connects to button 

while True:
  if button.is_pressed:
    print("Button is pressed!")
  else:
    print("Button is not pressed!")

We then press CTRL-X, then Y, then press Enter to save the program and return to the terminal.

To run the program, we type:

python3 push_button.py

When you press the push button switch, you should see a message that says “Button is pressed!”. Otherwise, you will see a message that says “Button is not pressed!”.

push-button-5
push-button-1

To stop the program, you press CTRL-C.

How to Blink an LED on Raspberry Pi 3 Model B+

In this post, I’ll show you how to blink an LED on Raspberry Pi 3 Model B+. This project shows you how to use the Raspberry Pi’s GPIO (General Purpose Input Output) pins as an output to manipulate an external device (in this case the LED).

Requirements

Here are the requirements:

  • Make an LED blink on Raspberry Pi 3 Model B+.

You Will Need

The following components are used in this project. You will need:

Directions

Set up the Raspberry Pi

Set up the Raspberry Pi as explained in this video:

Explore the Raspberry Pi (Optional)

From the Raspberry Pi desktop, click the Pi logo, and go to Preferences -> Raspberry Pi Configuration. Make sure your settings look like the image below and reboot (we’ll make use of these settings in future posts):

blink-led-11

Before we dive into the LED project, let’s have a look at the Raspberry Pi terminal.

The terminal is a way to communicate with your computer. Back in the 1980s and early 1990s when I first started using computers, the command-line interface of the terminal was the main way to send commands to your computer.

Back in those days computers did not have the processing power they have now. If you were born in the 1990s or later, you probably have only interacted with your computer via a graphical user interface. I like to use the command-line interface for robotics projects because it is more efficient, and you can tell the computer exactly what to do.

To open the terminal, click the Raspberry Pi logo in the upper left of the Raspberry Pi desktop and go to Accessories -> Terminal.

That black window you are looking at is the terminal. Typing ls will display all the files and folder in that directory. Blue items are directories. Green text shows our username (i.e “pi”).

blink-led-12

To change to a directory, you use the cd Directory Name command. For example cd Documents, gets you to the Documents directory.

Determine What Resistor to Use

Find out what the forward voltage is of your 5mm LED. Forward voltage is the minimum voltage required in order for the LED to light up. The forward voltage for my red LED is 1.8-2.2V.

Raspberry Pi is powered by 5V micro USB (2.5A). Each GPIO (General Purpose Input Output) pin supplies 3.3V (our source voltage) and can provide 16mA of current. Since 3.3V > 2.2V, we know that Raspberry Pi has enough voltage to power the LED.

Forward voltage is also the amount of voltage lost when a current runs through the LED. Consider it the “voltage drop” across the LED. To understand the basics of this concept, check out this 3D animation.

Find out what the maximum forward current of the 5mm LED is. Maximum forward current is the maximum current the LED can handle before it is at risk of getting damaged. The maximum forward current of my LED is 20mA (0.02A), which I obtained from the LED’s datasheet.

Now, we calculate the value of the resistor we need using Ohm’s Law (V = I * R):

  • Source voltage in volts = 3.3V
  • Forward voltage of LED = 1.8V
  • Maximum current of LED = 20mA = 0.02A
Resistor in ohms = ((Source voltage in volts) - (Forward voltage of LED in volts)) / (Maximum current in amps) = (Voltage leftover after the LED drops some of it) / (Maximum current)
Resistor in ohms = (3.3 - 1.8) / 0.02 = 75 ohms

So, we need at least a 75 ohm resistor. I’ll chose 330 ohms. The higher the resistor value you use, the dimmer the LED.

What is the current (represented as the capital letter ‘I’) in this case?

(3.3V - 1.8V) = I * 330
I = 4.5mA (which is well under the 20mA max current)

Now, we need to calculate how much power the resistor the LED can dissipate before it fails. We use this equation (P = VI):

Power in watts = Voltage in volts * Current in amps
Power in watts = (3.3 - 1.8) * 0.02A = 0.03 watts

Our resistor is rated at 0.25 watts, so we have more than enough cushion. We are good to go!

Wire the LED to the Breadboard

Here is the diagram to use to wire (using male to female jumper wire) the 330 ohm resistor and 5mm LED to the Raspberry Pi. That kink in one of the LEDs represents the long leg of the LED:

blink_led
blink-led-2

Blink the LED

Now we need to write a program in Python to blink the LED.

I have a folder in my Home Directory named robot. I get to this directory by opening up a terminal window in Raspberry Pi and typing:

cd robot

Now, we open up the Nano text editor to enable us to write the Python program. We name it led_blink.py. Here is the terminal command:

nano led_blink.py

We type in this python code:

import gpiozero  # The GPIO library for Raspberry Pi
import time  # Enables Python to manage timing

led = gpiozero.LED(17) # Reference GPIO17

while True:
  led.on() # Turn the LED on
  time.sleep(1)
  led.off() # Turn the LED off
  time.sleep(1)  # Pause for 1 second

We then press CTRL-X, then Y, then press Enter to save the program and return to the terminal.

To run the program, we type:

python3 led_blink.py

Your LED should be blinking. If it doesn’t blink, try connecting the red positive lead to another GPIO pin on the Raspberry Pi.

blink-led-3
blink-led-4

To stop the program, you press CTRL-C.

You can also try different color LEDs, as shown below.

blink-led-5
blink-led-6
blink-led-7
blink-led-8
blink-led-9
blink-led-10