RoadTest: RoadTest the Raspberry Pi 4 Model B (2GB)
Author: mpatton36
Creation date:
Evaluation Type: Development Boards & Tools
Did you receive all parts the manufacturer stated would be included in the package?: True
What other parts do you consider comparable to this product?: Older Versions of the Raspberry Pi like the Raspberry PI 3, 2, and B+.
What were the biggest problems encountered?: Sometimes the WiFi would lose connection while I'm browsing on the Pi
Detailed Review:
When I unboxed this product the first thing I did was get a feel of how the product worked. I first downloaded the latest version of the Raspian PIXE software from the Raspberry Pi website and it worked very smoothly. After I did the basic setup I decided to play with some of the features of the Pi. One of the features I played with was the VNC Connect from the Raspberry Pi to my Laptop. I first loaded the VNC Server onto my laptop so the Raspberry PI could VNC into my laptop. Once finished that I then connected my Raspberry Pi to my Laptop and controlled what I did on my laptop like browsing on the internet and running in code from my computer. The VNC connection was spotty at some points where the connection you turn off and on at different times.
Then I started to work on the main part of my project which was create a stoplight. I first started with the Blink LED program which allow me to play with the pins and program with the C program and the default wiring pi. It took me a while to fix syntax errors and to make sure the LED was connected properly to the circuit. Once I was able to create the blinking LED program I added another LED to get it to get both LEDs to blink back in forth. Then I added more LEDs
Once I experimented with the LEDs I created a mockup up on how to make my Stoplight. The first thing that I did was figure out how the logic of how a simple stoplight worked. So I decided that this was a simple stoplight where Light 1 represented a stoplight in the North/South direction and Light 2 represented a stoplight in the East/West direction. After I did that I created a state Machine Chart to show which state of the stoplights and which color each light would be at each stage. The chart looked something like this:
Stoplight State Machine 1 | ||||
Light 1 | Light 2 | Next State | Last State | |
---|---|---|---|---|
State 1 | Red | Red | 2 | 6 or Start |
State 2 | Green | Red | 3 | 1 |
State 3 | Yellow | Red | 4 | 2 |
State 4 | Red | Red | 5 | 3 |
State 5 | Red | Green | 6 | 4 |
State 6 | Red | Yellow | 1 | 5 |
Once I created the stare machine chart I then created the finite state machine diagram below to model what the chart stated. I made this so I can then translate this to some type of code where each state can represent a line of code of each of the LEDs.
When I looked at the first state machine I saw that state 1 and 4 was the same, being that both lights were red at those stages I reduced the light to make it more simple. Since I made my changes here's what the modified state machine looks like:
Stoplight State Machine 2 | ||||
State | Light 1 | Light 2 | Next State | Last State |
---|---|---|---|---|
State 1 | Red | Red | 2 or 4 | 3, 5 or Start |
State 2 | Green | Red | 3 | 1 |
State 3 | Yellow | Red | 1 | 2 |
State 4 | Red | Green | 5 | 1 |
State 5 | Red | Yellow | 1 | 4 |
And Here's what the modified Sate Machine looked light:
So then I modeled code that reflected how the state machine worked. Since this was a mockup c code I used print statements in lieu of LEDs so I can get a feel on how the code was when I ran it. I used switch case statements for the running in between stages because it seem a lot more flexible then using several if else statements. When I came to the part stage 1 I had to figure out a way where it had to determine whether or not the next stage was stage 2 or stage 4. I decided that for each case it was going to record the current stage and also look at the previous stage. So when I came to stage one I decided to write an if statement that looked to see if the previous stage wasn't 3 and determine what the next stage was from there. The reason I picked that solution was because I knew that the when the program starts there wasn't a previous stage and 5 was going to be the last stage. This is reflected in the code below.
if(prevStage != 3) { prevStage = stage; stage = 2; } else { prevStage = stage; stage = 4; }
Once I finished the code and ran it on the terminal the result looked something like this:
As you can see the mock up C program prints the stoplight cycle in the right order.
Next I then made the schematic for where I put my LED lights in and it looked something like this:
Which later looked something like this:
Once I set up the schematic I then edited the stoplight C program, by replacing the stoplight print statements with the LED configuration. I set the Delay at 5 seconds to allow ample time for each stage to show and I ended with a result like this:
When it is dark the stoplight looked something like this:
Other experiments I worked on the stoplight was rewriting the program in python. The challenge I faced in writing this program with python was I discovered that there was not switch case statements in that language. So I had to revisit the logic of the stoplight again and discovered that I need to code the program based off of my first state machine. I did this because it would run faster than making several if and else if statements. Once I was able to overcome this my light looked something like this:
I tried to use a push button on the program and I ran into either many errors or a dysfunctional stoplight but the concept of the push button was to change between the flashing reds and the normal functional stoplight. Here's that the lights look like on flashing reds:
In conclusion I think that the Raspberry Pi 4 Model B (2GB) was the perfect tool to use to run my experiment. The time was very good on when running though each stage so I'm content about that. My only regret was not getting the push button to work properly but I will continue on to make that happen. Next steps to this project is adding turn signals and crosswalks or railway crossings. Other considerations to consider is making international stoplights like red and yellow on before the light turns green or the green light blinking until the light turns yellow. I just want to thank the element14 community for allowing me the opportunity to Roadtest this model and I am looking forward to roadtesting other products in the future.
Top Comments
I enjoyed reading your presentation and discovering your approach.
I see in one of your pictures you have left the case cover off to make GPIO connections. Was this for convenience? Did the case provide…
Interesting use of state machine for driving the LED's(stoplights). One thing I noticed, was the use of If statements. In a large state machine, this can get ugly fast. Could I suggest a tabular approach…