Tag Archives: Servo

Jetson Xavier NX Lesson 8: Controlling Dual Pan/Tilt Raspberry Pi Cameras


In this lesson we show how to independently control two Raspberry Pi Cameras using servo controlled pan/tilt brackets. This work will serve as the foundation for allowing us to create cameras that scan a room and locate objects of interest.

In this lesson, I am using two pan/tilt camera mounts. You can get the gear I am using on amazon HERE. I suggest purchasing two units.

Then, we also need two Version two raspberry pi cameras. I like the following ones, because they include a neat little acrylic case, and the long cable, which makes it work much better on the pan/tilt bracket. You can get the cameras HERE.

If you do not have a Jetson Xavier NX yet, you can pick up the gear I am using below:

  1. First, you will need the Jetson Xavier NX, which you can get HERE:
  2. You will want a quality, large SD card, I have very good luck with this one HERE:
  3. You will need a camera. I have found that the Jetson Xavier NX works very well with most Logitech Webcams, but these cameras are a little hard to find right now. I suggest the best option if you do not have a logitech webcam is to get the Raspberry Pi Version 2 camera, which works very well. You can pick the camera up HERE.
  4. It is optional, but I have found that it is nice to have an extra, longer cable for the Raspberry Pi camera, which is available HERE. Also, a small case/stand for the camera is nice and you can get the one I use HERE.
  5. The Jetson Nano has a slot for a SSD drive. I really like having the SSD drive attached, and makes it much easier to keep your work backed up. The projects in these lessons will work fine with just the SD card, but if you like, the SSD drive makes life easier (note even with SSD drive, you will still need the SD card above). You can get the SSD drive I am using HERE.
  6. You can use USB keyboard and mouse, but I like to preserve my USB slots for other things, so like using a wireless keyboard and mouse. This is optional, but I have found these work well on the Jetson Xavier NX, and you can get what I am using HERE.
  7. You will need an HDMI cable and monitor, which you probably already have.

 

Jetson Xavier NX Lesson 7: Connecting and Controlling Servos

In this lesson we show you how to control a pan/tilt camera bracket with the NVIDIA Jetson Xavier NX. We go through the physical build of the bracket, how to connect the circuit, and then how to program the servos. We use the Adafruit circuitpython library, and show how to download and use the library. If you want to play along at home, you can pick the pan/tilt bracket and servos up HERE, and you can grab a couple of Raspberry Pi cameras HERE.

Below is the simple code for moving the servo using the Jetson Xavier NX:

 

Arduino Tutorial 31: Using Servo in a Simple Project

In this lesson we demonstrate a simple project that reads the brightness in a room, and then displays the brightness on a device consisting of a servo with an arrow pointing at vaiouse visual indications of brightness. This project demonstrates how to use Algebra and the equation of a line to take the data read from the light sensor, and calculate the desired angle value to send to the servo.

If you want to follow along at home, you can order the Arduino Kit we are using HERE.

Typically, the servos in electronics kits are not the best ones, but are suitable to learn with. If you want a more stable and better quality servo, this is the one I user in more of my projects: HiTEC

Arduino Tutorial 30: Understanding and Using Servos in Projects

In this lesson we explain step-by-step how to incorporate a servo into your Arduino project. This allows you to put motion into your prototypes. Servos act like little motors to create motion, but unlike motors, they do not spin all the way around. A typical servo can move between 0 and 180 degrees. They are relatively easy to program, and this video shows you the ins and outs of using a servo.

If you want to follow along at home, you can order the Arduino Kit we are using HERE.

Typically, the servos in electronics kits are not the best ones, but are suitable to learn with. If you want a more stable and better quality servo, this is the one I user in more of my projects: HiTEC

Beaglebone Black LESSON 12: Control a Servo from Python Using PWM

This lesson will show how to use Python running on the Beaglebone Black to control the position of a servo. First, I am using a small servo that I have verified can be powered from the Beaglebone Black without drawing too much current. All servos are different, so if you are unsure of the current requirements of your servo, it is safest to power it from an external 5 Volt power source. You can still control it through the control line connected to the Beaglebone Black, just make sure the servo and Beaglebone have a common ground.

Control of Servo From Beaglebone Black.

Most all servos have three wires; Power, Control, and Ground. For my servo, Control is Yellow, Power is Red, and Ground is Black. If you have a different servo, check the data sheet to see what colors are Control, Power and Ground on your servo. Note we are using pin P9_2 as ground, P9_7 as 5V power, and P9_14 as our control pin.

We will be controlling the position of the servo using PWM. We will have to play around with our individual servo to determine precisely what signal pulse width will result in the servo being in the full left position, and what pulse width will result in the servo being in the full right position.

For most servos, full left is somewhere around 1 milliseconds, and the pulse width that will give us full right position is about 2 milliseconds. These are ballpark numbers, and we will have to play around with things to find the exact values for our servo.

We will set up a 50 Hz PWM signal. A 50 Hz signal has a period of:

period = 1/frequency = .02 seconds = 20 miliseconds.

Hence, if we want to get to about the full left position we would want a duty cycle of about 5%. Because 20 milliseconds x .05 = 1 milliseconds. This one millisecond pulse width should put the servo about in the full left position. Similarly for the full right position, we would want a duty cycle of 10%, because that would give us a pulse width of 2 milliseconds, since:

PulseWidth = Period x DutyCycle

PulseWidth = 20 x .1 = 2 milliseconds.

We can use the following code to determine precisely for our servo what dutyCycle will give the precise full left and full right positions.

For my servo, running a 50 Hz PWM singnal, I find that a duty cycle of 2% puts it in the full left position and a duty cycle of 12% puts it in the full right position.

Now we would like to be able to just specify an angle we want and have it go to that angle. If we want an angle of 0 degrees we would apply a 2% duty cycle. This value is for my servo. You will have to play around with your servo and the code above to find what this number is for you. But for me, I have the point:

(0,2)

That is to say when I desire an angle of 0 on the servo, I should apply a dutyCycle of 2 to the PWM pin. Similarly, when I desire 180 degrees, I should apply a dutyCycle of 12. (Again, this number might vary for your servo). For my servo, I get the point:

(180, 12)

We can fit a line to these points, which would then allow us to calculate the dutyCycle for any desired angle. The slope from the two points above would be:

m=(y2-y1)/(x2-x1)=(12-2)/(180-0) = 10/180= 1/18

Using the point slope form of the line, we would get

y-y1 = m (x- x1)

y – 2 = 1/18( x – 0)

y= 1/18*x + 2

Now putting in our actual variable names we get:

dutyCycle = 1/18*desiredAngle + 2

You can develop the same type equation just using the values suitable for your servo from the experiment above.

Now we can use this code to smoothly move the servo to any desired position.