Why many people don’t like Arduino
Have you ever wondered why the specialists / professionals in the field of microcontrollers and automation treat those who work with Arduino as if they were doing something not serious, like playing in the sandbox?
About the same way my cat Vasya belongs to arduino .
Actually, for this I made a video where, clearly, using an oscilloscope, I will show and tell, from my point of view, why. I will try to highlight the obvious pros and cons of the Arduino theme :
To begin with, it should be said that Arduino is not as bad as it might seem. It is thanks to Arduino that many different projects were born that would never have come to life, due to the very large amount of information that needs to be "digested" in order to implement them. It's no secret that making arduino devices is much simpler, and also faster. It was because of this that I began to get involved in the topic of microcontrollers. And gradually I began to outgrow all sorts of digitalWrite (13, HIGH); and switch to PORTB = 32 ;, as the desire to increase the productivity of my devices increased.
Here is the code for a regular “flasher” in the language familiar to the “arduino”:
I think this example is familiar to many, because it is a classic exercise "hello world", which is designed to minimize the threshold for entering the Arduino microcontroller programming topic.
Let's see how it would look if we went the way ofnot least resistance using the microcontroller registers:
These examples, as you can see, consume 1030 and 176 bytes in Flash, that is, the arduinshiks lose almost 6 times in this regard. In the second example, I specifically added comments on what line does to simplify the understanding of what is happening. Yes, it was possible to completely describe what and how it works, but my article is not about that, so I ask you a vector for development, arduinists .
Now we will talk about using the resources of the microcontroller, which are not unlimited, and if they are thoughtlessly spent, they will lead, at best, to incomprehensible curses of the development environment, and at worst - days of proceedings, why it does not work correctly, hundreds of iterations of code in mind, line Behind the line, and the reason for this may bemysticism is the failure of the microcontroller stack.
But let's get backto our sheeps Arduino IDE development environment .
Pay attention to the use of memory in two examples, so that you don’t rush around the page up and down, here are two codes on one screen:
The first thing that catches your eye is the size of the code, if you write in the usual Arduino IDE language, it looks a little more compact. And if I took some more complex code, for example ReadAnalogVoltage which reads the voltage at the zero analogport of the pin, converts it to volts and outputs to the series, if all this is written using the microcontroller's registers, it will turn out several times more code. But in this case, more does not always mean worse, I would even say the opposite. Why is that? I will talk about this below.
Also pay attention to how much memory both examples consume, the code in the arduino language “eats” much more memory, and now let's figure out why.
In the development environment folder, along the \ hardware \ arduino \ avr \ cores \ arduino path, the Arduino core is located, there is the wiring_digital.c file, where our “gluttonous” digitalWrite function is actually written, we will find the following lines there:
You just look at how much work it does instead of just setting the port status (like for example PORTB = 32;). And this was done for a reason, since Arduino has a low entry threshold, as I said above, there are various checks for ala “protection against the fool”. For example, if a novice stupidly forgot to set the pinport as an output, so that he does not go into the Hi-Z state (which the novice still does not suspect about, most likely) and thus scared him off at the first error. But for this you have to pay increased consumption of resources, as you yourself see.
Now let's move on to the oscilloscope, as I promised at the beginning of the article.
I have two identical Chinese Arduino Pro Mini which are located on the same breadboard, that is, they will have the same conditions. Let's flash one of them without a delay and see what happens on the oscilloscope screen:
One example is written in the arduino language, and the second works directly with the registers: The
blue ray of the oscilloscope (KAN2) is a regular Arduino code, as you can see, the frequency there are more switchings from a logical unit to a logical zero for the yellow ray (KAN1):
2.67 versus 0.094 MHz, of course, the microcontroller port capacity does not allow you to get a clean meander as in the case of the arduino code, but if you look closely, the fronts are far from clean:
It turns out a performance loss in this case - 28 times. Of course, this does not mean that arduino works 28 times slower, but I think that for clarity, this is the best example of why arduino is not liked.
Also, I do not like the Arduino theme, for all these beautiful multi-colored modules, which for the most part can be made independently, and they are sold at exorbitant prices, as if there are gold conductors instead of copper ones.
Here is an example of how you can create a useful module yourself, for a penny. But sometimes laziness overcomes me and also buy, because there is not always time or desire for it.
I have to admit that I myself am an “arduinshik”, and I work mostly with Arduino boards, for example, a copy of the Pro Mini is not so expensive for the Chinese, of course, it’s cheaper than a “bare” microcontroller, but as I said above, there is not always time and desire to do wiring the board from scratch, it’s easier for me personally to integrate a board into the Arduino project, especially the inexpensive Arduino Pro Mini or the slightly more advanced Arduino Nano.
Also, I like working from the Arduino IDE development environment , regardless of its limitations and inconveniences, it can start immediately, without any settings, just download the ZIP archive, unpack where you need it and that's it, you can get to work, and besides it doesn’t take up much space when compared with more professional software, for example Atmel Studio. And yet, there is one useful feature - autoformatting (Ctrl + T key combination):
Of course, there is such a thing as a “rule of good taste”, and you need to accustom yourself to this from the very beginning, but if there is such a fit, then why not use it ?
Another of the amenities in the Arduino IDE is the ability to enable line numbering and code folding in the settings:
The last item significantly improves code navigation and is already a bit, but closer, to more professional solutions.
In addition, the Arduino IDE, as you noticed, can "digest" not only its own language but also C and even assembler.
PS In general, summing up what was written in the article and said in the video above, Sergey SharekinT would like to wish everyone to develop, arduino is not the limit of those opportunities that the world of microcontrollers gives, the folk wisdom “Live and learn forever” correctly says.
Related links:
Everything new - well-forgotten old ;
The latest version of the Arduino IDE is here ;
Arduino on Wikipedia ;
How to save memory on Arduino? ;
All my publications on geektimes .
About the same way my cat Vasya belongs to arduino .
Actually, for this I made a video where, clearly, using an oscilloscope, I will show and tell, from my point of view, why. I will try to highlight the obvious pros and cons of the Arduino theme :
To begin with, it should be said that Arduino is not as bad as it might seem. It is thanks to Arduino that many different projects were born that would never have come to life, due to the very large amount of information that needs to be "digested" in order to implement them. It's no secret that making arduino devices is much simpler, and also faster. It was because of this that I began to get involved in the topic of microcontrollers. And gradually I began to outgrow all sorts of digitalWrite (13, HIGH); and switch to PORTB = 32 ;, as the desire to increase the productivity of my devices increased.
Here is the code for a regular “flasher” in the language familiar to the “arduino”:
Open spoiler
//Привет geektimes
void setup() {
pinMode(13, OUTPUT);
}
void loop() {
digitalWrite(13, HIGH);
delay(1000);
digitalWrite(13, LOW);
delay(1000);
}
I think this example is familiar to many, because it is a classic exercise "hello world", which is designed to minimize the threshold for entering the Arduino microcontroller programming topic.
Let's see how it would look if we went the way of
Open spoiler
//Привет geektimes
#include
#include
int main( void )
{
DDRB |= (1 << 5); // вывод PB5 как выход
while (1) { // вечный цикл, аналог loop()
PORTB &= ~(1 << 5); // низкий уровень на выводе PB5
_delay_ms(1000); // задержка 1000 миллисекунд
PORTB |= (1 << 5); // высокий уровень на выводе PB5
_delay_ms(1000);
}
return 0;
}
These examples, as you can see, consume 1030 and 176 bytes in Flash, that is, the arduinshiks lose almost 6 times in this regard. In the second example, I specifically added comments on what line does to simplify the understanding of what is happening. Yes, it was possible to completely describe what and how it works, but my article is not about that, so I ask you a vector for development, arduinists .
Now we will talk about using the resources of the microcontroller, which are not unlimited, and if they are thoughtlessly spent, they will lead, at best, to incomprehensible curses of the development environment, and at worst - days of proceedings, why it does not work correctly, hundreds of iterations of code in mind, line Behind the line, and the reason for this may be
But let's get back
Pay attention to the use of memory in two examples, so that you don’t rush around the page up and down, here are two codes on one screen:
The first thing that catches your eye is the size of the code, if you write in the usual Arduino IDE language, it looks a little more compact. And if I took some more complex code, for example ReadAnalogVoltage which reads the voltage at the zero analog
Also pay attention to how much memory both examples consume, the code in the arduino language “eats” much more memory, and now let's figure out why.
In the development environment folder, along the \ hardware \ arduino \ avr \ cores \ arduino path, the Arduino core is located, there is the wiring_digital.c file, where our “gluttonous” digitalWrite function is actually written, we will find the following lines there:
void digitalWrite (uint8_t pin, uint8_t val)
void digitalWrite(uint8_t pin, uint8_t val)
{
uint8_t timer = digitalPinToTimer(pin);
uint8_t bit = digitalPinToBitMask(pin);
uint8_t port = digitalPinToPort(pin);
volatile uint8_t *out;
if (port == NOT_A_PIN) return;
// If the pin that support PWM output, we need to turn it off
// before doing a digital write.
if (timer != NOT_ON_TIMER) turnOffPWM(timer);
out = portOutputRegister(port);
uint8_t oldSREG = SREG;
cli();
if (val == LOW) {
*out &= ~bit;
} else {
*out |= bit;
}
SREG = oldSREG;
}
You just look at how much work it does instead of just setting the port status (like for example PORTB = 32;). And this was done for a reason, since Arduino has a low entry threshold, as I said above, there are various checks for ala “protection against the fool”. For example, if a novice stupidly forgot to set the pin
Now let's move on to the oscilloscope, as I promised at the beginning of the article.
I have two identical Chinese Arduino Pro Mini which are located on the same breadboard, that is, they will have the same conditions. Let's flash one of them without a delay and see what happens on the oscilloscope screen:
One example is written in the arduino language, and the second works directly with the registers: The
blue ray of the oscilloscope (KAN2) is a regular Arduino code, as you can see, the frequency there are more switchings from a logical unit to a logical zero for the yellow ray (KAN1):
2.67 versus 0.094 MHz, of course, the microcontroller port capacity does not allow you to get a clean meander as in the case of the arduino code, but if you look closely, the fronts are far from clean:
It turns out a performance loss in this case - 28 times. Of course, this does not mean that arduino works 28 times slower, but I think that for clarity, this is the best example of why arduino is not liked.
Also, I do not like the Arduino theme, for all these beautiful multi-colored modules, which for the most part can be made independently, and they are sold at exorbitant prices, as if there are gold conductors instead of copper ones.
Here is an example of how you can create a useful module yourself, for a penny. But sometimes laziness overcomes me and also buy, because there is not always time or desire for it.
I have to admit that I myself am an “arduinshik”, and I work mostly with Arduino boards, for example, a copy of the Pro Mini is not so expensive for the Chinese, of course, it’s cheaper than a “bare” microcontroller, but as I said above, there is not always time and desire to do wiring the board from scratch, it’s easier for me personally to integrate a board into the Arduino project, especially the inexpensive Arduino Pro Mini or the slightly more advanced Arduino Nano.
Also, I like working from the Arduino IDE development environment , regardless of its limitations and inconveniences, it can start immediately, without any settings, just download the ZIP archive, unpack where you need it and that's it, you can get to work, and besides it doesn’t take up much space when compared with more professional software, for example Atmel Studio. And yet, there is one useful feature - autoformatting (Ctrl + T key combination):
Of course, there is such a thing as a “rule of good taste”, and you need to accustom yourself to this from the very beginning, but if there is such a fit, then why not use it ?
Another of the amenities in the Arduino IDE is the ability to enable line numbering and code folding in the settings:
The last item significantly improves code navigation and is already a bit, but closer, to more professional solutions.
In addition, the Arduino IDE, as you noticed, can "digest" not only its own language but also C and even assembler.
PS In general, summing up what was written in the article and said in the video above, Sergey SharekinT would like to wish everyone to develop, arduino is not the limit of those opportunities that the world of microcontrollers gives, the folk wisdom “Live and learn forever” correctly says.
Related links:
Everything new - well-forgotten old ;
The latest version of the Arduino IDE is here ;
Arduino on Wikipedia ;
How to save memory on Arduino? ;
All my publications on geektimes .
Only registered users can participate in the survey. Please come in.
How do you feel about the Arduino theme?
- 40.4% Arduino is cool 424
- 42.6% Tolerant 447
- 11.2% Arduino is not where romance, the smell of rosin, a whole night to breed a fee 118
- 5.6% Arduino is evil. 59