Author Topic: First Foray into building microcontroller boards with ATtiny4  (Read 1498 times)

0 Members and 1 Guest are viewing this topic.

Offline LoveLaikaTopic starter

  • Frequent Contributor
  • **
  • Posts: 558
  • Country: us
First Foray into building microcontroller boards with ATtiny4
« on: September 17, 2021, 03:42:02 pm »
As a way to try something new at hand, I decided to try my hand at wiring a microcontroller board. This is just my first attempt, but I hope that with enough practice, I can move up to larger, perhaps more complicated boards like Arduinos and the like. A lot of people seemed to have written about how to work with microcontrollers; I figured it's about time I learn how to do it myself.

As such, I was wondering if I could get some critique on my first design? My microcontroller is the ATtiny4 microcontroller. It only has 6 pins, so I thought that it would be manageable. It's going to be powered via USB. I also discovered that it is programmed through TPI, so I followed these instructions on how to set it up to be programmed via USB (which unfortunately also seems to require an Arduino; perhaps I made a wrong design choice here). As for the purpose of this microcontroller...there really isn't one. I don't work with microcontrollers much, so I didn't really design it with a set purpose in mind. Nevertheless, I was wondering if my first design like this is...adequate?
 

Offline Renate

  • Super Contributor
  • ***
  • Posts: 1460
  • Country: us
Re: First Foray into building microcontroller boards with ATtiny4
« Reply #1 on: September 18, 2021, 12:26:28 am »
On the breakout: If you don't have to have compatibility with some thing I would definitely do 1=Gnd, 2 to n-1=gpio n=Vcc. (Although some could argue that 2 should be Vcc.)
You're using the ATTiny4 to bit-bop USB? People do do that, but I've never done it. I prefer something with built-in USB like the ATMega32u4. Ok, that is not in as convenient a packagefor hand soldering.
Where did you get 1k for R2? Normally the low-speed ID resistor is 1.5k
I'd rather run a LDO 3.3V regulator than to drop a zener and hope that the voltage is right. Incoming USB Vcc tends to be miserable and all over the place.
 

Offline Hiemal

  • Regular Contributor
  • *
  • Posts: 76
  • Country: us
Re: First Foray into building microcontroller boards with ATtiny4
« Reply #2 on: September 18, 2021, 01:24:03 am »
Yeah, as far as first foray's into micros go, the very lean/minimal micros tend to be a bit less user friendly compared to larger ones like the usual atmega328 series. Not impossible, sure!

I think you've also wired up your Vcc incorrectly? With the schottky (1N5819) how you have it, it'll block the USB voltage from reaching your micro unless that's what you intended.

The only thing I'd maybe suggest adding (within my pool of knowledge) is a polyfuse of some kind in series with your Vcc, in case you accidentally short one of your pins. Might help save your uC. Most Chinese arduino boards substitute a diode in place of the fuse.

As an alternative to the zeners, you could also use diode clamps, as shown in the photo I attached. Gives you the added benefit of clamping the negative rail as well to your diode's forward voltage.

That does make me wonder, is there any other benefit to using a zener clamp vs. a diode clamp? Would a zener be slower, or vice versa?

 

Offline sleemanj

  • Super Contributor
  • ***
  • Posts: 3020
  • Country: nz
  • Professional tightwad.
    • The electronics hobby components I sell.
Re: First Foray into building microcontroller boards with ATtiny4
« Reply #3 on: September 18, 2021, 02:37:16 am »
The article you linked is about the Tiny85, not the Tiny4, they are massively different beasts.

You are not going to be doing any USB on the Tiny4, it has 512 bytes of program memory (Flash) and 32 Bytes of Ram.

You can forget about a bootloader or you'll have no space left to do anything.  Just use a USBAsp which supports TPI.  Lose the USB port.


~~~
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: WattsThat

Offline LoveLaikaTopic starter

  • Frequent Contributor
  • **
  • Posts: 558
  • Country: us
Re: First Foray into building microcontroller boards with ATtiny4
« Reply #4 on: September 18, 2021, 04:01:02 am »
On the breakout: If you don't have to have compatibility with some thing I would definitely do 1=Gnd, 2 to n-1=gpio n=Vcc. (Although some could argue that 2 should be Vcc.)
You're using the ATTiny4 to bit-bop USB? People do do that, but I've never done it. I prefer something with built-in USB like the ATMega32u4. Ok, that is not in as convenient a packagefor hand soldering.
Where did you get 1k for R2? Normally the low-speed ID resistor is 1.5k
I'd rather run a LDO 3.3V regulator than to drop a zener and hope that the voltage is right. Incoming USB Vcc tends to be miserable and all over the place.

Thanks. I was just following the guide I linked in my post. While the processor is different, since it used the same programming interface,  I thought I could just map it the same way accordingly using the same components. This is all just practice,  I have no real plans to make it, but I figured it'd be good to learn how to build my own boards like this.
 

Offline LoveLaikaTopic starter

  • Frequent Contributor
  • **
  • Posts: 558
  • Country: us
Re: First Foray into building microcontroller boards with ATtiny4
« Reply #5 on: September 18, 2021, 04:03:58 am »
The article you linked is about the Tiny85, not the Tiny4, they are massively different beasts.

You are not going to be doing any USB on the Tiny4, it has 512 bytes of program memory (Flash) and 32 Bytes of Ram.

You can forget about a bootloader or you'll have no space left to do anything.  Just use a USBAsp which supports TPI.  Lose the USB port.

So, because of limitations, the ATtiny4 can't be programmed via USB? I thought my guide showed how to make it work. Different processors, but same pin out and same way to program it, TPI.

 

Offline LoveLaikaTopic starter

  • Frequent Contributor
  • **
  • Posts: 558
  • Country: us
Re: First Foray into building microcontroller boards with ATtiny4
« Reply #6 on: September 18, 2021, 04:07:42 am »
Yeah, as far as first foray's into micros go, the very lean/minimal micros tend to be a bit less user friendly compared to larger ones like the usual atmega328 series. Not impossible, sure!

I think you've also wired up your Vcc incorrectly? With the schottky (1N5819) how you have it, it'll block the USB voltage from reaching your micro unless that's what you intended.

The only thing I'd maybe suggest adding (within my pool of knowledge) is a polyfuse of some kind in series with your Vcc, in case you accidentally short one of your pins. Might help save your uC. Most Chinese arduino boards substitute a diode in place of the fuse.

As an alternative to the zeners, you could also use diode clamps, as shown in the photo I attached. Gives you the added benefit of clamping the negative rail as well to your diode's forward voltage.

That does make me wonder, is there any other benefit to using a zener clamp vs. a diode clamp? Would a zener be slower, or vice versa?

Thanks for replying. Yeah, I just followed the guide to program it via USB. The Schottky is probably reversed. Thanks for your notes on the polyfuse. Circuit protection is always good. I also like your idea with the diodes. It makes much more sense than with the Zener.

With such a limited board, what can you do with it? All I can think of is breaking it out to headers, but from there, not much else
 

Offline LoveLaikaTopic starter

  • Frequent Contributor
  • **
  • Posts: 558
  • Country: us
Re: First Foray into building microcontroller boards with ATtiny4
« Reply #7 on: September 18, 2021, 04:11:23 am »
Thanks also for your suggestions about the regulator. I suppose that's why Arduinos have these buck regulators on them. They're handy.

About the break outs, I broke them out on the three headers (PB, Breakout, and TPI) and I guess I can rearrange the pins to something more logical, but after that, what else? I can't begin to think about what I can do with it.
 

Offline sleemanj

  • Super Contributor
  • ***
  • Posts: 3020
  • Country: nz
  • Professional tightwad.
    • The electronics hobby components I sell.
Re: First Foray into building microcontroller boards with ATtiny4
« Reply #8 on: September 18, 2021, 06:18:58 am »


So, because of limitations, the ATtiny4 can't be programmed via USB?



Correct, no chance. 
~~~
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 jmelson

  • Super Contributor
  • ***
  • Posts: 2758
  • Country: us
Re: First Foray into building microcontroller boards with ATtiny4
« Reply #9 on: September 18, 2021, 03:24:38 pm »
The ATTINY-13A is very inexpensive, 8-pin SOIC and can be prograamed with the Sparkfun tiny AVR programmer that costs about $16.
I built a successful project around it.  It also can be run on 5 V.

Jon
« Last Edit: September 18, 2021, 03:28:25 pm by jmelson »
 

Offline LoveLaikaTopic starter

  • Frequent Contributor
  • **
  • Posts: 558
  • Country: us
Re: First Foray into building microcontroller boards with ATtiny4
« Reply #10 on: September 18, 2021, 06:20:31 pm »
I thought that since the ATtiny85 used the same TPI, rewiring it would work. So, how would you go about programming it then, and what would you use it for out of curiosity?
 

Offline LoveLaikaTopic starter

  • Frequent Contributor
  • **
  • Posts: 558
  • Country: us
Re: First Foray into building microcontroller boards with ATtiny4
« Reply #11 on: September 18, 2021, 06:28:03 pm »
It looks like Sparkfun has a lot of stuff to program the AVR. Maybe one of those can be used to program the ATtiny4. From what I read, SPI can be used to program anything ATtiny. So you need one of those sparkfun boards to work?

Thanks for your suggestion for the ATtiny-13a. Maybe that will be my next faux project, or maybe I'll just try something with USB capability.
 

Offline sleemanj

  • Super Contributor
  • ***
  • Posts: 3020
  • Country: nz
  • Professional tightwad.
    • The electronics hobby components I sell.
Re: First Foray into building microcontroller boards with ATtiny4
« Reply #12 on: September 18, 2021, 09:18:23 pm »
T85 uses SPI, T4 uses TPI

Some programmers support both.

That aside just because a programming interface is the same doesn't mean the code from one chip will work on another, and it sure won't for an 85 to a 4 - I can put petrol in both a honda ute and into a honda moped, but you wouldn't expect to be able to fit a concrete mixer in the grocery basket.

I suggest you start with replicating an Arduino Uno/Nano and understanding how that works before you start with the Tiny series, especially the 4/5/9/10.  The 85 and 13A are better entries into the Tinys
~~~
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 Doctorandus_P

  • Super Contributor
  • ***
  • Posts: 3322
  • Country: nl
Re: First Foray into building microcontroller boards with ATtiny4
« Reply #13 on: September 18, 2021, 10:02:34 pm »
My advise is to steer away from these very small microcontrollers, unless there is a specific reason to use them.

The number of pins has nothing to do with the complexity of the device.
If you want to stay with the AVR's, then the atMEGA328xx is a quite reasonable compromise.
You can stick a single IC in a breadboard and run it if it's internal RC oscillator, or buy small breakout boards such as the "arduino nano". Don't be afraid of either the "arduino" nor the "nano" part. First, the uC is reprogramable by any AVR programmer, so you don't have to fiddle with bootloaders and their peculiarities. The advantage of a normal programmer is that it **just works** (tm) No fiddling with buttons to get it into bootloader mode. No troubles by accidentally erased bootloaders, and other problems with those things.

Also don't be afraid of the "nano" part. It's not so small, it fits in any regular breadboard.

atMEGA328 is factory programmed to run at 1MHz from it's internal RC oscillator. You can just stick it in a breadboard, add two decoupling capacitors and power and it runs. Add a few "dupont" wires for the programmer and you're off having fun with adding more hardware and writing software for it.
And it also runs from less then 2V to about 5V5. You can run it directly from two AA's, 5V tapped from an USB port (or programmer), or a single Li-Ion without even a voltage regulator needed.

A few words of caution:
* Using a powered USB hub between your PC and electronics hobby is always advised. You'd much rather see smoke coming out of an USB hub, then out of your PC.
* Li-Ion cells always need some protection. They just burn too easily. A lot of them have built-in protection circuitry, but taking precautions and putting the thing in a decent battery holder inside a padded metal box (sardine can?) helps containing fire hazads.


The bare chip costs around EUR2 (From an european re-seller, no Ali stuff needed) and you can have either an TQFP (quite small) or SDIP (breadboard friendly) for that money.

If you want to go AVR, then I also recommend to stay with the Mega's. If you don't want to use the "arduino framework" and interact directly with registers, then there are quite some differences between the Tinie's and the Mega's. In my opinion this is a monstrous *&^%$#@! on atmel's side.

With the atMEGA328 you will also not run out of program space quickly, while the tiny chips can get filled with code quite quickly, and then you have to change chips halfway a project.

The atMega328 is as good as any other microcontroller family. It's about on par with the MSP430 I think, and a handful of other brands and uC families. But it's a decent way to start with uC's and it's relatively quick.

The harvard architecture with separated FLASH and RAM is a bit of a nuisance though. Especially when using C or C++ and using text strings. You can work around it (standardized constructs) but a (minor) nuisance anyway.

As a programmer, I've used USBasp for years. "It works" (tm) Atmel used to devise a new programming protocol every 4 years or so which makes switching to other chips also a bit of a nuisance. I once was tempted to bu an "AVR Dragon" Until I read multiple reviews of that thing blowing itself up, depending on what sort of USB cable you use. Yuck.
 

Offline LoveLaikaTopic starter

  • Frequent Contributor
  • **
  • Posts: 558
  • Country: us
Re: First Foray into building microcontroller boards with ATtiny4
« Reply #14 on: September 20, 2021, 02:06:43 pm »
My advise is to steer away from these very small microcontrollers, unless there is a specific reason to use them.

The number of pins has nothing to do with the complexity of the device.
If you want to stay with the AVR's, then the atMEGA328xx is a quite reasonable compromise.
You can stick a single IC in a breadboard and run it if it's internal RC oscillator, or buy small breakout boards such as the "arduino nano". Don't be afraid of either the "arduino" nor the "nano" part. First, the uC is reprogramable by any AVR programmer, so you don't have to fiddle with bootloaders and their peculiarities. The advantage of a normal programmer is that it **just works** (tm) No fiddling with buttons to get it into bootloader mode. No troubles by accidentally erased bootloaders, and other problems with those things.

Also don't be afraid of the "nano" part. It's not so small, it fits in any regular breadboard.

atMEGA328 is factory programmed to run at 1MHz from it's internal RC oscillator. You can just stick it in a breadboard, add two decoupling capacitors and power and it runs. Add a few "dupont" wires for the programmer and you're off having fun with adding more hardware and writing software for it.
And it also runs from less then 2V to about 5V5. You can run it directly from two AA's, 5V tapped from an USB port (or programmer), or a single Li-Ion without even a voltage regulator needed.

A few words of caution:
* Using a powered USB hub between your PC and electronics hobby is always advised. You'd much rather see smoke coming out of an USB hub, then out of your PC.
* Li-Ion cells always need some protection. They just burn too easily. A lot of them have built-in protection circuitry, but taking precautions and putting the thing in a decent battery holder inside a padded metal box (sardine can?) helps containing fire hazads.


The bare chip costs around EUR2 (From an european re-seller, no Ali stuff needed) and you can have either an TQFP (quite small) or SDIP (breadboard friendly) for that money.

If you want to go AVR, then I also recommend to stay with the Mega's. If you don't want to use the "arduino framework" and interact directly with registers, then there are quite some differences between the Tinie's and the Mega's. In my opinion this is a monstrous *&^%$#@! on atmel's side.

With the atMEGA328 you will also not run out of program space quickly, while the tiny chips can get filled with code quite quickly, and then you have to change chips halfway a project.

The atMega328 is as good as any other microcontroller family. It's about on par with the MSP430 I think, and a handful of other brands and uC families. But it's a decent way to start with uC's and it's relatively quick.

The harvard architecture with separated FLASH and RAM is a bit of a nuisance though. Especially when using C or C++ and using text strings. You can work around it (standardized constructs) but a (minor) nuisance anyway.

As a programmer, I've used USBasp for years. "It works" (tm) Atmel used to devise a new programming protocol every 4 years or so which makes switching to other chips also a bit of a nuisance. I once was tempted to bu an "AVR Dragon" Until I read multiple reviews of that thing blowing itself up, depending on what sort of USB cable you use. Yuck.

Thanks for your advice. I suppose I may have bit off a bit farther than I can chew, or however that phrase goes. I guess I'll move on to a simpler IC and work around it. While I know there are boards out there like the Nano, I sometimes think that it may be better to just build my own in order to make sure that the board will fit my requirements. There's always something about these boards that make me unsure if they can handle my needs.

If I may ask you something, looking at the Nano Every, it seems to have two processors: the ATSAMD11D14A and the ATMEGA4809, with the USB going directly to the ATSAMD. Why is it necessary to have two ICs like this? The ATMEGA doesn't have USB, so I suppose the ATSAMD is needed to interface with USB, but why wouldn't you just have only the ATSAMD if it can do everything the ATMEGA can?
 

Offline Renate

  • Super Contributor
  • ***
  • Posts: 1460
  • Country: us
Re: First Foray into building microcontroller boards with ATtiny4
« Reply #15 on: September 20, 2021, 03:35:38 pm »
Why is it necessary to have two ICs like this?
That's a very good question, I don't know if there is a good answer.

Arduino got themselves in a rut with the ATMega8u2 / ATMega328 combo.
So you can't talk directly to the "real" µC, you can only talk to the µC that is acting like an FTDI serial converter (ok, maybe CDC and not FTDI protocol).
Apparently they are still perpetuating that model.

You can buy an Arduino Leonardo:
Quote
The Leonardo differs from all preceding boards in that the ATmega32u4 has built-in USB communication, eliminating the need for a secondary processor.
You could also dump the Arduino brand and go with https://www.pjrc.com/store/teensy.html
 

Offline LoveLaikaTopic starter

  • Frequent Contributor
  • **
  • Posts: 558
  • Country: us
Re: First Foray into building microcontroller boards with ATtiny4
« Reply #16 on: September 20, 2021, 04:37:24 pm »
Why is it necessary to have two ICs like this?
That's a very good question, I don't know if there is a good answer.

Arduino got themselves in a rut with the ATMega8u2 / ATMega328 combo.
So you can't talk directly to the "real" µC, you can only talk to the µC that is acting like an FTDI serial converter (ok, maybe CDC and not FTDI protocol).
Apparently they are still perpetuating that model.

You can buy an Arduino Leonardo:
Quote
The Leonardo differs from all preceding boards in that the ATmega32u4 has built-in USB communication, eliminating the need for a secondary processor.
You could also dump the Arduino brand and go with https://www.pjrc.com/store/teensy.html

Thanks for replying. Doing a bit of research (looks like you were referring to the first version of Arduino), ATmega328 seems to only communicate via serial, so the ATmega8 is more-or-less a serial to USB converter. Looking at the ATmega4809, it seems pretty much the same (no USB, only serial), so maybe that's why. I might design a board around the ATSAMD and post it here as a project. I wonder if it can do the same thing as the Nano Every (if I'm just using the Nano every for I2C).

Thanks for reminding me about the Teensy boards. I had a look at them once before; they seemed promising, but for some reason, my team found it to be unusable based on the specs. I can't quite remember the reason why. Maybe it was a timing issue? My programmer is reading from a lot of sensors (magnetometers) via I2C, from Pi to Arduino Nano Every to said sensors. For some reason, he said there was a timing issue when reading the sensors from the Pi directly, so he had to use an Arduino Nano to interface with the sensors. We also tried using the Portenta in place of the Nano, but the Nano proved to be more accurate (or maybe timing issues) which made the Portenta worse off. I'm honestly not sure what he meant, but it's interesting to think about.
 

Offline Renate

  • Super Contributor
  • ***
  • Posts: 1460
  • Country: us
Re: First Foray into building microcontroller boards with ATtiny4
« Reply #17 on: September 20, 2021, 06:43:00 pm »
I'm not sure that you're attacking whatever you're trying to solve in the right domain.
Your problem is not "How do I build a µC board?"
Your problem (apparently) is "How do I do a bunch of magnetometer readings?"

Now, anybody who has done something similar will say, "I've already done A, B, C and I have some PCBs for that and I can code this in an hour."
And somebody else will say something completely different.

So, to get to the meat of this, please qualify:
  • Number of locations to measure
  • Maximum distance between a location and a central location
  • Number of samples at each location per second
  • Environment: outside/inside, field/temporary/permanent
There's a big difference if you're measuring a Tokamak for nuclear fusion or tectonic drift.

(Not a suggestion, but I use an ATMega328 over RS-485 Modbus to a Raspberry Pi to measure XY field rotation on a magnetically linked float arm in a propane tank. Unless your application is identical, your solution may be something else.)
 

Offline LoveLaikaTopic starter

  • Frequent Contributor
  • **
  • Posts: 558
  • Country: us
Re: First Foray into building microcontroller boards with ATtiny4
« Reply #18 on: September 20, 2021, 06:52:49 pm »
Thanks for the reply, but that comment was mainly anecdotal. As of now, I'm not trying to figure out how to do a bunch of magnetometer readings. It just so happened that using different microcontroller boards resulted in different issues. This little project of mine, building an MCU board, is unrelated for now. I'm mainly doing this for curiosity.
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf