loading
 
Arduino Module Combined with User Code
Carl Hoffman from United States  [1 posts]
12 year
Steven-

The Arduino module works great for my project.  I just have one problem with it.  I am using an ultrasonic sensor that needs special code on the Arduino Mega to output the distance.  This code is:
**************************************
const int pingPin = 8;//output cable
const int inputPin = 31;//input cable


void setup() {
  // initialize serial communication:
  Serial.begin(9600);
  
}

void loop()
{
  
  long duration, inches, cm;
  
  pinMode(inputPin, OUTPUT);
  digitalWrite(inputPin, LOW);
  delayMicroseconds(2);
  digitalWrite(inputPin, HIGH);
  delayMicroseconds(5);
  digitalWrite(inputPin, LOW);

  /
  pinMode(pingPin, INPUT);
  duration = pulseIn(pingPin, HIGH);

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

  
Serial.print(inches);
     Serial.println();
   delay(100);
}

long microsecondsToInches(long microseconds)
{
    return microseconds / 74 / 2;
}
*************************************

I am unsure how to combine this code with the RoboRealm Mega Sketch.

Or to be more broad, is there any way a user can add their own custom code to the Mega Sketch and have it implemented in the Mega Module? i.e. combining the MCU Communicator and Arduino Mega modules?

Thanks a lot,

-Carl H.
Anonymous 12 year
If I understand your question/comment, you desire to integrate your Ultrasonic range finder code to the Mega module. You can add an additional array of range data to the existing Mega data stream. Perhaps 2 more bytes representing the sensor bearing and range. The receiving software must parse out the data for display in addition to any collision avoidance scheme you may plan if incorporating the sensor in a robot. I have done a similar concept with a range sensor, Arduino, and Visual Basic. You can view this on my YouTube Channel.
http://www.youtube.com/watch?v=sfBOC980KYA&context=C3d9cd65ADOEgsToPDskLKccf1j8tb2lK_1qgeYpqD

If I missed your point, please provide clarification.

Good luck!
Doyle

This forum thread has been closed due to inactivity (more than 4 months) or number of replies (more than 50 messages). Please start a New Post and enter a new forum thread with the appropriate title.

 New Post   Forum Index