my take on an laser range finder with an arduino

The Dot Matrix Display (DMD) is a 32x16 array of high-brightness LEDs for visually striking effects. [Product Page]
Post Reply
coromonadalix
Posts:26
Joined:Wed Apr 09, 2014 9:03 pm
my take on an laser range finder with an arduino

Post by coromonadalix » Fri Aug 29, 2014 12:54 am

taken from : http://y6-multicopter.blogspot.ru/2014/ ... -post.html
and mostly the :
http://blog.qartis.com/parsing-laser-di ... 1053946662

I have compiled / adapted the following code :

It is working with both lcd 16x2 and dmd panels, i have renamed a dmd library made for an mega (using the sames pins as an duemilanove) to DMDmega, the serial terminal is working ok : Dist: 0.240m is showing on the 2 displays and the serial terminal.

My problem is : i whant to send the : Serial1.write("*11114#") to the laser to make it take 1 measurement per seconds maybe 10 times and stop, triggered by an external switch and stop.

But now
Once the laser is powered up, it take between 3 measurements to 7 meas... and stop.
The laser will power down after a determined time.

I have tried the first link code, and it works very well, but in the serial terminal it is shown as hexadecimal format (0 6 40 0 0 2 40 88) gives 0.242m, the 0 6 40 0 0 seem to be an header, the 88 is the check-sum value of the others digits, but the 1 meas a second is okay.

Ultimately my goal is : the arduino mega would power on the laser, take 10 meas, and stop, powerdown the laser and wait until the switch is pressed again. After that remove all lcd calls and functions just to show it on 4 dmd's.

Can some one tell me where i made a mistake ? for re-sending back the *11114# i can't put my finger on it, why it works a few times and stop dead. thanks

Code: Select all

#include <LiquidCrystal.h>
//RS = d12, RW = ground, EN = d10, data4 on d5, data5 on d4, data6 on d3, data7 on d2
LiquidCrystal lcd(12, 10, 5, 4, 3, 2);

#include "SPI.h"      
#include "DMDmega.h" 
#include "TimerOne.h"
//#include "Arial_black_16.h"<arial_black_16.h> 
#include "SystemFont5x7.h"
#define DISPLAYS_ACROSS 4   
#define DISPLAYS_DOWN 1       
DMD dmd(DISPLAYS_ACROSS,DISPLAYS_DOWN);

void ScanDMD()
{
dmd.scanDisplayBySPI();
}

int strstart_P(const char *s1, const char * PROGMEM s2)
	{
	    return strncmp_P(s1, s2, strlen_P(s2)) == 0;
	}
	 
	int getdist(void)
	{
	    char buf[64];
	    char *comma;
	    int dist;
	    int rc;
	 
	    for (;;) {
	        rc = Serial1.readBytesUntil('\n', buf, sizeof(buf));
	        buf[rc] = '\0';
	 
	        if (!strstart_P(buf, PSTR("Dist: ")))
	            continue;
	 
	        comma = strchr(buf, ',');
	        if (comma == NULL)
	            continue;
	 
	        *comma = '\0';
	 
	        dist = atoi(buf + strlen_P(PSTR("Dist: ")));
	        return dist;
	}
	}
	 
	void setup()
{
  
         // setup DMD refreshing
         Timer1.initialize( 5000 );           
         Timer1.attachInterrupt( ScanDMD );   
         dmd.clearScreen( true );             
         dmd.selectFont(System5x7);
       
         lcd.begin(16, 2);
         lcd.clear();
         Serial.begin(115200);	    
         Serial1.begin(115200);
	}
	 	
        void loop()
        {
                   
if (Serial1.available() > 0)
{     
Serial1.write("*11114#");  to make a 1 shot measurement       

    int dist_mm;
    int dist_m;
	    char buf[64];
	 
    dist_mm = getdist();
	    dist_m = dist_mm / 1000;
	 
	    snprintf_P(buf, sizeof(buf),
	    PSTR("Dist: %d.%dm"),
	    dist_m, dist_mm % 1000);
	 
    Serial.println(buf);

            dmd.clearScreen( true );
            dmd.drawString(3,4, buf , 12, GRAPHICS_NORMAL );
            
            lcd.clear();
            lcd.write(buf);
  
         
    Serial1.write("*11114#"); // to make a 1 shot measurement 


}
}

angusgr
Freetronics Staff
Freetronics Staff
Posts:853
Joined:Tue Apr 09, 2013 11:19 pm
Location:Melbourne, Australia
Contact:

Re: my take on an laser range finder with an arduino

Post by angusgr » Fri Aug 29, 2014 4:20 am

Hi coromonadalix,

I edited your post and put

Code: Select all

 tags around the sketch so it's easier to read.

Unfortunately I'm not familiar with that sensor so I don't have any suggestions to make.


Angus

coromonadalix
Posts:26
Joined:Wed Apr 09, 2014 9:03 pm

Re: my take on an laser range finder with an arduino

Post by coromonadalix » Sun Aug 31, 2014 2:54 pm

it seems one of my problems is timerone, if i remove all instance of the dmd and timerone and output it to an lcd, the laser does its job very well and continously.

Is there a substitute for timerone ??

Or to build an rs232 to dmd interface / receiver card, who could accept standard ascii characters ... this way i could get rid of the timerone problems in the first (sender) arduino, take mesures etc ... send them to the second one (receiver) and have a display of it.


i am checking for a few hints in the forums ....

User avatar
stryker
Posts:282
Joined:Sat Jan 14, 2012 2:44 pm

Re: my take on an laser range finder with an arduino

Post by stryker » Mon Sep 01, 2014 12:08 am

coromonadalix wrote: Is there a substitute for timerone ??

Or to build an rs232 to dmd interface / receiver card, who could accept standard ascii characters ... this way i could get rid of the timerone problems in the first (sender) arduino, take mesures etc ... send them to the second one (receiver) and have a display of it.
.
I'd think you're on the right track with using a different microcontroller to do the timing, to the one servicing the DMD. I'd expect having the microcontroller distracted every few microseconds isn't ideal with the rest of your work. You can do this with two wires between RX/TX pairs on your Arduinos without having to go to the effort of RS232. If there's a distance involved, even using a one way wireless connection will be a lower complexity.

Cheers!
Geoff

coromonadalix
Posts:26
Joined:Wed Apr 09, 2014 9:03 pm

Re: my take on an laser range finder with an arduino

Post by coromonadalix » Mon Sep 01, 2014 2:58 am

i have seen on this forum a near similar project, but it has a few bugs that i dont understand

see : viewtopic.php?f=26&t=5685


thanks

coromonadalix
Posts:26
Joined:Wed Apr 09, 2014 9:03 pm

Re: my take on an laser range finder with an arduino

Post by coromonadalix » Thu Sep 04, 2014 11:02 am

is there a substitute library fonction for Timer One ??

Post Reply