User avatar
HermannSW
Posts: 1235
Joined: Fri Jul 22, 2016 9:09 pm
Location: Eberbach, Germany
Contact: Website Twitter YouTube

Cheap [Arduino] pan/tilt system for Raspberry camera

Thu Mar 09, 2017 10:27 am

In this posting I got good advice to be careful not to damage my Raspberry camera flex cable with alligator clips.

I remembered that I did a camera pan/tilt Arduino system last year. I looked into my youtube channel and found the last video on that from May 4 2016. Then I looked up my Arduino sketches for 2016 and found below one (20 lines), that worked without changes.

Since the dual-axis XY Joystick module gives analog input some kind of module would be required for my PiZeroW anyway, I decided to let the pan/tilt system as is Arduino based. I just had to connect Raspberry camera to the holder. This was not difficult, I just drilled two holes for small screws into the plastic with screwdrivers (click photos for details):
Image

The bill of material for pan/tilt is really cheap, 7.10$ with free shipping in total: This is the whole setup, PiZeroW powered over USB and HDMI monitor connected:
Image

So why connect HDMI monitor?
I mostly used my other PiZeros headless sofar, and do so with new PiZeroW as well. But recently HDMI monitor was connected when I used "raspistill" and I noticed that during taking the photo the image got displayed on HDMI monitor! I tried "raspivid" and the same happens with it. When taking videos it is really helpful to see what gets recorded, especially with pan/tilt system.

I did a slowmo 90fps 640x480 video and uploaded it to youtube:
https://www.youtube.com/watch?v=mNpxKN91BOQ

This is the unmodified "raspivid" video (30MB):
https://stamm-wilbrandt.de/en/forum/t.h264

Here you can see PiZeroW directly as well as on HDMI monitor:
Image

The recoreded brightness was lower than that of my HDMI monitor, so I increased brighness on recording to 65 in ssh session on PiZeroW:

Code: Select all

[email protected]:~ $ raspivid -o t.h264 -t 20000 -w 640 -h 480 -fps 90 -br 65
[email protected]:~ $ 
The 20sec video gets played in 1:11min on youtube, which is slowdown of 90/25=3.6. If you change speed to 0.25 under youtube settings you can view the slowmo 14.4 times slower than original.

Copying the recorded video wirelessly off the PiZeroW was quick:

Code: Select all

$ scp [email protected]:t.h264 .
[email protected]'s password: 
t.h264                                        100%   29MB   1.4MB/s   00:21    
$ 
Summary:
Cheap Arduino based pan/tilt system for Raspberry camera, but easy to setup and use.
Also a specific position can be programmed easily with just another Arduino sketch.
That will allow better positioning of Raspberry camera for "raspistill" photo taking than the aligator clips of "third hand" I used sofar.

Hermann.

Code: Select all

$ cat Arduino/2016/sketch_may04a/sketch_may04a.ino 
#include <Servo.h>

Servo myservo1, myservo2;

int potpin1 = 0, potpin2 = 1;
int val1,val2;

void setup() {
  myservo1.attach(9);
  myservo2.attach(8);
}

void loop() {
  val1 = map(analogRead(potpin1), 0, 1023, 0, 180);
  val2 = map(analogRead(potpin2), 0, 1023, 0, 180);
  myservo1.write(val1);
  myservo2.write(val2);
  delay(15);
}

$ 
bookmark list: https://stamm-wilbrandt.de/en/Raspberry_camera.html

https://github.com/Hermann-SW/Raspberry_v1_camera_global_external_shutter
https://github.com/Hermann-SW/fork-raspiraw
https://github.com/Hermann-SW/userland
https://twitter.com/HermannSW

User avatar
HermannSW
Posts: 1235
Joined: Fri Jul 22, 2016 9:09 pm
Location: Eberbach, Germany
Contact: Website Twitter YouTube

Re: Cheap [Arduino] pan/tilt system for Raspberry camera

Thu Mar 09, 2017 8:19 pm

Bill of material cost can be reduced by 2$ to 5$. A 1$ ATTiny85 can do what the Arduino Uno did:
https://forum.arduino.cc/index.php?topi ... msg3168143

Hermann.
Image
bookmark list: https://stamm-wilbrandt.de/en/Raspberry_camera.html

https://github.com/Hermann-SW/Raspberry_v1_camera_global_external_shutter
https://github.com/Hermann-SW/fork-raspiraw
https://github.com/Hermann-SW/userland
https://twitter.com/HermannSW

User avatar
HermannSW
Posts: 1235
Joined: Fri Jul 22, 2016 9:09 pm
Location: Eberbach, Germany
Contact: Website Twitter YouTube

Re: Cheap [Arduino] pan/tilt system for Raspberry camera

Sun Mar 12, 2017 6:43 pm

> Also a specific position can be programmed easily with just another Arduino sketch.
>
I did preprogram the complete movement of Arduino pan/tilt system and recorded with Pi camera at full HD resolution. This is the repeated movement pattern:

Code: Select all

                                       +   (y-20)°
                                       ^
                                       !
+ -----------------------------------> +   (y-10)°
^
!
+ <----------------------------------- +   y°
180°              90°                  0°
Despite HD resolution, fullscreen display of the recorded Pi camera video looks smooth:
https://www.youtube.com/watch?v=8U1Vp2Z ... e=youtu.be

Hermann.

The pan/tilt system was based on ATTiny85 this time:
https://forum.arduino.cc/index.php?topi ... msg3168143

Here is the complete ATTiny85 sketch:

Code: Select all

#include <SoftRcPulseOut.h> 
 
SoftRcPulseOut myservo1, myservo2;
#define NOW 1

void setup() {
  myservo1.attach(1);
  myservo2.attach(0);

  myservo1.write(110);
  myservo2.write(0);
  delay(20);
  SoftRcPulseOut::refresh(NOW);
  delay(500);
}

void loop() {
  int i,j,h;
  
  for(i=110; i>=50; ) {
    for(j=0; j<=180; j+=1) {
      myservo1.write(i);
      myservo2.write(j);
      delay(20);
      SoftRcPulseOut::refresh(NOW);
    }
    for(h=0; h<10; ++h) {
      --i;
      myservo1.write(i);
      myservo2.write(j);
      delay(20);
      SoftRcPulseOut::refresh(NOW);
    }
    for(180; j>=0; j-=1) {
      myservo1.write(i);
      myservo2.write(j);
      delay(20);
      SoftRcPulseOut::refresh(NOW);
    }
    for(h=0; h<10; ++h) {
      --i;
      myservo1.write(i);
      myservo2.write(j);
      delay(20);
      SoftRcPulseOut::refresh(NOW);
    }
  }
}
bookmark list: https://stamm-wilbrandt.de/en/Raspberry_camera.html

https://github.com/Hermann-SW/Raspberry_v1_camera_global_external_shutter
https://github.com/Hermann-SW/fork-raspiraw
https://github.com/Hermann-SW/userland
https://twitter.com/HermannSW

User avatar
HermannSW
Posts: 1235
Joined: Fri Jul 22, 2016 9:09 pm
Location: Eberbach, Germany
Contact: Website Twitter YouTube

Re: Cheap [Arduino] pan/tilt system for Raspberry camera

Sat Mar 25, 2017 8:44 pm

I moved the ATTiny85 pan/tilt system above my motor test station (MTS) and fixed Raspberry Pi Zero and pan/tilt system with screws:
Image

Then I moved the camera looking vertical and took a first 90fps slowmo of MTS.

Today I got my new Arduino controlled caterpillar robot platform under control, even fast pirouettes did work, and the robot remained nearly stationary.

I wanted to repeat that robot run inside MTS and take a slowmo of it. Unfortunately the central nail was too long and did nowhere fit below the robot. Removing the battery box lid produced the needed whole in the center of the robot for the nail (click for details):
Image

After fixing the cables in battery box with tape all was set for taking the slowmo:
https://www.youtube.com/watch?v=2GnCmNw ... e=youtu.be
Image

In the past I used infrared speed sensors for high speed (up to 17m/s, 61km/h, 38mph) tests in MTS. But the groove width sometimes was too low and complete destruction happend. Nice to have Raspberry camera now as 90fps (totally contactless) speedometer for MTS high speed runs.

Hermann.
bookmark list: https://stamm-wilbrandt.de/en/Raspberry_camera.html

https://github.com/Hermann-SW/Raspberry_v1_camera_global_external_shutter
https://github.com/Hermann-SW/fork-raspiraw
https://github.com/Hermann-SW/userland
https://twitter.com/HermannSW

Electron752
Posts: 142
Joined: Mon Mar 02, 2015 7:09 pm

Re: Cheap [Arduino] pan/tilt system for Raspberry camera

Sat Mar 25, 2017 10:03 pm

Just out of curiousity, why are using arduno? The RPI 0 can already do most of what you are looking some. That way you wouldn't need to have a second processor to program.

The RPI already has PWM for controlling servos and such. It has interrupt for measuring movements and such. And you could add a cheap A/D converter that's controlled through SPI or I2C.

User avatar
HermannSW
Posts: 1235
Joined: Fri Jul 22, 2016 9:09 pm
Location: Eberbach, Germany
Contact: Website Twitter YouTube

Re: Cheap [Arduino] pan/tilt system for Raspberry camera

Sat May 13, 2017 10:24 am

Hi,

I bought a 1$ PCF8591 A/D I2C bus module, but have not used it sofar.
The ATTiny85 does cost 1$ as well, and is a complete microcontroller.
So you can do it either way, and have 5$ in total pan/tilt system for the Raspberry camera.

Hermann.

P.S: I use a tilt only system on my caterpillar robot platform (the upper part of above).
There the motor controlling as well as camera tilting is done by an Arduino (see animated .gif below),
which triggers raspivid movie creation on Pi 0 as well.
I use an Arduino there because the Pi 0 will be quite busy taking 640x480 @90fps video and running a gstreamer processing pipeline for frame-wise feature extraction and feeding back reduced information for Arduino PID motor control
https://forum.arduino.cc/index.php?topi ... msg3236016
Image
bookmark list: https://stamm-wilbrandt.de/en/Raspberry_camera.html

https://github.com/Hermann-SW/Raspberry_v1_camera_global_external_shutter
https://github.com/Hermann-SW/fork-raspiraw
https://github.com/Hermann-SW/userland
https://twitter.com/HermannSW

Return to “General discussion”