Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

serial, parrallel, or USB

Status
Not open for further replies.

phoenixy

New Member
Hi,

I am doing a project that involves getting some binary(on/off) sensor data into a Windows XP PC. I'm wondering which PC interface is the best.

So far, the number of sensor we need is still under discussion. But it would be a number between 1 to 8. The control software running on the PC would be Java. So, it is a matter of packing the sensor data into one of the ports, and then use something like

https://www.steelbrothers.ch/jusb/api/usb/windows/package-summary.html
https://java.sun.com/products/javacomm/index.jsp

to act as the driver for the main program

We will be using a PIC and our own circuit to act as an interface between the sensor and the PC port. From Microchip's website, it seems like some PIC has serial interface, some has parralle, some even has USB

So, which port is my best option? How does the PIC actually uses its own port(does MPLAB comes with C library that deals with data packing)? Is there any similar projects that I can borrow some ideas?

Cheers
 
The easiest method is to use the serial port, it's simple on both the PIC side and the PC side, USB is by FAR the most complicated. A lot depends on exactly what you are wanting to do?, but there's very rarely any need for anything other than serial - my PIC tutorials have examples of how to do it.
 
all right, USB is out of the equation then.

We only need to send about 8 bits of binary data to PC. The sample rate is probably 60Hz.

I will take a look at your tutorial, thanks
 
phoenixy said:
all right, USB is out of the equation then.

We only need to send about 8 bits of binary data to PC. The sample rate is probably 60Hz.

Serial is fine then, 9600 baud (960 bytes per second) is very easy to do, either in software or with the hardware USART in some PIC's.
 
which of your tutorials deals with the PIC and the pc

<
Nigel Goodwin said:
The easiest method is to use the serial port,
< it's simple on both the PIC side and the PC side, USB is by FAR < the most complicated. A lot depends on exactly what you are wanting < to do?, but there's very rarely any need for anything other than serial - < my PIC tutorials have examples of how to do it.

Nigel Goodwin:
I have looked high and low all over the Internet to find out how to connect a PIC to the PC using the <Serial Com port> . and ESPECIALLY
which PC program can input/output to the PIC.

I have looked at your site and browsed the material but I have NOT found the PIC tutorials you mentioned.

QUESTION:
which of your PIC tutorials deal with the PC program that will do this?

Thank you ,

marty
 
Re: which of your tutorials deals with the PIC and the pc

hawk2eye said:
<
Nigel Goodwin said:
The easiest method is to use the serial port,
< it's simple on both the PIC side and the PC side, USB is by FAR < the most complicated. A lot depends on exactly what you are wanting < to do?, but there's very rarely any need for anything other than serial - < my PIC tutorials have examples of how to do it.

Nigel Goodwin:
I have looked high and low all over the Internet to find out how to connect a PIC to the PC using the <Serial Com port> . and ESPECIALLY
which PC program can input/output to the PIC.

I have looked at your site and browsed the material but I have NOT found the PIC tutorials you mentioned.

QUESTION:
which of your PIC tutorials deal with the PC program that will do this?

Thank you ,

marty

My tutorials deal with the PIC side, on the PC you just use any standard comms program - the one that comes as part of Windows is called Hyperterminal. This allows you to display text on screen from the PIC, and send keyboard commands to the PIC.

Presumably you are wanting to write your own PC program for some specific purpose?, so you need to check how your particular language allows acces to the serial port. The most common method is to use MSCOMM, which can be used with a number of Windows programming languages. Another method is to open the serial port as a file, and access it in that way.

A lot depends on exactly what you are trying to do?, but the PC end has no real relationship to the PIC, it just sends and receives serial data.
 
USE PYTHON!!!! with the pySerial module, very easy to write the PC-software
 
Styx said:
USE PYTHON!!!! with the pySerial module, very easy to write the PC-software

I agree it's very simple. I did some PIC-communications with python.
Here is a small program I wrote that sends the name of the current song from winamp to a PIC:

Code:
import winamp
import serial
import string
import time
winamp = winamp.winamp()
n = 0
names = 0
dash = 0
TrackName = ''

track = string.split(winamp.getCurrentTrackName())          #Get info from winamp

for word in range(len(track)):      #Divide info up
    n = n + 1
    if track[word] == '-':          #Detect dashes
        dash = dash + 1
        if names == 0:              #Set first found dash
            names = n
        else:                       #Set last found dash
            namep = n-1
            
if dash == 1:                                       #If name contains one dash
    for word in range(1, names-1):
        TrackName = TrackName + track[word] + ' '
else:                                               #If name contains multiple dashes
    for word in range(names, namep):
        TrackName = TrackName + track[word] + ' '
TrackName = string.replace(string.replace(string.strip(TrackName), 'Å', 'A'), 'å', 'a')     #Strip Å and å

print 'TrackName:'

pic = serial.Serial(0)              #Open PIC communication

n = 0
for char in TrackName:              #Split up name in chars
    if n < 16:                      #Send only first 16 chars
        print char
        pic.write(char)            #Send char to PIC
        time.sleep(0.00001)        #Wait for PIC to prosess char
    n = n + 1

pic.close()                         #Close PIC communication

You can ignore the top part, it just extracts the track name from the artist - name string you get from wniamp. Just download python (https://www.python.org/) and the serial module https://sourceforge.net/projects/pyserial/ and look at the examples, trés easy. :)
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top