Author Topic: Attiny85: no serial output?  (Read 7201 times)

0 Members and 1 Guest are viewing this topic.

Offline phennesseyTopic starter

  • Contributor
  • Posts: 36
  • Country: us
Attiny85: no serial output?
« on: January 19, 2020, 12:43:48 am »
I’m seriously confused.

I have the Sparkfun Tiny AVR usb programmer for my attiny85. I’m testing a rotary encoder, and I want to see its output on my computer. No serial output method I could find would work, despite these sources saying they would.

But then, the Sparkfun AVR information page says the attiny85 doesn’t support serial output. Wait, what?

Who’s got it wrong? Anyone have experience with this? I have the chip in my breadboard, with all 8 lines connected to the programmer, and i can reprogram the chip while it’s on the breadboard. I set pins 3 and 4 to RX/TX. I even switch the chip to 8mhz mode (as some have suggested).

Still nothing. I’m at my wits end. All I want to do is test a rotary encoder so I can troubleshoot it (I’ll need an RC filter to help with debouncing, I just want to be sure that’s the problem and not my code.)

So. If you’ve successfully gotten serial output from this chip and this programmer, please let me know!

I’ll post more info and images soon.
« Last Edit: January 19, 2020, 12:49:29 am by phennessey »
 

Offline ataradov

  • Super Contributor
  • ***
  • Posts: 11906
  • Country: us
    • Personal site
Re: Attiny85: no serial output?
« Reply #1 on: January 19, 2020, 01:01:48 am »
ATtiny85 does not have a dedicated UART peripheral. It has something called USI (Universal Serial Interface), which can be used to accelerate multiple serial protocols.

Or alternatively you could just bit-bang the UART.

I don't know about support for any of this in Arduino-like software though.
Alex
 

Offline phennesseyTopic starter

  • Contributor
  • Posts: 36
  • Country: us
Re: Attiny85: no serial output?
« Reply #2 on: January 19, 2020, 01:46:57 am »
No idea how to “bit bang” or how to even interface with this. I need very specific step-by-step instructions. I am, after all, a beginner.
 

Offline james_s

  • Super Contributor
  • ***
  • Posts: 21611
  • Country: us
Re: Attiny85: no serial output?
« Reply #3 on: January 19, 2020, 01:51:04 am »
Start with a simpler project, or use a mega328 based arduino. You'll learn more by going through a series of tutorials from start to finish than you will asking for someone to do all the work for you and lay it out in neat tidy steps. Bit banging is a very basic concept that you will encounter often. Search engines are your friend.
 

Offline ataradov

  • Super Contributor
  • ***
  • Posts: 11906
  • Country: us
    • Personal site
Re: Attiny85: no serial output?
« Reply #4 on: January 19, 2020, 01:51:16 am »
Well, you perhaps picked the wrong device for a beginner. ATtiny85 is very cramped and hard to debug. But the limited memory size pretty much lets you just write the program and reasonably expect it to work right away if you know what you are doing.

I'm sure there are tutorials on this somewhere on the internet.
Alex
 

Offline phennesseyTopic starter

  • Contributor
  • Posts: 36
  • Country: us
Re: Attiny85: no serial output?
« Reply #5 on: January 19, 2020, 02:14:00 am »
I never asked anyone here for instructions. I merely stated that i needed them. Tutorials are definitely right up my alley.
 

Offline Nominal Animal

  • Super Contributor
  • ***
  • Posts: 7198
  • Country: fi
    • My home page and email address
Re: Attiny85: no serial output?
« Reply #6 on: January 19, 2020, 02:14:36 am »
The Arduino environment has two libraries you can use to implement serial output: SoftwareSerial (was also known as NewSoftSerial), and AltSoftSerial.

If you only need to send data from ATtiny85 to your computer, the SoftwareSerial will suffice.  (It is basically okay for whenever you know which side is sending and the other receiving, and data only flows in one direction at a time.)
It should be included with your Arduino installation automatically.

If you need bidirectional data transfers, you should use AltSoftSerial, as it allows full duplex (simultaneous send and receive) communications.  (AltSoftSerial is maintained by Paul Stoffregen, the Teensy developer and half of PJRC.com.)

Pick a baud rate, and set it for both the serial dongle, and in your Arduino code.  Remember that TX on one end is connected to RX on the other; i.e. the wires "cross".

The example sketch you can try with the ATTiny85 is as follows:
Code: [Select]
#include <SoftwareSerial.h>

SoftwareSerial mySerial(3, 4);  // rx, tx

void setup()
{
    mySerial.begin(9600); // 9600 baud
}

void loop()
{
    mySerial.println("Ping!"); // Write "Ping!" and newline to mySerial,
    delay(1000);  // and wait 1000ms = 1 second.
}
This is set to 9600 baud, but you can try other rates as well.
 

Offline Renate

  • Super Contributor
  • ***
  • Posts: 1460
  • Country: us
Re: Attiny85: no serial output?
« Reply #7 on: January 19, 2020, 03:35:08 am »
Yeah, the ATTiny85 is a strange beast.
I guess that they figured with so few pins you wouldn't use a crystal and without a crystal you wouldn't use serial data.

If you are just transmitting serial (especially fixed messages) you can do it easily using the USI as an SPI equivalent.
If you want to transmit "Hello", that's five characters of 10 bits (including start and stop), 50 bits total.
7 bytes of the proper SPI data will be the exact same thing. (You'll have an extra 6 bits of high at the end).

Ok, you have to sit down with a piece of paper to figure out the bits (or write a program).
I used this technique on a 4 button box that barks out canned phrases as a remote control.
 

Offline james_s

  • Super Contributor
  • ***
  • Posts: 21611
  • Country: us
Re: Attiny85: no serial output?
« Reply #8 on: January 19, 2020, 04:27:29 am »
The attiny85 was never part of the Arduino vision, support was added later and it comes with caveats given the limitations of the chip. The 8 pin attiny series was designed for simple embedded projects that need only a few pins, it's surprising how much you can implement with so few pins if you are clever. There is no onboard UART because it is not typically needed, few commercial products use RS232 anymore for anything other than debugging, if you're designing a product around the attiny and you need serial debugging, you can use a larger AVR for development and then move over to the tiny when you're finished.
 

Offline phennesseyTopic starter

  • Contributor
  • Posts: 36
  • Country: us
Re: Attiny85: no serial output?
« Reply #9 on: January 19, 2020, 05:25:03 am »
I did exactly this, but I’m not sure it’s working right. I’ll post photos of my setup so you can offer more feedback. I only want to read from the chip. I don’t need to send data to it.
 

Offline sleemanj

  • Super Contributor
  • ***
  • Posts: 3051
  • Country: nz
  • Professional tightwad.
    • The electronics hobby components I sell.
Re: Attiny85: no serial output?
« Reply #10 on: January 19, 2020, 05:33:12 am »
If I was better at marketing, everybody would know about my Arduino core (fork) which is especially tuned up for these very tiny tinys....

https://github.com/sleemanj/optiboot/blob/master/dists/README.md

with my core, Serial.print() should work out of the box, TX/RX pins as below



~~~
EEVBlog Members - get yourself 10% discount off all my electronic components for sale just use the Buy Direct links and use Coupon Code "eevblog" during checkout.  Shipping from New Zealand, international orders welcome :-)
 
The following users thanked this post: edavid, Habropoda, phennessey

Offline phennesseyTopic starter

  • Contributor
  • Posts: 36
  • Country: us
Re: Attiny85: no serial output?
« Reply #11 on: January 22, 2020, 12:58:10 am »
How do you edit the core?
 

Offline Psi

  • Super Contributor
  • ***
  • Posts: 10386
  • Country: nz
Re: Attiny85: no serial output?
« Reply #12 on: January 22, 2020, 01:30:09 am »
I did exactly this, but I’m not sure it’s working right. I’ll post photos of my setup so you can offer more feedback. I only want to read from the chip. I don’t need to send data to it.

Can you post your code?
The example Nominal Animal posted should work for you.

Some traps for young players.

- Tx and Rx connections can end up reversed because some manufactures label them correctly and others label them wrong.
- Baud rate maybe wrong due to clock speed being wrong. (or at least not what the code expects it to be)
Greek letter 'Psi' (not Pounds per Square Inch)
 

Offline sleemanj

  • Super Contributor
  • ***
  • Posts: 3051
  • Country: nz
  • Professional tightwad.
    • The electronics hobby components I sell.
Re: Attiny85: no serial output?
« Reply #13 on: January 22, 2020, 04:50:18 am »
How do you edit the core?

Do you mean how to install a third party core?  In that case, File > Preferences, "Additional Boards Manager URLs", click the window icon on that line and paste the third party core's json url.  Close preferences, Tools > Board > Board Manager find the core you want, install.  Choose Board from Tools > Board after installing.

Do you mean after you have installed a third party core and you want to change it for some reason?  File > Preferences, look down at the bottom of the window where it says "More preferences can be edited...." click the location of preferences.txt and it should open up the folder containing that, inside there is a packages folder, open the packages folder and you can drill-down into the installed core files.   But, be aware that if you update the installed core, your changes would be nuked.
~~~
EEVBlog Members - get yourself 10% discount off all my electronic components for sale just use the Buy Direct links and use Coupon Code "eevblog" during checkout.  Shipping from New Zealand, international orders welcome :-)
 

Offline hsn93

  • Regular Contributor
  • *
  • Posts: 114
  • Country: bh
Re: Attiny85: no serial output?
« Reply #14 on: January 22, 2020, 10:50:30 am »
I never asked anyone here for instructions. I merely stated that i needed them. Tutorials are definitely right up my alley.

fabacademy has one simple code for bit banging
https://fabacademy.org/2019/docs/FabAcademy-Tutorials/week08_embedded_programming/attiny_c.html

there is source codes here:
http://academy.cba.mit.edu/classes/embedded_programming/index.html
-------------------------------------
 

Online westfw

  • Super Contributor
  • ***
  • Posts: 4350
  • Country: us
Re: Attiny85: no serial output?
« Reply #15 on: January 25, 2020, 09:37:33 am »
Sleemanj: how’d you wind up with all that “core” code in an optiboot fork?

 

Offline sleemanj

  • Super Contributor
  • ***
  • Posts: 3051
  • Country: nz
  • Professional tightwad.
    • The electronics hobby components I sell.
Re: Attiny85: no serial output?
« Reply #16 on: January 25, 2020, 08:19:44 pm »
Sleemanj: how’d you wind up with all that “core” code in an optiboot fork?

Ostensibly because the original purpose was principally as a distribution of my optiboot fork.  As is common with this sort of thing, it grew a bit. 
~~~
EEVBlog Members - get yourself 10% discount off all my electronic components for sale just use the Buy Direct links and use Coupon Code "eevblog" during checkout.  Shipping from New Zealand, international orders welcome :-)
 

Offline phennesseyTopic starter

  • Contributor
  • Posts: 36
  • Country: us
Re: Attiny85: no serial output?
« Reply #17 on: January 27, 2020, 04:17:07 am »
Here's my setup:

   Rotary encoder with A/B pins connected to pins 2/3 on the attiny85
   All attiny pins connected to Tiny AVR Programmer with jumpers
   Attiny clock set to 8mhz

915444-0

Here's some sample code I tried -- not to interface with the encoder, just to get the chip to send a simple serial signal so I could confirm whether it even could work at all, so I found this code in another forum:

Code: [Select]
#include <SoftwareSerial.h>

SoftwareSerial Serial(3, 4);

void setup() {
  Serial.begin(9600);
}

void loop() {
  Serial.println("Hello World!"); //Print this once every second.
  delay(1000);
}

When I open the serial monitor, I see no activity. I tried different pins, different baud rates, different MHz settings (1 and 8, no higher!). Still...nothing.

I have another project (called RGB_trig) where I use the rotary encoder (successfully, I might add!) to adjust an RGB LED. When I try to combine this serial setup with the code (even just the #include at the top) and include a serial.println to be called when the rotary encoder triggers, I get this error:

Code: [Select]
libraries/SoftwareSerial/SoftwareSerial.cpp.o (symbol from plugin): In function `SoftwareSerial::read()':
(.text+0x0): multiple definition of `__vector_2'
sketch/RGB_trig.ino.cpp.o (symbol from plugin):(.text+0x0): first defined here
collect2: error: ld returned 1 exit status
Multiple libraries were found for "SoftwareSerial.h"
 Used: /Applications/Utilities/Arduino.app/Contents/Java/hardware/arduino/avr/libraries/SoftwareSerial
exit status 1
Error compiling for board ATtiny25/45/85.

Why can't it compile all of a sudden? I don't have multiple libraries of SoftwareSerial.h. I checked that directory, and it's just one file. Is this because I have an interrupt set up for the encoder? I use an interrupt so that I don't have to rely on a loop to adjust the LED brightness. Let me know if you all need to see my code for this.

Thoughts? All I want to do is trigger a serial print output when the switch is triggered so I can study its output and determine if it needs to be debounced.
« Last Edit: January 27, 2020, 04:36:35 am by phennessey »
 

Offline sleemanj

  • Super Contributor
  • ***
  • Posts: 3051
  • Country: nz
  • Professional tightwad.
    • The electronics hobby components I sell.
Re: Attiny85: no serial output?
« Reply #18 on: January 27, 2020, 05:02:32 am »
Here's my setup:

Do you actually have a USB Serial adapter connected?   

I think you may be perhaps thinking your programmer can do that, which is unlikely.

You should disconnect your programmer, and connect a USB Serial adapter (UART, not RS232 of course) in order to talk/listen to your chip over serial after programming.



Quote
Is this because I have an interrupt set up for the encoder?

Yes both SoftwareSerial and your own code are trying to use the same interrupt, which is no good.
~~~
EEVBlog Members - get yourself 10% discount off all my electronic components for sale just use the Buy Direct links and use Coupon Code "eevblog" during checkout.  Shipping from New Zealand, international orders welcome :-)
 
The following users thanked this post: phennessey

Offline phennesseyTopic starter

  • Contributor
  • Posts: 36
  • Country: us
Re: Attiny85: no serial output?
« Reply #19 on: January 27, 2020, 05:06:52 am »
Crap.

I thought this thing was more capable...guess not. Looks like I’ll be getting a separate serial adapter!
 

Offline ataradov

  • Super Contributor
  • ***
  • Posts: 11906
  • Country: us
    • Personal site
Re: Attiny85: no serial output?
« Reply #20 on: January 27, 2020, 05:15:29 am »
Separate serial adapter will not help here. Your MCU still can't output UART.  You need to make a thing that is similar to SoftwareSerial, but does not use interrupts. This is pretty easy for TX-only.
Alex
 

Offline phennesseyTopic starter

  • Contributor
  • Posts: 36
  • Country: us
Re: Attiny85: no serial output?
« Reply #21 on: January 27, 2020, 05:35:30 am »
You need to make a thing that is similar to SoftwareSerial, but does not use interrupts. This is pretty easy for TX-only.

How do I do that?
 

Offline ataradov

  • Super Contributor
  • ***
  • Posts: 11906
  • Country: us
    • Personal site
Re: Attiny85: no serial output?
« Reply #22 on: January 27, 2020, 05:42:14 am »
I don't have any readily available code. The basic idea is to set a GPIO pin high and low according to the UART protocol and your data. Use blocking loops to generate bit-long delays.

Or better yet, figure out how to use USI and use that.
Alex
 

Offline sleemanj

  • Super Contributor
  • ***
  • Posts: 3051
  • Country: nz
  • Professional tightwad.
    • The electronics hobby components I sell.
Re: Attiny85: no serial output?
« Reply #23 on: January 27, 2020, 06:28:18 am »
Separate serial adapter will not help here.

Yes it will.  That appears to be the poster's primary problem (ignoring the interrupt conflict) as even without the conflict they are unable to get any serial output when using SoftwareSerial - because they don't have a USB-Uart connected, only an ISP.

Quote
You need to make a thing that is similar to SoftwareSerial, but does not use interrupts.

Or, they could as I posted above, use my core.  Which provides "Serial" ready to roll on the pins indicated above and uses the Analog Comparator for it's interrupts, which should work out of the box with their code.

Or, they could rewrite their encoder handling so it does not use pin change interrupts (which SoftwareSerial does), either use the External Interrupt pin (85 only has one) or not use interrupts.

@phennessey

Install my core, as above.

Remove this

    #include <SoftwareSerial.h>
    SoftwareSerial Serial(3, 4);

you don't need it with my core.  Put your RX/TX on the pins indicated in my image above, connected to your USB-Serial (Uart) device, move your encoder to some other pins if you have that connected to those, adjust code to suit.




~~~
EEVBlog Members - get yourself 10% discount off all my electronic components for sale just use the Buy Direct links and use Coupon Code "eevblog" during checkout.  Shipping from New Zealand, international orders welcome :-)
 
The following users thanked this post: phennessey

Offline phennesseyTopic starter

  • Contributor
  • Posts: 36
  • Country: us
Re: Attiny85: no serial output?
« Reply #24 on: January 28, 2020, 03:56:56 am »
I'm not sure what kind of cable I actually need. Would a USB to TTL Serial Cable work?

I need to debug the encoder while its plugged into the Attiny85. Is it really impossible to do that while it uses pin interrupts?

The programmer I'm using clearly indicates serial in and out (MOSI, MISO). Why can't these work for me? https://cdn.sparkfun.com/assets/c/c/3/1/8/52715ae8757b7f30048b4567.png

What do you think about the information in this article?

https://www.hackster.io/porrey/easy-serial-on-the-attiny-2676e6
« Last Edit: January 28, 2020, 04:06:49 am by phennessey »
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf