text:
Improvised Keyboard?
I want to make a keyboard type panel, which will only have 7 buttons and two knobs, and connect it arduino to program it with functions, he heard that he needed the Keyboard library. but it is not available with arduino uno, which is what I work with, he heard about what I should do a keyboard mapping, it would help me explain to lay a foundation and carry out the project that I want "please do not leave me with the doubt". first of all, Thanks.

it is unclear what is your question

The Uno can't (easily) do keyboard functionality. Get a Leonardo or Micro instead.

If you plan to trigger function on a PC by keystroke and want to simulate a PC keyboard on the PC with your computer than I recommend to use the keyboard lib which is able to map your button to key codes and send them to a PC over USB. But the communication over USB and the simulation of a HID (Human Interface Device) connection is (as far as I know) not possible with an Arduino. (You need a 32u4 or SAMD micro based board) like the leonardo.
But if you just plan to trigger functions, that run on the Arduino, the kb lib is not necessary. That a standard job for the Arduino and can be done with 7 input pins and 2 analog pins.

It is actually a game of reactions, the game appears on the computer and the subject reacts from the panel, if possible? I don't know how to do it, they tell me, that I should do a keyboard mapping that I want to implement, but I don't have a micro or leonardo, what can I do?

is that it is my project to pass intern of my studies

I'm very busy this morning, but this evening I try to find a solution. In the meanwhile, there is a software called processing ( https://processing.org/ ), that can interact with arduinos of all kind. It something like the Arduino IDE and must also be programmed in a C/C++ dialect. Perhaps you find some ideas, if you look at the example projects. Can you control the game with serial input, I mean, have you access to the games code, and can write your own controlling interface? If not, you have to simulate keyboard events.

the game is made in java,
I will add the hardware part
and good
If you have any ideas, I would appreciate it !!
and thanks I will look at the page you recommended.
thanks for answering i'm stressed

If I understand you right, you build the hardware (the control panel) and some others write the game in Java. If they are nice guys, you and your colleagues  could create a text based control protocol and you use this protocol to send control statements to the game over the serial interface. That's easy for you and the game writers too. And it is the only easy way a UNO can communicate with a PC. In the arduino you only need Serial.print("control statement")` commands;  An in Java thei can use a serial communication lib like https://fazecast.github.io/jSerialComm/

Keep the protocol short and easy. e.g. assign a letter to a key. key1='A', key2='B', ... key7='G'. So if for instance key2 is pressed you send a Serial.print("pB") and if the key is released you send a Serial.print("rB"). In the game they use the first letter in the recieved string to indicat if the button is pressed or relased and the second letter to indentify the key.  The same is for the analog values of the knob use e.g. a "aA123" to indicate an analog value of 123 for knob A and "aB1023" to indicate an analog value of 1023 for knob B.

If you connect the arduino to a windows computer it should automatically create a COMxx port that can be used by the Java programm (the game).

Hope this helps you a little bit. And good luck with your project.

Thank you so much for everything


text:
Noise on piezo analog read due to Arduino power supply
I am making a device that measures temperature and vibrations and records the values onto an SD card. It will be a standalone device.
The hardware used:
- Arduino Uno
- PCF8523 RTC clock
- MAX3186 + PT100 RTD temperature sensor
- Adafruit data logger shield
- Typical bare piezo sensor
For the vibrations, a piezo sensor is used. Because it can produce a signal in two directions, I decided to use a voltage divider to offset the signal from GND. Two 5.1K resistors are connected from the piezo negative terminal to 5V and GND. A 1M resistor is placed in parallel with the piezo sensor. The positive terminal is connector to analog input 0.

The sensor is read 100 times per data point, the maximum and minimum values are stored and the final value is set to be the difference between the two (two times the amplitude).
USB

9V wall adapter

When the system is powered via a laptop USB port, the resting value has a jitter of a few bits. When a 9V wall adapter powers the arduino, the jitter is +/- 30 bits. Any small vibrations disappear in the noise.
USB with piezo

9V with piezo

9V without piezo

I would like some help to find the best way forward.
edit 29-10 17:53 Added better plots
edit 30-10 17:53 Added plots for 2.5V and 3.3V lines

Have you got an osci to check if the 5 V from Arduino Vcc is smooth or "rippled"? Did you use the AVRef Voltage reference? This should be stable. How long are your wires? Can you shorten them for the sensor and the resistors to make the antenna minimal? A schematic and a photo of you setup would be helpful. ;-)

@PeterPaulKiefer Sorry I don't have a oscilloscoop to check. I'm using the default analogread, I haven't changed the reference settings. Wire to piezo is roughly 75 cm and shielded, shield is not connected to GND at the moment. Strange thing is that the whole set-up is exactly the same for both plots but when powering the arduino with 9V I get the huge jitter issue. I've added a schematic for the piezo.

The 9V wall adapter is in most cases a switched power regulator with a high frequency. That's like a radio transmitter direct beside the wire. So there is nothing mystical, when the smooth USB Voltage does not show problems but the
"radio transmitter" does.
There are two ways the power supply can impact: over radio wave or as ripples over the regulated Voltage of your Arduino.
I asked myself, which one it is (or even both)? If you use the extra regulated analog voltage reference (AREF) as the +5V on your Voltage divider, it would be more likely that the problem comes through the air. Then it would help if you activate the shield of the wire by connecting it to GND.
If a rippled supply voltage is the problem, you have to smooth it. Perhaps with a low pass filter (a big Elko between Vcc and GND).
Perhaps you have a solenoid iron core. Then you can wrap the wire to the piezo sensor a few times around it (near the A0 Pin). This technique is often used in computer power supplies to prevent the switching frequencies from escaping to the public power lines.

To be clear, I'm using the regular 5V Vcc for the voltage divider. Is there a better, regulated voltage I can use on the board? I was under the impression that the Aref pin can only be used to supply an external reference. Can I use that pin to get a regulated 5V as well or have I misunderstood? How about using the 3.3V?

From my measurements, I know that the regular Vcc  is poorly stabilized. If the power supply has ripples, often I found attenuated ripples in the Vcc also. The VREF is a special pin that be programmed to provide a reference voltage for the ADCs. see https://www.arduino.cc/reference/en/language/functions/analog-io/analogreference/ . What I meant was connecting the VCC to VREF and set the analog reference to EXTERNAL. Than the voltage reference and the VCC have ripples. Because the digital value is obtained by comparing both voltages the error might be cleared.  But it is just an idea. ;-)

You can also build a external stabilized voltage add it to VREF and set the reference voltage to EXTERNAL. And you have to use this Voltage for your piezo reference. But it's only needed if the problem is caused by ripples on VCC. If the problem is cause by EMI you must try to filter the piezo voltage before it reaches the A0 input. I'm busy this morning, so I add just two comments. In the evening I'll edit my answer to order the information.  My English is not very well, so I might be fairly unclear. ;-)

Peter, not a problem, you have been very helpful so far! I now get what you mean with supplying Vref with Vcc. I did some tests on the voltages, I connected 5V to A1 and 3.3V to A2 and did the same measurements. I took 100 samples and show twice the amplitude (difference between min and max values).
USB
https://imgur.com/rmhgnRB
9V
https://imgur.com/MQEMvc9. I think a potential solution might be to use the 3.3V from the datalogging shield as it looks to be very stable! Although strangely, the 5V plots don't show a huge difference between the two power sources...

Actually, I have done the plots again and they now look like this. USB: https://imgur.com/ImOdHyC. 9V: https://imgur.com/JWyaxo2. I'm not sure where the difference comes from but these seem to make sense. So judging from these plots, I should have no issues running the piezo with the 5V via a voltage divider. I'll see if I can also measure the voltage after the divider.

Here are some plots of the 2.5V line with and without piezo. USB with piezo: https://imgur.com/mIbWWd4. 9V with piezo: https://imgur.com/JoxX7BS. 9V without piezo: https://imgur.com/buD1Fc0. Strange...

The last plots are definitely a hint, that the problem depends an the long wire to the piezo. If you remove it the signal is smooth. Have you tried to ground the shield?

A new plot gives even more insight... 9V with and without piezo: https://imgur.com/qEnOS7T. I manually connected a new, short wired (40 mm) piezo to the circuit and then disconnected it again. You can see the effect on the 2.5V...

A another plot where I connect and disconnect the long wired piezo, looks very similar. 9V source. https://imgur.com/TK63aF7

Sorry it has been getting late and I'm too tired to edit the Answer as promised. But I'm a bit irritated from what I see in the new plots. Shorten the wires increases the effect. It seems as if the power supply sends out waves and the piezo receives them, Perhaps it acts like a crystal oscillator, I've never heard of such effect before. Perhaps that's a well known behavior or I misinterpreted it wrong, but it's sure, we are beyond my limits. From what we know now, this is a question for the electronics forum in SE.

Peter thank you so much for your patience and help. I have finally found a solution for my problem and it turns out that connecting the shield from the piezo wire to Arduino GND was enough. I feel silly for not trying this before, I set my sights on voltage ripple because the USB connection did not have any problems with noise. I actually made a mistake with the short wired plots, I redid these in a proper way with a connector and didn't see the jitter....

You're welcome. I'd expect that you tried out the grounding, because you did not mentioned it again. So it's a bit of my fault also. I should have asked you one more time. In the beginning that solution was my favorite. But the conversation was very interesting and I had some new ideas of how the used e.g. a second UNO the simulate a very low frequency oscilloscope. I've learn much, and now it's my turn to thank you.

In addition to what Peter Paul Kiefer suggests, you will also want to place an RC low-pass filter, between the piezo transducer, and the analog input.
You mention that you'll be sampling this value 100 times per second. So the cutoff frequency, for the filter, should be set to 50 Hz (the Nyquist frequency).

I don't think the OP takes samles with 100 Hz. He only said that he takes 100 Samples to choose the maximum and minimum values from it. I believe he take it at the highest rate that's possible. I thought about low pass filters too, but as he used the piezo for shock detection I expect a part of the frequency spectrum (of the piezo pulses) in the same range as the EMI. So it's definitely worth a try, but I don't expect good results.

source: Stack Exchange

license: Creative Commons - Attribution Share-Alike - https://creativecommons.org/licenses/by-sa/4.0/

sort: votes


text:
EEPROM.get returns bad data
I am using the attached code.
What I am trying to do is:
Test if there is a personalized "board serial number" written in the EEPROM (by previous code run)
If data found was not 7 characters (e.g SN-XXXX), then generate a serial number and save it to EEPROM
Problem is: it generates a serial correctly, it even stores and reads it a few times, but when I disconnect the USB cable and reconnect to test again, it returns some bad data from the EEPROM, like: ⸮^R⸮y⸮| which seems to pass my 7 characters test and it doesn't generate a new one.
What am I doing wrong ?

#include <EEPROM.h>

// board SERIAL number
char serial_characters[] = {"ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"};
// will be filled as SN-A2KH
String serial_number;

void setup() {

  Serial.begin(9600);

  // Get the float data from the EEPROM at position 0
  EEPROM.get(0, serial_number);

  // serial from EEPROM valid
  if (serial_number.length() == 7) {
    Serial.println("Found valid serial in EEPROM");
    Serial.println(serial_number);
  }

  // serial from EEPROM not valid (e.g not: SN-XYZ5)
  if (serial_number.length() != 7) {

    Serial.println("Serial from eeprom is NOT 7 chars, generating a random serial");
    Serial.println(serial_number);

    // if analog input pin 0 is not connected, use noise from it in order to generate a random seed, otherwise random is not so random
    randomSeed(analogRead(0));

    // serial might be empty now, set a "SN-" prefix
    serial_number = "SN-";
    for (int i = 1; i <= 4 ; i++) {
      serial_number = serial_number + serial_characters[random(0, 35)];
    }
    Serial.println("Generated serial now: " + serial_number);

    // save to eeprom if format is valid
    if (serial_number.length() == 7) {
      EEPROM.put(0, serial_number);
      Serial.println("Written serial to EEPROM");
    }

  } // <<< serial from eeprom not correct, generated one

}

void loop() {}

You are saving a String object in EEPROM, which is useless. A string
object does not store the contents of your string. Instead, it just
stores:

the memory address where the actual contents (the characters) is
stored
the amount of memory allocated for this contents
the number of characters that actually make the string

This is what you are storing to, and retrieving from EEPROM. So you get
the correct number of characters (third item in the list above), but the
memory address now points to uninitialized RAM.
I suggest instead storing in the EEPROM a raw C string, i.e. an array of
8 chars (7 printable chars plus the terminating NUL). You could achieve
this by just changing the declaration of serial_number:
char serial_number[8];

For checking the validity, I would just check that it starts with "SN-"
and the last char is a NUL:
if (memcmp(serial_number, "SN-", 3) == 0 && serial_number[7] == '\0') {
    ...
}

You could do a more stringent validation though, and check that the
other 4 chars are within the valid set.
Edit: to build serial_number with random chars:
strcpy(serial_number, "SN-");
for (int i = 3; i < 7; i++)
  serial_number[i] = serial_characters[random(0, 36)];
serial_number[7] = '\0'; // terminating NUL

Just to have the full working code, I ended up with this:
#include <EEPROM.h>

char serial_characters[] = {"ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"};
// 7 chars for serial and one for string end '\0'
char serial_number[8];

void setup() {

  Serial.begin(115200);

  EEPROM.get(0, serial_number);

  // check found format
  if (serial_number[0] == 'S' && serial_number[1] == 'N'  && serial_number[2] == '-' && serial_number[7] == '\0') {

    Serial.println("serial from eeprom is valid");
    Serial.println((char*)serial_number);

  } else {

    Serial.println("no valid serial found in eeprom, generating new serial");

    // if analog input pin 0 is unconnected, use noise from it in order to generate a random seed, otherwise random is not so random
    randomSeed(analogRead(0));

    // generate a new serial
    serial_number[0] = 'S';
    serial_number[1] = 'N';
    serial_number[2] = '-';

    // overwrite ending chars of serial with random values
    serial_number[3] = serial_characters[random(0, 35)];
    serial_number[4] = serial_characters[random(0, 35)];
    serial_number[5] = serial_characters[random(0, 35)];
    serial_number[6] = serial_characters[random(0, 35)];

    // end string with null as raw C strings ?!
    serial_number[7] = '\0';

    Serial.println((char*)serial_number);

    // write new serial to eeprom
    EEPROM.put(0, serial_number);

  }

}

void loop() {

}

all_licenses: Creative Commons - Attribution Share-Alike - https://creativecommons.org/licenses/by-sa/4.0/


text:
Arduino-Controlled LED Matrix issues
I am making a 20 x 15 LED matrix, and am having some super annoying problems. I was hoping you all could help me find some answers.
It is very important to note that I am following BitLuni's video on this, following it using almost the same parts, and most definitely the same code (I put it below)
To start, this are the main things I am making it with:
6 sets of RGB LED Pixel Lights
1 Knock-off Arduino NANO
1 5v 20A Power Supply
My first problem arose when I received the Arduino Nano. I was able to see it, but not able to write to it. I was eventually able to make it work by using the old boot loader. Let me make it clear, I fixed that problem. But then I short circuited it and bought another one. And now I am faced with the same problem. I have tried using the company's own drivers on the darn thing, same issue.
I was going to put the error here, but when I tried to flash, my computer (Windows) got the blue screen of death. I tried opening the app just now, instant death. So I suppose I'll just reinstall it, just saying, something is MESSED UP with it.
Pretty much, I get the error "the selected serial port does not exist or your board is not connected. "I know for a fact that the COM Port is correct, but it just doesn't seem to like what I am doing.
But I still have another problem. While I had the arduino that I got to work, when I transitioned from using the 5v power supply on it to using the power supply I bought, the lights go nuts. They change to seemingly random colors super fast. But as soon as I change it back to the arduino's power, it was fine. I have tested, and the power output is PRECISELY THE SAME. The arduino just sends out the data for the lights to interpret. I have absolutely no idea why this is happening.
So if you have anything to suggest for either of the problems, I would appreciate it.
Also, here is my code for the lights (sorry this post is really chopped up) It is based on Adafruit_NeoMatrix example
#include <Adafruit_GFX.h>
#include <Adafruit_NeoMatrix.h>
#include <Adafruit_NeoPixel.h>
#ifndef PSTR
 #define PSTR // Make Arduino Due happy
#endif

#define PIN 6

// MATRIX DECLARATION:
// Parameter 1 = width of NeoPixel matrix
// Parameter 2 = height of matrix
// Parameter 3 = pin number (most are valid)
// Parameter 4 = matrix layout flags, add together as needed:
//   NEO_MATRIX_TOP, NEO_MATRIX_BOTTOM, NEO_MATRIX_LEFT, NEO_MATRIX_RIGHT:
//     Position of the FIRST LED in the matrix; pick two, e.g.
//     NEO_MATRIX_TOP + NEO_MATRIX_LEFT for the top-left corner.
//   NEO_MATRIX_ROWS, NEO_MATRIX_COLUMNS: LEDs are arranged in horizontal
//     rows or in vertical columns, respectively; pick one or the other.
//   NEO_MATRIX_PROGRESSIVE, NEO_MATRIX_ZIGZAG: all rows/columns proceed
//     in the same order, or alternate lines reverse direction; pick one.
//   See example below for these values in action.
// Parameter 5 = pixel type flags, add together as needed:
//   NEO_KHZ800  800 KHz bitstream (most NeoPixel products w/WS2812 LEDs)
//   NEO_KHZ400  400 KHz (classic 'v1' (not v2) FLORA pixels, WS2811 drivers)
//   NEO_GRB     Pixels are wired for GRB bitstream (most NeoPixel products)
//   NEO_RGB     Pixels are wired for RGB bitstream (v1 FLORA pixels, not v2)

// Example for NeoPixel Shield.  In this application we'd like to use it
// as a 5x8 tall matrix, with the USB port positioned at the top of the
// Arduino.  When held that way, the first pixel is at the top right, and
// lines are arranged in columns, progressive order.  The shield uses
// 800 KHz (v2) pixels that expect GRB color data.
Adafruit_NeoMatrix matrix = Adafruit_NeoMatrix(20, 15, PIN,
  NEO_MATRIX_TOP     + NEO_MATRIX_LEFT +
  NEO_MATRIX_ROWS + NEO_MATRIX_ZIGZAG,
  NEO_GRB            + NEO_KHZ800);

void setup() {
  matrix.begin();
  matrix.setTextWrap(false);
  matrix.setBrightness(255);
}

int x    = matrix.width();
int pass = 0;

void loop() {
  static int i = 0;
  i++;
  //matrix.fillScreen(0);
  for(int y = 0; y < 15; y++)
    for(int x = 0; x < 20; x++)
      if(y & 1)
        matrix.setPixelColor(19 - x + y * 20, matrix.gamma32(matrix.ColorHSV((x + y) * 256 * 8 + i * 128 * 2)));
      else
        matrix.setPixelColor(x + y * 20, matrix.gamma32(matrix.ColorHSV((x + y) * 256 * 8+ i * 128 * 2)));

  matrix.setTextColor(matrix.Color(0, 0, 0));
  matrix.setCursor(-((millis() / 30) & 127) + 20, 4);
  matrix.print(F(""));
  matrix.show();
}

Thanks all!
-Micah

Do you connect the GND of the second power supply to the GND of the arduino? The LEDs and the arduino need a common voltage reference on the control pin.

If you disconnect and connect the nano the COM port might change. But in the IDE the it does not change automatically. But this is just a very rough guess. I don't expect this to be correct.

@jsotola Sorry for not being specific enough and cluttering my post, I'll fix that. I was mostly asking in the post if I was missing anything or doing something wrong with the panel because I was having issues.

Thank you so much @PeterPaulKiefer! That actually fixed my light problem! I still need to fix the arduino problems but that you so much!

Update: I ended up just returning the arduino and purchasing another one.


text:
Byte not written to the memory
In the following code I'm computing crc and setting it as last (11th) byte in the array. The problem is it's sent on I2C just when I print it on the serial terminal.
  static constexpr uint8_t CLICK_MESSAGE_SIZE{11};
  ...
  uint8_t buf[CLICK_MESSAGE_SIZE];
  memcpy(buf, msgMouseClick[clickMessageCounter], CLICK_MESSAGE_SIZE);
  buf[10] = dallas_crc8(buf, 10);
  Serial.println(buf[10], HEX); //!!!has to be here, otherwise is CRC in packet wrong!!!
  Wire.write(buf, CLICK_MESSAGE_SIZE);

When I'm assig the result of to
auto crc = dallas_crc8(buf, 10);
buf[10] = crc;
Serial.println(crc);

and Serial.print ing it. Then It's works. But with  const auto crc = dallas_crc8(buf, 10); It does not!
I have slightly modified Wire library, where I'm passing pointer to the buffer and it's size. With precalculated CRCs on 11th position it's working fine even for hundreds of bytes arrays.
It feels like a black magic, or compiler error. I'm using latest arduino-1.8.10
Any tips or hints?

The code snippets you show look fine to me. Could you post a minimal, reproducible example showing your problem?

I don't get your problem. What do you mean by "it works" and what by "it does not"? Please provide exactly what you expect and what you get in both cases.

If the difference is just in serial monitor, maybe that missing HEX is the issue.

The problem is that without  Serial.println(buf[10], HEX); the value of the last byte sent with Wire.write(buf, CLICK_MESSAGE_SIZE); is the same like in declaration. Not as calculated and set in buf[10] = dallas_crc8(buf, 10);   The Serial.println(buf[10], HEX); is cruical for getting the last byte correctly.

Just to double-check that I understand you correctly: You are saying that without Serial.println(buf[10], HEX); the value at buf[10] is not what you assigned via buf[10] = dallas_crc8(buf, 10); when Wire.write(buf, CLICK_MESSAGE_SIZE); is executed? Is the value the 11th uint8_t from msgMouseClick[clickMessageCounter] or any other value? This seems so improbable that I'd like to ask you for a [example]. You might want to minimize it.

try it with AVR boards package 1.6.21. install it in Boards Manager. it has older version of gcc

Strangely it helped.

the new version of gcc is buggy


text:
Calling functions from an array of pointers in a library causes 'undefined reference to' error
I am trying to create a library, where I have an array of pointers to functions in it. This array is used by other functions in the library. This is the code of the header file:
class Lib {
  public:
    static void call();
    static void (*caller[])();
  private:
};

This is the code of the .cpp-file:
#include "Lib.h"

void (*caller[2])();

void Lib::call() {
  caller[0]();
}

The sketch executing this is
#include <Lib.h>

void setup() {
  Lib::call();
}

void loop() {}

When I try to compile this, I get the following error:

undefined reference to `Lib::caller'
  collect2: error: ld returned 1 exit status
  Mehrere Bibliotheken wurden für "Lib.h" gefunden

Another weird thing is that the error about the multiple found libraries goes away if I take away the line
Lib::call();

However, if I put the same code directly into the sketch like so:
void (*caller[2])();

void call() {
  caller[0]();
}

void setup() {
  call();
}

void loop() {}

I get no error. What's the problem here?

void (*caller[2])();

should be:
void (*Lib::caller[2])();

Since you are defining storage space for a static member variable you have to tell the compiler what class it's a static member of.

Thanks, that solves the part about the undefined reference. How does the problem with the multiple libraries originate from this though?

Probably because you do have two libraries named Lib.h somewhere?

(incidentally, I don't speak german, so had no clue what you were on about at first about multiple libraries...)

No, there is just one Lib.h file. The funny thing is, that, as I wrote, this error goes away when not calling the function in the sketch. And it also goes away with your solution. I was just wondering where it originated from.

Probably some bug in the IDE then...


text:
Incompatible types in assignment of 'uint8_t {aka unsigned char}' to 'uint8_t [1] {aka unsigned char [1]}'
I'm trying to send custom data. But it doesn't seem to work. I can't find a way to parse my string to a unit8_t. I tried to follow other people's solutions but they don't seem to work for me.
// Declaration
uint8_t myData[] = "";

void loop(){
    myData = *(uint8_t*)atoi("custom string".c_str());
}

This is the error message that I keep getting:
Incompatible types in assignment of uint8_t {aka unsigned char}' to 'uint8_t [1] {aka unsigned char [1]} .

What are you attempting to do there? Are you trying to convert a textual representation of a number into an actual number, or place a bit of text into a uint8_t buffer?

So you are constructing a C++ String object from a C-String literal, then retrieve the C-String from it and try to parse a number from it (which it does not contain). Makes totalle sense to me....

@Majenko I am  trying to place a bit of text in a uint8_t buffer, because I am trying to send data over the LoRaWAN network. If I declare myData[] as myData[] = "Test data"; It send over the network without compiling errors. When I try to put a string into myData after going through setup and in my loop it doesn't seem to be able to add this as simply as myData = "Custom String";

What is "custom string".c_str() supposed to mean? In modern C++ you can do "custom string"s.c_str(), but only if you do using namespace std::string_literals; first.

atoi is for converting a textual representation of a number ("123" for example) into an actual integer.
The c_str() function gives you a pointer to the internal buffer of the String (assuming you actually have a String) which is no different to a uint8_t[] or uint8_t * (other than the signedness).
Without knowing exactly what the destination function for this buffer requires it's very hard to help you, but you may want something like:
LoRaWan.send((uint8_t *)myString.c_str(), myString.length());

If you need to copy the data into a fixed length buffer then you need to first create a buffer of that actual size - then copy the string data into it:
// Create a buffer of 32 bytes
uint8_t myBuffer[32];
// Copy at most 32 bytes, but no more than there actually is, into the buffer
memcpy(myBuffer, myString.c_str(), min(myString.length(), 32));

I used your method and deleted the atoi method. I understand the methods a lot more now. I also added a pointer to my declaration variable like uint8_t* myData[2];

That will actually create an array of two unassigned pointers, not a pointer to an array of 2 bytes.

@MounirMehjoub This might help: https://majenko.co.uk/blog/arrays-pointers-what-c

Your code is a mess. It's clear you are badly confused between arrays, pointers, and C++ strings.
When you say
uint8_t myData[] = "";

you make myData of type "array of uint8_t" and make it contain an empty string. You should not then change that value.
When you say
uint8_t *myData;

it means that myData is a variable of type "pointer to uint8_t", but it doesn't point to anything yet.
With that declaration, you can later say:
myData = "custom string";

That points the myData pointer to the address of your constant string. I think that's what you want:
// Declaration
uint8_t *myData;

void loop(){
    myData = "custom string";
}

Yeah, I'm sorry @Duncan C you are right. I'm not really experienced in C++ with pointers. So I tried your resolution but It gave again an error. cannot convert 'String' to 'uint8_t* {aka unsigned char*}' in assignment. What I'm trying to do is convert a custom string to uint8_t so I can send it over LoRaWAN. The method for sending LoRaWAN messages that I use had uint8_t as a parameter.

Re “You should not then change that value”: There is no problem changing that value. Just be aware that it's an array of length 1.

Firstly, arrays in C and C++ are not assignable. So, your attempts to assign something to myData array with = operator are bound to fail in any case. Copying data into naked arrays should be done either manually or using library functions.
Secondly, your myData array is declared with size 1. It is just one byte. It is too small to store anything useful. It will not magically "stretch" by itself to accommodate more data. If you need to store more data in that array, it is your responsibility to declare with the appropriate size in advance.
Thirdly, what is "custom string".c_str() supposed to mean??? Something looking very similar to that can be expressed in modern C++ as
#include <string>
...
using namespace std::string_literals;
"custom string"s.c_str();

but I see no reason for that at all. If your input is a C-string, then function atoi is directly applicable to C-strings. No need to convert such C-string to std::string and then back.
Fourthly, atoi is a "dead" function that exists for compatibility with legacy code only. You are not supposed to use atoi in your code. A C-style string-to-number conversion functions are functions from strto... group. E.g. strtol in your case. But in C++ you might have better options, like std::stoi and such.


text:
How many sensors can be used in arduino for my project?
I'm doing a project on water purity finder. I dont know which arduino board can be used for the project. It uses upto 15 sensor modules excluded display, WiFi module. Can you tell me which board is better for my project.

It depends on what kind of sensors you're using. If you use I2C based sensors, and you can configure each with a separate I2C address, you could theoretically drive up to 128 of them. I say theoretically since you might not be able to push the signal across an I2C bus with that many devices on it. You could certainly manage 15 of them however.
The Mega 2560 has tons of I/O lines, so that might be a good choice if you need separate single lines for each sensor.
If you need a separate analog input for each of your sensors, you'd need to use an Arduino with at least 15 separate analog inputs. The Arduino Mega 2560 has 16, so that would work.
If you need 4 bit binary inputs, you'd need 4*15 or 60 inputs. The Mega 2560 has 54 digital inputs, which would not be enough for that situation.
You might also be able to use some sort of signal multiplexer and enable one sensor at a time.
Tell us which type of sensor you're using and we can provide more concrete help.


text:
Making a timer accurate to 1 millisecond possible? Using MAX7219 LED
I'm using the Max7219 (8 digits, 7bits) led display to try and make a timer.  I have downloaded an example code from the following site to set the led digits:
https://www.brainy-bits.com/arduino-countdown-timer-using-the-max7219-display/
However the original code simply loops as fast as possible and decriment the timer so it is not a true time.  I tried to add a 10 ms delay to make it decriment 10ms on the right most digit so the 3rd digit to the right would be seconds, however I found this to be inaccurate and taking slightly longer than 1 second .
My question is is it possible to make a timer with 1ms accuracy using led display and if so how do I do it?
/* CountDown Timer version 2 using Max7219

Created by Yvan / https://Brainy-Bits.com
This code is in the public domain...
You can: copy it, use it, modify it, share it or just plain ignore it!
Thx!

*/

#define Max7219DIN 7  // Pin 7 connected to DIN (DataIN)
#define Max7219CLK 6  // Pin 6 connected to CLK
#define Max7219CS 5   // Pin 5 connected to CS

#define Buzzer 8  // Pin 8 connected to Buzzer +positive pin
int BuzzTrigger=0;  // Variable to store buzzer trigger value

#include "LedControl.h"  // LedControl Library created by Eberhard Fahle at http://playground.arduino.cc/Main/LedControl

LedControl lc=LedControl(Max7219DIN,Max7219CLK,Max7219CS,1);   // Last number represent the number of Max7219 Modules connected

long int countnumber=24001000 ; // Countdown timer start value HH:MM:SSSS

// Variables to store individual numbers
int  firstnum=0;
int  secondnum=0;
int  thirdnum=0;
int  fournum=0;
int  fivenum=0;
int  sixnum=0;
int  sevennum=0;
int  eightnum=0;

void setup() {
    lc.shutdown(0,false);  // Wake up the display
    lc.setIntensity(0,7); // Set Brightness 0-15
    lc.clearDisplay(0);  // Clear display
    pinMode(Buzzer, OUTPUT);
    digitalWrite(Buzzer, LOW);  //Buzzer Off at startup

}

void loop() {

    for (countnumber; countnumber != -1; countnumber--) {
        String mystring = String(countnumber); // Transform Counter Int to String for manipulation

        // Convert number to a time value
        for (int z = 0; z < 6; z++) {

            if (mystring.substring(z) == "999999") {
                countnumber = (countnumber - 400000);
            }

            if (mystring.substring(z) == "9999") {
                countnumber = (countnumber - 4000);
            }
        }

        //  Display number on Display depending on number of digits remaining
        if (countnumber > 9999999) {
            firstnum = ((countnumber / 10000000) % 10);
            secondnum = countnumber / 1000000 % 10;
            thirdnum = countnumber / 100000 % 10;
            fournum = countnumber / 10000 % 10;
            fivenum = countnumber / 1000 % 10;
            sixnum = countnumber / 100 % 10;
            sevennum = countnumber / 10 % 10;
            eightnum = countnumber % 10;

            lc.setDigit(0, 7, firstnum, false);
            lc.setDigit(0, 6, secondnum, false);
            lc.setDigit(0, 5, thirdnum, false);
            lc.setDigit(0, 4, fournum, false);
            lc.setDigit(0, 3, fivenum, false);
            lc.setDigit(0, 2, sixnum, false);
            lc.setDigit(0, 1, sevennum, false);
            lc.setDigit(0, 0, eightnum, false);
            delay(10); //<<<<<<<<<<< I ADDED THIS
        } else {
            if (countnumber > 999999) {
                //      firstnum = ((countnumber/10000000)%10);
                secondnum = countnumber / 1000000 % 10;
                thirdnum = countnumber / 100000 % 10;
                fournum = countnumber / 10000 % 10;
                fivenum = countnumber / 1000 % 10;
                sixnum = countnumber / 100 % 10;
                sevennum = countnumber / 10 % 10;
                eightnum = countnumber % 10;

                lc.setChar(0, 7, '-', false);
                lc.setDigit(0, 6, secondnum, false);
                lc.setDigit(0, 5, thirdnum, false);
                lc.setDigit(0, 4, fournum, false);
                lc.setDigit(0, 3, fivenum, false);
                lc.setDigit(0, 2, sixnum, false);
                lc.setDigit(0, 1, sevennum, false);
                lc.setDigit(0, 0, eightnum, false);
                delay(10); //<<<<<<<<<<< I ADDED THIS
            } else {
                if (countnumber > 99999) {
                    //          firstnum = ((countnumber/10000000)%10);
                    //          secondnum = countnumber/1000000%10;
                    thirdnum = countnumber / 100000 % 10;
                    fournum = countnumber / 10000 % 10;
                    fivenum = countnumber / 1000 % 10;
                    sixnum = countnumber / 100 % 10;
                    sevennum = countnumber / 10 % 10;
                    eightnum = countnumber % 10;

                    lc.setChar(0, 7, '-', false);
                    lc.setChar(0, 6, '-', false);
                    lc.setDigit(0, 5, thirdnum, false);
                    lc.setDigit(0, 4, fournum, false);
                    lc.setDigit(0, 3, fivenum, false);
                    lc.setDigit(0, 2, sixnum, false);
                    lc.setDigit(0, 1, sevennum, false);
                    lc.setDigit(0, 0, eightnum, false);
                    delay(10); //<<<<<<<<<<< I ADDED THIS
                } else {
                    if (countnumber > 9999) {
                        //             firstnum = ((countnumber/10000000)%10);
                        //             secondnum = countnumber/1000000%10;
                        //             thirdnum = countnumber/100000%10;
                        fournum = countnumber / 10000 % 10;
                        fivenum = countnumber / 1000 % 10;
                        sixnum = countnumber / 100 % 10;
                        sevennum = countnumber / 10 % 10;
                        eightnum = countnumber % 10;

                        lc.setChar(0, 7, '-', false);
                        lc.setChar(0, 6, '-', false);
                        lc.setChar(0, 5, '-', false);
                        lc.setDigit(0, 4, fournum, false);
                        lc.setDigit(0, 3, fivenum, false);
                        lc.setDigit(0, 2, sixnum, false);
                        lc.setDigit(0, 1, sevennum, false);
                        lc.setDigit(0, 0, eightnum, false);
                        delay(10);//<<<<<<<<<<< I ADDED THIS
                    } else {
                        if (countnumber > 999) {
                            //              firstnum = ((countnumber/10000000)%10);
                            //              secondnum = countnumber/1000000%10;
                            //              thirdnum = countnumber/100000%10;
                            //              fournum = countnumber/10000%10;
                            fivenum = countnumber / 1000 % 10;
                            sixnum = countnumber / 100 % 10;
                            sevennum = countnumber / 10 % 10;
                            eightnum = countnumber % 10;

                            lc.setChar(0, 7, '-', false);
                            lc.setChar(0, 6, '-', false);
                            lc.setChar(0, 5, '-', false);
                            lc.setChar(0, 4, '-', false);
                            lc.setDigit(0, 3, fivenum, false);
                            lc.setDigit(0, 2, sixnum, false);
                            lc.setDigit(0, 1, sevennum, false);
                            lc.setDigit(0, 0, eightnum, false);
                            delay(10);//<<<<<<<<<<< I ADDED THIS
                        } else {
                            //              firstnum = ((countnumber/10000000)%10);
                            //              secondnum = countnumber/1000000%10;
                            //              thirdnum = countnumber/100000%10;
                            //              fournum = countnumber/10000%10;
                            //              fivenum = countnumber/1000%10;
                            sixnum = countnumber / 100 % 10;
                            sevennum = countnumber / 10 % 10;
                            eightnum = countnumber % 10;
a
                            lc.setChar(0, 7, '-', false);
                            lc.setChar(0, 6, '-', false);
                            lc.setChar(0, 5, '-', false);
                            lc.setChar(0, 4, '-', false);
                            lc.setChar(0, 3, '-', false);
                            lc.setDigit(0, 2, sixnum, false);
                            lc.setDigit(0, 1, sevennum, false);
                            lc.setDigit(0, 0, eightnum, false);
                            delay(10);//<<<<<<<<<<< I ADDED THIS
                        }

                    }
                }
            }
        }

    }
}

new implementation using millis
#define Max7219DIN 7  // Pin 7 connected to DIN (DataIN)
#define Max7219CLK 6  // Pin 6 connected to CLK
#define Max7219CS 5   // Pin 5 connected to CS

#include "LedControl.h"  // LedControl Library created by Eberhard Fahle at http://playground.arduino.cc/Main/LedControl

LedControl lc=LedControl(Max7219DIN,Max7219CLK,Max7219CS,1);   // Last number represent the number of Max7219 Modules connected

unsigned long countnumber;

// Variables to store individual numbers
int  firstnum=0;
int  secondnum=0;
int  thirdnum=0;
int  fournum=0;
int  fivenum=0;
int  sixnum=0;
int  sevennum=0;
int  eightnum=0;

void setup() {
  lc.shutdown(0,false);  // Wake up the display
  lc.setIntensity(0,7); // Set Brightness 0-15
  lc.clearDisplay(0);  // Clear display
  Serial.begin(9600);
}

void loop() {

  countnumber = millis();

  firstnum = countnumber / 10000000 % 10;
  secondnum = countnumber / 1000000 % 10;
  thirdnum = countnumber / 100000 % 10;
  fournum = countnumber / 10000 % 10;
  fivenum = countnumber / 1000 % 10;
  sixnum = countnumber / 100 % 10;
  sevennum = countnumber / 10 % 10;
  eightnum = countnumber % 10;

  lc.setDigit(0, 7, firstnum, false);
  lc.setDigit(0, 6, secondnum, false);
  lc.setDigit(0, 5, thirdnum, false);
  lc.setDigit(0, 4, fournum, false);
  lc.setDigit(0, 3, fivenum, false);
  lc.setDigit(0, 2, sixnum, false);
  lc.setDigit(0, 1, sevennum, false);
  lc.setDigit(0, 0, eightnum, false);

}

You code also takes some time to execute. So your loop takes 10ms, plus the time the code takes. To make it 10ms independent of the amount of code, you store the value of millis() at the beginning of the loop, and them at the end of the loop, wait till the difference between millis() and the stored millis value is greater that, or equal to 10.

Requiring “1 ms accuracy” doesn't make any sense if you don't specify over what time span you want that accuracy. Getting 1 ms accuracy is trivial if you are measuring a 100 ms time interval. It is far from trivial if you are measuring a 1 year interval. The accuracy you can get on an Arduino out of the box depends on the measured interval, on whether your Arduino has a crystal or a resonator, and on whether you are willing to calibrate it. Please read http://jorisvr.nl/article/arduino-frequency to get a general idea on what “accuracy” can mean in respect to Arduino timing.

@EdgarBonet what about over 5min trivial or no?

1 ms ÷ 5 min = 3.33 ppm. Not trivial but doable. You won't get that accuracy out of the Arduino's internal clock unless it is a crystal and you calibrate it against a reliable reference. Easiest solution would probably be using a high accuracy RTC, like the DS3231, which integrates a temperature-compensated crystal oscillator (TCXO). The ubiquitous DS1307 will likely not be accurate enough. Use either the 32kHz or the SQW output and one of your MCU's counters. Please, tag your question with the type of Arduino you are using.

You generally cannot rely on a processor for correct time keeping without a real time clock somewhere in your circuit.  However, the best way of doing things at certain times, is to call millis() which will return the number of milliseconds since the program started.  With that number you can determine how long something has taken (eg. 1 second) and then do something in response.  You can, for example, print out how long your loop is taking by setting a long integer to millis() at the start of the sketch and then subtracting it from mills() at the end of the loop and printing out the result.
void loop() {
   long start_time = millis();
   delay(500);
   long end_time = mills();
   Serial.println(end_time - start_time);
}

What do you rekon is the accuracy without real time clock? within 20ms?

From this article I understand that millis is incremented each 1.024ms, but if the error approaches 1ms then value is automatically corrected. Therefore in span of 20 ms error could accumulate to be close to half of a millisecond.

@bakalolo Try micros()?


text:
Cannot connect with online arduino editor but I can with Arduino IDE to an Arduino Nano
As the title says I have a Nano with CH340G and 168 that connects properly to Arduino IDE but not to Arduino online editor, it does not detect the board "Error uploading, check if the board is available"
What can I do?
EDIT: The IDE online I am using is https://create.arduino.cc/ I am using the same computer and exactly the same board model in both IDEs (both of them have the same options available so both of them should be in the same version)
EDIT 2: I can connect correctly from the online IDE to an Arduino UNO. The problem is just with the Nano.

Which exact online editor? I know several.

Does the browser run on the same computer as the IDE? Did you select the right board in the Online Editor? Nano comes with a new and an old version of it's firmware. Did you select the same firmware in the IDE and the Online Editor? Have you configured your browser to not connect to external periphery like COM ports?

@FilipFranik:  added information requested

@PeterPaulKiefer:  added information requested


text:
Arduino input to Visual Studio
I am completely new to programming, and I need some pointers where to look for a possible solution.
Currently I have been trying to get input from my Arduino buttons to Visual Studio to then do something with the input specifically.
There are three buttons setup and I want to use the input of these to control the answering for a quiz game in Visual Studio. Only one button can be pressed, then it will show a messagebox and advances to the next question. At the moment im having a hard time figuring out how to do this. Any pointers where to look is greatly appreciated.

Can you read a serial port from Visual Studio?

Yes, I have tried the excercise to control a LED using the form in Visual studio before. When I want to control physical buttons from Arduino to Visual Studio, then im not sure how to send the data over. I know that you can use portname.Readline(); so I can send strings over, but it takes everything thats printed in Serial Monitor?

When you connect an Arduino to a Windows computer it adds a COM port to the devices. You still use this COM-port from your serial terminal. If you detach it from the serial terminal and write a program that opens the COM-port for reading, then you can send e.g. text messages from the Arduino to the PC (your program). I don't know what programming language you use (C#?). So I can not give you a hint how to open the port and read from it.

If you are able to send texts to the PC, you can read this text in your program and interpret them. Of cause you must define a protocol, i.e. specify which text you send when a button is pressed and which text you send when the button is released and of cause which of the three button are pressed or released. e.g. "pA" if button 1 is pressed and "rB" if button 2 is released.

Thanks for taking the time to help me! I am using C#. I already have setup the com port / baud / and put the portname.Open() in. I dont know if its possible or how you can make it see the difference between strings that are going through Serial Monitor. It just react to everything when using Readline in Visual Studio.
Was thinking maybe assigning a "char" or "byte" to use for this, but I am not sure about it.

I managed to get button input into Visual Studio. It sends "A", "B" or "C" over the serial communication, that the C# program then picks up. However I want it to print only once, because with one press it prints multiple characters into serial monitor, so the messagebox that I want to show comes up multiple times.

Can you show us the sketch you're using?


text:
Multiple Interrupt Pins Generates Wrong Pulses
On MKR WAN 1300 board I added pulldown resistors to 0,1,4,5,6,7,8 pins to count pulses.I can catch interrupts, but sometimes pulses occur on other pins even though they are not touched. For example, button pulses are generating on pin 2 but shows pins 3 is also triggered , it shows like
pin 2=1
pin 2=2
pin 2=3
pin 2=4
pin 2=5
pin 2=6
pin 3=1
pin 2=7
What can be the reason ? How can I solve it ?
#include <MKRWAN.h>

#define debugSerial Serial
#define loraSerial Serial1

int DEBUG = 0;

/* Pins of External Interrupts */
const byte WATER_METER_1 = 0;
const byte WATER_METER_2 = 1;
const byte WATER_METER_3 = 4;
const byte WATER_METER_4 = 5;
const byte WATER_METER_5 = 6;
const byte WATER_METER_6 = 7;
const byte WATER_METER_7 = 8;

volatile int watMeterPulseArray[7] = {0, 0, 0, 0, 0, 0, 0};

unsigned long pulseTime[7] = {0, 0, 0, 0, 0, 0, 0};
unsigned long lastTime[7] = {0, 0, 0, 0, 0, 0, 0};
const long interval = 2000;// interval for next pulse

int  watMeterPulseArraySize = sizeof watMeterPulseArray / sizeof watMeterPulseArray[0];

void checkAndVerifyPulse(int pin) {
  pulseTime[pin] = millis();
  if (pulseTime[pin] - lastTime[pin] > interval ) {
    lastTime[pin] = pulseTime[pin];
    watMeterPulseArray[pin] ++;
    printlnToScreen("pin " + String(pin) + "=" + String(watMeterPulseArray[pin]));
  }
}
void incrementWatMeter1() {
  checkAndVerifyPulse(0);
}
void incrementWatMeter2() {
  checkAndVerifyPulse(1);
}
void incrementWatMeter3() {
  checkAndVerifyPulse(2);
}
void incrementWatMeter4() {
  checkAndVerifyPulse(3);
}
void incrementWatMeter5() {
  checkAndVerifyPulse(4);
}

void incrementWatMeter6() {
  checkAndVerifyPulse(5);
}

void incrementWatMeter7() {
  checkAndVerifyPulse(6);
}

void setup() {
  debugSerial.begin(115200);
  // If debugSerial is available(device connected to PC) set debug
  while (!debugSerial && millis() < 10000) ;
  if (millis() < 10000) {
    DEBUG = 1;
  }

  delay(100);

  pinMode(WATER_METER_1, INPUT_PULLDOWN);
  pinMode(WATER_METER_2, INPUT_PULLDOWN);
  pinMode(WATER_METER_3, INPUT_PULLDOWN);
  pinMode(WATER_METER_4, INPUT_PULLDOWN);
  pinMode(WATER_METER_5, INPUT_PULLDOWN);
  pinMode(WATER_METER_6, INPUT_PULLDOWN);
  pinMode(WATER_METER_7, INPUT_PULLDOWN);

  attachInterrupt(digitalPinToInterrupt(WATER_METER_1), incrementWatMeter1, RISING);
  attachInterrupt(digitalPinToInterrupt(WATER_METER_2), incrementWatMeter2, RISING);
  attachInterrupt(digitalPinToInterrupt(WATER_METER_3), incrementWatMeter3, RISING);
  attachInterrupt(digitalPinToInterrupt(WATER_METER_4), incrementWatMeter4, RISING);
  attachInterrupt(digitalPinToInterrupt(WATER_METER_5), incrementWatMeter5, RISING);
  attachInterrupt(digitalPinToInterrupt(WATER_METER_6), incrementWatMeter6, RISING);
  attachInterrupt(digitalPinToInterrupt(WATER_METER_7), incrementWatMeter7, RISING);

  delay(100);
}

void loop() {

}

// If Serial port is available on PC, print message to screen
void printToScreen (String message) {
  if (DEBUG) {
    debugSerial.print(message);
  }
}
void printlnToScreen (String message) {
  if (DEBUG) {
    debugSerial.println(message);
  }
}```

What is the value of the pull down resistor used?

I used 10k Ohm for pull down resistor


text:
Is if statement correct?
if(temperature < baselineTemp)else{
  digitalWrite(2, LOW);
  digitalWrite(3, LOW);
  digitalWrite(4, LOW);
}else if(temperature >= baselineTemp+2 && temperature < baselineTemp+4){
  digitalWrite(2, HIGH)
  digitalWrite(3, LOW)
  digitalWrite(4, LOW)
}else if(temperature >= baselineTemp+4 && temperature < baselineTemp+6){
  digitalWrite(2, HIGH)
  digitalWrite(3, HIGH)
  digitalWrite(4, LOW)
}else if(temperature >= baselineTemp+6){
  digitalWrite(2, HIGH)
  digitalWrite(3, HIGH)
  digitalWrite(4, HIGH)

No, the first lines should be:
if(temperature < baselineTemp) {
  digitalWrite(2, LOW);

Thus the else should be removed; after the first if and later else or else if conditions, statements can be placed.
Next time align your code by selecting it and select ctrl-K.
Also, your code can be much more simplified.
Hence the following (reverse engineered) requirements:

pin 2 is HIGH when temperature >= baselineTemp + 2, else LOW
pin 3 is HIGH when temperature >= baselineTemp + 4, else LOW
pin 4 is HIGH when temperature >= baselineTemp + 4, else LOW

So your entire code can be written as:
digitalWrite(2, temperature >= baselineTemp + 2 ? HIGH : LOW);
digitalWrite(3, temperature >= baselineTemp + 4 ? HIGH : LOW);
digitalWrite(4, temperature >= baselineTemp + 6 ? HIGH : LOW);


text:
Is analogWrite() not affected by blocking codes and/or Interrupts?
Well just as the question say, is the analogWrite() function will continue generating near-consistent PWM when it encounters blocking codes or signal interrupts?
Is it the same case for both the classic arduinos(atmega chips) and the new arduinos(SAMD21 chips).
If analogWrite() does get affected by blocking codes, is there a way to create a uninterruptible PWM signal?

is the analogWrite() function
  continue generating near-consistent PWM when it encounters blocking
  codes or signal interrupts?

Yes for 'hardware' PWM used by analogWrite on AVR and SAMD Arduinos. The hardware PWM is handled by wave output of Timers, which are MCU peripherals running independently from CPU and other MCU peripherals.

Is it the same case for both the classic arduinos(atmega chips) and
  the new arduinos(SAMD21 chips).

yes

If analogWrite() does get affected by blocking codes, is there a way
  to create a uninterruptible PWM signal?

N/A


text:
Setting a number inside a struct causes timer to misbehave
The following code:
struct l{
    uint8_t pin;
    uint8_t sensePin;
    float brightnessTarget;
    uint8_t PWMvalue;
    uint8_t inc;
};
typedef struct l led;

led* redLed;
led* whiteLed;
unsigned long secondsOfDay = 79140;
unsigned long minutesOfDay = 0;
unsigned int hoursOfDay = 0;
uint8_t interrupted=0;
uint8_t runPID;
int pin13=0;

void setup() {
  cli();
  TCCR1A = 0;// set entire TCCR1A register to 0
  TCCR1B = 0;// same for TCCR1B
  TCNT1  = 0;//initialize counter value to 0
  // set compare match register for 1hz increments
  OCR1A = OCR1A_val;// = (16*10^6) / (1*1024) - 1 (must be <65536)
  // turn on CTC mode
  TCCR1B |= (1 << WGM12);
  // Set CS10 and CS12 bits for 1024 prescaler
  TCCR1B |= (1 << CS12) | (1 << CS10);
  // enable timer compare interrupt
  TIMSK1 |= (1 << OCIE1A);
  pinMode(13,OUTPUT);
  pinMode(3, OUTPUT);
  pinMode(4, OUTPUT);
  sei();
}

void loop() {
  if (runPID){
    PIControl(redLed);
    PIControl(whiteLed);
    pin13 = (~pin13 & 1);
    digitalWrite(13, pin13);
    runPID=0;
  }
}

SIGNAL(TIMER1_COMPA_vect){ //1 second timer fire
  runPID = 1;
}

Toggles a pin. However, if I add:
redLed->pin = 3;
whiteLed->pin = 4;
redLed->sensePin = 0;
whiteLed->sensePin = 1;

In the setup anywhere (before cli(), after sei(), or within the block), the interrupt no longer toggles.
I'm absolutely baffled, and I have no idea what's going on.
Edit: everything but whiteLed->sensePin is fine. That line is what is causing the issue (and I still don't understand)

This:
led* redLed;

defines a global variable implicitly initialized to zero (i.e. a NULL
pointer). This is an invalid pointer you are not allowed to use until
you properly initialize it.
Here:
redLed->pin = 3;

you are writing to the memory pointed to by this invalid pointer. This
invokes what the C and C++ standards call undefined behavior. What
that means is that, according to the definition of the C++ language, the
behavior of your program is not defined. In other words, anything can
happen. Typically you get a program crash, but even that behavior is not
guaranteed.
Do not ever access memory through an invalid pointer.

Ugh. I knew it was a dumb oversight. Thank you!


text:
Can't use Arduino nano as ISP because it can't read the Device signature
I programmed the 8mhz internal oscillator Bootloader to a new Arduino Nano with another Arduino nano running the ISP Sketch, wich worked fine the first time(Arduino as ISP selected as programmer).
(I wanted to test it befor i want to burn this Bootloader on an Empty 328p-au uC.)
But now since I received the 328p-au uC's i tried the same thing, to burn the Bootloader to the epty uC's but somehow it can't read the device signature, neither from a fresh arduino Nano or another avr(At least that is what avrdude said). I wired everything exectly like it was written in the ISP Sketch.
Here is one of the error messages i received when I was trining to Burn the standard 16mhz Bootloader:
     Programmer Type : STK500
     Description     : Atmel STK500 Version 1.x firmware
     Hardware Version: 2
     Firmware Version: 1.18
     Topcard         : Unknown
     Vtarget         : 0.0 V
     Varef           : 0.0 V
     Oscillator      : Off
     SCK period      : 0.1 us

     Fehler beim Brennen des Bootloaders.
     avrdude: AVR device initialized and ready to accept instructions

     Reading | ################################################## | 100%          0.02s

     avrdude: Device signature = 0xff0000
     avrdude: Expected signature for ATmega328P is 1E 95 0F
     Double check chip, or use -F to override this check.

     avrdude done.  Thank you.

So what am I doing wrong?
(Using -F is what I tried but it didn't work, except the first time I programmed the 8Mhz Int. Oscillator Bootloader)
What stand out to me is that there was nothing happening on the MISO line. Here is a screenshot from my Logic Aalyzer software: ibb.co/hWXrpp7
And here is an Image of my setup(the right Arduino is the programmer and the left one has the empty uC soldered onto it): https://ibb.co/zXQFmwR
I am relative new to Arduino, so I hope some of you can help me with that.

do you have "Arduino as ISP" programmer selected?

Yes I did... Same error message.

so do you use other Arduino with "Arduino as ISP" sketch or not? because then there are no other programmer options for "same error". show in Question the output with the right programmer selected

Yes I use the "Arduino as ISP" Sketch and have " Arduino as ISP" Programmer selected. "Same error message" I just tried to programm by using avrdude directly to implement the idea of the other guy who answered but it didn't help.

do you have a capacitor on programmer Arduino to prevent the reset at new USB connection?

A new AVR chip from the manufacturer has some (so called) fusebits set. These prevent the MCU from being programmed or read out. This might be an explanation why you can not read out the signature. But the programmer should set these bits if you use it to upload a bootloader.  Here is a link from a guy that was unhappy with the documentation he found in the internet. He wrote his own
Howto: https://makersportal.com/blog/2018/3/15/arduino-internet-of-things-part-1-burning-the-arduino-bootloader-onto-a-blank-atmega328p-chip-using-the-arduino-uno

As @Jurai mentioned you need a ~ 100µF capacitor between the Reset Pin and the Ground of the programmer arduino. This is essential. I do not see this in the schematics of the link I pointed you to. So for newer UNOs or Nanos this might be integrated on the board. Ahh ... And I forgot: You wrote "internal oscillator". If the chip is new this oscillator might be  switched off, so you eventually need a external quartz to succeed. But that is just a guess.

Thank you, i had a 6.8u Capacitor between reset and ground but with a 100uf capacitor it still doesn't work. Since i soldered the emty uC on to the Nano board there is still the original 16mhz quarz. Here is an Image of my setup. The left one is the programmer and the right one the Arduino with the empty uC https://ibb.co/zXQFmwR

It seems that you are using too high programming speed. SCK period al of 0.1 us renders 10 MHz, which is to fast if crystal is working at 8 MHz. Not sure where to change it in Arduino environment, but you should add this key to avrdude.exe run string:
avrdude.exe -B 8
This will set programming speed to 125 kHz. Also I suggest you to buy a cheap USBasp programmer from eBay or AliExpress. It is well documented and have plenty GUI programs, running on top of the avrdude. In newest Arduino IDE you can generate hex files in the sketch directory, and burn it with programmer.

Thanks, but I tried this and it didn't work. It was awfully slow but I was getting the same error message(this time I was using avrdudess, gui for avrdude). Well I bought such a  cheap chinese USB ISP wich doesnt work, so i was trying to reprogramm the uC on this Programmer by following a tutorial. But as I said, I can't proramm using the Arduino nano anymore.

Oh and I monitord the SPI signals using a Logic Analyzer, so it seems like the Clock is running with 125khz, but as you may or may not see is that Nothing ever happens on the MISO line....

https://ibb.co/hWXrpp7

@LukasKamina You should edit your question to include that information.  All the relevant information should be included in your question.


text:
Autonomous Firetruck
I have a problem. I am making an autonomous (obstacle avoiding) firefighting firetruck. I already have a code however it only stops when it detects fire and when the ultrasonic reaches less than 15cm, the flame sensor automatically detects fire even there is no fire near the sensor. I get my code form different tutorials.
Here it is:
#include <Servo.h>
#include "Ultrasonic.h"

//Constants
const int button = 2;
const int led    = 3;
const int pump = 4;
const int motorA1= 6;
const int motorA2= 9;
const int motorB1=10;
const int motorB2=11;
const int flame=12;
const int buzzer=12;

Ultrasonic ultrasonic(A4 ,A5);
Servo myservo;

//Variables
int distance;
int checkRight;
int checkLeft;
int function=0;
int buttonState=0;
int pos=90;
int flag=0;
int flame_detected;

void setup()
{
 Serial.begin(9600);
   myservo.attach(5);
   myservo.write(pos);
 pinMode(button, INPUT_PULLUP);
 pinMode(led,  OUTPUT);
 pinMode(buzzer, OUTPUT);
 pinMode(motorA1,OUTPUT);
 pinMode(motorA2,OUTPUT);
 pinMode(motorB1,OUTPUT);
 pinMode(motorB2,OUTPUT);
 pinMode(flame,INPUT);
 pinMode(pump,OUTPUT);

}

void loop()
{
 flame_detected = digitalRead(flame);
 if (flame_detected == true)
 {
   Serial.println("No flame detected. stay cool");
 //Check button state
 buttonState = digitalRead(button);
 unsigned long currentMillis = millis();

   if (buttonState == LOW) {
     delay(500);
     if ( flag == 0){
         function = 1;
         flag=1;
     }
     else if ( flag == 1){
       function = 0;
       flag=0;
     }
   }

 if (function == 0){
   myservo.write(90);
   stop();
   noTone(buzzer);
   digitalWrite(led, HIGH);

 }
 else if (function == 1){
   //Read distance...
   distance = ultrasonic.Ranging(CM);

   if (distance > 15){
     forward();
     noTone(buzzer);
     digitalWrite(led,LOW);
   }
   else if (distance <=15){
     stop();
     tone(buzzer,500);
     digitalWrite(led,HIGH);

     for(pos = 0; pos < 180; pos += 1){
               myservo.write(pos);
               delay(10);
           }

           checkLeft = ultrasonic.Ranging(CM);

           for(pos = 180; pos>=0; pos-=1){
               myservo.write(pos);
               delay(10);
           }

           checkRight= ultrasonic.Ranging(CM);

           myservo.write(90);

           if (checkLeft < checkRight){
             left();
             delay(400);
             }
           else if (checkLeft > checkRight){
             right();
             delay(400);
           }
           else if (checkLeft <=10 && checkRight <=10){
             backward();
             left();
           }
   }
 }

}

else {
 put_off_fire();
 Serial.println("Flame detected...! take action immediately.");
}
delay(500);
}
void forward(){
 digitalWrite(motorA1, HIGH);
 digitalWrite(motorA2, LOW);
 digitalWrite(motorB1, HIGH);
 digitalWrite(motorB2, LOW);
}

void backward(){
 digitalWrite(motorA1, LOW);
 digitalWrite(motorA2, HIGH);
 digitalWrite(motorB1, LOW);
 digitalWrite(motorB2, HIGH);
}

void left(){
 digitalWrite(motorA1, HIGH);
 digitalWrite(motorA2, LOW);
 digitalWrite(motorB1, LOW);
 digitalWrite(motorB2, HIGH);
}

void right(){
 digitalWrite(motorA1, LOW);
 digitalWrite(motorA2, HIGH);
 digitalWrite(motorB1, HIGH);
 digitalWrite(motorB2, LOW);
}

void stop(){
 digitalWrite(motorA1, LOW);
 digitalWrite(motorA2, LOW);
 digitalWrite(motorB1, LOW);
 digitalWrite(motorB2, LOW);
}

void put_off_fire()
{
 {
   delay (500);

   digitalWrite(motorA1, HIGH);
   digitalWrite(motorA2, HIGH);
   digitalWrite(motorB1, HIGH);
   digitalWrite(motorB2, HIGH);

  digitalWrite(pump, HIGH);
  delay(500);
 }
 digitalWrite(pump,LOW);
 flame_detected=false;
}

I really need help. Thanks

What flame sensor are you using?

You need to provide a lot of information about your sketch if you expect us to help with it. What hardware are you using? Where can we read about it? You need to document the various sections of your code, what they're supposed to do, and explain the parts that aren't operating as you expect them to.

Sorry, I forget about that. I am using  Arduino Uno, Hl-01 flame sensor, HC-SR04  ultrasonic sensor, 2wd robot, servo  motor(allows ultrasonic and flame sensor to check side and front of the robot), button and l298n

I mostly rely on this tutorial https://www.ardumotive.com/obstacle-avoiding-robot.html for the obstacle avoiding code then I just added some code from other tutorials regarding with the fire/flame detection and fire fighting robot which I found on the Arduino project hub

I could not find a datasheet for that flame sensor. Can you link to one from? Maybe from your reseller?

it's just the regular Arduino flame sensor.
Here is the link:
https://www.google.com/search?q=flame+sensor+arduino&rlz=1C1GGRV_enPH814PH814&sxsrf=ACYBGNQ-JVW0XcDRF5gfvQhRRck1SMeS2w:1572793423083&source=lnms&tbm=isch&sa=X&ved=0ahUKEwil0KaKqM7lAhWR62EKHQHWDO0Q_AUIEigB&biw=1536&bih=722#imgrc=SX9yx_muZQ-mGM:


text:
HC-05 can not use lower pins only 8 and higher
#include <Arduino.h>
#include <SoftwareSerial.h>

char Incoming_value = 0;

// SoftwareSerial BTSerial( 10, 11 ); // RX | TX +
// SoftwareSerial BTSerial( 9, 10 ); // RX | TX +
// SoftwareSerial BTSerial( 8, 9 ); // RX | TX +
// SoftwareSerial BTSerial( 7, 8 ); // RX | TX - ???
// SoftwareSerial BTSerial( 6, 7 ); // RX | TX - ???
// SoftwareSerial BTSerial( 5, 6 ); // RX | TX - ???
// SoftwareSerial BTSerial( 4, 5 ); // RX | TX - ???
// SoftwareSerial BTSerial( 3, 4 ); // RX | TX - ???

SoftwareSerial BTSerial( 8, 9 ); // RX | TX +

void setup() {
        BTSerial.begin( 9600 );
        pinMode( 13, OUTPUT);
}

void loop() {
        delay( 1000 );
        BTSerial.println( "hello" );
        if( BTSerial.available() > 0 ) {
                BTSerial.println( "BINGO!" );
                Incoming_value = BTSerial.read();
                BTSerial.println( Incoming_value );
                if ( Incoming_value == '1' ) digitalWrite( 13, HIGH );
                else if ( Incoming_value == '0' ) digitalWrite( 13, LOW );
        }
}

My HC-05 Bluetooth module wont't work on lowers digital pins.

BOARD_TAG = leonardo

It works fine on highers digital pins: 8-9, 9-10 or 10-11 - everything fine.
but 2-3, 3-4, 4-5, 5-6, 6-7 or 7-8 - no....

Why? Should I inject jumper somewhere or what?
And yes: @Majenko, "0,1 - is required to debug from host". I want to have Serial from PC and BTSerial from bluetooth - to have both accesses to device simultaneously.
@Peter_Paul_Kiefer, so, you think, this is impossible with lowest pins, lower than 8?

Why are you using SoftwareSerial on a Leonardo? Just use Serial0 and pins 0/1.

From the official SoftwareSerial Site: https://www.arduino.cc/en/Reference/softwareSerial (Section Limitations)

Not all pins on the Leonardo and Micro support change interrupts, so
  only the following can be used for RX: 8, 9, 10, 11, 14 (MISO), 15
  (SCK), 16 (MOSI).


text:
Arduino Uno R3 and ESP8266(ESP-01) serial connection
I have done everything i found but just nothing works, or maybe i just dont understand why it wont work. Im only trying to pass data(String) from Arduino to Esp through serial comms. Please I need your help, I'm as dead as my deadlines.
Note: What I am trying to do is send data from arduino to esp and make esp send the data on a raspberry pi server through sockets. The rasp part is fine, i just need the data passed from arduino to esp.
Original Arduino code
volatile int flow_frequency; // Measures flow sensor pulses
unsigned int l_hour; // Calculated litres/hour
unsigned char flowsensor = 2; // Sensor Input
unsigned long currentTime;
unsigned long cloopTime;
void flow () // Interrupt function
{
   flow_frequency++;
}
void setup()
{
   pinMode(flowsensor, INPUT);
   digitalWrite(flowsensor, HIGH); // Optional Internal Pull-Up
   Serial.begin(9600);
   attachInterrupt(0, flow, RISING); // Setup Interrupt
   sei(); // Enable interrupts
   currentTime = millis();
   cloopTime = currentTime;
}
void loop ()
{
   currentTime = millis();
   // Every second, calculate and print litres/hour
   if(currentTime >= (cloopTime + 1000))
   {
      cloopTime = currentTime; // Updates cloopTime
      // Pulse frequency (Hz) = 7.5Q, Q is flow rate in L/min.
      l_hour = (flow_frequency * 60 / 7.5); // (Pulse frequency x 60 min) / 7.5Q = flowrate in L/hour
      flow_frequency = 0; // Reset Counter
      Serial.print(l_hour, DEC); // Print litres/hour
      Serial.println(" L/hour");
   }
}

ESP
#include <ESP8266WiFi.h>
#include <SoftwareSerial.h>

SoftwareSerial  ESPlease(3,1);

const char* ssid  = "sendhelp";
const char* password =  "ple4seH3lpm3";

uint16_t port = 8090;
const char* host = "192.168.1.3";

void setup()
{

  Serial.begin(9600);
  ESPlease.begin(9600);
  pinMode(3,INPUT);
  pinMode(1,OUTPUT);

  WiFi.begin(ssid, password);
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.println("...");
  }

  Serial.print("WiFi connected with IP: ");
  Serial.println(WiFi.localIP());

}

void loop()
{
    WiFiClient client;

    if (!client.connect(host, port)) {

        Serial.println("Connection to host failed");

        delay(1000);
        return;
    }
    String message = "";

    Serial.println("Connected to server successful!");
    while(Serial.available()) {
      message = Serial.readString();
     // messageReady = true;
    }
    String sensorValue = message;
    String sname = "flowRate-";
    String stringThree = sname + sensorValue;

    if(sensorValue != 0){
      client.print(stringThree);
    }

    Serial.println("Disconnecting...");
    client.stop();

    delay(10000);
}

please help me anyone :(

SoftwareSerial on hardware Serial pins? pin mode of RX/TX changed after Serial.begin()? where do you output data in Uno? I see only a simple print to Serial

that's it, i dont know where i output code anymore. some say all i had to do was print it to serial. I know the code is full of useless stuff its because I have tried so many times already

but the useless code is in the way. clean it up


text:
ESP32 + Fastled + WS2801
I'm using the ESP32 DevkitC board with Fastlib and a WS2801 LED strip.
The LED strips works fine, i connected it properly (sometimes all LEDs are on, no flickering).
I Connected the light strip's Data cable (blue) to GPIO16 and Clock cable (red) to GPIO17.
Compiling works but at first shows this error:
"No hardware SPI pins defined.  All SPI access will default to bitbanged output"

When the script starts, only the first 3 LEDs are glowing in light blue (instead of blinking) - here's my code:
#include <FastLED.h>

// How many leds in your strip?
#define NUM_LEDS 42

// For led chips like Neopixels, which have a data line, ground, and power, you just
// need to define DATA_PIN.  For led chipsets that are SPI based (four wires - data, clock,
// ground, and power), like the LPD8806 define both DATA_PIN and CLOCK_PIN
#define DATA_PIN 16
#define CLOCK_PIN 17

// Define the array of leds
CRGB leds[NUM_LEDS];

void setup() {
      // Uncomment/edit one of the following lines for your leds arrangement.
      // FastLED.addLeds<TM1803, DATA_PIN, RGB>(leds, NUM_LEDS);
      // FastLED.addLeds<TM1804, DATA_PIN, RGB>(leds, NUM_LEDS);
      // FastLED.addLeds<TM1809, DATA_PIN, RGB>(leds, NUM_LEDS);
      // FastLED.addLeds<WS2811, DATA_PIN, RGB>(leds, NUM_LEDS);
      // FastLED.addLeds<WS2812, DATA_PIN, RGB>(leds, NUM_LEDS);
      // FastLED.addLeds<WS2812B, DATA_PIN, RGB>(leds, NUM_LEDS);
      // FastLED.addLeds<NEOPIXEL, DATA_PIN>(leds, NUM_LEDS);
      // FastLED.addLeds<APA104, DATA_PIN, RGB>(leds, NUM_LEDS);
      // FastLED.addLeds<UCS1903, DATA_PIN, RGB>(leds, NUM_LEDS);
      // FastLED.addLeds<UCS1903B, DATA_PIN, RGB>(leds, NUM_LEDS);
      // FastLED.addLeds<GW6205, DATA_PIN, RGB>(leds, NUM_LEDS);
      // FastLED.addLeds<GW6205_400, DATA_PIN, RGB>(leds, NUM_LEDS);

      // FastLED.addLeds<WS2801, RGB>(leds, NUM_LEDS);
      // FastLED.addLeds<SM16716, RGB>(leds, NUM_LEDS);
      // FastLED.addLeds<LPD8806, RGB>(leds, NUM_LEDS);
      // FastLED.addLeds<P9813, RGB>(leds, NUM_LEDS);
      // FastLED.addLeds<APA102, RGB>(leds, NUM_LEDS);
      // FastLED.addLeds<DOTSTAR, RGB>(leds, NUM_LEDS);

       FastLED.addLeds<WS2801, DATA_PIN, CLOCK_PIN, RGB>(leds, NUM_LEDS);
      // FastLED.addLeds<SM16716, DATA_PIN, CLOCK_PIN, RGB>(leds, NUM_LEDS);
      // FastLED.addLeds<LPD8806, DATA_PIN, CLOCK_PIN, RGB>(leds, NUM_LEDS);
      // FastLED.addLeds<P9813, DATA_PIN, CLOCK_PIN, RGB>(leds, NUM_LEDS);
      // FastLED.addLeds<APA102, DATA_PIN, CLOCK_PIN, RGB>(leds, NUM_LEDS);
      // FastLED.addLeds<DOTSTAR, DATA_PIN, CLOCK_PIN, RGB>(leds, NUM_LEDS);
}

void loop() {
  // Turn the LED on, then pause
  leds[0] = CRGB::Red;
  FastLED.show();
  delay(500);
  // Now turn the LED off, then pause
  leds[0] = CRGB::Black;
  FastLED.show();
  delay(500);
}

Any ideas what's wrong?

This is hard to debug from afar...
Your sketch looks correct (hardly surprising, since it's just the Blink example). But I'd try to use IO18/SPI_CLK for clock and IO23/SPI_MOSI for data, as these are the hardware SPI pins of the ESP32. It might very well be that using these pins removes the warning about hardware SPI.
As I don't know all the variants of a WS2801 strip... is it maybe one of those strips that runs at 12V and can only be cut every three LEDs? This would explain why there are three LEDs lighting up instead of one (because then there would be one chip for three LEDs -- in other words, each "pixel" in your leds array corresponds to three physical LEDs)
Then there might be a problem with the voltage output of your ESP32 board. The ESP is running at Vcc=3.3V. The chips of the strip are running at Vcc=5V and expect 5V on their inputs. A logical 1 is assumed when the input in question is 0.7 * Vcc, i.e. the input signal may not be less than 3.3V. Now imagine that the power regulator on your ESP board drives the ESP at a teensy bit less (e.g. at 3.25V) and the power supply for the strip outputs a teensy bit more (e.g. 5.1V) -- suddenly, a logical 1 from the ESP is at 0.637 times the strips' Vcc and therefore in the undefined limbo between 0.3*Vcc (highest definition for logical 0) and 0.7*Vcc (lowest definition for logical 1). A level shifter module would help here to increase the ESP's output signal voltage (costs a few cents when ordered directly from China).
Then, at last, are you sure that the color order of the strip is RGB (as stated in your setup line)? I've seen more strips using GRB or BGR... which would explain why you see blue instead of red.


text:
IDE / Plugin / Compiler / Language: Which combination is closest to best-practice embedded development in C or C++?
Currently I'm pretty far out to sea with a combination of Visual Studio Code, the Platform.io extension, while writing new code in C++ using avr-gcc.
I'm hoping for a combination that would offer the most crossover educational value, in the event that I potentially experiment (if only to prove the Arduino platform's superiority to any doubters) with non-Arduino-specific embedded development.
The default IDE seemed to present me with less information about the remarkably sound underpinnings and marvelous overall artistry with which they've woven the many different design techniques and languages together. I'm mainly curious about other (inferior to Arduino, mind you), more widely used combinations / tool chains in the world of embedded programming.

Comments are not for extended discussion; this conversation has been moved to chat.

A great deal of what you learn with any comprehensive IDE will transfer to another one, if you need to. The IDEs that come to mind are Eclipse (listed first, only because it is my personal choice and has a broad range of application), Visual Studio, and others I have no experience with.
The Arduino IDE is as limited as you found it, primarily because it was written as (1) a learning tool for (2) AVR-based Arduinos, and goes to some lengths to offer an easier entry into embedded systems programming for non-programmer hobbyists. To that end, it achieves its goal very well. But as you have observed, you quickly run into its limitations, especially when your goal is to branch out onto other processors and other tool-sets.
Once someone is over the hump of basic programming and debugging, more advanced tools like a full-on IDE take most of those limitations out of your way, at the cost of less hand-holding, but by that time, you presumably need the freedom much more than the help!
I don't want to outright tell you "You need to use FiddleFoo 18.4 or you'll never get anywhere" - one (or a couple) of the industrial strength IDEs will appeal to your view of programming and your personal work-style. Try a few of them, paying attention to what toolsets and processors each one can target with OEM or third-party support, for the processors you think you might become interested in. It's quite likely T-H-E right IDE for you will stand out from the rest.
Update:
Eclipse will need a plug-in to target Arduino and other embedded system boards. The one I use - and the only one being maintained AFAIK - is Sloeber by Jan Baeyens, who occasionally posts here as jantje. It is pretty comprehensive, including the ability to write and import new board descriptors.
Memory limitations come with the hardware, and while compiler advances can help this out, it's pretty much governed by the numbers. An Arduino Uno still has only 2K of RAM and 32K of Flash minus whatever the bootloader uses (if you choose to use a bootloader). Heap is still problematic for all the usual reasons - fragmentation of free memory (positioned, as it is, between static area and the bottom of the stack), and reduction of available stack and/or data space. There are, of course, more embedded boards available, with larger memories, but that just helps you put off the inevitable. I view the use of heap in an embedded system as a reliability issue even more than as a memory limitation; it is all too easy for fragmentation and memory leaks to eventually take down your system, and a Blue Screen Of Death is a big no-no in embedded systems.

I appreciate the input, JRobert. It's been some years since I used Eclipse, and the only reason I stopped then was due to insufficient RAM, which shouldn't be an issue these days. I take it there isn't any plug-in / extension required? Also, since posting the original question last night I was able to find an older, but interesting, discussion concerning language use and memory limitations of various boards. Have these last five years changed that consensus (avoid the heap, C is best) with the increases in available onboard memory?


text:
Arduino uno + 5 IR obstacle sensor
I have IR sensor with current draw 100ma i have to connect 5 of them is i can connect all 5 with arduino directly or i have to use external power suplly for them

what sensors exactly?  Can you post a link to a datasheet?

An Arduino UNO has a max current of 20 mA per IO Pin and a max current of 200 mA of all Pins together. If you intent to drive the senders with the pins then this is impossible.
If you power the Arduino with USB, the VCC current is limited to 500 mA (thermo fuses). If you power it externally, it depends on the power supply. Using the voltage from the Vcc Pin is risky (IMHO), because the Arduino needs power too.
So with 100 mA per sensor I would definitively use an external power supply.

Can you please help which power supply i have to use soo that i can give supply to arduino as well as to my sensor externaly (becoz there is no use of give  usb power to arduino if i am connecting external power for sensors ) i want to do it with single power source

I fear, I can not help you, as I know nothing about your setup. And it is also not a good idea not ask a question and than extend it again and again and .... So please ask a new question eventually with a link to this one. The more information you add to the question the more help you will get. Which Sensors do you use (give a link to the data sheet).  How are they used. Are they all active at the same time, or just one or a few. Have you searched the internet for similar problems? Or edit this  question, but add the details I suggested.  (But do not add the details to a comment.)


text:
Why should I connect GND to RST to send data through Rx using USB-TTL?
I've found that when I use Arduino Nano connected with USB everything is working great, and when I tryed to use it with USB to TTL connector I've understood that I can only read data. I tryed to connect GND to RST as it was on some picture in Internet, and it works! Now I can send data through my USB to TTL (and through another UART device). So I can't uderstand, why should I do it? Why can't I just send data through Rx Arduino pin? Why do I need an extra action? Is it related with Arduino microcontroller?

add some diagram about what devices and how you connect

The key here is to remember the simple rules:

One device can send to many devices
One device can receive only from one device

In your situation you have three devices that are communicating:

The USB to UART chip
The on-board ATMega, and
The off-board ATMega connected to the TX/RX pins.

All three of those are connected together through the TX and RX pins.  This means that:

The UART chip sends to the on-board ATMega, and
The UART chip sends to the off-board ATMega

This fits with rule 1 above: one device can talk to many devices.
But:

The UART chip receives from the on-board ATMega, and
The UART chip receives from the off-board ATMega

This breaks rule 2 above. You can't have two devices sending to one receiver.
By connecting the RESET pin to GND you are effectively turning off the on-board ATMega. It's like you removed it from the board. It's not allowed to do anything - including communicating with the UART chip.
So that fixes rule 2 above, because now you only have one device sending to the UART chip, not two.

Thanks! That helped me to understand more! By the way, is it the best way I can itteract with another controller or there are another ones less difficult (Software Serial?) ?

It depends what and how you want to communicate. I2C is a popular choice for sending data from one MCU to another.

authors: Даниил Поляков


text:
12V but what Ampere?
So if my arduino will draw around 800mA @5V and the dc-dc buck converter around 266mA @5V plus solenoid 1.2A @12V, is it a good idea to get 12V 4A (48W) power supply? Since Filip Franik told me that it is a good practice to get 2 times the current I need just in case. Then what will happen to the current that are no in use?

Good practice is to calculate your needs and multiply them by 2 "just in case" So if you need 1.5A find a power supply that has a 3A max.a So you will need one that's around 36W (3A * 12V)

do not use the arduino as a power supply ... it tends to become an expensive fuse

I am using arduino for relay module, lcd, buzzer and keypad. Not using it as a power supply, I am trying to make the 12V the power supply for solenoid and arduino.

So you want to use the 5V voltage regulator on the Arduino serve as the supply for your 5V components, and feed the 5V regulator from the 12V supply that powers your solenoid?
The problem with that plan is heat. The voltage regulator on the Arduino is a poorly heat-sinked (heat-sunk?) "linear" regulator. A linear voltage regulator is basically a solid state circuit that converts excess voltage to heat.
The higher the supply voltage you provide to the voltage regulator, the more heat it generates for a given current load.
If you feed 12V into the Arduino's voltage regulator, it needs to reduce the voltage from 12V to 5V. 12V - 5V is 7V. So it will convert 7V to heat. You're only drawing ≈220 mA. Total power that will be converted to heat is 7V*0.22A, or around 1.54 watts of power. You should budget for at least 50% more current than you think you'll need, so lets use 330 mA. 7.0*0.33 is about 2.3 watts.
From a little research I did, it sounds like a typical Arduino voltage regulator can dissipate around 1 watt of heat. You're well over that limit even at your low ≈220mA number, so you need a solution that won't overheat your Arduino's voltage regulator.
If you were to instead supply the Arduino's voltage regulator with 7.5V, it would have a lot less work to do. That's a voltage drop of 2.5V. So for a 0.33 max current draw, that would be 2.5*0.33, or about 0.83 watts. That would be under the 1 watt ceiling. However, it sounds like your project is based on a 12V supply.
You could instead use an external switching voltage regulator to reduce 12V to 5V. (search for "boost voltage regulator".) Those are much more efficient, and don't generate nearly as much heat. You could then feed regulated 5V directly into the USB input on your Arduino, as well as supplying it to your other 5V components.

I have decided to choose the 12V 1.5A (18W) supply connected to 12V 1.2A solenoid and a DC-DC Step Down Buck Converter, stepping down from 12V to 7V, that will cause the current to increase from 1.5A to 2.5A for the Arduino.
AMS1117 5.0V SMD device (0.8A Adjustable/Fixed Low Dropout Linear Regulator) Max Input Voltage is 18V, Current limit is around 1.5A - 1.6A,
My current is around 2.5A minus off 1.5A, what will happen to the 1A?

I read a article, it says since there is no maximum current rating for the power supply connected to Arduino, the Arduino will draw as much current as it needs (and the voltage regulator can cope with). So its fine?

I don't understand what you are describing.

I totally forgot about DC-DC Step Down Buck Converter Output Current: Rated current 2A, maximum 3A (Additional heat sink is required). So from what I currently know buck converter will not create 2.5A just like that.

I am describing about the the ampere since buck converter steps down voltage (while stepping up current) from its input (supply) to its output (load).

Your various comments are VERY hard to follow. Please edit your question to state clearly what you plan to do. What you SHOULD do is to drive the 12V solenoid directly from the 12V supply. Then feed 12V into your buck converter, which is rated for up to 2A. I'm assuming you have selected a buck converter with a 5V output. you'd then feed that 5V into the USB port on your Arduino, along with using it to supply your other 5V components. The buck converter will only draw a very small amount of current from the 12V supply, and will not generate much heat at all.

If my supply increase from 12V 1.5A to 4A. My arduino will draw around 800mA @5V (571mA @7V) plus solenoid 1.2A @12V, is it a good idea to get 12V 4A (48W) power supply? Since Filip Franik told me that it is a good practice to get 2 times the current I need just in case.
I know there is the efficiency of the converter is calculated by dividing the output power (Pout) by its input power (Pin) and then times the input current to get output current.
So for example 7V divide 12V is around 58.3% x 4A = 2.33A. Even if the solenoid takes 1.2A @12V, the current left is 2.8A, so the current is 1.63A, @ 7V. If arduino current draw what it needs and as long as it doesn't draw more than 2A, I think it is sufficient and safe.