Author Topic: Arduino: To(o) cheap or not to(o) cheap?  (Read 8016 times)

0 Members and 1 Guest are viewing this topic.

Offline RyanTTopic starter

  • Contributor
  • Posts: 31
  • Country: ca
Arduino: To(o) cheap or not to(o) cheap?
« on: March 20, 2018, 04:43:03 am »
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: See post #12 for 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. :P

The problem I'm having getting an Arduino is that there are so many darned options, and what seems like a dearth of credible reviews on any of them. I can buy a brand name Uno R3 from Sparkfun for $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 up n + 1 times or is off-topic here. I spent quite a bit of time with the forum search and couldn't find anything relevant.
« Last Edit: March 20, 2018, 09:42:14 am by RyanT »
 

Offline imidis

  • Frequent Contributor
  • **
  • Posts: 426
  • Country: ca
Re: Arduino: To(o) cheap or not to(o) cheap?
« Reply #1 on: March 20, 2018, 04:46:30 am »
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.
Gone for good
 
The following users thanked this post: RyanT

Online Ian.M

  • Super Contributor
  • ***
  • Posts: 12864
Re: Arduino: To(o) cheap or not to(o) cheap?
« Reply #2 on: March 20, 2018, 07:49:43 am »
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/ArduinoToBreadboard and https://www.arduino.cc/en/Tutorial/ArduinoISP

Once 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.
« Last Edit: March 20, 2018, 10:30:30 am by Ian.M »
 
The following users thanked this post: RyanT

Offline josip

  • Regular Contributor
  • *
  • Posts: 152
  • Country: hr
Re: Arduino: To(o) cheap or not to(o) cheap?
« Reply #3 on: March 20, 2018, 07:54:06 am »
Money is a bit tight at the moment as I'm not able to work...

I will not suggest anyone today to 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_Pill
https://www.ebay.com/itm/201414966215
And ST-Link cone for around 2$...
https://www.ebay.com/itm/191736124906
« Last Edit: March 20, 2018, 07:56:31 am by josip »
 

Online Ian.M

  • Super Contributor
  • ***
  • Posts: 12864
Re: Arduino: To(o) cheap or not to(o) cheap?
« Reply #4 on: March 20, 2018, 08:29:19 am »
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.
 
The following users thanked this post: Mukrakiish

Offline Brumby

  • Supporter
  • ****
  • Posts: 12298
  • Country: au
Re: Arduino: To(o) cheap or not to(o) cheap?
« Reply #5 on: March 20, 2018, 09:02:56 am »
I will not suggest anyone today to start with 8-bit mcu.

What 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.
 
The following users thanked this post: xrunner, JoeO, imidis, RyanT

Offline NivagSwerdna

  • Super Contributor
  • ***
  • Posts: 2495
  • Country: gb
Re: Arduino: To(o) cheap or not to(o) cheap?
« Reply #6 on: March 20, 2018, 09:12:24 am »
Uno eBay auction: #142051313005

So 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.
« Last Edit: March 20, 2018, 09:13:55 am by NivagSwerdna »
 

Offline picandmix

  • Frequent Contributor
  • **
  • Posts: 395
  • Country: gb
Re: Arduino: To(o) cheap or not to(o) cheap?
« Reply #7 on: March 20, 2018, 09:22:26 am »
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.
 

Offline Mechatrommer

  • Super Contributor
  • ***
  • Posts: 11653
  • Country: my
  • reassessing directives...
Re: Arduino: To(o) cheap or not to(o) cheap?
« Reply #8 on: March 20, 2018, 09:26:26 am »
Money is a bit tight at the moment as I'm not able to work...
I will not suggest anyone today to 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_Pill
https://www.ebay.com/itm/201414966215
And ST-Link cone for around 2$...
https://www.ebay.com/itm/191736124906
+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. |O 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.
Nature: Evolution and the Illusion of Randomness (Stephen L. Talbott): Its now indisputable that... organisms “expertise” contextualizes its genome, and its nonsense to say that these powers are under the control of the genome being contextualized - Barbara McClintock
 

Offline ggchab

  • Frequent Contributor
  • **
  • Posts: 276
  • Country: be
Re: Arduino: To(o) cheap or not to(o) cheap?
« Reply #9 on: March 20, 2018, 09:29:29 am »
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  :)
 

Offline RyanTTopic starter

  • Contributor
  • Posts: 31
  • Country: ca
Re: Arduino: To(o) cheap or not to(o) cheap?
« Reply #10 on: March 20, 2018, 09:39:00 am »
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 I can program 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?
 

Offline bd139

  • Super Contributor
  • ***
  • Posts: 23032
  • Country: gb
Re: Arduino: To(o) cheap or not to(o) cheap?
« Reply #11 on: March 20, 2018, 09:39:40 am »
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.
 

Offline NivagSwerdna

  • Super Contributor
  • ***
  • Posts: 2495
  • Country: gb
Re: Arduino: To(o) cheap or not to(o) cheap?
« Reply #12 on: March 20, 2018, 09:45:51 am »
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!
« Last Edit: March 20, 2018, 11:11:22 am by NivagSwerdna »
 

Offline RyanTTopic starter

  • Contributor
  • Posts: 31
  • Country: ca
Re: Arduino: To(o) cheap or not to(o) cheap?
« Reply #13 on: March 20, 2018, 10:37:21 am »
If 'programming' a VCR is outside of your comfort zone, then forget about it and stick to analog electronics!

Does electrical tape over the clock count? ;D

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. :P
 

Online Ian.M

  • Super Contributor
  • ***
  • Posts: 12864
Re: Arduino: To(o) cheap or not to(o) cheap?
« Reply #14 on: March 20, 2018, 11:04:53 am »
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.
Good 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-PU
The 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.

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.
more mature than elsewhere.
Installing 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.
 

Offline NivagSwerdna

  • Super Contributor
  • ***
  • Posts: 2495
  • Country: gb
Re: Arduino: To(o) cheap or not to(o) cheap?
« Reply #15 on: March 20, 2018, 11:16:34 am »
"There are many things about the Arduino that suck from the point of view of an experienced developer".
This 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]
 

Online Ian.M

  • Super Contributor
  • ***
  • Posts: 12864
Re: Arduino: To(o) cheap or not to(o) cheap?
« Reply #16 on: March 20, 2018, 11:43:51 am »
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  infamous space bar heating hack would be preferable.
« Last Edit: March 20, 2018, 12:11:55 pm by Ian.M »
 
The following users thanked this post: newbrain, RyanT

Offline Brumby

  • Supporter
  • ****
  • Posts: 12298
  • Country: au
Re: Arduino: To(o) cheap or not to(o) cheap?
« Reply #17 on: March 20, 2018, 12:03:00 pm »
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.

Well .... ummmm .... that is something of a disclosure.


But if you want some inexpensive and useful hardware, Arduino clones are good value.
 

Offline NivagSwerdna

  • Super Contributor
  • ***
  • Posts: 2495
  • Country: gb
Re: Arduino: To(o) cheap or not to(o) cheap?
« Reply #18 on: March 20, 2018, 12:03:22 pm »
or vim with a vim clutch?

https://github.com/alevchuk/vim-clutch

PS
+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
« Last Edit: March 20, 2018, 12:05:41 pm by NivagSwerdna »
 

Offline RyanTTopic starter

  • Contributor
  • Posts: 31
  • Country: ca
Re: Arduino: To(o) cheap or not to(o) cheap?
« Reply #19 on: March 20, 2018, 12:29:34 pm »
or vim with a vim clutch?

Ha! 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.
 

Offline RyanTTopic starter

  • Contributor
  • Posts: 31
  • Country: ca
Re: Arduino: To(o) cheap or not to(o) cheap?
« Reply #20 on: March 20, 2018, 12:38:34 pm »
Well .... ummmm .... that is something of a disclosure.
Yeah, mea culpa. I really should have known you all don't know me as well as Steve does.

I miss Steve.
 

Offline josip

  • Regular Contributor
  • *
  • Posts: 152
  • Country: hr
Re: Arduino: To(o) cheap or not to(o) cheap?
« Reply #21 on: March 20, 2018, 03:00:36 pm »
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.html
It 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. :popcorn:
 

Offline imidis

  • Frequent Contributor
  • **
  • Posts: 426
  • Country: ca
Re: Arduino: To(o) cheap or not to(o) cheap?
« Reply #22 on: March 20, 2018, 05:28:38 pm »
Money is a bit tight at the moment as I'm not able to work...

I will not suggest anyone today to 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_Pill
https://www.ebay.com/itm/201414966215
And ST-Link cone for around 2$...
https://www.ebay.com/itm/191736124906

This just drives me nuts. Why on earth would anyone exclude any chip? 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.  :-//
Gone for good
 

Offline Mr. Scram

  • Super Contributor
  • ***
  • Posts: 9810
  • Country: 00
  • Display aficionado
Re: Arduino: To(o) cheap or not to(o) cheap?
« Reply #23 on: March 20, 2018, 05:42:39 pm »
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 I can program 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?
In 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.
 

Offline bd139

  • Super Contributor
  • ***
  • Posts: 23032
  • Country: gb
Re: Arduino: To(o) cheap or not to(o) cheap?
« Reply #24 on: March 20, 2018, 05:51:39 pm »
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.
 
The following users thanked this post: Ian.M, imidis

Offline RyanTTopic starter

  • Contributor
  • Posts: 31
  • Country: ca
Re: Arduino: To(o) cheap or not to(o) cheap?
« Reply #25 on: March 20, 2018, 06:40:05 pm »
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.
 
The following users thanked this post: imidis

Offline NivagSwerdna

  • Super Contributor
  • ***
  • Posts: 2495
  • Country: gb
Re: Arduino: To(o) cheap or not to(o) cheap?
« Reply #26 on: March 20, 2018, 07:37:39 pm »
socketed uC
Hot air is like removing from a socket for the SMD equivalent.  But each to their own. DIPs are so last century.  :)
 

Offline metrologist

  • Super Contributor
  • ***
  • Posts: 2213
  • Country: 00
Re: Arduino: To(o) cheap or not to(o) cheap?
« Reply #27 on: March 20, 2018, 08:02:20 pm »
Well, I like the nano form factor. Most of my solderless breadboards have a nano on them.
 

Offline Brumby

  • Supporter
  • ****
  • Posts: 12298
  • Country: au
Re: Arduino: To(o) cheap or not to(o) cheap?
« Reply #28 on: March 21, 2018, 12:58:25 am »
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 a casual user).  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.
 

Offline alsetalokin4017

  • Super Contributor
  • ***
  • Posts: 2055
  • Country: us
Re: Arduino: To(o) cheap or not to(o) cheap?
« Reply #29 on: March 21, 2018, 03:39:58 am »
Well, I like the nano form factor. Most of my solderless breadboards have a nano on them.

I 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.

The easiest person to fool is yourself. -- Richard Feynman
 

Offline paulca

  • Super Contributor
  • ***
  • Posts: 4055
  • Country: gb
Re: Arduino: To(o) cheap or not to(o) cheap?
« Reply #30 on: March 21, 2018, 07:44:15 am »
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 programmer if you 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.

"What could possibly go wrong?"
Current Open Projects:  STM32F411RE+ESP32+TFT for home IoT (NoT) projects.  Child's advent xmas countdown toy.  Digital audio routing board.
 

Offline bd139

  • Super Contributor
  • ***
  • Posts: 23032
  • Country: gb
Re: Arduino: To(o) cheap or not to(o) cheap?
« Reply #31 on: March 21, 2018, 09:33:01 am »
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: [Select]
#include <avr/io.h>
#include <util/delay.h>

int main()
{
// Set port D as output
DDRD = 0xFF;

while (1)
{
// Set PD0
PORTD |= (1 << PD0);

// Sleep a bit
_delay_ms(500);

// Unset PD0
PORTD &= ~(1 << PD0);

// Sleep a bit
_delay_ms(500);
}
}

Makefile:

Code: [Select]
# Project name
PROJECT=avrhelloworld

# Space separated list of all source files
SOURCES=main.c

# Set the target
MCU=atmega328p

# Clock speed of the AVR in Hz
SPEED=1000000

# AVRDUDE microcontroller type
MCUDUDE=m328p

# AVRDUDE programmer type
PROGRAMMER=usbasp

# not target specific. Don't need to change anything below
CC=avr-gcc
OBJCOPY=avr-objcopy
CFLAGS=-c -Os -Wall -DF_CPU=$(SPEED)UL
LDFLAGS=-mmcu=$(MCU)
ELF=$(PROJECT).elf
HEX=$(PROJECT).hex
OBJECTS=$(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:

make
avr-libc
avr-gcc
avrdude

go go go :)

USBasp from ebay/bitsbox/china/wherever. Make sure you stick it in 5V mode first.
 
The following users thanked this post: RyanT

Online Ian.M

  • Super Contributor
  • ***
  • Posts: 12864
Re: Arduino: To(o) cheap or not to(o) cheap?
« Reply #32 on: March 21, 2018, 09:53:54 am »
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 Hoodloader2
https://github.com/NicoHood/HoodLoader2
which 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,
 

Offline paulca

  • Super Contributor
  • ***
  • Posts: 4055
  • Country: gb
Re: Arduino: To(o) cheap or not to(o) cheap?
« Reply #33 on: March 21, 2018, 10:54:13 am »
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:

Who 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.
« Last Edit: March 21, 2018, 10:57:57 am by paulca »
"What could possibly go wrong?"
Current Open Projects:  STM32F411RE+ESP32+TFT for home IoT (NoT) projects.  Child's advent xmas countdown toy.  Digital audio routing board.
 

Offline bd139

  • Super Contributor
  • ***
  • Posts: 23032
  • Country: gb
Re: Arduino: To(o) cheap or not to(o) cheap?
« Reply #34 on: March 21, 2018, 11:00:26 am »
Who needs a bakery or supermarket!  Here's what I am using for bread:

I make my own bread!

 

Offline NivagSwerdna

  • Super Contributor
  • ***
  • Posts: 2495
  • Country: gb
Re: Arduino: To(o) cheap or not to(o) cheap?
« Reply #35 on: March 21, 2018, 11:21:21 am »
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)
« Last Edit: March 21, 2018, 11:23:53 am by NivagSwerdna »
 

Offline RationalRoot

  • Newbie
  • Posts: 1
  • Country: ie
Re: Arduino: To(o) cheap or not to(o) cheap?
« Reply #36 on: March 24, 2018, 09:44:58 am »
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/B0713XK923
Hard to go wrong. You just download & install the CH340 driver. I think I got it from https://www.elegoo.com/tutorial/CH340%20Driver.zip
« Last Edit: March 24, 2018, 09:49:37 am by RationalRoot »
 

Offline paulca

  • Super Contributor
  • ***
  • Posts: 4055
  • Country: gb
Re: Arduino: To(o) cheap or not to(o) cheap?
« Reply #37 on: March 24, 2018, 05:43:02 pm »
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.
"What could possibly go wrong?"
Current Open Projects:  STM32F411RE+ESP32+TFT for home IoT (NoT) projects.  Child's advent xmas countdown toy.  Digital audio routing board.
 

Offline josip

  • Regular Contributor
  • *
  • Posts: 152
  • Country: hr
Re: Arduino: To(o) cheap or not to(o) cheap?
« Reply #38 on: March 25, 2018, 07:17:13 am »
.... 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)[/li][/list]

Totally 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.

 

Offline RyanTTopic starter

  • Contributor
  • Posts: 31
  • Country: ca
Re: Arduino: To(o) cheap or not to(o) cheap?
« Reply #39 on: March 25, 2018, 11:08:38 am »
I'm not going to lie, debugging a uC with printf() 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. :P
 

Online Ian.M

  • Super Contributor
  • ***
  • Posts: 12864
Re: Arduino: To(o) cheap or not to(o) cheap?
« Reply #40 on: March 25, 2018, 11:58:28 am »
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! :(
 

Offline Brumby

  • Supporter
  • ****
  • Posts: 12298
  • Country: au
Re: Arduino: To(o) cheap or not to(o) cheap?
« Reply #41 on: March 25, 2018, 12:02:59 pm »
If you thought printf() debugging was ugly, wait till you see Serial.print() debugging! :(
Yeah ... it's not glamorous.
 

Offline paulca

  • Super Contributor
  • ***
  • Posts: 4055
  • Country: gb
Re: Arduino: To(o) cheap or not to(o) cheap?
« Reply #42 on: March 25, 2018, 12:17:20 pm »
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
« Last Edit: March 25, 2018, 12:22:17 pm by paulca »
"What could possibly go wrong?"
Current Open Projects:  STM32F411RE+ESP32+TFT for home IoT (NoT) projects.  Child's advent xmas countdown toy.  Digital audio routing board.
 

Offline ogden

  • Super Contributor
  • ***
  • Posts: 3731
  • Country: lv
Re: Arduino: To(o) cheap or not to(o) cheap?
« Reply #43 on: March 25, 2018, 12:32:57 pm »
I suggest to not confuse together learning with building. The best learning tool is not always best building tool. I usually suggest to start learning 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.
 

Offline westfw

  • Super Contributor
  • ***
  • Posts: 4199
  • Country: us
Re: Arduino: To(o) cheap or not to(o) cheap?
« Reply #44 on: March 26, 2018, 09:14:03 am »
Quote
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

Nonsense.   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: [Select]
#include <stdio.h>

int fput(char c, FILE* f) {
  Serial.write( c);
  return 0;
}

void setup() {
  Serial.begin(9600);
  stdout = fdevopen(fput, NULL);
}


Quote
Why on earth would anyone exclude any chip?
Well, 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."


Quote
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.
This 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, ...)
« Last Edit: March 26, 2018, 09:25:04 am by westfw »
 

Offline igendel

  • Frequent Contributor
  • **
  • Posts: 359
  • Country: il
    • It's Every Bit For Itself (Programming & MCU blog)
Re: Arduino: To(o) cheap or not to(o) cheap?
« Reply #45 on: March 26, 2018, 09:54:57 am »
Joining the discussion a bit too late  :)

I have seen many cheap Arduino clones with issues. Some from my own collection, some brought to me for repair by local makers. The problems can be anywhere - 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 not that much, 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.

Maker projects, tutorials etc. on my Youtube channel: https://www.youtube.com/user/idogendel/
 

Offline Mr. Scram

  • Super Contributor
  • ***
  • Posts: 9810
  • Country: 00
  • Display aficionado
Re: Arduino: To(o) cheap or not to(o) cheap?
« Reply #46 on: March 26, 2018, 10:54:26 am »
Joining the discussion a bit too late  :)

I have seen many cheap Arduino clones with issues. Some from my own collection, some brought to me for repair by local makers. The problems can be anywhere - 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 not that much, 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.
Another 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.
 

Offline NivagSwerdna

  • Super Contributor
  • ***
  • Posts: 2495
  • Country: gb
Re: Arduino: To(o) cheap or not to(o) cheap?
« Reply #47 on: March 26, 2018, 12:31:27 pm »
I have seen many cheap Arduino clones with issues.
100% 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.pdf
e.g. eBay auction: #142051313005 or eBay auction: #141676813121
 
« Last Edit: March 26, 2018, 12:38:18 pm by NivagSwerdna »
 

Offline igendel

  • Frequent Contributor
  • **
  • Posts: 359
  • Country: il
    • It's Every Bit For Itself (Programming & MCU blog)
Re: Arduino: To(o) cheap or not to(o) cheap?
« Reply #48 on: March 26, 2018, 01:14:02 pm »
I have seen many cheap Arduino clones with issues.
100% 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.pdf
e.g. eBay auction: #142051313005 or eBay auction: #141676813121

But... 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"  ;D
Maker projects, tutorials etc. on my Youtube channel: https://www.youtube.com/user/idogendel/
 

Offline Bassman59

  • Super Contributor
  • ***
  • Posts: 2501
  • Country: us
  • Yes, I do this for a living
Re: Arduino: To(o) cheap or not to(o) cheap?
« Reply #49 on: March 27, 2018, 03:39:02 am »
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.

Instead 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.
 

Offline westfw

  • Super Contributor
  • ***
  • Posts: 4199
  • Country: us
Re: Arduino: To(o) cheap or not to(o) cheap?
« Reply #50 on: March 27, 2018, 05:22:59 am »
Quote
Quote
I tend to stick to the "NHduino" variants which have a CPU XTAL as well as the USB XTAL.
But... all Uno-type boards have that, don't they?
AFAIK, 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?)


Quote
[mistakes include] #6.  Ditching main() and forcing the use of setup() and loop(). ... 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.
Recent 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...)
 

Online Ian.M

  • Super Contributor
  • ***
  • Posts: 12864
Re: Arduino: To(o) cheap or not to(o) cheap?
« Reply #51 on: March 27, 2018, 02:47:40 pm »
The problem is lines 42 to 63 of wiring.c
https://github.com/arduino/Arduino/blob/master/hardware/arduino/avr/cores/arduino/wiring.c
Moved to: https://github.com/arduino/ArduinoCore-avr/blob/master/cores/arduino/wiring.c
that 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.
« Last Edit: November 22, 2022, 11:50:40 am by Ian.M »
 

Offline bd139

  • Super Contributor
  • ***
  • Posts: 23032
  • Country: gb
Re: Arduino: To(o) cheap or not to(o) cheap?
« Reply #52 on: March 27, 2018, 02:57:37 pm »
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: [Select]
ISR(TIMER0_OVF_vect)
{
    // handle button down
    if (bit_is_clear(PIND, PD1) && button_down == false)
    {
        button_down = true;
        button_ticks = ticks;
    }

    // handle button up transition
    if (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.
« Last Edit: March 27, 2018, 02:59:28 pm by bd139 »
 
The following users thanked this post: Ian.M

Offline westfw

  • Super Contributor
  • ***
  • Posts: 4199
  • Country: us
Re: Arduino: To(o) cheap or not to(o) cheap?
« Reply #53 on: March 28, 2018, 09:44:27 am »
Quote
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.

Ah;  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"...
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf