from Hacker News

PSA: If you're a fan of ATmega, try AVR Dx

by scrps on 6/6/24, 3:03 AM with 117 comments

  • by JoeCortopassi on 6/6/24, 3:32 PM

    If you are a hobbyist reading all this, and trying to compare it to arduino or raspberry pi, do yourself a favor and buy one of these: https://www.adafruit.com/product/5325

    $12, fantastic documentation and tutorials, and you can literally just plug it in via usb and edit the python code as if it's just a text file on a thumb drive. No programmers, special IDE's, or specialty equipment

    Microcontrollers are fun again

  • by guitarbill on 6/6/24, 6:10 AM

    I'm a bit torn. While there's something nice about the simplicity of an 8-bit device and DIP packages, I've come to enjoy ARM's Serial Wire Debug, and ARM tooling. Definitely don't miss avr-gcc and avrdude.

    In a way, it's ironic. The AVR tooling back in the day was just so much better than PIC (for a novice hobbyist, pre-Arduino).

  • by watermelon0 on 6/6/24, 5:14 AM

    I generally use ESP32 nowadays, since most things I do benefit from having WiFi connectivity, but I have fond memories of using AVR microcontrollers in the past.

    For hobbyists, AVR (ATmega, ATtiny) microcontrollers were really great. Easy to use in C for most cases, great cross-platform toolchain, and many of them came as DIP package, which made them breadboard/protoboard friendly.

    Heck, we even had a USB 1.1 library, that could bitbang USB 1.1 on practically any AVR, including 8-pin ATtiny: https://www.obdev.at/products/vusb/index.html

    Not to mention, that Arduino started with ATmega, and still have many board featuring it.

    I definitely might check Dx line, just to see if the experience is the same as it was before.

  • by dotdi on 6/6/24, 1:36 PM

    I started working with Microcontrollers when 80C51s were still somewhat modern, and I remember how frustrating the toolchain and the general experience was.

    When AVR came out with their ATmegas, it was a revelation. Not having to use shitty proprietary programmers and windows-only software was amazing. We could finally use Linux. PIC was one of the main competitors in our circles, but it was losing the foothold quickly, because the AVR tooling was just hands-down better.

    Also, documentation was easier to read and interpret, especially compared to PIC, which is still giving me slight PTSD when I try to recall how hard it was to get non-mainstream features to work. Whenever I had to deep-dive PIC documentation I stumbled over weird behaviour or outright hardware bugs that, in some cases, could not even be worked around.

    I don't actively work with microcontrollers nowadays, but I am excited to hear that AVR is still making an effort to have an objectively good product. The market is tough nowadays, with ESP32s and ESP8266s being so cheap and widespread, but I hope AVR keeps it up.

  • by _benj on 6/6/24, 11:07 AM

    I have worked with DD and have some DA laying around. The UPDI is a very nice and simple programming interface. All that it takes is a USB-UART and a diode or a resistor (I used a diode) to connect between RX/TX.

    I didn’t used ATmega a lot, but comparing the experience to MSP430 and EFM8 the AVR chip has a bunch of niceties, superb documentation and life improvements like, in order to clear some registers all one need to do is write 1 instead of the whole =& ~(REG | 0x8) (or something like that, it’s been a while since I write embedded C)

    The other thing that I loved is that one can download headers for the chip directly from the manufacturer!

    Way too many chip manufacturers keep locking headers/libraries behind their proprietary IDEs, but Microchip, even though they have an IDE let’s you download the headers so one can use whatever tooling one is comfortable with! Props to Microchip for that!!

  • by buserror on 6/6/24, 9:08 AM

    Haven't played with these yet, but they do look interesting. Might have also to add support for the new IO blocks in my AVR simulator simavr[0] -- I still use the AVR a lot, since they have no pipeline and other fancy CPU optimization, they are 'cycle accurate' and are a lot closer to a PIO than most other more complex 32 bit CPUs.. Now that they ALSO have an equivalent to PIO it might even help with reaching faster IO speed when toggling pins.

    [0]: https://github.com/buserror/simavr

  • by newswasboring on 6/6/24, 11:58 AM

    This unlocked such fond memories, I'll buy some just to make some LEDs blink. I am glad my first exposure to embedded systems was through ATmega series, not for the chip, but the user's manual. That is perhaps the only manual I have read cover to cover, that thing took me to knowing rudimentary electronics to actually understanding a full system. The first real world system I could hold fully in my head, and that was an amazing feeling. Who ever wrote that, hats off. I remember then encountering the ARM manual which had similar clarity of writing. Were there like professional writers for these things?
  • by genter on 6/6/24, 3:49 AM

    Or, you can get an stm32g0 for $2, which is faster, has a modern 32 bit cpu, and has more powerful peripherals.
  • by dragontamer on 6/6/24, 2:49 PM

    AVR gives up on core/SRAM and instead offers incredible peripherals. While AVR DA, DB, DD, EA, and EB chips can serve as replacements to ATmega (albeit with new pinouts), the newer chips are a completely different ballgame.

    AVR DB has 3x OpAmps for free.

    AVR EA and EB have differential 12-bit ADCs with programmable 1x to 16x gain. We're not just talking about measuring 4mA to 20mA protocol easily, but you can measure uA of current with reasonable accuracy with just a shunt-resistor + the AVR EA's ADC.

    AVR DD has a dual power-supply with 1.8V to 5V support. That means that some pins can be on 3.3V logic while other pins are on 5V logic. IE: The AVR DD's job is to be a built-in full-and-proper level shifter.

    Bonus points: All modern AVR chips (Dx and Ex) have an event-system to route events from any peripheral (Timers, Pins, UART, etc. etc.) to many other pins and even interrupts to the CPU. This combines with the CCL programmable logic unit (Four 3-LUTs + two 1-bit memory cells) to have an incredible amount of "glue logic" built into these chips.

    Anyone who comes in this topic and talks about "But 32bit whatevers", ESP32 or about super-cheap RISC-V chips is missing the point of the AVR line. You're not really the ones in the market for this chip. Anyone who has to deal with a cheap design that manipulates a bit of analog sensors, or glue together logic... well... AVR is the right chip for these jobs.

    ----------

    There's one problem. It means that you need to know the ins-and-outs of the peripherals that are offered on these chips. AVR DD cannot do the same current-measuring job that an AVR EA or AVR EB can do.

    Mixed-signal Peripherals are so much harder to understand than MHz and SRAM. But for those who are "in the know", well... these are awesome peripherals. Its difficult to find competitors to these chips.

    Indeed, a proper bidirectional 3.3V to 5V level shifter across 28 I/O pins alone would probably cost you more than the $1-ish AVR DD.

    3x Rail-to-Rail OpAmps with programmable voltage-reference, a DAC and differential ADC is a *bargain* for the AVR DB's $2 price point.

    ---------

    And the whole line offers like 5V and 50mA in/out on the GPIO. Its an extremely forgiving chip. The fun trick is to run Resistor+LED directly off of GPIO because... you can. (Typical LEDs are 20mA).

  • by andrewstuart on 6/6/24, 3:54 AM

    There's actually tons of really interesting microcontrollers of every size and shape.

    Many of them are available as dev boards for under $20.

    You can burn plenty of hours and dollars browsing all the good stuff on electrodragon at https://www.electrodragon.com/product-category/dev-board/

  • by beryilma on 6/7/24, 3:24 AM

    I regularly use both atmega328p (Arduino Uno) and stm32g0 (st-nucleo boards) microcontrollers for hobby projects. The linux toolchain for both are equally good. But the Nucleo boards are a lot cheaper than Arduino Uno/Mega boards, have a lot more capabilities, any are 32-bit microcontrollers.

    I am actually fascinated with the things you can do with stm32 chips. If I ever do a commercial project, I would definitely use stm32 chips. Bare metal programming them has been a lot of fun.

  • by blutack on 6/6/24, 7:29 AM

    See also the CH32V003 [0] (more expensive variants also available), a neat, cheap and standalone RISC-V with plenty of modern & flexible peripherals, good package options, single wire debug and an open toolchain [1] for ~20c per.

    Mitxela has a great article on them [2] and I totally agree they have a lot of the same joy & simplicity of the ATTiny - but with the added bonus of lots of interesting DMA controller misuse!

    The peripherals have a very STM feel (in a good way) which perhaps isn't surprising given WCH's history.

    0: https://www.wch-ic.com/products/CH32V003.html

    1: https://github.com/cnlohr/ch32v003fun

    2: https://mitxela.com/projects/badge

  • by snvzz on 6/6/24, 7:45 AM

    AVR was cool, but I have moved on to RISC-V (ch32v, esp32c...).
  • by ThrowawayTestr on 6/6/24, 6:17 AM

    Does it have Arduino support?
  • by SomeoneFromCA on 6/6/24, 10:28 AM

    I want my AT90S2313 back. The best most versatile AVR imho of its era.
  • by contingencies on 6/6/24, 9:01 AM

    China prices are still double the old chips, with very limited availability (single digit volume for 2-3 models only). I trust China prices. If it aint there, it aint real.
  • by lloydatkinson on 6/6/24, 12:19 PM

    Would Rust for AVR work with these too I wonder?
  • by megous on 6/6/24, 2:46 PM

    Looks like a modern PIC with swapped out MCU core. Probably nothing to miss if you use PIC already.
  • by throwaway81523 on 6/6/24, 3:50 AM

    Yeah these are cool, there is a bunch of info on SpenceKonde's github pages,

    https://github.com/SpenceKonde/DxCore

  • by hi-v-rocknroll on 6/7/24, 7:32 AM

    The key points of marketing and executing a successful a MCU are:

    0. simplicity

    1. robustness

    2. developer support

    3. essential features