Going from Arduino Uno / IDE to plain C / breadboard - Page 1
Forum section: electronics / general

author: Rooster Cogburn
author_rank: Regular Contributor
timestamp: November 01, 2021, 02:27:58 am
content: For the past week or two I've been trying to figure out how to best go from writing sketches in the Arduino IDE with an official Arduino Uno to designing my own circuit on a breadboard and just using plain C / Makefiles / avr-gcc / avrdude. I have decent bit of Linux C/C++ experience so I think I'll manage the latter, but I'm having some issues with the former. I read a decent number of articles and tutorials but they seem to leave some questions unanswered or have something seemingly invalid or contradictory in them that I can't quite figure out myself.I'm thinking I'd like to do these three steps:- Switch from the Arduino Uno to my own circuit on a breadboard- Replicate what the Arduino IDE is doing with plain C / Makefiles / avr-gcc / avrdude- Switch away from the Arduino libraries and use just the plain AVR SDK, maybe manually bring some parts overI'm already struggling with step No 1. I tried following some tutorials, like this one:https://www.arduino.cc/en/main/standaloneFirst, most of them suggest using the Arduino as the ISP to burn the bootloader. The process and options seems to have changed quite a bit over the years as several tutorials have very different suggestions. But the basic idea is to load the 'Arduino ISP' sketch, select board & port as usual, select 'Arduino as ISP' for the programmer, connect power, SPI and reset to the target AVR and then use 'Burn Bootloader'. But where do I configure the target that gets the bootloader? For instance, wouldn't this need to set the fuses as well? If I want to use the ATMega328P on my breadboard in an Arduino Uno, it would have to set the right clock source fuse to use the external resonator, while if I wanted to keep in on the breadboard without external clock it shouldn't do that. Inside the ISP sketch are a few options, like the USE_OLD_STYLE_WIRING define. I've actually never seen any tutorial use 'new style wiring' despite that being the default, and I don't quite understand why that would matter anyway, aren't those pins on the ISP header the exact same SPI pins that we'd be connecting to anyway?This whole thing just seems needlessly confusing and I'd actually rather just buy a dedicated ISP to avoid all of this. But which one?https://www.aliexpress.com/wholesale?catId=0&SearchText=avr+isp+programmerI'd like to buy something that would work without any special drivers or setup on Linux and OS X, works with avrdude and I'd need to know what I tell avrdude about my programmer. I've also read about so called high voltage programmers that can recover an AVR with fuses set in a way that locks out normal programmers, is that something I should get?Assuming I figured out the above, the next step would setting up a UART connection. I've never quite understood what the exact motivation for this is and no tutorial seems to address this. We can already program our AVR at this point with the ISP. Why waste space on a bootloader and add another interface? Because UART uses less pins that SPI? Because we want a serial connection for debugging with the serial monitor? Can't we leave the ISP connected and just keep programming the AVR this way?Assuming I can figure all this out, I'd still need to buy a serial-to-usb interface:https://www.aliexpress.com/wholesale?catId=0&SearchText=ftdi+usb+to+serialJust like with the ISP I'd prefer to buy from AliExpress because it's cheap and will arrive without trouble. I'd of course again want something that would work without any special drivers or setup on Linux and OS X and works with avrdude. There seem to be quite a few options. Some of the devices have a 3.3V/5V jumper. Do these actually output power from USB or is that just power I have to supply to the interface?Assuming I found a suitable USB-serial interface and continuing to following the breadboard tutorial above, I'm confused that the reset line doesn't seem to be connected. They just connected TX/RX but without reset how can the IDE actually talk to the bootloader? Guess they just forgot to include that?Here's another official tutorial:https://www.arduino.cc/en/Tutorial/BuiltInExamples/ArduinoToBreadboardThis tutorial suggests"Select "Arduino Duemilanove or Nano w/ ATmega328" from the Tools > Board menu. (Or "ATmega328 on a breadboard (8 MHz internal clock)" if using the minimal configuration described below.)".There doesn't seem to be a board description file for the current IDE that adds that board. Also isn't the 'board' we select the Arduino Uno that's acting as the ISP, NOT the target we're burning a bootloader on?What I find interesting about this tutorial is that they show how removing the AVR from the Arduino One allows us to use its USB-to-serial converter to talk to the AVR on the breadboard after it has a bootloader. They also show the connected reset line, unlike the first tutorial.Hm, sorry if this is quite lengthy, just trying to figure out how to proceed. I'd like to (probably) buy an ISP and USB-to-serial interface for cheap from AliExpress and then start making my own circuit for the AVR, which will then hopefully turn into something I can build for real.

author: westfw
author_rank: Super Contributor
timestamp: November 01, 2021, 06:18:21 am
content: QuoteThere isn't really an AVR SDK. There's a C library (with no support for any peripherals), and there's "ASF" - another vendor-provided library that no one seems to like...QuoteThere are essentially three steps to using ArudinoISP:Configure your existing Arduino to be an ISPprogrammer. This consists of loading the ArduinoISP sketch and perhaps disabling the auto-reset feature. (there are mixed reports whether the latter is necessary. IMO, the disable removes a lot of ... uncertainty.)Connect the existing Arduino to your target CPU using the appropriate connections. Usually this means connecting the SPI interfaces together, and adding a GPIO output from the programmer to the target (nominally, digital pin 10.) But not all AVRs have SPI, and some have SPI but have their ISP programming on different pins.Issues host commands that talk to the programmer and cause things to happen to the target. People wishing to continue to use the Arduino environment can use the Arduino IDE, set the "board" to their target CPU and use the "burn bootloader" command. This will do BOTH the setting of the fuses (as appropriate for use with Arduino) AND uploading the bootloader. If you don't want to continue with Arduino, you can use regular avrdude commands to set fuses and upload your programs. (at this point, the Arduino is a "STK500v1" programmer, and avrdude doesn't need to know that it used to be an arduino. You do get to use a nice long and cryptic avrdude command line. (or perhaps "avrdudess" or other more convenient tool.)QuoteWell, you could get an official Microchip SNAP progammer, which would entitle you to yell at microchip, as well as potentially program PICs, UPDI, TPI, PDI, ARM, and maybe more. Also does debugging. About $30 (but sometimes goes on sale for 50% off.)Alternately, you could consider one of the microchip evaluation boards like the "Xplained mini 328p." That's basically compatible with the Arduino Uno hardware, but it's cheaper (about $12) and includes debugger support. (I actually highly recommend this for SW development. It's less "useful" if you want to play with hardware as well.)Those will both work "natively" with the Microchip development environments ("Microchip Studio" and "MPLABX") as well as with avrdude.(honestly, I've got SNAPs and a PICKIT4 and several Microchip development boards, but for most AVR programming tasks I end up using ArduinoISP. I get a certain comfort from being able to modify the code, if needed.)I also like the looks ofhttps://www.pololu.com/product/3172, which is both a programmer and a serial port provider.There are "MANY" "USBASP" clones of various convenience and documentation quality. They're all based onhttps://www.fischl.de/usbasp/and use a bit-banged USB implementation that is become less and less likely to work with modern computers. Very cheap, though!A "high voltage" programmer would be nice (HV Parallel, HV Serial, or HV UPDI are all DIFFERENT, though.) But they're relatively rare. Better to stick with chips and level of care that prevents you from needing one.If you don't need a UART connection, then you don't need a USB/UART adapter. The Arduino loads SW over UART, and of course it's available for "print based debugging." Those are both convenient but not strictly necessary. Even less necessary if you get a programmer that supports debugging (which might include a serial port as well. the XPlained mini boards do both ISP and UART, and so does the pololu.)QuoteThe main problem with the many tutorials about using stand-alone chips with Arduino is that they haven't kept up with the churn of arduino boards and "cores" that people are using. But if you're not planning on using Arduino with your standalone chip, you can stop reading the tutorials after you've uploaded ArduinoISP (as above.)QuoteSet the "board" to Uno when uploading "ArduinoISP", and then set it to the target that you're programming.

author: bingo600
author_rank: Super Contributor
timestamp: November 01, 2021, 06:42:52 am
content: Also1:Remember the builtin AVR oscillator might not be suitable for RS232 communications , it might be too imprecise.2:Most of those FTDI boards from China are clones , not a issue on Linux.But if you connect it to Windows, the FTDI driver might (by purpose) kill it.Why do you want to switch away from the arduino nano hardware ??The challenge of building your self ?You can program Arduino nano as a "Raw" AVR , without using the Arduino framework.You can't even buy the AVR MCU for the price of a full Nano board.

author: Doctorandus_P
author_rank: Super Contributor
timestamp: November 01, 2021, 11:53:04 am
content: I've been writing software (as a hobbyist) for AVR microcontrollers since about 10 years before "arduino" ever existed.A long time ago there was a package called "WinAVR" that had everthing needed to start writing software for the AVR microcontrollers, but this has been obsolete for 10+ years.Later I switched to LinuxEverything you need to start programming for AVR microcontrollers can be installed by installing just three packages:* gcc-avr (The Compiler with header files, linker scripts, etc)* avr-libc ( Default libraries)* avrdude ( Programmer software)avrdude is a command line programmer, which is ideal for integration into a makefile. You just build for the right target and your microcontroller gets programmed. Avrdude also has support for a lot of different programmers. It is quite old software though. If you can still find a PC with an LPT printer port, you can even use just a few wires to program an AVR.The programmer I use is USBasp from Thomas Fischl, but I've burned it into one of the Chinese "USBisp" (an "i" instead of an "a") dongle. "USBtinyISP" is another popular open source programmer for the AVR chips.This is a bare bones solution though. So even to get a uart working, you have to program the I/O registers to set the baudrate and other things.With this setup you can work with a bare ATmega microcontroller on a breadboard (Add decoupling capacitors, some wiring). For breadboards, the "arduino nano" is a more convenient solution though, because it adds a bit of standard hardware, including an ISP connector, so you don't have to remember the pinout or mess with separate wires.Due to the idiots in the arduino community it also has a 16MHz crystal, which is incompatible with normal UART baudrates, so just as with arduino you may encounter unreliable UART data, depending on external factors. (It can stay barely within aceptable standards if you program the X2 bit for the UART)

author: Rooster Cogburn
author_rank: Regular Contributor
timestamp: November 01, 2021, 12:20:07 pm
content: Quote from: westfw on November 01, 2021, 06:18:21 amSure, that's fine. A libc and some headers that define various MMIO/Registers is all I need. If there's some nice code from the Arduino world I could probably just port it over.Quote from: westfw on November 01, 2021, 06:18:21 amUh, OK, when using the Burn Bootloader / Upload Using Programmer option the 'Board' is the target chip and the 'Programmer' option tells the IDE everything it needs to know. I still don't really understand this whole new vs old style wiring thing since the ISP header should just be the same pins and I'm not sure where I'd get the right board definition files for my breadboard Arduino. But I anyway don't really want to use an Arduino Uno as a programmer and keep using the IDE. So, yeah, maybe it's not worth even looking further into any of this. I thought it would've been a nice transition step, but it's just more work and confusion :-)Quote from: westfw on November 01, 2021, 06:18:21 amI really would like to just buy a cheap ISP and USB-serial interface from AliExpress. Any opinions on those? I don't really want to buy any pricey official gear or any more evaluation/dev boards. I'd of course like to have a debugger, but I'm a bit scared how tricky that'll be to setup.Quote from: westfw on November 01, 2021, 06:18:21 amOh Jesus, even more different types of things, maybe you're right and I'll just stay away from this one.Quote from: westfw on November 01, 2021, 06:18:21 amOk, I can basically skip the bootloader / USB-to-serial step if I don't want a serial monitor for debugging? Can I leave the ISP attached at all times? I really need a single command build-upload-run dev cycle, I just would go insane if I have to attach a cable or push buttons etc. every time I want to test a code change.Quote from: westfw on November 01, 2021, 06:18:21 amYes, I think I'd rather just completely stop thinking about the Arduino IDE and the Arduino boards and just program a standalone chip with an ISP.Quote from: bingo600 on November 01, 2021, 06:42:52 amI know, I already got some 16&20Mhz crystal oscillators and would be using the AVR with those right after I figure out which fuses to set :-)Quote from: bingo600 on November 01, 2021, 06:42:52 amFTDI is basically a term like Kleenex or Xerox, right?So, those cheap serial-to-USB boards should just work out-of-the box on Linux/Mac? What is that about the 3.3/5V switch, is that about supplying or sinking? Haven't seen a vreg for 3.3V on those tiny boards so I assume that's the voltage supply to the board and the level of the UART lines etc.? Also what about those ISPs on Ali, are any of them usable?Quote from: bingo600 on November 01, 2021, 06:42:52 amThe official Nano board is like 18EUR? Which I assume has a gigantic open source tax since you get vastly more powerful RPi Picos and ESP32s for a fraction of that. I'm sure the AliExpress clones are cheaper.Quote from: bingo600 on November 01, 2021, 06:42:52 amOk, let me explain why I'm trying to go this route. Let me know if I'm off course somehow. I have ideas for a few gizmos I want to build. Maybe starting on a breadboard but eventually with my own PCB design. And I'm trying to figure out the best path for picking up all the required skills. Since I'm already familiar with the Arduino environment and started to use the actual architectural features like controlling the GPIO and timers through the registers myself, maybe I should stick with AVR and try this first. Just since I have some familiarity and they seem very popular.I think in the end there's a very good chance the 8bit AVRs will be too weak or just don't make sense for me, especially given that the vastly more capable RPi Pico and ESP32 exist and those are dirt cheap. Right now I'm having such a bad time with the tutorials / docs for the AVR that I'm thinking of just skipping this step and just getting an ESP32 & RPi Pico for a few bucks and looking if that's more my thing. I'm quite familiar with low-level development, writing assembly, working with DSP-like architectures or developing for old computers and game consoles, but my experience so far trying to figure out a basic AVR development setup, which choices to make or which hardware to buy was rather painful.Quote from: Doctorandus_P on November 01, 2021, 11:53:04 amYes, this all makes sense and is exactly what I want. I found this basic setuphttp://www.florentflament.com/blog/arduino-hello-world-without-ide.htmlThat just all seems sensible to me, that's what I want to get going. I'm just struggling more with the hardware part, which programming setup to use (bootloader? SPI? serial? which ISP device? which FTDI?).Quote from: Doctorandus_P on November 01, 2021, 11:53:04 amI think I'd rather just go the full custom breadboard route. I have all the required crystals, capacitors for the oscillator circuit, pulldown/up resistors, decoupling caps, switches, pin headers. Mostly trying to figure out the programmer & software setup for it. I'm fine sticking whatever crystals works on my breadboard. Not sure if I even need UART, all devices I'd be interested in are I2C/SPI and I if possible I'd be fine just programming the AVR with an ISP, if I can leave it attached and have a fast dev cycle.Right now I'm just mostly thinking if it makes sense to continue down the AVR route or if I should check out the RPi Pico / ESP32. Those are both dirt cheap (<4EUR), seem to have significantly more performance (~10x) and more peripherals onboard. They're available on boards with castellated vias so I could integrate them into any custom design I'll eventually build, I guess. I just want to see if they have a nice development story.

author: Doctorandus_P
author_rank: Super Contributor
timestamp: November 01, 2021, 02:48:17 pm
content: That tutorial from FlorentFalament looks quite usable.Working with makefiles is quite a nuisance because of it's archaic syntax but that site has some simple 20 liner examples which just defines some variables, simple rules and targets, and if you keep a makefile as simple as that it's quite doable.The AVR processors were quite amazing 20+ years ago, partially because it was one of the first that had a GCC port. Back then it also was a quite fast microcontroller for a small price. These day's you get swamped with options though.For the older AVR chips, you need GND +VCC, Reset and the SPI port (MISO, MOSI, SCK), and you can usually leave those connected in your application. For your application they are just regular I/O.If you use that I/O in your program (Either as bits or SPI bus) then you have to make sure there are no conflicts. The easiest way around that is to just not use those pins in your application. For firmware development I usually use a bigger AVR with more pins. This way I can also use a logic analyzer for software debugging. I only use the (older) Mega AVR's I have no interest in dealing with incompatibilities of the "ATtiny" processors and with the different programming protocols (I think the AVR's have 5 or more different programming protocols).I also dislike bootloaders for on-the-bench development.With a makefile and a real AVR programmer, you fist setup your IDE, and then with a single keystroke you both rebuild your application and program your AVR chip, and this works much more reliable than a bootloader can work.(Nearly?) all "arduino" boards have an ISP header. I advise to first program such a board with your new setup because it eliminates a lot of extra factors related to hardware. If you can get that working, then proceeding to a bare chip on a breadboard is a small extra step.These days the main advantages of the AVR processors is their simplicity, but it's not a fast microcontroller anymore. For similar prices (apart from last years electronics craze) you can get 10x faster microcontrollers (or 50x faster) but these microcontrollers have much more complexity.ESP32 (or ESP826) is great if you need the WiFi, but I find a nuisance to program them. They link in a few hundred kB of "stuff" and it takes 30+ seconds to program a blinking led application.I also have a bit experience with the STM32Fxxx microcontrollers. I bought a bunch of "Blue Pills" for around EUR3, before the Chinese started selling them with one of the 8 (partly incompatible) clones. But now the "Blue Pills" are broken. It's just too annoying to deal with them. I did buy a bunch of WeAct STMF411 boards. These are a bit more expensive (Around EUR 7) but have on-board hardware floating point and much more Flash.Programming the AVR's bare-bones is a good starting point for learning to work with microcontroller peripherals. Once you've got a bit of experience, you have a much better base for choosing your next microcontroller, based on clock frequency, available RAM+ Flash and the peripherals.I choose the STM32 partly because of the cheap Blue pills and cheap programmer (EUR3 ST-Link V2 clones from Aliexpress) but also because of the built in 3-phase motor controller with dead time insertion and hardware quadrature interface for keeping track of motor position.

author: HB9EVI
author_rank: Frequent Contributor
timestamp: November 01, 2021, 03:33:38 pm
content: there's nothing wrong about buying an ISP programmer; like it was already mentioned, it is nothing but a USBasp clone. At least they work for me since many years without problems; they are also switchable between 3.3V and 5V, what was not part of the original USBasp concept. Sure you go without support for TPI and UDI, but still most ATmega and ATtiny require classical ISP programmingI've built me both parallel programmers and HVSP programmers, but I almost never used them; though what was useful to have built is the AVR fuse doctor; if you mess up the fuses and locked yourself out from the ISP, it's the way to fix it.about your wish to change from arduino to classic C: my recommendation is the jump into to cold water. At least from my point of view there seems to be very little transition methods to slowly change from one to the other.the web is full of generic C codes for ATmega, so it's really no witchcraft to get into it.This also applies for arduino-related things like the bootloader: just drop it!it is uselessly bloated code which also blocks certain ressources from your uC you can use for more useful things.the ASF library is indeed not much useful; it can give some hints about certain external peripherals, but there are better libraries for things like LCDs, DACs and other stuff.it's that simple: all you need is avr-gcc, its libraries and avrdude

author: fchk
author_rank: Frequent Contributor
timestamp: November 01, 2021, 04:33:55 pm
content: Quote from: Rooster Cogburn on November 01, 2021, 12:20:07 pmGood tools are key to success. I prefer the vendor tools. A Snap or PicKIT4 together with MPLABX is a good way to start. It's basically plug&play, also with Linux and MacOS. Microchip(Atmel) STudio is Windows only and basically a dead end - MPLABX ist where Microchip puts its money into.I've used AVR decades ago but have turned away from them. A Mega2560 is just as expensive as a PIC32MZ MIPS32 or a ATSAM but has much less power, less advanced peripherials, less memory. It's just not worth it any more.Plus: ISP is a programming only interface. Being able to dump memory or perform single stepping while runnung own code is a big timesaver. All ARMs and nearly all PICs have debug capabilities.For UART-USB I suggest to use MCP2200 or MCP2221A. These are preprogrammed PICs with an USB-UART (+USB-I2c for MCP2221A) bridge application in it. They use the standard USB CDC-ACM and HID device classes and don't need any custom drivers. They are guaranteed to run on a fresh MacOS install or FreeBSD install just fine.fchk

author: Rooster Cogburn
author_rank: Regular Contributor
timestamp: November 01, 2021, 04:55:39 pm
content: Quote from: Doctorandus_P on November 01, 2021, 02:48:17 pmYeah, it looks all reasonable. I'm not scared of Makefiles and such, Linux software dev stuff is all fine.Quote from: Doctorandus_P on November 01, 2021, 02:48:17 pmYes, it's just always weird when the ESP32/RPiPico costs basically the same as an 8bit AVR when there's at least a 10x performance difference, probably like 100x when using floating-point on the Pico.Quote from: Doctorandus_P on November 01, 2021, 02:48:17 pmOk, I don't think I'll bother with a bootloader and serial. I'll just use and SPI ISP. On an ATTiny85 or so the pins are really limited so might be a bit of a challenge leaving eveything attached, but on the ATMega384P that's fine. I don't really know much about SPI so I'd have to see how difficult it would be to attach more than one device to it, though. Like if I also wanted to control some display or a DAC or something over SPI while leaving the programmer attached.Quote from: Doctorandus_P on November 01, 2021, 02:48:17 pmReally, then maybe I shouldn't bother with the ESP32. I thought for like 4 bucks or whatever I might as well buy one and give it a shot. I have no immediate use for any wireless communication, would just need the additional performance.Quote from: Doctorandus_P on November 01, 2021, 02:48:17 pmI don't really want to also look at the STM/PIC controllers, the headaches of figuring out one toolchain is enough. I figure it should just ditch Arduino and go with a the normal AVR tools and just use an ISP.Quote from: HB9EVI on November 01, 2021, 03:33:38 pmI have to admit I don't know what TPI/UDI are. Most of the programmers on AliExpress seem to have jumpers for the power supply. Is it a problem to leave the programmer in place when I'd normally power the AVR with my own power supply?Quote from: HB9EVI on November 01, 2021, 03:33:38 pmfuse doctor? I thought the HV programmer uses a 12V pulse or something on the reset pin that puts the AVR into a mode where it can be recovered even if ISP or the reset pin has been disabled. Is that what you mean?Quote from: HB9EVI on November 01, 2021, 03:33:38 pmYes, I think you're right. I'll just forget about Arduino.So I'd just order something like thishttps://www.aliexpress.com/item/32670511994.htmland wire it up. Is that a USBasp clone? Or what would I tell avrdude the programmer type is?Quote from: fchk on November 01, 2021, 04:33:55 pmI'd agree about good tools but for me investing in anything AVR related doesn't make much sense at this point, I'm just learning and there's a very good chance I'll have to move to something more powerful a few weeks down the road. I just want to take a few AVRs, wire them up on my breadboards, spend 5 bucks on AliExpress for a programmer, get a working dev environment and see how far I can get with these 8bit chips. There's a really good chance I'll get this working and play around with it for a bit and then move on to something like the Pi Pico.

author: bingo600
author_rank: Super Contributor
timestamp: November 01, 2021, 06:18:48 pm
content: For fuses , this page will come in handyhttps://www.engbedded.com/fusecalc/

author: HB9EVI
author_rank: Frequent Contributor
timestamp: November 01, 2021, 06:49:56 pm
content: Quote from: Rooster Cogburn on November 01, 2021, 04:55:39 pmTPI and UDI are just different programming methods for certain small ATtiny and ATXmega.Sometimes it can cause you problems when the programmer stays attached to circuit, mostly when you use the SPI bus for your circuit; there is no general 'yes' or 'no' but more 'it depends'Quote from: Rooster Cogburn on November 01, 2021, 04:55:39 pmthe AVR fuse doctor is working with HVSP, the only thing it does is resetting the fuses of the the ATmega or ATtiny which is not reachable anymore by the normal ISP programmer; otherwise the uC stays bricked and unusable.Quote from: Rooster Cogburn on November 01, 2021, 04:55:39 pmyep, this is such a USBasp clone; I'm also using such one.If you're into it later, you can always watch out for a programmer with other gimmicks like TPI/UDI/JTAG/SWDfor starters you don't do anything wrong with such a programmer.

author: RoGeorge
author_rank: Super Contributor
timestamp: November 01, 2021, 06:58:12 pm
content: Once I've needed a debugger, and come up to this setup that does not depend on Arduino in either the hardware nor the software, the example there is for an ATtiny13: Eclipse IDE -> avr-gdb -> dwdebug gdb server -> CH340G USB to serial adapterhttps://www.eevblog.com/forum/microcontrollers/avr-(arduino)-linux-debug/

author: westfw
author_rank: Super Contributor
timestamp: November 01, 2021, 11:31:58 pm
content: Quote"Old Style Wiring" means "use pins 11, 12, and 13 for SPI." "New Style Wiring" means "use PIN_MOSI, PIN_MISO, and PIN_SCK for SPI."These are EXACTLY THE SAME if you have an Arduino Uno or other ATmegaxx8-based board. But if you have a newer board, Mega, 32u4 or ATmega4809 based or maybe ARM, then the PIN_MISO/etc pins show up on the 6pin ISP connector, and are separate from pins 10/11/12.(an ATmega328 has 28 pins and 20 IO lines (not counting the crystal and reset), so the Uno pins digital 0-13 + Analog 0-5 are ALL THE PINS. The ISP connector, and the I2C pins (on "r3" boards) are shared with some other IO pins. If you have a board with a 48pin (or bigger) chip, there are enough pins to have D0-13, A0-6, 3 SPI pins, 2 TWI pins, and the "host" connection all without interfering with each other.)

author: westfw
author_rank: Super Contributor
timestamp: November 01, 2021, 11:41:45 pm
content: QuoteYou can leave ISP attached, but you basically lose the ability to use those three pins.The bootloader has nothing to do with serial monitor/debugging, but it does let you use the same two pins for both uploading code (which would use the bootloader) and using the serial port (for debugging or whatever), which might be what you would use the pins for anyway. Essentially "if you were going to have a uart connection to your PC for any reason, the bootloader gives you the ability to upload code over that same connection without using ANY additional pins."I'm going to mention again the danger of trying to use USBASP-style programmers with newer computers.Adafruit says: "Deprecation Warning: The Gemma bit-bang USB technique it uses doesn't work as well as it did in 2014, many modern computers won't work well."(and USBASP uses essentially the same code.) Spend the extra couple of bucks and get a programmer with actual hardware USB support.

author: Rooster Cogburn
author_rank: Regular Contributor
timestamp: November 02, 2021, 05:43:01 pm
content: Quote from: bingo600 on November 01, 2021, 06:18:48 pmI've seen that, seems useful. The clock options left me plenty confused, still wouldn't know what to set it for using my external 16/20Mhz crystals.Quote from: RoGeorge on November 01, 2021, 06:58:12 pmWould be neat, but I'll have to cross that bridge once I get to it. Just getting the chip programmed seems like a challenge right now :-)Quote from: westfw on November 01, 2021, 11:31:58 pmAh, thanks for clearing that up. I only got the Uno and I was confused because the SPI pins on the ISP header and the ones on the side headers are the same.Quote from: westfw on November 01, 2021, 11:41:45 pmYou can have multiple SPI devices on the same bus, so can't you have the programmer and some other devices sharing those pins? I guess giving up the UART for programming is nicer since it's one pin fewer and the SPI bus is probably more useful in general than the UART. I get that the serial monitor and the bootloader have nothing to do with each other, but both require a serial connection to the PC.Quote from: westfw on November 01, 2021, 11:41:45 pmYou have to understand that I don't know what any of this means. What is the 'Gemma bit-bang USB technique', how do I know that a programmer has 'actual hardware USB support'? What happened to computers after 2014 that would not allow them to talk to a programmer anymore? I assume this onehttps://www.aliexpress.com/item/32670511994.htmlis not OK since it says 'USBASP'? It seems like it has an ATMEGA8A on there, same as the Arduino Uno uses for its USB communication?I've seen you can also get these FTDI clone serial-USB interfaces with an ISP programming header (blue module):https://www.aliexpress.com/item/32273550144.htmlAny thoughts on these?

author: bingo600
author_rank: Super Contributor
timestamp: November 02, 2021, 06:18:12 pm
content: Quote from: Rooster Cogburn on November 02, 2021, 05:43:01 pmHave a look herehttp://www.martyncurrey.com/arduino-atmega-328p-fuse-settings/https://codingwithcody.com/2011/06/25/arduino-default-fuse-settings/For Xtal 16..20MHz fuses - No BOD , and no Bootloader.I'd prob go for something like this (I don't mind the 65ms delay to stabilize the Xtal)See attachments 1 + 2Arduino default settings are in the fuse-ardu.Last pic (arduino defaults) - Note you can set values here , and press apply , then the fuse info above will change accordingly.As westfw mentions , the cheap ones could have troubleI have never had any issues with the usbasp on my linux ... Well it's not a new pc ... (T430s)This one seems nice & not to expensive stk500 protocol - Doesn't that PIC have builtin usb ?https://www.ebay.de/itm/353510356385https://www.ebay.de/itm/124822288887/Bingo

author: Rooster Cogburn
author_rank: Regular Contributor
timestamp: November 02, 2021, 06:44:14 pm
content: Guess now I need to learn what the difference between a low power and a full swing crystal are, more reading to do :-)While looking at the USBASP clones on Ali (https://www.aliexpress.com/item/32670511994.htmletc.) I was a bit skeptical that they actually support 3.3V just from tracing things on the PCB, seems like that is the case:https://create.arduino.cc/projecthub/billy-cheung/3-3v-usbasp-modification-c20557So they still have 5V levels for SPI and that jumper is completely useless. Ah well, it's like all those displays or sensors being sold with 3.3-5V while they actually don't support that at all, no regulators or level shifters to be seen anywhere.Probably the same for these:https://www.aliexpress.com/item/32273550144.htmlWho knew it was so difficult to just buy a programmer and maybe a serial-USB interface :-)

author: bingo600
author_rank: Super Contributor
timestamp: November 02, 2021, 07:15:32 pm
content: Quote from: Rooster Cogburn on November 02, 2021, 06:44:14 pmDon't bother yet ... Everything running 8MHz or more is Full swingQuote from: Rooster Cogburn on November 02, 2021, 06:44:14 pmOhh yes Chinese have a "liberal attitude" to voltage levels.Quote from: Rooster Cogburn on November 02, 2021, 06:44:14 pmThe real FTDI's actually have an onboard Vio pin and a 3v3 regulator ... The chinese?I usually use CP2102 for 3v3 (The black one seems nice , have DCD/DTR etc)https://www.aliexpress.com/item/1005003459160150.htmlAnd CH340 for 5vhttps://www.aliexpress.com/item/32529737466.htmlI never trust the 5v/3v settings on those USB-serial , not without measuring them ... And my CH340 was putting 5v out when set for 3v3.So now i just use them as 5v units.I have two real FTDI's ($15), that i only use if the other ones act strange.I would not touch the PL230if they gave me them for freeNow buy that Poulu and get it over with ....Or go cheap , and use an Arduino as your 5V ISP programmer.https://www.best-microcontroller-projects.com/arduino-nano-isp.html/Bingo

author: admiralk
author_rank: Regular Contributor
timestamp: November 02, 2021, 07:23:08 pm
content: This series of videos should help.I assume you can figure out using make instead of the IDE. Do not use the avrdude that comes with Arduino.The getting setup videos are kind of jumbled up at the beginning, if I remember right.

author: westfw
author_rank: Super Contributor
timestamp: November 02, 2021, 11:46:34 pm
content: QuoteThe AVR is a "Slave" when being programmed, and most often a "master" when using SPI, so the usual "multiple SPI device" schemes don't quite apply. If the programmer is good about leaving all the pins "tri-stated" when it's not actually progamming, it MIGHT work.QuoteUSB is normally a protocol that involves high-speed bit-streams that require a USB controller peripheral to handle the transmission and reception of the packets used for data transfers. A couple of people noticed that it was just barely possible to write a bit-banged implementation of USB entirely in software (similar to "SoftwareSerial.") There were a couple of limitations - this only supported "low speed" USB (1.5Mbps max; normally used by devices like mice and keyboards), and it wasn't quite fully conforming to the USB specifications. But it did work, most of the time.A bunch of hobbyist-level projects used this software to eliminate the need and cost of an FTDI chip (which used to be ~$5 and hard to find) or microcontroller with USB hardware (harder to find, more expensive, unfriendly packaging, and less familiar.) DigiSpark and Gemma are Arduino-compatible boards in an ATtiny85 that use this hack (usually called VUSB) to upload software. The USBASP design uses VUSB in an ATmega8 to implement an AVR ISP programmer.The more "professional" programmers use CPUs with a hardware USB interface. EDBG (Atmel ICE, etc) uses an AVR32 chip, mEDBG (Xplained Mini) uses an ATmega32u4, and I think SNAP and PICKIT4 use one of the Atmel ARM chips. The Pololu programmer uses ahttps://www.microchip.com/en-us/product/PIC18F25K50QuoteMostly "USB3." In order to support the new USB "SuperSpeed" options, PC Chipset vendors implemented new USB hardware. I don't know for sure whether (some of) their implementations lost compatibility with VUSB's "almost OK" implementation out of necessity, by accident, or out of spite, but there isn't a lot of room for VUSB users to complain that their non-standard, non-approved, non-licensed, not-conforming no longer work.

author: Rooster Cogburn
author_rank: Regular Contributor
timestamp: November 03, 2021, 01:07:13 am
content: Quote from: bingo600 on November 02, 2021, 07:15:32 pmGot it, thanks!Quote from: bingo600 on November 02, 2021, 07:15:32 pmIt's a scourge in the retro gaming community. There's countless Chinese reproduction game carts or ROM/flash cartridges that interface modern 3.3V parts with vintage 5V consoles. On the video output side most old consoles output TTL level sync signals while all consumer TV equipment expects like a 700mV signal. There's supposed to be attenuation in the cable, but many Chinese cables are incorrectly build. I don't even want to know how many expensive vintage devices bit the dust due to those shoddy devices.Quote from: bingo600 on November 02, 2021, 07:15:32 pmSo how do those 3.3V devices you linked actually work? I wouldn't expect any fancy DC2DC stepdown converter, don't see a vreg, not even a zener? How do they get 3.3V from USB?Quote from: bingo600 on November 02, 2021, 07:15:32 pmThanks a lot! So basically the best way to evaluate these cheapo is to just look at the datasheet of the main chip.How do we know that the 'CP2102 black' has 3.3V on the signal lines? It seems like it can be powered directly from USB @5V, does it have a regulator internally?Some of the CH340 options you suggested for 5V actually have a 3.3V regulator on board, strange, I guess they don't power the chip from it and it's only for providing the 3.3V output? What's with the jumper between 3.3V and TX in all the pictures? Obviously I have to remove that to use the module, why is that there?I'm curious, what makes the PL230 so much worse than the other two options?Sorry for all the questions, just trying to understand what the differences are.Quote from: bingo600 on November 02, 2021, 07:15:32 pmYeah, I played around with that some more today, I'd really just prefer a standalone deviceThat Poulu programmer seems neat since it offers both an ISP and a serial port. Seems to work on Linux and OS X without drivers. Maybe that would be easier :-)Quote from: admiralk on November 02, 2021, 07:23:08 pmThanks, I haven't seen that one, will watch! While I'm still entirely clueless about electronics I at least have professional experience with Makefiles and Linux C/C++ development :-)Quote from: westfw on November 02, 2021, 11:46:34 pmOk, that's of course a bit of an issue with something like an ATTiny85 and I think even the ATMega328p has only a single SPI interface IIRC, so you basically lose SPI or have to disconnect the programmer each time.Quote from: westfw on November 02, 2021, 11:46:34 pmI have to admit that I know nothing about USB, so I simply assumed that the microcontrollers were using one of their various hardware interfaces to talk over USB. If it's just some barely out of spec bitbanged USB implementation that of course sounds like a source for trouble. Since the Pololu programmer doesn't exactly cost much I might as well buy that instead. I just don't want to invest too much in since I have no idea if I'll stick with this platform beyond a few weeks of playing around. The PIC in the Pololu has 'proper USB' thanks to its different chip?Quote from: westfw on November 02, 2021, 11:46:34 pmI got plenty of USB2 hardware, right now I SSH into an old USB2-only Linux laptop on my bench to talk to anything on there, but I might as well buy a more trouble free programmer since it doesn't cost much.

author: ledtester
author_rank: Super Contributor
timestamp: November 03, 2021, 04:14:55 am
content: Just want to mention that the forum avrfreaks.net is a good resource for non-Arduino programming of AVR devices.

author: SL4P
author_rank: Super Contributor
timestamp: November 03, 2021, 07:56:20 am
content: While a lot of the advice is helpful, I was lucky enough to come from the first generation of micros in the late seventies…As such, the layers of BS added by various parties really haven’t added any value over the years.I regularly build up my own boards (AVR and other), and as long as you can read a data sheet and errata, you’re generally good to go. Not much breadboarding required once you know what you’re doing.The choice of adding serial/USB is project dependent, if you’re not sure then you’re in the wrong business.If they’re free, you can expose the UART pins, and interface later, but ISP is all you need to get virtually any project running.So much of what’s being discussed as ‘fact’ depends entirely on your skill set, and what you’re trying to build.Yes, there are more complex projects, but they’re often just nailing other smaller blocks together (a skill in itself).

author: westfw
author_rank: Super Contributor
timestamp: November 03, 2021, 08:32:02 am
content: QuoteThat's the advantage of a SNAP (supports all sorts of Microchip MCUs) or using an Arduino as the programmer (can be switched back to being an Arduino.) If you want to have a "dedicated device", you CANdedicatea cheap Arduino clone to being a programmer. That's basically what I've done: I have an old derivative board (an MDC "Bare Bones Board" - one of the first Arduino work-alike kits) that conveniently doesn't even have the troublesome auto-reset circuit (or you can leave it out.) It sits there on my desk with ArduinoISP loaded and an ISP cable connected, and it only rarely needs anything else done to it.

author: Rooster Cogburn
author_rank: Regular Contributor
timestamp: November 03, 2021, 10:03:51 pm
content: Quote from: ledtester on November 03, 2021, 04:14:55 amYes, they're impossible to miss, shows up a lot in Google results!Quote from: SL4P on November 03, 2021, 07:56:20 amMaybe I should've started even simplerI thought it would valuable to go start with a simpler 8bit microcontroller like the AVRs. I plan to work towards building something involving analog video, so I might just need something more powerful like the ESP32 or the RPi Pico. But I figure it would be nice to start with something fairly basic. I got plenty of experience writing code for DSP-like architectures, game consoles, the usual 8bit CPUs like the 6502 etc., it's just trying to figure out all the electronics part and the AVR specific workflow that kept tripping me up.Quote from: westfw on November 03, 2021, 08:32:02 amI'm mostly trying to keep my spending under control. I the past months I acquired gear for various repair jobs and it's always easy to talk yourself into spending just a little more to get a bit more quality or another feature. There's also something to be said for starting with a cheap device and actually understanding the limitations. I started with a 10EUR multimeter and quickly understood why I needed something better. I've been using a 100EUR DMM for a couple of years and I now know exactly what I'd be looking for in a 500EUR one. I think I'll try to find a cheap local distributor for the Pololu and maybe order another programmer from AliExpress as well just to play around. And I still got that Uno, which is also just a nice device for quickly trying out things thanks to it's trivial setup time and pin headers.

author: admiralk
author_rank: Regular Contributor
timestamp: November 04, 2021, 08:46:32 pm
content: Quote from: Rooster Cogburn on November 03, 2021, 10:03:51 pmYou cannot get much simpler than AVR, there is virtually no setup involved. In the videos I posted, he shows you how to dig through the datasheet to find what you need, so it is easy to adapt to whatever AVR you have on hand.When you are ready to step up, I would suggest ARM over an ESP32. Nucleo boards are dirt cheap considering the programmer is built in.

author: Rooster Cogburn
author_rank: Regular Contributor
timestamp: November 05, 2021, 12:26:06 am
content: I watched the first few videos from the playlist you suggested, thanks again. I'm quite suprised that Atmel Studio looks decent. When I heard about an IDE made by a microcontroller manufacturer I expected the worst, but it's actually based on Visual Studio and seems usable, probably a decent option if you're on Windows.I've never heard of the microarchitecture of the ESP32 CPU core before, guess it was a lot cheaper to license than ARM.Haven't heard of Nucleo boards, but at ~35EUR they seem quite expensive compared to the <4EUR RPi Pico or ~6EUR ESP32 boards.

author: admiralk
author_rank: Regular Contributor
timestamp: November 06, 2021, 03:05:28 am
content: I like VS, so AS is a no brainer to me, although I tend to use Qt Creator for PC projects.I could be missing something, but I have not seen an ESP32 that did not have integrated wireless. Unless you are aiming for wireless, those resources could be put to better use. I never had much interest in PIs, my impression has always been they are just mini PCs, so cannot say anything about them.The last time I looked at a Nucleo board, a couple days ago, it was $13 USD and only available in Europe from RS. Actually I just checked and RS does not seem to want to deal with America, at least from the ST link, but they list it @ $13.https://www.st.com/en/evaluation-tools/nucleo-f401re.html#sample-buy<edit> Oh yea, that involves yet another IDE, but what does not. </edit>

author: Rooster Cogburn
author_rank: Regular Contributor
timestamp: November 06, 2021, 11:22:17 am
content: These days I'm mostly Mac/Linux but I've used VS for years and also quite like it, great to see this option exists!The normal RPis are just mini Linux PCs with the addition of a GPIO header that can do PWM, UART, I2C and SPI and some interfaces for cameras and displays. The RPi Pico is a custom designed ARM based microcontroller with a <4EUR dev board and <2EUR chips, so I think it's quite interesting. Considering how dirt cheap the ESP32 is I'm not sure the wireless going to waste is much of an issue. I know of some ESP32 based projects that only used the WiFi to allow for easy firmware update.btw, RS seems to be the only 'big' distributor in the sense of Mouser/Digikey here in Europe, the kind of place that basically got everything. I remember ordering from them quite a bit in the early 2000s, but now it seems they only accept business customers. They have a non-business site, but it's pretty terrible and lots of things don't seem to be available there. Hm, wish I could buy there!

author: Rooster Cogburn
author_rank: Regular Contributor
timestamp: November 06, 2021, 09:03:11 pm
content: btw, got my Pololu programmer today. I didn't do much with it yet, but it seems great. There's extensive and quality documentation, software for Windows, Linux and OS X, command line and GUI tools to configure the programmer, it does both AVR ISP and Serial, autodetects 3.3V vs 5V supply voltage and can be configured to output either, plenty of feedback about the USB connection, voltage supply, programming status etc. from the LEDs. Seems like a very well thought out device with lots of features and considering I paid like 11EUR shipped I'm extremely happy with it.

author: brucehoult
author_rank: Super Contributor
timestamp: November 06, 2021, 10:51:18 pm
content: Quote from: Rooster Cogburn on November 03, 2021, 10:03:51 pmYou can't get simpler than an AVR! Anything else is far more complex both electrically, and software-wise to initialise if you don't just use someone's library to do it for you.With the ATTiny85, for example, you just need to connect GND and VCC and it will start up and run at 1 MHz. Connect the RESET and SPI pins to your Uno running ArduinoISP and you've got it programmed.The Atmega328 can also be used from its internal 8 MHz oscillator without any external components. You need to connect GND to pins 8 and 22, and VCC to pins 7 and 20 as the 328 powers the analog and digital parts of the chip separately.Of course the clock frequencies will not be as exact as using a crystal, but it often doesn't matter. They're plenty good enough for generating in-tolerance UART baud rates or the timings to drive a string of WS281B? LEDs.If you're happy with the default clock speed then your program can just launch straight into configuring whatever GPIOs you need. Nothing else needed unless you want to.

author: brucehoult
author_rank: Super Contributor
timestamp: November 06, 2021, 11:00:17 pm
content: Quote from: Rooster Cogburn on November 05, 2021, 12:26:06 amI think you mean Instruction Set Architecture (ISA), not microarchitecture. CPUs with the same ISA can have dozens of different microarchitectures.Older ESP32 use xtensa, a fairly popular ISA now owned by chip design tools company Cadence. Its main claim to fame is that Cadence allow and encourage and provide tools for adding custom instructions to the CPU. It's a fairly generic RISC design with 16 GPRs and two instruction lengths of 16 bits and (unusually) 24 bits.New ESP32 chips use RISC-V cores, or in one intermediate model a fast(ish) xtensa core and a low power RISC-V core.