text:
Arduino uno - 4digit 7seg display via 74HC595 keeps blinking
I am trying to get my 4 digit display (SH5461AS) count from 0 to 9 based on millis() function.
The problem is that it keeps blinking. Even if I display just one number, it shows then it goes black then it shows again, instead of staying on.. Also the upper segment (A) is somewhat delayed. Sometimes it shows, sometimes it does not. I am really not sure what is going on. It is best illustrated in the video: https://youtube.com/shorts/gmbNnvEYq2I
I have arduino UNO R3 hooked up to the 74HC595 8-bit register and from there to the corresponding 'data' pins on the display.
It is a common cathode type so I have all of those connected via resistor to the ground.

I appologize for the messy cabeling:
From the display basically all resistors go to ground and all data cables to the register (Q0-DP omitted, segment A-Q7, B-Q6, .., G-Q1 [decimal number 1=A, 2=B, 3=AB,..]).
In the register I got VCC, Ground, data cables, EO grounded, serial data->arduino D4, storage clock -> D5, shift clock -> D6
 #include <LiquidCrystal.h>

//LCD
const int rs = 7, en = 8, d4 = 9, d5 = 10, d6 = 11, d7 = 12;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);

//7SEG DISPLAY
int LATCH = 5;
int CLOCK = 6;
int SERIALPIN = 4;

const byte numbers[] = {
  0b111111, 0b0000110, 0b1011011, 0b1001111, 0b1100110, 0b1101101, 0b1111101, 0b0000111, 0b1111111, 0b1101111
};

//OTHER

void setup() {
  //LCD
  lcd.begin(16, 2);
  lcd.print("Test!");

  //7SEG
  pinMode(SERIALPIN, OUTPUT);
  pinMode(CLOCK, OUTPUT);
  pinMode(LATCH, OUTPUT);

  //OTHER
  pinMode(13, OUTPUT); // turn off onboard diode
  Serial.begin(9600);
}

void loop() {
  countSeconds();
  delay(1000);
}

void countSeconds(){
    digitalWrite(LATCH, LOW);
    // int number = (millis()/1000%10);
    // Serial.println(number);
    shiftOut(SERIALPIN, CLOCK, LSBFIRST, numbers[0]); //for demonstration purposes display 0
    digitalWrite(LATCH, HIGH);
}

Any ideas what's wrong?

what happens if you exchange the two digitalWrite() program lines?

Hard to tell but it looks like the reset pin is floating. Make sure it is tied high (or controlled by your MCU).

As @Mat pointed out, the reset pin on the shift register was not connected. I didn't realize I need to anchor it high. Solved all problems, I guess it was resetting unpredictably..


text:
How to run avr-gcov on a .ino sketch file
I am new to Arduino and gcov. I have a .ino sketch file, avr-gcov, and avr-gcc from Arduino library in the same directory. Could someone guide me to the steps I should take to run avr-gcov on my .ino file and get a .gcov file?
These are the things I have tried so far. When I run
./avr-gcov filename.ino,
it throws the error filename.gcno: cannot open notes file. My assumption was that I needed create a .gcno file before running gcov. So I tried to create one using the command
./avr-gcc -c -Wall -pg -fprofile-arcs -ftest-coverage filename.ino.
But doing so gives a warning: linker input file unused because linking not done and doesn't produce anything.
I tried to create an object code from the sketch file by passing -o flag but that throws the error avr-gcc: fatal error: -fuse-linker-plugin, but liblto_plugin.so not found.
Any help would be appreciated.

why do you want to use gcov?

The sketch file is very large. I would like to get the code coverage and identify the blocks that are reached more often and generate a control flow graph based on that.

Code coverage by "gcov" has some prerequisites:

Instrumented code to count the number the control flow reaches certain points of the program. This is done via the options you tried.
Linking with the support library. This is done via the options you tried. The result is a "gcno" file for each translation unit.
This support library expects a file system to store the accumulated counter values.
Running the application, the support library creates a "gcda" file for each translation unit. This file holds the accumulated counter values.
"gcov" expects all these "gcno" and "gcda" files to generate an annotated listing.

Since common Arduinos don't have a file system, the prerequisites cannot be fulfilled. This is the reason why you receive the error messages.
So what can you do now? There are multiple alternatives, but this site is not appropriate to present you ready-made solutions.

You can compile the sketch for the PC. For this you need to provide all used Arduino functions, for example as mocks or simulation.
You can provide the missing functions on your own, some kind of persistent storage, and finally transfer the data as "gcda" files to your PC. (This sounds complicated and resource expensive, and it is. However, it's doable, I did this years ago with another embedded system and a former version of "gcov".)
Refrain from using "gcov" and try other approaches of finding your hot spots. For example, toggle different port pins and/or with different patterns to literally "see" which code is executed. You need a good oscilloscope or logic analyzer for this.

source: Stack Exchange

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

sort: votes


text:
Creating an IPAddress object from an unsigned int
If I create an IPAddress object using a decimal IP address, it appears to be reversed.
What am I doing wrong? See code examples below.
IPAddress addressOne(192,168,50,1);
Serial.print(addressOne);                // ==> prints "192.168.50.1"

//The decimal version of 192.168.50.1 is 3232248321
unsigned int iAddress = 3232248321;
IPAddress addressTwo(iAddress);
Serial.print(addressTwo);                // ==> prints "1.50.168.192"

You just found out that this IPAddress constructor interprets its
parameter in little endian order. Then encode your address as
little-endian:
//The decimal version of 192.168.50.1 is 20097216
unsigned int iAddress = 20097216;

Wow! I just learned something! Thanks!

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


text:
Same Bin file to similar ESP32 boards yields different results
Sorry for the confusing title. It is a bit hard to explain.
We have a remote developer who compiles his code into a bin file and sends it to all of us. He loads it onto his ESP32 boards and they work just fine. However, when we load the bin file onto our ESP32 boards, they do not work. We are all using the same configuration ESP32 boards. We are all using Expressif Flash Download tool to load the bin file.
Where would y'all recommend I start my investigation? What additional info do you need from me to help figure this out? I have confirmed that we are all using the same ESP32 boards as well as the same flash tool. Ideas?
By the way, I am not the programmer, I do not have access to the source code. I only have the bin file.
Thank you

how is the bin file created?

start by sending one of your boards to the developer for testing

@jsotola I can do that. Good call. I'll let you know how it works out.

My fault. I hadn't wired the final product exactly as the designer had. Once the wiring was correct the issue was resolved. Just needed a physical troubleshooting as the software troubleshooting wasn't the issue.
Funny thing is, there are only two wires on the entire project and I had gotten them wrong.
So I think the lesson here is, check your physical configuration as well as the software/firmware.
Thank you all for your help.


text:
Arduino RS485 do I need MAX485?
I'm trying to connect sesnor that use RS485 (I'm almost sure that's modbus). The sensor has RX/TX and +/- wires. Do I still need a component between the RX/TX pin from the Arduino UNO and the sensor itself? All the libraries I reviewed have an additional control pin. Or do I need, for example, a MAX485? Is it possible to simply connect RX of sensor to RX of UNO, TX of sensor to TX of UNO and + to 5V of UNO, and - to - ?

similar question https://arduino.stackexchange.com/questions/53287/dmx-on-the-arduino-without-additional-driver-chip

@Juraj So I need MAX485


text:
How to upload code to Arduino without a laptop
I would like to know is there a way of burning programs to microcontrollers like that on Arduino without using a computer? Like a pendrive or something? Suppose you want to update firmware on a utility end, must you carry the editable source code with you? How do the big companies do it?

SD card is possible. do you want a solution for Uno or is the tag random?

@Juraj Well I've been using Uno, nano and pro mini for now.

Are we talking strictly about solo Arduino boards? OTA (Over the Air) internet upload may be interesting feature for you

One good way to update Uno/Nano/Mini without connecting it to a computer is to use SD bootloader. SD bootloader reads at boot the bin file with the update from the attached SD card and copies it to flash memory.
There are not many SD bootloader for ATmega. I use avr_boot by zevero. It works well. The downside is that it doesn't support upload over USB.
zevero doesn't offer built binaries of the bootloader so you have to compile it with the avr toolchain.
avr_boot requires a bin file, not a hex file, but it is simple to set Arduino IDE to create a bin file along with the hex file. You create platform.local.txt file next to platform.txt in the avr boards package, and put this line into the file:
## Create output (bin file)
recipe.objcopy.bin.pattern="{compiler.path}{compiler.elf2hex.cmd}" -O binary {compiler.elf2hex.extra_flags} "{build.path}/{build.project_name}.elf" "{build.path}/{build.project_name}.bin"

Then you can use "Export compiled binary" from Sketch menu in Arduino IDE and you will find the binary file next to your ino file in the sketch folder.

There are different ways how to update an Arduino without connecting it to computer. For small ATmega328p on Uno/Nano/Mini there is not enough flash space to do a self update. The code required to do the update takes more than half of the flash so there is no space left to store the update binary before applying it. (The updated sketch of course must have to have the code for the self update too.)
For illustration what is possible, here is a sketch for Arduino Mega which does a self update from SD card reading a hex file. It requires a modified Optiboot available in MegaCore.


text:
Arduino Uno Stuck at uploading
I wrote a basic blink code and tried to run it on the auduino IDE. Compilation was sucessfull but the code stucks at uploaing. I turned on the verbose output while uploading and this is what I have found..
avrdude: Version 6.3-20190619
         Copyright (c) 2000-2005 Brian Dean, http://www.bdmicro.com/
         Copyright (c) 2007-2014 Joerg Wunsch

         System wide configuration file is
"/Users/_stelk/Library/Arduino15/packages/arduino/tools/avrdude/6.3.0-arduino17/etc/avrdude.conf"
         User configuration file is "/Users/_stelk/.avrduderc"
         User configuration file does not exist or is not a regular file,
skipping

         Using Port                    : /dev/cu.usbmodem101
         Using Programmer              : arduino
         Overriding Baud Rate          : 115200

I don't exactly understand what to do. Can somebody please help. Board is Arduino Uno but I don't think there is any problem with the hardware. Even when I disconnect the board..the same think happens without giving me an error. Everything was fine last night. When I launch the IDE now, it automatically selects the Uno board and when I hit upload, it compiles sucessfully and stucks at uploading. Should it not give an error like "No board found"? This same behaviour happens even when I connect the board and upload again.

try to remove "/Users/_stelk/.avrduderc"

Are you on a Mac? Which version of Arduino IDE? That may be relevant to answer this question. Also, the output you posted is just the output of avrdude before trying to open the usb-serial device for programming. Is there really no other option in the preferences that turns on verbose error logging?

Found this here: "Occasionally, the [Arduino IDE] 2.0 will upload. This typically happens after closing and reopening the app and using the tools menu to select the port and board instead of the automatic drop down menu. Currently, the port options list old ports that are now not connected. Plugging in to a new port does not updated the port list.", also "make sure the Serial Monitor is closed" -- Looks like there are still a lot of bugs in Arduino IDE 2.0. Which IDE version do you use?

By "UNO" you refer to an ATMega328P based UNO and not to an UNO WiFi or any other board with "UNO" in the name, right?

Are you using the correct COM port?  On a PC the COM port number can sometimes change when the PC starts or wakes up.  Also do you mean you wrote the blink program by hand or you used the blink program from the examples?  (Is it possible there is a mistake in your code)


text:
Is there a FreeRTOS library for an Arduino Nano 33 BLE?
I can't seem to find any library online so I can start developing FreeRTOS tasks for the Arduino Nano 33 BLE in the Arduino IDE. Is FreeRTOS incompatible with this Arduino?

the Arduino mbed platform for the Nano BLE is based on mbed RTOS. why do you want to use FreeRTOS?

I have a college assignment where I need to install and characterize FreeRTOS on 3 different systems, the ones I chose with the help of the professor were the Arduino Uno, the ESP-32 and the Arduino Nano 33. Since I never used ESP-32 and Arduino Nano 33 I just assumed the professor knew it would work, but it really seems like it doesn't support FreeRTOS. I don't know how to use mbed RTOS and I don't have a lot of time to work on this project, so it wouldn't make sense to use anything besides FreeRTOS, which is the only RTOS I can use.

esp32 arduino platform is RTOS too

Forget about the Arduino Uno. It's CPU is much to weak to run any OS.

The Arduino Uno actually runs FreeRTOS pretty well and is easily programmable because there is a library for it inside the Arduino IDE.


text:
Can't mount microSD card with Freenove ESP32 WROVER Module and Sparfun MicroSD module
I'm using Freenove's ESP32 WROVER Module with their GPIO expansion board as shown in the image below:

I'm trying to integrate Sparkfun's microSD module in the circuit. Here's my sketch. However, I'm unable to mount the card despite it works fine using an ESP32-CAM board with integrated SD card reader.
Any clues on what I'm doing wrong?

please do not post a link to code ... add the code text to your post ... use the edit button ... no pictures please

Your pinout to the SD is unclear from the picture, but I can see that you are using pin 15, which is the MTDO strapping pin- which will cause issues for sure.

You can learn more here about using alternative pins here:
https://randomnerdtutorials.com/esp32-spi-communication-arduino/


text:
Seting up registers in Samd based arduino board
I'm trying to setup the BOD33 for Samd51 MCU in th .ino file as a first thing, even before the #include lines in the .ino
// Define the base address for t_SUPC
#define T_SUPC_BASE 0x40001800UL

// Define the offsets for t_BOD33 and t_STATUS
#define T_BOD33_OFFSET 0x10
#define T_STATUS_OFFSET 0x0C

// Set the t_SUPC register
volatile uint32_t *t_SUPC = (volatile uint32_t *)T_SUPC_BASE;

// Set the t_BOD33 register
volatile uint32_t *t_BOD33 = (volatile uint32_t *)(T_SUPC_BASE + T_BOD33_OFFSET);

// Set the t_STATUS register
volatile uint32_t *t_STATUS = (volatile uint32_t *)(T_SUPC_BASE + T_STATUS_OFFSET);

// Clear bit 1 in t_BOD33 and then set it to 1
*t_BOD33 &= ~(1u << 1); // Clear bit 1

// Check bit 0 in t_STATUS and loop while it is 0
while ((*t_STATUS & 0x01) == 0)
{
}

*t_BOD33 &= (0x7D0300u << 1);

*t_BOD33 |= (1u << 1); // Set bit 1 to 1
while ((*t_STATUS & 0x01) == 0)
{
}

while ((*t_STATUS & 0x02) != 0)
{
}

// Clear bit 1 in t_BOD33 and then set it to 1
*t_BOD33 &= ~(1u << 1); // Clear bit 1
while ((*t_STATUS & 0x01) == 0)
{
}
*t_BOD33 |= (1u << 2);
*t_BOD33 &= ~(1u << 3);
*t_BOD33 |= (1u << 1); // Set bit 1 to 1

but I'm getting a compile problem and VScode is throwing those error, which I have no clue why since I never encountered it before
the errors are :
""
0_2.ino:28:10: error: expected constructor, destructor, or type conversion before '&=' token
   28 | *t_BOD33 &= ~(1u << 1); // Clear bit 1
      |          ^~
0_2.ino:31:1: error: expected unqualified-id before 'while'
   31 | while ((*t_STATUS & 0x01) == 0)
      | ^~~~~
0_2.ino:35:10: error: expected constructor, destructor, or type conversion before '&=' token
   35 | *t_BOD33 &= (0x7D0300u << 1);
      |          ^~
0_2.ino:37:10: error: expected constructor, destructor, or type conversion before '|=' token
   37 | *t_BOD33 |= (1u << 1); // Set bit 1 to 1
      |          ^~
0_2.ino:38:1: error: expected unqualified-id before 'while'
   38 | while ((*t_STATUS & 0x01) == 0)
      | ^~~~~
0_2.ino:42:1: error: expected unqualified-id before 'while'
   42 | while ((*t_STATUS & 0x02) != 0)
      | ^~~~~
0_2.ino:47:10: error: expected constructor, destructor, or type conversion before '&=' token
   47 | *t_BOD33 &= ~(1u << 1); // Clear bit 1
      |          ^~
0_2.ino:48:1: error: expected unqualified-id before 'while'
   48 | while ((*t_STATUS & 0x01) == 0)
      | ^~~~~
0_2.ino:51:10: error: expected constructor, destructor, or type conversion before '|=' token
   51 | *t_BOD33 |= (1u << 2);
      |          ^~
0_2.ino:52:10: error: expected constructor, destructor, or type conversion before '&=' token
   52 | *t_BOD33 &= ~(1u << 3);
      |          ^~
0_2.ino:53:10: error: expected constructor, destructor, or type conversion before '|=' token
   53 | *t_BOD33 |= (1u << 1); // Set bit 1 to 1
      |          ^~

thank you in advance.

The line where the error starts should go to a function e.g. setup(). You can compile the code below.
// Define the base address for t_SUPC
#define T_SUPC_BASE 0x40001800UL
// Define the offsets for t_BOD33 and t_STATUS
#define T_BOD33_OFFSET 0x10
#define T_STATUS_OFFSET 0x0C

// Set the t_SUPC register
volatile uint32_t *t_SUPC = (volatile uint32_t *)T_SUPC_BASE;
// Set the t_BOD33 register
volatile uint32_t *t_BOD33 = (volatile uint32_t *)(T_SUPC_BASE + T_BOD33_OFFSET);
// Set the t_STATUS register
volatile uint32_t *t_STATUS = (volatile uint32_t *)(T_SUPC_BASE + T_STATUS_OFFSET);

void setup()
{
    // Clear bit 1 in t_BOD33 and then set it to 1
    *t_BOD33 &= ~(1u << 1); // Clear bit 1

    // Check bit 0 in t_STATUS and loop while it is 0
    while ((*t_STATUS & 0x01) == 0)
    {
    }

    *t_BOD33 &= (0x7D0300u << 1);

    *t_BOD33 |= (1u << 1); // Set bit 1 to 1
    while ((*t_STATUS & 0x01) == 0)
    {
    }

    while ((*t_STATUS & 0x02) != 0)
    {
    }

    // Clear bit 1 in t_BOD33 and then set it to 1
    *t_BOD33 &= ~(1u << 1); // Clear bit 1
    while ((*t_STATUS & 0x01) == 0)
    {
    }
    *t_BOD33 |= (1u << 2);
    *t_BOD33 &= ~(1u << 3);
    *t_BOD33 |= (1u << 1); // Set bit 1 to 1
}


text:
error: 'CLASS' does not name a type only when creating object inside another object
I'm trying to use Adafruit's LED Backpack library within a custom class. When I use the Adafruit library directly within a sketch, it compiles fine. When I use an example sketch provided with the library, it compiles fine. However when I create an instance of my custom class with the Adafruit object within it, I get the following error:

In file included from sketch_feb18a.ino:6:
  /Users/lawnmowerlatte/Documents/Arduino/libraries/Bargraph/bargraph.h:18: error: 'Adafruit_24bargraph' does not name a type

All the reasons I've seen for this error stem from the library being missing or otherwise incorrectly installed. However, since I can use it directly, I think something else must be wrong.
Working
#include <Adafruit_LEDBackpack.h>
#include <Adafruit_GFX.h>
Adafruit_24bargraph bar = Adafruit_24bargraph();

void setup() { }
void loop() { }

Not Working
#include <bargraph.h>
Bargraph bargraph = Bargraph("Test", "api", 0);

void setup() { }
void loop() { }

bargraph.h
#ifndef Bargraph_h
#define Bargraph_h

#include <Adafruit_GFX.h>
#include <Adafruit_LEDBackpack.h>

#if (ARDUINO >= 100)
#include <Arduino.h>
#else
#include <WProgram.h>
#endif

class Bargraph {
  public :
    String name;
    String api;
    Adafruit_24bargraph bar;

    Bargraph(String _name, String _api, int _device,
        String _type="Default");

    void set(String _value);
    void setMax(String _max);
    void update();
    void print();

  private :
    int display[24];

    long max;
    long value;
    int device;
    int size;
    String type;

    void format();
    void write();
};

#endif

bargraph.cpp
#define OFF 0
#define RED 1
#define YELLOW 2
#define GREEN 3

#include <bargraph.h>

#if (ARDUINO >= 100)
#include <Arduino.h>
#else
#include <WProgram.h>
#endif

Bargraph::Bargraph(String _name, String _api, int _device, String _type) : bar() {
    name        = _name;
    api         = _api;
    max         = _max.toLong();
    device      = _device;
    type        = _type;
    value       = 0;

    for (int i=0; i<24; i++) {
        display[i] = OFF;
    }

    bar.begin(0x70+device);
}

**Methods Omitted for Brevity**

Can anyone explain what's going on here? I'm pretty certain my class syntax is correct as I have other object-in-object relationships working. I can post code to GitHub if anyone would like to see more context.

I think these lines still need to be in your main sketch file (in addition to being in your custom class file):
#include <Adafruit_LEDBackpack.h>
#include <Adafruit_GFX.h>

If I remember the Arduino IDE quirks correctly, it uses the #include directives in the main sketch file to determine which libraries to actually link. It's one of those annoying features that was intended to be beginner-friendly but sometimes just makes things more confusing.

Thanks for the answer. I tried this, but then I get a ton of redefinition and previous definition errors. If I wrap the Adafruit library in ifndef blocks, it works! Do you have any ideas why they wouldn't have put that in? It seems like good practice to do so.

@lawnmowerlatte - That's surprising. I can't see any reason that it wouldn't be there already.

If you used the serial port, Arduino sometimes causes confusion.
Close Arduino IDE and
delete files in folder C:/users/[your name]/AppData/Local/Temp/
Its working.
Regards

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


text:
/dev/cu port resource always busy on OS X 10.10
Is there any reason why is my /dev/cu port always busy? How can I fix that?
It happened on both Uno clone and Spark Core.
The problem is, I'm having issues doing serial communication. Where (as a programmer) I'm seeing something like dropped packets with /dev/tty port. I did a quick test running it on Win 7 (a loaner PC), it works fine...
The code for now is extremely simple. It waits for a command, and write a response.
String str = String(30);

void setup()
{
    Serial.begin(9600);
    str = "";
}

void loop()
{
    if (Serial.available() > 0) {
        char inChar = Serial.read();
        if ((inChar == '\n') || (inChar == '\r') || (inChar == 'z')) {
            str.trim();
            if(str == "READ") {
                String x = String(random(27, 45)) + "," + String(random(45, 300)) + "," + String(random(35, 250));
                Serial.println(x);
            }
            str = "";
        }
        else {
            if (str.length() < 30) {
                str += inChar;
            }
            else {
                str = "";
                str += inChar;
            }
        }
    }
}

I always use the tty one, and not the cu on my mac.

Yeah, me too. But so far, I've only need to upload sketches. Never really thought nor care about tty or cu.

Finally figured it out. I need to call Serial.flush().

Waits for the transmission of outgoing serial data to complete.

Serial.flush() is not my solution. anyone with any new information on this?

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


text:
Why 5V instead of 3V3?
I'm still quite new to electronics, so please forgive me if the answer is obvious.
I was wondering why virtually all the example circuits I find use the 5V power supply with resistors for all the components instead of the 3V3 power supply directly.
Even for the most simplistic "Blink" example, they use 5V pin and a 220 Ohm resistor to protect the LED instead of using the built-in 3.3V pin.
Yes, I know that in former times "everything" ran on 5V, but since we already have a lower voltage built-in, why not use it and reduce the number of components needed?
TIA for anyone who can solve this puzzle for me.
mav

Could you give an example of a circuit that uses 5V for the supply and resistors for all the components? My guess is that these resistors would still be necessary even if the circuit ran on 3.3V (possibly with different values). For example, the current through an LED should always be limited (by a resistor or otherwise), regardless of what voltage supply it's connected through. With a 3.3V supply you would still need a resistor although possibly a lower value.

The reason that you will still find many examples using 5V is that the "classic" Arduino Uno that many hobbyists start out with still runs on 5V.

First, even with 3.3V, an LED needs a resistor to limit the current through it. So, running with 3.3V doesn't solve that particular problem. Try Googling for "LED current limiting resistor".
Second, many Arduinos are designed to run using 5V. In many cases they have an input power jack which can accept a range of voltages and use a voltage regulator to convert it down to 5V,
Why not convert down to 3.3V you might ask? Well, the higher the voltage, the faster the processor can run, within its design limits. For example, the Atmega328P (which is in the Arduino Uno, and others) could only run at 13 MHz at 3.3V rather than 16 MHz.

... instead of using the built-in 3.3V pin

But that pin is only provided for convenience. You can't turn it on or off by a program.
The higher voltage (5V vs 3.3V) can be more convenient in some situations, for example switching motors on and off, or with other devices designed to work with 5V.
Motors or other high-power devices are typically turned on with MOSFET transistors. To be efficient, they need to fully turn on (have a low resistance between Source and Drain) and even so-called "logic level" MOSFETs typically require 5V to fully turn them on, rather than 3.3V. If you tried to control a motor with a 3.3V based board you would probably need extra components to turn the MOSFET on properly, so lowering the voltage could potentially add components, not reduce them.
On the other hand, many components these days are designed to work with 3.3V (or lower) so the choice of 5V is a bit of a compromise.

Also: USB, which is a very common way of powering devices these days, is 5V by default (extending to higher voltages on request with USB-C Power Delivery)

"For example, the Atmega328P could only run at 13 MHz at 3.3V rather than 16 MHz" is a  bit confusing, given that faster CPUs use lower voltages. But the reason is obviously not the same.

@PMF But, those faster CPUs that allow runtime frequency scaling generally also scale down voltage at lower frequencies, and most people who intentionally underclock their system do so so they can also under-volt it (and therefore save power).

@PMF - I am just quoting (extrapolating) from the figures in the datasheet. In the case of the Atmega328P, there are speed limits depending on voltage. And you can actually use less power by using a lower voltage, trading off speed for power savings. For various reasons, heat probably being the main one, modern high-speed CPUs would indeed use lower voltages, but they would be designed with that in mind.

@NickGammon That was what I was talking about. Higher voltages result in higher heat losses. And if you want to overclock a CPU, you typically have to increase the voltage (to make sure the electronics can properly switch from high to low) - and install a large heat sink.


text:
Can an Arduino and an NI USB-6009 DAQ board interfere with each other's signals when they are simultaneously reading signals from different sensors?
Hello dear Arduino SE community.
I have 5 sensors. I read 4 of them with an NI USB-6009 DAQ board and I read the fifth one with an Arduino UNO R3. Though, with the fifth sensor not only I read a signal from it, but I also send a signal to it.
Both the Arduino and the NI board are connected to a computer via two different USB ports and send the signals to the computer simultaneously. Also - simultaneously - the Arduino sends a signal to the fifth sensor.
I noticed a strange behavior with the signal from one of the sensors read by the NI board. It starts with giving me a signal that is clearly wrong and over the course of, approximately, 5 minutes gradually changes to a correct reading.
That hadn't happened when I didn't have Arduino connected to the computer at the same time.
Thus, I'm wondering if it is possible that an Arduino and an NI board can interfere with each other's signals when connected to the computer simultaneously. If it is possible, is it something widespread and is there a working solution?
Thank you in advance.
Ivan
P.S. I deliberately don't provide the specs of my system because the point of my question is not to resolve the issue but to learn if what I described is possible theoretically and if such cases have been encountered.

anything is possible ... please ask a focused question that is actually answerable

I have found a solution to my problem.
The sensor that was giving me the wrong signal was plugged to the same electrical circuit with "heavy" equipment (two DC laboratory power supplies). It is well known that one shouldn't do it because "heavy" equipment sends noise back to the circuit which, ultimately, causes noise in the signal generated by the sensor.
Thus, my issue had nothing to do with the Arduino interfering with the USB-6009 through the computer.
To make sure, I disconnected the Arduino from the computer and still got the same wrong signal from the problematic sensor. Then, I plugged the problematic sensor to another electrical circuit, connected the Arduino back to the computer and got the right signal.
Thus, I conclude that one can safely use an Arduino and a USB-6009 with the same computer.


text:
The port is not recognized when working with esp32 in arduino ide 2.2.1 (windows 11 home edition)
I'm trying to program the ESP32 board with Arduino IDE.

But The port it's not recogniized when working with esp32 in arduino ide 2.2.1.
After some research I found that the port is not recognized by my operating system (WINDOWS 11 home edition).
Image of Device Manager showing the message that the port is not recognized.

I installed the Silicon Labs drivers for the CP210x USB to UART Bridge.
After restarting the PC, the port is still not recognized.
I did a search with the command line and the driver CP210x USB to UART Bridge is not installed.
CMD Line image:

I'm out of ideas how to solve this problem, some one knows how to solve this issue?

please do not post a picture of text ... copy and paste the text instead ... format it as "code" so that it looks the same as on screen

I don't have a Stack Account yet, but i saw this and i know the answer...

it appears by your photo that you do indeed have a CP2102 Chip which requires the driver from here
CP2102 DRIVER

This driver should be able to be installed without connecting your ESP32 Dev Board.

This is a driver issue, so .. do this
In Device Manager  (i'm going to make some assumptions because i don't know what motherboard you have or machine )  But....

Uninstall the USB Drivers completely
Re Install the USB Drivers
Re Install the chipset drivers for your mainboard
Ensure your BIOS is up to date, if not, Update it via the correct software.

After all that , Restart Your computer

Try it again, if problem persists

Open cmd.exe    Run  sfc/scannow    and press enter
This will run the windows System File Checker

Try again, If problem persists

You likely have a knock off board, They are notorious for not wanting to play
nice with the drivers.

it's also possible that your computer is faulty,  Try it on another computer, obviously
but at the end of the day , it's more likely that you have a knock off board or
you have a driver issue and things need to get updated and resolved.

I installed the drivers using legacy mode of the device manager. But the operating system trys to open the ESP32 as a simple usb. I'll try to uninstall the drivers, then I'll give the feedback.


text:
How to optimize checking for specific string in a UART stream
I want to check for specific string (like "RecordStart") in a UART stream (115 200 baud 8N1) from a camera, to know when it is recording or not/if there is an SD. I am using an ESP32-WROOM-32UE with 16MB flash. I wired the Tx from the camera to one of the pin of the ESP. The ESP32 is programmed with VsCode (platformIO) through Arduino framework. I am using freeRTOS.
The thing is, "RecordStart" or "RecordStop" or other strings, appear just one time. Sometimes (when the camera is powering on), there are many many strings sended, very fast. So, from time to time, I lose some bytes and I can't find the strings I am looking for. I would like to optimize my code to never miss a string.
How the code works ?
If there is at least 1 byte in the serial buffer, the taskUART priority is set to 2 (while other tasks are priority 1. If a null character is detected, the message_UARTcam buffer starts to be filled. Then, each time a byte enters the buffer, I am checking if the buffer contains the strings I am looking for. It is working quite well but sometimes, I lose some bytes and the strings are not detected. I think It is because many other tasks are running and the serial buffer fills up faster than it empties. Increase temporarily the priority of the UART task improves the detection but I am still missing some bytes.
The code:
void taskUART(void *parameter)
{
  while (1)
  {
    if (SerialPortCam.available() > 0)
    {
      vTaskPrioritySet(nullptr, 2);
      char incomingChar = SerialPortCam.read();
      // Serial.write(incomingChar);

      if (flagNullChar == 1 || bufferIndex_UARTcam > 0 && bufferIndex_UARTcam < BUFFER_LEN_UART_CAM)
      {
        message_UARTcam += incomingChar;
        // Serial.println(message);

        if (message_UARTcam.indexOf(stringStart_app) != -1 || message_UARTcam.indexOf(stringStart_button) != -1)
        {
          // Serial.println("Start recording");
          SD_UARTcam = 1;
          record_UARTcam = 1;
          bufferIndex_UARTcam = 0;
          message_UARTcam = "";
        }
        else if (message_UARTcam.indexOf(stringStop) != -1)
        {
          // Serial.println("Stop recording");
          record_UARTcam = 0;
          bufferIndex_UARTcam = 0;
          message_UARTcam = "";
        }
        else if (message_UARTcam.indexOf(stringSdError) != -1)
        {
          // Serial.println("SD error");
          SD_UARTcam = 0;
          record_UARTcam = 0;
          bufferIndex_UARTcam = 0;
          message_UARTcam = "";
        }
        else if (message_UARTcam.indexOf(stringSdInitOk) != -1)
        {
          // Serial.println("SD init OK");
          SD_UARTcam = 1;
          bufferIndex_UARTcam = 0;
          message_UARTcam = "";
        }
        else if (message_UARTcam.indexOf(stringSdRemoved) != -1)
        {
          // Serial.println("SD removed");
          SD_UARTcam = 0;
          record_UARTcam = 0;
          bufferIndex_UARTcam = 0;
          message_UARTcam = "";
        }

        bufferIndex_UARTcam++;
        flagNullChar = 0;
      }

      if (incomingChar == 0x00)
      {
        flagNullChar = 1;
        message_UARTcam = "";
        bufferIndex_UARTcam = 0;
      }
    }
    else
    {
      vTaskPrioritySet(nullptr, 1);
    }
  }
}

Camera output example:
␛[0;36m[00105849][CA9] ␀[App - Connected] <OnMessage> Received msg: 0xE001000C (param1 = 0x0 / param2 = 0x0)␛[0m
␛[0m[00105849][CA9] ␀RecCapState:0 RecCurrMode:0 RecNextMode:0 GFlags:0X7 Flags:0 StreamType:0␛[0m
␛[0m[00105849][CA9] ␀[App - Widget] <Off> widgetId: -1␛[0m
␛[0;33m[00105849][CA9] ␀[App_Glob_PWM_Buzzer] PWM Buzzer : 2␛[0m
␛[0m[00105849][CA9] ␀[App - ButtonOp] <MgrTask> Received msg: 0x0 (Param1 = 0x0 / Param2 = 0x0)␛[0m
␛[0m[00105849][CA9] ␀[App - ButtonOp] <MgrTask> Received msg: 0x1 (Param1 = 0x0 / Param2 = 0x0)␛[0m
␛[0m[00105899][CA9] ␀[rec_connected_cam_record_start] Start␛[0m
␛[0m[00105899][CA9] ␀[App - Connected] <RecordStart> REC_CONNECTED_CAM_RECORD_START␛[0m
␛[0m[00105899][CA9] ␀Dechi.motion_detec: 0␛[0m
␛[0m[00105899][CA9] ␀[Applib - ExtendEnc] <_ExtendEnc_SetEnableStatus> Enable flag: 0␛[0m
␛[0m[00105899][CA9] ␀[AppLib - MuxMp4] <SetTrickRecDivisor> Cur TrickRecDivisor: 1, New TrickRecDivisor: 1␛[0m
␛[0;34m[00105899][CA9] ␀[App - Sensor] <GetVinMode> Vin Mode = 11␛[0m

Here is an idea that may work: instead of buffering the input stream
and comparing the buffer with the search string, you could do the
comparison on the fly, as you receive the characters. Then you have no
buffering at all, and no time spent in scanning through the buffer.
Below is a function that searches for the "RecordStart" marker, while
being fed one character at a time. This function remembers how many
correct characters it has received so far (this is the static variable
pos), and updates this count on each received character. It returns
true when it has just detected the marker, and false otherwise:
bool marker_found(int c) {
    const char marker[] = "RecordStart";  // search string
    static int pos = 0;  // correct characters received so far
    if (c == -1) return false;  // shortcut for a common case
    if (c == marker[pos]) {
        pos++;                      // count a correct character
        if (marker[pos] == '\0') {  // we got the complete string
            pos = 0;                // reset for next time
            return true;            // report success
        }
    } else if (c == marker[0]) {
        pos = 1;        // we have the initial character again
    } else {
        pos = 0;        // we received a wrong character
    }
    return false;
}

You would use it like this:
if (marker_found(SerialPortCam.read())) {
    // handle the incoming record
}

Note that you do not need to test for SerialPortCam.available() > 0,
as this is already handled by marker_found().

I tried your code and it is working very well. I am going to test the performances when multiple tasks are running.


text:
How to estimate the storage room for txt file when writing data to SD card module?
I'm planning to use Arduino UNO to do some measurements and record it in a SD card module. The measurements is going to last for a year or 20 month. I need some advice on how to estimate how long can the SD card storage last without overflow. Right now I'm doing measurements every second, each second contains 13 lines of data, each line is roughly 30 characters. How big is the txt file gonna be if I left the Arduino unit recording for a year?

This is just a multiplication problem.
13 lines times 30 characters is 390 bytes per measurement.
There are 86400 seconds in one day.
86400 * 390 = 33,696,000
So that's around 34 megabytes per day.
After 1 year it would be:
365 * 33.696 = 12299 MB or a little more than 12 GB.

I just realized I put 86400 in my calculator as 68400.  I am editing to correct now.

What type of SD card are you using? Based on the capacity, you can calculate SD card storage time to overflow with data/second. Since a character has a size of one byte, the amount of data used per day should be 30 * 13 * 86400 (sec/day) = 33696000 bytes or 0.033696 gb per day.


text:
OTA updates for Arduino using nRF24L01+
Is it possible to send OTA updates to Arduino via nRF24L01+ module?
Here are my findings:
Here is an instructable explaining how to program Arduino wirelessly but this thing uses a BT module which shows up on PC as a COM port.
Here is something similar using Xbees.
However, these use another arduino attached to a PC on the other end. In my case, I am planning to use rPi hooked to another nRF24L01+ rather than PC.
This is an excerpt from the datasheet of Atmega chip:

In ATmega88A/88PA/168A/168PA/328/328P the Boot LoaderSupport provides
  a real Read-While-Write SelfProgramming mechanism for downloading and
  uploading program code by the MCU itself. This feature allows flexible
  application software updates controlled by the MCU using a
  Flash-resident Boot Loader program. The Boot Loader program can use
  any available data interface and associated protocol to read code and
  write (program) that code into the Flash memory, or readthe code from
  the program memory.

Here is what I planned as a strategy.
Master programmer = Raspberry Pi + nRF module.
Slave arduino = Arduino + nRF24L01 + external EEPROM
Once I have to upload a new code, I can transmit the compiled code to the arduino (I can do that, right?) and Arduino will save it in the external EEPROM for the time being.
When the transfer is complete, I will send a signal which will make the arduino reset and copy the code from EEPROM to its flash memory.
My questions:
Is the strategy correct and feasible?
How should I proceed to achieve it?
Any other suggestions which you might have are welcome.

Using external EEPROM would make your bootloader a lot simpler to write, and would make things more robust. Sound feasible to me.

Not sure what protocol you're using on top of ESB, but you should be aware that the 16 bit CRC provided by the nRF24L01 is not sufficient to protect a firmware upload.  Your algorithm should have a stronger test (e.g. a CRC over the entire FW) before it accepts the new image.

@Ben - I was skeptical about the data integrity. That's why I am planning to verify it first and store it in an external EEPROM first. Once the data is checked, then only the stored code will be applied to micro-controller.

Perhaps http://forum.arduino.cc/index.php?topic=332191.0 can lead to examples how to reprogram the flash from an own sketch...

You can investigate how MySensor does it. I'm fairly certain it'd help you.

Your best strategy would be to write your own bootloader.
The existing bootloader receives data through the serial port and writes it, a page at a time, to the flash.  Your custom bootloader, instead, would receive the data through the nRF module and write it to flash, a page at a time.
You could use the source code for the existing bootloader (maybe use optiboot?) as a starting point and remove the UART code, replacing it with nRF code.
Of course, you still need a way to enter the bootloader when you want to program it - the easiest way is to ensure that is added into any sketch you upload so you can send an instruction to that sketch to enter the bootloader.
You would also need to create a program on the Pi to do the programming over the air - or modify an existing one like avrdude.
It may, in the long run, be simpler to have a pair of other Arduinos (maybe something small like an ATTiny based board) to act as bridges between UART and the nRF modules so they become a transparent wireless serial link.

There is an Arduino optiboot fork for this now, which seems to handle what you want.
You would use a PC, RPi or whatever that could run avrdude to send the update to an Arduino acting as the update server, which transmits the code to the client.
The instructions on the page seem quite comprehensive.

Thanks Kurt for answering. I will look into it. Hopefully a modified version of this might help in my future projects. However I have moved to esp8266 now following the terrible range of nRFs. Esp has added benefit of pre-defined data transfer protocols and recently OTA updates for ESP have been released in ESP arduino library. Seems like esps are better choice as compared to nRFs due to good range and better data transfer reliability. Moreover, for simple work, I don't even need another arduino hooked to esp.

Did anyone was able to make this work? I have used https://github.com/nicolas-schurando/optiboot-nrf24l01-flasher and https://github.com/nicolas-schurando/optiboot-nrf24l01 was able to burn the bootloader and the flasher (remote has bootloader and local has flasher) but I am not sure which avrdude command to use in order to burn the remote station - it seems to always overwrite my local arduino and remove the flasher sketch from it - instead of forwarding it...

If you're working with remote sensor nodes, perhaps consider the MySensors library.
It's got support for two methods of delivering OTA updates - one using a node.js controller running on a rPi; and another third-party solution with a .NET front-end.
Failing that, you could borrow the bootloader code from the library and customise to your own needs.

As per @Majenko and @Kurt suggestions:
Please check out me blog post, it is exactly about that!
https://www.2bitornot2bit.com/blog/arduino-bootloader-with-ota-over-the-air-support-over-nrf24l01
I have made a complete tutorial about this issue and also modified the suggested code above so debugging will be easier.
The basic idea is to have a local station which forwards the new sketch from the computer->uart->spi->rf24 to a remote Arduino running a custom bootloader which listens on the rf24->spi instead of the UART. This bootloader does everything as usual (expecting protocol commands as part of the stk500 protocol and so on) but, instead of getting them over UART the packets arrive from the RF24 module through SPI.
During boot, the bootloader will have to initialize the RF module registers and then parse the incoming bytes if any; after a timeout, it will quit and run the sketch currently there in a loog as usual
In my blog you will see some notes about the Hardware configuration for the local station: you need a 10uF capacitor between the RESET and GND pins to avoid flashing the local station while trying to flash the remote station.
That post also incldues the commands needed to use AVRdude to flash the bootloader and then to flash the remote station (which has the new bootlaoder) through the local station running the "flasher" sketch (station with the capacitor).
Basic commands are:
avrdude -C "C:\Users\Ben\Downloads\avrdude\etc\avrdude.conf" -b 19200 -c usbtiny -p m328p -v -e -U efuse:w:0xFD:m -U hfuse:w:0xDA:m -U lfuse:w:0xFF:m -F
avrdude -C "C:\Users\Ben\Downloads\avrdude\etc\avrdude.conf" -b 19200 -c usbtiny -p m328p -v -e -U flash:w:optiboot_atmega328_new_bootlader.hex -U lock:w:0x0F:m

You can find the code on my blog and links to other sources and tools needed
(such as an AVR programmer).

While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference.  Link-only answers can become invalid if the linked page changes. - From Review

@jfpoilpret added description, feels like anything is missing?

It's definitely feasible and it's been done. Look at Low Power Labs site where Felix did the same thing, but with a RF69 radio and an external flash chip. You do need a modified bootloader as he uses, one that would detect the new sketch in the external flash and will upload it to the Arduino on reset. Radio difference aside this should work well for your purposes.
Given the flaky nature of the radio communication I think it's a good idea to store the program separately rather than create a highly modified bootloader which will read the radio stream - it might be that for programming you need a constant stream of bytes which the radio can't always provide (though I'm not 100% sure about this); another reason being that the extra code you would need to access the radio will make for a larger bootloader.

I was skeptical about the data integrity. That's why I am planning to verify it first and store it in an external EEPROM first. Once the data is checked, then only the stored code will be applied to micro-controller. Thanks for that article. I will go through it.


text:
Need help writing to and then reading from a serial device
I have a serial device hooked up to my Arduino (ESP32 WROOM). I'm not a serial expert but I have at least some stuff working. The manual is chinese (or at least, very broken english) and I'm trying to make sense of it.
The device needs to be configured as such:

Baud rate: 115200
Word width: 8bit
Stop bit: 1
Parity: None
Flow control: none (no idea what that is?)
Receive/send settings: ASCII

I would assume that is done by doing: (it's on RX2/TX2)
MMWave.begin(115200, SERIAL_8N1, 16, 17);
When I try the following code I get the output from the device as expected:
#include <Arduino.h>

HardwareSerial MMWave(1);
const byte numChars = 32;
char receivedChars[numChars];   // an array to store the received data
bool newData = false;

void setup() {
    Serial.begin(115200);
    MMWave.begin(115200, SERIAL_8N1, 16, 17);
}

bool sent = false;

void loop() {
    byte index = 0;
    while(MMWave.available() > 0) {
        char rc = MMWave.read();
        receivedChars[index] = rc;
        index++;

        if (rc == '\n') {
            Serial.print(receivedChars);
            index = 0;
            delay(1000);
        }
    }
}

The output is exactly as in the manual:
mov, dis=2.95
mov, dis=2.83
mov, dis=2.83

Now comes the problem, I can write parameters to the device as well. They say to send/receive data in ASCII in the manual and that when I write the command "get_all" to the device I should get a response returning all the current configuration parameters.
If I do not get the feedback from the device the manual tell me to make sure that the command is sent "with a carriage return and line feed".
I would expect that when I:
MMWave.write("get_all");
MMWave.write('\r');
MMWave.write('\n');

And then use the above code to read again...I would get the output from the command. But instead it keeps outputing the mov lines (default output) and it doesn't respond at all to my command. I also tried to:
MMWave.println("get_all");

And
MMWave.print("get_all\r\n");

Nothing seems to work. Any advice would be greatly appreciated. I have read alot of serial introduction stuff but I can't seem to match the correct info to my use case.
Thank you guys in advance!
For anyone interested the manual can be downloaded here: Sensor manual

Try String myCMD="get_all";  myCMD += "\r\n";     MMWave.print(myCMD);  Looks like you are using some kind of serial assist program...and with no docs - you don't need to do that.

for RX2/TX2 I would use Serial2

Ì have switched over to Serial2 and tried the myCMD approach. Both to no avail, the output is still decent but the output from get_all doesn't show at all.

Note that your three ways of sending "get_all\r\n" are strictly equivalent.

That is what I thought @EdgarBonet but it returns nothing none the less.
Sometimes something but almost always nothing.


text:
Atmega328P - SCK pin
I am using Atmega328p with arduino bootloader in a project. There happens to be an LED connected on SCK pin. During Start (or restarts), the LED appears to flicker a couple of times (3 times to be exact). I don't want this to happen. I can change the connections but I would prefer a software solution because hardware change means a PCB modification.
I probed the SCK pin and I got some expected waveforms. There were two different cases:
1) When I powered the arduino using USB to serial programmer i.e. Tx Rx connected to a PC:

2) When I powered the arduino with an external power source (the case with my project):

This is what I think:
1) As mentioned in this thread, the bootloader has a piece of code which makes it act that way.
The bootloader code has a pin definition file which declares SCK pin as a LED and blinks it a couple of times to indicate that it has entered the bootloader. I found the code here:
#if defined(__AVR_ATmega168__) || defined(__AVR_ATmega328P__) || defined(__AVR_ATmega328__) || defined(__AVR_ATmega88) || defined(__AVR_ATmega8__) || defined(__AVR_ATmega88__)
/* Onboard LED is connected to pin PB5 in Arduino NG, Diecimila, and Duemilanove */
#define LED_DDR     DDRB
#define LED_PORT    PORTB
#define LED_PIN     PINB
#define LED         PINB5

Other relevant piece of code is here.
In this case, changing the LED definition to PINB4 and burning the bootloader and program again should take care of the issue. However this didn't work out for me. This is what I did exactly:
a) Opened the file D:\Program Files (x86)\Arduino\hardware\arduino\avr\bootloaders\optiboot\pin_defs.h
b) Modified the PINB5 to PINB4 on line 6.
c) Saved the file, burnt the bootloader and then program.
d) Powered up the chip and tested whether I am getting those 3 pulses. I got those 3 pulses.
(Even though it didn't work, I am still going to try it a few more times just in case I might have made an error.) :(
2) This brings me to second thought that since atmega328 accepts code through SPI by default, it checks for incoming data by clocking the SCK pins 3 times during startup. In this case, a software fix won't do anything.
What do you guys suggest? Should I go for the PCB modification or is there still some hope left?
Ignacio pointed out that I can disable bootloader to get rid of the issue. I want to program the chip using arduino IDE (preferably via UART) but I can consider SPI as well in case everything else fails.
Note: I am not sure whether this post is more suited for EE or Arduino. In case you guys(mods) think I'd get better suggestions there, feel free to move my post to Arduino.

Can you explain in more detail how modifying the bootloader "didn't work out"?

I modified PINB5 to PINB4, burnt the bootloader, burnt the code and powered the circuit. I was still getting the same 3 pulses.

It might make more sense to set LED_START_FLASHES to 0. There is code in the file you linked to that does that as long as it hasn't been defined elsewhere.

I can try that Dave. I am more of a hardware guy rather than coder. I'll try what you suggested and update my question. Thanks

In that case, you need help from the people who understand the details of the Arduino software. Migrating.

"Saved the file, burnt the bootloader and then program." - didn't you miss out the step where you actually compile the bootloader with your new settings in it?

Do I need to do that? I didn't know that part. Can you please tell me how to do that? I thought arduino will pick the settings on the fly as it does for board definitions. (I changed the extended fuse settings in the boards file and it worked directly)

https://github.com/Optiboot/optiboot/wiki/CompilingOptiboot

As Majenko said, the bootloader is an HEX file, i.e. pre-compiled. You will need to compile it again; search for optiboot and, if needed, download the sources and compile them; you will need to program it with an SPI programmer, though

Thanks majenko and frarugi. I am stuck with the steps that I need to follow. Can you please give me exact steps required to compile? I can do the edits and burning easily. I am just having hard time figuring out the exact command to compile.

I compiled Optiboot a while back using the shell script below. This is for Linux, you may need to adapt slightly for other operating systems.
BIN_LOCATION='/home/nick/Development/arduino-1.6.5-r5/hardware/tools/avr/bin'

$BIN_LOCATION/avr-gcc -mmcu=atmega328p \
    -D__AVR_ATmega328P__ \
    -DF_CPU=16000000L \
    -DBOOTLOADER_ADDRESS=7E00\
    -DBAUD_RATE=115200 \
    -DLED_START_FLASHES=0 \
    -DOPTIBOOT_FIX=1 \
    -Os \
    -gdwarf-2 \
    -fno-inline-small-functions \
    -fno-split-wide-types \
    -fno-tree-scev-cprop  \
    -fno-exceptions -ffunction-sections -fdata-sections \
    -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums -fno-jump-tables  \
    -fno-keep-inline-functions -fno-common \
    -std=gnu99 \
    -Wl,--section-start=.text=7E00 \
    -Wl,--relax -nostartfiles \
    -Wl,--gc-sections \
    -ooptiboot.elf optiboot.c

rm -f optiboot.hex

$BIN_LOCATION/avr-objcopy -O ihex --set-section-flags=.eeprom=alloc,load \
    --no-change-warnings \
    --change-section-lma \
    .eeprom=0 \
    -R .eeprom optiboot.elf optiboot.hex

$BIN_LOCATION/avr-objdump -j .sec1 -d -m avr5 optiboot.hex > optiboot.lst

You will need to find where your copy of avr-gcc and insert that into the first line above.
Notice I have changed the define for LED_START_FLASHES to be zero above. That should fix the issue.
To save you the trouble of doing that, I have made a "no blink" version for the Atmega328 and put it here:
http://gammon.com.au/Arduino/optiboot_no_blink_atmega328.hex
Warning - the script above compiled the "no blink" version OK, but using the latest version of the Optiboot.c code, and the latest compiler, makes a .hex file that is four bytes too long, for reasons I can't work out. However it compiles fine if you omit the blinks, because there is less code there.

Note re the LED on D13. Because the LED is driven by an op-amp (on the Uno), it will flash even with the above code. However that is because the op-amp has a high-impedance input. If you use a pull-down resistor on D13 it won't flash.

Now that I look at the download, it is so short I may as well include it here:
:107E0000112482E08093C00088E18093C10086E065
:107E10008093C20080E18093C40084B714BE81FFC8
:107E2000C8D088E1809360008DE080936000259A3F
:107E300018E108E033E0F32EEE24EA94DD24D39435
:107E400045E0C42E51E1B52EA7D0813429F481E05C
:107E5000BED083E09AD096C0823419F484E1B7D0C2
:107E600091C0853419F485E0B2D08CC0853599F481
:107E700093D0C82FD0E0D0930102C09300028CD0E1
:107E80009E01382BC901880F991F9093010280939E
:107E9000000297D077C0863529F484E098D080E03E
:107EA00074D070C0843609F042C07ED0E0910002E8
:107EB000F0910102F0925700E895C0E0D1E002C0D5
:107EC0006BD089938C2F90910202C917C8F38C1B39
:107ED00001C0E9929C2F980F9034D8F372D007B666
:107EE00000FCFDCF40910002509101029A01A0E0F8
:107EF000B1E08C911296FD013197608190E0962B54
:107F0000F9010C01D0925700E89511242E5F3F4FE4
:107F1000A038F1E0BF0769F7FA01C0925700E89571
:107F200007B600FCFDCFB0925700E8952BC0843710
:107F3000B1F43AD046D0E0910002F0910102CF01B5
:107F40000196909301028093000284911ED080914B
:107F500002028150809302028111EDCF13C0853758
:107F600041F42FD08EE111D085E90FD08FE00DD0F4
:107F700009C0813531F4109360000093600021D076
:107F800001C01FD080E101D05FCF9091C00095FF6C
:107F9000FCCF8093C6000895A8958091C00087FF0C
:107FA000FCCF8091C6000895F7DFF6DF80930202D0
:107FB000F3CFE0E6F0E088E180831082EE27FF2730
:107FC0000994EADF803209F0F4DF84E1DECFCF9359
:0C7FD000C82FE2DFC150E9F7CF91F3CFDA
:0400000300007E007B
:00000001FF

Just save that as optiboot.hex.

Thanks a lot, Nick. I'll be using the hex file that you generated for me. I really appreciate your help and efforts. I'll give it a go and update you about the results. Have a nice day, Sir.

I downloaded the file and burnt the bootloader. The issue went away. Thanks a lot Nick. You helped more than I asked for.

Hey Nick, the bootloader seems to be causing some RESET issues. Can you check once. Sometimes I feel that I am having difficulty uploading code or resetting the chip by grounding the RESET pin. Can you check if you disabled the reset pin in the bootloader? Thanks

It isn't possible to disable the reset pin, whatever bootloader you use. You might do it with a fuse setting, but the bootloader itself can't do it.

I posted a new question here. Can you please take a look? Thanks

There is nothing in the default megaAVR initialization that causes SCK to behave in this manner; it is all caused by the bootloader.
Fortunately all you have to do to solve this is disable the bootloader. Unprogramming the BOOTRST fuse (ext:0) will cause execution to start at address 0 instead of the beginning of the bootloader on reset.

But then I won't be able to program the chip using Arduino IDE. I need that functionality. Any other suggestion?

Sure you will. You'll simply program it via ISP instead of serial.

Ohh that's what you meant. I can consider this option. However is there a way I can keep UART programming feature intact?

If I was going to then I'd just remove the whole LED blinking part. Which I wouldn't, because I'm far too used to ISP to put up with serial programming.

Dave suggested something in comments - seems equivalent to deleting the LED blinking part. I was just hoping that there is a code way to do which is there it seems after reading your answer and his comment. I'll give it a try and let you guys know. Thanks a lot for posting the answer. (+1)


text:
Custom Bootloader on Atmega328p - PU - 28 pin DIP
I am experimenting with low-power wireless arduino modules. For that, I needed 3V powered arduino so that I can do away with voltage regulators which eat up a lot of battery juice.
I am using 28 pin Atmega328p-PU dip IC with 8 MHz external crystal oscillator. Just for trying, I dumped the arduino pro mini 3.3V 8 MHz bootloader into it and it was a success. Everything is working as expected. However, I realized that SMD package which is being used in pro mini has 8 ADC pins compared to 6 in the DIP version.
Should I be worried about it?
Second feasible option is modifying the Arduino UNO board definition to use 8 MHz clock source as compared to 16 MHz and leave everything else same. Do you think this will serve my purpose?

The Atmega328p has 8 analog inputs. Some packages (such as the DIP) don't have enough pins to bring all of them out, but they are in there. The SMD package brings all of them out, but it apparently the Pro Mini does not pick up two of them. The net result is the same - 6 useable and 2 unusable analog inputs.

At least the sparkfun Pro Mini has plated-thru holes for A4-A5-A6-A7. Some clones don't have A6-A7, and some have them located near the reset switch

Then, I suppose there shouldn't be a problem with pro mini bootloader on 28 DIP. Thanks for solving the mystery. :)


text:
RF network using Arduino
I am working on home automation project. A network consists of one master device and many (maybe 10-20) slave devices, all communicating via these RF modules. I am using arduino in slave devices. Master will be based on raspberry Pi (most probably). Slave nodes can be sensors or switches(to control household electronics). To and fro communication will include data such as : a) Turn off bulb 1, b) Turn on TV, c) Set the bulb brightness to 34%, d) Temperature reading is 23 degree Celsius etc.
From security point of view, imagine there are similar other networks in the range and one network must not interfere with another. As such, I need to implement some sort of authentication whenever each data transfer takes place between master <---> slave. What logic do you suggest for this process?
There can be cases when data has not been received successfully by the receiving end. In such cases, I am planning to use some sort of checksum and acknowledgement system. If acknowledgement is not received, data will be resend in time intervals of 1s, 5s, 10s, 30s, 30s. If these 5 resends fail, the slave/master will be considered as unavailable/powered down. Your opinions/suggestions on this?
Slave arduino will be busy controlling appliances/sensors connected to it (real busy when controlling appliances). As such, it won't have much time for communication. Less time required for communication == Awesome. How much time do you think the arduino will take to complete one such data transfer?
Another solution I could think of was using two arduinos connected via i2c in each slave module. One arduino will be busy controlling the lights/sensors. Other one will take care of RF communication. If it receives some valuable info which was meant for this particular module, it will transfer the same to the other one using i2c bus. Is this a feasible backup plan?
Am I doing wrong by selecting RF modules for this purpose? Should I switch to Zigbees?
Thanks guys for reading. Any constructive suggestions from your side will be very helpful.

Got any example code ? Then i can throw it on my arduinos and try it out.

There is existing mesh network software for Arduinos. What you are tryingto do is doable but tends to be reinventing te wheel - which has its place :-).

Those are pretty "dump" rf-devices. You'd have to do the entire protocol, and error correction yourself. I'd suggest going with NRF24L01. I've no experience with zigbee (too expensive in my oppinion)

@Magic-Mouse - Sorry, no code yet. I am still to decide what to use. I did some research and I think I should use NRF24L01 as suggested by Gerben

@Gerben - Thanks a lot dude! I did some research and I feel that NRF24L01 is way better than what I was planning to use.

@RussellMcMahon - I agree with you totally. :) That's why I planned to ask before doing so. Since there are easier ways as pointed by others, I am not going to reinvent the wheel now. Anyways thanks for reminding.

NRF24L01 are nice BUT have limited data capacity per "packet" (32 Bytes AFAIR). That is by no means fatal but may be 'annoying'. The ESP8266 modules for about $5 or less give you a full TCPIP/WiFi/Internet access OR can be run as UART bridges (And have their own processor if keen enough an you want to use them as the whole system)

The one thing I don't like about these simple RF modules is that they have absolutely no security. This may be a problem for home automation applications. If you are willing to use wires, then RS485 could be a good option instead, see http://www.gammon.com.au/forum/?id=11428. The chips are quite cheap, you can have multiple devices on the one bus, and the protocol is designed to be robust to noise.

@RussellMcMahon - I did some research and I feel that NRF24L01 might be enough for my job. Basically, I'd be sending simple data such as turn this thing On/Off. Set dimmer level to 23% etc. I guess 32 bytes are more than enough. However, I am planning to explore esp8266 modules because it's capabilities are great. Might use it where I need large data thoroughput. Thanks for the suggestion. :)

@DaveP - I agree with you. I have decided to use NRF24L01 for my project. However I am yet to decide some sort of encryption protocol. Rolling code comes to my mind. Any suggestions?

@user3455594 - I haven't tried any of them, but https://github.com/DavyLandman/AESLib, https://www.das-labor.org/wiki/AVR-Crypto-Lib/en and https://code.google.com/p/avr-hardware-random-number-generation/ have libraries for encryption on AVR/Arduino, and secure random number generation.

The NRF24s are great, but limited to communication only.
Digi's XBee 2mW module has got great indoor range, but more to the point it's got 8 I/O lines and 6 10-bit ADCs on board. It's also built for mesh networks (or you can get star-network equivalents) and has security encryption to boot. This means that, for some of your nodes, you don't need any other hardware to have a fully functioning control point (not including relays and sensors of course), so you can ditch having arduinos at every node.
They're so easy to use, very low power, and have plenty of support and documentation available online.
Do it!


text:
Atmega328P constantly restarting when defining a function
I wanted to make a simple led on/off program using USART interface. When the code doesn't have any functions other than main it runs fine, however Arduino keeps resetting when one is included. At this point I have no clue what could I be doing wrong. Here's the code:
#include <avr/io.h>
#include <util/delay.h>

#define BAUD 19200
#define BAUDRATE ((F_CPU / 16 / BAUD) - 1)

// void init()
// {
//     // Keeps resetting when uncommented, runs fine when commented
// }

int main() {
    // Initialize USART
    UBRR0H = (BAUDRATE >> 8);
    UBRR0L = BAUDRATE;
    UCSR0B = (1 << RXEN0);
    UCSR0C = (1 << UCSZ01) | (1 << UCSZ00);
    // Set bit 3 to output and pull it high
    DDRD |= 0b00001000;
    PORTD = 0b00001000;

    char char_arr[128];

    while(1)
    {
        int i;
        // Read USART
        for(i = 0; i < 128; i++){
            loop_until_bit_is_set(UCSR0A, RXC0);
            char c = UDR0;
            if(c == '\r')
                break;
            char_arr[i] = c;
        }
        // Handle received characters
        for(int j = 0; j < i; j++){
            switch(char_arr[j]){
                case '1':
                    PORTD = 0b00001000;
                    break;
                case '0':
                    PORTD = 0b00000000;
                    break;
            }
            _delay_ms(100);
        }
    }
}

Does this happen if the function has a name other than init()?

@EdgarBonet yes, function name doesn't matter

the compiler should remove that function during optimization, because the function is not used .... maybe the problem is in the compiler command line


text:
Arduino hangs / freezes - can't figure out why
I am building a remote controlled boat. My remote project freezes after an arbitrary amount of time. The serial stops output, the OLED doesn't update anymore and instructions are not send / received anymore.
For the life of me I cannot figure out why my project freezes. Using an Arduino Nano.
I have tried the following:

Keep memory small
Disable Serial as not to overflood
Not use any risky variables; like String
Determine if a specific circumstance causes the hang (X amount of time, certain instructions, losing radio connection, etc)
Replace the Arduino
Replace the power supply
Replace the power supply cable
Put the radio into debug mode, it becomes slow and nothing interesting shows on serial

Please provide help to allow me to continue my two-year long project. My gratitude for any pointers or help is unending.
The Arduino is connected to a NRF24L01 with adapter board, an OLED and two potentiometers.
This is my code:
#include <SPI.h>
#include "printf.h"
#include "RF24.h"
#include "SSD1306Ascii.h"
#include "SSD1306AsciiAvrI2c.h"
#include <DifferentialSteering.h>

// Debugging mode:
int debugging_serial = 0;
int debugging_delay = 0;
int debugging_verbose = 0;

// Timers init;
unsigned long start_timer = 0;
unsigned long end_timer = 0;

// Oled state for clearing
int oledstate = 0;

// Create nRF24L01 transceiver using pins 9 and 10.
RF24 radio(9, 10);

// OLED init
#define I2C_ADDRESS 0x3C // 0X3C+SA0 - 0x3C or 0x3D
#define RST_PIN -1 // Define proper RST_PIN if required.
SSD1306AsciiAvrI2c oled;

// Set potentio meter pins
int pot_one_pin = A0;
int pot_two_pin = A1;

// Set Diff Steering
DifferentialSteering DiffSteer;

// Register two radio addresses to use for communication.
uint8_t address[][6] = { "1Node", "2Node" };

// Define sending and receiving payload structs. Note: these should be inversed on remote vs boat code
// DEFINE WHAT WE WILL BE SENDING
struct SendingPayloadObject
{
  // We are sending two numbers
  uint8_t Motor1Speed;
  uint8_t Motor2Speed;
};
// Also create the payload object to prepare and load with defaults in setup
SendingPayloadObject payload;

// DEFINE WHAT WE WILL BE RECEIVING
struct ReceivingPayloadObject
{
  // We are sending a message and a number
  char message[7];  // only using 6 characters for TX & ACK payloads
  uint8_t counter; // struct counter variable as example
};

void setup()
{
  if(debugging_serial)
  {
    Serial.begin(115200);
    Serial.println("Remote Code Started!");
  }

  // Oled setup
  // Call oled.setI2cClock(frequency) to change from the default frequency.
  oled.begin(&Adafruit128x64, I2C_ADDRESS, RST_PIN);
  //oled.setFont(System5x7);
  oled.clear();
  oled.println("Boat Remote Started!");
  oled.clear();

  // Check if radio works
  if (!radio.begin())
  {
    if(debugging_serial)
    {
      Serial.println(F("Radio hardware is not responding!"));
    }

    while (1) {}  // hold
  }

  // Set the PA Level low to try preventing power supply related problems
  // because these examples are likely run with nodes in close proximity to
  // each other. (RF24_PA_MAX is default)
  radio.setPALevel(RF24_PA_LOW);

  // To use ACK payloads, we need to enable dynamic payload lengths (for all nodes). ACK payloads are dynamically sized
  radio.enableDynamicPayloads();

  // Acknowledgement packets have no payloads by default. We need to enable this feature for all nodes (TX & RX) to use ACK payloads.
  radio.enableAckPayload();

  // Set the TX address of the RX node into the TX pipe and the opposite to the RX pipe. The remote radio address is 1!
  radio.openWritingPipe(address[1]);
  radio.openReadingPipe(1, address[0]);

  // Sender role code
  // Set payload defaults and put radio in send (TX) mode
  payload.Motor1Speed = 0;  // set the payload payloadMotor1Speed
  payload.Motor2Speed = 0;  // set the payload payloadMotor1Speed
  radio.stopListening();                 // put radio in TX mode

  if(debugging_verbose)
  {
    printf_begin();             // needed only once for printing details
    radio.printDetails();       // (smaller) function that prints raw register values
    radio.printPrettyDetails(); // (larger) function that prints human readable data
  }

  // DiffSteer init
  DiffSteer.begin(0);
}

void loop()
{
  //// REMOTE CONTROL STUFF:

  // NEW LOGIC FOR MANEURVERING
  int motorSpeed1 = 0;
  int motorSpeed2 = 0;

  // Steering using potentiometers
  int steering_pot_value = map(analogRead(pot_two_pin), 0, 1023, -127, 127);
  int power_pot_value = map(analogRead(pot_one_pin), 0, 1023, 0, 127);

  // Go Straight when steering almost straight
  if(steering_pot_value <= 15 && steering_pot_value >= -15)
  {
    steering_pot_value = 0;
  }

  // Compute differential steering
  DiffSteer.computeMotors(steering_pot_value, power_pot_value);

  // map motor outputs to needed range
  motorSpeed1 = map(DiffSteer.computedLeftMotor(), 0, 127, 0, 255);
  motorSpeed2 = map(DiffSteer.computedRightMotor(), 0, 127, 0, 255);

  // Corrective measures for smoother steering
  // Fix division by 0, full power when pot completley off
  if(power_pot_value <= 1) { motorSpeed1 = 0; motorSpeed2 = 0; };

  // OLED motor control code (for testing)
  //  Speeds directley from pot meters
  //  motorSpeed1 = map(analogRead(pot_one_pin), 0, 1023, 0, 255);
  //  motorSpeed2 = map(analogRead(pot_two_pin), 0, 1023, 0, 255);
  //

  // Set motor speeds in payload
  payload.Motor1Speed = motorSpeed1;
  payload.Motor2Speed = motorSpeed2;

  //// RADIO STUFF:

  // Let's time the tranmission for maagd / nerd purposes
  if(debugging_serial)
  {
     start_timer = micros();                  // start the timer
  }

  // Send over radio TX;
  bool report = radio.write(&payload, sizeof(payload));  // transmit & save the report

  if(debugging_serial)
  {
    end_timer = micros();                    // end the timer
  }

  if (report)
  {
    if(debugging_serial)
    {
      Serial.print(F("Time to transmit = "));
      Serial.print(end_timer - start_timer);  // print the timer result
      Serial.print(F(" us. Sent (Motor 1 Speed: "));
      Serial.print(payload.Motor1Speed);
      Serial.print(F(" , Motor 2 Speed: "));
      Serial.print(payload.Motor2Speed);
      Serial.print(F(")"));
    }

    // Define the pipe
    uint8_t pipe;

    if (radio.available(&pipe))
    {
      if (oledstate != 1) { oled.clear(); }; oledstate = 1;
      oled.set1X();
      oled.setFont(System5x7);
      oled.setCursor(0 , 0);
      oled.print("Transmission OK \n");
      oled.setCursor(0 , 30);
      oled.print("Motors L:");
      // Add leading zeroes to get true values (otherwise old number remains)
      if(payload.Motor1Speed < 100 && payload.Motor1Speed >= 10) { oled.print("0"); };
      if(payload.Motor1Speed < 10) { oled.print("00"); };
      oled.print(payload.Motor1Speed);
      oled.setCursor(80 , 30);
      oled.print("R:");
      if(payload.Motor2Speed < 100 && payload.Motor2Speed >= 10) { oled.print("0"); };
      if(payload.Motor2Speed < 10) { oled.print("00"); };
      oled.print(payload.Motor2Speed);

      // is there an ACK payload? grab the pipe number that received it
      ReceivingPayloadObject received;
      radio.read(&received, sizeof(received));  // get incoming ACK payload

      if(debugging_serial)
      {
        Serial.print(F(" Recieved "));
        Serial.print(radio.getDynamicPayloadSize());  // print incoming payload size
        Serial.print(F(" bytes on pipe "));
        Serial.print(pipe);  // print pipe number that received the ACK
        Serial.print(F(": "));
        Serial.print(received.message);    // print incoming message
        Serial.println(received.counter);  // print incoming counter
      }
    }
    else
    {
      if (oledstate != 2) { oled.clear(); }; oledstate = 2;
      oled.set1X();
      oled.setCursor(0, 0);
      oled.setFont(System5x7);
      oled.print("Transmission: \n \n");
      oled.setCursor(0, 80);
      oled.set2X();
      oled.print("No Reply (empty ACK)");

      if(debugging_serial)
      {
        Serial.println(F(" Recieved: an empty ACK packet"));
      }
    }
  }
  else
  {
    if (oledstate != 3) { oled.clear(); }; oledstate = 3;
    oled.set1X();
    oled.setCursor(0, 0);
    oled.setFont(System5x7);
    oled.print("Transmission: \n \n");
    oled.setCursor(0, 80);
    oled.set2X();
    oled.print("Failed");

    if(debugging_serial)
    {
      Serial.println(F("Transmission failed or timed out"));
    }
  }

  // Add a delay while programming for reading purposes
  if(debugging_verbose)
  {
    delay(10000);
  }
  else
  {
    if(debugging_delay)
    {
      delay(1000);
    }
  }
}

Maybe add to your post the RAM/storage usage statistics which the compiler provides at the end of the output. Also say what board it is.

where does the program hang?

Approaching the problem from another angle, why not use a watchdog to reboot the Arduino when it hangs.

Thanks for your replies! I dont have the usage number at hand, but it was very low. Maybe 30%. Using a Nano. The program hangs somewhere in if radio.availible as far as I can determine. A watchdog is not a great solution as it would render the boat inoperable for some seconds. Looking forward to more thoughts and advice!

You appear to have used a relatively complex nrf24l01 code base for your project which originally supported role swapping between the "transmitter" and "receiver" parts. If you have a single transmitter and a single receiver then a simpler example, also handling ack packets, can be found here: https://forum.arduino.cc/t/simple-nrf24l01-2-4ghz-transceiver-demo/405123/3 .
If you don't use your debugging options, the transmitter is likely to flood the receiver because there is otherwise no pause in the loop().

Thank you for your reply. Can you eloborate a bit on the last part? Why would I want a pause, since I aim to keep control instant and snappy? How would I confirm and prevent a flood event? Can it be set up more like UDP than TCP - speaking in networking terms? @6v6gt

The  receiver will take a finite amount of time to respond to the transmitter. There are also unpredictable effects like retransmissions of either the payload or the acknowledgement affecting the round trip time. You can bring this under some control with the setRetries() method. I guess that at least a 50ms or so pause at the end of the loop would be good but that depends also on what the receiver is doing after the ack is sent. The protocol for handling clean end to end transmission of the data is proprietry "Shock Burst". The options are here: https://nrf24.github.io/RF24/classRF24.html

It would be much easier to help you if we knew what you have. Post an annotated schematic showing exactly how you have wired it including all connections, power, ground and power sources.

A basic rule of debugging complex problems is to simplify the configuration until you get to a working baseline, and then build back up from there, one chunk at a time.
I would start with the simplest possible setup with a single RF transceiver at each end. No other peripherals, no other code; something that simply sends "hello" back and forth at wide spaced intervals - like once per second, to make sure there's no way the RF channel will be overloaded.
Once you get to a baseline where your test configuration will run indefinitely, then start adding code and/or peripherals, one at time, with a long-duration test at each step.  Eventually you will reach a point where the system becomes intermittent; when this happens, back up one step to confirm proper operation, and then repeat this forward/back step until you are convinced that this is the step that produces the errant behavior.
Then divide the last step (the one that produces the bad behavior) into smaller steps, and find out which one of those steps produces the bad behavior, and eventually you will get down to one line of code, or one particular peripheral that causes the problem, and in all likelihood it will be something where you will say "OH! I should have thought of that long ago!".
Just as a last thought - you mentioned the 'if radio.availible()' function as a possible culprit.  You could start the process by, for instance, modifying the library code (you can do this - it's just another bit of Arduino code) so that it simply returns 'true' (or false - doesn't matter) every time it is called. If your system operates OK with this setup, but doesn't operate OK with the original library code, then that may well be the source of the problem.
Looking at the RF24.cpp, I see that available() calls get_status(), so maybe it is get_status() that is hanging up.
Just some thoughts,
Frank


text:
How does Arduino IDE reset a board before flashing? Why doesn't avrdude do it?
I have the beetle board, a Leonardo clone same as in this  question.

Using the reset pin and quick hands on the keyboard, I am able to flash with avrdude and get also the board info with a command line like this:
$ avrdude -c avr109 -p atmega32u4 -P /dev/ttyACM1

And get the output:
Connecting to programmer: .
Found programmer: Id = "CATERIN"; type = S
    Software Version = 1.0; No Hardware Version given.
Programmer supports auto addr increment.
Programmer supports buffered memory access with buffersize=128 bytes.

Programmer supports the following devices:
    Device code: 0x44

avrdude: AVR device initialized and ready to accept instructions

Reading | ################################################## | 100% 0.00s

avrdude: Device signature = 0x1e9587 (probably m32u4)

avrdude: safemode: Fuses OK (E:CB, H:D8, L:FF)

avrdude done.  Thank you.

This is good but when I flash something from the ArduinoIDE I noticed I don't have to reset the board manually by grounding the reset pins, the boot loader starts automatically
How does ArduinoIDE reset the bootloader, some kind of communication on /dev/ttyACM1?

The uploaded Arduino sketch has in the part provided by core a code which waits for a 1200 baud connection on USB. If a 1200 baud connection is established it resets the board to bootloader. The bootloader then starts the com port and waits for the upload.
To reset a board which has in boards.txt upload.use_1200bps_touch=true Arduino IDE opens a 1200 baud connection to the board, then detects the new com port and start avrdude for the upload.


text:
Serial port field greyed out with error on launch (Ubuntu 14,04)
I know this has been asked several times already, but I've nevered seen it asked with an error included on launch.
Here is the message that comes up in the terminal when I launch arduino (with root privileges if thats relevant):
(java:9042): GLib-GIO-CRITICAL **: g_dbus_connection_get_unique_name: assertion 'G_IS_DBUS_CONNECTION (connection)' failed
When I try to compile the code, it gives me the standard, "COM1 NOT FOUND" and a bunch of other errors. I can post the entire error message here.
Any suggestions?

That error has nothing to do with the serial port.

Are you in the dialout group (if I remember what ubuntu calls it) so you have permission to open the serial ports?

Yes, I am in the dialout group.


text:
How to store firmware configuration or image in source-control?
I'm writing an Arduino application in C/C++ and I'm storing my source code in Github.
However, to make my code runnable, I have had to install multiple libraries through the Arduino desktop tool like this:

And I have had to update the firmware and certificates through the Arduino desktop tool like this:

How can I store these firmware updates, library changes and certificates in source control? Is there a binary image I can download and check in? Better yet, is there some plain-text source file that I can check-in to derive such a binary?

For libraries only add comment next to #include with version number and author's name if the library is in Library Manager or the download location if it is not in Manager.
Example:
#include <MemoryFree.h> // https://github.com/mpflaga/Arduino-MemoryFree
#include <Ethernet.h> // Ethernet 2.00

Put NINA firmware version in some comment at the top of the main sketch file. The firmware is part of the Arduino boards package so no need to store it in your repo. If you modified the firmware, publish source code in your fork of the official repository and there you can then release the binary too.
Put public certificate keys and similar files in sketch folder in subfolder called extras or data.
And write a README file for your repository.


text:
Solution needed for sending HTTPs requests from multiple Arduino units in the field
I'm using the Arduino Wifi Nina Library to connect an Arduino Uno Wifi Rev2 to wifi and then using the Arduino HTTP Client library to make HTTP post calls to the internet. It is working. However when I switch from HTTP to HTTPs (ie: switching the port to 443 from 80) the code below fails. I understand This is because I don't have a cert on the Arduino. I need to purchase/obtain a cert and download it to the Arduino.
I need to find a solution to this problem that meets the following constraints I have:

I will only be sending https requests to one URL:
https://api.mailgun.net
The amount of memory storage available on Arduinos is severely constrained
I plan to deploy this Arduino into the field. After I deploy it, I will no longer be able to physically access it to manually update any expired certificates. But the Arduino unit must be able to send HTTPs requests to https://api.mailgun.net in perpetuity.
I plan to deploy not just this Arduino unit, but a fleet of similarly functioning Arduino units with the same functionality. And I need to keep the costs of any certificate(s) to an absolute minimum.

    #include <WiFiNINA.h>
    #include <ArduinoHttpClient.h>

    #define REMOTE_SERVER_DOMAIN "api.mailgun.net"
    #define REMOTE_SERVER_PORT 443
    #define MAILGUN_USER "my-user"
    #define MAILGUN_PASSWORD "my-secret"

    bool sendEmailViaHTTPS()
    {
        WiFiClient wifiClient;
        HttpClient httpClient = HttpClient(wifiClient, REMOTE_SERVER_DOMAIN, REMOTE_SERVER_PORT);
        httpClient.beginRequest();
        httpClient.post("/v3/sandbox7d1aaf2f157f42d8844b1ac4c38a0ef7.mailgun.org/messages");
        httpClient.sendHeader("Content-Type", "application/x-www-form-urlencoded");
        httpClient.sendBasicAuth(MAILGUN_USER, MAILGUN_PASSWORD);
        String postData = String("from=Mailgun%20Sandbox%20%3Cpostmaster%40sandbox7d1aaf2f157f42d8844b1ac4c38a0ef7.mailgun.org%3E&to=Me%20%3Cmyemail%40gmail.com%3E&subject=Hello%20World1&text=Hello%20World2");
        httpClient.sendHeader("Content-Length", postData.length());
        httpClient.beginBody();
        httpClient.print(postData);
        httpClient.endRequest();
        int statusCode = httpClient.responseStatusCode();
        String response = httpClient.responseBody();
        Serial.print("Status code: ");
        Serial.println(statusCode);
        Serial.print("Response: ");
        Serial.println(response);
        return statusCode == 200;
    }

What is the best solution to enabling my Arduino to send HTTPs requests as stated above with the least cost and friction?

You don't need to buy any certificates. Only the server (mailgun.net) requires to buy a certificate, not the client (your Arduino). To validate if the certificate the server is using is valid you need to store the Root CA certificate(s). A lot of Arduino projects skip this step, as it's to complicated, or the Arduino doesn't have enough memory/processing power to handle this.

For secure TCP connection with WiFiNINA library use WiFiSSLClient instead of WiFiClient.
The Arduino firmware in the NINA ESP32 module has certificates of well known CA authorities so the server's certificate verification should work. If necessary, you can add public keys of server certificates to NINA.

Worked! I had to add the root cert corresponding to the server I wanted to access. Thank you!


text:
Real time programming with real time module
If you install a real time clock like DS3231 Real Time Clock Module RTC Sensor High Precision, can you program digital output (such as turning 12VDC valves on) based on day of week and time?
I mean like turning digital output 5 on Friday at 7am for 10 minutes, for example.

Yes you can.  You do have to take into account power fails and reboot procedures.

@RohitGupta Please do not answer in comments. Make an answer. Thank you.

Is this a battery powered project where the solution has to be low power ?

you can program the state of a digital output based on almost any event you can think of, providing that you have a way to detect the event


text:
How to flash program in ESP32-S3?
I build a custom board using ESP32-S3-WROOM-1-N16R2. I gave a two pin jumper for boot pin.

and my reset switch is,

This is my USB Section,

What I did is,

Shorted the Boot connector
Connected the USB Cable
Press the reset switch and released while holding the boot pin to low
Release the boot connection

But I got a problem like,
USB Not recognized..

and my device manager shows
Unknown USB device(Device Descriptor request failed)

Always USB not be detected. I cannot flash my board. Please give guidence to flash program to my board!

There is not enough of the schematic to see exactly what you have done but ensure that pins EN and GPIO0(boot) are pulled high at boot time. Module Datasheet/Schematic: https://www.espressif.com/sites/default/files/documentation/esp32-s3-wroom-1_wroom-1u_datasheet_en.pdf but also look at an example which uses native USB: https://files.seeedstudio.com/wiki/SeeedStudio-XIAO-ESP32S3/res/XIAO_ESP32S3_SCH_v1.1.pdf . When you get the USB device not recognised error, the port is usually blocked until a restart of your PC.

GPIO46 is also significant and not shown.


text:
NodeMCU V3 GOT OVERHEATED AND DIED
My NodeMCU V3 got overheated and died. Please help me figure out what i did wrong.
Brief Desrip: Project is an RC Car on ESPNOW Protocol. Transmitter setup have an Arduino Nano to take values from Two analogue joysticks and sends to a NodeMCU through Tx & Rx Pins, which then Transmits the values to the NodeMCU V3 in my Receiver (An RC CAR) over ESPNOW Protocol. Transmitter side is working perfect.
But, the NodeMCU V3 in my Receiver setup has got overheated and Died during a full throttled action. Here I am attaching the wiring diagram of the receiver setup. Please help me figure out whether there is any issues with the wiring.

Which part died? The NodeMcu or the motor driver?

the wiring diagram is not enough ... please provide info about the motor driver module ... it is unclear how the motor driver is getting 5 V ... looks like the motor driver and the servo are pulling power from GPIO D3

Based on https://lastminuteengineers.com/l298n-dc-stepper-driver-arduino-tutorial/ I'd have (a) ensured that the jumper for the 5v regulator was in place and (b) powered the NodeMCU VIN through the +5v of the motor driver board instead of the 7.4 volts from the battery pack. Have you removed the ENB/+5V jumper ?  What part got hot ? The regulator or the ESP8266 module or what ? Did you simultaneously connect a USB cable to the NodeMCU ?

Hint: A Power Supply the Arduino is Not!

@jsotola Motor Driver module is L298N. and D3 is the ENA pin for Speed regulation.

@PMF The nodeMCU. it got really hot and stopped working. It still gets detected by the pc, but cant upload code, and ESP8266 Module in it gets extremely hot.

@6v6gt Yes, the 5v reg. jumper is in place. previously i used a buck converter to supply 5v to arduino, but the car's motor was not working with its full potential. Now the car's performance was really good. Why this has happeded? from the information i got, the nodemcu is capable of handling a voltage upto 12v. ... :( i have removed the enb 5v jumper for speed regulation. The nodemcu esp8266 has got hot and died. No didn't connect Usb cable along with other power supply.

@NonTechGuyinTech  the L298N is one of the components in the motor driver module ... L298N is not the module itself

@jsotola Could you please tell me what you call an L298N Based motor control module ???

you just did in your comment ... L298N Based motor control module ... the point to my previous comment is that saying it's an L298N module does not specify which actual module it is ... a person cannot expect all of the L298N based modules to be the same ... information is needed, about the module you are using

Based on https://lastminuteengineers.com/l298n-dc-stepper-driver-arduino-tutorial/, you have wired your servo incorrectly. The third pin on the bottom blue connector (VSS) is the second input, not the output.

I can only speculate what happened, but I suspect that the servo tried to draw power from the D4 pin which overloaded and fried some internal circuitry of the ESP8266.

The Arduino Cookbook is a good reference to have. First skim it then zero in on sections that are pertinent to your project.


text:
How to control camera lens by Arduino's PWM? What FOCUS A+, FOCUS A- wires means?
I have a camera lens which I want to control by arduino (like this https://vi.aliexpress.com/item/1005004141070063.html)
I have an info about wires description but I can't understand what focus A+, A-, B+, B- means? I guess I need to send PWM pulses to A and B wires to move focus in straigt and opposite direction but I can't understand what + and - means. Is it just signal and ground?

It looks like you will be dealing with bipolar stepper motors. Most
likely, A+ and A− are connected to one coil, whereas B+ and B− are
connected to the other coil.
See the Arduino documentation: Arduino and Stepper Motor
Configurations for instructions on driving this kind of motor.