Working with schematics to wire digital outputs
Now, it is time to take advantage of the prototyping capabilities of the breadboard and start working on a more complex example. We will turn on and off 9 LEDs by using 9 digital outputs of the Intel Galileo Gen 2 board. Each digital output is going to control whether an LED is turned on or turned off.
After we finish the necessary wirings, we will write Python code that counts from 1 to 9 by controlling the digital output to turn on the necessary number of LEDs. In this case, our first approach won't be the best one. However, after we learn many things, we will create new versions and we will improve both the initial prototype and the Python code.
We need the following parts to work with this example:
- Three red ultrabright 5mm LEDs
- Three white ultrabright 5mm LEDs
- Three green ultrabright 5mm LEDs
- Nine 270Ω resistors with 5% tolerance (red violet brown gold)
The following diagram shows the components connected to the breadboard, the necessary wirings and the wirings from the Intel Galileo Gen 2 board to the breadboard. The Fritzing file for the sample is iot_fritzing_chapter_03_02.fzz
and the following picture is the breadboard view.
In this case, we decided to match the GPIO pin number with the LED number. This way, whenever we want to turn on LED 1, we write a high (1) value to GPIO pin number 1, whenever we want to turn on LED 2, we write a high (1) value to GPIO pin number 2, and so on. Later, we will realize it is not the best decision because the wiring becomes a bit more complex than expected due to the positions of the pins in the board. However, we will analyze this situation later and we will create a new version of this example with improvements based on everything we learned from the first version.
The following picture shows the schematic with the electronic components represented as symbols. The schematic makes it easier to understand the connections between the Intel Galileo Gen 2 board GPIO pins and the electronic components. Clearly, the schematic benefits from the fact that the GPIO pin number matches the LED number and it will be easy to write our first version of the code.
As seen in the previous schematic, each GPIO pin labeled from D1 to D9 in the board's symbol is connected to a 270Ω resistor, wired to an LED's anode, and each LED's cathode is connected to ground. This way, whenever we write a high (1) value to any of the GPIO pins, the board will put 5V on the pin and the LED will turn on. Whenever we write a low (0) value to any of the GPIO pins, the board will put 0V on the pin and the LED will turn off.
Tip
As we left the jumper labeled IOREF in its default 5V position, the board will be operating with 5V for its GPIO pins. Thus, a GPIO pin will have 5V when we write a high value to it. If we change the position of this jumper to 3.3V, a GPIO pin will have 3.3V when we write a high value to it. Unless specified otherwise, we are using the default position for this jumper in all the examples.
Now, it is time to insert the components in the breadboard and make all the necessary wirings.
In order to shutdown the Yocto Linux, enter the following command in your ssh
terminal. Make sure you have exited the Python interpreter when you enter the command.
shutdown
As a result of the previous command, you will see the time at which the shutdown process is going to begin. The message will be similar to the following output but with different dates and times.
Shutdown scheduled for Mon 2016-01-25 23:50:04 UTC, use 'shutdown -c' to cancel. root@galileo:~# Broadcast message from root@galileo (Mon 2016-01-25 23:49:04 UTC): The system is going down for power-off at Mon 2016-01-25 23:50:04 UTC!
Then, wait around 1 minute until the operating system closes down and all the onboard LEDs turn off. At this time, you can safely remove the power supply from the board.
We have to pay special attention when inserting the LEDs in the breadboard. As we can notice in the schematic, the resistor is wired to an LED's anode, and each LED's cathode is connected to ground.
We can easily identify the LED's anode, that is, its positive lead, because its lead is slightly longer than the other lead. The LED's cathode, that is, its negative lead is shorter than the other lead. In the following picture, the LED's cathode, that is, its negative lead is the lead located at the left-hand side (the shorter lead). The LED's anode, that is, its positive lead, is the lead located at the right-hand side (the slightly longer lead). You can also notice that the metal piece inside the LED connected to the LED's anode, that is, its positive lead, is smaller than the metail piece inside the LED connected to the LED's cathode, that is, its negative lead.
The LED in the picture is located in the same position than the LEDs are connected in the previously shown breadboard picture. Thus, we have to connect the shorter lead at the left and the larger lead at the right in the breadboard. The next picture shows the LED representation in the breadboard picture with its cathode and anode.
The following picture shows the schematic electronic symbol for the LED with the same positions for the cathode and anode than in the previous picture that showed the breadboard picture.
The following picture shows all the LEDs connected to the breadboard. You can check the cathode and the anode based on the metal parts that you can see through the LED's plastic.
The following picture shows all the LEDs connected to the breadboard where you can check that the LEDs are connected as we have seen in the breadboard view for the Fritzing diagram.
Resistors are the same forward and backwards, and therefore, it doesn't matter which way you use them in the breadboard. The following picture shows a 270Ω axial-lead resistor with 5% tolerance. Notice that the color bands from left to right are red, violet, brown and gold. The color bands allow us to know the resistance in ohms and their tolerance value without having to measure the resistor.
The following picture shows the components connected to the breadboard, the necessary wirings and the wirings from the Intel Galileo Gen 2 board to the breadboard.