Sending analog values over serial using a PIC 18F14K50

PICkit 2, pl2303 usb to serial converter and a PIC 18F14k50

PICkit 2, pl2303 usb to serial converter and a PIC 18F14k50

There’s a Robosumo competition coming up. The microcontroller chosen for the job was the PIC 18F14k50. The sensors being used are Sharp infrared rangefinder (to locate the opposing robot), and IR colour detecting sensors (to detect when the robot has reached the edge of the ring). All of these sensors give out a voltage somewhere between 0-5v. In order to start writing some code, it is extremely helpful to read the output of each analog channel in real time.

This is the code used to read from the analog channel and transmit it over serial:

On the computer end of things, a python script is used to print the incoming serial data to the screen.

import serial
import time
import numpy as np
import cv2

ser = serial.Serial('/dev/ttyUSB0', 9600)

ser.close()
ser.open()

while True:

	print ser.readline()

Link to the Python script : https://drive.google.com/file/d/0B5yKKaW8az34NE9hdHdONWFWaE0/edit?usp=sharing

Link to the C file : https://drive.google.com/file/d/0B5yKKaW8az34TlNTX1QzZEVkWmM/edit?usp=sharing

This entry was posted in C, Microcontrollers, pic microcontrollers, Python and tagged , , , , , , , . Bookmark the permalink.

Leave a Reply