• Home
  • pcDuino
  • WiKi
  • Store
  • Distributors
  • Home
  • pcDuino
  • WiKi
  • Store
  • Distributors
HomepcDuinoArduino-ish ProgramUARTUse Serial 16×2 LCD and ultrasonic sensor on ...
Previous Next

Use Serial 16×2 LCD and ultrasonic sensor on pcDuino

Posted by: Alvin Jin , March 11, 2014

[vc_row][vc_column][vc_column_text]pcduino测距-1024x768 In this project, we will use a serial 16×2 LCD and ultrasonic ranging to do an interesting experiment.[/vc_column_text][/vc_column][/vc_row][vc_row][vc_column width=”1/1″ el_class=”Results”][vc_tour][vc_tab title=”Parts List” tab_id=”1394503810-1-24″][vc_column_text]

  1. 1 x [bigcommerce link=”/serial-basic-16×2-character-lcd-black-on-green-5v-uart/” target=”_blank”]Serial 16 × 2 LCD[/bigcommerce]
  2. 1 x HC-SR04 Ultrasonic Module
  3. 1 x [bigcommerce link=”/pcduino-v2-an-minipc-with-arduino-headers-ubuntu-android-google/” target=”_blank”]pcDuino v2[/bigcommerce]
  4. 1 x [bigcommerce link=”/protoshield-for-arduino-with-mini-breadboard/” target=”_blank”]Breadboard[/bigcommerce]
  5. Jumper wires

[/vc_column_text][/vc_tab][vc_tab title=”Wire Diagram” tab_id=”1394503810-2-9″][vc_column_text]

  1. ultrasonic module VCC —–>pcDuino  +5 v
  2. ultrasonic module GND —–>  pcDuino  GND
  3. ultrasonic modules Trig—–> pcDuino D2
  4. ultrasound module Echo—–> pcDuino  D3
  5. Serial 16 × 2 LCD  +5 v —–> pcDuino +5 v
  6. Serial 16 × 2 LCD  GND—–> pcDuino GND
  7. Serial 16 × 2 LCD RX—–> pcDuino TX

Because pcDuino only  have a +5 v output port, so use a T-board to do voltage translation.[/vc_column_text][/vc_tab][vc_tab title=”Sample Code” tab_id=”1394505988024-2-5″][vc_column_text]

#include <core.h>

const int LCDdelay=10;
 const int TriPin = 2;
 const int EchoPin = 3;
 float cm;
 void lcdPosition(int row, int col) {
 Serial.write(0xFE); //command flag
 Serial.write((col + row*64 + 128)); //position
 delay(LCDdelay);
 }
 void clearLCD(){
 Serial.write(0xFE); //command flag
 Serial.write(0×01); //clear command.
 delay(LCDdelay);
 }
 void backlightOn() { //turns on the backlight
 Serial.write(0x7C); //command flag for backlight stuff
 Serial.write(157); //light level.
 delay(LCDdelay);
 }
 void backlightOff(){ //turns off the backlight
 Serial.write(0x7C); //command flag for backlight stuff
 Serial.write(128); //light level for off.
 delay(LCDdelay);
 }
 void serCommand(){ //a general function to call the command flag for issuing all other commands
 Serial.write(0xFE);
 }

void setup()
 {
 Serial.begin(9600);
 pinMode (TriPin, OUTPUT);
 pinMode (EchoPin, INPUT);
 }

void loop()
 {
 digitalWrite (TriPin, LOW);
 delayMicroseconds (2);
 digitalWrite (TriPin, HIGH);
 delayMicroseconds (10);
 digitalWrite (TriPin, LOW);
 cm = pulseIn (EchoPin, HIGH, 100000) / 58.0;
 cm = (int (cm * 100.0)) / 100.0;
 backlightOn ();
 clearLCD ();
 lcdPosition (0, 0);
 Serial.print (“cm = “);
Serial.print (cm);
 Serial.print (” LinkSprite”);
delay (1000);
 }

[/vc_column_text][/vc_tab][vc_tab title=”Results” tab_id=”1394505989558-3-5″][vc_column_text]When there is a object in front of the ultrasonic module , and pcDuino will show the  distance on the Serial 16 × 2 LCD.[/vc_column_text][/vc_tab][/vc_tour][/vc_column][/vc_row]

Tags: UART

Share!
Tweet

Alvin Jin

About the author

Leave a Reply Cancel reply

You must be logged in to post a comment.

Category

  • Home
  • pcDuino
  • WiKi
  • Store
  • Distributors