What I have been doing for most of my projects recently is to use the Arduino programming environment, but instead of an Arduino board using a bare ATMega328P chip (sometimes other chips such as the ATTiny85) with the Atmel AVR ISP programmer. This setup works really well.
One thing I have wanted to do since I started working with Aruino/Atmel chips that I have not done yet is create a device that could be USB tethered to a computer to receive data or commands. For example, the computer could control relays or an LED display via the Atmel chip over USB. Not all Atmel chips have USB built in, but many do. I have a few ATMEGA8U2 chips, the chip several versions of Arduino uses for USB bootloading as well as the USB Serial Light Adapter product. Obviously the Arduino engineers know how to do this. I'm having a bit of trouble finding the right documentation or sample source code for this right now and I was wondering if anyone could provide a pointer if someone has already accomplished this? The source code doesn't have to be for Arduino, it can be for Atmel Studio or any compiler I can get an eval copy of.
One good hint would be the source code for the USB Serial Light Adapter. The product page at http://arduino.cc/en/Main/USBSerial says this source code is available, but there is no link to it.
Thanks, but everything listed has to do with flashing the ATMega8U2 in system on an Arduino board, using another Arduino and sending it a magic binary that someone else has written for you. I already know how to flash most Atmel chips and this is not the way I would do it anyway because I have an actual Atmel programmer and let me tell you it is a lot easier with a programmer than the method described . What I need to know is how to write the magic USB code. Over the last year I have read all the articles here on how to use the analog ports, how to do SPI, how to do I2C, etc. There is no tutorial on how to do USB. Which totally makes sense, the ATMEGA328P and ATMEGA2560 chips don't have built-in USB so it is not germane to Arduino as a programming platform.
Now when I look at some of the libraries available for Arduino I see one that is not really what I need but is at least relevant:
This allows you, using a Arduino Leonardo make your Arduino appear to Windows to be a USB mouse or keyboard. The Arduino is then an input device to the computer. What I need is for the Arduino to appear to be an output device to the computer, or better yet an input/output device. All I want to do is send a byte stream back and forth just like a serial connection so I can use a host program on the computer to tell the Arduino "what to do" for certain applications.
And I know this sounds like a job for the Serial library, but that requires a Arduino board with an ATMega328P chip with digital pins 0 and 1 connected to an ATMega16U2 running the correct firmware and that extra chip doing the USB hauling work. I'm trying to achieve this with one Atmel microcontroller, not two, and no Arduino board, just the microcontroller itself.
It boils down to this: Since we know the ATMega16U2 can do this work, what does the code on the ATMega16U2 look like?
Any other input? I wonder why no one has ever wanted to do this before.
using a Arduino Leonardo make your Arduino appear to Windows to be a USB mouse or keyboard. The Arduino is then an input device to the computer. What I need is for the Arduino to appear to be an output device to the computer, or better yet an input/output device
Mice and Keyboards ARE "input/output devices" (HIDs, or Human Interface Devices.)
Unless you want to write custom USB device drivers on the PC side of things, an HID is probably your best bet (lots of "random" electronics enumerate as HIDs.) Or there is always the serial port (CDC device class.) The USB port of a Leonardo runs as as Serial Port by default, allowing you to talk with it using Serial.xxx on the Arduino side, and "COMn" on the PC side.
What exactly did you want to accomplish? Aside from appearing as Mouse/Keyboard/Serial, the main advantage to directly accessing the USB level of the microcontroller might be to allow the arduino to appear as "Multiple endpoints." (for example, the USB-aware CPU on a TI Launchpad presents as both an HID device for programming/debugging, and a CDC device to provide a serial port for communications with the target.)
JoeN:
What I need is for the Arduino to appear to be an output device to the computer, or better yet an input/output device.
Which is exactly what the Leonardo does, using a single 32U4 chip. The code you want is in the libraries for the Leonardo.
JoeN:
All I want to do is send a byte stream back and forth just like a serial connection so I can use a host program on the computer to tell the Arduino "what to do" for certain applications.
That is what the serial library does, when compiled for a Leonardo.
How similar the 16U2 is, I don't at this point know. Do the research!
I've been thinking about this for a while too, just haven't started researching it yet. A well-written primer to USB applications would be nice indeed. I nominate Nick Gammon.
Unless it's already in Arduino for Teens that is...
Seriously though, the complexity of the host side could make this quite a rabbit hole. Especially beyond the HID class. I know some doo-dad I found online used libusb for a little help with proprietary device drivers on the PC side. It's available for Windows and Linux, possibly Mac OS X as well. That's about all I know.
SirNickity:
I've been thinking about this for a while too, just haven't started researching it yet. A well-written primer to USB applications would be nice indeed. I nominate Nick Gammon.
Unless it's already in Arduino for Teens that is...
Seriously though, the complexity of the host side could make this quite a rabbit hole. Especially beyond the HID class. I know some doo-dad I found online used libusb for a little help with proprietary device drivers on the PC side. It's available for Windows and Linux, possibly Mac OS X as well. That's about all I know.
This is exactly what I was worried about. LUFA and Atmel's code looks very very flexible, but very complex. OTOH, I found this chip from Microchip:
It's cheap, $2.33 at Digikey. It has a DLL which can be used to configure those GPIOs as inputs and output and pull data from or send data to the chip. You could tie one of the GPIO lines to an interrupt and simply have the Arduino program pull the data in when that line changes (use it as a clock). This chip only has 8 GPIOs. 9 would have been better as I see it as needing one of them for a clock which only leaves 7 for data, so maybe you transfer a nibble at a time. Or you can use the UART functionality but I think that would cause my brain to hurt. I assume you need to define some lines as output from the chip and input to the host for response codes so possibly the best idea is simply for one clock line, one data line from host to chip and one clock line, one data line from chip to host. I am convinced that for what I want this to do the data transfer rate doesn't have to be maximal at all. I haven't thought this out all the way yet but I am convinced I can get this to work, even if it is a kludge.
All I want to do is send a byte stream back and forth just like a serial connection so I can use a host program on the computer to tell the Arduino "what to do" for certain applications.
All I want to do is send a byte stream back and forth just like a serial connection so I can use a host program on the computer to tell the Arduino "what to do" for certain applications.
What we want is to "rate" it as a good deal for everyone. That is why I recommended to design with a "real" Arduino or a licensed clone and then to migrate to naked chips or inexpensive imports.
The small profit made from real and licensed boards fund research, create jobs, and keeps this forum afloat. Atmel could care less where you buy their chips! The Arduino was never intended to be a consumable product... rather, it is an educational and prototyping product. Some do use 'em in low-volume art and projects, but for anything where the parts are not coming back home to be recycled, the non-licensed Chinese products made from the open hardware designs are adequate. It is simply a matter of economics. No doubt, Adafruit, Sparkfun, and Arduino could be in this market, but there is no significant profit to support the products... therefore, their closest products are 2x to 3x the price and a few dollars less than the authentic Arduino - but these are licensed so Arduino does get a little benefit.
My bottom line - if you are a newbie, noobie, or simply do not know much about Arduino, hardware, and C++ then you are advised to stay away from the inexpensive imports... you will NOT get any support from China. You need to be prepared for the occasional dud... so, if you need 10, buy 12. My experience across over 50 is one bad cold-solder joint. But, your results could be worst!
Edit - CAVEAT:
We are heading into January and the Chinese New Year. Things stop in China during this time and orders become delayed and sometime lost. I would recommend to NOT ORDER during this time. The coming Chinese New Year is 2014-01-31. It is 31 days away. If you order, order very soon or wait until mid-February.
mrburnette:
What we want is to "rate" it as a good deal for everyone. That is why I recommended to design with a "real" Arduino or a licensed clone and then to migrate to naked chips or inexpensive imports.
Agree, I have three or four "genuine" Arduinos which I use for prototyping then I use eBay boards for my final gadgets.
OTOH every beginner I see these days seems to own the cheapest possible 'kit' they could find on eBay (usually a box full of unidentified parts with no manual and no way to know what library they need to drive the obligatory LCD screen...)
mrburnette:
Edit - CAVEAT:
We are heading into January and the Chinese New Year. Things stop in China during this time and orders become delayed and sometime lost. I would recommend to NOT ORDER during this time. The coming Chinese New Year is 2014-01-31. It is 31 days away. If you order, order very soon or wait until mid-February.
Yep. eBay delivery times have been abysmal lately...4 to 6 weeks for everything since mid-October.
"genuine" Arduinos which I use for prototyping then I use eBay boards for my final gadgets.
Yes, me too! Seems the best compromise between sane development w/support and low-cost consumable projects. Although, I still get a kick from screwing with insanity: http://www.instructables.com/id/Build-A-FLAT-duino/
I return to the soldering station periodically - usually after the burns heal
"genuine" Arduinos which I use for prototyping then I use eBay boards for my final gadgets.
Yes, me too! Seems the best compromise between sane development w/support and low-cost consumable projects. Although, I still get a kick from screwing with insanity: http://www.instructables.com/id/Build-A-FLAT-duino/
I return to the soldering station periodically - usually after the burns heal
Ray
If that guy was going either for small or flat he failed at the first possible moment by selecting a DIP. The 328P is available in much smaller packages like the QFN and you can get adapters you can solder them to smaller than that thing which headers can be dropped onto no problem. And if you are willing to make your own PCB you can go smaller still.
If that guy was going either for small or flat he failed at the first possible moment by selecting a DIP. The 328P is available in much smaller packages like the QFN and you can get adapters you can solder them to smaller than that thing which headers can be dropped onto no problem. And if you are willing to make your own PCB you can go smaller still.
I'm pretty certain that guy was making a point that anyone can use simple to obtain materials to build a test 'n prototype board that is essentially 1/2 the size of common protype boards, equivalent to the same square area as the LC Studio SD board. Since the headers are horizontal instead of vertical, the author must have seen some humor at the moment and called it FLAT. No attempt was being made to create anything small for a record book, or even anything pretty. Just a fun weekender for Arduino fans who would shy away from QFN and adapters and such.
I took delivery of two of these today. It turns out that a Leonardo compatible clone is just the ticket for a project that I am going to do next, a PID controller for a reflow oven:
I already sent up the sample software. No way to test it yet, I am waiting on one of the parts still. But it took it just fine.
This Sparkfun Leonardo clone clone seems very pirated to me. Not only are they using the Sparkfun schematic, which I guess is kosher, they actually have the Sparkfun logo on them, which I am certain is not.