DMD with an sr04 ping sensor

The Dot Matrix Display (DMD) is a 32x16 array of high-brightness LEDs for visually striking effects. [Product Page]
coromonadalix
Posts:26
Joined:Wed Apr 09, 2014 9:03 pm
DMD with an sr04 ping sensor

Post by coromonadalix » Wed Apr 09, 2014 9:18 pm

hello
I am a newbiee
I am trying to mix a dmd library with an sr04 sensor to have a big distance meter display.

i cant figure how to mix those two libraries. Since the sr04 libray is working fine on an lcd and the serial terminal.

here`s the sr04 pde, it will be shown on a 16x64 pixels (2 DMD panels)

i have tested the setup wit a few DMD examples in the forums, it works very well,

In red i have to remove it beceause of the DMD display, Mostly i need Inches measurements. or maybe an flash text between the cm and inch measurement once finished.

Maybe add an trigger event like a switch to start the measurement process.

thanks a lot

--------------------------------------------------------------------------------------------

#include <LiquidCrystal.h> // include LiquidCrystal library
LiquidCrystal lcd(8, 9, 4, 5, 6, 7); // modified to fit cheaphousetek LcdKeypad Shield

// this constant won't change. It's the pin number
// of the sensor's input and output:
const int triggerPin = 2;
const int echoPin = 3;

void setup()
{
// initialize serial communication. We are going to watch our progress in the monitor
Serial.begin(9600);
lcd.begin(16, 2);
// lcd.clear();
lcd.print("testing...");
}

void loop()
{
// establish variables for duration of the ping,
// and the distance result in inches and centimeters:
long duration, inches, cm;

// The device is triggered by a HIGH pulse of 2 or more microseconds.
// Give a short LOW pulse beforehand to ensure a clean HIGH pulse:
pinMode(triggerPin, OUTPUT);
digitalWrite(triggerPin, LOW);
delayMicroseconds(2);
digitalWrite(triggerPin, HIGH);
delayMicroseconds(5);
digitalWrite(triggerPin, LOW);

// The echo pin is used to read the signal from the device: a HIGH
// pulse whose duration is the time (in microseconds) from the sending
// of the ping to the reception of its echo off of an object.
pinMode(echoPin, INPUT);
duration = pulseIn(echoPin, HIGH);

// convert the time into a distance
inches = microsecondsToInches(duration);
cm = microsecondsToCentimeters(duration);

Serial.print(inches);
Serial.print(" po, ");
Serial.print(cm);
Serial.print(" cm");
Serial.println();

lcd.clear();
lcd.setCursor(0, 0);
lcd.print(inches);
lcd.print(" po, ");
lcd.print(cm);
lcd.print(" cm");


delay(1000);
}

long microsecondsToInches(long microseconds)
{
// *** THIS NEEDS TO BE CHECKED FOR THE HC-SR04 ***
return microseconds / 74 / 2;
}

long microsecondsToCentimeters(long microseconds)
{
// *** THIS NEEDS TO BE CHECKED FOR THE HC-SR04 ***
return microseconds / 29 / 2;
}

andrew
Freetronics Staff
Freetronics Staff
Posts:978
Joined:Sun Jul 14, 2013 7:06 am
Location:Melbourne, Australia
Contact:

Re: DMD with an sr04 ping sensor

Post by andrew » Wed Apr 09, 2014 10:01 pm

Could you please clarify things a little? For example - does the distance sensor not work when you're using a DMD? Or can't you display the readings from the sensor on the DMD?

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

Re: DMD with an sr04 ping sensor

Post by coromonadalix » Wed Apr 09, 2014 10:48 pm

hello

The DMD is working fine with an example found on this forum (scrolling text for bus arrival)
The ping sensor sr04 is working with the displayed post, but i whant to use a DMD as a display instead of an lcd. i understand the basics of dmd you can have in one row or in a coloumn, and the lines you change for that, the spi speed and a few things, but i have some dificulties to understand the displayed text positioning and a few functions in the dmd librairies.

Basicly declaring the dmd as a huge display

thanks

andrew
Freetronics Staff
Freetronics Staff
Posts:978
Joined:Sun Jul 14, 2013 7:06 am
Location:Melbourne, Australia
Contact:

Re: DMD with an sr04 ping sensor

Post by andrew » Thu Apr 10, 2014 4:30 am

coromonadalix wrote:hello

The DMD is working fine with an example found on this forum (scrolling text for bus arrival)
The ping sensor sr04 is working with the displayed post, but i whant to use a DMD as a display instead of an lcd. i understand the basics of dmd you can have in one row or in a coloumn, and the lines you change for that, the spi speed and a few things, but i have some dificulties to understand the displayed text positioning and a few functions in the dmd librairies.

Basicly declaring the dmd as a huge display

thanks
We have the DMD guide here which shows how to display text in different sizes and so on:
http://www.freetronics.com/pages/using- ... ronics-dmd

The only thing is that you can't display numbers straight to a DMD, they need to be converted to a String first - which can then be displayed.
http://arduino.cc/en/Reference/StringObject

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

Re: DMD with an sr04 ping sensor

Post by coromonadalix » Thu Apr 10, 2014 2:26 pm

thanks i understand a little bit better but compiling this code give me an error

the dmd.clearScreen( true ); gave this error : error: expected constructor, destructor, or type conversion before '.' token

i can`t figure out where to paste the sr04 readed value for the DMD panel ?
while trying to output it to the serial terminal at the same time.
i have a duemilanove. May use a mega if i dont have enough memory or speed ...

----------------------------------------------------------------------------------------------------------------

const int triggerPin = 2; // was pin 12 defore the DMD
const int echoPin = 3; // was pin13 before the DMD


#include <SPI.h>
#include <DMD.h>
#include <TimerOne.h>
#include "SystemFont5x7.h"
#include "Arial_black_16.h"

#define DISPLAYS_ACROSS 2 // i whant to display it on 16x64 pixels
#define DISPLAYS_DOWN 1
DMD dmd(DISPLAYS_ACROSS, DISPLAYS_DOWN);

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


void setup()
{

// initialize serial communication for the terminal windows.
Serial.begin(9600);

Timer1.initialize( 5000 );
Timer1.attachInterrupt( ScanDMD );
dmd.clearScreen( true );

}

void loop()
{
// establish variables for duration of the ping,
// and the distance result in inches and centimeters:
long duration, inches, cm;

// The device is triggered by a HIGH pulse of 2 or more microseconds.
// Give a short LOW pulse beforehand to ensure a clean HIGH pulse:
pinMode(triggerPin, OUTPUT);
digitalWrite(triggerPin, LOW);
delayMicroseconds(2);
digitalWrite(triggerPin, HIGH);
delayMicroseconds(5);
digitalWrite(triggerPin, LOW);

// The echo pin is used to read the signal from the device: a HIGH
// pulse whose duration is the time (in microseconds) from the sending
// of the ping to the reception of its echo off of an object.
pinMode(echoPin, INPUT);
duration = pulseIn(echoPin, HIGH);

// convert the time into a distance
inches = microsecondsToInches(duration);
cm = microsecondsToCentimeters(duration);

Serial.print(inches);
Serial.print(" po, ");
Serial.print(cm);
Serial.print(" cm");
Serial.println();

delay(1000);
}

long microsecondsToInches(long microseconds)
{
// *** THIS NEEDS TO BE CHECKED FOR THE HC-SR04 ***
return microseconds / 74 / 2;
}

long microsecondsToCentimeters(long microseconds)
{
// *** THIS NEEDS TO BE CHECKED FOR THE HC-SR04 ***
return microseconds / 29 / 2;
}

dmd.clearScreen( true );

dmd.selectFont(System5x7);
dmd.drawString( 0,0 "po", 2, GRAPHICS_NORMAL );
dmd.drawString( 0,9 "cm", 2, GRAPHICS_NORMAL );
}
}
delay(2000);
}

andrew
Freetronics Staff
Freetronics Staff
Posts:978
Joined:Sun Jul 14, 2013 7:06 am
Location:Melbourne, Australia
Contact:

Re: DMD with an sr04 ping sensor

Post by andrew » Thu Apr 10, 2014 10:38 pm

You were trying to define two new functions in void loop, and missed a comma in your dmd. drawstring functions. I've rearranged it for you so it compiles:

Code: Select all

#include <SPI.h> 
#include <DMD.h> 
#include <TimerOne.h> 
#include "SystemFont5x7.h"
#include "Arial_black_16.h"

const int triggerPin = 2; // was pin 12 defore the DMD
const int echoPin = 3; // was pin13 before the DMD

#define DISPLAYS_ACROSS 2 // i whant to display it on 16x64 pixels
#define DISPLAYS_DOWN 1
DMD dmd(DISPLAYS_ACROSS, DISPLAYS_DOWN);

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

long microsecondsToInches(long microseconds)
{
  // *** THIS NEEDS TO BE CHECKED FOR THE HC-SR04 ***
  return microseconds / 74 / 2;
}

long microsecondsToCentimeters(long microseconds)
{
  // *** THIS NEEDS TO BE CHECKED FOR THE HC-SR04 ***
  return microseconds / 29 / 2;
} 


void setup()
{
  // initialize serial communication for the terminal windows.
  Serial.begin(9600);

  Timer1.initialize( 5000 ); 
  Timer1.attachInterrupt( ScanDMD ); 
  dmd.clearScreen( true ); 
}

void loop()
{
  // establish variables for duration of the ping,
  // and the distance result in inches and centimeters:
  long duration, inches, cm;

  // The device is triggered by a HIGH pulse of 2 or more microseconds.
  // Give a short LOW pulse beforehand to ensure a clean HIGH pulse:
  pinMode(triggerPin, OUTPUT);
  digitalWrite(triggerPin, LOW);
  delayMicroseconds(2);
  digitalWrite(triggerPin, HIGH);
  delayMicroseconds(5);
  digitalWrite(triggerPin, LOW);

  // The echo pin is used to read the signal from the device: a HIGH
  // pulse whose duration is the time (in microseconds) from the sending
  // of the ping to the reception of its echo off of an object.
  pinMode(echoPin, INPUT);
  duration = pulseIn(echoPin, HIGH);

  // convert the time into a distance
  inches = microsecondsToInches(duration);
  cm = microsecondsToCentimeters(duration);

  Serial.print(inches);
  Serial.print(" po, ");
  Serial.print(cm);
  Serial.print(" cm");
  Serial.println();

  delay(1000);


  dmd.clearScreen( true );

  dmd.selectFont(System5x7);
  dmd.drawString( 0,0, "po", 2, GRAPHICS_NORMAL );
  dmd.drawString( 0,9, "cm", 2, GRAPHICS_NORMAL );
  delay(2000);
}





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

Re: DMD with an sr04 ping sensor

Post by coromonadalix » Fri Apr 11, 2014 1:45 pm

thanks johnb

it helped a lot, i am trying to understand the comas and the void loop section, and pass the infos as a string if i remember.

Now i have the two values (po and cm) on the serial monitor at 1 hz refresh rate, and the po and cm displayed onDMD, but no values are shown ?

I just need to find how to pass the two values :

long microsecondsToInches and the long microsecondsToCentimeters to their places in the DMD

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

Re: DMD with an sr04 ping sensor

Post by coromonadalix » Mon Apr 14, 2014 2:21 am

hello i am unable to find how to send the 2 measurements to the 2 lines of display of the dmd ,

i am trying to understand the dmd tutorial ... but i dont catch how to send thoses measurements.

i have little experience with thoses functions ... i understand a few of the dmd examples in the forums ...

thanks

I am a french person, my english is not very good.

andrew
Freetronics Staff
Freetronics Staff
Posts:978
Joined:Sun Jul 14, 2013 7:06 am
Location:Melbourne, Australia
Contact:

Re: DMD with an sr04 ping sensor

Post by andrew » Mon Apr 14, 2014 4:01 am

coromonadalix wrote:hello i am unable to find how to send the 2 measurements to the 2 lines of display of the dmd ,

i am trying to understand the dmd tutorial ... but i dont catch how to send thoses measurements.

i have little experience with thoses functions ... i understand a few of the dmd examples in the forums ...

thanks

I am a french person, my english is not very good.
As mentioned earlier, you need to change the numbers to a String first - which can then be displayed.
http://arduino.cc/en/Reference/StringObject

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

Re: DMD with an sr04 ping sensor

Post by coromonadalix » Mon Apr 14, 2014 2:36 pm

i understand i have to search for my answers, i do not understand the string things ... with the draw functions of the dmd. I am searching thru the arduino librairies and help files to help me.

im lost when i see the :

StringFinalString; ...
void createtext...
finalstring= ...
drawtext ...

i dont know how to parse my cm and inches values and send them.

Post Reply