This may be on the limit of ATTiny13 possibilities, but still: is it possible to connect ATTiny13 to USB to get ADC readings (one way)?

According to this article http://www.vk2zay.net/article/211 (and my understanding of it) it seems doable, though the size of the serial communication program takes a lot of memory.

However, instead of max232 I have Micro USB to Serial Adapter from microbot (http://www.microbot.it/products/mr002-002-1.php ). (Well, I also have max3323 chip, but I would like to spare it for something else).

I am aware of this question: How can I communicate between micro-controller and PC without the use of RS232/USB Adapter?

but can't quite understand why max232 is needed in between?

UPDATE: I can't find any better datasheet on the adapter, but it uses MCP2200 chip.

UPDATE 2: as Passerby answered below, one can connect attiny directly to the microbot's adapter. For the record, these are changes I made to above mentioned project to make it work:

  1. Line 52 of the code needed "const": const unsigned long mags[10] PROGMEM = {... to make avr-gcc happy.

  2. Pin 6 of the attiny needs to be connected to RX of the adapter (attiny can use Vdd and Gnd for 5v power)

  3. I have not set any fuses with avrdude (removed them in Makefile)

  4. Baud rate in my case was 1200, and all it took to see the output of attiny was cu -l /dev/ttyACM3 -s 1200 (I guess, cu does some magic to the adapter in the beginning to set the baud rate). Baud rate has been calculated by looking at the pin 6 output with oscilloscope, which gave about 0.8 ms min pulse width. (cu is Linux/Unix serial utility, another one tried is minicom)

  5. The datasheet for the adapter is not enough. I needed to look up MCP2200 chip's specs to make better guesses

  • 1
    \$\begingroup\$ MAX232 is just a voltage level and drive circuit to translate the uC physical interface to the RS-232 interface. You do not want your uC to directly drive these signals, especially over possibly long cable. Also, the RS-232 spec allows for varying levels of voltage signal all the way up to +/- 15V or +/- 25V for special apps and these are not compatible with your 5V or 3.3V uC. \$\endgroup\$ – EwokNightmares Aug 12 '13 at 17:50
  • \$\begingroup\$ The idea is to use RS232 till the USB-to-serial adapter, and I believe it works on 5v (normal USB voltage), so level shifter is not needed. The question really is if it's possible for the USB serial adapter to read whatever attiny13 is capable to give. Actually, I want to get power from the same USB connection. \$\endgroup\$ – Roman Susi Aug 12 '13 at 18:40

The microbot adapter is a TTL (Typically 5v) based usb-to-serial adaptor. I can't tell what IC they use, but they all act the same. Just hook up the TX, RX, and GND pins to your ATTiny13, and start a regular serial communication. Or in this case, just ATTiny's TX to the adapter's RX pin and Ground pins together, as the project you link to is transmit only. You would simply replace the max232 in the circuit, with the usb adapter instead. Everything else stays the same.

The max232 is used when converting from TTL serial (0v Low, +5v High) to actual RS232 like a computer serial port would use (+3~25V Low, -3~25V High). Since you are using a usb-to-serial adaptor with TTL levels, the same that the ATTiny13 would use, the max232 is not needed. There are some usb-to-serial adaptors intended to be used with actual rs232 level stuff, so the max232 or similar chip would be useful then, but not in your case.

The 5v from the microbot adapter is directly connected to the usb 5v pin. This gives you up to 500mA to use.

  • \$\begingroup\$ I have tried it (Vdd, Gnd, Tx. The latter connected to to pin 6 (PB1), and then listened with minicom on /dev/ttyACM3, but there was nothing from there, except for some chars, when I connect RTS to Vdd. Do I need to connect CTS/RTS high/low to enable communication? I can see digital signal on PIN 6, so I guess attiny is trying to send something all the time. Shortest pulse is about 0.8ms. \$\endgroup\$ – Roman Susi Aug 16 '13 at 17:00
  • \$\begingroup\$ Same story with 'cu -l /dev/ttyACM3 -s 115200' (tried also 9600 8N1). \$\endgroup\$ – Roman Susi Aug 16 '13 at 17:12
  • \$\begingroup\$ Just occured to me, it's 1200 baud rate: 1/ 0.0008 ≅ 1200. Maybe, I need to configure the adapter somehow. \$\endgroup\$ – Roman Susi Aug 16 '13 at 17:24
  • \$\begingroup\$ @RomanSusi speed depends on what your attiny code is set for. That project sets it at baud_rate = 9600, but really as "F_CPU/256/BAUD_RATE;" so if you change the expected cpu speed the code expects, the baud speed changes \$\endgroup\$ – Passerby Aug 16 '13 at 17:27
  • 1
    \$\begingroup\$ From atmel docs: "If CKDIV8 is programmed, CLKPS [clock prescaler register] bits are reset to “0011”, giving a division factor of eight at start up." "The device is shipped with the CKDIV8 Fuse programmed." I think, it explains the oddity. \$\endgroup\$ – Roman Susi Aug 16 '13 at 18:43

AVRs have the advantage of the LUFA software stack. You can connect an AVR directly to the USB D+ and D- pins and get a reasonable semblance of USB from it. It won't meet the USB spec exactly, but it's close enough for almost all general applications.

From there, it should be pretty straightforward to use the ADC peripheral on the ATTiny and let LUFA take care of the USB side of things.

Edit: actually it looks like you want V-USB now. Sorry about the red herring. Specifically, here is an example of interfacing an ATTiny45 with an LDR to get you started.

  • \$\begingroup\$ Thanks for pointing to V-USB... I guess, I can't use attiny13 for this, because it has "1K Byte of In-System Programmable Program Memory Flash" and V-USB requires at least 2 kB of Flash memory, 128 bytes RAM... I am not sure even with attiny26, which has 2k... In a way, your message is: use more powerful MCU - attiny45 or attiny85... \$\endgroup\$ – Roman Susi Aug 12 '13 at 19:22
  • 1
    \$\begingroup\$ You can look at the DigiSpark design for an example of an ATtiny85 hooked up directly to an USB connector. You might get by with 2K of flash, but 4K would probably be a safer bet. \$\endgroup\$ – microtherion Aug 12 '13 at 20:41

There is a excellent tutorial here that may help you out.

It shows how to use a 9 dollar usb to USART bridge, or you could just build your own, and the free HyperTerminal or RealTerm terminals to communicate with AVR's.

  • 1
    \$\begingroup\$ Not sure how the tutorial can help me. I am not using neither atmega, nor USART. \$\endgroup\$ – Roman Susi Aug 16 '13 at 16:39
  • \$\begingroup\$ USART is how you communicate with max232 which then translates it so the USB can understand it. Also if you cant look at atmega code and figure out how to adapt it for you own use then you might be taking on to big of a project. \$\endgroup\$ – Wallace Aug 20 '13 at 2:27
  • \$\begingroup\$ The tutorial (if I understood it right) uses USART of the chip. There is no such thing on attiny13 (UCSRA, UDR, etc). So, in this case, to adapt means writing software implementation from scratch. Or am I missing something? \$\endgroup\$ – Roman Susi Aug 20 '13 at 3:33
  • \$\begingroup\$ Looks like your right. Sry about that, I was just posting a tutorial that was helpful to me when I used a controller plus usb. I didn't read the attiny13 datasheet before posting. \$\endgroup\$ – Wallace Aug 20 '13 at 5:34
  • \$\begingroup\$ No problem. While it's not exactly for this case, it hints on using another MCU with full-duplex USART. \$\endgroup\$ – Roman Susi Aug 20 '13 at 5:49

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.