Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

oled 128x64_i2c with HC-SR04 sensor #317

Open
GoogleCodeExporter opened this issue Apr 13, 2015 · 3 comments
Open

oled 128x64_i2c with HC-SR04 sensor #317

GoogleCodeExporter opened this issue Apr 13, 2015 · 3 comments

Comments

@GoogleCodeExporter
Copy link

hello 8) , i just wanna do a simple rangrefinder with a hc-sr04 and a tiny oled 
128x64_i2c but no sucess ....
i try to combine 2 sketchs, 1 for the ultrasonic sensor and 1 for the screen.

So on the screen there is "hello world" and if i check the serial monitor on my 
computeur i can see the range finder working well...

But i wanna have the value of the sensor on the screen and i cannot find my way 
to it...

thanks and sorry for my english (french guy )


#include "U8glib.h"

int triggerPin = 7; 
int echoPin = 8;    

U8GLIB_SSD1306_128X64 u8g(U8G_I2C_OPT_NONE|U8G_I2C_OPT_DEV_0);

void draw(void) {
  // graphic commands to redraw the complete screen should be placed here  
  u8g.setFont(u8g_font_unifont);
  u8g.setPrintPos(0, 20); 
  u8g.print("Hello World!");
}

void setup(void) {
  Serial.begin(9600);  
  pinMode(triggerPin, OUTPUT); 
  pinMode(echoPin, INPUT);
}

void loop(void) {
  // picture loop
  u8g.firstPage();  
  do {
    draw();
  } while( u8g.nextPage() );

  // rebuild the picture after some delay
  delay(500);

  int duration, distance;    //Adding duration and distance

  digitalWrite(triggerPin, HIGH); //triggering the wave(like blinking an LED)
  delay(10);
  digitalWrite(triggerPin, LOW);

  duration = pulseIn(echoPin, HIGH); //a special function for listening and waiting for the wave
  distance = (duration/2) / 29.1; //transforming the number to cm(if you want inches, you have to change the 29.1 with a suitable number

  Serial.print(distance);    //printing the numbers
  Serial.print("cm");       //and the unit
  Serial.println(" ");      //just printing to a new line
}

Original issue reported on code.google.com by creazy...@gmail.com on 5 Feb 2015 at 6:22

@GoogleCodeExporter
Copy link
Author

u8g.print is identical to Serial.print
So yu can use u8g.print(distance)

Original comment by olikr...@gmail.com on 5 Feb 2015 at 9:12

@GoogleCodeExporter
Copy link
Author

thank you so much for the advise!!!!!!!!it work noww :-)

Original comment by creazy...@gmail.com on 6 Feb 2015 at 5:14

@GoogleCodeExporter
Copy link
Author

ok, i will close this issue

Original comment by olikr...@gmail.com on 6 Feb 2015 at 5:43

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant