Other Parts Discussed in Thread: ENERGIA
Hello,
I am new to the tiva c connected launch pads and I am stuck now
I am trying to test the HC-SRO4 with the TI EK-TM4C1294XL but I cant even get the distance out of it
I am using energia and this is the code which I am using
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//Ultrasonic pins definition
const int echo = 9, Trig = 10;
long duration, cm;
/////////////////////////////////////////////////////////////////////////////////////////
//Time update variables
unsigned long LastUpdateMicrosecs = 0;
unsigned long LastUpdateMillisecs = 0;
unsigned long CurrentMicrosecs = 0;
unsigned long MicrosecsSinceLastUpdate = 0;
float SecondsSinceLastUpdate = 0;
void setup()
{
//Init Serial port with 115200 buad rate
Serial.begin(115200);
SetupUltrasonic();
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//Setup UltrasonicsSensor() function
void SetupUltrasonic()
{
pinMode(Trig, OUTPUT);
pinMode(echo, INPUT);
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//MAIN LOOP
void loop()
{
Update_Ultra_Sonic();
delay(200);
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//Will update ultrasonic sensors through serial port
void Update_Ultra_Sonic()
{
digitalWrite(Trig, LOW);
delayMicroseconds(2);
digitalWrite(Trig, HIGH);
delayMicroseconds(10);
digitalWrite(Trig, LOW);
// The echo pin is used to read the signal from the PING))): 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.
duration = pulseIn(echo, HIGH);
// convert the time into a distance
cm = microsecondsToCentimeters(duration);
//Sending through serial port
Serial.print("Distance=");
Serial.print("\t");
Serial.print(cm);
Serial.print("\n");
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//Conversion of microsecond to centimeter
long microsecondsToCentimeters(long microseconds)
{
// The speed of sound is 340 m/s or 29 microseconds per centimeter.
// The ping travels out and back, so to find the distance of the
// object we take half of the distance travelled.
return microseconds / 29 / 2;
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
the circuit is simple I am connecting the sensor to a level shifter in high level 5V and then from the other side which is 3.3V to the launch pads I am pretty sure that the connections are OK but I dont know what I missed