Micro with USB support for a software guy - Page 1
Forum section: electronics / general

author: ndictu
author_rank: Regular Contributor
timestamp: May 22, 2011, 10:51:04 am
content: Hi guys,I've been watching Dave's blog for quite a while and recently started reading these forums and it's awesome, I learned a lot from you. I tried searching around but since I don't even know what I want I didn't find it, so I thought I would ask you, sorry if this was already discussed before.I'm a software person but always liked playing hardware stuff so I got an Arduino some time ago, did some very basic stuff on the breadboard with it and so on. Anyway, I think it's time to move away from this to a more standalone project. The arduino hides a lot of stuff from me and it just isn't the real thing. I want to make a simple little project from scratch, design it on breadboard and then make my first PCB, get it manufactured and build it. Nothing fancy, just a microcontroller, USB port, few LEDs and some sensors (probably 1Wire since I already have DS18B20).So, I guess what I'm looking for is a simple, cheap uC in DIP package (breadboarding+my soldering still sucks), has USB support (I want to make software that will communicate with the uC and read sensor data / write LED status, maybe even put on some bootloader and program it over the USB but that isn't that important) and then just some basic stuff like few ADCs, few PWM pins for the LEDs and support for SPI/1Wire/I2C.I tried looking on my local electronics' shop site but from that very limited selection they have (http://www.gme.sk/sk/elektronicke-soucastky/mikroprocesory-atmel-avr-mega/552911636.html,Slovak but I guess you can understand the important stuff) I couldn't find anything that has USB support in DIP package. And since I'm unaware of a better local distributor and don't want to pay big shipping from Mouser/DigiKey just for a few micros, I'm not sure what to get.Thanks for your time guys. Maybe if there is someone here from Slovakia you could recommend me a better distributor?

author: Psi
author_rank: Super Contributor
timestamp: May 22, 2011, 11:12:59 am
content: I'm no Arduino expert (in fact i've never used one) but i'm sure the USB port on all the arduinos is not part of the microcontroller at all.It's a separate chip that appears to windows/linux/osx as a typical serial port.So the microcontroller only needs a serial port (which 99% of them do) and it can communicate over USB to a computer through this separate chip.That's probably why you're having problems finding a cheap micro you can use that has a usb port. It's typically the expensive high spec micros that come with built in USB.It's much easier to use a separate chip that does a USB->SERIAL bridge because then you don't need to worry about coding any USB protocol, which is quite complex and not something you want to do for your first project.

author: Bored@Work
author_rank: Super Contributor
timestamp: May 22, 2011, 11:23:03 am
content: Since you mentioned Atmel 8-bit AVRs, non of the USB models come in a DIP package. But that isn't the biggest problem (you can get ready-made boards). The big problem with Atmel AVRs is that you need to know a lot about USB to get the USB periphery working. A lot needs to be done in software, the AVR USB hardware is rather dumb.There are at least two libraries out there to help. One from Atmel, and one called LUFA. The Atmel one isn't worth to mention. LUFA is rather complete, but still requires you know USB and know what you are doing once you want to do something not covered by the included demos.At typical alternative is to use a normal AVR with a serial interface and connect that to some FTDI FT232R. However, the FT232R also doesn't come in a DIP package. Another alternative is to look for some cheap mobile phone "data cable" for older mobile phones. They often contain TTL level serial to USB converters. Yet another alternative is to use a typical RS232 level converter (MAX232) together with the AVR and then a cheap RS232 to USB adapter.Or look at other vendors. Microchip has the PIC18F13K50 and PIC18F14K50 in DIP with USB. Microchip also offers USB framework software for them. But again, you need to know what you are doing if you want to do anything outside what is included as demo.

author: ndictu
author_rank: Regular Contributor
timestamp: May 22, 2011, 12:08:59 pm
content: Quote from: Psi on May 22, 2011, 11:12:59 amQuote from: BoredAtWork on May 22, 2011, 11:23:03 amYep, I have the Dueamillanove and this is exactly what they use there. I already tried looking for this in DIP but couldn't find it, and I also hoped I could avoid doing that if I could find one uC with USB support.Quote from: BoredAtWork on May 22, 2011, 11:23:03 amQuote from: Psi on May 22, 2011, 11:12:59 amOh, didn't know that. I wasn't looking for a full USB stack support, just a simple FTDI-like converter so I can do text-based communication between the uC and my desktop software.Quote from: BoredAtWork on May 22, 2011, 11:23:03 amYeah, I was hoping to avoid this adapter hell. I want something simple and reusable, so when I make another board I just put on the USB connector and use a standard USB cable since I have lots of those.Quote from: BoredAtWork on May 22, 2011, 11:23:03 amAfter a quick check I found some distributor for the PICs, I could get it for 3.58eur + 5eur shipping, that's not so bad if I would order a bunch of them, maybe if I tried harder I could get better price. But I couldn't find them in the local shop where I can just go pick it up, fast and no shipping costs.Would it be hard to just do serial communication? I don't need anything else, just read current sensor values in my software, do some logging/processing and send back settings for LEDs or something like that. Just two-way text communicationSo, I guess I either go with the PICs, get a bunch of them delivered, buy a programmer and hope I can use the USB stack.Or, get whatever AVR/... that I can find locally and try to find some DIP package USB<->serial chip right?Maybe I'm just thinking the wrong way. Basically, I want something that I can prototype on a breadboard to read some 1Wire/SPI/I2C sensors, drive some LEDs and talk to my PC over USB, then I want to take that, make a schematic and PCB of the final design and get it manufactured, solder it (I don't think I can do any SMT) and have a permanent board I can use.

author: Psi
author_rank: Super Contributor
timestamp: May 22, 2011, 01:47:34 pm
content: Might be worth looking to see if there is any code available to create a USB-SERIAL bridge using an AVR thats available in DIP.You might be able to buy two DIP AVRs of the same type and use one for the USB-SERIAL bridge and one for your code.I know there's definitly code available to create a USB joystick out of an ATMEGA8 (which is available in DIP).It implements the entire USB stack in software so doesnt need any hardware USB support in the micro at all

author: Leo Bodnar
author_rank: Frequent Contributor
timestamp: May 22, 2011, 02:27:53 pm
content: PIC18F2550-I/SPAVR software emulated USB stack is low speed (1.5 Mbps)

author: sacherjj
author_rank: Frequent Contributor
timestamp: May 22, 2011, 02:44:02 pm
content: The new Arduinos (Uno and Mega) use the ATMega 8U2 chip for the USB to Serial conversion. You can use the U2 style chips for direct USB interfacing.

author: ndictu
author_rank: Regular Contributor
timestamp: May 22, 2011, 03:03:05 pm
content: Quote from: sacherjj on May 22, 2011, 02:44:02 pmI know, but those are available just in QFN32 package, which is even worse than the FT232 in SSOP. I would rather stick with just PTH parts for my first project. Also I have no idea how I would prototype with a SMD on my breadboard, I would have to get/make a breakout first.Quote from: Leo Bodnar on May 22, 2011, 02:27:53 pmWell, it's not like I need some highs-speed communication. Just a bit of data every second or so about the status of sensors, every once in a while some message about button press/... and then some response from PC.Quote from: Psi on May 22, 2011, 01:47:34 pmCouldn't I then just use one AVR that will connect to USB and do all the other work?Anyway, I'm leaning towards the PICs. I would get a few of the PIC18F???s, a programmer (PICkit, 2 or 3? I need to do some research on this) and then I could do something like this:http://www.waitingforfriday.com/index.php/Building_a_PIC18F_USB_device(hopefully).Also there seem to be some bootloaders available so after I burn that I wouldn't need the PICkit anymore and if I decide to make a modification to the already finished product I could just program it over USB, right? That would be pretty sweet.So what do you guys use on your PC-connected projects? The FT232/similar SMD chip?EDIT: Another option would be to do something like this:http://arduino.cc/en/Main/StandaloneI would get an FT232RL breakout, burn the arduino bootloader and then program it over the USB port. Then I would make the PCB with both pads for the FT232RL and headers for the breakout. Then I could try to (somehow ... that thing looks really small) solder the SSOP on there, and if I fail I'll just plug on the breakout board. Little expensive at 10eur/breakout (http://www.sparkfun.com/products/718).

author: ndictu
author_rank: Regular Contributor
timestamp: May 22, 2011, 06:14:19 pm
content: So, I guess I'm going to answer my own thread (since I hate finding threads that describe my problem exactly only to scroll down and find no resolution).I kept looking around and seems like the PIC is really my best choice if I can't use FT232R/MCP2200/*U2.There are few quite nice tutorials around like this one:http://www.pyroelectro.com/tutorials/simple_pic_usb_interface/schematic.htmlThanks for the suggestions everyone.So I just have to find a good distributor for the chips and PICkit. If you happen to know about one that has low/free international shipping please let me know.

author: tsmz
author_rank: Contributor
timestamp: May 22, 2011, 06:21:59 pm
content: I think it mainly depends on what you want to do. The arduino is great for prototyping, as it abstracts quite a bit from the hardware.Burning an arduino program to a standalone chip and programming the chip with directly C/C++ without the Arduino libraries are wholly different worlds. The first one is rather easy, as you just need to get some support parts and an AVR programmer (the arduino itself can be made into a very basic one by just loading a sketch--I think it's even included in the examples) and it allows you to re-use your arduino program. The second one involves massive amounts of datasheet reading to be able to actually program the hardware.It's not 100% clear what you really want, so recommending a solution is not that easy. I know there's a software USB implementation for almost all AVRs (can't remember the name right now, sorry), which probably could do the trick for you.If you don't need debugging support and could use the software USB solution for the AVR or get some cheap USB-TTL converter, you could go the rather cheap route of just using the arduino as a crude AVR programmer to just get the feel of programming microcontrollers with C/C++ or even Assembler directly before investing lots of money. It could well be entirely possible you don't want to mess around without the Arduino's big selection of easy-to-use libraries if you're just into small one-off projects. The Arduino uses a commonly available, yet a bit overpowered AVR, which is good for quick prototyping and helps when using memory-intensive libraries, but you would most certainly use a cheaper chip when programming it in standard C/C++. However, if you're just interested in getting a one-off project done relatively quickly as a hobby and don't care too much about cost, the Arduino as a development solution is an excellent choice. It might simply be more of a hassle to carefully choose the component you need for the price you're willing to pay than simply getting an overpowered solution for a higher price and call it a day. Really depends on your needs and whishes.

author: ndictu
author_rank: Regular Contributor
timestamp: May 22, 2011, 07:11:45 pm
content: Quote from: tsmz on May 22, 2011, 06:21:59 pmReally at the simplest level what I want is a bidirectional communication over USB where the uC says "Hey, sensor1 changed value to 42" and the software on PC responds "OK, turn LED1 on". I know I could just take another Atmega328, burn on the bootloader, program it and put it on a boards but I that keeps me in the walled-in arduino garden that abstracts away all the real things with fancy libraries. I want to move to something more low level, something that doesn't hide the entire compilation/programming phase from me.I'm prepared to spend weeks debugging my code, reading datasheets (actually, I LOVE datasheets. After years of reading the outdated, broken or simply missing documentation for most software there is I can really appreciate the few hundreds of well written pages talking about every little aspect of that chip) and burning chips. Of course I'll still use arduino for some quick ideas and test, but I don't want to get stuck at the beginner level forever.

author: Leo Bodnar
author_rank: Frequent Contributor
timestamp: May 22, 2011, 07:30:45 pm
content: Quote from: ndictu on May 22, 2011, 07:11:45 pmI think you have developed some sort of guilt syndrome and emotional attachment to some soulless piece of silicon.There are about50 manufacturers of ICs with hardware USB support.Draw a little table and see what IC suits your needs best (availability/cost/package/features/support/free projects/compilers/etc) and go for it.Atmel makesat least a few dozensof USB hardware enabled chips with AVR, 80c51 and ARM cores if you have a sweet spot for Atmel or affected by online bullies.

author: Bored@Work
author_rank: Super Contributor
timestamp: May 22, 2011, 07:58:04 pm
content: I consider the Arduino a PoS. But if you have one, then you also have everything to do normal AVR programming.Most Arduinos comes with an STK500 compatible bootloader in the AVR. I don't like bootloaders, but if you already have an Arduino or payed five times as much for an AVR with an Arduino bootloader, you can as well use it as-is.The bootloader doesn't care what kind of program you send to it. You can used it to load a normal AVR C program into it, instead of some Wiring/Processing stuff. It is a normal bootloader, that even existed before the Arduino became reality.Note: STK500 is also the name of an AVR dev board. Its programming protocol gave the STK500 protocol its name.The good old avrdude software can do the STK500 protocol under the name 'stk500v1'. Newer avrdude versions even have a programming type 'arduino', which takes care of a few Arduino-specific deviations from STK500.

author: ndictu
author_rank: Regular Contributor
timestamp: May 22, 2011, 08:15:55 pm
content: Quote from: Leo Bodnar on May 22, 2011, 07:30:45 pmI'm not sure if you misunderstood me, or I misunderstood you. I'm all for moving away from Arduino, that's the whole point of this thread.I'm still going to use arduino on some prototypes/tests, because 1) pretty much the only thing I have right now, 2) It's easy and simple, I think it's good for a quick test of something. But for serious things I'll use something else. I do not want to use them as a disposable platforms like I sometimes see on some electronics blogs where people use the board for some very simple but permanent project and need to get a new one.Of course it's not a great board, it's not supposed to be. But it helped me get started. That's why I want to do a standalone project, to move away from arduino to a next level. I'll go with the PIC, the USB support looks good enough and I can buy them around here, at least some models.

author: Leo Bodnar
author_rank: Frequent Contributor
timestamp: May 22, 2011, 11:01:24 pm
content: Quote from: ndictu on May 22, 2011, 08:15:55 pmPossibly, but no problems! I did not mean anything sinister. Piece!

author: st1
author_rank: Contributor
timestamp: May 24, 2011, 02:13:30 pm
content: I see where you are coming from,I'm studying something called "Rafeindavirkjun" in Iceland, (Low voltage engineering type of stuff).I also got my self Arduino and it dosnt really let me get my hands as dirty as I'd likeI'm trying to do pretty much what your describing, and having some problems, Since I'm not really a Software guy I went on a book search.And found a book called"Advanced PIC Microcontroller Projects in C: From USB to RTOS with the PIC 18F Series"It has an interesting USB chapter, So I hope that helps,(Oh yeah, I'm going to go see if I can set up some basic communication in Proteus) I'll get back to you

author: ndictu
author_rank: Regular Contributor
timestamp: May 24, 2011, 02:31:45 pm
content: Quote from: st1 on May 24, 2011, 02:13:30 pmGreat, thanks for the tip, I'll add it to my book ToDo listI also want to write all the stuff down and make a little reference for myself / tutorial for others once I get my project working.

author: st1
author_rank: Contributor
timestamp: May 24, 2011, 04:45:20 pm
content: Indeed! I'm working with the code and example from the book and some other places i'm trying to get this sucker to workHere's a site I got some code fromhttp://www.lvr.com/hidpage.htm#MyExampleCodeGotta pop off to work but I'll be back in a few hours to continue this little adventureoh and here's a pic of the circut, very basic but lets hope it workshttp://desmond.yfrog.com/Himg402/scaled.php?tn=0&server=402&filename=usb101.png&xsize=640&ysize=640

author: Leo Bodnar
author_rank: Frequent Contributor
timestamp: May 24, 2011, 09:39:13 pm
content: Quote from: st1 on May 24, 2011, 04:45:20 pmYou need some current limiting resistors for LEDs unless they have internal ones.

author: mikeselectricstuff
author_rank: Super Contributor
timestamp: May 25, 2011, 08:15:26 am
content: There are several PICs in DIP packages with USB. Even one with USB host (PIC24FJ64GB004).

author: Psi
author_rank: Super Contributor
timestamp: May 25, 2011, 08:52:58 am
content: Quote from: ndictu on May 22, 2011, 03:03:05 pmImplementing usb on an avr in software is pretty demanding, there isn't much power left to do other things.Plus it's convenient if you can just flash someones code into an avr and you have a nice USB-SERIAL bridge all ready to go, without needing to change anything in their code (which could be in ASM).

author: ndictu
author_rank: Regular Contributor
timestamp: May 25, 2011, 10:06:08 am
content: Quote from: Psi on May 25, 2011, 08:52:58 amSo just using it like a FT232 replacement. I might try that some time but the PICs with USB support look more practical.Quote from: mikeselectricstuff on May 25, 2011, 08:15:26 amI was looking at that one actually, might order some and use them for an android hardware accessory. But I still don't have the newest software update for that and want to avoid rooting my phone while it's in warranty.