Author Topic: What is easiest way for a micro to talk to a computer?  (Read 11351 times)

0 Members and 1 Guest are viewing this topic.

Offline Red SquirrelTopic starter

  • Super Contributor
  • ***
  • Posts: 2750
  • Country: ca
What is easiest way for a micro to talk to a computer?
« on: March 20, 2016, 08:11:21 am »
Say I want to communicate with an atmel or pic based micro project using C++ within a computer what is the easiest way to achieve this?  I'm thinking some form of either USB or RS232 serial.  Since most computers don't have RS232 ports some form of USB emulated serial port is probably the best bet. 

Just wondering what solutions are available, either chips that I can bit bang to and they translate, or tutorials on how to bit bang it directly.  I'm helping someone with an electronics project and he is using a Pic, I've only really worked with arduino as far as interfacing projects with a PC, but I want to learn how to do it without so it will be a learning experience for me too.   Essentially I just want to be able to read sensor values and also alter digital pin values from a computer program that I will write.

I briefly heard about FDTI chips that do just this, is that basically all I need?  What kind of language do I use to talk to it from the micro, is it literally just big banging the ascii values of serial or is there more to it than that?    I'll probably play with it with an atmel chip at home as I have a bunch, but idealy I'll want it to work on a pic too.  I told him to do research for that and let me know what he comes up with but figured I'd check too what is involved, as I'll probably end up helping him code the actual PC portion of the program but still need to get a general idea of how the micro will talk with the PC first.   
 

Offline westfw

  • Super Contributor
  • ***
  • Posts: 4218
  • Country: us
Re: What is easiest way for a micro to talk to a computer?
« Reply #1 on: March 20, 2016, 08:23:22 am »
Quote
I briefly heard about FDTI chips that do just this, is that basically all I need?
Yep.  The Micro sees an async serial port, and can implement that using either bit-banging, or using a hardware UART peripheral (most micros have hardware UARTs these days.)
The PC-side application also sees a COM port, and writes software as if it were an ordinary serial port.  The PC USB stack and the FTDI chip (or equivalent) invisibly do all of the USB magic in between the two "ends" of the serial interface.
 

Offline Howardlong

  • Super Contributor
  • ***
  • Posts: 5321
  • Country: gb
Re: What is easiest way for a micro to talk to a computer?
« Reply #2 on: March 20, 2016, 08:31:04 am »
RS232 is still the easiest way with commonly available interfaces available although not at standard RS232 voltage levels, do it directly at logic levels. I use them extensively for debugging, either for command line entry in Linux based devices or for debug metrics in more bare metal designs.

If you don't already have a logic level (or "TTL") USB to serial converter, get one! Note that some are 3.3V and others are 5V logic levels, so take care to get the right one for your application.

Also note that due to extensive cloning of chips, make sure you get a kosher device, or it might not work. Even some kosher devices based on older Prolific chips won't work on later versions of Windows. FTDI inspired counterfeit clones also have a history of being rendered useless.

How do you know if it's kosher? It's not always easy, but you do stand a better chance by purchasing from well established local suppliers than going direct to China.
 

Offline Red SquirrelTopic starter

  • Super Contributor
  • ***
  • Posts: 2750
  • Country: ca
Re: What is easiest way for a micro to talk to a computer?
« Reply #3 on: March 20, 2016, 09:07:00 am »
Actually what exactly is a UART, I can't seem to find a definitive answer when I search, I thought it was just a fancy name for the I/O pins on the micro but is it something else?

Would this chip do what I need, or is there a better/more popular one?  Guessing these are common enough that Linux and Windows would probably have drivers built in and it just shows up as a virtual serial port? 

http://www.digikey.ca/product-detail/en/ftdi-future-technology-devices-international-ltd/FT230XS-R/768-1135-1-ND/3029155

Are there any good tutorials or libraries on communicating using these chips?  Ex: sending/receiving strings of text. 

Also do I need to isolate the USB from the micro (assuming the micro has it's own power source), or as long as I combine the grounds I'm good?  Trying to keep this simple, but I guess I could use opto isolators.

I have a few of my own projects I want to eventually start on so the idea of adding USB/serial support cheaply so I can connect a laptop and terminal app to get a custom admin interface that I code sounds very awesome.

As for ensuring I get the genuine part, are places like Digikey and Mouser a safe bet or can duds end up on those sites too?    I sometimes order parts off Amazon but typically I try to stick to Digikey as amazon, Ebay etc can be sketchy.  Depends on the part I want really.  Stuff like LEDs or resistors or capacitors I might get "packs" for cheap knowing they're probably garbage but I'm probably going to blow them up anyway.   :-DD
« Last Edit: March 20, 2016, 09:13:02 am by Red Squirrel »
 

Offline Red SquirrelTopic starter

  • Super Contributor
  • ***
  • Posts: 2750
  • Country: ca
Re: What is easiest way for a micro to talk to a computer?
« Reply #4 on: March 20, 2016, 10:23:21 am »
Oh ok so UART is basically just a built in serial interface for RS232?  So kinda like a dedicated i2c and so on.  Yeah I'd probably want to use that if available.

So the chip I posted should do what I want right? Or is there a better one to pick?  Idealy I'd like through hole but not sure if there are any.   Idea is if I add these to my own projects I'd probably just have a USB square plug like for a printer.
 

Online nctnico

  • Super Contributor
  • ***
  • Posts: 27056
  • Country: nl
    • NCT Developments
Re: What is easiest way for a micro to talk to a computer?
« Reply #5 on: March 20, 2016, 01:15:46 pm »
I'd try to avoid the readily made FTDI based UART / USB board due to the high chance you end up with a cloned FTDI device. CP210x based UART/USB converters are a safe bet (and also slightly more stable than the FTDI chip).
There are small lies, big lies and then there is what is on the screen of your oscilloscope.
 

Offline Red SquirrelTopic starter

  • Super Contributor
  • ***
  • Posts: 2750
  • Country: ca
Re: What is easiest way for a micro to talk to a computer?
« Reply #6 on: March 20, 2016, 01:19:49 pm »
Good to know, think I'll go with that chip then, I like the idea of leaving a permanent USB interface on any project I might make.  I can either have it in there for configuration or debug info or what not.  Or download information... depending what the project is.

Once I am more versed into playing with MCUs I might look into true USB as well but serial is good enough for any needs I can think of and much easier to work with at the computer end too.

 

Offline SL4P

  • Super Contributor
  • ***
  • Posts: 2318
  • Country: au
  • There's more value if you figure it out yourself!
Re: What is easiest way for a micro to talk to a computer?
« Reply #7 on: March 20, 2016, 03:35:16 pm »
It sounds like you are running away from non-existent shadows.

If you have Arduino experience as mentioned in your OP - then you have already used the 'USB serial' interface.
After uploading the 'sketch', the Arduino interface becomes the default serial port (Serial.) used with the serial monitor, or your previous PC <--> Arduino experiments.

Nothing else to do.
All you're doing for the free-standing PIC solution, is ensuring there is a physical connection and appropriate interface - in the same way as the AVR chip. There are many ways to implement both, all trivial.
Don't ask a question if you aren't willing to listen to the answer.
 

Online nctnico

  • Super Contributor
  • ***
  • Posts: 27056
  • Country: nl
    • NCT Developments
Re: What is easiest way for a micro to talk to a computer?
« Reply #8 on: March 20, 2016, 04:00:37 pm »
I think what is confusing the OP is that a UART isn't always called a UART but it can also be called a serial interface, asynchronous serial interface or acronyms like SCPI, etc, etc. It takes reading the datasheet and user manual carefully to determine whether a microcontroller actually has an asynchronous serial interface.
There are small lies, big lies and then there is what is on the screen of your oscilloscope.
 

Offline exe

  • Supporter
  • ****
  • Posts: 2570
  • Country: nl
  • self-educated hobbyist
Re: What is easiest way for a micro to talk to a computer?
« Reply #9 on: March 20, 2016, 04:30:47 pm »
I bought bluetooth-serial adapter and so far I'm happy with it, though initial setup was a pain.
 

Offline Howardlong

  • Super Contributor
  • ***
  • Posts: 5321
  • Country: gb
Re: What is easiest way for a micro to talk to a computer?
« Reply #10 on: March 20, 2016, 04:41:53 pm »
I'd try to avoid the readily made FTDI based UART / USB board due to the high chance you end up with a cloned FTDI device. CP210x based UART/USB converters are a safe bet (and also slightly more stable than the FTDI chip).

It's interesting that because there is a risk of FTDI's own drivers bricking a device, that we're now steering clear of any FTDI serial device because there's no way of knowing it's conterfeit or not until it's sitting on your desk plugged in.
 

Offline Karel

  • Super Contributor
  • ***
  • Posts: 2227
  • Country: 00
Re: What is easiest way for a micro to talk to a computer?
« Reply #11 on: March 20, 2016, 04:59:15 pm »
I'd try to avoid the readily made FTDI based UART / USB board due to the high chance you end up with a cloned FTDI device. CP210x based UART/USB converters are a safe bet (and also slightly more stable than the FTDI chip).

The change that you end up with a clone chip is very low. Just don't buy it from some cheap/shady places and you'll be fine.
FTDI has a very good reputation for USB/serial converters and, at least in my experience, they provide the most stable drivers.
Personally, I wouldn't buy anything else than FTDI for USB <-> serial.

At least with Linux, we had some strange issues with Silab based converters that caused the converter responseless and we had
to disconnect and connect the device again. With FTDI based chips, we never had any issues.

 

Online nctnico

  • Super Contributor
  • ***
  • Posts: 27056
  • Country: nl
    • NCT Developments
Re: What is easiest way for a micro to talk to a computer?
« Reply #12 on: March 20, 2016, 05:11:32 pm »
I'd try to avoid the readily made FTDI based UART / USB board due to the high chance you end up with a cloned FTDI device. CP210x based UART/USB converters are a safe bet (and also slightly more stable than the FTDI chip).
The change that you end up with a clone chip is very low. Just don't buy it from some cheap/shady places and you'll be fine.
The latter is the problem. A USB to TTL UART converter board (bare PCB without housing) isn't a high priced product so chances are high they originate somewhere/somehow from China. The last time I ordered some RS485 boards from China they all had fake FTDI chips. One of my customers had a bunch of proprietary USB/serial port boards made in China and those also contained fake FTDI chips. So you are left with two choices: pay $30 to $40 for a board from a local source with (hopefully) a real FTDI chip or pay less than $2 including shipping for a USB-UART board based on a Silabs chip:
www.ebay.com/itm/6Pin-USB-2-0-to-TTL-UART-Module-Serial-Converter-CP2102-STC-Replace-Ft232-Module-/400565980256
Note how it is advertised as a FT232 replacement  :)
« Last Edit: March 20, 2016, 05:13:21 pm by nctnico »
There are small lies, big lies and then there is what is on the screen of your oscilloscope.
 

Offline Red SquirrelTopic starter

  • Super Contributor
  • ***
  • Posts: 2750
  • Country: ca
Re: What is easiest way for a micro to talk to a computer?
« Reply #13 on: March 20, 2016, 06:36:34 pm »
It sounds like you are running away from non-existent shadows.

If you have Arduino experience as mentioned in your OP - then you have already used the 'USB serial' interface.
After uploading the 'sketch', the Arduino interface becomes the default serial port (Serial.) used with the serial monitor, or your previous PC <--> Arduino experiments.

Nothing else to do.
All you're doing for the free-standing PIC solution, is ensuring there is a physical connection and appropriate interface - in the same way as the AVR chip. There are many ways to implement both, all trivial.

I know I can just use an Arduino and call it a day I've done it before, but I just want to learn how to do it "manually" so to speak, and if I decide to make a project where I want it to have built in USB it's much cheaper than using an Arduino each time.  Though I do kinda cheat and use the Arduino libraries and just burn the Arduino project directly on the Atmel chip. :P  But it's still a stand alone setup at the end.   

As for the source for the chip I'll stick to Digikey to be safe.   I also imagine the Linux driver is written by Linux community so it probably does not have that issue where it bricks the chips, hopefully.
 

Offline SuzyC

  • Frequent Contributor
  • **
  • Posts: 792
Re: What is easiest way for a micro to talk to a computer?
« Reply #14 on: March 20, 2016, 07:38:01 pm »
IMHO the easiest, most quick, no HW to buy, simplist and so the cheapest and most reliable way for a PC to communicate with the outside world using languages such as C or VB is to use the parallel port.
(If you are fortunate enough to have an older XP Windows PC around with a motherboard that has a parallel port.)

All it takes is Porttalk22 (attached.) and works with Windows XP very well, and there also exists .dlls that unlock the parallel port in windows, such as inpout32.dll and inpout64.dll  that support windows 7 in 32-bit and 64-bit as well.

Then, bit-banging is just a matter of using simple statements something like Out() or Inp() in your programs.
« Last Edit: March 20, 2016, 07:56:06 pm by SuzyC »
 

Offline retrolefty

  • Super Contributor
  • ***
  • Posts: 1648
  • Country: us
  • measurement changes behavior
Re: What is easiest way for a micro to talk to a computer?
« Reply #15 on: March 20, 2016, 07:57:11 pm »
I bought bluetooth-serial adapter and so far I'm happy with it, though initial setup was a pain.

 Adafruit sells a bluetooth serial converter module that has the same pin out as the popular FTDI adapters including emulation for the DTR comm signal (that arduino use to reset and activate a bootloader). It's baudrate transparent and requires no setup from the micro. But of course it costs more but truly a 'universal solution'  for PC<>micro communications applications, especially if you desire or need DC isolation.

https://www.adafruit.com/products/1588
« Last Edit: March 20, 2016, 10:39:41 pm by retrolefty »
 

Offline dannyf

  • Super Contributor
  • ***
  • Posts: 8221
  • Country: 00
Re: What is easiest way for a micro to talk to a computer?
« Reply #16 on: March 20, 2016, 10:19:32 pm »
Quote
but I just want to learn how to do it "manually" so to speak,

Your Arudino environment / boards have all you need to do it "manually".
================================
https://dannyelectronics.wordpress.com/
 

Offline Karel

  • Super Contributor
  • ***
  • Posts: 2227
  • Country: 00
Re: What is easiest way for a micro to talk to a computer?
« Reply #17 on: March 20, 2016, 11:30:07 pm »
I'd try to avoid the readily made FTDI based UART / USB board due to the high chance you end up with a cloned FTDI device. CP210x based UART/USB converters are a safe bet (and also slightly more stable than the FTDI chip).
The change that you end up with a clone chip is very low. Just don't buy it from some cheap/shady places and you'll be fine.
... The last time I ordered some RS485 boards from China ...

You'll get what you pay for. Just don't buy cheap shit from China.

The op doesn't need rs485.

This cable will work just fine: http://www.newark.com/ftdi/us232r-100/cable-usb-to-rs232-serial-converter/dp/34M8933



 

Offline Karel

  • Super Contributor
  • ***
  • Posts: 2227
  • Country: 00
Re: What is easiest way for a micro to talk to a computer?
« Reply #18 on: March 20, 2016, 11:35:24 pm »
IMHO the easiest, most quick, no HW to buy, simplist and so the cheapest and most reliable way for a PC to communicate with the outside world using languages such as C or VB is to use the parallel port.
(If you are fortunate enough to have an older XP Windows PC around with a motherboard that has a parallel port.)

All it takes is Porttalk22 (attached.) and works with Windows XP very well, and there also exists .dlls that unlock the parallel port in windows, such as inpout32.dll and inpout64.dll  that support windows 7 in 32-bit and 64-bit as well.

Then, bit-banging is just a matter of using simple statements something like Out() or Inp() in your programs.

Nope, it isn't. The easiest way is to use the serial port (or a usb to serial converter cable) and this library:

http://www.teuniz.net/RS-232/

No need for an old pc, no need for an (old) windows os, no need to do some silly bit-banging.

 

Offline Buriedcode

  • Super Contributor
  • ***
  • Posts: 1619
  • Country: gb
Re: What is easiest way for a micro to talk to a computer?
« Reply #19 on: March 21, 2016, 12:32:20 am »
Whilst many have covered the hardware needed - I too think a USB-serial bridge is the easiest way to get data between a PC and micro - it isn't all rosey.  The PC-side software for the serial port can be a bit buggy depending on what you're doing, and what API's libraries you use.  In .NET (the nice easy-to-use managed code) environment, the serial port can be buggy.  Its fine for small strings, but for long runs, continuous data or anything approaching 'high speed' it can easily drop bytes.  I ended up having to abandon most of the routines provided and read from the buffer directly with a timer on a different thread.

If you're just sending and receiving control data (occasional packets) its fine.  Not trying to scare you off, but it trips up a lot of people.
 

Offline SuzyC

  • Frequent Contributor
  • **
  • Posts: 792
Re: What is easiest way for a micro to talk to a computer?
« Reply #20 on: March 21, 2016, 12:48:19 am »
Karel..
There is nothing simple or easy or inexpensive in cost or time about your suggestion.

There is nothing simple about needing to be experienced in GCC/Linux/Unix programming to just do what the op asked to do.

There is nothing simple about going through the hundreds of options and compile options to just bit-bang to an external port.

The parallel port solution only requires only a few lines of code to make  it work with C, C++ or Visual Basic.

There is no hardware to buy.


Parallel port supports handshaking, has several handshaking pins useful for handshaking protocol.

Parallel ports feature open-collector outputs and can interface directly to 3.3V or 5V logic level systems.

« Last Edit: March 21, 2016, 12:53:18 am by SuzyC »
 

Online nctnico

  • Super Contributor
  • ***
  • Posts: 27056
  • Country: nl
    • NCT Developments
Re: What is easiest way for a micro to talk to a computer?
« Reply #21 on: March 21, 2016, 01:23:22 am »
Karel..
There is nothing simple or easy or inexpensive in cost or time about your suggestion.

There is nothing simple about needing to be experienced in GCC/Linux/Unix programming to just do what the op asked to do.

There is nothing simple about going through the hundreds of options and compile options to just bit-bang to an external port.

The parallel port solution only requires only a few lines of code to make  it work with C, C++ or Visual Basic.

There is no hardware to buy.


Parallel port supports handshaking, has several handshaking pins useful for handshaking protocol.

Parallel ports feature open-collector outputs and can interface directly to 3.3V or 5V logic level systems.
I think you mean by parallel port some kind of I/O interface? Printer ports don't have open collector outputs and modern PCs don't have printer ports for over a decade.

Still a serial port is very standard and a USB-UART interface can be bought for less than $2. There are tons of libraries out there to use a serial port in your own PC software in whatever language you want. If one library doesn't work then hop on to another and don't look back.
« Last Edit: March 21, 2016, 01:25:04 am by nctnico »
There are small lies, big lies and then there is what is on the screen of your oscilloscope.
 

Online Monkeh

  • Super Contributor
  • ***
  • Posts: 8008
  • Country: gb
Re: What is easiest way for a micro to talk to a computer?
« Reply #22 on: March 21, 2016, 01:30:05 am »

There is no hardware to buy.


Sorry, uhm, I just looked at every computer I use on a daily basis. I can't find one of these parallel port things anywhere. Do you happen to know what year they were introduced? My machines aren't the newest, so maybe they're a little out of date..
 

Offline SuzyC

  • Frequent Contributor
  • **
  • Posts: 792
Re: What is easiest way for a micro to talk to a computer?
« Reply #23 on: March 21, 2016, 02:10:22 am »
There is no doubt that the PC Parallel Port is now "legacy", but this can also mean easy access to a mountain of  free used PC's and this can be an advantage in finding an easy, low-cost(likely no-cost) solution for hardware interfacing an external world circuit or MCU to a PC.

Such a machine can be used for programming, debugging MCU's, machine control, home automation, factory custom automation, to name a few applications.

In a third-world environment, such PC's control solar power, manufacturing assembly lines, etc., with the lowest possible cost and complexity.

The main 8-bit parallel data port is 5V TTL in/out, but the control handshake lines are open-collector.

To interface with 5V MCU's the parallel port provides a super stable, fast bi-directional 8-bit interface with handshake lines.


I should have said:

Parallel ports control ports feature open-collector outputs and can interface directly to 3.3V or 5V logic level systems.

Just using the control port pins allows assigning one of the pins as Clk and another as Data and by using other Control Port pins for handshaking, it is easy enough to just create your own custom fast serial channel interface to/from a target MCU.


If you Wikipedia Parallel Port:

For electronics hobbyists the parallel port is still often the easiest way to connect to an external circuit board. It is faster than the other common legacy port (serial port) and requires no serial-to-parallel converter, and requires far less interface logic and software than a USB target interface. However, Microsoft operating systems later than Windows 95/98 prevent user programs from directly writing to or reading from the LPT without additional software (kernel extensions).[9] Current CNC Milling Machines also often make use of the parallel port to directly control the machine's motors and attachments.

There is no need to fiddle around with bogus FTDI boards and shuffle through the FTDI website to only find that some drivers don't work.  I have provided these already to anyone interested and they have been tested and do work.
« Last Edit: March 21, 2016, 02:57:41 am by SuzyC »
 

Offline David_AVD

  • Super Contributor
  • ***
  • Posts: 2813
  • Country: au
Re: What is easiest way for a micro to talk to a computer?
« Reply #24 on: March 21, 2016, 02:21:03 am »
Recommending the parallel port for data i/o these days is nuts.  How many people have a PC with a parallel port on it?  Windows XP is also rapidly losing share and is no longer supported by most vendors.

Buying a genuine FTDI (or whatever brand you like) USB-TTL adapter is easy and not as expensive as you may think.  FTDI have PC drivers and code examples on their web site.  I'm sure the other vendors do too.
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf