0% found this document useful (0 votes)
34 views36 pages

Raspberry Pi Project Tutorials Guide

The document provides a series of tutorials for creating electronic projects using Raspberry Pi and Visual Designer. It covers three main projects: flashing an LED, designing a nightlight with Grove sensors, and controlling motors with a DC and Stepper motor hat. Each tutorial includes steps for project setup, programming, and testing, emphasizing the use of flowcharts and peripheral integration.

Uploaded by

shokax
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
34 views36 pages

Raspberry Pi Project Tutorials Guide

The document provides a series of tutorials for creating electronic projects using Raspberry Pi and Visual Designer. It covers three main projects: flashing an LED, designing a nightlight with Grove sensors, and controlling motors with a DC and Stepper motor hat. Each tutorial includes steps for project setup, programming, and testing, emphasizing the use of flowcharts and peripheral integration.

Uploaded by

shokax
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

RASPBERRY PI TUTORIALS

Introduction
It's remarkably simple to design and create electronic projects with Visual Designer. These short
tutorials each cover a separate project and include various different techniques and methods in
the project design.
Raspberry Pi Tutorials
Tutorial 1 : Flashing an LED (raw Pi).
Covers project creation, adding peripherals. basic flowchart programming and Proteus
simulation.

Tutorial 2 : Nightlight (w/ Grove).


Includes grove module configuration, decision making flowcharts, interactive simulation and
basic debugging.

Tutorial 3 : Motor Control (w/ rPi Hat)


Includes programming with loops, adding and calling sub-routines and using the clipboard..

1
LABCENTER ELECTRONICS LTD.

Tutorial 1 : Flashing LED

Introduction
This tutorial covers the basics of project creation, working with flowcharts, raspberry Pi
simulation and programming the real hardware. The actual goal of flashing the LED is kept as
simple as possible so that we can cover the end-to-end process. Working with more complex
peripherals and hats is covered in subsequent tutorials.
New Project Wizard
Visual Designer is integrated into the Proteus Design Suite and so we start our Visual Designer
Projects from the Proteus Home Screen. The easiest and best way to create a Visual Designer
Project is, unsurprisingly, through the New Flowchart Wizard.

The first page allows you to select the name and destination of your project.

2
Raspberry Pi Tutorials

Next up is the firmware screen and it is here that we really define our Visual Designer project.
First, we change the radio buttons at the top to the option for Flowchart Project and then we
select the Raspberry Pi family and either the RPi3 or the RPi3 + GrovePi Hat from the controller
combo box.

Finally, you will be presented with a summary page of your configuration.

3
LABCENTER ELECTRONICS LTD.

After you exit the dialogue form the project will be created and you will see both a skeleton
schematic with the Raspberry Pi processor placed and a skeleton chart project with the familiar
Setup and Loop routines on the Editing Window.

4
Raspberry Pi Tutorials

Now we are ready to start designing our project.


Adding a Peripheral
The first thing to do is to add the peripheral(s) for the project. These can be Raspberry Pi Hats
or just little breakout peripherals. The Raspberry Pi does not need a Hat to operate and you can
add peripherals which talk to the GPIO Pins Directly.

We'll be adding a Breakout LED. In Visual Designer, we right click on the Project Tree and
select the Add Peripheral command. Next, switch to Breakout Peripherals and select one of the
LED's.

5
LABCENTER ELECTRONICS LTD.

Add the Peripheral from the context menu command in VSM Studio

Double click on the LED to add it to the project.


Repeat the process to add a Breakout button. If you then switch to the schematic tab you will
see that the 'virtual hardware' has been autoplaced for you.

Schematic view with both LED and push button auto-placed.

6
Raspberry Pi Tutorials

To avoid clutter on the schematic, connections are made on the schematic by giving terminals
the same name. Any terminals with the same name can be thought of having an invisible wire
between them.

Terminals with the same name are considered connected together.


In real hardware, this equates to connecting the Breakout button and Breakout LED to the GPIO
Pins on the Raspberry Pi

Note that you must attach the peripherals onto the same GPIO pins on the Raspberry Pi as they
are designated on the Proteus schematic. You may need the pinout to see which GPIO pins go
where.

7
LABCENTER ELECTRONICS LTD.

GPIO pins on the Raspberry Pi


You must also ensure that you don't have two peripherals with the same terminal label on the
schematic; if you do, you need to switch to the schematic and edit the terminal labels on one of
the peripherals. Some pins may need unlocking.

If you have two terminals with the same name they will be connected ! Need to edit one and re-
assign to another GPIO line.
Flowchart Design
Back in Visual Designer, you'll notice that the Project Tree now has two entries under the
peripherals section.

8
Raspberry Pi Tutorials

The beauty of Visual Designer is that you can expand the peripherals to find a list of methods.
These methods are the primary way in which we interact with the hardware. For example, drag
and drop the 'On' method of the LED into the loop routine

Drag and Drop methods onto the program.


To test this simply press the play button. The program will compile, the simulator will start and
the LED will turn on. You can see this either via the Active popup at the right of Visual Designer
or by switching to the schematic tab.

9
LABCENTER ELECTRONICS LTD.

Run the simulation to test results.


Press stop to exit the simulation and we'll extend our program to switch the LED on and off with
a button press. You'll notice that the button has no methods in the project tree

Stop the simulation when finished.


The only sensible information we need from the button is to know whether it has been pressed
and for that we have what we call a 'sensor function'. A sensor function returns either TRUE or
FALSE depending on whether the basic peripheral function is true or not. For example, the
sensor function for a button will return TRUE when the button is pressed and FALSE if it isn't.

Similarly, the sensor function for an LED will return TRUE when the LED is on and FALSE when
the LED is off. Place the sensor function for the button by dragging and dropping from the
button itself onto the loop function of the flowchart

10
Raspberry Pi Tutorials

Drag the sensor function onto the flowchart


You will notice that it appears as a decision block. Sensor functions always return TRUE or
FALSE and a decision block allows us to split our code into two conditional paths. Your loop
routine should currently look something like the following.

We are constantly testing the button to see if it is pressed and we are turning on the LED if it is.
However, we still need to tell the program what to do if the button is not pressed. We want the
LED to turn off so lets drag and drop that method into space alongside the ON operation.

Now, we need to wire from the decision block to the top of the OFF command. To place a
flowline click on an output node (the decision block), move the mouse to an available input node
(top of the OFF routine) and click the mouse again.

11
LABCENTER ELECTRONICS LTD.

Similarly we need to connect the flow from the bottom of the OFF command back into the main
loop.

Your program should now look like the following.

Having made this change, our program now turns the LED off when the button is down and on
when the button is released. To compile and test, first press the play button and then use the
mouse to press the button down..
12
Raspberry Pi Tutorials

Programming the Hardware


This section assumes that you have completed the initial configuration of the Raspberry
Pi.

13
LABCENTER ELECTRONICS LTD.

Here on the Left is a Raspberry Pi 3, and on the Right is the pinout for the GPIO Pins. The very
first thing you need to understand is the orientation. Both these images are oriented in the same
way. The top 2 pins are both power (Left pin is 3.3V and Right pin is 5V). You can find this
pinout on the raspberry pi website. Some of the Raspberry Pi I cases have the pinout engraved
into it making it very easy to find each pin. Failing that, you can use a template or make one
with a little bit of card to make life easier.

14
Raspberry Pi Tutorials

Engraved casing or simple template to identify lines on the header block.


15
LABCENTER ELECTRONICS LTD.

Now in our program we connected the LED to GPIO 10. Not to be confused with Pin 10 which is
GPIO 15. GPIO and Pin numbers are very different so make sure you connect the correct one.
Just like the schematic we've included a protection resistor to prevent he LED from getting
damaged by the current from the Raspberry Pi.

Here you can see we've used Male to Female wires connecting the Raspberry Pi to the
Breadboard.

Assuming all is correct your led should flash just like the project.

16
Raspberry Pi Tutorials

Tutorial 2 : Night Light (w/ Grove)

Introduction
In this tutorial we are going to use a couple of Grove sensors and an LED to design a mini
nightlight. Project setup is covered in the first tutorial however this time we will want to change
the controller to the RPI3 + GrovePi Hat.

Adding Hardware
We'll use the Grove infra-red proximity sensor and the Grove luminance sensor along with a
Grove LED. All of these can be picked via the Add Peripheral command on the Project Menu.

17
LABCENTER ELECTRONICS LTD.

After they have been added to the project, you will see the methods for controlling the
peripherals in the Project Tree and the 'virtual hardware' for the peripherals placed for you on
the schematic.

It is vitally important to configure the Grove connectors properly and this is often not as simple
as it first appears. Let's take an example:

The real proximity sensor requires only three wires with the fourth left NC. Note therefore that,
when plugged into socket A0 the sensor is connecting to analogue pin A1.

This is fine, except if you then plug the luminance sensor into socket A1. The luminance sensor
will use analogue pin A1 on socket A1 and therefore clash. You should plug this sensor into
socket A2.
Golden Rule
Look closely at the Grove board to see the connections and double check against the sensors
for conflicts. Unlike the Arduino the conflicts are not shown on the board and need to be
checked separately.

18
Raspberry Pi Tutorials

The sockets include connections through to two Raspberry Pi IO pins and there is a pin overlap.
For example:
Socket A0 can use pins A0 and A1
Socket A1 can use pins A1 and A2
Socket A2 can use pins A2 and A3.
etc
Digital sockets are exactly the same.

Grove Peripherals connected.


Our configuration for this project is therefore proximity sensor in socket A0 and luminance
sensor in socket A2. The LED can be in any digital socket we like.

19
LABCENTER ELECTRONICS LTD.

Designing the Program


In our Nightlight mock up we are looking for our LED to light when the following are true:
It's is dark.
Someone is nearby.
These are both decisions on the flowchart. Start by drag and drop the readLuminance() method
onto the loop routine of the chart.

This sensor returns a lux value between 0 and 1000, with 0 being pitch black and 1000 max
light. Let's then use our result in a decision block and set our initial test value to around 100.

The datasheet for the APDS-9002 photo sensor used in this Grove module provides data
on lux values.

See Also: [Link]

For the proximity sensor, we want to read a distance so drag and drop into the top of the loop.

20
Raspberry Pi Tutorials

Set the Variable that it's reading to be LUX

The proximity sensor can detect up to 80cm but we'll set our initial test to 20cm. Add another
Decision block above the LUX Decision block, and set to be cm<20:

See Also: [Link]

Since, we need both conditions to be true for the LED to turn on, make sure that the second
decision is on the YES branch of the first decision.

21
LABCENTER ELECTRONICS LTD.

Next, drag and drop the led on method at the bottom of the YES branch.

Finally, place the LED off method to the right of the main loop beside the LED on method.

Since we want the LED to turn off if either condition is false we can wire both NO branches from
the decisions to this method.

Finally, connect the bottom of the NO program branch back into the main program loop. Your
final program should look like the following:

22
Raspberry Pi Tutorials

Simulation and Testing


To test our program, all we need to do is press the play button and then adjust the distance
display on the proximity sensor and the lux display on the luminance sensor.

The LED should turn on when the distance value is less than 20 and it's a little cloudy.

23
LABCENTER ELECTRONICS LTD.

Pause the simulation and set a breakpoint on the LED off method.

Press play again to run the simulation and change either the distance or the light until the
breakpoint triggers

24
Raspberry Pi Tutorials

You'll notice that both our variables are available in the variables display.

Comparing these values to the tested decisions will tell us which condition has failed.

As you single step via the icons at the top you'll notice the LED turn off.

25
LABCENTER ELECTRONICS LTD.

Programming
Before programming the Raspberry Pi you need to first perform the one time. See
Programming the Raspberry Pi

Since everything seems to working in good order, the remaining task is to plug in the Raspberry
Pi and program the real hardware. The process here is:

1) Plug the Grove sensors into the Grove baseboard in the same connectors as on the
schematic. See also the golden rule discussed earlier.

2) Connect the Grove hat to the Raspberry Pi and connect the Raspberry Pi to the same
WIFI as the computer. Now within Proteus within the project options change the
Programmer from NONE to RPISSH and the raspberry pi should appear.

3) Click the program upload button in Visual Designer.

4) The program will now run on the Hardware.

26
Raspberry Pi Tutorials

Tutorial 3 : Motor Control

Introduction
This tutorial shows how you can easily control both DC motors and Stepper motors with Visual
Designer. We'll do this using the Adafruit DC and Stepper motor hat for Raspberry Pi.

Setup
Start by creating a new Visual Designer Project and then Add the Raspberry Pi Hat with DC and
Stepper Motors from the peripheral menu.

Picking the Adafruit Hat from the Add Peripherals command in Visual Designer
Unlike the Arduino Hat the Raspberry Pi Hat lets you connect the motors yourself. This means
you need to first find the motors via the schematic pick devices form (MOTOR-DC & MOTOR-
BISTEPPER) and double click to insert them into the project.

27
LABCENTER ELECTRONICS LTD.

Using the Pick Devices Dialogue on the Schematic to add the motors to your design.
Then connect the part to the hat using the terminals. The usual rules apply in that terminals with
the same name are deemed connected together

Here you can see we have connected one stepper motor and two DC motors with connections
made by terminals.
Programming
For this project we will have 2 buttons, one will start a dc motor and the other will stop that
motor. After we have this project working we will then simulate it and work with the debugging
tools.

Firstly, you will need 3 components, 2 buttons and a motor. Add the two buttons using the add
peripheral method.
28
Raspberry Pi Tutorials

Add Button Peripheral.


Make sure you change the GPIO pins so that they are not both using the same pin

Make sure the buttons are assigned to unique GPIO Lines

You should already have at least one DC motor. If not then make pick one from the libraries and
make sure it is connected to motor 1 (M11,M12) of the hat. It should look something like this:

29
LABCENTER ELECTRONICS LTD.

Correctly connected DC Motor on Motor 1 of the Hat.

Note that if you want the motor to appear in Visual Designer during simulation you will
need to draw an Active Popup box around the motor.

Now you can drag the code blocks on. We want to change the speed of motor 1 each time a
button is pressed. Button 1 will start the motor and button 2 will stop the motor. You won’t need
any code in setup. Your finished program should look like the following

Motor Control flowchart. Uses the sensor functions for the buttons to make decisions.

30
Raspberry Pi Tutorials

Testing and Debugging


Now that the project is ready to go we can test it out in simulation. The remainder of this tutorial
is essentially a detailed look at simulation and stepping commands to make sure that you
understand how to control a running simulation and how you might debug problems with your
code.

The simulation is controlled from the animation control panel at the bottom left of the Proteus
application.

Here you will find the play, step, pause and stop buttons. The play button will start the project or
continue if the project is paused.

The step button will allow you to slowly step through the project pausing after every block of
code.

The pause button will pause time allowing you to look at variables, voltages and other elements.

The pause button will not stop the project and you can restart it with the play button.

The stop button will stop the whole project and allow you to edit and modify it.
Basic Single Stepping
We will start by simply pressing run, the program will start, and you will enter simulation mode.
Press button one to start the motor going. Let the motor gain some speed then press button 2 to
stop power to the motor. The motor will now slow down. Once you have tested this and
confirmed that everything is working properly you can stop the program using the stop button.

31
LABCENTER ELECTRONICS LTD.

Next, press the step button once to start then pause the program. At this stage the program
code is currently sat in the setup block. Next, pres the Step Into button to get to the end of the
Setup block:

You will now see the End of setup light up. This shows that the setup function has ended.

Pressing the Step Into button again will advance the program to the first decision block of the
loop routine.

If button 1 is pressed the code will follow the 'Yes' line, if its not pressed it will follow the 'No'
line. In our case the button is not pressed so when we keep stepping the code the program will
move through to the next decision block. We'll then continue running around this loop routine
until a button is pressed.

32
Raspberry Pi Tutorials

Finally, note that you can lock a button in place by pressing the red vertical arrows in the side of
it. This way it will be held down even when you take your mouse away

Stepping and Routines


Let's look now at how the step into and step out debugging commands work when we have sub-
routines in our program. These basically navigate us in and out of the program stack.

To help explain, we have modified our program to include a couple of sub-routine calls.

33
LABCENTER ELECTRONICS LTD.

In this new program you can step through however it will only highlight the event call and not
enter the event block. It will jump between CheckButton1, CheckButton2 and End without
entering the two events. If you do want to enter an sub-routine wait until the event is highlighted.

Then press step into to enter the routine and highlight the first code block in the routine.

We could continue to step through the routine with our normal step commands or use the step
out button to exit the routine and pause at the next code block following the return from the
routine.
Breakpoints
Breakpoints allow you to stop the code when it reaches a specific block of code. To toggle
breakpoints, enter Visual designer, right click on the block you wish to place the breakpoint and
toggle breakpoint.

34
Raspberry Pi Tutorials

Now run the program, assuming button 1 is up nothing will happen. The code will run normally
until you press button 1. Once button 1 has been pressed the code will pause on that block.

From here you can step through the code to debug further.
Debugging Generated Code
If you want to look deeper into what is happening in the code you can look directly at the code
and not the blocks. Right click on the project menu and select debug generated code.

Now when you run the project the flowchart won’t be present. Instead there is a blank screen.
By pressing the step button once it will load up the python script. Now every time you step it will
step line by line opposed to block by block.

35
LABCENTER ELECTRONICS LTD.

You should now be able to navigate and follow the code using the same debugging and
stepping tools we discussed earlier. To navigate through different routines, use the dropdown
box above the code.

Note about Addresses


Some hats are stackable such as this motor hat. When using multiple hats together you may
need to change the I2C addresses. You can do this by using the jumpers. The Hat will have a
base address, for the motor hat the base address is 0x60. The Jumpers work in binary so by
connecting A0 the address will go to 0X61, and connecting A1 the address will go to 0x62 and
so on. The motor hat has a possibility of 32 different addresses including address 0x60.

36

You might also like