Thursday, January 20, 2011

Microcontrolling the LED



Wednesday Jan 19:

The focus for this class was learning to interact with a pic micro-controller through a USB to serial output. In the photo below, the black 8 pin chip is the pic micro-controller of type 08M.
Part no. 12f683. The white wire at the top of the photograph is the Tx to computer wire, the grey wire on the left side of the photo is the communications FROM the computer, and it is wired in series with a resistor to prevent an overload of the communications pin.
Setting up the board was painless, but getting the serial communication to work took the bulk of the head scratching.

As it turns out, I was trying to program with an old version of the picaxe programming editor. The newest version (v5.3.2) solved my communication problems and it can be found here:
http://www.rev-ed.co.uk/picaxe/software.htm

The rest of the evening was spent trying to get this servo PAN/TILT platform to interface with the pic micro-controller.
The PIC has built in syntax for controlling servo motors;
The code I used to move the servo by changing the amount of light hitting a LDR (Light Dependent resistor) is shown below.
============================================
init: servo 2,125
main:
readadc 4, b0
serout 0, N2400, (#b0)
serout 0, N2400, (10,13)
if b0> 95 then position
if b0< 96 then outdown

goto main

position:
servopos 2, b0
pause 200
goto main

outdown:
servopos 2, 95
pause 200
goto main
=====================================

No comments:

Post a Comment