GP2D12 to OOPic Example
Last Modified: 2006-10-25
find:

basket

Acroname Robotics PDF webpage version GP2D12 to OOPic Example PDF

Related
Products

Product image for Sharp GP2D12 Detector Package
Sharp GP2D12 Detector Package
Product image for OOPic parallel cable harness
OOPic parallel cable harness

Contents

Physical interfacing of GP2D12 to an OOPic.

Introduction

In this example, an OOPic microcontroller uses a Sharp GP2D12 detector to measure distances to obstacles.  The program converts the analog voltage at the output of the GP2D12 detector to an 8-bit value.  The program turns on an LED when this value exceeds a threshold. 

Circuit Schematic

The following schematic assumes the OOpic has an appropriate power supply.  The typical current draw of a GP2D12 is 33ma so it can be powered by the OOPic's 100ma onboard regulator.  The pin selections match those in the source code listed below. 

This circuit is very simple.  All that is required is hooking up an LED and directly wiring the Sharp GP2D12 output to one of the four OOPic pins that can be used for analog-to-digital conversion.  See a similar Sharp GP2D12 Project with a more detailed discussion at the OOPic Web Site

Wiring schematic and pinout of OOPic to the GP2D12.

Source Code

This code uses BASIC syntax.  It runs with version 3.0.1 of the OOpic compiler and version A.1.7 of the OOpic chip. 

' Filename: GP2D12-2.osc ' This program reads the Sharp GP2D12 sensor ' It demonstrates the use of an oA2D object ' and an oDio1 object. In this program, an LED ' turns on when an object is too close to the ' GP2D12 sensor. dim bitTest as new oDio1 dim adc1 as new oA2D sub main() bitTest.Ioline = 9 bitTest.Direction = cvOutput bitTest.value = 0 Oopic.ExtVRef=0 adc1.ioline=1 adc1.operate=cvtrue do if adc1.value > 100 then bitTest.value=1 else bitTest.value=0 end if loop end sub

Revision History:

  • 2000-07-11: Example Created
  • 2000-08-02: Added statement to code: adc1.ExtVRef=0 . This ensures proper ADC operation. Special thanks to Jeff Clayton for pointing this out.
  • 2000-08-14: Added version info for OOPic compiler and OOPic chip used in this example.
  • 2000-11-07: Made error while adding 8/02/00 revision. The command adc1.ExtVRef=0 should be Oopic.ExtVRef=0 , otherwise the code does not compile. Thanks go to Randy L. Gordon for noticing that.
  • 2001-10-31: Added comment about current drawn by the GP2D12.
 
 
voice: 720-564-0373, email: sales@acroname.com, address: 4822 Sterling Dr., Boulder CO, 80301-2350, privacy
© Copyright 1994-2008 Acroname, Inc., Boulder, Colorado. All rights reserved.