Raspberry Pi Project Tutorials Guide
Raspberry Pi Project Tutorials Guide
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.
1
LABCENTER ELECTRONICS LTD.
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.
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
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
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.
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.
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
9
LABCENTER ELECTRONICS LTD.
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
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.
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
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
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
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.
19
LABCENTER ELECTRONICS LTD.
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.
For the proximity sensor, we want to read a distance so drag and drop into the top of the loop.
20
Raspberry Pi Tutorials
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:
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
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.
26
Raspberry Pi Tutorials
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
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.
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
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
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.
36