SRF02 LCD 16*2

Hello,
i have to do measure the distance with a srf02 and show it on a lcd 162.
I use for that a ATMEGA 2560.
I found the program for the srf02 on the arduino website but i don’t know how can i add the display on the program.
Thank’s for your help
Salut,
Je dois pour un projet mesurer des distances a l’aide d’un srf02 et l’afficher ensuite sur un lcd 16
2.
J’utilise un ATMEGA 2560.
J’ai trouve le programme pour le srf02 sur le site d’arduino mais je ne sais pas comment faire en sorte que le resultat final s’affiche sur mon lcd.
Merci de votre aide.

#include <Wire.h>

void setup() {
Wire.begin(); // join i2c bus (address optional for master)
Serial.begin(9600); // start serial communication at 9600bps
}

int reading = 0;

void loop() {
// step 1: instruct sensor to read echoes
Wire.beginTransmission(112); // transmit to device #112 (0x70)
// the address specified in the datasheet is 224 (0xE0)
// but i2c adressing uses the high 7 bits so it’s 112
Wire.write(byte(0x00)); // sets register pointer to the command register (0x00)
Wire.write(byte(0x50)); // command sensor to measure in “inches” (0x50)
// use 0x51 for centimeters
// use 0x52 for ping microseconds
Wire.endTransmission(); // stop transmitting

// step 2: wait for readings to happen
delay(70); // datasheet suggests at least 65 milliseconds

// step 3: instruct sensor to return a particular echo reading
Wire.beginTransmission(112); // transmit to device #112
Wire.write(byte(0x02)); // sets register pointer to echo #1 register (0x02)
Wire.endTransmission(); // stop transmitting

// step 4: request reading from sensor
Wire.requestFrom(112, 2); // request 2 bytes from slave device #112

// step 5: receive reading from sensor
if (2 <= Wire.available()) { // if two bytes were received
reading = Wire.read(); // receive high byte (overwrites previous reading)
reading = reading << 8; // shift high byte to be high 8 bits
reading |= Wire.read(); // receive low byte as lower 8 bits
Serial.println(reading); // print the reading
}

delay(250); // wait a bit since people have to read the output :slight_smile:
}

Have you looked at the LiquidCrystal examples in the IDE ?

  lcd.print(reading);

With, of course, the correct instantiation of an LCD object.

Edit: and for posting the same question four times, you could spend your forum time-out reading the forum guidelines.