Arduino serial monitor, From this forum because, I need an intelligent answer - Page 1
Forum section: electronics / general

author: Quarlo Klobrigney
author_rank: Super Contributor
timestamp: August 03, 2018, 10:58:28 pm
content: I am an Atmel fanboy, and have been programming them since the AT90S1200 in both asm & C.My point being, I just don't get the Arduino syntax gobbly-gook.I can't understand what's going on in the background.What say, for example what pin 13 is tied to in a sketch <- "I hate that word"Is it PD7 or really pin 13 on the IC?Another thing is getting for example to display whats in the serial monitor on a port.Any help to answer my inquiries or point me to any other site besides Arduino. I'm old and don't have a lot of patience to wade through all the stuff scattered on hundreds of large font pages.Signed: Dazed in the hot southern sun..... Thanks

author: mc
author_rank: Regular Contributor
timestamp: August 03, 2018, 11:10:14 pm
content: Regarding pin mapping, it depends on the board/chip. The pin refers to pin number on the Arduino board in question, not the chip.For example with an UNO, Pin 13 is actually PB5.If you look at the product page for whatever board you are using (product listing page can be foundhere), then select the Documentation tab and scroll down the page, you should find a link to the relative pin mapping for that board.For example, the UNO pin mapping can be found athttps://www.arduino.cc/en/Hacking/PinMapping168

author: Ian.M
author_rank: Super Contributor
timestamp: August 03, 2018, 11:19:06 pm
content: Arduino pin numbers are virtual pins and the mapping to a specific MCU port and bit depends on your model Arduino board, and the mapping to a MCU physical pin number depends on the MCU and the package its in.The Arduino libraries don't really have the concept of a group of pins as a bitmapped port. However as it uses the AVR GCC toolchain for all AVR based Arduinos, complete with the standard AVR headers that declare all the registers, you could copy a byte received from the UART to a hardware port configured for output. However on the Arduino Uno and many other low-end Arduinos, there isn't a complete 8 bit port available as the UART needs two pins of port D, the only full 8 bit I/O port on an ATmega328P. You could however mask off the bottom two bits (UART RXD and TXD) and instead output those bits on a different port.There's also the issue that the Arduino terminal works with ASCII characters , so if you want to control a port, simply copying the received byte to the port wont let you set it to all the possible binary values. To fix that, you have to recieve a string and parse it to extract a human readable number, convert it to binary then send it to the port.

author: sokoloff
author_rank: Super Contributor
timestamp: August 03, 2018, 11:22:44 pm
content: If you're using the Arduino IDE, open the serial monitor to see the serial output. (Note that, by default, this will restart the "sketch".)You can also use any other serial port program (putty, screen, HyperTerm, Termite, etc).

author: Quarlo Klobrigney
author_rank: Super Contributor
timestamp: August 03, 2018, 11:28:16 pm
content: So for the Uno, the 13 in the snippet below is PB5?I've got it now about D0 & D1 being useless as being functional for other than serial.Now what about the serial monitor display, say a decimal number 0-255 being able to be sent to a port as well?Code:/*-----( Import needed libraries )-----*//*-----( Declare Constants and Pin Numbers )-----*/ #define led 13 // built-in LED/*-----( Declare objects )-----*/

author: sokoloff
author_rank: Super Contributor
timestamp: August 04, 2018, 12:07:41 am
content: Quote from: Quarlo Klobrigney on August 03, 2018, 11:28:16 pmCode:int val = 56;Serial.print(F"Val: ");Serial.println(val);

author: sokoloff
author_rank: Super Contributor
timestamp: August 04, 2018, 12:09:04 am
content: See also the "DigitalReadSerial" Example code that comes with the Arduino IDE.

author: Quarlo Klobrigney
author_rank: Super Contributor
timestamp: August 04, 2018, 12:20:34 am
content: I think I am getting confoosedas to what I was trying to describe.I this example, (from the web) a standard rotary encoder counts off in the serial monitor. I was looking for a way to output what is an obvious count in decimal to a port. I just don't see a variable in the code for which to "pick off" the count. Can someone set me on the path to enlightenment?Code:// InterruptRotator.ino - Example for the RotaryEncoder library.// This class is implemented for use with the Arduino environment.// Copyright (c) by Matthias Hertel, http://www.mathertel.de// This work is licensed under a BSD style license. See http://www.mathertel.de/License.aspx// More information on: http://www.mathertel.de/Arduino// -----// 18.01.2014 created by Matthias Hertel// -----// This example checks the state of the rotary encoder in the loop() function.// The current position is printed on output when changed.// Hardware setup:// Attach a rotary encoder with output pins to A2 and A3.// The common contact should be attached to ground.#include <RotaryEncoder.h>// Setup a RoraryEncoder for pins A2 and A3:RotaryEncoder encoder(A2, A3);void setup(){Serial.begin(57600);Serial.println("SimplePollRotator example for the RotaryEncoder library.");// You may have to modify the next 2 lines if using other pins than A2 and A3PCICR |= (1 << PCIE1); // This enables Pin Change Interrupt 1 that covers the Analog input pins or Port C.PCMSK1 |= (1 << PCINT10) | (1 << PCINT11); // This enables the interrupt for pin 2 and 3 of Port C.} // setup()// The Interrupt Service Routine for Pin Change Interrupt 1// This routine will only be called on any signal change on A2 and A3: exactly where we need to check.ISR(PCINT1_vect) {encoder.tick(); // just call tick() to check the state.}// Read the current position of the encoder and print out when changed.void loop(){static int pos = 0;int newPos = encoder.getPosition();if (pos != newPos) {Serial.print(newPos);Serial.println();pos = newPos;// Just to show, that long lasting procedures don't break the rotary encoder:// When newPos is 66 the ouput will freeze, but the turned positions will be recognized even when not polled.// The interrupt still works.// The output is correct 6.6 seconds later.if (newPos == 66)delay(6600);} // if} // loop ()// The End

author: Quarlo Klobrigney
author_rank: Super Contributor
timestamp: August 04, 2018, 12:28:16 am
content: Where about is it located. I'm waiting on some ESP32 hardware from China and have filled up my "sketch" area with examples and it's hard to climb or descend the tree now.Quote from: sokoloff onTodayat 19:09:04

author: sokoloff
author_rank: Super Contributor
timestamp: August 04, 2018, 12:39:30 am
content: Quote from: Quarlo Klobrigney on August 04, 2018, 12:20:34 amnewPos is the variable to use (and is already being sent to the serial port in that code example!).

author: sokoloff
author_rank: Super Contributor
timestamp: August 04, 2018, 12:44:16 am
content: Quote from: Quarlo Klobrigney on August 04, 2018, 12:28:16 amIt was installed with your IDE.The associated website (with code explanations) is here:https://www.arduino.cc/en/Tutorial/DigitalReadSerial

author: Quarlo Klobrigney
author_rank: Super Contributor
timestamp: August 04, 2018, 12:50:47 am
content: So I've been playing around with that variable as you have stated. Nothing I do gets it out to a port. For example, dump the variable to leds not the serial port. I can do that out of the Arduino IDE. Any ideas? thanksQuote from: sokoloff onTodayat 19:39:30

author: carl0s
author_rank: Unknown
timestamp: August 04, 2018, 12:55:57 am
content: Quote from: Quarlo Klobrigney on August 03, 2018, 10:58:28 pmYeah as others have said you really do need to read about the specific board you've bought, if you're using Arduino, as you will be using their Arduino libraries and board description files which map e.g. PA1 to whatever physical pin.I never did anything with actual genuine Arduino - I started off with an Adafruit Feather M0 (via Arduino IDE) from the get go, which I feel was a positive step as it put me straight into ARM territory and lots of multiplexed I/O peripherals (shitloads of SPI, UART or I2C whereever you want it..)Crucially, Adafruit do good docs generally. Although as time goes on I'm starting to think they're too focused on flashy lights for kids.On STM32, it all makes sense because PA1 means GPIO Port A, Pin 1, and GPIOH3 means GPIOH, Pin 3. Once you start trying to do just the simple Arduino things in stm32 (HAL_GPIO_WritePin - after setting the pin type - but you can learn all this from the example code that CubeMX generates), and then you use your proper IDE (PlatformIO with VSCode was my favourite when doing Arduino, but now I'm learning stm32 with HAL and CubeMX, I am using TrueStudio), you can dig into what's actually happening, and then you can see it all tying into the datasheet.e.g.:#define SPI_CR2_FRXTH_Pos (12U)#define SPI_CR2_FRXTH_Msk (0x1U << SPI_CR2_FRXTH_Pos) /*!< 0x00001000 */#define SPI_CR2_FRXTH SPI_CR2_FRXTH_Msk /*!< FIFO reception Threshold */once you dig in (right-click, open declaration), the code starts to make sense to the actual chip level datasheet:http://www.internetsomething.com/stm32/stm32-f767-programming-manual.pdf(page 1358 - it's bit 12!. It takes a bit of a while to get it (especially if you're trying to debug that big clock gap which you will see in a few more posts.. and appears to be caused by the rx buffer /counter seeing 16 bits and then going to an rx-retrieve sub-procedure (even though you'd like it to ignore the first 8 bits) - but doesn't happen if you use DMA). The more you can think in term of bits, registers, and then bit-shifting, the the more it starts to half make sense...)I really hated the Windows 10 calculator and went out of my way to install a classic calculator up until recently. But - 3 years on, it no longer takes 10 seconds to open (yes, horsepower, vs efficiency), *and* it's great for doing hex -> binary (and vice versa) calculations for those of us that don't just have it in mind naturally.

author: carl0s
author_rank: Unknown
timestamp: August 04, 2018, 12:57:16 am
content: I'd forget about ESP32, unless you really need cheap WiFi.The 240MHz isn't what it seems: too many gotchas?https://blog.classycode.com/esp32-floating-point-performance-6e9f6f567a69and so few I/Oand the docs.yes stm isn't perfect, but it's way ahead.

author: Quarlo Klobrigney
author_rank: Super Contributor
timestamp: August 04, 2018, 12:58:31 am
content: Yes thanks, but I'm wanting to dump whatever is on the serial monitor screen to a port not the serial port. As listed in the post reply above. But now I know which variable is which now.Still looking o dump it on a port (in parallel)Quote from: sokoloff onTodayat 19:44:16https://www.arduino.cc/en/Tutorial/DigitalReadSerial

author: Quarlo Klobrigney
author_rank: Super Contributor
timestamp: August 04, 2018, 01:03:13 am
content: Lots of examples on the web I'm doing the ESP32 WROOM which is fast, BT & WiFI, and has more ports. And the 3 dreaded letters: IOTI'm sorry Dave.Regarding the docs for Arduino, I can just program in real C and bypass the IDE. The thing is I'm trying to decipher the pseudo babble that they use on a limited pin function device.I also do STM32 stuff.Quote from: carl0s onTodayat 19:57:16

author: carl0s
author_rank: Unknown
timestamp: August 04, 2018, 01:04:51 am
content: If you were using a proper development environment with a debugger, you wouldn't be thinking about trying to 'display a variable on a port'.You'd just set a breakpoint, use you ST Link V2 (clone) and see it..I swear I'm not a shill..

author: carl0s
author_rank: Unknown
timestamp: August 04, 2018, 01:06:48 am
content: Quote from: Quarlo Klobrigney on August 04, 2018, 01:03:13 amI'm sure I counted esp32 pins this morning and it was in the region of ~30 or 40, vs ~200 on a typical stm32 ?definitely no RGB, nevermind the rest.

author: Quarlo Klobrigney
author_rank: Super Contributor
timestamp: August 04, 2018, 01:11:03 am
content: Sometimes you need a sledgehammer and sometimes you need a tack hammer.

author: carl0s
author_rank: Unknown
timestamp: August 04, 2018, 01:15:12 am
content: Quote from: Quarlo Klobrigney on August 04, 2018, 01:11:03 amHmm.I'm not telling you to go buy a Cray supercomputer.Just buy whatever has good tools and a big drive (people!) behind it.

author: carl0s
author_rank: Unknown
timestamp: August 04, 2018, 01:18:06 am
content: I can't stress enough how Arduino is amazing as it introduces you to the world of microcontrollers - (although I think you're already beyond that - you said you write for other MCUs in asm and c.), but Arduino is just a terrible development and debugging environment. Plus there are wider MCU choices than those that Arduino limits you to. I was introduced to stm32 via stm32duino and PlatformIO though. Some of these non-(native)-Arduino chips give you free (non-arduino) tools if you use their chips. ST just bought TouchGFX,. so... sorry I really do sound like a shill now.ST. When are we getting ToughGFX for free?

author: carl0s
author_rank: Unknown
timestamp: August 04, 2018, 02:10:13 am
content: PaulS needs to get onboard with stm32. But there needs to be a way to monetise the effort. That sort of work can't be for nothing.I've bloody nailed it.ST:: Make Paul Stoffregen rich - forever (and beyond: cover the whole family). That'd be a really great business move.

author: sleemanj
author_rank: Super Contributor
timestamp: August 04, 2018, 03:11:48 am
content: Quote from: Quarlo Klobrigney on August 04, 2018, 12:20:34 amWhat youseemto be asking isn't so much an arduino thing, it's a general programming question.Sooo.. you have an 8 bit number and you want to output the bits of that number simultaneously on pins 0-7 of a given PORT (collection of pins addressable in the same register)?Well, the first problem you have there is that the ATMega328 only has one complete 8 bit port, port D, which also includes the UART RX and TX, so you will mess up serial comms if you do that (if you don't need serial comms, then whatever).PORTD = your8BitUnsignedVariable;et voila, your 8 bits are written (assuming you have previously set the pins to output mode, either using arduino pinMode functions or writing to the DDRD register).Alternatively of course you can do it bit by bit using arduino pin operating functions if you wanted, which might be useful if you wanted to map the bits of your byte to different arduino pins...Code:uint8_t arduinoPinToUseForBit = { 4,5,6,7,8,9,10,11 };for(uint8_t x = 0; x <= 7; x++){digitalWrite(arduinoPinToUseForBit, (my8BitVariable>>x) & 0x01);}Or maybe you wanted to pulse an LED on a pin that (count) number of times, in which caseCode:for(uint8_t x = 0; x < my8BitVariable; x++){digitalWrite(pinToPulseOn, HIGH); delay(howLongEachPulseIs); digitalWrite(pinToPulseOn, LOW); delay(timeBetweenPulses);}as I say, this isn't a "how do I use arduino" thing, it's just programming, there's plenty of ways to skin this cat.

author: westfw
author_rank: Super Contributor
timestamp: August 04, 2018, 07:20:06 am
content: QuoteQuoteSo in that case, you're doomed. The Arduino "abstractions" don't do "ports"; only single pins. At some point the authors of the original code decided that their target audience of Artists and Designers were not capable of (or should not be needing) understanding things like bitmask, base-two numbers, and boolean arithmetic (I suspect they are right.) The preferred way to output to more the one pin at a time is ... one pin at a time. And yes, that's about 100x slower than "PORTC = value;"QuoteSo ... just bypass it. You can write "PORTC=value;" just fine, right? Part of the attraction of Arduino to people beyond that target audience of beginners is that ... it's just C, and the normal avr-libc stuff is all there, and you don't NEED to use the "gobbly-gook"Yeah, you'll need to either lookup a pin diagram, examine the schematics, or read the Arduino core source code to figure out which ports and bits go to which "pins." And if it's NOT an AVR, you may have to hunt up info in strange places (the ESP chips in particular are an obscure architecture with awful documentation (by Western Chip Vendor standards. It's really amazingly better than the documentation we usually get for Chinese chips.)

author: Quarlo Klobrigney
author_rank: Super Contributor
timestamp: August 04, 2018, 08:03:05 am
content: Ah at last someone who understands what I getting at. I know it's a limited architecture, but the blasted thing needs learning. I know all the regular GCC command stoof PORTx = 0xnn and the (1<<zzzz) etc. etc. Don't get me started on millis(). And no _BV.As you say it was restricted function wise for the "artists" & "hackers" who learned how to make a LED flash after 3 weeks.As far as the thread hijack, your right, the docs on the ESP32, but isn't so bad from what I can see. Time will tell once product arrives in a few weeks (months?).Thanks to all who replied with your intelligent answers.Quote from: westfw onTodayat 02:20:06

author: carl0s
author_rank: Unknown
timestamp: August 04, 2018, 12:52:42 pm
content: Ahhh.. I get what you're doing now, sorry :-) That's an interesting idea, using the gpio as a parallel data bus. I still think you should have a look at the stm32 stuff though too 😁

author: westfw
author_rank: Super Contributor
timestamp: August 04, 2018, 11:00:33 pm
content: Yeah: the first things to learn about the Arduino core functions:IO is referred to by "pin number""pin numbers" are defined by the board, not by the chip. They're not necessarily grouped by the "ports" of the underlying chip (for example, the Arduino MEGA groups all the UART pins together, and "a bunch" of the PWM pins.)Except for higher IO functions, like UART, SPI, or I2C, which become C++ objects. Sometimes configured with a bunch of pin numbers, sometimes HW-fixed. (Why isn't a Pin an object too? We may never know!)And except for some things they overlooked (attachInterrupt() should surely use a pin number, rather than the AVR "interrupt number.")So the preferred "generic" Arduino implementation of a PORT in an Arduino environment involves an array of pin numbers, set one-at-a-time with digitalWrite() This is slow, but works on any board, allows the port to span multiple chip-level "ports", and allows an arbitrary number of bits in the PORT. If you're good, and write a PORT library, you can go ahead and optimize as much as you want to (it's pretty common to cache the pin to port/bit translation data and skip some of the digitalWrite() work like "turn off PWM if it was turned on." Or to detect whether the pins specified implement the hardware version of the function being provided...)

author: Quarlo Klobrigney
author_rank: Super Contributor
timestamp: August 05, 2018, 02:23:32 am
content: Yep it's all a bit counter intuitive. Give me my STK500 (2 of them free from Atmel seminars) AS4, (not AS7 bloat) and I can have my way with any chip, sans SMD.Funny you should mention the MEGA (2560), I was just looking at it before seeing your reply. I bought it PT (pre-tarrif or pre-Trump, choose 1, 2 or none) so it was fairly cheap.I don't like Arduino. I hated it when a less savvy colleague (IT) said "look what I can do!"He never programmed an Atmel chip in his life.My reply was "it'll never last. It's just a fad" That was 4 years and 1 job ago.It's an abomination in my eyes, but like I said, it needs to be learned. Painfully or not.Thanks again for you kind input.

author: westfw
author_rank: Super Contributor
timestamp: August 05, 2018, 05:04:51 am
content: QuoteWhatever. It's a recent player in a long string of "abominations" like BASIC52, BASIC Stamp, PLCs, and so on.Overall, I find it ... less depressing than the long string of "Vendor Libraries" of questionable merit.It is annoying to get old and curmudgeonly when the job and "stylish" markets want you to be wildly enthusiastic about something new and not-nearly-as-different as they want to believe.

author: AG7CK
author_rank: Regular Contributor
timestamp: August 05, 2018, 02:07:04 pm
content: Quote from: Quarlo Klobrigney on August 03, 2018, 10:58:28 pmI cannot understand the helplessness of certain "experts" asking for "intelligent" answers.Search string: 'arduino pin map to ports'One of the first returned results in all major engines:https://www.arduino.cc/en/Hacking/PinMapping168Contains cute little figure that - if one uses one's wit - answers a lot about Arduino pins, ic pins, ports and Arduino serial :Digging a bit more will yield a figure where one will see that the ASCII-based serial can be parallel dumped on a port using a "bigger" board where there are ports without dedicated pins.Imo almost all the OP's further questions can be answered in a similarly simple way. Not being able to find the (both) web- and IDE-accessed 'DigitalReadSerial' example is beyond my understanding.Arduino is no worse or better than anything else. Just different. The information on how to use or discard it on any level is easy searchable.

author: Quarlo Klobrigney
author_rank: Super Contributor
timestamp: August 05, 2018, 03:50:49 pm
content: Well I suppose because you are infinitely more intelligent than everyone else. You presuppose that I have not looked. Wrong. Perhaps i lack the search results for the questions that I submitted. I got my answer previous to you, so move along now.

author: rrinker
author_rank: Super Contributor
timestamp: August 06, 2018, 07:03:38 pm
content: I have a different one, with an ATmega328 and the pin labels are all color-coded. One color is the Atmel port, one is the Arduino "Pin", one s the function, etc. I printed this out and put it in a protective sleeve because I refer to it often as I do a lot of my prototyping work on Uno or Nano but my final projects just use bare ATMega328's.As for 'abomination' - why? Unlike many other "designed for beginner' environments, with Arduino you can freely bypass the 'simplifications' that cost performance and do the register writes yourself, as others have pointed out. You aren't stuck with the limitations of JUST the Arduino functions. The sheer mass of the Arduino movement has resulted in Arduino plug-ins for MANY different editors and development environments, if your ire is strictly directed at the official Arduino IDE. Don't like it? Don't use it, but still write the same code.One of my designs will make use of the normally 'reserved' pins 0 and 1, because the bare chip will have no serial IO connected, so those pins are free to use for whatever I want, just like programming the bare micro with any Atmel compatible devlopment environment. Best thing is, I am writing the code to those bare chips using - an Arduino!It should be obvious by now that the Uno/Nano and similar are just not suitable for what you are attempting to do, because there are no full 8 bit ports available. But the Mega DOES have full 8 bit ports available and you should be able to easily accomplish this. For a 'pure' Arduino solution you will have to decode the value into binary and set the pins accordingly, or just skip the whole thing and set the port register - which I do not think of as not using 'Arduino' because in all but the most beginner of Arduino references I have read, the technique of bypassing the pinMode and digitalWrite and so forth is well documented as a way to massively increase performance.

author: Quarlo Klobrigney
author_rank: Super Contributor
timestamp: August 06, 2018, 09:04:33 pm
content: It's not that it's not suitable, I'm just trying to understand why crippling certain functions are good thing.Remember as you say, the bare 328 and others, are fully functional, and I have used them so for years.I'm approaching this backwards. From full ops to reduced ops. So a head scratcher for me.Not to mention learning that int8_t is now int, _delay_ms() is now delay(), PORTD 0 & 1 are unusable in the boards, and so on and so on. In the native Arduino language.I spent a few hours trying to figure out why D0 & D1 would not go low or go into output mode (including reflashing the bootloader on the STK500. Thanks to westfw above I found out that I can't use it on an Arduino board!Thanks, I do appreciate all of your input(s). You just didn't understand my direction of flow.Looking at someone else's sketch, I'm trying to learn the syntax. Not necessarily how to program an AVR, as well as finding out the limitations of the boards.

author: carl0s
author_rank: Unknown
timestamp: August 06, 2018, 09:08:07 pm
content: I'm sure I used uint8_t in Arduino as well.To be fair, I was pulling my hair out when that didn't work at repl.it the other day. Apparently I just needed to include stdint.h or something.Anyway, use platformio. Or stm32 and truestudio.

author: Quarlo Klobrigney
author_rank: Super Contributor
timestamp: August 06, 2018, 09:47:48 pm
content: And yet I can do FPGA's Altera... And STM32's in Eclipse.For some reason the Arduino is counter-intuitive to my brain.Maybe I suffer from CRS.Quote from: carl0s onTodayat 16:08:07

author: rstofer
author_rank: Super Contributor
timestamp: August 06, 2018, 10:49:44 pm
content: Quote from: Quarlo Klobrigney on August 06, 2018, 09:47:48 pmThe device was never intended for engineers or programmers. It was designed specifically for artists as it allows them to add some amount of animation to their creations.Once you start to apply the device beyond simple artistic animations, it falls flat. In its domain, it is highly capable.Because the boards are cheap, they are being used in all kinds of projects for which they really weren't designed. The users have to adapt their thinking to the platform or just keep the bootloader and write everything else from scratch. There's no compelling reason to use the Arduino libraries as long as the user is capable of writing every single line of code (or possibly use avr-lib). But sometimes the Arduino libraries are truly worthwhile.When I want something in a big hurry, I reach for the Arduino. I use the VisuaMicro Arduino plug-in for Microsoft Visual Studio.https://www.visualmicro.com/

author: westfw
author_rank: Super Contributor
timestamp: August 06, 2018, 11:31:43 pm
content: QuoteHave you ever tried to explain "PORTD &= (1<<PD4);" to someone with minimal embedded programming experience? Even somewhat experienced application programmers don't get it, what with bitwise operations and shifting being pretty uncommon in the numeric and text processing worlds.I pretty much believe that the "pin number" abstraction is one of the best design decisions in the Arduino core.QuoteNo. int is still int (16 bits), and uint8_t is still available. "byte" is also uint8_t, which is a common alias (also "BYTE", and "BYTE8") in various environments. Because it took the C folk so freaking long to admit that maybe having exact sized variables was a good idea.Quotedelay() is somewhat different than _delay_ms() Well, substantially different, actually, given that the argument doesn't have to a floating point compile-time constant.QuoteUm. They shouldn't be "unusable": D1 should act pretty normal, and D0 should act like it has a relatively strong (~1k) pull-up attached. Unless you're trying to use Serial communications at the same time, which wouldn't work on a bare ATmega328p, either. (I guess it's less than obvious that D0/D1 are shared with the UART pins than if you were dealing with bare ports. Not all Arduinos have this limitation, BTW - chips with more than 20 usable IO pins, or with native USB, shift things around (easy to do, give the "board pin number based" scheme) and have different things to worry about.

author: sleemanj
author_rank: Super Contributor
timestamp: August 07, 2018, 02:11:04 am
content: Some people seem to rail against the Arduino abstractions... I don't get it, abstractions are good, "digitalWrite(1, HIGH)" does exactly what it says on the tin, on any "arduino" core/derivation/board, same with the higher level stuff like Serial, SPI or Wire (I2C).Yes the way that some of the abstractions are implemented in the standard core are a bit... suboptimal (for various reasons historical political and implementational), and there could be some more (for port-wide writing for example) but the idea of the abstractions themselves is GOOD, for readability, for simplicity, and for portability.Above all, if you don't like the abstractions, then don't use them, nobody is twisting anybody's arm when it comes to Arduino, if you want to write to ports directly do it, if you want to mix in assembly, do it, if you want to handle all your own Serial comms do it.Very little is actually setup for you in the core's main(), basically just the timer for millis and ADC stuff form memory, all easily disabled or changed in your "setup()" if you don't want that.It's like a naive web developer saying "I don't use a database abstraction layer, it's faster to do mysql_query()", yeah sure it's faster but it's a terrible idea for all sorts of reasons.

author: Nusa
author_rank: Super Contributor
timestamp: August 07, 2018, 03:03:45 am
content: I think your primary problem is that you are far less of an expert than you think you are and are frustrated because you don't know some core details about the C or C++ language.You can't read and understand a book or proper tutorial about C without learning that "int" is a language defined hardware-dependent type with a MINIMUM size of 16 bits. You'd also know about "char" and "long" and "unsigned", etc.The int8_t and similar types you're used to are useful extensions to the language defined by typedefs in a header file. #include <stdint.h> and you should be able to use them again. Go look at that file if you want to see what they're defined as for the arduino hardware.

author: rrinker
author_rank: Super Contributor
timestamp: August 07, 2018, 03:09:51 pm
content: Quote from: Quarlo Klobrigney on August 06, 2018, 09:04:33 pmSimple - keeping it simple. The 'crippling' is just using the PD0 and PD1 as the serial port that is part of the Atmel architecture to provide a simple serial (USB) connection for the user. Surely easier than some non-micro expert trying to figure out how to connect one of a multitude of ICSP programmers. It's all part of the overall picture - just plug your board into your computer, write some code, click the button, and it gets compiled and uploaded. Penalty: loss of two potential data pins.Same thing with the timers and stuff. The whole idea is to isolate the user from the intricacies of all the register programming, so the Arduino 'shell' assigns things in a consistent manner to provide functions that the beginner can use without figuring out how to configure the timer registers or even worse, read them.Is it the ideal way to utilize this (or any other supported by Arduino) micro? Certainly not, removed from the ecosystem you can do anything the micro is capable of, not just a limited subset. The cost is more complexity. The goal of Arduino was not to exploit the capabilities of the micro, it was to provide an easy to learn consistent basis for non-programmers.I think I DO know where you are coming from. You are already well beyond the knowledge level of the typical Arduino target audience. You just KNOW that "this" is the way to accomplish a particular task, but in the simplified Arduino world, it just isn't possible. It's hard to go backwards. I felt much the same way back in the day going from an 1802 CPU in my first computer to trying some assembly on a 6502. On the 1802, I had 16 registers, each 16 bits wide to play with. Then I got to the 6502 and it was horrible to me. So much more complicated despite being, in essence, a simpler design. I had to make and manage a stack for even relatively trivial programs, whereas on the 1802 I could simply store some data in one of the registers I wasn't using.It's hard going back. It's like driving around in a Ferrari for a year, then having to give it up and drive a Yugo.

author: cstratton
author_rank: Regular Contributor
timestamp: August 22, 2018, 04:02:04 am
content: Quote from: Quarlo Klobrigney on August 04, 2018, 08:03:05 amNo, it wasn't restricted at all. All of those capabilities of the AVR hardware are still there. Beginners are lead to using some questionable abstractions, but you aren't required to follow suit. There are plenty of raw AVR-isms appearing in "sketches" that accomplish real, useful tasks. Sometimes that is warranted, sometimes it is stylistic, but apart from a very few things to keep in mind (such as not colliding with default background functionality) you're free to do things either the Arduino way, or the AVR way,in the same program..Of course if your target platform is not an AVR Arduino but an official or unofficial Arduino port to some other platform, then primitives exposed (at least with the right include files) are those of that chip, rather than an AVR.

author: brucehoult
author_rank: Super Contributor
timestamp: August 22, 2018, 05:33:20 am
content: Quote from: westfw on August 04, 2018, 07:20:06 amI'm not sure you could call xtensa (which is what at least the ESP8266 uses) an obscure architecture! It's owned these days by Cadence, one of the biggest vendors of EDA software. It's certainly not in the league of x86 or arm but it's one of only about 20 ISAs supported by the linux kernel, and you can get gcc and llvm for it.

author: mtdoc
author_rank: Super Contributor
timestamp: August 22, 2018, 05:50:12 am
content: Quote from: rstofer on August 06, 2018, 10:49:44 pmNo, not really. It was developed for design students and other non-engineers - which does not mean “artists”. Sure, some artists have made use of Arduino, but they’ve always been a very tiny minority of Arduino users. Most artists are too non-tecnical to even consider encorporating even simple electronics into their work. It is fallacious thinking to suppose that non-engineer == artist.This thread has some some great responses and really does a great job at flushing out some of the misunderstandings and misconceptions about the reality of what the Arduino platform is about and what it is and is not capable of. Some really great nuggets of info here! If it was really as limiting as some seem to assume, it would never have grown as vast a community (even including many engineers) as it has.

author: westfw
author_rank: Super Contributor
timestamp: August 22, 2018, 10:08:04 am
content: QuoteHow many xtensa-based chips can I go out and buy, other than the two (?) from Espressif?Is there a cheap version of the core that I can add to hobbyist-sized FPGA boards?

author: sokoloff
author_rank: Super Contributor
timestamp: August 22, 2018, 10:23:10 am
content: Have a look:https://ip.cadence.com/ipportfolio/tensilica-ipTensilica shipped billions of cores, not all xtensa (Cadence later bought Tensilica), so I have to agree that it’s not “obscure”.

author: brucehoult
author_rank: Super Contributor
timestamp: August 22, 2018, 11:41:55 am
content: Quote from: westfw on August 22, 2018, 10:08:04 amThere are billions of them. Most are embedded so deeply that users never know they are there, let alone what ISA they are.I regret now that when I did some work on the Samsung Bio Processor (https://en.wikipedia.org/wiki/Samsung_Bio_Processor) systolic array chip, and its earlier cousins that listen for "OK Google" in phones, I didn't check the instruction set precisely against xtensa. I definitely had the very strong impression that it looked a lot like xtensa with some extra (doh) stuff added.

author: hans
author_rank: Super Contributor
timestamp: August 22, 2018, 12:43:07 pm
content: Quote from: Quarlo Klobrigney on August 06, 2018, 09:04:33 pmIt's not crippling.. just another set of tools. Let's define what the Arduino is:- A range of boards to choose from. Some may use the ATMEGA328, some don't. But above all, they are standardized on pin maps.- The micros have a bootloader integrated, most of them are serial.- You can upload programs via the Arduino IDE, or commandline tools.- Sketches are preprocessed C++ programs. They include a few libraries:- Millisecond time base- Basic serial library, with asynchronous data receive (interrupts)- Functions for GPIOs, PWM and ADCs- A gazillion number of user libraries, of varying quality- A setup() and loop() convention, which is basically:Code:void main() {backgroundSetup();setup();while(1){loop();}}Coincidentally, people rant on just about everything I just mentioned. The classic boards standardization have weird mechanical dimensions (off-grid). The IDE has no debugger, is limited to use (it provides no details such that beginners are not intimidated). The provided software libraries are confusing or inefficient.You got to take it for what it is, or find alternatives. You can skip almost all of the software libraries if you want to. You can program (almost) bare programs compiled with GCC into an Arduino. Most arduinos also feature an ISP header, so you could even bypass the bootloader if you want. Or you could program the bootloader onto any ATMEGA328 and use Arduino software on your own boards.It's up to you. I rarely use Arduino, but for what it is (rapid prototyping), it does the job quite well.

author: Quarlo Klobrigney
author_rank: Super Contributor
timestamp: August 22, 2018, 06:21:35 pm
content: Again for clarity, I'mnottrying to program with the Arduino IDE in GCC, I'm trying tolearn amuddle through a whole other way of doing it "their" way.I use the AVR GCC commands that I always use in Studio,withdebugging.I just didn't realize that such a thing was possible with the Arduino IDE (sans debugging) until 6 months ago. Just a dumbed down, obfuscated bloat IMHO.Again, to restate the goal here is the "learning" of nativeArduino syntax.No rod of correction or chastising is necessary.I saw this a few days ago from a YouTube comment, not my words, and I quote:Name WithheldI feel we walk in each other's shoes.This is the terrible result of the dark age of the Arduino.The generation behind has no idea how to program in assembly much less how to dotiming calculations on an RC circuit.The Arduino is a dumb bomb aimed directly at America.Europe has been in the back seat of science and engineering since WWII.Now from the most unproductive parts of a dead European empire (the Mediterranean)comes the perfect weapon to destroy America's technological leadership - the Arduino.Things will be much worse before turning about. There must be a generation of failedembedded systems before academia wakes up and again challenges youth to learn Boolean algebra.It came to mind that the Soviet Union went through a phase like this. In their case,Stalin's purges were the dumb bomb that wrecked their generation of scientists.Long rant. I know. But I am depressed at the state of blissful ignorance in the mindsthat should be learning Maxwell's equations but is instead captivated by idiotName Withheldand his blinkies.Sad days in America.End quote.

author: mtdoc
author_rank: Super Contributor
timestamp: August 22, 2018, 07:24:16 pm
content: So IOW, just another disgruntled engineer whining about Arduino.There are literally millions of people around the globe whose introduction to electronics and embedded systems is only due to Arduino. Many thousands of those, whose interest was sparked by their Arduino experience, will go on to learn to use C or even Assembly as their project or educational requirements dictate.That would never have happened if the only option for learning embedded programming was the “professional” approach using non-intuitive toolchains and/or expensive professional IDEs.It’s as if some just can’t tolerate the fact that there are millions of “non-engineers” out there building embedded projects that previously only those in the elite club of embedded engineers and sophisticated hobbyists could do.So what if there are better ways to program and produce more efficient code? Without the “inefficient” Arduino abstractions there are millions who would never be coding at all.The value of the Arduino approach has even been validated by professional engineers who have admitted they often trun to it for quick prototyping.If you don’t like Arduino - fine just don’t use it. But this type of circuitous criticism is pretty transparently just sour grapes IMO.

author: sokoloff
author_rank: Super Contributor
timestamp: August 22, 2018, 08:22:32 pm
content: Quote from: mtdoc on August 22, 2018, 07:24:16 pmI expect the same kind of arguments from those opposed to electric starters, then automatic transmissions, then anti-lock brakes, then traction control, then stability control, then collision avoidance on automobiles.If it was hard for me, it damn well ought to be hard for others as well.I made a living as a programmer; I did my time, wrote assembly, C, C++, others, did digital logic labs in college, wrote my undergrad thesis on finite state machine design tools, etc. With all that as background, I find Arduino to be a marketing and community building stroke of genius.It's not an elite priesthood anymore; I think that's a great thing for hobbyists and consumers.

author: technix
author_rank: Super Contributor
timestamp: August 22, 2018, 09:00:11 pm
content: For the Arduino sketch system, it is kind of a mini-RTOS with its own, semi-standardized hardware abstraction. The sketch is actually based on C++, and the build tool includes a preprocessor that can extract the usual project settings from the sketch file. Arduino implemented a layer of hardware abstraction to mask both the hardware implementation details (a set of drivers with standardized API) and the board differences (the same physical connector can map to different port/pin on different board and chip.) The RTOS part comes in either a dumbed-down FreeRTOS or Arduino's own preemptive context switching, as well as a good selection of guides on writing cooperative multitasking code.

author: cstratton
author_rank: Regular Contributor
timestamp: August 22, 2018, 10:19:03 pm
content: Quote from: technix on August 22, 2018, 09:00:11 pmNo, it isn't. Not even remotely.Having interrupt based serial buffers and a timer interrupt does not constitute an RTOS or even cooperative multitasking.

author: sokoloff
author_rank: Super Contributor
timestamp: August 22, 2018, 10:27:15 pm
content: Quote from: cstratton on August 22, 2018, 10:19:03 pmThough it isn't on the AVR implementation, it is on the ESP32 Arduino implementation.https://github.com/espressif/arduino-esp32Whether that'sreallyArduino or not is perhaps of some debate.

author: westfw
author_rank: Super Contributor
timestamp: August 22, 2018, 10:36:54 pm
content: I find it vaguely amusing that the people who complain loudest about the inefficiency of "digitalWrite()" vs "PORTB |= 1" usually have a particularly poor understanding of the differences between the two...

author: brucehoult
author_rank: Super Contributor
timestamp: August 23, 2018, 05:50:25 am
content: Quote from: hans on August 22, 2018, 12:43:07 pmAnd if you want to automate things on a time scale of milliseconds or longer -- which is almost unimaginably quickly for the people Arduinos are aimed at -- then the fact that digitalWrite() takes a few us while you could bit-bang the actual register in a fraction of a us is of absolutely no importance whatsoever.And if by some chance it's not fast enough on a 16 MHz 8 bit AVR then go and buy a 32 bit 80 MHz ARM-based board, or a 256 MHz RISC-V HiFive1. Your code will probably work as-is, zero changes, and any shields will plug right in also.