I’ve been chugging merrily along with programming the Orangutan. But today I tried to hook up my first sensor, and it’s the darndest thing – whenever it’s connected, the program seems to continually reset and start over.
The sensor is a Sharp GP2Y0A21, which has three pins: Ground, Vcc, and Vout. I’ve double-checked the datasheet, and confirmed that I have Ground connected to the outermost row on the Orangutan’s ADC6; Vcc connected to the middle row; and Vout connected to the top row.
When the sensor is not connected, my program works fine: it displays a greeting, beeps once per second or so until I press PB0, does a quick buzzer slide, and then goes into a loop where it reports the 10-bit value read on AD6. Of course with the sensor unplugged, this value is always 0.
When the sensor is connected, two things are different. First, my once-per-second beep (a simple call to buzzer(440, 200)) has become a much more complex tone. Second, every second or two, the program resets and starts over from the beginning. So if I push the button to put it into sensor-reporting mode, it does briefly report sensor values — they even look like reasonable numbers (varying between 200 and 500, but I haven’t played with the sensor much yet). But then it quickly goes back to start of the program.
Could it be a problem in my code? I’m calling analog_init() near the top of main(), and I read the sensor by a macro defined as (analog10(6)). The loop where the reset occurs is just:
int lastDist = -1;
for (;;) {
int curDist = FRONTDISTANCE;
if (curDist != lastDist) {
lcd_gotoxy(0,1);
lcd_int( curDist);
lastDist = curDist;
}
}
It feels like a hardware problem to me, but this same sensor worked fine on my ARMmite board, and it’s about as simple as an analog sensor can get — it just returns a voltage between 0 and Vcc on Vout. Any idea what’s going wrong?
Thanks,
— Joe