9
\$\begingroup\$

I want to make my own modular USB device using an ATtiny45 that simply sends data to the PC over USB. I'm not reading data, so a single way ( ATtiny -> PC ) connection would be completely okay.

I am using an Arduino Uno as ISP with the standard ArduinoISP sketch loaded from within the Arduino Software. I'm thinking of using AVRDUDE to programm the ATtiny45 with the Arduino as ISP because I want to be able to use C code compiled to HEX since it is more advanced than the Arduino Programming Langue.

My basic thoughts of the circuit: enter image description here

As you can see, I want a "direct" USB connection. So far I know that i have to use a software based solution for this.

  1. I've managed SoftwareSerial to work with my ATtiny45. For this I've used the Arduino Software to Programm the ATtiny45 with following code:

    #include <SoftwareSerial.h>
    #define rxPin 3
    #define txPin 4
    SoftwareSerial serial(rxPin, txPin);
    
    void setup() {
        pinMode(rxPin, INPUT);
        pinMode(txPin, OUTPUT);
        pinMode(led, OUTPUT);     
        serial.begin(4800);
    }
    
    void loop() {
        serial.println("1");
        delay(1000);
    }
    

    Please note that I don't use Pin 3 ( yet ) but I need to define it for SoftwareSerial.

    This way, using SoftwareSerial, i was able to send data from the ATtiny directly into the TX pin of my Arduino UNO that had a blank sketch loaded onto it for this test. I was using the Serial Monitor of the Arduino Software to read the data on COM4 ( in my case ) because my PC didn't recognized any device ( COM port ) as I've tryed to hook the programmed ATtiny directly to a USB cable.

    Unfortunately I only got strange unicode characters in the Serial Monitor. I think it's because the data is in hex format or so. So I've noticed that I need to connect a USB/Serial Converter betewwn the USB and the ATtiny45... I've searched for such converters, but I don't want to use any pre-made boards, since I want all my components on a single board. I think an FTDI chip would be way too "much" for my project, isn't it ? ( It has too tiny pins to solder... )

  2. V-USB was then my second approach, since it doesn't need a USB/Serial converter ( as i know ). So to use V-USB I would need to use AVRDUDE as I mentioned earlier.

    I've found this nice example V-USB EasyLogger. It contains a circuit design and example firmware. ( C / C++ / HEX )

    The only thing I want to know is: Do i really need to make my circuit look like shown in the example ? -> enter image description here

What else do I need to know about this kind of USB connection ? ( Why do I need a USB / Serial converter ? Can I just hook up the +5 & VCC ? What components do I absolutely need ? what kind of signal do i need to send via TX ? bits ? hex ? what voltage does it needs to be ? )

Thanks for all of your answers.


UPDATE

Here are some aditional links that really helped me in some points. But I still didn't understood it fully...

the first one -> http://www.ernstc.dk/arduino/tinycom.html

and the second -> http://www.re-innovation.co.uk/web12/index.php/en/blog-75/227-attiny-arduino ( scroll down to the "Serial Output" section )

\$\endgroup\$
  • 2
    \$\begingroup\$ Yes, you do, at least if you don't want to violate the electrical limit specifications too badly. Please note that your "USB" connector in your upper diagram is grossly mislabeled. D+/D- are not distinct transmit and receive lines, but rather a bidirectional differential pair. \$\endgroup\$ – Chris Stratton Oct 7 '13 at 19:08
  • \$\begingroup\$ I'm sorry for my bad sketch. I'm really not the electric guy, but a programmer. The "drawing" was just a visualisation of my thoughs that I had in mind as I was planing this project. \$\endgroup\$ – Ace Oct 7 '13 at 19:16
5
\$\begingroup\$

You can communicate the ATtiny45 to USB directly, without a FTDI converter.

To make everything work you will need the V-USB library.

A very good example of everything working is here, that it uses the same example from EasyLogger.

The same author have some other nice tips and projects with USB and uC.

A sample circuit with the ATtiny:

schematic

simulate this circuit – Schematic created using CircuitLab

\$\endgroup\$
  • \$\begingroup\$ The asker has already looked at V-USB. \$\endgroup\$ – Ignacio Vazquez-Abrams Oct 9 '13 at 14:08
  • \$\begingroup\$ Thank you so much. I will try this as soon as I can. But first i want to ask you for the propper way to programm the ATtiny45 with the V-USB lib.. I am not sure what and how to do.. I've looked into AVRDUDE. so far I know that I have to load a bootloader??? to the tiny as well as the firmware ( hex file ?? ). And I think i need to compile the C code ( e.g. the easylogger example ) after I've changed the code for my application. right ? \$\endgroup\$ – Ace Oct 9 '13 at 18:30
  • \$\begingroup\$ and also could you please "simplify" the circuit to the bare minimum ? I get confused because of e.g. the LED... i really dont need any aditional components like LED's or Sensors at this time. \$\endgroup\$ – Ace Oct 9 '13 at 18:42
  • \$\begingroup\$ and what kind of diodes are D2 & D3 ? Schottky diodes ? \$\endgroup\$ – Ace Oct 9 '13 at 18:46
  • \$\begingroup\$ and also, whats about the Fuse bits ? and the very end of the post you've linked, they say something about fuses?? I heard that if I make something wrong with the fuses, I can ruin the tiny ? \$\endgroup\$ – Ace Oct 9 '13 at 18:58
5
\$\begingroup\$

Basically, USB is a high level communication protocol with specific requirements for signal line level driving, timing and terminating. It is not as simple as serial, it has differential data lines and NRZI encoding, required polling, handshaking, etc. That is why you need a USB/Serial adapter, or why you need a USB hardware or software implementation.

While USB uses 5V power, the signal lines are actually 3.3V to 3.6V. This is why the VUSB circuit you show uses zener diodes on those two lines. The Tiny cannot simply run at 3.3V because it cannot be clocked at the needed 16MHz at 3.3V.

The rest of the parts, R1-R3, D1, D2, and C1, C2 are bare minimum required parts. That is not really asking alot for the features you get. See this page for a list of all the projects that use vusb.

The switch, R4, and LED1 are all part of the specific data logging firmware example, and can be avoided if you don't need it/change the firmware.

\$\endgroup\$
  • \$\begingroup\$ Thank you for that answer. I knew that the data lines of usb use ~3.3V. But what I dont understand is, how exactly the USB signal is defined ? Aren't those a row of bits ? Can't I just "emulate" those bits with the right timing in a loop ( tunring signal on & off ) ? I already have the tiny use the internal osc to run at 8MHz and a serial boudrate of 4800, so the timing should not be the problem according to some blogposts i've found... \$\endgroup\$ – Ace Oct 7 '13 at 19:13
  • 1
    \$\begingroup\$ @Ace 4800 bps is 4.8 khz. USB low speed is 1.5 MHZ And there is encoding, parity, usb descriptors and everything. VUSB does "emulate" usb data, but its very very complex. \$\endgroup\$ – Passerby Oct 7 '13 at 19:20
  • 1
    \$\begingroup\$ @Ace basically, you are trying to do the equivalent of someone trying to use morse code on a computer, by tapping on the monitor. \$\endgroup\$ – Passerby Oct 7 '13 at 19:22
  • \$\begingroup\$ HAHA XD The reason why I'm using a boudrate of 4800 is explained in the second link in my update. \$\endgroup\$ – Ace Oct 7 '13 at 19:30
1
\$\begingroup\$

Far too many questions to answer in one post, but here are a few quick points:

Some microcontrollers contain a USB "endpoint" and the relevant hardware, but the Atmel site shows that the ATTiny45 does not.

Therefore you can't simply connect the microcontroller ports to a USB connector like that, because USB is a complicated bus at both the electronic and protocol level.

However as noted in the comments below you are searching along the right lines with V-USB, I have not used this so will leave others to comment.

The FTDI chips are not too hard to solder, but a proper PCB with solder resist will make it easier.

Previously I have used something like this FT232 cable:

FT232 USB cable
(source: ftdichip.com)

It has the FTDI chip embedded in the USB connector and handles all level translation whilst also supplying power. The end is a simple 0.1" pitch connector that you could connect to a pin header.

They are available on eBay for reasonable prices.

\$\endgroup\$
  • \$\begingroup\$ Here, read. \$\endgroup\$ – Ignacio Vazquez-Abrams Oct 7 '13 at 18:17
  • \$\begingroup\$ That is quite interesting. I will edit my post accordingly, perhaps somebody else can help with the V-USB specifics. \$\endgroup\$ – David Oct 7 '13 at 18:19
  • \$\begingroup\$ @David - Yes, VUSB basically emulates USB. Your post is correct in general but specifically the ATTiny family can be connected to USB through this method. \$\endgroup\$ – Gustavo Litovsky Oct 7 '13 at 18:25
  • \$\begingroup\$ Thanks for your answer. I should have mensioned that I am planing to build the project on a single board that has a USB A head ( like this one computerkabelversand.de/pictures/picturesbig/… ) on it. so basically it looks like a common USB stick. no cables, just a 3pin-jack at the other end. this is why I called it "modular". this way I'm able to programm the ATtiny individually ( it's removable ) and have my diferent sensors / devices connected to the 3 or 4 ( the RX that i dont use yet ) left pins. \$\endgroup\$ – Ace Oct 7 '13 at 19:25
  • 1
    \$\begingroup\$ Saw this today which might be of use to you: rayshobby.net/?p=7363 \$\endgroup\$ – David Oct 14 '13 at 13:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.