I2c Ezb Arduino1 Sensor

Description

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

Code:


print(I2CRead(0, 2,6 ))


The code for the...

Step 1

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

Code:


print(I2CRead(0, 2,6 ))


The code for the Arduino is

Code:



#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.


ARC Pro

Upgrade to ARC Pro

ARC Early Access will give you immediate updates and new features needed to unleash your robot's potential!