Monday 11 February 2019

microcontroller - Firmware & Circuit of ATtiny45 direct USB 2.0 Connection


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 
    #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 )




Answer



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


No comments:

Post a Comment

arduino - Can I use TI's cc2541 BLE as micro controller to perform operations/ processing instead of ATmega328P AU to save cost?

I am using arduino pro mini (which contains Atmega328p AU ) along with cc2541(HM-10) to process and transfer data over BLE to smartphone. I...