text:
Remap SPI functions to default pins Arduino Zero via software?
I am looking at the documentation for the Arduino Zero, and I am a little confused.
It indicates that pins 13, 12, and 11 can be used for CIPO, COPI and SCK, but using SPI.begin() puts the signals on the 6-pin header SPI pinout, which makes sense since it is designated for SPI.
Is there a way to switch to the digital pins via C code? Or do I need to edit the header files?  We are using another board that can only attach to the digital pins.

it looks like SERCOM1 could be configured as SPI on pins 11, 12, 13, but how do you want to use it?

I am sending a 32-bit word to another device via SPI protocol, and want to use all the same functions as the 6-pin header on the default digital pins.  I tried some pin mapping with the SERCOM but the code didn't seem to work.

the guide doesn't show how to use SERCOM for SPI, but similar approach as for Wire should work: https://docs.arduino.cc/tutorials/communication/SamdSercom

guide for SPI by Adafruit https://learn.adafruit.com/using-atsamd21-sercom-to-add-more-spi-i2c-serial-ports/creating-a-new-spi

EDIT: Provably wrong answer below, see comments from though.

Unfortuantely the Arduino Zero doesn't support remapping of SPI pins as far as I know. Many other modern boards do, like the ESP8266/ESP32, but not the Zero, at least as far as I can tell.

That's really unfortunate if that's the case. Why would they include the SPI options on the digital pins on the documentation?  Or is it just outdated? https://docs.arduino.cc/static/b1fbc77f1b73dcd9ac379af596e3472e/ABX00003-full-pinout.pdf

@eramirez2024 That it can't be remapped doesn't mean it has only one SERCOM, you can probably use another one. For example SERCOM0 is on pins PA04..PA07

@KIIV Apologies, I didn’t realize the Zero ran on the SAMD21, and I am not super knowledgeable about SERCOM, however I found this extremely relevant guide that may help (particularly pages 11-14) https://cdn-learn.adafruit.com/downloads/pdf/using-atsamd21-sercom-to-add-more-spi-i2c-serial-ports.pdf


text:
try to send AT commands from Arduino nano to ESP01
I encountered an issue when I try to send AT commands from Arduino nano to ESP01 I tried to find any tutorial for more helps, but I find nothing. please someone can help me.
I tried the tutorial from this link.
https://electronicslovers.com/2017/11/learn-how-to-setup-wifi-module-esp8266.html
But nothing happens when I type AT in serial monitor. I didn't see any response from the ESP module.

maybe the two modules are not connected together

Show your code. There are some errors in the code in the text of the linked article. For example,  here if(a != ‘r’ && a != ‘n’ && (a < 32)) the 'n' should be '\n'  (new line character). Did you notice that the wiring diagram shows the top view of the ESP-01 module, not the underside which nomally you'd make the connections to.

I really connect them together as shown in the diagram on the site and I also already fixed the error in the code then I upload the code in the Arduino but always nothing.

I notice all you say 6v6gt but it's impossible communicate both microcontrollers.

this is my code.
`#include <SoftwareSerial.h>
SoftwareSerial softSerial(3, 2); // RX, TX
void setup()
{
uint32_t baud = 9600;
Serial.begin(baud);
softSerial.begin(baud);
Serial.print("SETUP!! @");
Serial.println(baud);
}
void loop()
{
while(softSerial.available() > 0)
{
char a = softSerial.read();
if(a == '\0')
continue;
if(a != '\r' && a != '\n' && (a < 32))
continue;
Serial.print(a);
}`

the other part of the code here
while(Serial.available() > 0)     {       char a = Serial.read();       Serial.write(a);       softSerial.write(a);     } }

Please put the code in your original question as comments are unsuitable for long pieces of code and it is very difficult to read.
The code does not anyway appear to match the diagram in your linked article. RX of one device should be connected to TX of the other device. Try: SoftwareSerial softSerial(2, 3); // RX, TX note 2&3 intercahnged .

source: Stack Exchange

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

sort: votes


text:
Arduino sketch doesn't work when uploaded to arduino nano and OLED display shows npothing (possible issue: lack of memory)
I need some hand here. I wrote some code for a small arduino console-like device that has five pushbuttons, 128x64 I2C OLED display and arduino nano. And it doesn't work when uploaded to arduino nano - display goes blank.
Anamnesis: The Code includes two classes: menu class and button class. When I upload the code on my device - it doesn’t display anything on oled but arduino still executes the code. Wiring is not an issue. But when I remove games_menu or pongLevel_menu or settings_menu and sound_menu from class objects and comment lines where these objects are used, the code works just fine.
Question: Maybe the thing is that arduino nano has some kind of memory, where it stores class objects, and my code uses too much of this memory. Since I am kinda new to arduino and programming - I can make mistakes. Can you please help me with this problem? Minimum reproducible code (sorry, I know that it looks like a big chunk of code but that's what I can shrink it to so that it still reproduces the problem):
#include "Wire.h"
#include "Adafruit_GFX.h"
#include "Adafruit_SSD1306.h"
Adafruit_SSD1306 display(128, 64, &Wire, -1);
//------------variables-------------
    //--------menu variables--------
    unsigned long sec;
    byte selY = 12;
    boolean up;
    boolean down;
    boolean left;
    boolean right;
    boolean a;
    boolean b;
    int location = 0;

    //--------stopwatch variables--------
    unsigned long startTime;
    bool stTimeB = 1;
    unsigned long millisec;
    byte seconds;
    byte minutes;
    byte hours;
//--------classes-------
    //----class menu----
    class menu {
    public:
      menu(String caption, String item1, String item2, String item3, String item4, unsigned int minn, unsigned int maxx);
      void play();

    private:
     String cap;
     String it1;
     String it2;
     String it3;
     String it4;
     unsigned int _min;
     unsigned int _max;
  };
  menu::menu(String caption, String item1, String item2, String item3, String item4, unsigned int minn, unsigned int maxx){
    cap = caption;
    it1 = item1;
    it2 = item2;
    it3 = item3;
    it4 = item4;
    _min = minn;
    _max = maxx;

    }

  void menu::play(){
    if(up == 1 && millis() - sec > 199){
      selY -= 10;
      sec = millis();
    }
    if(down == 1 && millis() - sec > 199){
      selY += 10;
      sec = millis();
    }
    if(selY < _min){
      selY = _max;
    }
    if(selY > _max){
      selY = _min;
    }

    display.clearDisplay();
    display.setTextSize(1);
    display.setTextColor(WHITE);
    display.setCursor(50, 0);
    display.print(cap);
    display.drawLine(0, 9, 128, 9, WHITE);
    display.setCursor(6, 13);
    display.print(it1);
    display.setCursor(6, 23);
    display.print(it2);
    display.setCursor(6, 33);
    display.print(it3);
    display.setCursor(6, 43);
    display.print(it4);
    display.drawRoundRect(1, selY, 122, 11, 4, WHITE);
    display.display();

  }
    //--------class button--------
    class button {
  public:
    button(byte xx, byte yy, byte rr, byte var, String caption11, String caption22, String type_, byte tSize);
    void disp();
    void changeCap(bool caption);
    bool getStatus();
    void update_();

  private:
   byte x;
   byte y;
   byte r;
   byte txtSize;
   bool capB = 0; // 1
   bool pres = 0;
   byte btnPin;
   String caption1;
   String caption2;
   String type;
};
button::button(byte xx, byte yy, byte rr, byte var, String caption11, String caption22, String type_, byte tSize){
  x = xx;
  y = yy;
  r = rr;
  btnPin = var;
  caption1 = caption11;
  caption2 = caption22;
  type = type_;
  txtSize = tSize;
  }

void button::disp(){
  display.setTextSize(txtSize);
  if(pres == 0){
    display.drawRoundRect(x, y, (((caption1.length() + 2)*(5*txtSize)) + (caption1.length() - 1)), ((7+4)*txtSize), r, WHITE);
    display.setTextColor(WHITE);
  }
  else{
    display.fillRoundRect(x, y, (((caption2.length() + 2)*(5*txtSize)) + (caption2.length() - 1)), ((7+4)*txtSize), r, WHITE);
    display.setTextColor(BLACK);
  }

  if(pres == 0){display.setTextColor(WHITE); }
  if(pres == 1){display.setTextColor(BLACK);}

  if(capB == 0){
    if(pres == 1){display.setTextColor(BLACK);}
    if(pres == 0){display.setTextColor(WHITE);}
    display.setCursor(x+(5*txtSize), y+(2*txtSize));
    display.print(caption1);
  }
  else{
    display.setCursor(x+(5*txtSize), y+(2*txtSize));
    display.print(caption2);
  }
}

bool button::getStatus(){
  return pres;
}
void button::update_(){
  if(type == "push_button"){
    if(!digitalRead(btnPin) == 1 && millis() - sec > 19){
      pres = 1;
      sec = millis();
    }
    if(!digitalRead(btnPin) == 0){
      pres = 0;
    }
  }
  if(type == "switch"){
    if(!digitalRead(btnPin) == 1 && millis() - sec > 189){
      pres = !pres;
      sec = millis();
    }
  }
}

void button::changeCap(bool captionB){
  capB = captionB;
}
//--------class objects--------
menu main_menu("main", "games", "stopwatch", "timer...", "settings", 12, 42);
    menu games_menu("games", "pong", "guess a number...", " ", " ", 12, 22);
      menu pongLevel_menu("level", "easy", "hard", "expert", "impossible ", 12, 42);
    menu settings_menu("settings", "sound", "credits", " ", " ", 12, 22);
        menu sound_menu("sound", "on", "off", " ", " ", 12, 22);

button startB(25, 32, 6, 14, "start", "stop", "switch", 2);

//--------functions-----------
void buttonsUpdate(){
  up = !digitalRead(A0);
  down = !digitalRead(A2);
  left = !digitalRead(12);
  right = !digitalRead(A1);
  a = !digitalRead(4);
}
void resetTime(){
    millisec = 0;
    seconds = 0;
    minutes = 0;
    hours = 0;
}
void cookTime(){ // logic for stopwatch and calcuulating milliseconds, seconds, minutes and hours
  startB.update_();
  if(startB.getStatus() == 1){startB.changeCap(1);digitalWrite(13,1);}
  if(startB.getStatus() == 0){startB.changeCap(0);stTimeB = 1;digitalWrite(13,0);}

  if(startB.getStatus() == 1){
    if(stTimeB == 1){resetTime(); startTime = millis(); stTimeB = 0; }
    millisec = ((millis()-startTime)/10) % 100;
    seconds = ((millis()-startTime)/1000)%60;
    minutes = ((millis()-startTime)/(1000*60))%60;
    hours = ((millis()-startTime)/(1000*60*60))%60;
  }
}

void dispStopwatch(){ // display stopwatch
  cookTime();
  display.clearDisplay();
  startB.disp();
  display.setTextColor(WHITE);
  display.setTextSize(2);
  display.setCursor(8, 10);
  display.print(hours);
  display.print("|");
  display.print(minutes);
  display.print("|");
  display.print(seconds);
  display.print("|");
  display.print(millisec);
  display.display();
}

void setup() {
  Wire.begin();
  display.begin(SSD1306_SWITCHCAPVCC, 0x3C);
  display.clearDisplay();
  pinMode(13, OUTPUT);
  // buttons' pins setup
  pinMode(A0, INPUT_PULLUP); // up
  pinMode(A1, INPUT_PULLUP); // right
  pinMode(12, INPUT_PULLUP); // left
  pinMode(A2, INPUT_PULLUP); // down

  pinMode(4, INPUT_PULLUP);  // a
 }

void loop() {
 buttonsUpdate();
  if(up == 1 && down == 1){location = 0;}

  if(location == 0){//main menu
    main_menu.play();
    if(a == 1 && selY == 12/*if a btn is clicked while selected first item*/ && millis() - sec > 199){location = 1/*games*/; sec = millis();}
    if(a == 1 && selY == 22/*if a btn is clicked while selected first second*/ && millis() - sec > 199){location = 2/*stopwatch*/; sec = millis();}
    //if(a == 1 && selY == 32 && millis() - sec > 199){location = 3/*timer*/; sec = millis();}
    if(a == 1 && selY == 42/*if a btn is clicked while selected first fourth*/ && millis() - sec > 199){location = 4/*settings*/; sec = millis();}
  }

  if(location == 1){//game menu
        games_menu.play();
        if(a == 1 && selY == 12 && millis() - sec > 199){location = 11/*pong*/; sec = millis();}
      }
          if(location == 11){//pong levels
          pongLevel_menu.play();
          }

  if(location == 2){//stopwatch
        dispStopwatch();
  }
  if(location == 4){//settings
        settings_menu.play();
        if(a == 1 && selY == 12 && millis() - sec > 199){location = 41/*sound*/; sec = millis();}
        if(a == 1 && selY == 22 && millis() - sec > 199){location = 42/*credits*/; sec = millis();}
      }
          if(location == 41){// sound menu
            sound_menu.play();
          }
          if(location == 42){// credits
           // drawBitmap();
          }
}

Please put your code into the question. Also what is that link? To a comment on SE with another link to a different question on SE?

I tried to put code but it separates some lines and writes it as text. Link is to stack Overflow where code can pase normaly

Responders on StackOverflow have already suggested you make use of Flash memory to reduce the amount of the (very limited) RAM your code needs. Some additional suggestions: Strings often fragment available RAM into unusably small pieces; C strings - null-terminated character arrays - are much more RAM-friendly. Any constants, constant strings, constant members of objects, can be moved to Flash too, to free more of the limited RAM. Search "PROGMEM Arduino" for tutorials. Practice with them until you can apply the principles to your code.

Thank you very much for this suggestion, I will try to implement that into my code

Link is to stack Overflow where code can pase normaly ... the code parses the same way here ... read Syntax highlighting for code here
https://arduino.stackexchange.com/editing-help ...

I have copied the code.  But please delete the question on stackoverflow.  Multi-postings is frowned upon.

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


text:
Powering a NodeMCU as well as a GSM module
I'm trying to connect a GSM module(sim800L) with a NodeMCU to execute remote operations. But the GSM module cannot be powered using the NodeMCU. So, what are the other ways to power the board as well as the module. Also I want to connect directly to a wall power supply instead of using a battery.

connect them to the supply in parallel.

So, I would have to use a 5V 2A power adapter and then connect the devices in parallel to it. Right?

Check if your SIM800L can actually take 5V. If so, then you can connect both in parallel.

the sim800l module operates between 3.7 to 4.7 V

After a bit of researching, I have found the following solution:-
A DC-DC buck converter (such as the LM2596) can convert a 12 V 2A rated power supply down to 4 V (the value is adjustable) which can then be used to power the module.


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:
How do I use a transmitter and receiver to send string messages conditionally to a receiver?
I'm working on a project to build a plant monitor that works from the outside with Arduino that picks up light and water values from it's environment then uses a nRF24L01 with an antenna and I've come across a roadblock in the code with using a transmitter and receiver, heres the code fully below.
Appreciate any help, been stuck for weeks trying to figure this out.
Transmitter Code
/*
 * NAME: <Mario Ronci>
 * Healthy Plant Monitor  V2  T
 *
 *
 */

 //** **/
#include <nRF24L01.h>
#include <printf.h>
#include <RF24.h>
#include <RF24_config.h>
//create an RF24 object
RF24 radio(9, 8);  // CE, CSN

//address through which two modules communicate.
const byte address[6] = "00001";

int ldrValue;
int sensorPin = A0;    // select the input pin for the Water Comparator
int sensorValue = 0;
int light_threshold = 650;
int water_threshold = 850;
String dark_message = " ALERT:Plant is Dark!";
String bright_message =" Brightness Achieved! ";
String water_message1 = " Plant has enough water.";
String water_message2 = " Need Water...!";
String healthy_message = "Plant is Healthy!";
String unhealthy_message = "Unhealthy...!";
//String engineerinfo = "Mario Ronci 2023";

void setup() {

  pinMode(LDR, INPUT);
  pinMode(POT, INPUT);
  pinMode(10, OUTPUT);
  pinMode(9, OUTPUT);
  Serial.begin(9600);
  Serial.println(engineerinfo);
  // put your setup code here, to run once:
radio.begin();
  //set the address
  radio.openWritingPipe(address);
  //Set module as transmitter
  radio.stopListening();

}

//This checks if the plant is getting enough light,//
//by taking a acceptable or unacceptable light value
//from a LDR and prints the value to the serial monitor
//and if the light value is acceptable

void ldrCheck(int device, int duration1,int duration2){

ldrValue = analogRead(device);

if(ldrValue >= light_threshold)

{
  messageLight = light_message + String(ldrValue);
  sendByteMessage(); // Call the function to send the byte message
   delay(duration1);// Wait for some time before sending the next message

}

if(ldrValue < light_threshold){
  messageLight = dark_message + String(ldrValue)
  byte messageBytes[message.length() + 1]; // Create a byte array to store the message
  delay(duration2);
}

void sendByteMessage() {
  byte messageBytes[message.length() + 1]; // Create a byte array to store the message

  // Convert the string message into a byte array
  message.getBytes(messageBytes, message.length() + 1);

  // Send the byte array through the transmitter
  radio.write(&messageBytes, sizeof(messageBytes));
}

}

////This checks if the plant is getting enough water,//
//by taking a acceptable or unacceptable hydration value
//from a LDR and prints the value to the serial monitor
//and if the hydration value is acceptable , the yellow LED will turn on
//and blink, if it's not it will print a message to the serial monitor
//to alert you

//********* Note replace POT with hydrometer code*********//
void potCheck(int device,int duration3){

potValue = analogRead(device2);

if(potValue > water_threshold)
{
  Serial.print(potValue);
  Serial.println(water_message1);

}

else{
  Serial.println(water_message2);

}

}

//This checks if the plant is getting enough water and light
//, if it's not it will print a message to the serial monitor
//to alert you and if it is getting enough it will print a
//message to the serial monitor telling you the plant is healthy

void healthyCheck(int led_4,int duration4,int duration5){

if((ldrValue >= light_threshold) && (potValue > water_threshold)){
digitalWrite(led_4, HIGH);
Serial.println(healthy_message);
delay(duration4);
}

else{
digitalWrite(led_4,HIGH);
delay(duration5);
digitalWrite(led_4,LOW);
delay(duration5);
Serial.println(unhealthy_message);

}

}

void loop(){

//This calls the function/method

//in loop call transmitter

ldrCheck(LDR, 1000,100 );
sendByteMessage(LDR)
potCheck();
healthyCheck(2000,800);

}

Receiver Code
#include <nRF24L01.h>
#include <printf.h>
#include <RF24.h>
#include <RF24_config.h>

//Create an rf24 object

RF24 radio(9,8) ; //CE,CSN

//address through which two modules communicate.

const byte address[6]  = "00001";

void setup() {

while(!Serial);
 Serial.begin(9600);

 radio.begin();

 //set the address
 radio.openReadingPipe(0, address);

 //set module as receiver
 radio.startListening();

}

void loop() {
  //Read the data if available in buffer

  if (radio.available())
  {
    char text[32] = {0};
    radio.read(&text, sizeof(text));
    Serial.print(ldrValue);
    Serial.println(light_message);
  }

What specifically do you need help with?
I'm trying to modify original code to work with the transmitter and receiver functionality
before I had code that used leds meaning the plant monitor would turn on certain colored LEDs based on condition.Now in V2 of this project i decided to do away with the LED's and make the goal to have communication between the componets from the outside to send messages about the plant status inside where another arduino would print to the serial monitor
I need help with having the transmitter code work with the conditional statements atm I'm confused where to insert the each piece of code so the transmitter sends a message to the receiver and prints in the serial monitor.It should work as the componets take inputs from the environment like the ldr, then that value is stored and applied to if statment , if x is this value then send this message and then the transmitter sends the message to the receiver that prints it to the serial monitor
What have you tried?
I've tried to create a seperate variable for the message I want to send along with the analog sensor values from the ldr.( I've not gotten to the hydrometer yet I only got the wiring for it done) Turn the ldr from int to a string and then call the variable in the byte message function within a function for checking for ldr values. Then in the receiver code i tried testing by writing Serial Print for each value but It's not working and I think its because the value is out of scope.Not in the same sketch.
What do you think the problem is?
I think it may be the order of the code and or syntax,maybe if I put the transmitter code outside of the ldr check function it would work, but im not sure. Could also be that the datatypes are strings and ints and changing that to the bytes isn't as straightfoward as I thought.
The actual build and components
Master  (  transmitter ) takes inputs from the environment using a Ldr and hydrometer
both water and light values and sends it to the slave microcontroller the receiver, wiring is correct.

Slave ( receiver) processes the values from the transmitter and prints them in the serial monitor the messsage it recieves will depend on conditions such as light value thresholds  and water value thresholds in simple terms if the light  or water values exceed a certain value or are below a certain value it will send a different message for each situation.

at this time, your post is equivalent to I need help with building a car ... please focus on only one problem ... start with the communication link ... forget all about LEDs, water, and plants ... focus on sending a single byte between the two devices, nothing more

Ok i get the idea of working one step at a time. But i was already able to send message to the transciever and print  it  to the serial monitor ,  but when I added the code where I added the conditional if statements it fell apart. That's my issue : Can i send the message  using the conditionals?

your code is a mess ... it is not formatted properly ... looks like there are extra braces, but it is not immediately evident ... do yourself a favor and format your code and then examine it ... correctly formatted code looks something like this ... https://www.programiz.com/cpp-programming/examples/vowel-consonant-frequency-string ... for example, there is no guessing which code executes when an if statement runs ... you should never see two successive closing braces at equal indent level as are in your code

I would restructure the code. The transmitter side should regularly collect data from the environment (light value, water value, other health values) and bundle these  raw data items into a single fomatted message (C++ struct) for transmission. The receiver, on receiving such a message, unpacks it, interprets it and generates any messages on the display etc. This matches your text description near the pictures but not your code. Incidentally, where in the receiver do the values ldrValue and light_message come from?

Use Ctrl+T in the IDE to attempt to format the code better. (Tools menu -> Auto Format).

You say the radio part works? But when you add  "conditional" code it does not? What I do w/my battery operated radio linked remote devices is always send an "unconditional" message and use it as a "heart beat".  To tell if the battery of the remote transmitter is dead. Do not set this too often if you are using batteries as it will put an extra drain on them.  But, for testing, just temporarily drop in a send in your LOOP function.

@MarioRonci can you highlight which conditional statements you are talking about specifically?

I figured the issue out.

code was a mess but after troubleshooting it for a while the if statements didn't make sense and had no good flow to them plus too complicated. I had copied and pasted some code without making sense of it.

It worked when I focused on one component like @jstola said. The photoresistor only and so the main thing is to add the conditional then turn string into a byte message and then void loop sends byte message to receiver arduino. Then the next part there were symbols appearing in the serial monitor and that was weird. So I experimented with the char data type instead of string and worked. Also use chatgpt as well for some syntax help.

Now I have base to work from. So next is to tackle the hydrometer.
Transmitter Code - with photoresistor only
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
#include <printf.h>
#include <RF24_config.h>

RF24 radio(9, 8); // Create an instance of the RF24 object

const byte address[6] = "00001"; // Set the pipe address

int ldrValue;
int sensorPin = A2;    // Select the input pin for the LDR
int light_threshold = 650;
String light_message = "Plant has enough light :";
String dark_message ="Alert: Plant is Dark! :" ;
String water_message1 = " Plant has enough water.";
String water_message2 = " Need Water...!";
String healthy_message = "Plant is Healthy!";
String unhealthy_message = "Unhealthy...!";

void setup() {

  pinMode(sensorPin, INPUT);
  radio.begin();
  radio.openWritingPipe(address);
  radio.stopListening();

}

void loop() {
  ldrCheck(sensorPin, 1000, 100);
}

void ldrCheck(int device, int duration1, int duration2) {
  ldrValue = analogRead(device);

  if (ldrValue >= light_threshold) {
    String message = light_message + String(ldrValue);
    sendByteMessage(message);
    delay(duration1);
  }
  else {
    String message = dark_message + String(ldrValue);
    sendByteMessage(message);
    delay(duration2);
  }
}

void sendByteMessage(String message) {
  byte messageBytes[message.length() + 1];
  message.getBytes(messageBytes, message.length() + 1);
  radio.write(&messageBytes, sizeof(messageBytes));
}

reciever Code - with photoresistor only
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
#include <printf.h>
#include <RF24_config.h>

RF24 radio(9, 8); // Create an instance of the RF24 object

byte address[6] = "00001"; // Set the pipe address

void setup() {
  Serial.begin(9600);
  radio.begin();
  radio.openReadingPipe(1, address);
  radio.startListening();
}

void loop() {
  if (radio.available()) {
    char message[32] = ""; // Create a character array to store the message
    radio.read(&message, sizeof(message));
    processMessage(message);
  }
}

void processMessage(char* message) {
  String receivedMessage = String(message); // Convert the character array to a String
  Serial.println(receivedMessage);
  delay(1000);
}

result:

Video


text:
ArduinoJSON - How to check if array is empty
Parameters file defines the creation of entities and stored in flash. Its structure is given, and all fields ( keys & values ) are given.
In current phase - those parameters are hard-coded in a const char* cont_params, as shown below.
My goal, is when array is empty, for example RF_2entity - means that current MCU does not uses its RF abilities, and will not init any RF entities. The way RF_2entity is defined below, as empty array, [] , ArduinoJSON's isNull() function return 0 in that case.
How can I keep parameters file's structure and logic, rather that fill its values with 255 for example.
  Serial.begin(115200);
  StaticJsonDocument<1200> doc;
  const char *cont_params = "{\"entityType\": [1,1,1,1],\
                    \"SWname\": [\"SW_0\",\"SW_1\",\"SW_2\",\"SW_3\"],\
                    \"SW_buttonTypes\": [2,1,1,1],\
                    \"SW_timeout\": [10,11,12,13],\
                    \"SWvirtCMD\":[0,0,0,0],\
                    \"Winname\": [],\
                    \"WextInputs\": [],\
                    \"WinvirtCMD\":[],\
                    \"RF_2entity\": [],\
                    \"v_file\": 0.5}";
  DeserializationError err = deserializeJson(doc, cont_params);
  JsonArray array = doc["Winname"].as<JsonArray>();
  serializeJsonPretty(array,Serial);
  Serial.println(array.isNull());

output:
[]0

sorry, but I don't understand the question. what is the problem? isNull() returned 0 (false), not 1 (true)

@Juraj - Question edited. you are right.... isNull() returns that array is not empty.

The method isNull() is not what you want. It tells you whether the instance holds an array at all or not. And of course, your specific instance holds an array, though an empty one. Therefore, the method correctly returns false, aka 0.
As the API documentation shows, there are more methods to use.
What you want is size(), which returns the number of elements in the array. It will even return 0 on an instance without an array.

in that case, doc["Winname"].size() will suffice. I don't really need to use an array.


text:
Sending values with pyserial does not function if there is also sensing on Arduino Due
I'm using an Arduino Due to make a feedback loop using python, but this does not seem to function. The python code I'm using is the following:
from serial import Serial
board = Serial('COM11',9600)
board.write('100'.encode()) # 100 is taken as an example

In fact, if I just use Arduino to measure the sensor voltage, it succeeds. It's the same if the voltage is sent without measuring the sensor. But, as soon as I put both simultaneously, the sensor is good but nothing is read by the Arduino.
However, if I send the voltage not using Python but using the Arduino IDE, everything is okay.
It seems that the Arduino can't do the two operations at the same time, but this is weird. Here is my Arduino code:
int const controller = DAC0; // Set the controller output pin
int const sensor = A1; // Set the sensor pin
double MeanNumber = 500;

void setup() {
  Serial.begin(9600);
  pinMode(controller, OUTPUT);
  analogReadResolution(12);
}

double get_voltage(int Measure)
{
  double voltage;
  voltage = Measure * 3.3 / 4095.0;
  return voltage;
}

void loop() {
  double Measure = 0;

  double voltage;
  for (int i = 0; i < int(MeanNumber); i++) // Realize an average each MeanNumber value
  {
    Measure = Measure + analogRead(sensor) / MeanNumber;
    delay(1);
  }

  // Send the averaged measure to python
  voltage = get_voltage(Measure);
  Serial.println(voltage,4);

  // Get the feedback from python
  if (Serial.available() > 0)
  {// Verify if data are available
    String receivedData = Serial.readString(); // Read the voltage value from bytes to string
    float value = receivedData.toFloat(); // Convert the voltage into float
    analogWrite(controller,value); // Send the signal via the Arduino
  }

}

Do you have an idea of what is wrong with my job?

Whenever Python opens a port, the Arduino will get reset. What usually helps is right after you open a port in Python, sleep for a couple of seconds (time.sleep(3)).

Opening a Serial connection will reset the Arduino.  The python code may be doing that when it creates the port.  Put a Serial.print("Starting") line in your setup function to see if that's what is happening.


text:
Adafruit Si4713/IDE not working
My IDE shows "Adafruit Radio - Si4713 Test", but without "RDS on!", which is supposed to show up. The radio I use (Inscabin M60) shows static. Am I doing something wrong?
Adafruit Radio - Si4713 Test
Couldn't find radio?
Adafruit Radio - Si4713 Test
Couldn't find radio?
Adafruit Radio - Si4713 Test
Couldn't find radio?
Adafruit Radio - Si4713 Test
Couldn't find radio
Adafruit Radio - Si4713 Test
The italic represents where I made a mistake.
This is the code, where I only changed the error message. I previously changed the #define FMSTATION to 9670, but KTCK has taken that signal, so I changed it back.
/***************************************************
This is an example for the Si4713 FM Radio Transmitter with RDS
Designed specifically to work with the Si4713 breakout in the
adafruit shop
----> https://www.adafruit.com/products/1958
These transmitters use I2C to communicate, plus reset pin.
3 pins are required to interface
Adafruit invests time and resources providing this open source code,
please support Adafruit and open-source hardware by purchasing
products from Adafruit!
Written by Limor Fried/Ladyada for Adafruit Industries.
BSD license, all text above must be included in any redistribution
Many thx to https://github.com/phrm/fmtx/blob/master/firmware/firmware.ino !
****************************************************/
#include <Wire.h>
#include <Adafruit_Si4713.h>
#define _BV(n) (1 << n)

#define RESETPIN 12

#define FMSTATION 10230      // 10230 == 102.30 MHz

Adafruit_Si4713 radio = Adafruit_Si4713(RESETPIN);

void setup() {
  Serial.begin(9600);
  Serial.println("Adafruit Radio - Si4713 Test");

  if (! radio.begin()) {  // begin with address 0x63 (CS high default)
    Serial.println("Couldn't find radio");
    while (1);
  }

  // Uncomment to scan power of entire range from 87.5 to 108.0 MHz
  /*
  for (uint16_t f  = 8750; f<10800; f+=10) {
   radio.readTuneMeasure(f);
   Serial.print("Measuring "); Serial.print(f); Serial.print("...");
   radio.readTuneStatus();
   Serial.println(radio.currNoiseLevel);
   }
   */

  Serial.print("\nSet TX power");
  radio.setTXpower(115);  // dBuV, 88-115 max

  Serial.print("\nTuning into ");
  Serial.print(FMSTATION/100);
  Serial.print('.');
  Serial.println(FMSTATION % 100);
  radio.tuneFM(FMSTATION); // 102.3 mhz

  // This will tell you the status in case you want to read it from the chip
  radio.readTuneStatus();
  Serial.print("\tCurr freq: ");
  Serial.println(radio.currFreq);
  Serial.print("\tCurr freqdBuV:");
  Serial.println(radio.currdBuV);
  Serial.print("\tCurr ANTcap:");
  Serial.println(radio.currAntCap);

  // begin the RDS/RDBS transmission
  radio.beginRDS();
  radio.setRDSstation("AdaRadio");
  radio.setRDSbuffer( "Adafruit g0th Radio!");

  Serial.println("RDS on!");

  radio.setGPIOctrl(_BV(1) | _BV(2));  // set GP1 and GP2 to output
}

void loop() {
  radio.readASQ();
  Serial.print("\tCurr ASQ: 0x");
  Serial.println(radio.currASQ, HEX);
  Serial.print("\tCurr InLevel:");
  Serial.println(radio.currInLevel);
  // toggle GPO1 and GPO2
  radio.setGPIO(_BV(1));
  delay(500);
  radio.setGPIO(_BV(2));
  delay(500);
}

Your Arduino using this code obviously fails to communicate with the radio. Please show how you've connected the board to your Arduino.


text:
Connecting Arduino Mega 2560 to Python with PyFirmata
I am currently controlling two servos using the Arduino IDE, but now need to integrate my Arduino code into a Python script. I read about how to use PyFirmata and went through the process of uploading StandardFirmata to my Arduino Mega 2560 board after changing the samplingInterval value to 99, instead of the default 19. However, having followed the exact procedure of translating Arduino code to Python and downloading/using the correct pyfirmata package, the board simply does not react. I tested the board, the individual servos, power, etc. and have even used the ArduinoMega module in pyfirmata, but there is absolutely no reaction when using the Python code. I have looked through multiple online forums and it seems that this is a recurring issue, but no one has posted a solution (as per my knowledge) to the problem and it would be of great help if someone could help me fix this. Please let me know if you would like to see any of the code, it is very simple and I do not mind sharing it if required. Thanks in advance!

Some code sure help to understand the issue. Also, you can send some predetermined commands from Python to Arduino through a serial port to make your Arduino do what it is supposed to do. You don't necessarily need PyFirmata if your case is simple servo control.


text:
Unable to read the sensor data from all the sensors connected
I am trying to build a project where I have connected 8 Sparkfun TOF Sensors to an I2C MUX which is connected to a Sparkfun RedBoard.
I need to read and display the data from each sensor on the serial monitor right now and later on an OLED Display. The issue I am facing is that it is reading data only from the first sensor and then it stops running.
I have pasted my code below. I am new to all of this so any help would be appreciated on how to fix this issue.  The enableMux() and disableMux() functions are from the GitHub example code libraries. I want to know if the issue is that I am not enabling my ports properly or if the issue is with my data reading. Do I need to initialize each sensor individually?
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include "SparkFun_TMF882X_Library.h"

#define sensors 8
SparkFun_TMF882X  myTMF882X;

void setup()
{
  Serial.begin(9600);
  while(!Serial);
  Wire.begin();
  for(byte x=0;x<sensors;x++)
  {
    enableMuxPort(x);
    if(!myTMF882X.begin())
    {
        Serial.println("Error - The TMF882X failed to initialize - is the board connected?");
        while(1);
    }
    else
    Serial.print(x+1);
    Serial.println(" TMF882X started.");
    disableMuxPort(x);
  }
}

void loop()
{
    delay(500);
    for(byte x=0;x<sensors;x++)
    {
      enableMuxPort(x);
      struct tmf882x_msg_meas_results myResults;

      myTMF882X.startMeasuring(myResults);
      Serial.print(myResults.num_results);
      unsigned int distance = myResults.results[0].distance_mm;
      Serial.print("Sensor ");
      Serial.print(x+1);
      Serial.print(" distance: ");
      Serial.print(distance);
      Serial.print("mm");
      Serial.println();
      disableMuxPort(x);
    }
}

Hardware Used:

Microcontroller: Sparkfun Redboard Turbo
MUX: SparkFun Qwiic Mux Breakout - 8 Channel (TCA9548A) - BOB-16784 - SparkFun Electronics
Sensor: Qwiic dToF Imager (TMF882X) Hookup Guide - SparkFun Learn

Below is the output I am getting:
1 TMF882X started.

2 TMF882X started.

3 TMF882X started.

4 TMF882X started.

5 TMF882X started.

6 TMF882X started.

7 TMF882X started.

8 TMF882X started.

9Sensor 1 distance: 3325mm

0Sensor 2 distance: 0mm

you have to supply the module I2C address when you instantiate the SparkFun_TMF882X  object

I'd have started with the assumption that you have to create 8 objects of type SparkFun_TMF882X as
SparkFun_TMF882X myTMF882X[ 8 ]; instead of using a shared object. Alternatively, call the begin() method each time you switch to a different sensor. You could also test the multiplexing by hardcoding say enableMuxPort(2); to see if it works  for just sensor 2.

Where is the definition of enableMux() and disableMux()?


text:
Arduino Uno Gravitech Rev 3.0 with avrdude CLI (Mac OS) - Is my script correct?
I am dealing with an Arduino Nano board rev 3.0 from Gravitech.
There is a program inside that I'd like to download to a HEX file. Thus I can upload it to other Arduino Nano boards.
I'm a newbie with Arduino. Therefore I've read much documentation on the internet and I came to the point to use avrdude in the command line as Arduino IDE does not provide a feature to perform a download to an HEX file (as far as I've understood).
I've installed all the necessary software on my Mac OS Mojave (avrdude v7.0 using 'Mac Ports'). And after powering up and connecting the Arduino Nano board to a USB port of my Mac, I launched the following command line:
avrdude -p m328p -D -c arduino -P /dev/tty.usbserial-A9077L99 -U flash:r:programme_arduino.bin:r -v -x attempts=4
I obtain the classical message

stk500_recv(): programmer is not responding

I've noticed that the 'Rx' led and the 'L' led were blinking during the attempts.
From your perspective, do the options look good (-p -c ...)?

Thank you jsotola for your comment. Arduino IDE allows to upload a sketch to the Arduino board. The command line utility 'avrdude' should allow to download the Flash ROM content of the Arduino board to a hex file or binary file. Correct in my command line I put 'programme_arduino.bin' instead of 'programme_arduino.hex'. However I think it doesn't make a difference.

I add a precision, I used 'programme_arduino.bin' based on the settings I found on the website https://www.evilmadscientist.com/2011/avr-basics-reading-and-writing-flash-contents/

my apologies, I misunderstood what you are asking ... start with a blank Arduino Nano and the Arduino IDE ... in settings, turn on show verbose output during upload ... upload an empty sketch to the Nano ... the Arduino IDE will display the avrdude command line that is required to upload a sketch ... then edit the command line to do a download instead

show verbose output during upload sounds a good hint to get a good reference for my command line. However as I don't want to overwrite my existing code, I've tried this setting with my board disconnected. Arduino IDE does not display the command line as no port is connected.

Your first problem is the no-response complaint. You said "I've noticed that the 'Rx' led and the 'L' led blank during the attempts." Is "blank" a typo (i.e., the LEDs do blink?) or did you mean they do nothing? Are you using the same cable you used to program the nano? Can you swap with another cable? Test this cable with another nano? Is the port ID typed correctly (/dev/...etc)?
Double-check the programmer ID (-c option) and part number (-p option) by querying AVRDUDE (specify '?' instead of a valid value on each of those).
For the -U option, you'll want to name the output file with a .hex extension, and specify the file-format as 'i' for intel hex:
-U flash:r:programme_arduino.hex:i
Here is the AVRDUDE reference I used.
Update:
I agree that your port ID must be correct and the cable is working, since your LEDs are blinking. But you get an error message about "not responding". Does the Nano have a bootloader in it? Could the boot-loader have been damaged when you uploaded the code (e.g., the code is large enough to over-write some of the bootloader)?
Is binary code in the Nano the only copy, or do you have the source code for it? If you have the source, you can recompile it (if necessary) and retrieve the resulting .hex file. Would that solve your problem? By setting the IDE to produce verbose output, you'll see the path to the temporary files, including the .hex file. Then use Finder (or a Terminal command, if you are comfortable with that) to copy that temporary .hex file to someplace safe.
Update 2:

Are bootloader ROM area and Flash ROM area two different memory areas?

Not separate - the boot-loader is placed at the top of Flash. It is possible for a large enough program to over-write it - I'm not sure whether that has to be specifically allowed, such as by setting fuses. If it does get over-written, it obviously becomes unusable.
I wonder if the flash can be read using a hardware programmer? Do note that these chips have lockout-fuses that can be set to prevent further programming or reading of the flash.
Since the code in this device seems valuable to you, I would suggest putting this Nano board aside, and only experiment with another, hopefully identical, board. On the new board -

Upload a sketch to it;
Copy the AVRDUDE command line used to by the IDE to upload it, and modify it as you've already described. Of course, this command will already have the board-specific parameters;
Use the modified command to download the sketch to another file, and compare it to the file that was just uploaded.

Once you can do this successfully, apply that last step to copy the sketch from your valuable Nano, then put that board away again. Load and test the downloaded code on your experimental Nano. Don't forget to include the valuable Nano's EEPROM - it might contain some critical data.

About 'blank' I wrote it incorrectly (excuse my English I am French ;-)). I meant 'blink' i.e. the led is blinking during the avrdude attempt.

I tried with 2 mini-B USB cables. The behavior is strictly the same. To notice that those cables are not original ones delivered with the Arduino board.

I have only one Arduino Nano board. I can not try with another one.

I consider the port ID is typed correctly as during the avrdude attempts I see the leds blinking (Rx, L). It means there are some data going through the Arduino USB Rx line at least...

About the programmer ID (-c option), here is something I don't understand well. I have a doubt about the one to choose, 'arduino', 'usbtiny', ... I keep 'arduino' as I have a bit of communication with it at least...

About the part number (-p option), I initially use 'm328p' (value given when I tried to use Arduino IDE). However, now looking at the schematic of the Arduino Nano from Gravity, I see the microcontroller 'ATmega168' is used. So I assume I should use 'm168' by the end...

About the memory operation (-U option), I used the setting from the following website: https://www.evilmadscientist.com/2011/avr-basics-reading-and-writing-flash-contents/. Reading it again it is about downloading a raw binary format.

Thank you @JRobert for your update: the binary code in the Arduino Nano is the only copy I have. I don't have the source code unfortunately (the guy who made it left a long time ago. Therefore there is no way to recover the source code).

Good question about the boot-loader. The code is running as I can interact with the  overall electronic as expected. Are bootloader ROM area and Flash ROM area two different memory areas? I.e. a .HEX file coud be uploaded overlapping both bootloader ROM area and Flash ROM are?!


text:
How do I turn on 3 LEDs in a repetitive sequence where all three LEDs would then turn OFF when the push button used is released?
Basically, how do I modify my code listed below to turn ON each of the three LEDs one at a time in a repetitive sequence while keeping the push-button pressed?

Red (3 sec),
Yellow (1 sec), and
Green (3 sec).

I'm trying to get all three LEDs to turn OFF when the push button is released.
The code I wrote that doesn't allow me to achieve what I'm trying to do (I'm not sure where I went wrong):
#define Button_Pin 2  //Push Button Pin
#define LED_Pin_1 11 //Red LED
#define LED_Pin_2 10 //Yellow LED
#define LED_Pin_3 9  //Green LED

byte Button_State;

void setup() {
  pinMode(Button_Pin, INPUT);
  pinMode(LED_Pin_1,  OUTPUT);
  pinMode(LED_Pin_2,  OUTPUT);
  pinMode(LED_Pin_3,  OUTPUT);

  Serial.begin(9600);
  Serial.println("Design Part B - Digital I-O Control");
  delay(1000);
}

void loop() {
  Button_State = digitalRead(Button_Pin);
  Serial.print("Button State: ");
  Serial.print(Button_State);

  if (Button_State == 1){
    digitalWrite(LED_Pin_1, HIGH);
    delay(3000); //Wait for 3 Secs
    digitalWrite(LED_Pin_2, HIGH);
    delay(1000); //Waits for 1 Sec
    digitalWrite(LED_Pin_3, HIGH);
    delay(3000);
    Serial.println(" --> Button Pressed --> LED ON");
  }
  else{
    digitalWrite(LED_Pin_1, LOW);
    digitalWrite(LED_Pin_2, LOW);
    digitalWrite(LED_Pin_3, LOW);
    Serial.println(" Button is Released --> LED OFF");
  }
}

look carefully at the code inside the if (Button_State == 1){ block .... think about what it does and how long it takes to do it ... then examine the blinkWithoutDelay example sketch in the Arfuino IDE

When you turn yellow on, should red be turned off? Or does it stay on?

I guess that the button pin is wired with an external pull down resistor say 10k.

I've attached what the circuit looks like if that helps clear up anything. I will examine the example sketch you suggested and think more carefully about what that block does and so forth

The clue here is that once your LED sequence has started, it must run to completion - 7 seconds worth - before the button can be detected. Even if you hold the button for, say 3 seconds, starting shortly after the sequence starts, you may give up and release it before the sequence completes, and the code will never have tested it.

here is some code I wrote that uses several timers ... it may give you some ideas ... https://wokwi.com/projects/362275278547275777

Having examined several sample sketches, including the recommended one, and watching instructional YouTube videos to grasp the fundamentals of Arduino programming, I am delighted to announce that my understanding of programming the Arduino and comprehending its functions has significantly improved, considering my novice status.
I can confidently assert that this question has been resolved, and I have enclosed the code that fulfills the initial requirements that was asked of me.
#define pushButton_pin 2
#define grn_LED_pin 9
#define yel_LED_pin 10
#define red_LED_pin 11

bool pushButton_state;

void setup() {
pinMode(pushButton_pin, INPUT);
pinMode(grn_LED_pin, OUTPUT);
pinMode(yel_LED_pin, OUTPUT);
pinMode(red_LED_pin, OUTPUT);

Serial.begin(115200);

Serial.println("Use push button (digital input) to control 3 LEDs (digital
output)");
delay(1000);
}

void loop() {
pushButton_state = digitalRead(pushButton_pin);
Serial.println(pushButton_state);
if (pushButton_state == 1) {
digitalWrite(grn_LED_pin, LOW);
digitalWrite(yel_LED_pin, LOW);
digitalWrite(red_LED_pin, HIGH);
Serial.println(" :push button state is 1, red LED is ON");
delay(2000);
digitalWrite(grn_LED_pin, LOW);
digitalWrite(yel_LED_pin, HIGH);
digitalWrite(red_LED_pin, LOW);
Serial.println(" :push button state is 1, yel LED is ON");
delay(1000);
digitalWrite(grn_LED_pin, HIGH);
digitalWrite(yel_LED_pin, LOW);
digitalWrite(red_LED_pin, LOW);
Serial.println(" :push button state is 1, grn LED is ON");
delay(2000);
} else {
digitalWrite(grn_LED_pin, LOW);
digitalWrite(yel_LED_pin, LOW);
digitalWrite(red_LED_pin, LOW);
Serial.println(" :push button state is 0, all LEDs OFF");
}
delay(500);
}

But it appears that releasing the button has no immediate effect. It must still wait until the full cycle has completed before all leds are switched off. To improve this, you must use a "state machine" type solution as has already been suggested. Using delay() statements is very inflexible. Everything is blocked until these terminate.

I stated that I wanted to get all three LEDs to turn OFF when the push button is released. I should've been clearer about exactly what I wanted to achieve so apologies for the confusion there, however I still wanted it to still run the full cycle when pressed before turning off.

You need a state machine (to remember which LED is currently on) and use millis() to find the current time, in a loop, which is testing whether the switch is closed or not.
If the switch is closed you compare the time now (with millis()) to the time you turned that particular LED on. When the time is up you advance the "state" (eg. a counter) to the next one, and remember the new time that this state change happened.


text:
MPU6050 when searching is at address 0x68 but as a result shows only "0"
My circuit uses an Arduino Nano which I communicate via Α4 and A5 via I2C. There are several BMP280, HMC5883 and MPU6050 sensors on the I2C line. While I was dealing with these other two sensors, my MPU6050 stopped working. She started outputting single zeroes regardless of the movements. I found similar problems and it was suggested to conduct a search and if it is searched to try some other code.I tried and nothing helped. They also wrote about power supply problems, but the board I use has resistors between the microcircuit and the SCL/CLK terminals. I also heard about FIFO, but did not understand anything.
I don't know what I did wrong because before that it was working fine. I will add the code I used.
/*
The contents of this code and instructions are the intellectual property of Carbon Aeronautics.
The text and figures in this code and instructions are licensed under a Creative Commons Attribution - Noncommercial - ShareAlike 4.0 International Public Licence.
This license lets you remix, adapt, and build upon your work non-commercially, as long as you credit Carbon Aeronautics
(but not in any way that suggests that we endorse you or your use of the work) and license your new creations under the identical terms.
This code and instruction is provided "As Is” without any further warranty. Neither Carbon Aeronautics or the author has any liability to any person or entity
with respect to any loss or damage caused or declared to be caused directly or indirectly by the instructions contained in this code or by
the software and hardware described in it. As Carbon Aeronautics has no control over the use, setup, assembly, modification or misuse of the hardware,
software and information described in this manual, no liability shall be assumed nor accepted for any resulting damage or injury.
By the act of copying, use, setup or assembly, the user accepts all resulting liability.

1.0  5 October 2022 -  initial release
*/

    #include <Wire.h>
    float RateRoll, RatePitch, RateYaw;
    void gyro_signals(void) {
      Wire.beginTransmission(0x68);
      Wire.write(0x1A);
      Wire.write(0x05);
      Wire.endTransmission();
      Wire.beginTransmission(0x68);
      Wire.write(0x1B);
      Wire.write(0x8);
      Wire.endTransmission();
      Wire.beginTransmission(0x68);
      Wire.write(0x43);
      Wire.endTransmission();
      Wire.requestFrom(0x68,6);
      int16_t GyroX=Wire.read()<<8 | Wire.read();
      int16_t GyroY=Wire.read()<<8 | Wire.read();
      int16_t GyroZ=Wire.read()<<8 | Wire.read();
      RateRoll=(float)GyroX/65.5;
      RatePitch=(float)GyroY/65.5;
      RateYaw=(float)GyroZ/65.5;
    }
    void setup() {
      Serial.begin(57600);
      pinMode(13, OUTPUT);
      digitalWrite(13, HIGH);
      Wire.setClock(400000);
      Wire.begin();
      delay(250);
      Wire.beginTransmission(0x68);
      Wire.write(0x6B);
      Wire.write(0x00);
      Wire.endTransmission();
    }
    void loop() {
      gyro_signals();
      Serial.print("Roll rate [°/s]= ");
      Serial.print(RateRoll);
      Serial.print(" Pitch Rate [°/s]= ");
      Serial.print(RatePitch);
      Serial.print(" Yaw Rate [°/s]= ");
      Serial.println(RateYaw);
      delay(50);
    }

here is what it outputs now ("0"), although before it was perfectly responsive. At least it accurately displayed the + or - sign along with some values
The type of MPU6050 I used:

Can you restore the circuit and code to the previous state so the MPU6050 once again  works? Have you considered I2C address conflicts between the various modules? Each module may have its own I2C pullup resistors and too many of these in parallel may be a problem.

please do not post pictures of text ... post the text instead

I am responding to 6v6gt's comment.
My circuit didn't change, I had all three sensors connected from the start. However, I just disconnected the BMP280 and HMC5883 from the I2C, leaving only the MPU6050 connected. It will continue to show only zeros.

It sounds like something is broken. Assuming the MPU6050 accelerometer / gyroscope worked with the Arduino. Then, after adding the BMP208 pressure sensor and the HMC5883 magnetometer the MPU6050 stopped working. Finally, after physically removing the BMP208 and HMC5883 from the I2C bus AND REVERTING TO THE VERSION OF CODE which worked with the MPU6050 the MPU6050 continued to not work. Please read that carefully and confirm you did physically remove the 2 new sensors from the I2C but and you did revert back to the code which worked with the MPU6050.

I am responding to st2000's comment.
Just picked up and connected the MPU6050 to another arduino Nano that has nothing else connected except this MPU6050. It shows zeros again.
But I want to note that if you choose the wrong address (that is, not 0x68 or simply do not connect), then -0.02 is displayed instead of zero.

And so I dealt with these sensors separately from each other, that is, they remained connected, but in the code I communicated only with it. And in the case of the MPU6050, I used the above code.
I also remembered that I had a problem with the BMP280, it worked at first and then something froze and I could not connect back to it for several minutes. But now only MPU6050 is not working.


text:
How to offset PWM output so it would also have negative amplitude?
So PWM goes from 0 to 5V. How could I do -2.5 - 2.5V? Basically I am asking how to add offset to PWM signal. Should I use operational amplifier? How would I use it? I never had to deal with them, but I have LM2904P laying around.

You could use an op-amp as a comparator, but you would need to supply it with suitable power rails. Your question may be more appropriate for https://electronics.stackexchange.com/

@ EdgarBonet's and @ st2000's responses are perfectly appropriate. But to clarify for future readers (and hopefully not confuse anyone): the PWM output is not a voltage but a wave form with a duty-cycle ranging from 0% to 100%, and as such, is not able to take on negative values. That waveform can be converted to a voltage (a step that was understood but not included in the question and the replies); the resulting voltage can have whatever range one designs into the conversion circuit.

Consider removing the average of the PWM voltage by subtracting the Direct Current (DC) component of the PWM output.
Often, between different audio amplifiers stages, the DC component of the signal is removed through the use of coupling capacitors. The above link offers these guide lines for picking the value of the capacitor:

Below is a basic rough guideline of capacitors that can be used for
various frequencies.
For coupling a 100Hz signal, a 10μF capacitor can be used.
For a 1000Hz signal, a 1μF capacitor can be used.
For a 10KHz signal, a 100nF capacitor can be used.
For a 100KHz signal, 10nF capacitor can be used.
For a 1MHz signal, a 1nF capacitor can be used.
For a 10MHz signal, a 100pF capacitor can be used.
For a 100MHz signal, a 10pF capacitor can be used.
This is a rough estimate that will be effective the majority of the
time. The only variable that could affect the above values is the
resistance in parallel to the capacitor.

Consider the last paragraph above when designing your circuit.  The lower the input impedance of the circuit you are driving the more likely the possibility of unexpected results.  At which point you might consider adding the OpAmp suggest in the question.


text:
Scrambled Text on SSD1306 Using ESP32-S2
SSD1306 OLED display connected to an ESP32-S2 over hardware I2C. I noticed that the text will sometimes get scrambled or lag during a screen update. When left running long enough, the screen will get stuck and stop updating, despite serial monitor continuing to function. Does anyone know how to fix this? Here is a video of the laggy behavior: https://youtu.be/9OYW00cE24U

#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
unsigned long drawState = 1;
unsigned long previousTime = 0;
unsigned long eventInterval = 4000;

#define OLED_ADDR 0x3C
#define SCREEN_WIDTH 128
#define SCREEN_HEIGHT 32
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1);

void setup() {
  Serial.begin(115200);
  Wire.setClock(400000);
  if (!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) {
    Serial.println(F("SSD1306 allocation failed"));
    for (;;)
      ;
  }
}

int screenSwitchLast = millis();

void loop() {

  if (millis() - screenSwitchLast >= eventInterval) {
    screenSwitchLast = millis();

    switch (drawState) {
      case 1:
        drawTemp(); //draw Temperature
        break;
      case 2:
        drawHum(); //draw Humidity
        break;
    }

    drawState++;
    if (drawState > 2) {
      drawState = 1;
    }
  }
}

void drawTemp() {
  Serial.print("Temp ");
  Serial.println(millis());
  display.clearDisplay();
  display.setTextSize(2);
  display.setTextColor(SSD1306_WHITE);
  display.setCursor(0, 12);
  display.print("Temp: ");
  display.print("10");
  display.print("F");
  display.display();
  delay(1);
}

void drawHum() {
  Serial.print("Hum ");
  Serial.println(millis());
  display.clearDisplay();
  display.setTextSize(2);
  display.setTextColor(SSD1306_WHITE);
  display.setCursor(0, 12);
  display.print("Hum: ");
  display.print("20");
  display.print("%");
  display.display();
  delay(1);
}

I saw this post which recommends running screen update code on the second core but the ESP32-S2 only has 1 core. I'm at odds with how I'd get this to work reliably on a single core ESP32.
Board: Adafruit ESP32-S2 Feather- 4M Flash and 2M PSRAM
Display: 128x32 12C OLED - Ox3C

Arduino Settings:
   - USB CDC on Boot: Enabled
   - CPU Frequency: 240mHz (WiFi)
   - Core Debug Level: None
   - USB DFU on Boot: Disabled
   - Erase All Flash Before Sketch Upload: Disabled
   - Flash Frequency: 80mHz
   - Flash Mode: QIO
   - Flash Size: 4MB (32Mb)
   - USB Firmware MSC on Boot: Disabled
   - Partition Scheme: Minimal SPIFFS 1.9MB APP with OTA/190KB SPIFFS
   - PSRAM: Enabled
   - Upload Mode: Internal USB
   - Upload Speed: 921600

You are constantly clear the screen as clear screen is a relatively "time-consuming" process, plus the i2c buffer for display is quite small (32-bytes if I remember correctly). Move display.clearDisplay();, display.setTextSize(2); and display.setTextColor(SSD1306_WHITE); to the setup() function as all those only need to be setup once in your application, and also move the delay(1) to the main loop, this will  help to address the lagging issue. You may need to print an extra space after "%" as "% " to overwrite the "F" previously print by the temperature string though.

I tried the changes you suggested, but the lack of 'display.clearDisplay();' leaves the "Temp: 10F" text in place and when the "Hum: 20%" gets printed, it simply overlaps it. See photo here: https://jmp.sh/23oUnVHW

You're using Adafruit's library; have you tried running their example code to see if it works for you?

Sorry, I mixed up with another library SSD1306Ascii which does not need to call display.clearDisplay() every time. BTW, I tested your original code with a 128x32 oled, and don't see the lagging your experienced, on both Adafruit library and SSD1306Ascii, but I use a classic ESP32 Dev kit.

@hcheung I switched over to a regular ESP32 as well and it's working fine. I'm really curious to find out what is causing the issue with the S2 variant, so I'm going to try the example code like romkey mentioned. I'm also going to try disabling the radios to see if that helps.


text:
Modbus rtu server library which logs the requests
Kindly seek help. In my project I want to ‘fake’ a smart meter via Modbus rtu server for a solis inverter.
Somehow the solis realizes that I am faking him, so I am wondering which Modbus rtu server library you can recommend to allow me seeing what registers the solis is querying?
As of now I am using Emilianov Modbus-8266 library to run the rtu server/slave and platform is an esp32 with max3485.

So let me elaborate. Mine Solis simply sucks during low-light conditions. It can not decide if it shall charge or discharge, resulting in heavy oscialltion, jumping from feeding to much into grid and then taking to much from grid - peaks are ranging from +800Watt to -800Watt when it starts oscillating.
On the com-port you are true - here the solis acts as slave. But on its RS485 meter-port I understand the Solis acts as master and the smart meter is the slave.
My goal is to fake the smart-meter.
So topology would be:
Solis(master)-----(slave)ESP32(master)-----(slave)smartmeter
So I am looking for a solution that any read-request from the Solis is transparently passed-through to the smart-meter. But I want one register intercpeted (most likely total-active-power, which to mine understanding is the only value the solis want to bring back to zero in its control-loop).
As of now I can read the Solis and ther Seplos BMS via ESP32/RS485 successfully. I even have a running slave which I thought shall be good enough to get accpeted as fake-smart-meter, but it is not. The solis is asking for more register then my fake-solution is providing. hence mine ask, which ESP32 slave/server modbus library can print any request its arriving.
If my view is incorrect, kindly get me corrected.

What are you really trying to do? You need to read up on Modbus. First of all, you are confusing what is acting as a client and what is acting as a server. If you look at the general Modbus manual for Solis inverters, they act as slaves, or, in modern-speak, as servers. You need to setup a master - nowadays a 'client' - to query - poll - the server, not vice versa. You need to provide the code, the manual and the model of your specific inverter, and, possibly, the hardware setup. Why don't you try polling the inverter with something like a USB-RS485 dongle first with ComTest or Modbus Poll?

Try looking at this as a starting point
https://github.com/straga/Smart-Meter-Gateway
My approach has been different but will come back to this if my current approach fails.

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.


text:
How to produce a USB CDC serial port for Arduino nano 33 BLE?
I'm trying to program an Arduino Nano 33 BLE bare-metal to get some precise timing and size measurements. I've managed to upload the code to my card, but I cannot communicate with it. More specifically, when I upload the code, the port 'deactivates' after I upload the code, so the serial monitor prints a cannot exec '/dev/ttyACM0' error.
Can someone help me figure out how to make it work? I've seen tutorials online but they're for AVR microcontrollers, and I've been told that this specific board isn't. I've also been told that I must include some code in my c/cpp file to produce a USB CDC serial port, but I don't know how to do that.

upload a simple example from the IDE Examples menu Communication section

What are you measuring that you can't do it with freeRTOS/mbed-os? You can always use timer(s), events and tasks + shortcuts (or generic connection) and DMA

Well, it seems that mbedOS is messing up with my timing experiments, the measurements fluctuate when they shouldn't. Plus, even an empty sketch uses a lot of memory, and I wish to be able to compare the memory consumption of multiple programs. I guess I could always subtract the cost of an empty sketch, but that doesn't seem very practical to do that by hand.

I'm not sure, but I think rtos usually has some memory stats https://os.mbed.com/docs/mbed-os/v6.16/apis/runtime-memory-statistics.html about timing, you can use high prio task (+ delays to allow lower priority tasks to do run)

Have you seen any of these Q+As? https://arduino.stackexchange.com/search?q=%2Fdev%2FttyACM0

The Nano 33 BLE board uses a NORDIC nRF52840 processor which contains the USB interface hardware inside the processor. The current Arduino Uno uses an Atmel (now owned by Microchip) processor and uses an external processor for USB communications. So any Arduino USB tutorial will be very different with respect to these two Arduino designs.
Normally, Arduino Sketches (Programs) are only part of all the software running on a processor. The preprogrammed software on a new Arduino board abstracts the more complex part of embedded programming from the average Arduino user. This likely includes a working USB port.
To do bare metal programming on a NORDIC nRF52840 processor, consider starting with the NORDIC Software Development Kit (SDK). Also, most vendors support their own development boards (provide example programs and libraries) better then development boards made else where.  Consider this before committing to learning how to bring up a "bear metal" USB/CDC peripheral device using the Nano 33 BLE board.
An alternative approach: Many ports of Arduino occur on github.com.  The adaptation of the Arduino code may offer insights as to how the host processor's hardware works. The Nano 33 BLE preprogrammed software comes from this github repository.

the current core for Nano BLE is here https://github.com/arduino/ArduinoCore-mbed

Thanks, fixed the answer to include the new link.


text:
Analogue input spikes
i have a project where i read two analogue inputs from two sensors and a pro Mini. I have some spikes in my readings that are present when i'm powering the system using a powerbank step-up module. When i use a 7805 and a 9V battery, the results seem clear. The spikes appear every 600-650ms.
Is there any way to filter them out on a hardware level without using code?
The frequency of the spikes is about 1.5HZ, too slow for a typical ripple of a "dirty" dc converter i think.
My first though was that the module was checking for sufficient load to stay powered on. I added a dummy load but nothing changed. The project is a datalogger and unfortunately i don't really want the code to do the filtering, as it's gonna cost me some speed.

Re “i don't really want the code to do the filtering, as it's gonna cost me some speed”: A 3-point median is a very cheap filter speed-wise, and should be quite effective against this kind of spikes.

Are you charging a battery while you are running the program?

No, i'm using a fully charged 18650 battery, not plugged in into an external charger.

@stelPet to me, my initial thought process points to an inductive spike. I'm wondering if putting a snubber diode across the inductor will help with them; if not, you would have to resort to implementing a hardware filter as described below. Two more things to consider - how are you checking the voltage? If you are using a scope with an isolated ground, then you'd have to make sure that the ground are bonded together with the module and the scope - there was a thread on AllAboutCircuits - when I'll find it I'll link it. You could ask in EE SE.

@stelPet also, commercial dataloggers often use digital filters for filtering out 50/60 Hz and stuff like that. What is the application for your datalogger? Unless it's a high-speed acquisition FPGA-based datalogger, I doubt you'd have too much impact on your processing if you do minor digital filtering - it might be just easier to use Edgar's advice rather than fiddle around with soldering stuff to the module (at that point, you should be making your own module, I'm sure there are good charge regulator ICs out there).

On a hardware level, without a substantial delay, you could use active filters, such as active low-pass or band-pass filters, that can provide better control and customization over the filtering process.


text:
Mirroring PWM input on a pin + Motor Encoder
I am interested in hooking up a nano to an RC receiver. I want the nano to mirror the PWM input and output on another pin when a specific command is given via serial. I also want to send the received command via serial to a computer(Pi or Jetson) at the same update rate.
I can run pin change interrupt on the input pins to basically enable/disable the pins but I'm wondering if there is a better way.
I also will be updating a motor encoder at pin change interrupt, I'm guessing around 4k interrupts/second.
Do you think the Nano provides enough juice or I should use a Pico?

You haven't mentioned the PWM frequency nor did you mention the baudrate of the serial. But if we do the math here, classic Nano runs on 16MHz i.e. per cycle is 62.5 nanoseconds. That's plenty if juice if you do everything right.


text:
converting comma delimited Serial message to 7 Unsigned Long variables
Working on a project where I get an input where its a comma delimited string like:
"255,10000000,42949672950254,12,22".

and then the numbers (no commas), would be split into 6 Long variables
like
var1 = 255
var2 = 10000000
...

I wanted a function like this:
void extractIntegersFromString(String str, int& integer1, int& integer2, int& integer3, int& integer4, int& integer5, int& integer6, int& integer7) {
  int count = 0;
  String temp = "";

  for (int i = 0; i < str.length(); i++) {
    char c = str.charAt(i);

    if (c == ',') {
      if (count == 0)
        integer1 = String(temp).toInt();
      else if (count == 1)
        integer2 = String(temp).toInt();
      else if (count == 2)
        integer3 = String(temp).toInt();
      else if (count == 3)
        integer4 = String(temp).toInt();
      else if (count == 4)
        integer5 = String(temp).toInt();
      else if (count == 5)
        integer6 = String(temp).toInt();
      else if (count == 6)
        integer7 = String(temp).toInt();

      count++;
      temp = "";
    } else if (c >= '0' && c <= '9') {
      temp += c;
    }
  }

  // Store the last integer if the string doesn't end with a comma
  if (temp != "") {
    if (count == 0)
      integer1 = String(temp).toInt();
    else if (count == 1)
      integer2 = String(temp).toInt();
    else if (count == 2)
      integer3 = String(temp).toInt();
    else if (count == 3)
      integer4 = String(temp).toInt();
    else if (count == 4)
      integer5 = String(temp).toInt();
    else if (count == 5)
      integer6 = String(temp).toInt();
    else if (count == 6)
      integer7 = String(temp).toInt();
  }
}

This function makes it work through ints, but I need the larger size of a Long.
P.S. I've tried the atol() function (and similar others), but that didn't work...

First of all, it is worth noting that the third number in you example
message (100000000000, i.e. 1011) is too large to fit in an
unsigned long. On AVR-based Arduinos, and most non-64-bit platforms,
an unsigned long is 32-bits wide and can only hold numbers up to
4294967295 (about 4.3×109). I do not know of any easy way to
parse such a large number on AVR.
That being said, for parsing this kind of string into unsigned long
numbers, I would recommend the strtoul() function. Compared
to atol(), it has the benefit that it tells you where the number it
read ended, so you know where to search for the next one: it saves you a
call to strchr(). It also allows some error-checking, so you know
whether the message does conform to the expected format.
Here is a tentative implementation:
/*
 * Parse up to `count` numeric values from `message`,
 * which must be in comma-separated-values format.
 *
 * Return the number of values successfully parsed.
 */
int parse_message(const char *message,
                  unsigned long *values, int count) {
    for (int i = 0; i < count; i++) {
        char *end;  // pointer to next non-digit
        values[i] = strtoul(message, &end, 10);
        if (end == message) return i;  // parsing failed
        if (*end == ',') end++;        // skip comma
        message = end;                 // move to the next field
    }
    return count;
}

And a small test sketch:
void setup() {
    Serial.begin(9600);

    unsigned long values[7];
    int count = parse_message("255,10000000,100000000000,0,255,12,22",
            values, 7);
    Serial.print(count);
    Serial.println(" numbers successfully parsed:");
    for (int i = 0; i < count; i++)
        Serial.println(values[i]);
}

void loop() {}

Thank you for your reply, I'll check it and I'll accept the answer for future reference!! :)

String.toInt actually returns a long. See the code:
long String::toInt(void) const
{
    if (buffer) return atol(buffer);
    return 0;
}

I've tried the atol() function (and similar others), but that didn't work

Please post your "try", don't just say that you did it. Maybe you did it incorrectly.

Re your entire technique: There is a function strtok that is specifically designed to break up a string into substrings at a delimiter. You could use that rather than re-inventing the wheel.
However that doesn't solve your specific problem of converting the substrings into a long.

Its a bit long; how would I include it here?

"Its a bit long; how would I include it here? "  ... If someone asks for something in the comments, the answer (for just about any of the dozens of stackexchange web sites) is to edit the question and make it better.

Edit your question and show the half-a-dozen or so lines of code where you used the atol() function. Also show the results. "Didn't work" is to vague it could mean anything. Did it not compile? If it did compile what results did you get? Show the numbers. Don't say "it didn't work".


text:
Serial plotting a pwm
I'm trying to plot the value of the pwm that increases (every 2 sec) then decreases to compare it to the value of an encoder. I was expecting a continued value (like a step ) during 2 seconds but instead I have a triangle signal.
Here is my code
const int pwmG = 2;
const int DirG = 8 ;
int a =0;

#define encoder1_CHA 18  //Left encoder
#define pin_channelB_left 6
int b =0;

void setup() {
  Serial.begin(9600);
  pinMode(pwmG,OUTPUT) ;
  pinMode(DirG,OUTPUT) ;
  attachInterrupt(digitalPinToInterrupt(encoder1_CHA),interruptUp,RISING);

  }

void interruptUp(){
  b = !b;

}

void loop() {
  Serial.println(b);
  //Serial.print(" ");
  pwm();

  //Serial.println(a);

  //Serial.println(b);
}

void pwm(){
   for (int i =0; i< 10; i++){
      a = a +5;
      analogWrite(pwmG, a);

      Serial.println(a);
      delay(200);
      }
      //Serial.println(b);

  for (int i =0; i< 10; i++){
    a = a -5;
    analogWrite(pwmG, a);

    Serial.println(a);
    delay(200);
  }
}

What I have :

What I expected (exemple found on the internet :

Look at the output of your sketch on the serial monitor, not on the plotter. It should become immediately clear what is going on.

The first point here is, that the Serial Plotter will plot the values against time by connecting them with a straight line. This is just how it represents the data in the plot (it is just for ad-hoc visualization, not for detailed plotting and data analysis).
The second point is, that for each step you are sending only one value through the Serial interface, so only one data point per step. The Serial Plotter then plots this data point against time and connects it with the points for the other steps with a straight line. Thus you get sloped lines/triangle signal in the Serial Plotter.
The image, that you expected, looks like from an oscilloscope. This will have many more data points along the x-axis, not just one per step. Thus you can actually see the steps. If you want to reproduce the image with your code, then you can send the current value of a more often in each iteration of the for loop (like looping 20 times over sending the value and delaying about 10ms).


text:
Wemos D1 Mini deep sleep
I am building a very simple battery powered touch button using a Wemos D1 Mini (it is basically an ESP8266) and a capacitive touch sensor (something like this: https://www.az-delivery.de/en/products/touch-sensor-modul-1).
Since it is battery powered, I need to reduce as much as possible to consumption of the Wemos D1 Mini. I learnt that, in order to obtain minimum power consumption, we need to use the deep sleep mode. In order to do that, we need to connect RST to D0 (being D0 the WAKE PIN) and program the device accordingly.
My question is: will the Wemos D1 Mini wake up when the touch button is activated (aka: when PIN D1 is pulled up)?

Could this be the solution? I could use this as a switch to reset the Wemos D1 Mini and program it to send certain instructions when woken up.
https://youtube.com/watch?v=ojcwgxWMAo8

Why not try it to find out?

it will not. deep sleep is complete off. wake-up from deep sleep is a reset.

it would be far better to power the ESP from the button, perhaps though a mosfet. This will enable the button to work for years on the same battery.

@dandavis could you elaborate, please? Seems like an interesting solution

Please do not post further queries as "answers". This isn't a forum. If you want to add more detail to your question, please edit it. I have moved your "answer" into your question.


text:
How to change partition scheme with arduino-cli
I'm using arduino-cli to program an ESP32-S2.  If I compile my sketch using the default partition scheme
> arduino-cli compile -b esp32:esp32:esp32s2 sketch

a lot of space is allocated for SPIFFS and OTA, which I don't use.
Sketch uses 646558 bytes (49%) of program storage space. Maximum is 1310720 bytes.
Global variables use 39540 bytes (12%) of dynamic memory, leaving 288140 bytes for local variables. Maximum is 327680 bytes.

Thus. I'd like to use the huge_app scheme, as defined in the boards.txt:
esp32s2.menu.PartitionScheme.huge_app=Huge APP (3MB No OTA/1MB SPIFFS)
esp32s2.menu.PartitionScheme.huge_app.build.partitions=huge_app
esp32s2.menu.PartitionScheme.huge_app.upload.maximum_size=3145728

However, selecting it doesn't have any effect:
> arduino-cli compile -b esp32:esp32:esp32s2 sketch --build-property build.partitions=huge_app
Sketch uses 646558 bytes (49%) of program storage space. Maximum is 1310720 bytes.
Global variables use 39540 bytes (12%) of dynamic memory, leaving 288140 bytes for local variables. Maximum is 327680 bytes.

Is my command line incorrect?  Why is arduino-cli not using the specified partition scheme?

according to platform.txt it is build.custom_partitions the value is the selected partitioning from boards.txt

Thanks for your suggestion, I've checked platform.txt and found custom_partitions as well.  Unfortunately, it didn't help: arduino-cli compile sketch --build-property build.custom_partitions=huge_app results in Sketch uses 646558 bytes (49%) of program storage space. Maximum is 1310720 bytes.

Are you uploading the bin file by arduino-cli?

So, it turns out I have to add another build property:
> arduino-cli compile --build-property build.partitions=huge_app --build-property upload.maximum_size=3145728 sketch

where the upload.maximum.size is from the boards.txt file.  Indeed, a maze of twisty little files, all alike.

Just like the original Adventure. :)


text:
Access non contiguous RAM slots in Arduino Nicla Vision
I'm working on a TinyML project with an Arduino Nicla Vision and I need to store a model with size 608kB in RAM. In the Nicla Vision datasheet, it is stated that 864kB of SRAM are available, but it is segmented in three non contiguous parts (AXI SRAM, SRAM1-3, SRAM4).

When I try to load the model in RAM, I get the error 'linker_script.ld:110 cannot move location counter backwards (from 240aa610 to 2407fc00)' because only the AXI SRAM (524kB) is used.
Is there a way to distribute the model over all the available non contiguous RAM?


text:
I'm planning on using 2 arduino boards for my project. Should I use 2 voltage regulators for project or use 1 for both?
For context, my first board would contain a motor circuit with an L298N motor driver while my second contains a controlled heating system that uses 2 relays with PTC heating elements, DHT11 sensor, I2C LCD display, and 1 12V exhaust fan.
My input would be a 12V DC power adapter and I'm going to use it to run the motor, the fan, and the 2 heating elements.
Since I want to minimize the chances of my boards from overheating, I want to reduce the input voltage for my board to around 7V, so I want to integrate a voltage regulator circuit.
Should I include 2 voltage regulator circuits or should just utilize 1 for both boards?

The Uno already has a voltage regulator. Can you clarify (perhaps with a diagram) what you are trying to do exactly?

I dont want to overheat my arduino boards and I've heard from a few sources 12V could potential do that even thought its within range

If you are that concerned with heat from the built in linear power supplies, consider using an external switching power supply.  However, the current draw of only the 2 processors is so low that this switch may not be noticeable.

Nick and st2000, OP writes in the question "I want to reduce the input voltage for my board to around 7V, so I want to integrate a voltage regulator circuit" (and it was not edited)

the Q is "Should I include 2 voltage regulator circuits or should just utilize 1 for both boards?" and the answers is 1 or 0

but why 12 to 7 and then 7 to 5? use a 12 V to 5 V converter and power the boards over the 5 V pin or USB connector.

If you want an external voltage regulator, one should be plenty. In that case I would regulate down to 5V (not 7V) and connect that to the 5V pin on the board.
An alternative might be to just run the 12V from the battery through a diode or two, thus dropping 0.7V for each diode. Use a diode that can handle a reasonable amount of current, eg. 1N4004. Then you would still connect it to the normal "power input" socket (not the 5V pin).
I assume that the heating, motors, etc., are not being powered by the Arduino board, but directly from the battery via some sort of switching, like a MOSFET or a relay.

I would use a buck or SEPIC regulator and feed Vin on each of the Arduino with about 7.5V from the one regulator. I prefer using Vin because of the additional filtering I get. Also be sure you are using appropriate drivers for your loads, such as relays or MOSFETs.
Consider replacing the L298N with a newer part, that will lose about 3V on the motor leads which is burnt up as heat in the device. There are many others that use MOSFET outputs which will drop less them 0.2 volts.


text:
nano 33 BLE problems with reading RC signal
I'm using an Arduino Nano 33 BLE and a L293D motor driver to control a three-wheeled RC robot. The sketch I'm using worked fine with my Uno Rev3, but I've moved to the Nano for size/weight reasons, and it's no longer working. Whenever I turn the power on, the motor I'm using to test spins clockwise at what appears to be full-speed, without considering the receiver's signal at all. I actually removed the wires from the receiver and the motor just kept on spinning.
I tried looking at the serial plotter, but it appears that the Nano is disconnecting itself from my laptop whenever I turn the RC transmitter on, so I haven't been able to get any information that way.
I've troubleshooted to the best of my limited ability, and the problem seems to be with the Nano not processing the signals from the receiver. Beyond that, though, I don't have the first clue what the root of the problem is. I'm pretty new to Arduino & coding haha.
I followed this YouTube tutorial for the process of reading the RC values, and the variables with color names are referring to the motors. Here's the sketch:
//set the port speed for host communication
#define SERIAL_PORT_SPEED 115200

#include <math.h>
#define RC_NUM_CHANNELS 2
#define RC_CH1 0 //right stick LR
#define RC_CH2 1 //right stick UD
#define RC_CH1_INPUT 2 //pin 2 on arduino
#define RC_CH2_INPUT 3 //pin 3 on arduino

// Set up some arrays to store our pulse starts and widths
uint16_t RC_VALUES[RC_NUM_CHANNELS];
uint32_t RC_START[RC_NUM_CHANNELS];
volatile uint16_t RC_SHARED[RC_NUM_CHANNELS];

const int enable_pink = 13; //pin that enables pink motor
const int enable_blue = 12;
const int enable_yellow = 11;

int dead_zone = 10; //within 10 of 0, motor will not move
const int error_pin = 4; //this lights up when something unexpected happens
int UD;
int RL;
double pi = 3.1415926;

int pink; // analog value out of 255 for the pink motor
const int pink_cw = 5; // pin that signals pink motor to move clockwise
const int pink_ccw = 6; //pin signals counterclockwise
int blue;
const int blue_cw = 7;
const int blue_ccw = 8;
int yellow;
const int yellow_cw = 9;
const int yellow_ccw = 10;

void setup() {
  // set the speed to communicate with the host PC:
  Serial.begin(SERIAL_PORT_SPEED);

  //set pin modes to input for reciever
  pinMode(RC_CH1_INPUT, INPUT);
  pinMode(RC_CH2_INPUT, INPUT);
  //attach interrupts to these pins
  attachInterrupt(digitalPinToInterrupt(RC_CH1_INPUT), READ_RC1, CHANGE);
  attachInterrupt(digitalPinToInterrupt(RC_CH2_INPUT), READ_RC2, CHANGE);
  //set pin mode for error pin
  pinMode(error_pin, OUTPUT);

  //set all green wires (motor-enabling wires) to OUTPUT
  pinMode(enable_pink, OUTPUT);
  pinMode(enable_blue, OUTPUT);
  pinMode(enable_yellow, OUTPUT);

  //set all motor signal outputs to OUTPUT
  pinMode(pink_cw, OUTPUT);
  pinMode(pink_ccw, OUTPUT);
  pinMode(blue_cw, OUTPUT);
  pinMode(blue_ccw, OUTPUT);
  pinMode(yellow_cw, OUTPUT);
  pinMode(yellow_ccw, OUTPUT);

  //enable all motors
  digitalWrite(enable_pink, HIGH);
  digitalWrite(enable_blue, HIGH);
  digitalWrite(enable_yellow, HIGH);

}

void loop() {
  // read the values from our RC reciever
  rc_read_values();

  //map RC values to analog scale
  UD = map(RC_VALUES[RC_CH1], 800, 2200, -100, 100);
  RL = map(RC_VALUES[RC_CH2], 800, 2200, -100, 100);

  //output raw RC input to serial plotter
  Serial.print(UD); Serial.print(",");
  Serial.println(RL);

  //do the math to calculate wheel vectors
  pink = RL;
  blue = (UD/(cos(pi/3))) + (RL/(sin(pi/3)));
  yellow = -(UD/(cos(pi/3))) - (RL/(sin(pi/3)));

  //now map the wheel vectors to analog scale:
  blue = map(blue, -800, 800, -255, 255);
  yellow = map(yellow, -800, 800, -255, 255);

  //now, output each value to each motor
  set_color(pink, pink_cw, pink_ccw);
  set_color(blue, blue_cw, blue_ccw);
  set_color(yellow, yellow_cw, yellow_ccw);

  //output pink blue and yellow values to serial plotter:
  Serial.print(pink); Serial.print(",");
  Serial.print(blue); Serial.print(",");
  Serial.println(yellow);

}

//create function to give the signals to the motors
void set_color(int color, int color_cw, int color_ccw) {
  if (color > dead_zone) {
    analogWrite(color_cw, color);
  } else if (color <-(dead_zone)) {
    analogWrite(color_ccw, abs(color));
  } else if (color <= dead_zone && color >= -(dead_zone)) {
    return;
  } else {
    digitalWrite(error_pin, HIGH);
  }
}

// These functions are called by the interrupts. We send them all to the same place to measure the pulse width
void READ_RC1() {
   Read_Input(RC_CH1, RC_CH1_INPUT);
}
void READ_RC2() {
   Read_Input(RC_CH2, RC_CH2_INPUT);
}

// This function reads the pulse starts and uses the time between rise and fall to set the value for pulse width
void Read_Input(uint8_t channel, uint8_t input_pin) {
  if (digitalRead(input_pin) == HIGH) {
    RC_START[channel] = micros();
  } else {
    uint16_t rc_compare = (uint16_t)(micros() - RC_START[channel]);
    RC_SHARED[channel] = rc_compare;
  }
}

// this function pulls the current values from our pulse arrays for us to use.
void rc_read_values() {
  noInterrupts();
  memcpy(RC_VALUES, (const void *)RC_SHARED, sizeof(RC_SHARED));
  interrupts();
}

any help would be greatly appreciated, I'm truly stumped here

a smaller Uno is a classic Nano. Nano 33 BLE is very different and uses Mbed OS.

The "nano" is basically form factor + pinout, 33 in the board name means it's 3.3V only board (usually has ARM mcu) and being said nano 33 ble has mbed-os which means your code will be interrupted by other threads (unless it has higher priority than other threads)


text:
display.begin(); function breaks working code
I've been setting up a system using an Arduino Uno board that reads from both an Adafruit MPU6050 6-way gyroscope and accelerometer and an Adafruit NAU7802 connected to a load sensor. I have code for that working, but I would also like to connect an Adafruit FeatherWing OLED to display the results.
Since this is the first time I've used Arduino or any of these parts, I first wrote a sketch to output the readings from my sensors into the serial monitor and a separate sketch to experiment with the display. However, when I try to use the code from the display sketch with my sensor reading script, it completely breaks the working sensor script.
My void setup code for my sensors looks like:
#include <Adafruit_MPU6050.h>
#include <Adafruit_NAU7802.h>

Adafruit_MPU6050 mpu;
Adafruit_NAU7802 nau;

void setup() {
  Serial.begin(115200);

  Serial.println("\n\nstart test\n");
  delay(10);

  if (!mpu.begin()) {
    Serial.println("Failed to find MPU6050 chip");
    } else {
      Serial.println("MPU6050 Found!");
    }
  if (!nau.begin()) {
    Serial.println("Failed to find NAU7802");
    } else {
      Serial.println("NAU7802 Found!");
    }

I then tried to add a few lines to power up the display:
#include <Wire.h> //for I2C
#include <Adafruit_MPU6050.h> //for 6-way
#include <Adafruit_NAU7802.h> //for ADC
#include <Adafruit_GFX.h> //for display
#include <Adafruit_SH110X.h> //for display

Adafruit_MPU6050 mpu;
Adafruit_NAU7802 nau;
Adafruit_SH1107 display = Adafruit_SH1107(64, 128, &Wire);

void setup() {
  Serial.begin(115200);

  Serial.println("\n\nstart test\n");

  if (!mpu.begin()) {
    Serial.println("Failed to find MPU6050 chip");
    } else {
      Serial.println("MPU6050 Found!");
    }
  if (!nau.begin()) {
    Serial.println("Failed to find NAU7802");
    } else {
      Serial.println("NAU7802 Found!");
    }

  delay(200); //allows OLED to power up
  display.begin(0x3C, true); // Address 0x3C default
  display.display();
  delay(1000);

  display.clearDisplay();
  display.display();

}

Does not turn on the display, but instead causes all of the code in the setup before the display.begin() function is called to loop indefinitely (even though it's not even in the loop part of the sketch.)
I have no idea what is going on here, and any advice would be appreciated! Thank you!
EDIT: Thank you so much for all of the comments! I will try to answer the questions as best as I can here.
I was only powering the device through the USB port. Based on your suggestions, I tried the script again using 9V through the barrel jack to power the device, but it, unfortunately, didn't fix the issue.
I tried reversing the dimensions in the Adafruit_SH1107(64, 128, &Wire) function, but that also didn't change anything. Also, all of my libraries are up to date as far as I can tell.
Both the OLED and the sensors successfully run independently while both are attached to the circuit. So -- I can get the OLED to display something while the sensors are attached to the circuit, and I can get the sensors to read into the serial monitor while the display is attached to the circuit. The problem arises when I try to have all of the parts called in the same script.
Here's a picture of the circuit:
Thank you all again for your help!

setup() loops when the arduino is repeatedly resetting ... maybe the arduino has inadequate power

Please show us your circuit and explain how you are powering everything

Not sure this is related. but according to the Adafruit_SH110x library, the api for create an instance is Adafruit_SH1107(WIDTH, HEIGHT, &Wire), you seems to had it revered with width = 64, and height = 128 in Adafruit_SH1107(64, 128, &Wire).

If the OLED was working independently then resetting the Arduino due to incorrect initialization (dimensions) is unlikely. The same can be said for using an outdated version of the Adafruit GFX library. Never the less, the Adafruit SH1107 driver does come w/this warning: "This library depends on Adafruit_GFX being present on your system. Please make sure you have installed the latest version before using this library.".  Please double check these settings/configurations and update your Question if necessary.

Also, can you please clarify that you can run the sensors while the OLED hardware is installed but the OLED software is not in the Sketch?  All these devices (OLED, Accelerometer & Stress Sensor) exist on your I2C bus.  And several have independent pull up resistors. In a good hardware design there should only be 1 set up pull up resistors at the far end of the I2C bus.  Having multiple higher resistance pull up resistors will likely work but there is an upper limit.