RPi Node-Red: Neopixel LED Ring

Goal:

Use string injection nodes and a specific LED ring node to control a LED ring

What You Will Learn:

• Basic Node-Red Programming

Parts List:

12 pixel LED ring

3x male to female jumper wires

Getting Started:

Setting up the Hardware

Use jumper cables to attach the LED ring as in the image.
Attach the red wire to +5v, the black to ground, and the white data line to GPIO pin 18.

Setting up Node-Red

Start Node-Red and navigate to 127.0.0.1:1880  using the web browser.
Drag in the ‘rpi neopixels’ node; and double click on it to start editing its properties.

Set the LEDs field to the number of LED on the ring: 12. Set the Mode to ‘bar – Number of pixels’.  The other fields are all optional, but it might be nice to lower the Brightness, here I lowered it to 15 to lower eye damage. The LED ring can be painfully bright if you are indoors.

Next we drag in the ‘injection’ node, the LED ring node reads strings of text-based commands, and turns them into output on the ring.
We configure our injector like this; setting up Payload to be a string, and contents to be  ‘Blue’. Set the checkbox for Inject once after and set the timer to 1 seconds. Repeat can be set to ‘none’.

Connect the two nodes up like this, check your wiring from the start of the tutorial; and then you’re ready to hit Deploy.
If everything is setup correctly the LED ring should display blue within a few seconds.

The command ‘Purple’ sets the background color to purple on the LED ring.
When the LED ring is initialized all the LEDs are changed to the background color, this can also be set in the node preferences as one of the fields we ignored earlier.
If you read the ‘Node Help’ page for the LED ring node you can see further commands.

For example if we change the payload in the injection node to ‘5,Red’ and Deploy then the first 5 LED will be turned Red; the rest of the LED will remain at the background color we can set in the properties field.

Another possible command is a range of pixels, for example the command ‘3,7,Red’ will set pixels 3-7 Red.
The Color names the LED ring will accept can be found here on Wikipedia : https://en.wikipedia.org/wiki/Web_colors

CONTINUING
the next step is to connect this knowledge with other tutorials, see other tutorials to maybe connect the LED ring to a physical button, or use it in concert with other outputs like speakers.
More advanced logic can be used to turn the LED ring into a clock, or dial.

3D Printing: 3D Printer Setup

Goal:

Setup your QIDI 3D printer from un-boxing to first print

What You Will Learn:

• How to assemble your printer
• How to level the bed of your printer
• How to slice 3D STL models into files the printer can print

User Manual

If you require a detailed procedure, you can follow the user manual below:

QIDI TECHNOLOGY 3D PRINTER START-UP GUIDE

RPi Node-Red: Camera

Goal:

Install the Raspberry Pi camera and take a picture using Node-Red

Parts List:

• Pi Camera
• Pi Camera Ribbon Cable

Getting Started:

Setting up Node-Red

Start Node-Red and navigate to 127.0.0.1:1880.  Into the flow area drag an “inject” node and a “camerapi takephoto” node.

Deploy the flow, then point the camera at something and press the inject button.  The camera will take a picture and then store it in /home/pi/Pictures by default.  Open the file explorer.

Click on the Pictures folder.

Whats Next?

• Try and trigger the camera node with a Raspberry Pi input node connected to a button or PIR sensor.

(Archive) RPi Node-Red: PIR(motion) Sensor

Goal:

Learn how to wire a passive infrared sensor and read it’s state in Node-Red.

What You Will Learn:

• Basic Circuit Prototyping
• Basic Node-Red Programming

Parts List:

• One PIR
• Some Jumper Wires
• One 100 Ohm Resistor

What is a PIR?

A passive infrared sensor or PIR is able to detect movement by measuring the change of infrared radiation.  This PIR comes in a 3 pin package, if you remove the diffusion cap you can see that the pins are labeled “VCC”, “OUT”, and “GND”.  VCC means “voltage at the common collector” and normally refers to a power rail within a circuit, this sensor requires 5 volts. OUT is the pin we will read information from.  GND is the ground connection.

Getting Started:

Setting up the Hardware

I encourage gently taking off the diffusion cap on the PIR to view the pins labels.  GND goes to ground, VCC goes to 5V, and OUT is connected to a 100 ohm resistor and then to GPIO20.

Setting up Node-Red

Start Node-Red and navigate to 127.0.0.1:1880.  Drag a Raspberry Pi input node and a Debug node into the flow area.

Double click on the Raspberry Pi input node to open its configuration menu.  Set the Pin to GPIO20.  Name the node “PIR”.

The debug node can be left with it’s default settings, wire the button node to the debug node and deploy the flow.

If everything has been put together correctly, the state under the PIR node should change from a 0 to a 1 if movement has been detected and then back to 0 after a period of time, inspect the debug tab to view a log of these state transitions.  You may have noticed the two components under the PIR with a plus pattern on them. These are adjustable potentiometers, they control the sensitivity of the PIR and the duration of the activated state.

RPi Node-Red: Push Button + LED or Buzzer

Goal:

Combine the use of Raspberry Pi input and output nodes in Node-Red to control an LED or buzzer with a push button.

What You Will Learn:

• Basic Circuit Prototyping
• Basic Node-Red Programming

Parts List:

• At Least 1 LED
• At Least 1 Resistor
• Piezoelectric Buzzer
• Some Jumper Wires

Optional

• Needle Nose Pliers

Getting Started:

Setting up the Hardware

This wiring diagram is simply the combination of the individual LED, buzzer, and push button circuits.  Make sure that the LED has a resistor on it. Wire a pin on the buzzer to GPIO16, wire the positive leg of the LED to GPIO12, and wire one of the pins on the button to GPIO25.  You can wire all the grounds to a rail and then to the GPIO GND or the connections can be made individually.

If it is difficult to put the components into the breadboard without the legs bending try and use needle nose pliers to help push the pins in.

Setting up Node-Red

Start Node-Red and navigate to 127.0.0.1:1880.  Drag one Raspberry Pi input node and two Raspberry Pi output nodes into the flow area.

Double click the Raspberry Pi input node to open its configuration menu.  Set the Pin to GPIO25.  Set Resistor? to pulldown.  I set the Name to “button”.

Double click one of the Raspberry Pi output nodes to open its configuration menu.  This will be the LED so set the Pin to GPIO12.  Leave Type set to Digital output, Initialise the pin state to low.  Name the node “LED”

Double click the other Raspberry Pi output node to open it’s configuration menu.  Set Pin to GPIO16.  Set Type to PWM output.  Set Frequency to 100.  Name the node “buzzer”.

Wire each output node to the single input node and deploy the flow.

If everything works properly activating the button should turn on the LED and activate the buzzer.  To stop either output node from activating just remove its connection to the button node and redeploy the flow.

Whats Next?

• What other combinations can you make with the items in your kit?

(Archive) RPi Node-Red: Push Button

Goal:

Learn how to wire a push button and read it’s current state in Node-Red

What You Will Learn:

• Basic Circuit Prototyping
• Basic Node-Red Programming

Optional

Parts List:

• 1 Push Button
• Some Male-Female Jumper Wires

Optional

• Multi Meter
• Needle Nose Pliers

What is a Push Button?

A push button is a momentarily activated button.  When the button mechanism is fully depressed an internal electrical connection is made and this newly made connection can be read as the activation of the button.

A breadboard is a prototyping platform that allows the easy creation of circuits without having to solder.  Each row of the breadboard is connected internally (not across the middle break). This mean that putting something into position 1a and 1b connects them electrically together while something plugged into position 1a and 2a are electrically isolated.

The power rails on the left and right hand side of the breadboard are connected in a column and can be an easy way to access ground of power if you choose to route it there.  The color red and by extension the red column is often used for power while blue is often associated with ground and thus used for a ground connection.

Getting Started:

Setting up the Hardware

Take care when wiring the button to the GPIO, you want to connect the correct pins.  In it’s 4 pin package only some pins are isolated in the inactivated state.  A pair of pins that come out of the same side of the button are isolated as well as diagonal partners.  A multi meter on the diode setting can also be used to test if there is a connection between pins in an activate/inactivated state. Once you have identified the correct pair of pins attach one to 5V and the other to GPIO25.

Additionally it can be difficult to get the short legs of the push button to correctly make contact with the breadboard, I find that using needle nose pliers to straighten the legs of the push button and then inserting them 2 at a time to be a successful method.

Setting up Node-Red

Start Node-Red and navigate to 127.0.0.1:1880.  Drag a Raspberry Pi input node and a Debug node into the flow area.

Double click on the Raspberry Pi input node to open its configuration menu.  Set the Pin to GPIO25.  Set Resistor? to pulldown.  You can Name the node anything, I chose “button”.

The debug node can be left with it’s default settings, wire the button node to the debug node and deploy the flow.

If everything has been put together correctly you should see the number under the button node in the Node-Red flow change from a 0 to a 1 when the button is activated and from 1 to 0 when the button is deactivated.  You should also be able to see a record of the button activation in the debug tab of Node-Red.

(Archive) RPi Node-Red: LED

Goal:

Turn a light emitting diode(LED) on and off using a button in Node-Red.

What You Will Learn:

• Basic circuit prototyping
• Basic Node-Red programming

What You Need to Know:

• Node-Red Basics

Optional

Parts List:

• At Least 1 LED
• At Least 1 resistor
• At least 2 male-female jumper wires

A breadboard is a prototyping platform that allows the easy creation of circuits without having to solder.  Each row of the breadboard is connected internally (not across the middle break). This mean that putting something into position 1a and 1b connects them electrically together while something plugged into position 1a and 2a are electrically isolated.

The power rails on the left and right hand side of the breadboard are connected in a column and can be an easy way to access ground of power if you choose to route it there.  The color red and by extension the red column is often used for power while blue is often associated with ground and thus used for a ground connection.

What is a Resistor?

A resistor is an electrical component that has a specific value of resistance measured in ohms.  Resistors are used to restrict the amount of current in a circuit or facilitate a drop in voltage.  Its value of resistance can be read in ohms using the colored bands on the body of the resistor.

What is an LED?

An LED is a light emitting diode.  Diode’s are a class of electronic components that are designed to only allow current to pass through them in one direction.  This means that LEDs are polar meaning they have an anode (positive) and a cathode (negative). Current must flow into the anode and the cathode must be attached to ground.

There are several methods of identifying the anode and cathode:

• Look at the lengths of the pins, If the LEDs’ pin have not been modified the longer pin is the anode and the shorter pin is the cathode
• Look at the sides of the LED a portion of the case will be flat the pin on that flat side is the cathode
• Look inside of the bulb, each pin is connected to a flat piece of metal internally.  The pin that is attached to the larger piece is the cathode

An LED must have a current limiting resistor between it and ground or between it and power.  An unprotected LED will pull more and more current until it burns itself out. The value of the resistor will have an effect on the LEDs’ luminosity.  The higher the value of resistance the resistor has the less current will get to the LED and thus the dimmer the bulb will shine. The amount of current can be calculated in milliamps with Ohm’s Law, using the value in ohm’s for resistance

$text{current} = frac{text{voltage}}{text{resistance}}$

Getting Started:

Setting up the Hardware

If you are following the wiring diagram make sure to attach the cathode (straight leg in the diagram) of the LED to a resistor and then to GND (ground).  Attach the anode (leg with the kink) to GPIO #12.

Setting up Node-Red

Start Node-Red and navigate to 127.0.0.1:1880  using the web browser. Drag two inject nodes and a Raspberry Pi output node into the flow area

Double click on the Raspberry pi output node to open its configuration menu.  Set the Pin to the same pin you physically connected the LED to. If you are following the wiring diagram this is GPIO12.  Leave the Type as Digital Output.  We can also Name the node, since I used a green LED I named it “Green led”, this follows a good programming practice of accurately and succinctly naming variables.

Double click one of the inject nodes.  Use the drop down menu to change the Payload data type number, type a “1” in the text box.  Name the inject node “on”.

Double click the unmodified inject node.  Use the drop down menu to change the Payload data type to number, except type a “0” in the text box.  Name this node “off”.

1 and 0 correspond for to values of a binary digit(bit) true and false, high and low, on and off respectively.  These are called boolean values and are a fundamental data type in Computer Science.

Connect the inject nodes to the output node and then deploy the flow.

The green square under the Green LED node tells us what state the LED is in, 1 being on and 0 being off.  Injecting a different value will change the state from off to on or from on to off.

RPi Node Red + Camera

In this lesson, students will create a TinkerCAD account, as well as learn the basics of creating a 3D object.

3D Printing: Overview

Overview

3D Printing & Computer Aided Design (CAD) will allow students to discover the potential and limitations of 3D Printing through a build intensive design project. Students will learn how to use CAD software such as AutoDesk, SolidWorks, etc. An excellent opportunity for anyone interested in prototyping, creating artworks, or product customizations.

TinkerCAD is a simple, online 3D design and 3D printing app for everyone. TinkerCAD is used by designers, hobbyists, teachers, and kids to make prototypes, artworks, and Minecraft models!

To 3D Print your own models you need to slice the STL file into an X3G file that you save to the SD card while it is plugged into your computer.

Makerbot Desktop is the easiest one to use and the one I recommend you start with.

After installing the software select “MakerBot Replicator” (NOT Replicator 2X) as your printer type.

After you have the X3G file on your SD card you plug it into the 3D printer and select “Print from SD card”.

RPi Minecraft + Networking

In this activity students will learn about networking on the Raspberry Pi using a popular pre installed game called Minecraft.

I use this opportunity to speak about the human networking that happens when a team of individuals work together. Minecraft is known as a sandbox game where blocks can be created or destroyed.   Many students have played Minecraft in a way that players attack each other known as player vs player, or PVP. Establish that this is not the kind of environment that is being created.  Students will work together to build something cool.

Establishing a level of experience with Minecraft is a good way to start.  I like to group advanced users with each other and beginning users together.  Each group needs to brainstorm, plan and build something in a specified amount of time.  I usually give students between 15 and 30 minutes and encourage them to stretch to collaborate.   Groups can range in size from 2 – 5 players.  One student will “host” the world on their device and will need to identify their I.P address to share with partner players.

Immediately upon opening up Minecraft students given an option to join game or create a new world.  If they create a world, it exists on their pi, if they join a world they need to know who’s world they are joining.  This becomes a process of students calling out and identifying who’s pi is at which IP address.  The IP address can be found by hovering over the Wifi signal in the upper right corner of the screen.

Students who have never used Minecraft will need assistance learning to move within the world, to place a block and to change their inventory.  These students should focus on building something very simple.  Advanced students might build a castle or a huge underground maze.  At the end of the build time, join into the world on your Pi and let one of the students from each group share what they created.

If students wish to save the world they are working on, they will need to navigate to the .minecraft folder from and drill down to the folder of the world they were playing in.  The following video goes over how to do this.

RPi Scratch Reaction Time

Programing is about giving a computer a set of instructions. Instructions can be given in a text based format or in a visual format. Scratch is a visual programing language that allows a user to easily create interactive stories, games, and animations by dragging specific bits of code to an area and running the program. To get an idea of what Scratch can do, share this overview video.

Scratch can be run in a browser on a regular computer but it is a bit resource intensive to run on a Pi. Two versions come installed on the Raspberry Pi, the classic version labeled Scratch, and an updated version Scratch 2.0.  Scratch 2.0 tends to be a bit less responsive, however it has some very cool features that are explored in a later lesson.

Have students open Scratch (not scratch 2) from the program menu and follow along with the tutorial below.

When students have been able to do some basic functions in a Scratch environment introduce them to this project creating a reaction time game.

Getting Started

There are a myriad of ways to edit text files and code built into the Raspbian distribution; several even inside the terminal. But here we will cover some of the easier to use graphical programs.

It’s important you know your way around the terminal before continuing, please see the terminal tutorial -> here

Leafpad is a lightweight notepad-like text editor that is bundled with Raspbian; we will use it here to edit simple config files in the file system.
For example the led ring tutorial directs us to edit the /boot/config.txt and comment out some lines.
To do this navigate to the /boot/ directory in the terminal; and then run ‘sudo leafpad config.txt’, this is similar to other commands you have seen taking a path as an argument, the important difference is the ‘sudo’ prefix which tells the terminal to run this command as a ‘super user’. This allows us to overwrite important system files and access gpio pins ect. You’ll have to use it often but you should still be careful.

We get an editor window like notepad on windows, we can insert a ‘#’ before dptparam to comment it out, and then save with control s
after exiting the editor you will regain control of your terminal.

Editing and running python scripts with Thonny

Next we can use a slightly complicated editor, Thonny is specifically for python ‘.py’ files and has some features that make debugging scripts easier.
Thonny can be found in the menu in the top left corner, or again opened from the terminal with ‘sudo thonny’.
Most scripts accessing the GPIO require sudo powers to work correctly, so its best to get used to running it as sudo.
You open a file to edit by navigating to it in the thonny gui; like notepad on windows.

We can enter python scripts line by line into the main window, and at any moment run our script with F5 or the gui button (green arrow).
Here is what it looks like to run a simple program inside thonny.
note the output in the lower window, this is the result of pressing F5 or the run button

RPi Sense HAT+Minecraft

The Sense HAT was developed by the folks at Raspberry Pi as an add on board that contains a number of sensors and a LED display. In this lesson we can demonstrate how to use the Sense HAT in conjunction with Minecraft to visualize real world data and control the LED Screen.

I use this lesson primarily to get students excited about the connection between a sensor and the way that we can visualize data through Minecraft.  This worksheet from the folks at the Raspberry Pi foundation is an excellent resource. In the latter portions of the lesson it goes into methods of collecting data from the Sense HAT and displaying it within the Minecraft world.

https://www.raspberrypi.org/learning/exploring-space-with-minecraft/

Follow along with the Sense HAT installation and the first several worksheets of this project.

4. Github Intro

Github is known as a repository for cool programs that can be used in all sorts of ways on your Pi. In this lesson we will learn how to install programs from Github using the terminal.

First lets install a program that can do screen captures. Something that is handy when students have created something amazing in their Minecraft world.

Lets follow the instructions for taking screenshots provided by Martin O’Hanlon.

Here is a video going through the process.

Students will be really excited when they learn to download programs that can run within their Minecraft world. Lets go back to Martin’s API tutorial and have students select one of the first three items, clock, cannon, or snake video game.

In each of these examples, there is a section of code that should be copied into the terminal. When enter is pressed on the keyboard, a bunch of code will appear and a new program file will be placed in the home directory on the Pi

Have students navigate to the file folder and open the file with the .py extension by right clicking on the file and selecting open with python 2 from the drop down menu.  If the program is run while Minecraft is open it will place an exciting new feature in the Minecraft world. This will hopefully trigger a desire to try downloading other python programs to modify their Minecraft worlds.

Navigating with the terminal

Like on windows or any other computer, files in Linux are arranged in a hierarchical directory structure; meaning starting at root there is a sort of tree of folders containing files and other folders.
The terminal has a concept of ‘working directory’ ; using the metaphor of navigating an office building this is simply what room the terminal is in. If you use a command to list files it will look around the current directory and return you a list of files currently visible.

After opening a terminal with the icon in the upper left you will be confronted with something like this (but most likely with a different color-scheme and font)

upon opening terminal

We can now use the ‘pwd’ print working directory command to see what directory or room we are in; the result is returned to us in simple text:

Now we know what directory we are in, but we still don’t have any idea what accompanies us; for that we can use ‘ls’ list command; which returns us a list of files and directories in our working directory.

I have added a file here to demonstrate that files are coloured differently to directories.
Now we can try entering one of the directories listed, for this we can use the cd change directory command. This command takes a ‘path’ as an argument. Paths are just strings of text describing the location of a directory or file; pwd returns the ‘path’ of our current working directory. Another path could be ‘/home/pi/Documents/’. Paths can also be relative to our current location, so if our current working directory is ‘/home/pi’ then ‘Documents’ would be a valid path.

Most of the time you will use relative paths, they are shorter and easier to work with too.
To navigate to a directory relative to our own we first use ls to see what our options are.

Then we use the cd command with a path to enter one, we’ll use the python_games directory because we know ahead of time its not empty: cd python_games

Another valid and equivalent command would again be cd /home/pi/python_games

Once we enter the directory we can use the ls command to orient ourselves.

We can see dozens of files and no directories, here we can practice running and terminating a python script.

Running and Exiting python scripts

Just like the cd command there is a python command pre-installed that takes a python script as an argument, python scripts are files with a .py extension.
To run a game choose any file with a .py extension and use it as an argument to run python.

To exit the program at any time use the Control-C keybind, this sends a kill signal to the python process we just started; this will also be used regularly when you want to exit python scripts you are testing.

Next we will navigate back home using terminal commands and create our own directories and files.
Apart from relative and absolute paths that we already covered there are some more special cases, for example the ‘..’ path refers to the directory one level above our current working one. This makes it easy to navigate upwards out of whatever area we entered.
To navigate back to the home directory use ‘cd ..’, and then use ‘pwd’ to check if you made it back.

Finally we will create our own directory and some files to populate it. Just like the cd command there exists a mkdir command which again takes a path. This command simply spawns a folder with our chosen path, for example..

At first we have no indication that our command did anything, but a simple ls will reveal all.

We don’t want to spam files all over our home directory, so before we start making them lets enter our directory with cd.
The command for creating files in the terminal is called touch, it takes a path and creates an empty file whereever we tell it too, or if the file already exists it just ‘touches’ it; updating its last modified date ect.

Now that we are safely in our own directory we can try it out:

There does exist a rm command to remove files, but it can be dangerous if you accidentally delete some script or important document you were just working on!
as you can guess it takes a path as its argument; here we can see it at work.

Last of all we can clean up after our empty directory, navigate back to the home using cd, and then use the sister to rm, rmdir to remove our directory.

Conclusions

In this tutorial we reminded ourselves what directories and files are, how to find our current working directory in the terminal, how to list files and folders, how to enter and leave directories, how to run and exit python scripts, and how to create and delete files / folders.

1.1 Box Build

If you are setting up the box for the Raspberry Pi Kit, here are the steps you need to follow.

Step 1: Glue the bottom of the box together. Use a tiny bit of glue on each tab. Let the box dry for at least 2 hours.

It should look like this:

Step 2: Screw the hinges

Step 3: Screw the hinges on to the top part of the box with the screen attached.  Be sure to insert the HDMI cable and the power cable for the screen through the appropriately sized holes.

Step 4: Put the side panel on the box lid.

Step 5: Put the top of the box on.

Step 6: Put the post screw with the wooden hinge on the side panel, make sure to align with the hole in the base.

Step 7: Fit the side panel with the hinge on the box and do the same thing on the other side.

Step 8: Connect the wooden hinge to the box with another post screw

Step 9: Put all the screws and square nuts on the sides of the box

1. Getting Started

In this lesson students will learn about the Raspberry Pi computer and the components provided in the kit.  Having a completed kit as an example will be helpful but not necessary.  Begin by showing this short video about a raspberry Pi.

If the boxes have not been assembled have students refer to this post for building instructions.

The kits include these parts:

Raspberry Pi 3 + support
• Raspberry Pi 3
• Micro SD card 16GB – With Raspbian
• Micro USB Cable
• USB Power Supply 3 Port
Screen / Interface Parts
• LCD 7″ 1024×600 with speakers
• 30CM HDMI Cable
• Keyboard – wired compact – full size keys
• Mouse – wired retractable cord
Accessory Parts
• RPi Compatible 5MP Camera – Not official
• RPi GPIO Reference Card
• Jumper Wire 20pcs 20CM 2.54mm M-F
• Jumper Wire 20pcs 20CM 2.54mm F-F
• Jumper Wire 20pcs 20CM 2.54mm M-M
• Alligator clip jumper 2 pieces random color
• 5x LEDs 5MM
• 4x Push Buttons – Breadboard Compatible
• 20x 100R Resistor
• 20x 330R Resistor
• 20x 470R Resistor
• 20x 1K Resistor
• 20x 10K Resistor
• 20x 100K Resistor
• Piezo passive speaker
• PIR infrared motion sensor
• Ultrasonic Distance Sensor
• DHT11 humidity + temp sensor
• RGB LED Ring 12 pixels – WS2812
• 2x 9g Servo
Growth Mindset
• 2x Brushbot kit
Packaging

The video below introduces the various components and describes how to to power on the Raspberry Pi computer.