Commit b634e060 authored by Parinaz Hathiram's avatar Parinaz Hathiram
Browse files

Merge branch 'master' into 'master'

Networking and Inputs updated

See merge request !146
parents f856ce3e 573d5509
Pipeline #313652 passed with stage
in 40 seconds
......@@ -163,13 +163,23 @@ This group consists of Alaric, Aaron, Jada, Pari
## NVIDIA Jetson NANO
Aaron and Alaric worked on setting up the [jetson nano](https://developer.nvidia.com/embedded/learn/get-started-jetson-nano-devkit#write). It functions similarly to a raspberry pi so it requires a monitor, mouse, and a keyboard although it was designed to utilize AI. They booted up the device with a goal of lighting an LED. They used this site as a [workflow](https://automaticaddison.com/how-to-blink-an-led-using-nvidia-jetson-nano/?msclkid=4a724931b54711ec8ccb8045104f0bce). When activating it they recieved a sign in screen but the user was dated back to the year 2019. They couldn't figure out the password and were locked out.
<<<<<<< HEAD
Aaron, Alaric, and Pari worked on setting up the [jetson nano](https://developer.nvidia.com/embedded/learn/get-started-jetson-nano-devkit#write). It functions similarly to a raspberry pi so it requires a monitor, mouse, and a keyboard although it was designed to utilize AI. They booted up the device with a goal of lighting an LED. They used this site as a [workflow](https://automaticaddison.com/how-to-blink-an-led-using-nvidia-jetson-nano/?msclkid=4a724931b54711ec8ccb8045104f0bce). When activating it they recieved a sign in screen but the user was dated back to the year 2019. They couldn't figure out the password and were locked out.
Pari tried to figure out the user, by reaching out and finding the most used passcodes in the lab. Although, there wasnt any luck so, she proceeded to as Alaric, to help find a solution.
=======
Aaron, Alaric, Jada and Pari worked on setting up the [jetson nano](https://developer.nvidia.com/embedded/learn/get-started-jetson-nano-devkit#write). It functions similarly to a raspberry pi so it requires a monitor, mouse, and a keyboard although it was designed to utilize AI. They booted up the device with a goal of lighting an LED. They used this site as a [workflow](https://automaticaddison.com/how-to-blink-an-led-using-nvidia-jetson-nano/?msclkid=4a724931b54711ec8ccb8045104f0bce). When activating it they recieved a sign in screen but the user was dated back to the year 2019. They couldn't figure out the password and were locked out.
>>>>>>> 675691fb0de4aba809472ba77619b1af86eae25b
Alaric proceeded to first wipe the sd card with some advice from [Jack](https://fabacademy.org/2022/labs/charlotte/students/jack-donnelly/) by using [rufus](https://rufus.ie/en/#).
Alaric and Pari proceeded to first wipe the sd card with some advice from [Jack](https://fabacademy.org/2022/labs/charlotte/students/jack-donnelly/) by using [rufus](https://rufus.ie/en/#).
![](../images/week09/alaricJetsonRufus.jpg)
He then followed the instructions on [the jetson nano site](https://developer.nvidia.com/embedded/learn/get-started-jetson-nano-devkit#write). After downloading the sd card image from it, he downloaded and launched [the sd card formatter for windows](https://www.sdcard.org/downloads/formatter/sd-memory-card-formatter-for-windows-download/) to format the sd card.
<<<<<<< HEAD
Pari and Alaric then followed the instructions on [the jetson nano site](https://developer.nvidia.com/embedded/learn/get-started-jetson-nano-devkit#write). After downloading the sd card image from it, Alaric downloaded and launched [the sd card formatter for windows](https://www.sdcard.org/downloads/formatter/sd-memory-card-formatter-for-windows-download/) to format the sd card.
=======
They then followed the instructions on [the jetson nano site](https://developer.nvidia.com/embedded/learn/get-started-jetson-nano-devkit#write). After downloading the sd card image from it, he downloaded and launched [the sd card formatter for windows](https://www.sdcard.org/downloads/formatter/sd-memory-card-formatter-for-windows-download/) to format the sd card.
>>>>>>> 675691fb0de4aba809472ba77619b1af86eae25b
![](../images/week09/alaricSDCardFormater.jpg)
......@@ -177,16 +187,16 @@ To finish setting it up, he used [balena etcher](https://www.balena.io/etcher/)
![](../images/week09/alaricBalenaEtcher.jpg)
Aaron after the card was reset proceeded to create a new account for the Jetson. He had to connect an ethernet to the Jetson because the commands for the workflow required python and the code was also python based.
Aaron and Jada after the card was reset proceeded to create a new account for the Jetson. He had to connect an ethernet to the Jetson because the commands for the workflow required python and the code was also python based.
![image](../images/week09/PluggedInJetsonNano.jpg)
He went to the [python website](https://www.python.org/) to download version 3.8.6. After downloading it he ran into some errors about ``pip`` and ``pip3`` not being recognized as commands. After a lot of reaserch [Adam Durrett](https://www.linkedin.com/in/adam-durrett-038892163) helped him find this line of code ``apt-get install python-setuptools``. After writing this, pip was installed and he was able to pull the Jetson GPIO library from the internet. The repository is also available [here](https://github.com/NVIDIA/jetson-gpio). After typing this he followed the rest of the workflow.
They went to the [python website](https://www.python.org/) to download version 3.8.6. After downloading it he ran into some errors about ``pip`` and ``pip3`` not being recognized as commands. After a lot of reaserch [Adam Durrett](https://www.linkedin.com/in/adam-durrett-038892163) helped him find this line of code ``apt-get install python-setuptools``. After writing this, pip was installed and he was able to pull the Jetson GPIO library from the internet. The repository is also available [here](https://github.com/NVIDIA/jetson-gpio). After typing this he followed the rest of the workflow.
He created a new directory then typed this command which allowed him to type code into
They created a new directory then typed this command which allowed him to type code into
```gedit gpiodemo.py```
He used the code below
They used the code below
```
......@@ -218,7 +228,7 @@ while True:
```
He looked at the pinout of for the GPIO's and connected the wires accordingly.
They looked at the pinout of for the GPIO's and connected the wires accordingly.
![image](../images/week09/JetsonNanoPinout.png)
......
......@@ -227,18 +227,178 @@ def convert(latitude, longitude):
print(convert(41.145556, 121.2322))
```
This code was AMAZING it was two simple inputs, the size of the map and the longitude and latitude. They tested the code by using the coordinates of (0,0) on a psudo 12 x 24 in map and the value came back with (6,12) whcih is exacly the middle of the map. This
**IMAGE OF CODE WORKING FOR LONG AND LAT SCREENSHOTS**
This code was AMAZING it was two simple inputs, the size of the map and the longitude and latitude. They tested the code by using the coordinates of (0,0) on a psudo 12 x 24 in map and the value came back with (6,12) whcih is exacly the middle of the map.
They the tried to use this code on the map that Aaron had made earlier and realized one thing, they didn't know whether the y value was from the top of the map or bottom of the map. They inputted a negative value for the latitude and received a value greater than half of the map size, meaing the y was in refernce to the top of the map.
They tried to test (0,0) on their map and realized that their was an offset. Because of the map Aaron had printed their was a 1.5 in offset for the y-value, even thought the map looked semetrical. After fixing this problem they were finished.
**IMAGE OF MARKER ON THE MAP**
![image](../images/ElonMuskImages/markedMap.jpg)
All marks made on the map are circled in red to make it more visible.
To make sure everything was working They both went to the Rasberry Pi 2 Model B, installed the libraries, and ran the code; it was successful.
## Final Code
Alaric put everything together in the final code and split it between 3 files.
### apiData.py
This had functions involving getting raw data from the api and converting it from latitude longitude to inches on the map.
```
import requests
import math
from numpy import log as ln
def get_lat_lon(callsign='N502SX'):
# uses the api to get the latitude and longitude and returns a list of 2 ints
url = 'https://adsbexchange-com1.p.rapidapi.com/v2/callsign/' + callsign + '/'
headers = {
"X-RapidAPI-Host": "adsbexchange-com1.p.rapidapi.com",
"X-RapidAPI-Key": "27d6e0192emsh0b0d9c0364793c1p175136jsn803c2abbbc60"
}
response = requests.get(url, headers=headers)
data = response.text
lat, lon = 0.0, 0.0
flying = False
for i in range(len(data)):
if data[i: i + 6] == '"lat":':
lenNum = 1
while data[i + lenNum] != ',':
lenNum += 1
lat = float(data[i + 6: i + lenNum])
flying = True
elif data[i: i + 6] == '"lon":':
lenNum = 1
while data[i + lenNum] != ',':
lenNum += 1
lon = float(data[i + 6: i + lenNum])
flying = True
return [lon, lat], flying
def lat_lon_to_xy(pos):
# Define the size of map
mapWidth = 584.2
mapHeight = 431.8
# get x value
x = (pos[0] + 180) * (mapWidth / 360)
# convert from degrees to radians
latRad = (pos[1] * math.pi) / 180
# get y value
mercN = ln(math.tan((math.pi / 4) + (latRad / 2)))
y = (mapHeight / 2) - (mapWidth * mercN / (2 * math.pi))
return [x, mapHeight-y] # mapHeight - y makes the origin point from the bottom left corner for the latitude
```
### stepper.py
This had a class for the stepper motor that used a combination of code from Alaric's outputs week (converted from arduino to python of course) and work from Aaron and Jada.
```
import RPi.GPIO as GPIO
from time import sleep
class Stepper():
def __init__(self, chan, delayTime):
self.chan = chan
self.delayTime = delayTime
self.phase = 0
def run_step(self):
if self.phase == 0:
GPIO.output(self.chan, (GPIO.HIGH, GPIO.LOW, GPIO.HIGH, GPIO.LOW))
elif self.phase == 1:
GPIO.output(self.chan, (GPIO.LOW, GPIO.HIGH, GPIO.HIGH, GPIO.LOW))
elif self.phase == 2:
GPIO.output(self.chan, (GPIO.LOW, GPIO.HIGH, GPIO.LOW, GPIO.HIGH))
elif self.phase == 3:
GPIO.output(self.chan, (GPIO.HIGH, GPIO.LOW, GPIO.LOW, GPIO.HIGH))
sleep(self.delayTime)
def step_cw(self, num_steps):
for i in range(num_steps):
self.phase = (self.phase + 1) % 4
self.run_step()
def step_ccw(self, num_steps):
for i in range(num_steps):
self.phase = (self.phase - 1) % 4
self.run_step()
def clear(self):
GPIO.output(self.chan, (GPIO.LOW, GPIO.LOW, GPIO.LOW, GPIO.LOW))
```
### main.py
This put everything together with keeping track of the gantry while taking data from the api and moving accordingly.
```
import apiData #hello
from stepper import Stepper
import math
from time import sleep
import RPi.GPIO as GPIO
__name__ = 'main'
if __name__ == 'main':
gear_diameter = 12
gear_cirumference = 12 * math.pi
step_dist = gear_cirumference / 200
GPIO.setmode(GPIO.BOARD)
motorx_chan = (29, 31, 33, 35)
motory_chan = (32, 36, 38, 40)
GPIO.setup(motorx_chan, GPIO.OUT)
GPIO.setup(motory_chan, GPIO.OUT)
stepperx = Stepper(motorx_chan, 0.005) # add pins and stuff later
steppery = Stepper(motory_chan, 0.005) # add pins and stuff later
callsign = input('Enter a callsign of a plane to track: ')
# steps from corner 9.42477796076938mm each direction to get to map 0
#stepperx.step_cw(50)
#steppery.step_cw(50)
pos = [0, 0]
while True:
latLon, flying = apiData.get_lat_lon(callsign)
print(latLon)
if not flying:
stepperx.clear()
steppery.clear()
sleep(60)
else:
new_pos = apiData.lat_lon_to_xy(latLon)
new_pos[1] -= 31.75
new_pos[1] %= 431.8
print(new_pos)
while new_pos[0] > pos[0]:
stepperx.step_cw(1)
pos[0] += step_dist
while new_pos[0] < pos[0]:
stepperx.step_ccw(1)
pos[0] -= step_dist
while new_pos[1] > pos[1]:
steppery.step_ccw(1)
pos[1] += step_dist
while new_pos[1] < pos[1]:
steppery.step_cw(1)
pos[1] -= step_dist
stepperx.clear()
steppery.clear()
sleep(60)
```
## 3D Design of Full Model
......@@ -295,6 +455,8 @@ Their was one problem that they noted, it was that one of the motors wasn't rota
Alaric designed this parametrically in [cuttle](cuttle.xyz), and the result can be found in the svgs in the files zip that can be downloaded at the top of the page. It was fairly simple with 4 holes in each of the four corners to have the vertical steel rods go into and a rectangle that would be pocketed out for the map to go into. The corners were rounded, and an offset between the outer edge and the edge of the map was made in accordance with other parts of the design. The pocket cut for the map was made slightly bigger than the map for 2 reasons. Firstly, we wanted the map to be able to be easily slid in. Secondly, we wanted to account for the round bit not cutting all the way into the corner and causing the map not to fit, but we thought using dogbones would not be aesthetically pleasing, so making the pocket bigger would solve the problem while keeping aesthetic elements.
![](../images/ElonMuskImages/base.jpg)
### CNC Machine
Then Jada and Aaron started the CNC cut. They loaded the wood onto the board and Jada screwed the wood in the four corners. First they had to do was change the bit to a .5in Bit. Their instructor [David Taylor](https://www.linkedin.com/in/david-c-taylor-phd-9b447a23?trk=people-guest_people_search-card) showed them how here:
......
......@@ -14,4 +14,63 @@ The third chained arudino worked:
<iframe width="560" height="315" src="https://www.youtube.com/embed/V0ARStuL5fs" title="YouTube video player" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>
Nick wrote the above documentation whilst the images and videos were uploaded by the people who took them.
\ No newline at end of file
Nick wrote the above documentation whilst the images and videos were uploaded by the people who took them.
## Group 2: Pari, Andrew, Aarush
This week [Pari](https://fabacademy.org/2022/labs/charlotte/students/parinaz-hathiram/assignments/week14/), [Andrew](https://fabacademy.org/2022/labs/charlotte/students/andrew-jiang/assignments/week13/), and [Aarush](https://fabacademy.org/2022/labs/charlotte/students/aarush-vemuganti/assignments/13.NetworkingAndCommunications/) worked together to network Arduino boards together using the I2C protocol. Prior to the networking they received a short lecture on I2C from a lab guru [Dr. Harris](https://www.linkedin.com/in/dradamcharris/).
![](../images/week15networking/I2Cexplanation.jpg)
Next they started with networking two arduinos, where they got some inspiration from this helpful [arduino tutorial](https://docs.arduino.cc/learn/communication/wire).
First they uploaded this peripheral sender code to their peripheral arduino.
```
// Wire Master Writer
#include <Wire.h>
void setup()
{
Wire.begin(); // join i2c bus (address optional for master)
}
void loop()
{
Wire.beginTransmission(8); // transmit to device #4
Wire.write("hello");
Wire.endTransmission(); // stop transmitting
delay(500);
}
```
Then they uploaded this controller reader code to the master arduino.
```
// Wire Controller Reader
#include <Wire.h>
void setup() {
Wire.begin(); // join i2c bus (address optional for master)
Serial.begin(9600); // start serial for output
}
void loop() {
Wire.requestFrom(8, 6); // request 6 bytes from peripheral device #8
while (Wire.available()) { // peripheral may send less than requested
char c = Wire.read(); // receive a byte as character
Serial.print(c); // print the character
}
delay(500);
}
```
After connecting the peripheral sender arduino to a 9V power supply, they found success. As you can see the message is sent from one arduino to the other using I2C.
<iframe width="560" height="315" src="https://www.youtube.com/embed/UroeutkH9rI" title="YouTube video player" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>
Next they moved on to the next hurdle, which was getting 3 arduinos networked with 1 master and 2 peripherals. Just like they had done with two arduinos, they connected another Arduino’s SDA and SCL pins with the rest of them, and also configured a common ground between the three. Here’s a photo of the wiring.
![](../images/week15networking/network3arduinowiring.jpg)
Using the same method as before but simply adding another peripheral sender, they found success with 3 arduinos. They had to keep in mind to use a different address for the third arduino so both I2C input data could be read at the same time
<iframe width="560" height="315" src="https://www.youtube.com/embed/OU7Fn22X6Hs" title="YouTube video player" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>
# 14. Inputs (CLS Students)
## Group 1 - Nick, Jack, Aaron
## Group 1 - Nick, Jack, Aaron,
The three all worked on measuring an analog input, whereas group 2 did digital input. With this in mind, they used Nick's soil moisture sensor. Nick wired the sensor up to an osiliscope based off a tutorial found by Aaron which can be found [here](https://www.youtube.com/watch?v=XfZPumtTUPA). Aaron helped set up the osiliscope as well as Jack and the two of them took the photos and videos.
......@@ -17,3 +17,10 @@ Nick wrote the above documentation whilst Aaron and Jack inserted their respecti
<iframe width="560" height="315" src="https://www.youtube.com/embed/HGoW8-2lNmg" title="YouTube video player" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>
Alaric interpreted the results of the readings noting that it was high most of the time due to the fact that i2c needs a pullup resistor. There would be flashes where the reading goes low which shows the line being pulled to low while sending information.
## Jada, Pari and Andrew
[Jada](https://fabacademy.org/2022/labs/charlotte/students/jada-greene/assignments/week13/), [Pari](https://fabacademy.org/2022/labs/charlotte/students/parinaz-hathiram/assignments/week11/), and [Andrew](https://fabacademy.org/2022/labs/charlotte/students/andrew-jiang/assignments/week12/), used Pari's Doppler Radar Sensor because we are also testing analog inputs. Jada helped wire the radar and connected the Doppler Radar using the the ground power and analog pins. Andrew helped set up the oscilloscope using [this](https://www.radartutorial.eu/22.messpraxis/mp05.en.html) site they found while researching the sensor. Then Pari read the value off from the oscilloscope. They all took pictures, videos, and notes on how the oscilloscope functioned and how it connected to the sensor. The three figured out how to use the oscilloscope to help read whether the sensor was detecting movement or not. This is the result Pari recorded:
<iframe width="560" height="315" src="https://www.youtube.com/embed/UHniJJIwFVI" title="YouTube video player" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>
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