In this lesson we show how to interact with the GPIO pins on the NVIDIA Jetson Nano. The GPIO pins on the Jetson Nano have very limited current capability, so you must learn to use a PN2222 BJT transistor in order to control things like LED or other components. In this lesson we show how the Jetson Nano can be used to control a standard LED.
Robotics Training LESSON 11: Controlling the Elegoo Smart Car With IR Remote
In this lesson we show how you can control a robot with an IR remote. We program the Elegoo Smart Car version 3.0 to respond to commands to the remote to go forward, backward, left and right.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 | #include <IRremote.h> int IRpin=12; IRrecv IR(IRpin); decode_results cmd; int ENA=5; int ENB=6; int IN1=7; int IN2=8; int IN3=9; int IN4=11; float d; int degRot=90; int left; int right; float v; void setup() { // put your setup code here, to run once: Serial.begin(9600); IR.enableIRIn(); IR.blink13(true); pinMode(ENA,OUTPUT); pinMode(ENB,OUTPUT); pinMode(IN1,OUTPUT); pinMode(IN2,OUTPUT); pinMode(IN3,OUTPUT); pinMode(IN4,OUTPUT); digitalWrite(ENA,HIGH); digitalWrite(ENB,HIGH); } void loop() { int wv; v=1.2; d=1; wv=(v-.35)/.0075; left=wv; right=wv; setSpeed(left,right); while (IR.decode(&cmd)==0){ } Serial.println(cmd.value,HEX); if (cmd.value==0xFF629D){ Serial.println("Forward"); forward(d,v); } if (cmd.value==0xFFA857){ Serial.println("Backward"); backward(d,v); } if (cmd.value==0xFFC23D){ Serial.println("Right"); turnRight(degRot,wv); } if (cmd.value==0xFF22DD){ Serial.println("Left"); turnLeft(degRot,wv); } IR.resume(); //calR(wv); //forward(8,v); //v=1.5; //wv=(v-.35)/.0075; //left=wv; //right=wv; //setSpeed(left,right); //backward(8,v); } void setSpeed(int leftVal,int rightVal){ analogWrite(ENA,leftVal); analogWrite(ENB,rightVal); } void forward(float d, float v){ float t; digitalWrite(IN1,HIGH); digitalWrite(IN2,LOW); digitalWrite(IN3,LOW); digitalWrite(IN4,HIGH); t=d/v*1000; delay(t); stopCar(); } void backward(float d, float v){ float t; digitalWrite(IN1,LOW); digitalWrite(IN2,HIGH); digitalWrite(IN3,HIGH); digitalWrite(IN4,LOW); t=d/v*1000; delay(t); stopCar(); } void turnRight(int deg, int wv){ float t; stopCar(); delay(100); analogWrite(ENA,125); analogWrite(ENB,125); digitalWrite(IN1,HIGH); digitalWrite(IN2,LOW); digitalWrite(IN3,HIGH); digitalWrite(IN4,LOW); t=(deg+6)/136.29*1000.; delay(t); stopCar(); analogWrite(ENA,wv); analogWrite(ENB,wv); } void turnLeft(int deg, int wv){ float t; analogWrite(ENA,125); analogWrite(ENB,125); digitalWrite(IN1,LOW); digitalWrite(IN2,HIGH); digitalWrite(IN3,LOW); digitalWrite(IN4,HIGH); t=(deg+6)/136.29*1000.; delay(t); stopCar(); analogWrite(ENA,wv); analogWrite(ENB,wv); } void stopCar(){ digitalWrite(IN1,LOW); digitalWrite(IN2,LOW); digitalWrite(IN3,LOW); digitalWrite(IN4,LOW); } void calF(){ digitalWrite(IN1,HIGH); digitalWrite(IN2,LOW); digitalWrite(IN3,LOW); digitalWrite(IN4,HIGH); delay(5000); stopCar(); } void calB(){ digitalWrite(IN1,LOW); digitalWrite(IN2,HIGH); digitalWrite(IN3,HIGH); digitalWrite(IN4,LOW); delay(5000); stopCar(); } void calR(int wv){ stopCar(); analogWrite(ENA,125); analogWrite(ENB,125); digitalWrite(IN1,HIGH); digitalWrite(IN2,LOW); digitalWrite(IN3,HIGH); digitalWrite(IN4,LOW); delay(3000); analogWrite(ENA,wv); analogWrite(ENB,wv); stopCar(); } void calL(int wv){ analogWrite(ENA,125); analogWrite(ENB,125); digitalWrite(IN1,LOW); digitalWrite(IN2,HIGH); digitalWrite(IN3,LOW); digitalWrite(IN4,HIGH); delay(5000); analogWrite(ENA,wv); analogWrite(ENB,wv); stopCar(); } |
Jetson Xavier NX Lesson 14: Face Recognition and Identification on NVIDIA Xavier NX
In this video lesson we show you how to train the NVIDIA Jetson Xavier NX to recognize faces, and then demonstrate finding those faces in a new unknown image. We show step by step instruction in this easy to follow tutorial. We develop two python programs. The first one simply finds the faces in an unknown image, and the second program actually identifies the known faces. For your convenience, the code is included below.
Simple face detection Python code:
1 2 3 4 5 6 7 8 9 10 11 12 13 | import face_recognition import cv2 print(cv2.__version__) image=face_recognition.load_image_file('/home/pjm/Desktop/pyPro/demoimages/unknown/u1.jpg') face_locations=face_recognition.face_locations(image) print(face_locations) image=cv2.cvtColor(image,cv2.COLOR_RGB2BGR) for (row1,col1,row2,col2) in face_locations: cv2.rectangle(image,(col1,row1),(col2,row2),(255,0,0),2) cv2.imshow('myWindow',image) cv2.moveWindow('myWindow',0,0) if cv2.waitKey(0)==ord('q'): cv2.destroyAllWindows() |
This next python program will learn faces, and then recognize them in new images.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 | import face_recognition import cv2 print(cv2.__version__) donFace=face_recognition.load_image_file('/home/pjm/Desktop/pyPro/demoimages/known/Donald Trump.jpg') nancyFace=face_recognition.load_image_file('/home/pjm/Desktop/pyPro/demoimages/known/Nancy Pelosi.jpg') mikeFace=face_recognition.load_image_file('/home/pjm/Desktop/pyPro/demoimages/known/Mike Pence.jpg') donEncode=face_recognition.face_encodings(donFace)[0] nancyEncode=face_recognition.face_encodings(nancyFace)[0] mikeEncode=face_recognition.face_encodings(mikeFace)[0] Encodings=[donEncode,nancyEncode,mikeEncode] Names=['Donald Trump','Nancy Pelosi','Mike Pence'] font=cv2.FONT_HERSHEY_SIMPLEX testImage=face_recognition.load_image_file('/home/pjm/Desktop/pyPro/demoimages/unknown/u11.jpg') facePositions=face_recognition.face_locations(testImage) allEncodings=face_recognition.face_encodings(testImage,facePositions) testImage=cv2.cvtColor(testImage,cv2.COLOR_RGB2BGR) for (top,right,bottom,left), face_encoding in zip(facePositions,allEncodings): name='Unknown Life Form' matches=face_recognition.compare_faces(Encodings,face_encoding) if True in matches: first_match_index=matches.index(True) name=Names[first_match_index] cv2.rectangle(testImage,(left,top),(right,bottom),(255,0,0),2) cv2.rectangle(testImage,(left,top),(left+200, top+30),(0,255,255),-1) cv2.putText(testImage,name,(left,top+20),font,.75,(255,0,0),2) cv2.imshow('myWindow',testImage) cv2.moveWindow('myWindow',0,0) if cv2.waitKey(0)==ord('q'): cv2.destroyAllWindows() |
Robotics Training LESSON 10: Using the Infrared (IR) Remote to Control Robot
In this lesson we show how to use the IR remote in the Elegoo Smart Car to send signals to the robot. The IR remote sends IR signals to the IR detector on the Electronic Shield sitting on top of the Smart Car. In this lesson we show how to install the IR library, and how to write code to send and detect IR signals. The code we develop in today’s lesson is included below for your convenience.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | #include <IRremote.h> int IRpin=12; IRrecv IR(IRpin); decode_results cmd; void setup() { // put your setup code here, to run once: Serial.begin(9600); IR.enableIRIn(); IR.blink13(true); } void loop() { // put your main code here, to run repeatedly: while (IR.decode(&cmd)==0) { } Serial.println(cmd.value,HEX); delay(500); IR.resume(); } |
Jetson Xavier NX Lesson 13: Installing Face Recognition and Identification Libraries
In this video lesson we show you how to install DLIB and face_recognition libraries on the NVIDIA Jetson Xavier NX. We take you through the installs step-by-step. This will be foundational libraries for future lessons on Face Recognition and Deep Learning.