Commit 7b5ddceb authored by Jack Hollingsworth's avatar Jack Hollingsworth
Browse files

embedded programming final update

parent 1a268691
# 6. Architecture Types
This week's assignment was to learn about and analyze different workflows for diferent types of architectures.
This week's assignment was to learn about and analyze different workflows for diferent types of architectures. As we had only programmed microcontrollers with variants of C thus far in Fab Academy, we decided to configure and program an LED to blink on a Raspberry Pi 4 and a Raspberry Pi Pico in order to investigate the programming and uploading process using different form factor boards and a different language from what we are used to.
## PI Setup
![](../images/week06/RaspPI_Imager.jpg)
As we could not find a Pi that already had an operating system installed and configured, we decided to boot a fresh copy of Raspbian on a new RPi 4 in order to take advantage of the faster write speeds offered by the latest variant of the microcomputer. Nevertheless, we were still booting from a microSD card, which are not known for celeritous read/write speeds. As such, the entire installation process of the lite version of Raspbian took upwards of 30 minutes to fully complete.
![](../images/week06/raspberry_pi_downloading_packages.jpg)
After booting a fresh OS on the Pi, we verified that all of the modules, programs, and libraries that we would need to make the LED blink were included in the base installation of Raspian. After installing Python 3.8 we were ready to begin wiring the LED to the Pi's GPIO array.
![](../images/week06/raspberry_pi_installing_python3.jpg)
![](../images/week06/raspberry_pi_setup.jpg)
After downloading the necessary programs, we began researching the pinout of the GPIO array on the rPi 4 in order to know how to wire our LED to properly address it via a python script. We used <a href="https://roboticadiy.com/how-to-blink-led-with-raspberry-pi-4/">this guide</a> as a reference for the wiring of our LED to our rPI 4.
## GPIO Control
......@@ -19,8 +24,72 @@ This week's assignment was to learn about and analyze different workflows for di
![](../images/week06/raspberry_pi_photo_of_code.jpg)
![](../images/week06/raspberry_pi_troubleshooting.jpg)
After a good bit of troubleshooting with very simple codes, we finally found 2 possible reasons the LED was not blinking. The first thing we found was that instead of using a 330 ᘯ resistor, we were accidentally using a 1,000,000 ᘯ resistor. While the LED would technically still turn on, it would be so dim that the change would not be visible. The reason we were using the incorrect resistor was that the 1,000,000 ᘯ resistor were in the 330 ᘯ resistor box and we did not check the value with a multimeter. This, however, did not solve our issue.
We decided to write the python using an internal text-editor, nano, that is included in the base installation of most Linux distros, including base installations of Ubunto and Debian, that can be opened with the command 'sudo nano *filename*' and executed by simply typing the filename into an active Linux shell. This method does not require an external IDE that must be installed by a user, and due to the simplicity of the code that was necessary for our LED to blink, it made total sense to utilize this basic text editor rather than using alternative environments like Thonny or IDLE.
After repeated troubleshooting with very simple codes, we finally found 2 possible reasons the LED was not blinking. The first thing we found was that instead of using a 330 ᘯ resistor, we were accidentally using a 1,000,000 ᘯ resistor. While the LED would technically still turn on, it would be so dim that the change would not be visible to humans, which defeated the purpose of making the LED blink. We ultimately discovered that the 1,000,000 ᘯ resistors were mixed with the 330 ᘯ resistors in our lab, and an incorrect resistor had been selected from the box. After swapping the 1,000,000 ᘯ for a 330 ᘯ resistor that we verified did have the correct resistance value with a multimeter, the LED still did not blink.
After switching the resistor proved futile in resolving our problem, we postulated that the issue likely was caused by a faulty LED. To eliminate verify the state of the LED that we were using, we connected it directly to VCC and GND on the rPI, with a 330 ᘯ resistor connected between VCC on the LED and the Pi, and discovered that we were using a faulty LED as it still was not illuminated. After identifying this potential cause of the issue, we swapped the LED to an LED that we verified was working correctly with a multimeter, and executed our python script with the new connection made. After running the code, the LED turned on and toggled its state each second.
The following code is what is running on the Pi in the final video of our LED blinking on the Raspberry Pi 4.
```
from gpiozero import LED
from time import sleep
led = LED(17) #GPIO 17
thisCodeWorks = True
while thisCodeWorks:
led.on()
sleep(1)
led.off()
sleep(1)
```
<iframe width="1000" height="500" src="https://www.youtube.com/embed/sh8Dp8q2XmM" title="YouTube video player" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>
## LED Blink with Raspberry Pi Pico
The Raspberry Pi Pico is a relatively new proprietary microcontroller product that is manufactured by Raspberry Pi, which is an incredibly economical option compared to the Arduino class of boards which tend to cost 2-3x as much for a comparable product. The Pico also has considerably superior technical specifications to the ATMega328P microcontroller that is found on most consumer-grade Arduino Products. The Pico has a clock speed of 133MHz while the 328P runs at just 16MHz. Additionally, the Pico features 30 GPIO pins, while the 328P features 26. As nobody in our group had employed this compelling new technology prior to this week, it was incredibly interesting to delve into the world of Raspberry Pi's first proprietary microcontroller that is an incredibly promising rival to the Arduino series of products, which will hopefully incite speedier proliferation from each side in the coming years. We decided to do the same thing that we did with the rPI 4, blinking an LED via GPIO headers, in order to compare the processes for writing to the LED using the different protocol that is required by each board.
### Configuring rPi Pico
As the Raspberry Pi Pico is a standalone microcontroller board, it requires a connection to a PC, preferably a machine running Windows 7, 8, or 10, and some software on the machine. The board also uses a different variant of Python that is converted into code that is readable by the microcontroller, which is called MicroPython. First, we needed to install <a href="https://www.putty.org/">PuTTy</a>, which would allow us to write directly to the microcontroller without needing to perform uploads each time we wanted to put new code onto the Pico. Configuring the Pico requires a relatively straightforward process, but as the most optimal resetting process requires destroying the USB connection between the board and master machine, it can become a quite tedious process during phases that require repeated troubleshooting. Using PuTTy, users must search for the Pico in the 'Device Manager' Windows tab and manually select the specific port of the device within PuTTy.
![](../images/week06/dmanager.PNG)
After locating the port address of the Pico, there are several fields that need to be filled out within PuTTy before a successful connection can be made to the board. The proper values for each field are displayed below. The next step is to open a serial connection between the PC and the Pico and begin the transcription of code in the console that is opened.
![](../images/week06/sillyputty.PNG)
### Wiring the LED to the Pico
While the connections on all other Raspberry Pi variants exist soley betwene the Raspberry Pi and GPIO devices, the Raspberry Pi Pico requires a USB connection to a PC in order to receive uploads. The GPIO connections to the microcontroller were made using the schematic found below. We first decided to make the onboard LED blink because it does not allow for errors to be made in the actually addressing of the pins, and would give us a better idea of what we were doing right so we could then apply that knowledge to the blinking of an external LED without questioning our ability to make any LED blink with the Pico.
![](../images/week06/fabG600.png)
### Prog(r)am(m)ing
After opening a serial connection to the Pico using PuTTy, MicroPython code can be transcribed in the console line by line and is directly injected into the board. This is incredibly useful for rapid-prototyping, though a serial connection must be closed in order to restart; however, there could be an integrated restart feature that we are unaware of.
![](../images/week06/fabG603.PNG)
We first tested the MicroPython shell with a brief print statement. After verifying that the shell was working correctly, we began injecting MicroPython code into the Pico in order to blink the external LED that we attached to pin 0 on the device.
![](../images/week06/fabG604.PNG)
```
print("GPIO blinking LED makes me happy")
import time
from machine import Pin
led1 = Pin(0, Pin.OUT)
jackAttractsLotsOfWomen = True
while jackAttractsLotsOfWomen:
led1.high()
time.sleep(1)
led1.low()
time.sleep(1)
Our second possible issue was the LED itself. To test it out, we just connected the LED directly to ground and VCC (with the 330 ᘯ resistor, ofcourse) to see if the LED itself might have been the problem. We discovered that it was not turning on like this. This meant we had identified the problem, which was just that we had a faulty LED. When we tested out another LED, it turned on and blinked when we uploaded the code.
```
<iframe src="https://player.vimeo.com/video/543402489?title=0&amp;byline=0&amp;portrait=0&amp;speed=0&amp;badge=0&amp;autopause=0&amp;player_id=0&amp;app_id=58479" width="640" height="360" frameborder="0" allow="autoplay; fullscreen; picture-in-picture" allowfullscreen title="pico blink external LED Fab Group Site Week 6 Attempt 001"></iframe>
<iframe width="560" height="315" src="https://www.youtube.com/embed/sh8Dp8q2XmM" title="YouTube video player" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>
\ No newline at end of file
## Conclusion
After successfully uploading a code that effectively accomplished an identical task using two vastly disparate workflows for two different boards, our group reflected on the stark differences that exist between the Raspberry Pi 4 and Raspberry Pi Pico. Firstly, we felt that our task was not intensive enough for the performance differences between the two devices to be noticeable in their ability to complete the task, meaning that the Pico made far more financial sense as it costs roughly 10% that of its mircocomputer counterpart. We found that the rPi 4 made rapid re-iteration significantly easier, as the Pico requires a multi-step process in order to be ready to receive fresh code injections via PuTTy. Ultimately, our group work for embedded programming week in comparing similar tasks on two different architectures provided an intriguing glimpse into the processes outside of the Arduino IDE and Atmel ecosystem, which many of us hope to utilize in our final projects as well as in future endeavors outside of Fab Academy.
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment