Go Down

Topic: ATtiny85 and Nano serial monitor (Read 387 times) previous topic - next topic

majhi

For starters, I have no idea what I'm doing.  Rudimentary experience with Arduino, but absolutely zero with ATtiny chips.

Okay now that that's out of the way, I'm trying to get a serial monitor running on an Arduino Nano from an ATTiny85.  Starting super basic because how am I supposed to get the end goal to work if I can't even get the basics to work in the first place?  Here is the schematic:



And here is the code:

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

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

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

void loop() {
  Serial.println("test");
  delay(1000);
}


After uploading to the ATtiny85, when I plug in the Nano and open the serial monitor on that particular USB port, absolutely nothing happens at all.  So what am I doing wrong?

pourduino

#1
Sep 24, 2020, 10:03 pm Last Edit: Sep 24, 2020, 10:06 pm by pourduino
I don't know about tiny85 but the internal oscillator of tiny13 needs calibration for serial communication (sometimes, depends on the chip).
Also I don't see a 0.1uF capacitor connected to the tiny. It pretty much won't work without that.
Also, in the core I use for tiny13 (MiniCore) I have to select the clock speed first, then burn the fuses and then upload the sketch. If I don't burn the fuses the MCU won't know what clock speed I want to use.

DrAzzy

So you're trying to use the nano as a passive serial adapter?

No, what you need to do for that is tie reset to ground, so the nano is always in reset and won't interfere with serial transactions.

Also, if using ATTinyCore, consider using the builtin soft serial, instead of SoftwareSerial (SoftwareSerial prevents you from using all PCINTs in exchange for being able to use any pin for RX, mine doesn't interfere with PCINTs (uses the analog comparator interrupt instead - but pins are fixed)
ATTinyCore for x4/x5/x61/x7/x8/x41/1634/828/x313 megaTinyCore for the megaavr ATtinies - Board Manager:
http://drazzy.com/package_drazzy.com_index.json
ATtiny breakouts, mosfets, awesome prototyping board in my store http://tindie.com/stores/DrAzzy

majhi

Also I don't see a 0.1uF capacitor connected to the tiny. It pretty much won't work without that.
Is this for uploading a sketch to the tiny via the Nano, or for one-way serial communication?  I've seen tutorials on using the cap to upload, but I have a USBasp that I've been using for that.

No, what you need to do for that is tie reset to ground, so the nano is always in reset and won't interfere with serial transactions.

Also, if using ATTinyCore, consider using the builtin soft serial, instead of SoftwareSerial (SoftwareSerial prevents you from using all PCINTs in exchange for being able to use any pin for RX, mine doesn't interfere with PCINTs (uses the analog comparator interrupt instead - but pins are fixed)
Okay so I tied them together without the cap and then removed the SoftwareSerial library with no change.  However that leads me to another question.  In another thread on these forums, I read that the tiny doesn't have a built-in hardware serial and so SoftwareSerial is needed.

Also this is probably a stupid question, but do I need to upload a sketch to the Nano that includes something like the following?
Code: [Select]
if (Serial.available()) {
   Serial.println(Serial.read());
}

DrAzzy

No, not the 0.1uF cap between reset and DTR of serial adapter (you need a separate serial adapter if you want that to work anyway), the 0.1uF decoupling cap which must be present between Vcc and Gnd of the tiny85 (and almost any other digital IC) for proper functioning. Decoupling caps are not optional (the datasheet implies it's not necessary on the t85. Maybe it isn't if you have good board level decoupling. But your image shows no board level decoupling for the t85... and in fact, no board at all (I assume it's on a breadboard, not dead-bug style - but either way, you need the decoupling cap, or nothing is expected to work)

Re: Serial and lack of hardware serial, refer to the ATTinyCore documentation (main doc page and part specific documentation). There is a builtin software serial implementation on fixed pins which has several advantages over SoftwareSerial. It''s all in the documentation.

If reset is tied to ground, and you have TX of target connected to tx of nano, no.

The approach you described will work if you have TX of target connected to RX of nano, but only if there's no resistor between target and nano in the serial connection (otherwise it can't' overpower the TX of the serial adapter, which is connected through a 1k resistor on most nano clones. A few omit the resistor entirely (in which case it will never work like that. But yeah, for guaranteed success, tie reset to ground, and connect TX of target to TX of nano, while you wait for a $2 serial adapter to arrive in the mail (search ebay or aliexpress for "ch340g 6pin" without quotes, and get the black ones with the little switch (not the black ones with a jumper on the 6-pin header, those have problems). Next month I will have some much nicer CH340 serial adapters for sale, based on the CH340E, and before the end of the year, I will have the Ultimate USB Serial Adapter available based on the Holtek chip available (my current order is going to include a very crude prototype - but I don't have time to route it professionally to make it fit on a reasonably sized PCB - gltta get this order placed ASAP, as I've got close to a dozen new designs that I really need to get my hands on in this order...
ATTinyCore for x4/x5/x61/x7/x8/x41/1634/828/x313 megaTinyCore for the megaavr ATtinies - Board Manager:
http://drazzy.com/package_drazzy.com_index.json
ATtiny breakouts, mosfets, awesome prototyping board in my store http://tindie.com/stores/DrAzzy

majhi

while you wait for a $2 serial adapter to arrive in the mail (search ebay or aliexpress for "ch340g 6pin" without quotes, and get the black ones with the little switch (not the black ones with a jumper on the 6-pin header, those have problems).
Okay I'm back.  Got that adapter in the mail today.  Having a lot of difficultly finding decent information online on how to use it, but at least I got a small change in results.  Loaded the following sketch onto the ATTiny and hooked it up as seen in the image.  Used this site as guidance (in French, but at least that's a language I know).

Code: [Select]
#include <SoftwareSerial.h>
SoftwareSerial mySerial(3, 4);

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

void loop() {
  mySerial.println("1");
  delay(1000);
}



So now the serial monitor reads something (that at least is progress), but it's utter garbage.  Instead of printing "1" on a new line, it just prints four backwards ? marks on the same line after each delay.  I know you said to not use SoftwareSerial, but that's all I've been able to find online so if you have other documentation, I'm all ears.

Also I wasn't too clear on the 0.1uF cap guidance on the ATTinyCore documentation page.  Is that still required with the USB-TTL adapter?

I'm sorry for being such a noob.  This project is intended to be a gift to a friend who's going through some hard times so I'm willing to sound like an idiot if it gets this project working.

pourduino

The 0.1uF cap is mandatory. Place it between VCC and GND pins of the ATtiny and as close to them as possible.

If that didn't work your clock settings might be incorrect. Did you "burn bootloader" on it?
If not, connect it to your Arduino for programming, then from 'tools' menu select 'burn bootloader'. This is necessary to do the first time you program it or when you change clock speeds. After that use shift+upload to upload the code to the tiny.

If that didn't work either then try different clock speeds. I don't have the core installed but there should be an option for changing clock/CPU speed in the 'tools' menu. Remember to do the "burn bootloader" thing every time you change clock speed

majhi

The 0.1uF cap is mandatory. Place it between VCC and GND pins of the ATtiny and as close to them as possible.

If that didn't work your clock settings might be incorrect. Did you "burn bootloader" on it?
If not, connect it to your Arduino for programming, then from 'tools' menu select 'burn bootloader'. This is necessary to do the first time you program it or when you change clock speeds. After that use shift+upload to upload the code to the tiny.

If that didn't work either then try different clock speeds. I don't have the core installed but there should be an option for changing clock/CPU speed in the 'tools' menu. Remember to do the "burn bootloader" thing every time you change clock speed
Capacitor ordered, now to wait again.  The last time I tried burning the bootloader (I've been using a USBasp for programming), it seemed to have bricked the chip because then I couldn't burn anything else onto it.  Just error messages whenever and however I tried.

pourduino

#8
Oct 13, 2020, 08:55 am Last Edit: Oct 13, 2020, 08:56 am by pourduino
We wait then.
In the meanwhile you might want to read these if you haven't. This is from ATtinyCore github page:

Quote
- When using a chip for the first time, or after changing the clock speed, EESAVE or BOD settings, you must do "burn bootloader" to set the fuses, even if you are not using the chip with a bootloader.

- Problems programming some parts for first time, especially ATtiny841/441: These parts are less forgiving of the SCK clock rate. I'm not sure why USBAsp doesn't seem to be working anymore (it used to, and I haven't changed anything), looking into options there. Arduino as ISP or USBTinyISP SLOW will program without issue.

- Chips sold as "ATtiny85" with wrong signature: Enable verbose upload output, and it will tell you what sig it actually saw. 0x1e9005 means you got scammed (all 0's or all F's is wiring problem, or bricked chip from choosing clock source that isn't present). Apparently one or more foreign sellers have been remarking the much cheaper ATtiny12 as an 85 and ripping people off on ebay/etc.

- All ATtiny chips (as well as the vast majority of digital integrated circuits) require a 0.1uF ceramic capacitor between Vcc and Gnd for decoupling.

Changing clock speed:
Changing the ATtiny clock speed, B.O.D. settings etc, is easy. When an ATTinyCore board is selected from the Tools -> Board menu, there will appear extra submenus under Tools menu where we can set several ATtiny properties:

Tools > Save EEPROM: (Boards without bootloader only - controls whether EEPROM is erased during a chip erase cycle)
Tools > Timer 1 clock: (ATtiny25/45/85 only - allows Timer1 to be clocked off the PLL for higher frequency PWM)
Tools > LTO: (Link Time Optimization makes sketches smaller, but requires AVR boards 1.6.11 or later)
Tools > B.O.D Level: (trigger voltage for Brown Out Detection - below this voltage, chip will be held in reset)
Tools > Chip: (Select the part being used )
Tools > Clock: (Select the desired clock speed)
Tools > B.O.D. Mode (active): (441, 841, 1634, 828 only - see B. O. D. section below)
Tools > B.O.D. Mode (sleep): (441, 841, 1634, 828 only - see B. O. D. section below)

After changing the clock source, BOD settings, or whether to save EEPROM on chip erase), you must do "Burn Bootloader" with an ISP programmer.
About clock speeds below 0.5MHz it says:

Quote
These options are slow enough that many ISP programmers may not be able to program them. Depending on the ISP programmer (and in some cases the firmware on it), there may be a setting or jumper to slow the SCK frequency down for programming these parts, or it may automatically figure it out.
So perhaps you selected the 128KHz clock for that chip you said is bricked.

majhi

We wait then.
In the meanwhile you might want to read these if you haven't. This is from ATtinyCore github page:

About clock speeds below 0.5MHz it says:
So perhaps you selected the 128KHz clock for that chip you said is bricked.

Hi again, the cap arrived today.  Before I burn the bootloader to another Tiny and risk making the same mistake, I want to make sure I'm doing it right this time.  I left all the settings on default when I burned the bootloader last time.


As for the maybe-maybe not bricked chip, when I hook it up to my computer via USBasp and try to upload a sketch, it doesn't give me an error signature like the one referenced, it just says "the selected serial port does not exist or your board is not connected."  I don't get this error when I upload before burning the bootloader.  Full error is here:
Code: [Select]
avrdude: error: program enable: target doesn't answer. 1
avrdude: initialization failed, rc=-1
         Double check connections and try again, or use -F to override
         this check.


avrdude done.  Thank you.

the selected serial port
 does not exist or your board is not connected



pourduino

Hmm... unfortunately it appears to be beyond me.
Maybe quote DrAzzy and ask him about it. He's the developer of AttinyCore.

majhi

Hmm... unfortunately it appears to be beyond me.
Maybe quote DrAzzy and ask him about it. He's the developer of AttinyCore.
That's okay, thanks for trying anyway!  I appreciate it.

But yeah, for guaranteed success, tie reset to ground, and connect TX of target to TX of nano, while you wait for a $2 serial adapter to arrive in the mail (search ebay or aliexpress for "ch340g 6pin" without quotes, and get the black ones with the little switch (not the black ones with a jumper on the 6-pin header, those have problems).
Arbitrarily selected something to quote.  What do you think of the above?  Thanks in advance.

Go Up