Saturday, July 27, 2013

Serial Port Interface

Serial Port Programming Using Python in Windows


1 - Download and Install Python Installer from here. User the version according to your version of operating system.


2 - You can use python by running "Python (command line)" or "IDLE (Python GUI)" from All programs - Python.

2 - In order to invoke Python from the Command Prompt (cmd) you need to add ";C:\Python34" to the PATH environment variable.

To do this, 

Right click on "computer" , go properties select "advance system properties" than "Environmental Variables". In the "System variables" variable list,  select path from the list and add ";C:\Python34" 


 Now open command terminal and type python, you should see something like this



Now, come out of the python interpreter by typing the command 


exit()


3 - Download pySerial from https://pypi.python.org/pypi/pyserial . Unzip and copy pyserial-2.6 folder into C:\Python27 directory


4- Navigate to C:\python27\pyserial-2.6 using cd command

cd c:\python27\pyserial-2.6 

5 - To install pySerial, type the following command


python setup.py install


Now, to test the serial port interface with the micro-controller board, download term.py from the link "http://academy.cba.mit.edu/classes/embedded_programming/index.html". Navigate to the downloaded directory using the cd command. To run term.py type following command (replace COM10 by actual serial port number you find in device manager)

python term.py \\.\COM10 115200

You should get the following window and it should return what you have typed




/// Draft ///









 Reciever

Code in the micro-controller board continuously monitor the Tx pin of transmitter and waits for start bit (logic low). Once the start bit is observed it continuously samples 8 data bits. After transmitting 8 bits the transmitter sends one (or more) stop bits i.e. Tx pin is logic high. The receiver again waits for logic low (start bit) and the process is repeated for every character byte.

PC COM Port

PC's serial port uses RS232 standard for communication. For RS232 standard logic high is

 a signal voltage in the range of -3 V to -15 V (typically -12 V), and a logic low is between +3 V to +15 V (typically +12 V).  On the other hand for micro controller board logic high is 5V and logic low is 0V. For this reason an FTDI cable is used which convert RS232 high (-12V) into micro-controller logic high (5V).

synchronous (requires a synchronized clock between the transmitter and receiver) - See more at: http://embedded-lab.com/blog/?p=1296#sthash.VjIImNKO.dpuf
two modes of operation: synchronous (requires a synchronized clock between the transmitter and receiver) and asynchronous (no synchronization clock required). - See more at: http://embedded-lab.com/blog/?p=1296#sthash.VjIImNKO.dpuf

two modes of operation: synchronous (requires a synchronized clock between the transmitter and receiver) and asynchronous (no synchronization clock required). - See more at: http://embedded-lab.com/blog/?p=1296#sthash.VjIImNKO.dpufsdsdsd

Thursday, July 25, 2013

Servo Motor Controller

A servo motor has three wires, Black (GND), Red (VCC) and White (Control)

Black and Red wire is connected to ground and Vcc respectively and White wire is used to control the rotation of the servo motor.

Servos are controlled by sending them a pulse of variable width. The control wire is used to send this pulse. The servo expects to see a pulse every 20 ms. The parameters for this pulse are that it has a minimum pulse width (usually 0.5ms), a maximum pulse (usually 2ms), and a repetition rate (20ms). 

Given the rotation constraints of the servo, neutral is defined to be the position where the servo has exactly the same amount of potential rotation in the clockwise direction as it does in the counter clockwise direction.  The pulse width of neutral position is usually 1.5ms.

When these servos are commanded to move they will move to the position and hold that position. Servos will not hold their position forever though; the position pulse must be repeated (every 20ms) to instruct the servo to stay in position.

  When a pulse is sent to a servo that is less than 1.5 ms the servo rotates to a position and holds its output shaft some number of degrees counterclockwise from the neutral point. If a pulse larger than 1.5ms is sent, the servo will rotate clockwise to certain angle depeding upon the exact pulse width.

Figure below shows some sample pulse trains