Embedded Eye

Give your gizmo the gift of sight

ArduEye Aphid Standalone Example #1: Generate PWM based on light position

INTRODUCTION

As an experiment, I've decided to make a few ArduEye Aphid examples written specifically for an Aphid, and written for "very easy" use. Specifcially, these examples will meet the following criteria:

  • The source code must fit all within one sketch, and not require any external libraries other than standard Arduino libraries. All you need to program the sensor with the firmware is the Arduino IDE.
  • The source code does not require any modification to use- you can compile it and program the Aphid with it as-is.
  • The example does not require the Processing GUI to use.
  • The example has a very simple interface designed for embedded use.
  • In many cases, the example does not even require the use of the serial monitor for configuration.

I know the first criterion violates many "good practice" programming habits. However I think this will make these examples much easier to use and thus more accessible, which fits the basic philosophy behind the Arduino project.

OVERVIEW

This example implements a simple "bright light detector". The Stonyman chip is binned from the raw 112x112 image down to a 12x24 image, using 8x4 superpixels. The brightest pixel is identified, and the row and column of that pixel is output on two pins in a PWM format. If you hold a flashlight or an LED in front of the lens, the PWM outputs will change according to the position. You can also trigger the Aphid to acquire a calibration mask by shorting a third digital pin to Ground.

SOURCE CODE

The source code may be found here: ArduEye_Aphid_BrightLight_v1.zip

PIN DESCRIPTIONS

These following pins, on the peripheral header, are as follows:

G = Ground
P = Power (5V)
D/SDA = Horizontal position of light PWM output
C/SCL = Vertical position of light PWM output
D9 = Short to ground to obtain calibration. Do this while viewing uniform texture.

DIRECTIONS

These instructions assume you are familiar with the basics of the Aphid as outlined in Part 1 of the initial tutorial, and that you have already installed the Arduino IDE. You do NOT need the ArduEye libraries or the GUI to compile and use this sketch!

Step 1) Compile the source code and upload it to the ArduEye Aphid. Make sure under "Tools" to set the board type to "Arduino Pro or Pro Mini (5V/16MHz) w/ ATmega328".

Step 2) Power the Aphid. You can leave the Aphid connected to the Sparkfun FTDI 5V breakout board used for programming, or you can use the G and the P pins on the peripheral header for Ground and Vin (5V) respectively.

Step 3) Calibrate: Aim the sensor at a uniform texture such as a white blank sheet of paper. Using an external wire, short pin D9 to ground. The LED will increase in brightness for a second or two. Hold the Aphid in place until the LED returns to normal brightness. You only need to acquire the calibration once- it is stored to EEPROM, and read in from the EEPROM the next time the Aphid is powered up.

Step 4) Monitor PWM outputs: Using an oscilloscope, probe the the SDA and SCL pins of the peripheral header (marked D and C respectively). The SDA pin encodes the horizontal position of the brightest pixel. The SCL pin encodes the vertical position of the brightest pixel. The pulse varies from about 100us to 3ms in duration. You can monitor these signals with another microcontroller that measures pulse widths.

Above: Sample oscilloscope trace. The row (blue) of the light is lower in numerical value than the column (yellow).

USER DEFINABLE PARAMETERS

Near the top of the sketch and after the copyright notices, there are five #define values that you can change to modify the operation of this script. For example, this includes adjusting the delays to speed up or slow down the PWM, or add delays between frames to increase the time between pulses.

USAGE WITH A SERIAL MONITOR

When the Aphid is connected to the Arduino IDE via the serial terminal, you have a few commands you can send to the sensor. Note that these are not required for normal use:

Command A dumps the acquired image in a MATLAB-readable format

Command C dumps the calibration image in a MATLAB-readable format

Command c acquires a calibration pattern but does not store it to EEPROM

Command d modifies debug mode: d1 turns debug mode on, so that the brightest
row and column are dumped to the serial monitor. d0 stops this

Command r loads the calibration pattern from EEPROM

Command s saves the current calibration pattern to EEPROM

Command z zeros out the calibration pattern in memory (but not in the EEPROM)

COMMENTS:

  • You can use this script without calibration, but the Aphid will have a reduced sensitivity and may not pick up the light unless it is sufficiently bright. This is especially true if there is already a calibration pattern stored to EEPROM from a different firmware example.

Views: 807

Reply to This

© 2017   Created by Geoffrey L. Barrows.   Powered by

Badges  |  Report an Issue  |  Terms of Service