Advanced search FAQ Register Login

It is currently Wed Jan 24, 2018 2:43 am

 

Postby bowen73 » Fri Jan 13, 2017 4:30 pm

Hi, im trying to follow a project from https://www.modmypi.com/blog/motion-triggered-video-recording

in that project it says about using a PIR on pin 7. i dont have a pir so im using a laser instead, so when the laser is triggers it sends a signal to pin7 but its not starting the camera up. do i need to do something else to get this to work?

thanks

Code: Select all

#include <time.h>
#include <errno.h>
#include <stdio.h>
#include <signal.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <wiringPi.h>

struct tm tmdatim; time_t now;
char buf1[21], buf2[21], tstr[127];
int err = 0, pin = 7; FILE *logFile = NULL;
volatile sig_atomic_t done = 0; volatile int inInt = 0;

void pinInt(void) { ++inInt; }
void sigterm(int signum) { done = 1; }

void dateTime(void) {
   now = time(0); tmdatim = *localtime(&now);
   strftime(buf1, sizeof(buf1), "%d-%m-%Y.%H%M%S", &tmdatim);
}
void fileLog(char *str) {
   dateTime(); fprintf(logFile, "%s - %s\n", buf1, str); fflush(logFile);
}
int Err(char* str) {
   err = errno; sprintf(tstr, "%s", str);
   if (errno) { sprintf(tstr, "Error: %s. Msg: %s", str, strerror(errno)); }
   fileLog(tstr); errno = 0; return err;
}
int main(void) {
   struct sigaction sigact; memset(&sigact, 0, sizeof(struct sigaction));
   sigact.sa_handler = sigterm; sigaction(SIGTERM, &sigact, NULL); errno = 0;

   logFile = fopen("/var/log/camera.log", "a");
   if (!Err("Opening /var/log/camera.log")) { wiringPiSetup();
      if (!Err("Initialising wiringPiLib")) { wiringPiISR(pin, INT_EDGE_RISING, &pinInt);
         if (!Err("Setting wiringPiIntSR")) {
            while (!done) {
               if (inInt) {
                  dateTime(); sprintf(buf2, "%s", buf1);
                  sprintf(tstr, "raspivid -o /home/pi/Videos/vid.%s.h264 -t 30000 -fps 25 -hf > /dev/null", buf2);
                  fileLog("Recording 15 second video..."); system(tstr);
                  sprintf(tstr, "MP4Box -fps 25 -add /home/pi/Videos/top.%s.h264 /home/pi/Videos/top.%s.mp4 > /dev/null", buf2, buf2);
                  fileLog("Converting video to MP4....."); system(tstr);
                  sprintf(tstr, "sudo rsync -ravP --compress --remove-source-files /home/pi/Videos/top.%s.mp4 /media/top_cam/top.%s.mp4 > /dev/null", buf2, buf2);
                  fileLog("Copying video to server....."); system(tstr);
                  inInt = 0; sleep(13);
               }
               else sleep(3);
            }
            fileLog("Stopping Program...");
         }
      }
   }
   if (logFile) { fclose(logFile); } return errno;
}

bowen73
n00b

Posts: 8

Joined: Fri Jan 13, 2017 4:21 pm

Postby Dave » Fri Jan 13, 2017 5:13 pm

Do you have any details on the laser you are using?

Looking at your script I see you have edited this line:

Code: Select all

sprintf(tstr, "rsync -az /vids/vid.%s.mp4 server:/srv/vids/vid.%s.mp4 > /dev/null", buf2, buf2);


and changed it to:

Code: Select all

sprintf(tstr, "sudo rsync -ravP --compress --remove-source-files /home/pi/Videos/top.%s.mp4 /media/top_cam/top.%s.mp4 > /dev/null", buf2, buf2);


Have you tried it with the original line of code (with the directory and file name changes)?

so something like this:

Code: Select all

sprintf(tstr, "rsync -az /home/pi/Videos/top.%s.mp4 /media/top_cam/top.%s.mp4 > /dev/null", buf2, buf2);

Dave
ModMyPi

User avatar

Posts: 2085

Joined: Wed Jul 22, 2015 11:36 am

Forum Administrator & Technical Support

Postby bowen73 » Fri Jan 13, 2017 7:39 pm

The rsync code works on its own as i was testing transferring files over the network to a windows pc so im pretty certain its not that.

When i tested it without a breadboard the camera did seam to trigger and come on but dont know if i hit other pins with the cable when doing a quick test (stupid i know didnt have a breadboard to hand) but when i was breaking the beam sometimes it triggered sometimes it didnt but wasnt sure if its because i wasnt holding the cable on the pin steady.

ive now fixed it to the pin so there is no way i can move it but now it wont trigger the camera.

not sure if this is the correct model as i dont have it with me now until monday, but this is the pretty much what i have https://www.sick.com/de/en/product-portfolio/photoelectric-sensors/photoelectric-sensors/w12-3/c/g203237

it has 4 wires. pos, neg, test and signal. you can change the sensor to signal on break or stop signal on break, ive tried it both ways but nothing (unless i have a dodgey laser of course)

bowen73
n00b

Posts: 8

Joined: Fri Jan 13, 2017 4:21 pm

Postby Dave » Mon Jan 16, 2017 10:59 am

bowen73 wrote:The rsync code works on its own as i was testing transferring files over the network to a windows pc so im pretty certain its not that.

When i tested it without a breadboard the camera did seam to trigger and come on but dont know if i hit other pins with the cable when doing a quick test (stupid i know didnt have a breadboard to hand) but when i was breaking the beam sometimes it triggered sometimes it didnt but wasnt sure if its because i wasnt holding the cable on the pin steady.

ive now fixed it to the pin so there is no way i can move it but now it wont trigger the camera.

not sure if this is the correct model as i dont have it with me now until monday, but this is the pretty much what i have https://www.sick.com/de/en/product-portfolio/photoelectric-sensors/photoelectric-sensors/w12-3/c/g203237

it has 4 wires. pos, neg, test and signal. you can change the sensor to signal on break or stop signal on break, ive tried it both ways but nothing (unless i have a dodgey laser of course)


Ok best bet is to get a volt meter and test the voltage of the signal from the laser. If its any more than 3.3V then you will have to make a little voltage divider as the Pi's GPIO will not handle anything more.

Dave
ModMyPi

User avatar

Posts: 2085

Joined: Wed Jul 22, 2015 11:36 am

Forum Administrator & Technical Support

Postby bowen73 » Mon Jan 16, 2017 12:04 pm

Dave wrote:Do you have any details on the laser you are using?

Looking at your script I see you have edited this line:

Code: Select all

sprintf(tstr, "rsync -az /vids/vid.%s.mp4 server:/srv/vids/vid.%s.mp4 > /dev/null", buf2, buf2);


and changed it to:

Code: Select all

sprintf(tstr, "sudo rsync -ravP --compress --remove-source-files /home/pi/Videos/top.%s.mp4 /media/top_cam/top.%s.mp4 > /dev/null", buf2, buf2);


Have you tried it with the original line of code (with the directory and file name changes)?

so something like this:

Code: Select all

sprintf(tstr, "rsync -az /home/pi/Videos/top.%s.mp4 /media/top_cam/top.%s.mp4 > /dev/null", buf2, buf2);


i changed the code... like a dumbass newbie the code running direct via terminal worked but didnt when running via the script. now i have the video running but its starting on its own without the laser being broken, about 18secs after the last video stopped.

now i'm back in the office, the laser is a sick WL24-2b430 according to their website the output is 'Output current Imax. ≤ 100 mA'
https://www.sick.com/de/en/photoelectric-sensors/photoelectric-sensors/w24-2/wl24-2b430/p/p231902

bowen73
n00b

Posts: 8

Joined: Fri Jan 13, 2017 4:21 pm

Postby bowen73 » Mon Jan 16, 2017 1:10 pm

also, how can i add in a delete to remove the h264 file once its been converted? i can remove the mp4 with rsync when its transfered it but cannot figure out how to add in the code to remove the h264 files too.

thanks

bowen73
n00b

Posts: 8

Joined: Fri Jan 13, 2017 4:21 pm

Postby Dave » Mon Jan 16, 2017 3:19 pm

bowen73 wrote:also, how can i add in a delete to remove the h264 file once its been converted? i can remove the mp4 with rsync when its transfered it but cannot figure out how to add in the code to remove the h264 files too.

thanks


This is untested but should work:

Code: Select all

sprintf(tstr, "sudo rm /home/pi/Videos/top.%s.h264", buf2);
fileLog("Removing h264 file.....");
system(tstr);

Dave
ModMyPi

User avatar

Posts: 2085

Joined: Wed Jul 22, 2015 11:36 am

Forum Administrator & Technical Support

Postby Dave » Mon Jan 16, 2017 3:25 pm

bowen73 wrote:i changed the code... like a dumbass newbie the code running direct via terminal worked but didnt when running via the script. now i have the video running but its starting on its own without the laser being broken, about 18secs after the last video stopped.

now i'm back in the office, the laser is a sick WL24-2b430 according to their website the output is 'Output current Imax. ≤ 100 mA'
https://www.sick.com/de/en/photoelectric-sensors/photoelectric-sensors/w24-2/wl24-2b430/p/p231902


Hmm, it doesn't mention anything about the signal voltage, I wonder if its the same as the supply voltage. If that's the case this will damage your Pi if you are plugging the signal line directly into the Pi's GPIO. Also, you definitely want to include a resistor in the circuit to make sure you dont draw too much current

Never demand that any output pin source or sink more than 16 mA

source: http://www.mosaic-industries.com/embedd ... ifications

Dave
ModMyPi

User avatar

Posts: 2085

Joined: Wed Jul 22, 2015 11:36 am

Forum Administrator & Technical Support

Postby bowen73 » Mon Jan 16, 2017 3:30 pm

Dave wrote:
bowen73 wrote:also, how can i add in a delete to remove the h264 file once its been converted? i can remove the mp4 with rsync when its transfered it but cannot figure out how to add in the code to remove the h264 files too.

thanks


This is untested but should work:

Code: Select all

sprintf(tstr, "sudo rm /home/pi/Videos/top.%s.h264", buf2);
fileLog("Removing h264 file.....");
system(tstr);


thats perfect, thank you. I managed to setup a cron running every5 mins but this is far cleaner :-)

I just need to try figure out why its triggering on its own now instead of when the laser is broken, thats the only thing thats causing me an issue now. Ive tried all switches on the laser in different permutations but still the same result :-s

bowen73
n00b

Posts: 8

Joined: Fri Jan 13, 2017 4:21 pm

Postby bowen73 » Tue Jan 17, 2017 5:11 pm

ok, getting a little closer...

the laser triggeris giving out .06v according to the tester, so thats why it appears to be triggering constantly. when it triggers it sends a 12v signal.

so what wouldbe the next step?? i was thinking a 12v relay so it wont allow it to pass the .06v as a non triggered current the maybe a resistor to set it down to 5v from 12v once the relay has triggered??

any idea which relay/resistor i would need?

bowen73
n00b

Posts: 8

Joined: Fri Jan 13, 2017 4:21 pm

Next

Who is online

Users browsing this forum: No registered users and 1 guest

Board index

The teamDelete all board cookies • All times are UTC [ DST ]