I2c Ezb Arduino1 Sensor

Luis Vazquez

USA

Hello all,

I wail back I posted some information on using an Arduino as a I2C Sensor controller to use with the EZB3&4

I will post this in 3 stages ..

Stage one.. right here right now.

In this video you can see how im using the arduino to read the ultrasonic sensor . that in turn is being read by the EZB board via I2C.

This is the only code needed to read the ping for the EzBuilder script


print(I2CRead(0, 2,6 ))

The code for the Arduino is



#include 

void setup()
{
  Wire.begin(2);                
  Wire.onRequest(requestEvent); 
}

void loop()
{
  delay(100);
}

void requestEvent()
{

  long duration, inches, cm;
  pinMode(9, OUTPUT);// attach pin 3 to Trig
  digitalWrite(9, LOW);
  delayMicroseconds(2);
  digitalWrite(9, HIGH);
  delayMicroseconds(5);
  digitalWrite(9, LOW);

  pinMode (8, INPUT);//attach pin 4 to Echo
  duration = pulseIn(8, HIGH);
  // convert the time into a distance
  inches = microsecondsToInches(duration);
  cm = microsecondsToCentimeters(duration);
  
  String outtoezb;
  
  outtoezb +=  "D1=";
  outtoezb += inches;
  outtoezb += ":";
  
  char  tempout[outtoezb.length() + 1];
  outtoezb.toCharArray(tempout,outtoezb.length() + 1); 
  Wire.write(tempout); 
}

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

long microsecondsToCentimeters(long microseconds)
{
  
  return microseconds / 29 / 2;
}


Phase two will be adding the 3 other ping sensors and a temp sensor to the arduino . I hope to have it all encased together will plugs and off the project board.

I will follow up on this thread as the next phase is done I will provide the code for EzBuilder as well as the arduino code.

Hope yall can use it.

By — Last update

ARC Pro

Upgrade to ARC Pro

Unleash your robot's full potential with the cutting-edge features and intuitive programming offered by Synthiam ARC Pro.

#1  

Hi Luis, great tutorials on the Arduino:) I'm working to hook up an Ultrasonic to an Arduino Mega, and not sure about the pinout. Just looking for some quick input:) This is confusing me a little bit so thought i should ask.

pinMode(9, OUTPUT);// attach pin 3 to Trig

Of course the pinout will differ with the mega, but i see you referring to Pin 3 to Trig,

But init, Pin 9. The D1 in reference to the EZB. Where does Pin 3 come into play?

Sensor HC-SR04

User-inserted image

#2  

Not to belittle what is being done here, why not just connect the ultrasonic sensors directly to the EZB ? What is the advantage of connecting them to an Arduino board?

#3  

I have to agree with @Bob.... @dwrightny2266 Once you really start getting into the ezb4 and ARC, I'm afraid your arduino days will be numbered... Yes, the ezb is that amazing... Eventually like mine, sooner than later your arduinos will end up in the back of your hobby drawer collecting dust too...;)

#4  

Hey guys, thanks for the input, and In terms of running the robot/rover itself, it will definitely be handled by the EZB4 boards, wouldn't have it another way:) The overall project is pretty ambitious, and started out all Arduino, but not now Thanks to this product and community, we have switched gears . With that said, A big portion of the project involves Arduino as well as other platforms for educational purposes, mainly programming. Again, the Main operating system including autonomous navigation, will be all EZB. The rest will be external systems, accessed independently, to control various parts of the rover.

#5  

@dwrightny2266 Ok sounds awesome... So the Arduinos are too "entrenched" into this project... Got ya' ... Keeps us updated on the project...

Cheers :)

#6  

The Rover will be eventually in Utah, and will act as an educational platform for various types of programming, such as C++. It will be accessed, with a lesson plan, to program, trouble shoot, etc... part of the rover, Robotic arm for example, by a student. When it comes to teaching long distance remote navigation skills, that will be a different system entirely, involving the EZB:) Very exciting! The first concept rover is set for testing in 4 moths.

#7  

Maybe you can up load some picks when you have a chance. I (we) would love to see your project... Again, sounds awesome....:)

#8  

@Richard R,

The other use for this concept is similar to why a Sabertooth is better than most other H-bridges. Using a single UART port on the EZ-B you an greatly expand the number of sensors available, and they can run largely independently and only tell EZ-B when there is a problem to react to, taking away some of the processing load (only an issue with low power computers, but could effect some embedded systems)

Alan