Arduino: To(o) cheap or not to(o) cheap? - Page 1
Forum section: electronics / beginners

author: RyanT
author_rank: Contributor
timestamp: March 20, 2018, 04:43:03 am
content: Tiny bit of background: I'm getting back into electronics as a hobby after a brief 30-year(!) break, in part thanks to Dave's excellent content and this intellectually electroplated gold mine of a forum. I threw together a few simple circuits (555 stuff, bench meters, fixed our ice machine, etc.), but would like to start some Arduino hacking (probably with an UNO R3, but really any of them would be fine for now).[Edit:Seepost #12for more background. I stupidly left out the fact that I've been an embedded programmer (including ARM/Atmel micro programming) for a couple of decades.]Right, background over.The problem I'm having getting an Arduino is that there areso manydarned options, and what seems like a dearth of credible reviews on any of them. I can buy a brand nameUno R3 from Sparkfunfor $24.95, or one of the many clones for $5-10 shipped on a slow dinghy from Shenzhen. It turns out I'm still pretty decent with a soldering iron, so I don't mind putting the thing together if it'll save a few bucks. Money is a bit tight at the moment as I'm not able to work, so if I can save and put that toward other components, and/or get two Arduino boards, I'm all for it, as long as the board isn't likely to let the blue smoke out the third or fourth time I power it up, barring stupidity on my part.So what would you all recommend? Go brand name, or no? And if no, it would really help to have a link to some known good ones. (As best you can, anyway, as it seems the Arduino clone market is a fast moving target.) At least then it'd be an educated guess.Finally my apologies to the mods and regulars if this question has now come upn+ 1 times or is off-topic here. I spent quite a bit of time with the forum search and couldn't find anything relevant.

author: imidis
author_rank: Frequent Contributor
timestamp: March 20, 2018, 04:46:30 am
content: If you are on a budget buy a clone, 5ish bucks. I've got several, no problems. Same with lots of the aliexpress stuff. I just don't trust any of the mains powered stuff.

author: Ian.M
author_rank: Super Contributor
timestamp: March 20, 2018, 07:49:43 am
content: The main reason to start with Arduino, specifically an ATmega328P based one, is its popularity that has resulted in a massive ecosystem supporting Arduino users. There are many things about the Arduino that suck from the point of view of an experienced developer, but its got the mass market penetration, and wealth of add-on shields, hardware libraries and tutorials to appeal to a novice. However you need some aptitude for programming.If you've ever programmed an 80's era 8 bit home computer, or done any C programming for a resource limited system, you wont have any issues that cant be resolved with a little research or a quick question here or on one of the many specialist Arduino forums. If 'programming' a VCR is outside of your comfort zone, then forget about it and stick to analog electronics!I would suggest a UNO clone with a socketed ATmega328P (or even a genuine official one if you are rich and want to support Arduino.cc anonymously), simply so you know you can easily replace the chip if you let the holy smoke out.To prepare in advance for accidents, get a couple of spare PDIP ATmega328P chips, either from a specialist Arduino supplier, preloaded with the Arduino bootloader - 16MHz version, or blank from your preferred regular distributor. If they are blank, set up the Arduino with the ArduinoISP sketch to burn them with the UNO bootloader.See:https://www.arduino.cc/en/Tutorial/ArduinoToBreadboardandhttps://www.arduino.cc/en/Tutorial/ArduinoISPOnce they have the bootloader installed, check them in your Arduino board with the Blink sketch, then put the two spares aside. Unless you are really unlucky and fry the USB<=> logic level serial chip on your Uno, you've then got some chances to fix it if you do something stupid like blow out an I/O pin.Also, you can easily use those spare chips in your own projects - simply prototype it on the Uno then move the programmed chip to your own board and replace the Uno's one with one of the spares.Once you've dabbled your toe in the Arduino waters, you'll have a much better idea of where you want to go from here - whether its deeper into Arduino-land or abandoning it totally for a more powerful MCU.

author: josip
author_rank: Regular Contributor
timestamp: March 20, 2018, 07:54:06 am
content: Quote from: RyanT on March 20, 2018, 04:43:03 amI will not suggest anyonetodayto start with 8-bit mcu. Even for blink example.Blue Pill (Cortex-M3, 72 MHz, 64 KB Flash, 20 KB RAM) can be found on ebay for around 2$...http://wiki.stm32duino.com/index.php?title=Blue_Pillhttps://www.ebay.com/itm/201414966215And ST-Link cone for around 2$...https://www.ebay.com/itm/191736124906

author: Ian.M
author_rank: Super Contributor
timestamp: March 20, 2018, 08:29:19 am
content: One starts with a socketed 5V, 8 bit MCU for the simplicity and ease of interfacing.Of course it doesn't make sense from a price/performance viewpoint, but if that PSoC kit Blueskull recommended or that Cortex-M3 you just proposed sits in the cupboard gathering dust because the learning curve is slightly too steep for some novices, the price/performance ratio is infinitely unfavourable.Worst case, if the O.P. decides embedded programming isn't their cup of tea, an Arduino Uno can easily be passed on to someone else locally. A more specialised MCU board is either likely to end up in the trash, or one has to advertise it online to find anyone to take it off your hands then ship iit to them.

author: Brumby
author_rank: Unknown
timestamp: March 20, 2018, 09:02:56 am
content: Quote from: josip on March 20, 2018, 07:54:06 amWhat a stupid exclusion.When getting started, let's not muddy the water with issues THAT ARE BEYOND the Op's ability to utilise at this point in time. Let them start cheap and easy, gain success, find limitations, learn more and develop their skills.To the OP: Go and grab yourself a couple of UNO clones and just dive in. They are cheap and there is an established following and an IDE that you can download for free and get something simple running in minutes. Sure, it may not be as "perfect" as some of the hard-nosed might prefer - but you can do a huge range of stuff. You can even rise above the IDE and get really serious if you want. The choice is up to you.Just ignore the other noise people will make about "Get this" or "Don't get that" - until YOU find you are encountering limitations that are really affecting your progress ... but unless you have exotic projects in mind, it's going to take you a while to get there. I'm not saying these people don't have a point - but until you get enough experience to be able to judge for yourself, you are simply going to get spun out by it all.As for where to get the boards, I have purchased MEGA, UNO and NANO clones from whoever had the cheapest and all of them have been OK.Just jump in.

author: NivagSwerdna
author_rank: Super Contributor
timestamp: March 20, 2018, 09:12:24 am
content: UnoeBay auction: #142051313005So cheap it's not even worth thinking about it for very long. I prefer Unos that have two crystals (rather than a resonator) due to some of my applications which are timing sensitive. I even buy these sometimes for parts for my own designs since they are so cheap.

author: picandmix
author_rank: Frequent Contributor
timestamp: March 20, 2018, 09:22:26 am
content: Agree with most of what IanM says, a clone Uno board is the best way to begin with, its got the widest support and masses of online tutorials of any of the micros.The Uno is also preferred because it has all its i/o pins on handy sockets ready to plug into breadboards etc.While I agree with Ians point about a dip chip version of the Uno in principle, I don't think its worthwhile these days, the price of a new 328 dip chip is typically the same or more than the cost of a new clone Uno board with a smd chip.Not sure about Canada, but here in the UK you can pick up clone Unos cheap enough locally without having to wait weeks from the far east.

author: Mechatrommer
author_rank: Super Contributor
timestamp: March 20, 2018, 09:26:26 am
content: Quote from: josip on March 20, 2018, 07:54:06 am+1 i've been meaning to move to arm chip in fact i have all the tools already but atmega/attiny/pic poison still flow in my intervein blocking my desire to move on.if you have to go arduino way, buy clone there is no justification to buy original other than to support the original creator. and if you have to solder in, i think you'll need avr programmer as well such AVR Mk 2 or such. the cost might be similar to buying arm ecosystem anyway.

author: ggchab
author_rank: Frequent Contributor
timestamp: March 20, 2018, 09:29:29 am
content: My son is still learning the PIC16F84/16F627 at school. They designed a small PCB and they are now playing with I/O ports, timer, interrupts to control a few LEDs and keys and even a 2x16 characters LCD. Programmed in assembly. This is simple and fantastic the discover how things are really working

author: RyanT
author_rank: Contributor
timestamp: March 20, 2018, 09:39:00 am
content: Thanks for all the replies so far! Great info.One apparently very important point that I left out of the OP in some misguided attempt at Canadian humility and clearly failed brevity is my programming background. I've been a ARM/x86 C/assembly/etc. embedded software developer for 25+ years, with a good amount of Atmel and PIC micro programming, talking to custom FPGAs for which the "datasheet" was literally a guy named Steve who sat next to me, for a number of years.As such I know Icanprogram just about anything with inputs and a clock pin. However I've also more than once pissed away weeks of (fortunately, paid) work patching toolchains and writing drivers to port and cross-compile libraries for poorly supported or downright unpopular architectures my employer used in their products to save five cents and a couple milliwatts. I don't have any particular love for the Arduino as I've never worked with it, but as far as I'm aware, it has one of the largest (if not the largest) collections of free and supported libraries/software in the land, and most of it Just Works™. Is that reasonable, or am I on the wrong track?

author: bd139
author_rank: Super Contributor
timestamp: March 20, 2018, 09:39:40 am
content: Arduino is absolutely fine to start with. It has a few advantages that make it easier to start with:1. Clones are dirt cheap. I mean really cheap. They all work fine.2. Provided libraries are quite good. They do the job certainly.3. Set up time is minimal. This is the opposite of every other embedded platform out there.When you have had enough or hit a limitation, you can reuse the hardware and just program it with AVR-gcc, AVR-libc and avrdude.Personally I started with Z80, hand assembled and toggled in. Then 6502 assembly+BBC BASIC. Then moved to 68k, x86 and SPARC assembly and C. Then PIC, then AVR. The AVR is pretty nice and the tooling is way more mature than elsewhere.

author: NivagSwerdna
author_rank: Super Contributor
timestamp: March 20, 2018, 09:45:51 am
content: Uno is entry level, mega2560 has multiple uarts and more I/o, esp32/esp8266 is awesome for WiFi connectivity, STM has some interesting stuff (blue pill?), Rpi for some Linux and some I/o, de10-nano for FPGA soc, and I love PIC (various series) since they brainwashed me with their samples program over the years.It rather depends on what you are trying to achieve!

author: RyanT
author_rank: Contributor
timestamp: March 20, 2018, 10:37:21 am
content: Quote from: Ian.M on March 20, 2018, 07:49:43 amDoes electrical tape over the clock count?Seriously, thanks for this really comprehensive reply. You did say "There are many things about the Arduino that suck from the point of view of an experienced developer". Would you care to elaborate on that a bit? I do have significant professional experience in embedded dev, but I'm not so stuck in my ways that I wouldn't work with another IDE if absolutely necessary (though 99% of the time I'd be happier with Vim and a good command line toolchain in a Linux terminal).My use case for this is really just to have a relatively general purpose dev board on hand for miscellaneous prototype/experimental/fun projects. Nothing real-time, high performance, or high power. If I was to build anything more serious, I already know how to spec an appropriate micro for a specific set of requirements. It's just that my current requirements are deliberately and frustratingly non-specific.

author: Ian.M
author_rank: Super Contributor
timestamp: March 20, 2018, 11:04:53 am
content: Quote from: picandmix on March 20, 2018, 09:22:26 amGood point. Maybe keep a spare Arduino with a SMD MCU, but if you don't get a socketed Uno, you loose the easy option for moving the programmed chip to your own project board when you get fed up with jumpering over to a breadboard or scratch-building proto-shields.However if you can stand the excrescence of an unused USB<=>UART chip and USB connector sitting inside your project, getting a ten pack of Arduino Nano clones cheap from China (for the bulk price) and soldering it in as a daughter-board may be easier and equally cost effective. Where that approach falls down is battery micro-power projects, as there's a lot of board hacking to disable stuff you don't need that will cause excessive quiescent current consumption if you leave it, and when you've hacked out the LEDs and lifted the CH340g supply, RXD and TXD pins, there's a significant risk the ATmega328P is *STILL* going to draw excessive sleep current due to damage due to poor ESD control at the factory and during distribution and shipping. OTOH If you get a bare chip from a reputable western distributor, it comes in an antistatic bag, and you can be fairly confident it will deliver its rated sleep current unless you FUBAR it by lack of ESD precautions yourself.Anyway a ATmega328P-PU chip isn't very expensive at MicrochipDirect:https://www.microchipdirect.com/product/ATmega328P-PUThe only issue will be prohibitive P&P on very small orders, which is why I recommended using one's usual distributor so you can combine it with other stuff - unless they are ripping you off on Atmel MCUs.Quote from: bd139 on March 20, 2018, 09:39:40 amInstalling the Arduino IDE is one of the easiest ways of getting a reasonably current AVR-GCC toolchain installed on a Windows PC, even if you never use the Arduino IDE because you prefer your own favourite IDE or programmer's editor.

author: NivagSwerdna
author_rank: Super Contributor
timestamp: March 20, 2018, 11:16:34 am
content: Quote from: RyanT on March 20, 2018, 10:37:21 amThis is oft quoted but personally I don't agree. The default Arduino environment has a very basic IDE and the device itself has 'wiring' which abstracts away the hardware but there are no reasons you cannot drop down a level and get at the registers directly or put all your code in your own routine and avoid the overhead of loop(), or use the ICSP connection and Atmel ICE or Dragon and use AVR Studio. Even assembly level programming is available in the Ardunio IDE with a few tweaks,[I'm assuming this is non-commercial tinkering]

author: Ian.M
author_rank: Super Contributor
timestamp: March 20, 2018, 11:43:51 am
content: Things that IMHO suck about Arduino Uno and Arduino IDE.Hardware - crazy Italian design decisions:#1. Off-grid header layout that makes it difficult to use stripboard or matrix board. Seriously, how hard is it to set the grid to 0.1" and enable snap to grid when placing connectors on a PCB? There *MUST* have been some other agenda - maybe to encourage the sale of shields.#2. Crappy capacitive coupling of Reset pin to USB UART chip's control line. Would an isolation resistor or pluggable jumper so AVR debugWIRE would work 'fresh out the box' with an external debugger, have cost that much? Having to take an Xacto knife to your Uno if you want to use debugWIRE or even if you want to avoid the Uno resetting if you close and reopen the USB serial port from the PC, is a PITA. Not putting unpopulated pads for the user to add a pluggable jumper after making that cut is unforgivable.#3. Marginal heatsinking for 5V regulator - it could have used a lot more copper area and possibly pads round its tab for the user to solder on additional heatsinking.#4. When the Uno was revised to use an AVR for its USB interface, which required a real 16MHz crystal, would it have been too much to ask to add a single gate buffer to tap that reasonably accurate 16MHz for the ATmega328P to replace the crappy ceramic resonator?IDE & toolchain suckitude:#5. The code 'pre-munger' that attempts to automate forward declarations, (but FUBARs some legitimate C++ stuff) and parses the primary .ino file of the sketch to determine what files go in the build.#6. Ditching main() and forcing the use of setup() and loop(). IMHO it would have been better if a hidden auto-generated main.cpp was created for each sketch, containing the main() function (with calls to initialisation functions and user supplied setup() and loop() functions) and Timer 0 interrupt vector definition, so the expert user could un-hide it and customise it to write vanilla AVR GCC code that hits the bare metal. There are some workarounds that let you write your own main(), but you cant get the Arduino timekeeping ISR off the timer 0 overflow vector unless you write your own patched AVR core.#7. Sucky IDE editor - lets not go there - EMACS with the apocryphal and infamousspace bar heating hackwould be preferable.

author: Brumby
author_rank: Unknown
timestamp: March 20, 2018, 12:03:00 pm
content: Quote from: RyanT on March 20, 2018, 09:39:00 amWell .... ummmm .... that is something of a disclosure.But if you want some inexpensive and useful hardware, Arduino clones are good value.

author: NivagSwerdna
author_rank: Super Contributor
timestamp: March 20, 2018, 12:03:22 pm
content: or vim with a vim clutch?https://github.com/alevchuk/vim-clutchPS+1 to everything Ian said, but an experienced developer will be able to work around quite a few of the niggles... and the hardware is SO SO SO cheap. But don't disregards the ESP32 suggested earlier... that's very fun for IoT

author: RyanT
author_rank: Contributor
timestamp: March 20, 2018, 12:29:34 pm
content: Quote from: NivagSwerdna on March 20, 2018, 12:03:22 pmHa! Yeah, I have a very similar looking pedal that plugs into the back of my Kinesis Ergo with an RJ11 plug that I've mapped for the same purpose. Also doubles as a great hands-free push-to-talk button in online voice chat. As you do, I guess...Thanks again for the advice.

author: RyanT
author_rank: Contributor
timestamp: March 20, 2018, 12:38:34 pm
content: Quote from: Brumby on March 20, 2018, 12:03:00 pmYeah,mea culpa.I really should have known you all don't know me as well as Steve does.I miss Steve.

author: josip
author_rank: Regular Contributor
timestamp: March 20, 2018, 03:00:36 pm
content: Just to clarify...I mentioned Blue Pill, because it can be integrated in Arduino IDE...https://hackaday.com/2017/03/30/the-2-32-bit-arduino-with-debugging/https://onetransistor.blogspot.hr/2017/11/stm32-bluepill-arduino-ide.htmlIt is 3.3V device, but this voltage is enough for driving 5V logical input / signal. It has 5V tolerant pins, and board can be inserted (stacked) to another proto board, so chip package is irelevant here.Unfortunately, when I was starting in micro world (30 years ago), I used what was available at that time. But if I am starting today, I will do it by ARM way, definitely. Don't see any reason for comeback to stone age. If I am teacher in class, and I have privilege to chose devices by myself, it will be ARM, and I will do low cost boards by myself for this. No PIC, Atmel or MSP.My 2 cents, only.

author: imidis
author_rank: Frequent Contributor
timestamp: March 20, 2018, 05:28:38 pm
content: Quote from: josip on March 20, 2018, 07:54:06 amThis just drives me nuts. Why on earth would anyone excludeanychip? If someone is actually going to seriously get into stuff like this, choosing an appropriately spec'd chip and appropriately priced chip for the task is important. Seem kinda silly to use something like a cortex-m3 when some cheaper and simpler will do a particular task just fine.

author: Mr. Scram
author_rank: Super Contributor
timestamp: March 20, 2018, 05:42:39 pm
content: Quote from: RyanT on March 20, 2018, 09:39:00 amIn that case you can't go wrong with a couple of Chinese Arduino clones. I don't think they're failure prone at all. If you want to get your feet wet with something more modern the aforementioned Cypress sticks are great value. Both have a well developed IDE and are both cheap and capable devices.As I understand it the STM toolchain can be a bit more challenging.

author: bd139
author_rank: Super Contributor
timestamp: March 20, 2018, 05:51:39 pm
content: Just a point on power, your average AVR is more than adequate for a huge amount of tasks where someone just says "use a Cortex-M3" or something. It actually annoys me.Incidentally, the most compact I've found is PIC. I recently downsized a project from Cypress+FreeRTOS to AVR with tiny homebrew OS to PIC with an interrupt handler. Compiled codebase which was equally as functional went down from 18k to 5k to 800 bytes. I wrote the PIC version in assembly which is burned into my brain after many years. It's really easy to pull in a lot of expensive and heavy functions in C.

author: RyanT
author_rank: Contributor
timestamp: March 20, 2018, 06:40:05 pm
content: Update!On the advice of several of you, I've gone ahead and ordered a couple of $4 Uno 3 clones (socketed uC). I also tagged a couple of extra ATmega328Ps for my next Digi-Key order, for bits and giggles.I by no means want to discourage further conversation, though. The kind of information you've all shared will be invaluable for future projects, too.Thanks again.

author: NivagSwerdna
author_rank: Super Contributor
timestamp: March 20, 2018, 07:37:39 pm
content: Quote from: RyanT on March 20, 2018, 06:40:05 pmHot air is like removing from a socket for the SMD equivalent. But each to their own. DIPs are so last century.

author: metrologist
author_rank: Super Contributor
timestamp: March 20, 2018, 08:02:20 pm
content: Well, I like the nano form factor. Most of my solderless breadboards have a nano on them.

author: Brumby
author_rank: Unknown
timestamp: March 21, 2018, 12:58:25 am
content: I like the nano FF as well. In my last serious project, the board could fit inside the existing case even using the mini USB socket with a creative cabling solution, which allowed for a field replaceable USB cable.Although having limited on board I/O there's still a lot you can do. This project used everything except the TX/RX pins and digital pin 13 (but that last one is tagged for an additional option).The only problems I've had were:* At the very beginning, realising I needed the CH340 driver. I was expecting FTDI, but once I worked this out I actually felt a whole lot more comfortable knowing I didn't have the FTDI Sword of Damacles to worry about.* Not being able to find some of the library components in the IDE (that is seriously impossible to follow for acasualuser). A fresh download and install of the complete IDE fixed that.* Incorrect testing technique (a.k.a. my own stupidity) blowing out an I/O pin or two. The processor still works and if I ever get around to it, I could identify the dud pins and maybe use it for some simple project.* Bricking a couple through my own less-than-brilliant efforts. It's probably just the bootloader I've stuffed and maybe I'll get around to reflashing that at some point.I have a couple of MEGA 2560 and MEGA ADK boards as well as UNO, but I buy the NANO in lots of 5. At circa $3 a pop, why wouldn't you?And, yes, there are certainly "better" chips and platforms out there - but they aren't necessary for the type of stuff I generally do today. Arduino does it. If I ever step into an area where that's inadequate, then I will examine the options at that time. Doing that now might turn out to be an exercise in studying history.

author: alsetalokin4017
author_rank: Super Contributor
timestamp: March 21, 2018, 03:39:58 am
content: Quote from: metrologist on March 20, 2018, 08:02:20 pmI like the ProMini myself, since once a project is encased I no longer need a USB interface. They are so cheap from China it's unbelievable.

author: paulca
author_rank: Super Contributor
timestamp: March 21, 2018, 07:44:15 am
content: My 2 cents...Uno clones are grand. They come in a variety of honesty though. A "good" clone will have a socketed DIP ATMega chip and a 16u2 USB interface.... ie. it will look exactly like the original. They can be found for under $5 on ebay. The cheaper clones use a surface mount ATMega and usually a CH380 USB chip. The later can have some driver issues in Window's I'm told, but it's solvable with google. The CH380 is much more robust, the genuine Arduino USB chip is prone to getting fried if you do anything nasty with the power rails.Don't aim for STM, Arm, et. al. as there is nowhere near as much support when getting started.Nano clones are potentially better as they slot into a breadboard limiting the amount of stuff on the desk and make it easy to just embed one into a project long term, or even solder it into a strip board. Nano clones can be got for as little as $3.You won't need a programmer straight off as both the Uno and and Nano are capable of being a decent ISP programmerifyou choose to go "chip only" on a breadboard. The sketch you need comes with the Arduino IDE "Arduino as ISP" and the only other thing you need are 5 breadboard jumper leads. I have found the other cheap ISP programmers less reliable. Genuine AVR programmers are far more expensive.

author: bd139
author_rank: Super Contributor
timestamp: March 21, 2018, 09:33:01 am
content: Actually who needs an arduino? Here's what I'm using for AVR dev. As simple as it gets. If you're on windows use the arduino toolchain to build it:Schematic:Hardware:Program:Code:#include <avr/io.h>#include <util/delay.h>int main(){// Set port D as outputDDRD = 0xFF;while (1){// Set PD0PORTD |= (1 << PD0);// Sleep a bit_delay_ms(500);// Unset PD0PORTD &= ~(1 << PD0);// Sleep a bit_delay_ms(500);}}Makefile:Code:# Project namePROJECT=avrhelloworld# Space separated list of all source filesSOURCES=main.c# Set the targetMCU=atmega328p# Clock speed of the AVR in HzSPEED=1000000# AVRDUDE microcontroller typeMCUDUDE=m328p# AVRDUDE programmer typePROGRAMMER=usbasp# not target specific. Don't need to change anything belowCC=avr-gccOBJCOPY=avr-objcopyCFLAGS=-c -Os -Wall -DF_CPU=$(SPEED)ULLDFLAGS=-mmcu=$(MCU)ELF=$(PROJECT).elfHEX=$(PROJECT).hexOBJECTS=$(SOURCES:.c=.o)all: $(SOURCES) $(ELF) $(HEX)$(ELF): $(OBJECTS)$(CC) $(LDFLAGS) -o $@ $(OBJECTS)$(HEX): $(ELF)$(OBJCOPY) -j .text -j .data -O ihex $(ELF) $(HEX).c.o:$(CC) $(LDFLAGS) $(CFLAGS) $< -o $@clean:rm $(OBJECTS) $(HEX) $(ELF)burn:avrdude-c $(PROGRAMMER) -p $(MCUDUDE) -u -U flash:w:$(HEX)Packages required:makeavr-libcavr-gccavrdudego go goUSBasp from ebay/bitsbox/china/wherever. Make sure you stick it in 5V mode first.

author: Ian.M
author_rank: Super Contributor
timestamp: March 21, 2018, 09:53:54 am
content: Another reason to get the genuine Uno or a 100% compatible clone with the ATmega16U2 USB interface is you can actually load custom code into the 16U2.Here's how to use the 16U2 to emulate a AVRISP mkII and program a blank '328P in its usual socket. Minimal soldering required - just to populate the header JP2, then its just a matter of connecting four short F-F jumper wires and using Atmel's FLIP tool to reload the 16U2 in DFU mode.https://make.kosakalab.com/make/electronic-work/burn_bootloader_uno_en/If you are feeling somewhat braver (and have a spare Arduino or AVR ISP programmer handy in case you brick the 16U2, or want to revert it to the DFU bootloader), you can install Hoodloader2https://github.com/NicoHood/HoodLoader2which lets you run sketches on the 16U2, turning the Uno into a multi-processor board equivalent to a cut-down Arduino Micro (only 10 I/Os available with 3 used for comms to the other AVR) with a serial interface to the standard Uno 328P,

author: paulca
author_rank: Super Contributor
timestamp: March 21, 2018, 10:54:13 am
content: Quote from: bd139 on March 21, 2018, 09:33:01 amWho needs a bakery or supermarket! Here's what I am using for bread:No, not really. I go to Tesco's.Where the non-arduino AVR stuff come into play is when you:a) Want to put your arduino-ified breadboard onto a PCB and... not solder a Nano or Mini in there.b) Want or need to decouple yourself from the nursing libraries provided by Arduino. Usually this is because the Arduino libraries come at a cost in software terms and aren't always as efficient as you would hope for. digitalWrite() probably the most used function is actually really slow in comparison to a single bit set operation on an IO port.But... until you care about those, the Arduino, to me, is like using a DMM instead of having to build a voltage divider and panel meter for each voltage measurement. I can plug it in, write a few lines of code and hit Upload, then pull it back out of the project and throw it into another one.When I come to bulding a PCB, then... I pull out the minimal schematics for the ATTiny85 or ATMega328. I still use the Arduino libs as I have yet to find them detrimental to my project. I have as a learning project created Blinky-sans-Arduino just for fun and a challenge though.To go from sitting down the bench to blinky with an arduino, I'd estimate 5 minutes.To go from sitting down at the bench and building an ATMega328P on a breadboard and creating blinky with AVR-Gcc et. al. More like an hour.To getting something like an oLED clock with a temp sensor and LDR running with avr-gcc, not including the time to port the libraries away from Arduino functions... a day.

author: bd139
author_rank: Super Contributor
timestamp: March 21, 2018, 11:00:26 am
content: Quote from: paulca on March 21, 2018, 10:54:13 amI make my own bread!

author: NivagSwerdna
author_rank: Super Contributor
timestamp: March 21, 2018, 11:21:21 am
content: Random thoughts...Instead of the 16U2 variant for USB HID devices there are lots of alternatives... e.g. Teensy (I have been meaning to update my TM22 joystick for ages) or PICs...All the NHduino clones I have use CH340G and work fine with Windows 10.I bought an AVR dragon (it was very cheap at the time) but have never actually used it on Uno.... but this does remind me that Arduino development on the whole tends to be printf or pin toggle debugging rather than proper breakpoints. (However when timing gets involved breakpoints have limited use... YMMV)

author: RationalRoot
author_rank: Newbie
timestamp: March 24, 2018, 09:44:58 am
content: Some Arduino clones need a separate driver download. Don't let this trouble you. The generally provide a link. I've used elegoo if you want a brand to try. Cheap as chips. Works just fine.https://www.amazon.com/Arduino-Elegoo-ATmega328P-without-compatible/dp/B0713XK923Hard to go wrong. You just download & install the CH340 driver. I think I got it fromhttps://www.elegoo.com/tutorial/CH340%20Driver.zip

author: paulca
author_rank: Super Contributor
timestamp: March 24, 2018, 05:43:02 pm
content: The clones are usually fine.Just as a small aside, I got one smoking the other night. Literally smoking. Supplying +5V to it's ground pin and connecting it's 5V line to earth ground via another USB device apparently didn't kill it. I had clicked "Upload" and wondered why it wasn't working, so a good 20 seconds had passed until I noticed the smoke rising from it.Wired the circuit correctly and the Aruino UNO clone still works fine.

author: josip
author_rank: Regular Contributor
timestamp: March 25, 2018, 07:17:13 am
content: Quote from: NivagSwerdna on March 21, 2018, 11:21:21 amTotally agree with this. I never use breakpoint debugging with micros.BTW, MSP430 CPUxV2 devices are with mailbox system, that can be used for log by SBW / JTAG, without any extra connection or hardware peripheral. Target device is in free running mode, during exchanging data with SBW / JTAG master.

author: RyanT
author_rank: Contributor
timestamp: March 25, 2018, 11:08:38 am
content: I'm not going to lie, debugging a uC withprintf()is going to feel like cheating compared to the embedded work I'm used to, but I think I'll manage to sufficiently assuage my guilt.

author: Ian.M
author_rank: Super Contributor
timestamp: March 25, 2018, 11:58:28 am
content: In Arduinoland, printf() is borked. It isn't connected to the UART I/O streams that communicate via the on-board USB chip to a terminal on your PC.Attempts to connect it either conflict with the Arduino's proprietary 'standard' Serial library, or have massive overheads, so get used to using their Serial.print() (or Serial.println()) methods that will only print a single variable at a time with default formatting that can only be changed between DEC HEX and OCT for integers.If you thought printf() debugging was ugly, wait till you see Serial.print() debugging!

author: Brumby
author_rank: Unknown
timestamp: March 25, 2018, 12:02:59 pm
content: Quote from: Ian.M on March 25, 2018, 11:58:28 amYeah ... it's not glamorous.

author: paulca
author_rank: Super Contributor
timestamp: March 25, 2018, 12:17:20 pm
content: A handy tip for debug and error reporting on Arduino when you don't have a serial connection is to blink an LED.This becomes more important when you put an AVR chip into a PCB and realise you have no Rx/Tx test/debug pins available. I'm sure you could use the ISP header (if you have one of those), but the LED method will still be available when your circuit is away from the apron strings of the PC.As an example on my solar charge controller WiFi monitor device - which uses an ESP8266 but the concept is the same - I use the built in LED as diagnostics.At power up I turn the LED on.When waiting on the Wifi to connect I toggle the LED repeatedly with a 100ms delay. (Rapid flashing).When the WiFi connects I flash the IP address 4th octet, eg, if it gets 192.168.0.8, then I flash the LED 8 times. If it gets 252 I flash the LED twice, wait, flash it 5 times, wait, flash it twice.The LED then goes out.When in it's main operational loop, a single 100ms pulse signifies a successful operation. 3 flashes denotes a failed operation. Constant rapid flashing indicates a terminal condition it cannot recover from and should probably force a reset.So without plugging it in or poking at it with the Wifi and checking logs on the thing that receives data from it, I can look at it and wait 5 seconds for a loop to complete, if it pulses once, it's fine. When I turn it on I can see the rapid flashing as it connects to the Wifi and known when it stops everything is fine, if it doesn't stop it's borked.Consider this if you ever put a power LED into an AVR circuit. Instead run the power LED off a uC pin and use it not just for power, but for diagnostics. If you have more complex output, just use more LEDs.(Aside: Of course as mine is an ESP8266 which is substancially more powerful than an Arduino and has built in Wifi I could probably construct SysLog UDP packets and send them to a SysLog server to actually create a log file.)https://github.com/arcao/Syslog

author: ogden
author_rank: Super Contributor
timestamp: March 25, 2018, 12:32:57 pm
content: I suggest to not confusetogether learning with building. The best learning tool is not always best building tool. I usually suggest tostartlearning with Arduino, yet I do not suggest to build anything with it. Depending on your personal learning curve steepness after Arduino you can move to next level sooner or later. Some just buy everything - arduino, bluepill and what not, from very beginning, check everything to see which one is the best for them.

author: westfw
author_rank: Super Contributor
timestamp: March 26, 2018, 09:14:03 am
content: QuoteNonsense. Adding printf() support to an AVR Arduino is relatively trivial, and has no more overhead than most printf() implementations (significantly less than the average newlib-based printf(), in fact.)Code:#include <stdio.h>int fput(char c, FILE* f) {Serial.write( c);return 0;}void setup() {Serial.begin(9600);stdout = fdevopen(fput, NULL);}QuoteWell, I'd suggest excluding things like the ATtiny13, or ATmega48 just to for "playing", even if it does save several dimes per chip. That kind of optimization is for ... later. In theory, the ARM vs AVR decision is similar. In practice, it's not - an ATmega328 Arduino had plenty of headroom in both performance and memory space for most "applications."QuoteThis seems to be underdeveloped, and used a lot less frequently than might have originally be intended. One reason is that Arduino (and competitors) with actual native USB support started showing up, and they're generally a better solution if you want to speak directly to USB.(Teensy, Arduino Micro, Leonardo, ...)

author: igendel
author_rank: Frequent Contributor
timestamp: March 26, 2018, 09:54:57 am
content: Joining the discussion a bit too lateI have seenmanycheap Arduino clones with issues. Some from my own collection, some brought to me for repair by local makers. The problems can beanywhere- from fake/wrong ICs to missing bootloaders to faulty soldering at the hardest-to-reach places.For the price of a genuine Arduino board, one can buy 5-6 clones and most of them will be ok (assuming not all are bought from the same seller of course). However, having to troubleshoot a bad board is really hard, annoying and discouraging for beginners. So at least in countries where $30 is notthatmuch, my advice is to get one genuine board to begin with. When you know your way a little around the Arduino you can risk clones.

author: Mr. Scram
author_rank: Super Contributor
timestamp: March 26, 2018, 10:54:26 am
content: Quote from: igendel on March 26, 2018, 09:54:57 amAnother way of dealing with that would be to use the numbers to your advantage. Buy two variants. In the unlikely case one has issues, the other should be fine.

author: NivagSwerdna
author_rank: Super Contributor
timestamp: March 26, 2018, 12:31:27 pm
content: Quote from: igendel on March 26, 2018, 09:54:57 am100% of mine have worked. Guess I have been lucky. I tend to stick to the "NHduino" variants which have a CPU XTAL as well as the USB XTAL.https://www.mikrocontroller.net/attachment/258727/CH340G_UNO_ArduinoBoard_3.pdfe.g.eBay auction: #142051313005oreBay auction: #141676813121

author: igendel
author_rank: Frequent Contributor
timestamp: March 26, 2018, 01:14:02 pm
content: Quote from: NivagSwerdna on March 26, 2018, 12:31:27 pmBut... all Uno-type boards have that, don't they? I think only the old Duemilanove models with the FTDI chips didn't have a cyrstal for the USB. Or perhaps I should say"FTDI"

author: Bassman59
author_rank: Super Contributor
timestamp: March 27, 2018, 03:39:02 am
content: Quote from: paulca on March 25, 2018, 12:17:20 pmInstead of blinking an LED, you could monitor an otherwise-unused GPIO pin (or two, or more) with an oscilloscope. This is very handy for checking to see how often an interrupt occurs, for example. Set the pin when you enter the ISR, clear it when leaving. Or just toggle it on entry. You’ll never see that change on an LED, but it’s quite obvious on a ‘scope.

author: westfw
author_rank: Super Contributor
timestamp: March 27, 2018, 05:22:59 am
content: QuoteAFAIK, all of the uno-type boards that need it have a crystal for the USB microcontroller, but the official boards opted for a resonator for the main processor. (and I don't understand why. The original Unos has a dual-layout PCB, and at least one batch was populated with crystals. Despite occasional statements to the contrary, standard-ish crystals don't seem to be significantly cheaper than resonators. The resonator on the Uno is TINY, but doesn't need to be. And as Ian pointed out, if they were really cutting costs, they could have used an output from the USB microcontroller to drive the main CPU input. OTOH, this was also about the time that Arduino was trying to get their boards into retail stores like Radio Shack and MicroCenter, so perhaps they were being especially paranoid about emissions?)QuoteRecent versions of the Arduino core have their main() specified as "weak", so you can easily write your own code based on main(). I'm pretty sure that all you have to do to get the Arduino timer (and other stuff) running is call init() The Arduino main() is pretty trivial. (https://github.com/arduino/Arduino/blob/master/hardware/arduino/avr/cores/arduino/main.cpp#L33)(OTOH, if you want JUST the timer and not the A2D and other initialization, that might be more complicated. It probably shouldn't be, now that they're using LTO and splitting up init() would probably not add code...)

author: Ian.M
author_rank: Super Contributor
timestamp: March 27, 2018, 02:47:40 pm
content: The problem is lines 42 to 63 of wiring.chttps://github.com/arduino/Arduino/blob/master/hardware/arduino/avr/cores/arduino/wiring.cMoved to:https://github.com/arduino/ArduinoCore-avr/blob/master/cores/arduino/wiring.cthat declares an ISR permanently attached to the TIMER0_OVF_vect that handles the timekeeping used by millis() and delay().If you want to hook that interrupt, you are S.O.L.There is a kludgy workaround - setup a 'Compare A' interrupt, with OCR0A=0 so it fires at the same timer count as the Timer 0 overflow interrupt, and attach your ISR to the TIMER0_COMPA_vect.

author: bd139
author_rank: Super Contributor
timestamp: March 27, 2018, 02:57:37 pm
content: That was the turd I tripped over. I wanted to use TIMER0 for debounce and button down timing. Doing this in arduino is a bag of shit:Code:ISR(TIMER0_OVF_vect){// handle button downif (bit_is_clear(PIND, PD1) && button_down == false){button_down = true;button_ticks = ticks;}// handle button up transitionif (bit_is_set(PIND, PD1) && button_down == true){button_down = false;event_button(ticks - button_ticks);}}event_button was manipulating state that the system tick on TIMER1_COMPA_vect reacted to.

author: westfw
author_rank: Super Contributor
timestamp: March 28, 2018, 09:44:27 am
content: QuoteAh; yes, I agree that it's a pain to hook into any interrupt whose vector is already defined in the "required" core...It can be similarly annoying to try to use your own serial ISR for one of the "other" UARTS, if you're also using the core functions on "Serial"...