text:
Read one byte from file and convert to decimal
Ok, I'm fairly new to Arduino and I'm trying to read bytes from a file in an SD card and convert to integer values (0-255).
I have a file, with 1 byte on it (128 int value, created in Python, can provide the code if necessary) and the hex dump (binary mode) is:
xxd -b single_byte.dat
00000000: 10000000

So far so good, right? So I was expecting to read this byte from the file (SD card) and then convert back to 128 value. This is my Arduino code:
#include <SPI.h>
#include <SD.h>

// set up variables using the SD utility library functions:
Sd2Card card;
SdVolume volume;
SdFile root;
const int chipSelect = 4;

void setup() {
  // Open serial communications and wait for port to open:
  Serial.begin(9600);
  while (!Serial) {
    ;
  }

  delay(100);
  Serial.print("\nInitializing SD card...");

  if (!card.init(SPI_HALF_SPEED, chipSelect)) {
    Serial.println("initialization failed. Things to check:");
    Serial.println("* is a card inserted?");
    Serial.println("* is your wiring correct?");
    Serial.println("* did you change the chipSelect pin to match your shield or module?");
    while (1);
  } else {
    Serial.println("Wiring is correct and a card is present.");
  }

  // print the type of card
  Serial.println();
  Serial.print("Card type:         ");
  switch (card.type()) {
    case SD_CARD_TYPE_SD1:
      Serial.println("SD1");
      break;
    case SD_CARD_TYPE_SD2:
      Serial.println("SD2");
      break;
    case SD_CARD_TYPE_SDHC:
      Serial.println("SDHC");
      break;
    default:
      Serial.println("Unknown");
  }

  // Now we will try to open the 'volume'/'partition' - it should be FAT16 or FAT32
  if (!volume.init(card)) {
    while (1);
  }

  File file;
  byte one_byte;
  int dec_value;

  file = SD.open("single_byte.dat", FILE_READ);
  one_byte = file.read();
  file.close();

  dec_value = int(one_byte);

  Serial.println(dec_value, DEC);

}

void loop(void) {
}

I was expecting the output to be 128.
However I get:

What am I missing? (yes, I tried generating the .dat file with big-endian encoding, same result)

Which version of Python are you using? "Note: Since Python 3.6, all files are read and written by Python using utf-8 by default, even on Windows."  Maybe you are writing UTF16 and do not realize it.  What happens if you try to read the next byte, and the next?

I'm using Python 3.9 (on Debian 11)... I haven't tried reading more bytes but, the hex dump displays a single byte on the file so, I think file is ok?

Oh, I think I see what you did.  Try adding SD.begin.

I just tried adding the SD.begin(4) code, no luck, same result as before: message "initialization done" is displayed, but the output on my variable is the same. What else can I try? Maybe the int(one_byte) is not the way to go and something else (bit manipulation?) must be done?

@melev Can you update your code to show where you added the SD.begin(4)?

... @melev, I see where you get most of your code from the 2nd example on the arduino.cc page I linked to in the answer below.  Assuming all examples on that page work, consider using just the 1st example on that same page.  True, it does not give you as much diagnostic details, but it may be a better place to start given our assumption the example is able to open and read a file on an SDCard successfully.

@st2000 I got it working, turns out I'm an idiot, LOL. your comment "given our assumption the example is able to open file" got me thinking, so I added an if(file) and guess what... it wasn't!!! so I was just reading garbage I guess. I'm posting the full explanation as the answer, thanks A LOT for your time.

@Fahad I got it working, it was the freaking filename that was the problem, check my answer. Thanks!

FWIW, xxd clearly shows that the file doesn't contain a single byte, it contains 4 bytes. Probably a uint32le. But, the nice thing about little-endian is that if you read it as a single byte you'll get the right answer anyway as long as the value is <256.

Ok, I got it working now, here's what was happening:
Turns out the file wasn't being opened. Why? seems like there's a limitation on the filename length, I noticed this after adding the lines:
root.openRoot(volume);
// list all files in the card with date and size
root.ls(LS_R | LS_DATE | LS_SIZE)

And sure enough my file was not detected as single_byte.dat but it was something like: single_~.dat so I renamed the file to test.dat and tada! code now works like a charm.
I guess I overlooked this restriction on the documentation, so keep this in mind when you use an SD card.
Also, make sure to check if you are really opening your file because no exception will be thrown if you reference an uninitialized file pointer I guess.
Just make sure to have:
file = SD.open(filename, FILE_READ);
if(file){
    // Do things here.
}
else{
    Serial.println("You're out of luck: Can't open file");
}

Ok, there goes my Sunday. Thanks all for reading!!!

The root of this restriction is partly Microsoft and partly the library. On one hand Microsoft stuffed long file names on their old FAT filesystems trying to be backwards compatible. Each files has a 8+3 short name and following some directory entries for the long name. On the other hand the library apparently saves on size and left out the code to work with long names. -- However, the main lesson you learned is: Always check return values!

Ah, good catch! So you asked: "Why? seems like there's a limitation on the filename length, I noticed this after adding the lines:"  The "Why" is because the FAT file system format dates back from when Bill Gates grabbed something called DOS from some computer club.  That fixed all file names to 8.3 or an eight-characters-decimal-point-three-character format.  That still exists.  Some clever workarounds are used to hide it.  But it still exists.  So the actual file name gets "mangled" when you try to go beyond the 8.3 format. I think the clever trick is that they all get "mangled" uniquely.

Consider adding a call to SD.begin() as is done in the example found on this arduino.cc web page.
Here's the section of the example code where SD.begin() is used:
  Serial.print("Initializing SD card...");

  if (!SD.begin(4)) {
    Serial.println("initialization failed!");
    while (1);
  }


text:
Arduino IDE v 2.2.1 log file not limited in size (on Ubuntu 23.04)
I was learning/building with a new Arduino Nano ESP32 yesterday and left the Arduino IDE running overnight on Ubuntu 23.04 and it used all the space on my hard drive to write log files which broke my system till I booted in with a pen drive and removed some files to make space to then boot normally and find out what the problem was.
How can I limit the size of these log files, or even disable them?

I have been having the same issue. I think it might have something to do with the serial monitor being open, but I haven't found a fix yet.

Well, you could do it at the Unix level if you can't restrict it otherwise say using a volume quota, a script or other trick.

source: Stack Exchange

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

sort: votes


text:
Is there a way to retrieve signature from the Voice Recognition module? (Elechouse Voice Recognition V3.1)\
As of right now, I'm attempting to build a voice recognition system that will respond to what I say accordingly. I have been scouring as to how to retrieve the signature from the voice recognition module's library.
This is my result:

My arduino code that produced the result is below:
#include <SoftwareSerial.h>
#include "VoiceRecognitionV3.h"

VR myVR(2,3);

uint8_t record[7];
uint8_t buf[64];

#define onRecord (0)
#define offRecord (1)

void printSignature (uint8_t *buf, int len) {
  int i;
  for(i = 0; i < len; i++) {
    if(buf[i] > 0x19 && buf[i] < 0x7F) {
      Serial.write(buf[i]);
  } else {
      Serial.print("[");
      Serial.print(buf[i], HEX);
      Serial.print("]");
    }
  }
}

void printVR(uint8_t *buf)
{
  Serial.println("VR Index\tGroup\tRecordNum\tSignature");

  Serial.println(buf[2], DEC);
  Serial.println("\t\t");

  Serial.print(buf[2], DEC);
  Serial.print("\t\t");

  if(buf[0] == 0xFF){
    Serial.print("NONE");
  }
  else if(buf[0]&0x80){
    Serial.print("UG ");
    Serial.print(buf[0]&(~0x80), DEC);
  }
  else{
    Serial.print("SG ");
    Serial.print(buf[0], DEC);
  }
  Serial.print("\t");

  Serial.print(buf[1], DEC);
  Serial.print("\t\t");
  if(buf[3] >0) {
    printSignature(buf+4, buf[3]);
  }
}

void setup() {
  myVR.begin(9600);

  Serial.begin(115200);

  if(myVR.clear() == 0) {
    Serial.println("Recognizer cleared.");
  } else {
    Serial.println("Not find VR Module");
    while(1);
  }

  if(myVR.load((uint8_t)onRecord) >= 0){
    Serial.println("onRecord loaded");
  }

  if(myVR.load((uint8_t)offRecord) >= 0){
    Serial.println("offRecord loaded");
  }
}

void loop() {
  int ret;
  ret = myVR.recognize(buf, 50);

  if(ret > 0) {
    printVR(buf);
  }
}

Any suggestions as to how I'd go in retrieving the signature from this module?
Edit: The module have been trained to recognize my speech saying "two" and is assigned
 the signature 'two'.

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


text:
Problem with I2C
I trying to make a project to write and i2c display from a renault megane vehicle. There is many people showing it but there is no code that i can use.
So i buy a cheap analyzer and i can clearly see what radio says to display.
Now i try to do it with arduino... but there is something wrong... i can just read a sequence of "01000110" thats i think that is begin transmission ... but what i write with "Wire.write" is not sending or something... Im so frustrating ... if anyone can tell me why im not receiving more data than 01000110 will be awesome. I will give 2 screens to let us know more.
This is the sniff from the radio

This is the sniff from my code

As you can see only the 01000110 bits is same for both, but there is no more data...
This is my arduino code
    #include <Wire.h>
int _mrq = 2;
void setup() {
  pinMode(_mrq, OUTPUT);
  digitalWrite(_mrq, HIGH);

  Wire.begin();
  Wire.setClock(7140);
  Wire.beginTransmission(0x23);
  delay(500);
  digitalWrite(_mrq, LOW);
  sendInit(0x01, 0x01);
  digitalWrite(_mrq, HIGH);
  delay(100);
  digitalWrite(_mrq, LOW);
  sendInit(0x01, 0x10);
  digitalWrite(_mrq, HIGH);
  Wire.endTransmission();
}

void loop() {
  delay(500);
  Wire.beginTransmission(0x23);
  digitalWrite(_mrq, LOW);
  sendInit(0x01, 0x01);
  Wire.write(0x0c);
  Wire.write(0x90);
  Wire.write(0x7e);
  Wire.write(0x72);
  Wire.write(0x01);
  Wire.write(0x20);
  Wire.write(0x4c);
  Wire.write(0x4f);
  Wire.write(0x53);
  Wire.write(0x34);
  Wire.write(0x30);
  Wire.write(0x20);
  Wire.write(0x20);
  sendInit(0x01, 0x11);
  digitalWrite(_mrq, HIGH);
  Wire.endTransmission();
  delay(1);
}

void sendInit(int a, int b)
{
  delay(20);
  Wire.write(a);
  delay(100);
  Wire.write(b);
  delay(20);
}

so, what is your question?

The NAK that you're getting is stopping any further communication. Either whatever you're sending to doesn't like what you're sending, or it's wired up wrong.

Please tell us, how everything is wired up. Also: What voltage levels do the Atmega2560 and the I2C display use?

@chrisl I have 3 cables, PIN 2 is MRQ that is a stuff that use radio / display, and pin 20 and 21 (SDA/SCL) display uses 12v but sda/scl is digital and works from 0 to 5.

What is MRQ here? Has it something to do with the display? The delays around Wire.write() are meaningless. This function only puts the data into a buffer. The actual transmission is done only in Wire.endTransmission()

@chrisl nope https://i.gyazo.com/b568257e5489418adaafaaa700c23234.png now i put MRQ to ground before endtransmission and then high again... but sill missing all, only 01000110 is received (again)

Please try to add a delay between outputting ground to MRQ and Wire.endTransmission(). I think the MRQ pin activates the I2C peripheral of the display. It might need some time, before it is ready to answer.

After reading something about I2C i know that i got NACK... so something goes wrong... but in the radio sniff it get ACK so its OK ... maybe the speed is the problem ? https://i.gyazo.com/6c397a8063fce2bb183753653bc100ba.png (radio) https://i.gyazo.com/2b5190053f046b0402271bb6204a8f0c.png (arduino) (i set speed to 7140 (7.14 Khz with Wire.setClock(7140), its ok ?

Only specific values are valid for the frequency. You cannot set it to arbitrary values. At least thats what the documentation says. Have you included the delay before endTransmission?

yep, i added a 500 microseconds after and before endTransmission


text:
Error code board and boards.txt? Formatting error? cannot verify alarm.txt or any
Arduino: 1.8.8 (Windows 10), Board: "Arduino/Genuino Uno"
Error reading file (E:\arduino\arduino-1.8.8\hardware\arduino\avr**\boards.txt:0**): Invalid line format, should be 'key=value'
Error compiling for board Arduino/Genuino Uno.[/b]
This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.
I was trying to do this experiment: http://wirebeings.com/arduino-intruder-alarm.html
but with Arduino Uno + geeetech iduino yun shield setup.
http://www.geeetech.com/wiki/index.php/Iduino_Yun_Shield
Please help (also short do you short the two pins properly?)
this is the board.txt file:
unoyun.name=Arduino Uno --Iduino Yún
unoyun.upload.via_ssh=true
unoyun.vid.0=0x2341
unoyun.pid.0=0x0043
unoyun.vid.1=0x2341
unoyun.pid.1=0x0001
unoyun.upload.tool=avrdude
unoyun.upload.protocol=arduino
unoyun.upload.maximum_size=32256
unoyun.upload.maximum_data_size=2048
unoyun.upload.speed=57600
unoyun.upload.disable_flushing=true
unoyun.upload.use_1200bps_touch=true
unoyun.upload.wait_for_upload_port=true
unoyun.bootloader.tool=avrdude
unoyun.bootloader.low_fuses=0xff
unoyun.bootloader.high_fuses=0xde
unoyun.bootloader.extended_fuses=0x05
unoyun.bootloader.file=optiboot/optiboot_atmega328.hex
unoyun.bootloader.unlock_bits=0x3F
unoyun.bootloader.lock_bits=0x0F
unoyun.build.mcu=atmega328p
unoyun.build.f_cpu=16000000L
unoyun.build.board=AVR_YUN
unoyun.build.core=arduino
unoyun.build.variant=standard

and this is the boards.txt file:
# See: http://code.google.com/p/arduino/wiki/Platforms

menu.cpu=Processor

##############################################################

yun.name=Arduino Yún
yun.upload.via_ssh=true

yun.vid.0=0x2341
yun.pid.0=0x0041
yun.vid.1=0x2341
yun.pid.1=0x8041
yun.vid.2=0x2A03
yun.pid.2=0x0041
yun.vid.3=0x2A03
yun.pid.3=0x8041

yun.upload.tool=avrdude
yun.upload.protocol=avr109
yun.upload.maximum_size=28672
yun.upload.maximum_data_size=2560
yun.upload.speed=57600
yun.upload.disable_flushing=true
yun.upload.use_1200bps_touch=true
yun.upload.wait_for_upload_port=true

yun.bootloader.tool=avrdude
yun.bootloader.low_fuses=0xff
yun.bootloader.high_fuses=0xd8
yun.bootloader.extended_fuses=0xfb
yun.bootloader.file=caterina/Caterina-Yun.hex
yun.bootloader.noblink=caterina/Caterina-Yun-noblink.hex
yun.bootloader.unlock_bits=0x3F
yun.bootloader.lock_bits=0x2F

yun.build.mcu=atmega32u4
yun.build.f_cpu=16000000L
yun.build.vid=0x2341
yun.build.pid=0x8041
yun.build.usb_product="Arduino Yun"
yun.build.board=AVR_YUN
yun.build.core=arduino
yun.build.variant=yun
yun.build.extra_flags={build.usb_flags}

##############################################################

uno.name=Arduino/Genuino Uno

uno.vid.0=0x2341
uno.pid.0=0x0043
uno.vid.1=0x2341
uno.pid.1=0x0001
uno.vid.2=0x2A03
uno.pid.2=0x0043
uno.vid.3=0x2341
uno.pid.3=0x0243

uno.upload.tool=avrdude
uno.upload.protocol=arduino
uno.upload.maximum_size=32256
uno.upload.maximum_data_size=2048
uno.upload.speed=115200

uno.bootloader.tool=avrdude
uno.bootloader.low_fuses=0xFF
uno.bootloader.high_fuses=0xDE
uno.bootloader.extended_fuses=0xFD
uno.bootloader.unlock_bits=0x3F
uno.bootloader.lock_bits=0x0F
uno.bootloader.file=optiboot/optiboot_atmega328.hex

uno.build.mcu=atmega328p
uno.build.f_cpu=16000000L
uno.build.board=AVR_UNO
uno.build.core=arduino
uno.build.variant=standard

##############################################################

diecimila.name=Arduino Duemilanove or Diecimila

diecimila.upload.tool=avrdude
diecimila.upload.protocol=arduino

diecimila.bootloader.tool=avrdude
diecimila.bootloader.low_fuses=0xFF
diecimila.bootloader.unlock_bits=0x3F
diecimila.bootloader.lock_bits=0x0F

diecimila.build.f_cpu=16000000L
diecimila.build.board=AVR_DUEMILANOVE
diecimila.build.core=arduino
diecimila.build.variant=standard

two boards.txt files or did I edit it wrong and the "and this is the boards.txt file:" is inside your board.txt file?

two files
both in \hardware\avr - board.txt or boards.txt file worked

nvm, apparently some guys suggesting utf-8 bom encoding change or something because I saw 1 question related to this
(it didn't work)
then I changed it to utf-8 encoding
(both done through notepad++)
it worked.

John Doe, thanks for the tip about utf-8.
I just ran into this exact problem.  boards.txt had been hand-edited in Windows Notepad and saved as utf-8 and was throwing this error.
Arduino: 1.8.10 (Windows 10), Board: "Arduino/Genuino Uno"
loading hardware from C:\Program Files (x86)\Arduino\hardware:
loading package arduino: loading platform release:
Error reading file (C:\Program Files (x86)\Arduino
\hardware\arduino\avr\boards.txt:0):
Invalid line format, should be 'key=value'

I changed the text file format to ANSI and saved, and that fixed the problem, able to compile.  At this point, guessing that maybe changing format merely cleaned up a defect, I saved again to utf-8, but it broke again.  Thus back to ANSI.


text:
ESP8266 SoftwareSerial not receiving any character
I want to use a ESP8266 (ESP12) to receive data from a counter at 9600 baud via SotwareSerial. But my program does not receive any data. I broke it down to the code i attach here. I tried it using different libraries (Arduino SoftwareSerial and also espsoftwareserial) i found. I connected and tested RX and TX in different combinations of the available pins 4/5/12/13/14. But no combination is receiving data at all. I only can send data - checked by oscilloscope. Running my test program attached i connected the RX and TX pin together so i should loop back the data from tx.
I hopefully find somebody in the community who can give me a helpful hint. Thank you in advance!
#include <SoftwareSerial.h>
SoftwareSerial mySerial1(14, 12, false, 256);  // RX, TX

void setup() {
mySerial1.begin(9600);   //  Kommunikation mit Zähler
mySerial1.setTimeout(5000);
mySerial1.listen();
//delay(100);
//mySerial1.listen();

Serial.begin(9600);
delay(1000);
Serial.print(__DATE__);Serial.print(" ");Serial.println(__TIME__);

char ch;
while(1){
  wdt_reset();
  Serial.println("\nSoftware serial test started");
  Serial.print("Data sent: ");
  for (byte i = 32; i < 128; i++) { mySerial1.write(i);
  Serial.print(char(i)); }
  Serial.println();
  mySerial1.println();
  ESP.wdtFeed();
  delay(100);
  Serial.print("Data recv: ");
  if(mySerial1.available()) {
    while(mySerial1.available()){
      ch = mySerial1.read();
      Serial.print(ch);
    }
    Serial.println("_");
  }
  delay(400);
}
}

void loop() {}

Dear @fhpa, before answering, I suggest you to remove while(1) from setup() function and move content of while(1) inside loop() function. Loop() function, as suggested by its name, loops consecutively. https://www.arduino.cc/en/Reference/Loop?setlang=en

Please, be more precise, provide the schematic. Are you sure that connection are correct?

Thank you commenting. Yes, the connections have been correct. In the meantime my question was answered and the problem is solved: SoftwareSerial cannot send and receive at the same time.

If the ESP8266's software serial is anything like the Arduino's software serial, it cannot receive data while it's transmitting. It's strictly half-duplex.
To test your system you will need to test the transmission and reception completely separately, and that means having some external device sending data for you to attempt to receive.

Thank you Majenko for your answer solving the problem. You are right saying the SoftwareSerial is working strictly half duplex. I tested it with a second esp only sending data and receiving with the second ESP. BTW i only need to receive data. I think you saved me a lot of my time!


text:
How to use ESP8266 with Google API for GPS as well as controlling Arduino pins
I am working on IoT based project and I want to control the device using mobile App. Everything works fine, I can switch the load and get the status back on mobile app, but I want to use my ESP8266 as a GPS using google API.
I have googling many many times but people work with standalone ESP8266 as a GPS using google API.
Here there are the two github project for Standalone ESP8266 as GPS:

Google GeoLocation API wrapper for Arduino MKR1000, ESP8266 and ESP32
Google Geolocation API for fetching location on ESP8266 board without using any GPS hardware

My Question is: how can I use my ESP8266 for IoT application (Controlling the Arduino pins) as well as GPS module using Google API?
In my case, I need to use an Arduino Mega/Uno because much more sensors were used in this project which I not mentioned here.
I attached my code, its working perfect, means I controlled the Arduino pins and Arduino send the status using ESP8266 on my mobile App.
String server = ""; //variable for sending data to webpage
boolean No_IP = false; //variable to check for ip Address
String IP = ""; //variable to store ip Address
char data;
char values = 'c';
int flag = 1;

 void setup()
{
Serial.begin(9600);
Serial1.begin(9600);
wifi_init();
delay(200);
showIP();

}

    void loop()
{
  delay(50);
  String temp = "";
while(Serial1.available()) // Check the Esp Serial
{
  temp = Serial1.readString(); // Read the String from Esp Serial
  Serial.println(temp);
  delay(50);
}
if ((temp.substring(11) == "a" or temp.substring(11) == "A") and flag == 1) // If "a" or "A" received
{
  digitalWrite(13,HIGH); // Load conected on pin 13 ON
  Serial.println("Char received High");
  flag = 0;
  sendData("Light On");
  delay(1000);
}

else if ((temp.substring(11) == "a" or temp.substring(11) == "A") and flag == 0)
{
  digitalWrite(13,LOW); // Load conected on pin 13 OFF
  Serial.println("Char received Low");
  flag = 1;
  sendData("Light Off");
  delay(1000);
}
else
{

}

delay(200);

} // Void loop End

These are the functions which is used to established the connection.
Note: I used the ESP 8266 in Station mode
Check in void wifi_init() function,
`
void findIp(int time1) //check for the availability of IP Address
{
  int time2 = millis();
  while (time2 + time1 > millis())  {
    while (Serial1.available() > 0)    {
      if (Serial1.find("IP has been read"))      {
        No_IP = true;
      }
    }
  }
}

void showIP()//Display the IP Address
{
  IP = "";
  char ch = 0;
  while (1)
  {
    Serial1.println("AT+CIFSR");
    while (Serial1.available() > 0)
    {
      if (Serial1.find("STAIP,"))
      {
        delay(1000);
        Serial.print("IP Address:");
        while (Serial1.available() > 0)
        {
          ch = Serial1.read();
          if (ch == '+')
            break;
          IP += ch;
        }
      }
      if (ch == '+')
        break;
    }
    if (ch == '+')
      break;
    delay(1000);
  }
  Serial.print(IP);
  Serial.print("Port:");
  Serial.println(80);
}

void establishConnection(String Serial1and, int timeOut) //Define the process for sending AT Serial1ands to module
{
  int q = 0;
  while (1)
  {
    Serial.println(Serial1and);
    Serial1.println(Serial1and);
    while (Serial1.available())
    {
      if (Serial1.find("OK"))
        q = 8;
    }
    delay(timeOut);
    if (q > 5)
      break;
    q++;
  }
  if (q == 8)
    Serial.println("OK");
  else
    Serial.println("Error");
}

void wifi_init() //send AT Serial1ands to module
{

  establishConnection("AT", 100);

  establishConnection("AT+CWMODE=1", 100);
  establishConnection("AT+CWQAP", 100);
  findIp(5000);
  if (!No_IP)
  {
    Serial.println("Connecting Wifi....");
    establishConnection("AT+CWJAP=\"SSID\",\"PASSWORD\"", 7000);        //provide your WiFi username and password here
  }
  else
  {
  }
  Serial.println("Wifi Connected");
  // showIP();
  establishConnection("AT+CIPMUX=1", 5000);
  establishConnection("AT+CIPSERVER=1,80", 7000);
}

void sendData(String server1)//send data to module
{
  int p = 0;
  while (1)
  {
    unsigned int l = server1.length();
    Serial.print("AT+CIPSEND=0,");
    Serial1.print("AT+CIPSEND=0,");
    Serial.println(l + 2);
    Serial1.println(l + 2);
    delay(100);
    Serial.println(server1);
    Serial1.println(server1);
    while (Serial1.available())
    {
      Serial.print(Serial.read());
      if (Serial1.find("OK"))
      {
        p = 11;
        break;
      }
    }
    if (p == 11)
      break;
    delay(100);
  }
}

Is it possible to use ESP8266 for IoT applications as well as GPS module using google API?

@Juraj problem is that How to GPS values (long and lat) get using google API?. because in the above I mention, #include "ESP8266WiFi.h" used in first link and others, and in the second link #include <WifiLocation.h> is used. Both are not compatable with Arduino mega. these libraries are used with NodeMCU and ESP8266 standalone.....

sorry. you use AT commands. hard to see in you snippets for what platform the code is. then start to code for the esp8266. put the networking part and location in the esp8266 and exchange data with Mega over Serial

@Juraj I can't understand your comment, have you any solution, so please can you share code snippet on answer?. that how ESP 8266 works the above functionality and also getting the GPS location from google API and then exchange with Arduino with Serial communication ?

the google api uses https, so SSL encryption. I don't know about an AVR + esp8266 solution for that with firmware in esp8266. you must write your own sketch for the esp8266 to do the location with google api

@Juraj I think you guide me on right path, I still trying multiple ways, and let you know......Thanks


text:
Arduino and using a SSL secured mqtt broker
I'm looking for a library helping me to connect from an Arduino to a MQTT Broker. Of course I want to secure the connection via TLS/SSL.
The "physical" connection is established via a SIM800 module.
The Arduino itself should be as power efficient as possible (it's battery/solar powered).
In case the Arduino is too weak to perform such a task (SSL) is there any other suitable device? maybe a PyBoard?
Anyone can point me to the right direction?

I think an ESP8266 or an ARM based board running mbed-os would be the minimum requirement for such a product. Have you worked on one of these platforms already?

I used a esp8266 before, but i don't have wlan available at the location where this thing will be placed. thats why I need to use a sim800 module

You can switch off the WiFi radio of the ESP8266 and just use it as a cheap but fast 80MHz processor. But if you need real low power you should look in the STM32L1/4 series, e.g. a Nucleo L476RG board? That can drive the radio and a full TLS session with no problems.


text:
Eclipse "CDT Core Builder" error
I installed an Eclipse Version: 2018-12 (4.10.0) for Arduino.
I’ve got an CDT Core Builder error  when I try to compile.
I’ve searched but cannot fix the problem.

It is strange, because I added AVR Eclipse Plugin and GNU AVR-GCC toolchain.
Also creating new project C/C++ -> Arduino Project. According some sources it works. But mine shows CDT error.

I have no clue what you installed. If you want to make arduino in eclipse easy use my sloeber at sloeber.io


text:
Is my code triggering the N-Channel MOSFET as I have intended to
I have a certain bit of code that I believe after 10 seconds will send a high signal to the second digital pin for 50 seconds. After it will not do anything.
For some reason the nichrome wire is not heating up. I realize there could be a problem with my circuit but just want to make sure for the final time it is not an issue with my code. Thanks.
int nichromePin = 2;

unsigned long burnTime = 10000;
unsigned long dt = 50000;
unsigned long time;

void setup()
{
  pinMode(nichromePin, OUTPUT);
  Serial.begin(9600);
  Serial.println("Balloon Countdown...");
  Serial.print("When Will It Burn: ");
  Serial.println(burnTime);

}

void loop()
{
  time = millis();

  if (time > burnTime && time < burnTime+dt)
  {
  digitalWrite(nichromePin, HIGH);
  Serial.print("Time: ");
  Serial.println(time);
  }
}

Try simplifying.  Make dt = 60000 and then check if time is more than burntime and less than dt.

The code is as follows: After 10 seconds following Arduino power up, burn the nichrome for 60 seconds, after which do nothing. I just tested it on my UNO and it works fine, so it must be your circuit. Post your nichrome question in the EE forums for help on that.
P.S. This code is kinda silly tho there's no trigger event!

And note that there's no code to turn the nichrome wire off again once you're done.


text:
White squares LCD display
for a school project I need to program a display. I've got in almost working.
I made a setup screen in the setup() that just says our groupname and the name of our project for 8 seconds (this works perfectly). After the 8 seconds, I used lcd.clear() and tried to type another line. But after the 8 seconds all it shows are 32 white squares. Anyone has any idea how to fix this?
#include <SoftwareSerial.h> // use the software uart

include <Wire.h>

include <LCD.h>

include <LiquidCrystal_I2C.h>  // F Malpartida's NewLiquidCrystal library

define I2C_ADDR       0x3F // Define I2C Address (use i2c scanner if >necessary)

define BACKLIGHT_PIN  3

define En_pin         2

define Rw_pin         1

define Rs_pin         0

define D4_pin         4

define D5_pin         5

define D6_pin         6

define D7_pin         7

define LED_OFF        0

define LED_ON         1

int x = 5;

/*-----( Declare objects )-----*/

LiquidCrystal_I2C
lcd(I2C_ADDR,En_pin,Rw_pin,Rs_pin,D4_pin,D5_pin,D6_pin,D7_pin);

SoftwareSerial bluetooth(10, 9); // RX, TX

int CurrentCommandASCII = 0; // dit is het commando in ASCII

char CurrentCommand ;// Hier wordt het commando omgezet naar Letters

void setup() {
  bluetooth.begin(9600); // start bluetooth

  Wire.begin();

  delay(200);

  Serial.begin(9600); // start seriele monitor

     pinMode(13, OUTPUT);

   digitalWrite(13, HIGH);

      lcd.begin (16,2);  // initialize the lcd

    // Switch on the backlight

    lcd.setBacklightPin(BACKLIGHT_PIN,POSITIVE);

    lcd.setBacklight(LED_ON);

        // Reset the display

    lcd.clear();

    lcd.home();

    lcd.setCursor(4,0); // Start at character 0 on line 0

    lcd.print("Test");

    delay(1000);

    lcd.setCursor(5,1); // Start at character 0 on line 1

    lcd.print("Test");

    delay(8000);

 lcd.clear();

32 white squares: Is that the entire display, or just part of it? (how many characters can it display in total?) Perhaps the contrast should be adjusted?

Add your sketch.

Jose can u c It is a 16x2 display so indeed the whole screen is filled with white blocks. I btw use a lcd display with backpack. i tried adjusting contrast but it doesn't work

Please add a schematic as to how exactly everything is connected.

your code is incomplete


text:
Combining 2 sensors in one code with 1 push button
I am trying to create a circuit with one tactile pushbutton, and LCD and two sensors: 1) temperature, and 2) pulse sensor. When the circuit is on, the LCD initially shows the reading from the temp sensor, when the button is pressed the LCD shows the reading from the pulse sensor.
The code compiles, the LCD shows both of the temperature function and pulse reading work.
I attached a picture of the schematic of the circuit.
The problem is that when the button is pressed, it takes many pushing of the button for the circuit to go from temperature reading to pulse reading. I thought maybe debouncing the button was unnecessary so I tried to write a code without the code, but it made no difference. My coding skills are still in the beginner side but I am trying my best for my coding to make sense. I just need some guidance and advice on what the problem could be and how I can tackle the problem. My code is attached here:
#include <LiquidCrystal.h>
#define BUTTON 2

const int rs = 12, en = 11, d4 = 7, d5 = 6, d6 = 5, d7 = 4;
LiquidCrystal lcd(12, 11, 7, 6, 5, 4);

//TEMPERATURE
const int tempPin = A0;              // LM35 in A0

int T1=60;

//PULSE
#define USE_ARDUINO_INTERRUPTS true    // Set-up low-level interrupts for most acurate BPM math.
#include <PulseSensorPlayground.h>     // Includes the PulseSensorPlayground Library.

int PulseWire = A1;                 // Pulse Sensor purple wire connected to analog pin A0
int blinkPin = 13;                // pin to blink led at each beat
int Threshold = 550;           // Determine which Signal to "count as a beat" and which to ignore.
// Use the "Gettting Started Project" to fine-tune Threshold Value beyond default setting.
// Otherwise leave the default "550" value.
PulseSensorPlayground pulseSensor;  // Creates an instance of the PulseSensorPlayground object called "pulseSensor"

//=========BUTTON DEBOUNCE============
boolean lastButton = LOW;     // last button state
boolean currentButton = LOW; // current button state
int switchMode = 1;             //cycle between function
//====================================
void setup()
{

  lcd.begin(16, 2);
  // Configure the PulseSensor object, by assigning our variables to it.
  pulseSensor.analogInput(PulseWire);
  //pulseSensor.blinkOnPulse(LED13);       //auto-magically blink Arduino's LED with heartbeat.
  pulseSensor.setThreshold(Threshold);

  // Double-check the "pulseSensor" object was created and "began" seeing a signal.
  if (pulseSensor.begin()) {
    Serial.println("We created a pulseSensor Object !");  //This prints one time at Arduino power-up,  or on Arduino reset.

  }//end if

}//end void setup()

//Debouncing Function
boolean debounce(boolean last) {
  boolean current = digitalRead(BUTTON);
  if (last != current)
  {
    delay(T1);         //wait #ms
    current = digitalRead(BUTTON); //read it again
  }//end if
  return current;     //return the current value
}//end boolean debounce

void setMode(int mode) {

  //TEMP ON
  if (mode == 1)
  {
    Serial.begin(9600);
    int value = analogRead(tempPin); // read the value from the sensor
    lcd.setCursor(0, 1);
    float millivolts = (value / 1024.0) * 5000;
    float celsius = millivolts / 10;
    lcd.clear();
    lcd.setCursor(0, 0);
    lcd.print("Temp = "); lcd.print((celsius * 9) / 5 + 32);  lcd.print((char) 223); //turning the celsius into fahrehait
    lcd.print("F");
    lcd.setCursor(7, 2);
    lcd.print(celsius); lcd.print((char) 223);
    lcd.print("C");
    delay(1600);

    lcd.clear();
    delay(T1);
  }//end if TEMP ON

  //RED ON
  else if (mode == 2) {
    {
      Serial.begin(9600);
      int myBPM = pulseSensor.getBeatsPerMinute();  // Calls function on our pulseSensor object that returns BPM as an "int".
      // "myBPM" hold this BPM value now.

      if (pulseSensor.sawStartOfBeat()) {            // Constantly test to see if "a beat happened".
        Serial.println("♥  A HeartBeat Happened ! "); // If test is "true", print a message "a heartbeat happened".
        Serial.print("BPM: ");                        // Print phrase "BPM: "
        Serial.println(myBPM);                        // Print the value inside of myBPM.

        lcd.setCursor(0, 0);
        lcd.print("HeartBeat Found!");
        lcd.setCursor(4, 1);
        lcd.print("BPM: "); lcd.print(myBPM);

        delay(1600);
        lcd.clear();
        delay(T1);
      }//end if
    }//end setMode void function
  }
}
    void loop()
    {
      currentButton = debounce(lastButton); //read debounced state
      if (lastButton == LOW && currentButton == HIGH) /// if it was pressed
      {
        switchMode++;
      }
      //if cycled through the different options,
      //reset the counter to 0
      if (switchMode == 3) switchMode = 1;
      setMode(switchMode);
    }//end loop

I also considered doing a switch case statement, but so far it hasn't worked either. Please let me know some ideas!
Thank you!!

While we wait for 1 more person to approve the edits made to this question...  @LG_18, You need to research what a state machine is and apply that to de-bouncing your button.

the code that you posted does not compile (@matej made some corrections) ..... i think that the code on your computer also does not compile ...... i also think that you are editing your code, and you think that you are compiling and uploading after the edit, but the compile fails and your arduino does not get updated with a new sketch ..... then you run a test on the arduino and it still behaves as it did before

Your code has various issues, but the main one is that you can’t use delay() when you’re trying to more than one thing at a time. Delay causes your program to freeze, and not do anything else.
(Basically you should forget about the delay() function and never write any Arduino code that uses it. It is a code smell.)
You need to rewrite your code to record the value of millis() and then check back the next time through your loop function to see if enough time has passed. Do a Google search on “Arduino blink without delay” for an explanation of how to do this. Here’s an example article: https://learn.adafruit.com/multi-tasking-the-arduino-part-1/using-millis-for-timing
(Note that some solutions suggest that you increment a counter every time through your loop and see if some magic number of counts has gone past based on how frequently you expect your loop to be called. That is a bad approach. You want to use the millis() function.

Also note that you should not call Serial.begin() more than once in your program. You should put that code in your setup function.

Your loop function needs to call debounce() and setMode() as often as possible, and none of your functions must use delay(). Instead, they compute the time elapsed since the last action, and if it is greater than what you now use as a delay value, perform its next action; otherwise, it should just return.
Just as a curiosity, your present code will probably function (better...) if you press and hold the button until you get a response, instead of press-and-releasing multiple times, hoping to get one. The latter way depends on your pressing the button just as the system is reading it, but the system reads it too infrequently for that to be workable, as you found out. The delay() calls are the reason.


text:
Use 2 DHT22 AND PASS THE DATA TO SD?
I have the code to pass the data from dht22 to sd but for only one and i want to pass the data from 1 dht22 with one file and the data from other sensor to other file and logging in to sd. Anyone can help me?
#include
#include
#include "DHT.h"
#define DHTPIN 8
#define DHTTYPE DHT22
DHT dht(DHTPIN, DHTTYPE);
File data_file;

int CS_pin = 10;
long sec=00;
long mint=00;
long hr=00;

void setup() {
Serial.begin(9600);
pinMode(CS_pin, OUTPUT);
dht.begin(); //This command will start to receive the values from dht22
// SD Card Initialization
if (SD.begin())
{
Serial.println("SD card is initialized and it is ready to use");
} else
{
Serial.println("SD card is not initialized");
return;
}
}

void loop() {
data_file = SD.open("data.txt", FILE_WRITE);
if (data_file) {
getData();
}
// if the file didn't open, print an error:
else {
Serial.println("error opening data.txt");
}
delay(1000);
}

void getData(){
for(long sec = 00; sec < 60; sec=sec+2){
float temp = dht.readTemperature(); //Reading the temperature as Celsius and storing in temp
data_file.print(hr);
data_file.print(":");
data_file.print(mint);
data_file.print(":");
data_file.print(sec);
data_file.print(", ");
data_file.println(temp);
Serial.print(hr);
Serial.print(":");
Serial.print(mint);
Serial.print(":");
Serial.print(sec);
Serial.print(", ");
Serial.println(temp);
if(sec>=58){
mint= mint + 1;
}
if (mint>59){
hr = hr + 1;
mint = 0;
}
data_file.flush(); //saving the file
delay(2000);
}
data_file.close(); //closing the file
}

Thanks

It isn’t clear what you’re asking. You want to collect data from 2 sensors? What 2 files are you referring to? You have 2 source files? How are they structured? Why do you need 2 source files? Why not write a function that collects data from 2 sensors?

To me it was pretty clear, what the question was. And OP also acknowledged that in his comment below my answer...

@oh.dae.su you're a better man (or woman) than I. I took it to mean 2 different sketch files but outputting the data to 2 different files on the SD card makes a lot more sense.

@Duncan C my comment was not intended as a direct answer to you, but in general in response to the question being put on-hold as unclear... ;-)

First you need to setup the second DHT sensor and a second file. Please replace the X by the number of the pin your second sensor is connected to after #define DHTPIN2
#define DHTPIN 8
#define DHTPIN2 X
#define DHTTYPE DHT22
DHT dht(DHTPIN, DHTTYPE);
DHT dht2(DHTPIN2, DHTTYPE);
File data_file, data_file2;

In setup() you need to also start the second dht sensor:
dht.begin(); //This command will start to receive the values from dht22
dht2.begin(); //This command will start to receive the values from dht22

In loop() you have to open the second data file in addition to the first one:
data_file = SD.open("data.txt", FILE_WRITE);
if (data_file) {
getData();
}
// if the file didn't open, print an error:
else {
Serial.println("error opening data.txt");
}
data_file2 = SD.open("data2.txt", FILE_WRITE);
if (data_file2) {
getData2();
}
// if the file didn't open, print an error:
else {
Serial.println("error opening data2.txt");
}

Although not the most efficient/elegant solution, this requires you to duplicate your void getData() function as void getData2() to work for the second sensor/file, by replacing dht by dht2 and data_file with data_file2.
This would do the logging on the two sensors in sequence.
If you want the logging in parallel you need to add the measurement and writing of the second sensor/file into the void getData() function.

Thanks for your help. Now finally i can do it ;)

You are welcome. Glad I could help. Btw. please read the stack exchange tour page https://arduino.stackexchange.com/tour to learn, how things work out on this site, e.g. how to deal with answers to your questions.

I don't know why but the program now say File does not name a type.

@jawad bouhali please either ask a separate question including the code and the exact error message or edit your question and append this information to it.


text:
How to print not enough credits if the credits is not sufficient
The problem of my code is in the serial monitor it print the not enough credits even i did not pressed the button. The output that i want is it must be print not enough credits when i pressed the button.
#include <Servo.h>
const int coinpin = 2;
const int buttonPin = 7;

// Variables
volatile int credits = 0;
int buttonState = 0;
const int servoPin = 8;
 Servo servo;

// Setup
void setup() {
  servo.attach (servoPin);
  Serial.begin(9600);
  attachInterrupt(digitalPinToInterrupt(coinpin), coinInterrupt, RISING);
  pinMode(buttonPin, INPUT);
  servo.write(0);

}

// Main loop
void loop() {

Serial.println(credits);
delay(2000);
buttonState = digitalRead(buttonPin);
if (buttonState == HIGH && credits == 5) {

  Serial.println(credits);
  servo.write(180);
  delay(1000);
  servo.write(0);
}

if(credits !=5) {
  Serial.println("NOT ENOUGH CREDITS");
  delay(2000);
}

}

// Interrupt
void coinInterrupt(){

  // Each time a pulse is sent from the coin acceptor, interrupt main loop to add 1 cent and flip on the LED
  credits = credits + 1;
}

i understand that you want to print a message if a button is pressed and print a different message when the button is not pressed ...... it is unclear if you are able to detect the button press ..... have you tested the button with simple code that lights an LED when the button is pressed?

Look at lines of code I marked:

Each loop you check for credits being equal to 5, and if it's not equal to 5 you write "NOT ENOUGH CREDITS" You might want to modify your "if" structure to only check for credits when the button is pressed.
Immediately I see two bugs:

What happens when number of credits is 6? Is it enough or not?
What happens when user presses the button for 2 or more "loop"s?

The physical button press looks to the hardware as several consecutive button presses because the button "bouncess" under your finger. Fixing that issue is called "debouncing" and there are several ways to do that. Read more about that.

Tnx for the reply i already fixed it the problem that am facing now is, How to disable the button if the stock of products is Zero.

The second if statement is standalone and not inside the button press check if statement so will always print 'not enough credit' whenever credit is not exactly 5.
You might also want to look at debouncing the button as you're liable to get multiple triggers on one press.


text:
Problem with counting inside INT0 ISR while in PowerDown
The issue that I have is in INT0 service in which it doesn't perform properly when MCU is set in PowerDown mode. I declared a global variable as "counter" and put it inside INT0 ISR but its value doesn't change.
To make sure that the issue is coming from the Sleeping of the MCU, I commented-out "sleepNow();" inside Loop(), at line 156, and un-commented the following 3 lines and everything was working as expected and variable "counter" was changing correctly. I think I haven't constructed the sleeping part properly, which has caused this issue. I tried to play with the code and searched Google, but I couldn't find that much help. I also looked at the following topics, but those didn't help me either:
Waking up async the Arduino while it's sleeping periodically
Send out a short signal every 10 seconds to an arduino
Use lowpower-libary and still use serial connection and other things
How do interrupts work on the Arduino Uno and similar boards?
My simplified code is here:
#include <SoftwareSerial.h>
#include <avr/sleep.h>
#include <avr/wdt.h>
#include <avr/power.h>

#define Voltage A7                 // Analog Pin A7 | ADC7 - QFN pin 22
#define En_V A0                  // Analog Pin A0 - PC0 -QFN pin 23 | Trigger pin to turn on MOSFETs
#define En_Sensors 9             // Digital Pin D9 - PB1 -QFN pin 13 | Trigger pin to turn on sensor
#define En_I2C2 3
#define En_Sigfox A1       // GPIO9 On Sigfox - It is Set to PULL UP by default in Sigfox module. Set to LOW for waking up

#define SF_rxPin 5     //Sigfox
#define SF_txPin 6     //Sigfox

boolean debug =  true;
SoftwareSerial Sigfox (SF_rxPin, SF_txPin);

///////////////////////Interrupt changes////
const int interruptPin = 2; // INT0 - PD2 | INT1 - PD3
const uint8_t LED = A2;
volatile uint8_t counter = 0;
volatile bool IntFlag = false;
volatile bool WdtFlag = false;
////////////////////////////////////////////
uint8_t MCU_Sleep_Cycle = 4;

void wakeUp()
{
    sleep_disable();
    detachInterrupt(0);// INT0 - PD2 | INT1 - PD3
    counter++;
    IntFlag = true;
}

ISR (WDT_vect)
{
  // WDIE & WDIF is cleared in hardware upon entering this ISR
  wdt_disable();
  WdtFlag = true;
}

void Sleep_Sigfox() {
  digitalWrite(En_Sigfox, HIGH);     // to go into DeepSleep mode
  setPowerMode(2);
}

void setup() {
  pinMode(Voltage, INPUT);
  pinMode(En_V, OUTPUT);
  pinMode(En_Sensors, OUTPUT);
  pinMode(En_I2C2, OUTPUT);
  pinMode(SF_rxPin, INPUT);
  pinMode(SF_txPin, OUTPUT);
  pinMode(En_Sigfox, OUTPUT);

  pinMode(interruptPin, INPUT_PULLUP);

  if (debug) {
    Serial.begin(9600);
  }
  Sigfox.begin(9600);
  delay(3 * 500);
  analogReference(EXTERNAL);
  digitalWrite(En_I2C2, LOW);
  if (debug) {
    Serial.println(F("Hello"));
  }

  digitalWrite(En_Sensors, LOW);
  Sleep_Sigfox();
  delay(2 * 1000);

  attachInterrupt(0, wakeUp, LOW);
}

uint8_t volt() {
  uint16_t tmp = 0;
  float v1, tmp2, tmp3;
  uint8_t v;
  delay(2 * 100);
  tmp = analogRead(Voltage); //A7
  if (tmp > 0) {
    v1 = tmp * 3.3 / 1023;
    tmp2 = v1 * 840 / 33; //10*(51+33)/33;  to represent in 10*V, (51+33)/33 is a HW Voltage divider.
    tmp3 = round(tmp2);
    v = tmp3;
  }
  else {
    v = 0;
  }
  return (v);
}

void loop() {
  //delay(2 * 500);

  if (WdtFlag) {
    wdt_reset();

    if (debug) {
      Serial.println(F("\nI woke up"));
      //Serial.print("IntFlag: ");
      //Serial.println(IntFlag);
      Serial.print(F("WdtFlag: "));
      Serial.println(WdtFlag);
      Serial.print(F("counter: "));
      Serial.println(counter);
      delay(500);
    }

    uint8_t rs = 0;
    uint8_t v = 0;
    char to_be_sent[12];
    memset(to_be_sent, 0, sizeof(to_be_sent));
    digitalWrite(En_V, HIGH);

    delay(300);

    v = volt();
    rs = counter;
    sprintf(to_be_sent,  "%2X%02X", v, rs);
    digitalWrite(En_V, LOW);

    if (debug) {
      Serial.print(F("Volt*10: "));
      Serial.println(v);
      Serial.print(F("RS-count: "));
      Serial.print(rs);
      Serial.println(F("\n"));
      delay(1000);
    }

    ///////////////////////////////// Send Values here
    delay(1 * 50);
    if (debug) {
      Serial.print(F("Sending Message: "));
      Serial.println(to_be_sent);
      delay(20);
    }
    counter = 0;
  }

  if (debug) {

    Serial.print(F("MCU is going into DeepSleep for "));
    Serial.print(MCU_Sleep_Cycle);
    Serial.println(F(" cycles."));
    delay(40);
  }
  for (uint8_t i = 0; i < MCU_Sleep_Cycle ; i++) { //15 cycles = 2min | 6 cycles = 48sec
    if (debug) {
      Serial.print(F("."));
      delay(10);
    }
    sleepNow();
    //WdtFlag=true;
    //attachInterrupt(0, wakeUp, LOW);
    //delay(2*1000);
  }

}

String setPowerMode(uint8_t mode) {
  //0: Software reset
  //1: sleep, send a break to wake up
  //2: deep_sleep, toggle GPIO0 or Reset_N to wake up

  if (debug) {
    Serial.print("Sigfox Power mode: " + String(mode) + "\t");
    //Serial.print(res);
    switch (mode) {
      case 0: Serial.println(F("Soft reset is done.\n")); break;
      case 1: Serial.println(F("Module is in sleep mode. zZzZ\n")); break;
      case 2: Serial.println(F("Module is in DeepSleep mode. zZzZ\n")); break;
    }
    delay(500);
  }

  Sigfox.print("AT$P=");
  Sigfox.print(mode);
  Sigfox.print("\r");
  //String res = getData();
  //return res;
}

void sleepNow() {
  //cli();   //disable interrupts
  EIFR |= (1 << INTF0); // Clearing INTF0 by setting this bit up. Int0 flag cleared.
  EIMSK |= (1 << INT0); //enable INT0

  byte adcsra_save = ADCSRA; //ADC backup
  byte WDTCSR_save = WDTCSR; //WDT backup

  WdtFlag = false;
  IntFlag = false;

  sleep_enable();          // enables the sleep bit in the mcucr register. so sleep is possible. just a safety pin
  set_sleep_mode(SLEEP_MODE_PWR_DOWN);   // sleep mode is set here
  ADCSRA &= ~(1 << 7); //clear bit 7 of register ADCSRA and disable ADC
  sleep_bod_disable();
  //power_all_disable ();   // turn off all modules
  sei();//enable interrupts
  attachInterrupt(0, wakeUp, LOW); //when pin 2 gets LOW, run function wakeUp() // INT0 - PD2 | INT1 - PD3
  wdt_enable(WDTO_8S);
  WDTCSR |= (1 << WDIE);
  //sleep_mode();// here the device is actually put to sleep. THE PROGRAM CONTINUES FROM HERE AFTER WAKING UP
  sleep_cpu ();

  sleep_disable();
  //power_all_enable ();   // turn on all modules
  sei();
  ADCSRA |= (1 << 7); //Set bit 7 and Enable ADC
  ADCSRA = adcsra_save;  // Config ADC again as before
}

What MCU is used?
The MCU is an ATMEGA328P running on 3.3V at 8MHz
What I want to do?
I would like to put the MCU into deep sleep mode for a fixed period (e.g. 15 minutes, though in the code above I have reduced time to less than a minute), but monitor the number of times the external interrupt is happening. At the end of 15 minutes, when the MCU wakes up, I would like to get the interrupt count total from variable "counter", which should have been incremented by the INT0 ISR, once per external interrupt.
What is the issue?
The issue is that the variable "counter" is not increasing when the MCU is in sleep mode. When the MCU sleeps, the power consumption goes down. The WDT is also working. The interrupt INT0 wakes up the MCU, but value of the counter is not incrementing. I suspect that after the INT0 ISR executes, an MCU reset is happening, reinitializing the "counter" variable -- so that might be the reason why counter keeps staying at zero.
What did I do?
I tried to run the code while the MCU is not sleeping and in that case, variable "counter" works well. So, I suspect my sleeping instructions may not be correct. To do this, I commented line 156, sleepNow();, and un-commented lines 157-159 at the end of main void Loop(){}. Please see attached picture.
What do I expect?
I expect that, while MCU is in sleep mode, it can count the number of external interrupts.
What IDE, compiler and platform am I using?
Arduino IDE adjusted for board Arduino pro mini 3.3V - Windows 8 64bit
But the board that I have is not a genuine Arduino board. I just use the Arduino IDE adjusted for Arduino pro mini since it has the same settings and compilation is easier for me.
Thanks

i do not have time to examine your code in detail, but i see counter = 0; inside the loop() block

@jsotola that part is after reading and printing its value. Moreover, before reaching that line, its value will be copied to variable "rs".

perhaps the compiler has somehow optimized it out of existence ... what happens if you assign a value other than 0 at the variable declaration

@ jsotola, I already tried that one with not giving it an initial value in declaration and still it was zero in readings. After triggering external interrupt, MCU resets and everything starts from "Setup()" and it might be the reason that "counter" is zero. Triggering Ex.Int is not supposed to reset MCU. When I tried without putting MCU in PowerDown mode, everything is fine and external interrupt works as expected. The issue occurs when it is in PowerDown mode.

you may have to use an external counter


text:
Multiple I2C slave devices on Arduino - Pull-up values
This question is asked a lot and I've found many usable details on different forums regarding adding pull-up resistors on SDA/SCL lines. I know that only one resistor should be added on these lines regardless of how many devices are attached.
One thing that is not clear for me is that what if I2C devices are powered on from different sources, at different timing?
In following schematic, I have used pull up resistors for both I2C devices. Considering devices might be turned on and off at different timing, or even one device might be absent, is it fine to remove the second pull up resistors (second I2C device) and connect them directly to SDA/SCL pins on uC? In this case (removing pull-up resistors from second device), what happens if device 1 is not available and only second device is connected?
---edit:

Schematic was updated to include only one pair of pull up resistors connected to master side.
I will not how swap or hot plug I2C devices.
I2C devices are sensors (BME280 here, and Chirp capacitive soil moisture, here), not on breakout boards with preset pull up resistors.
Is it possible to just connect resistors on master side and not slave side? In this case, would it be fine for both sensors?

simulate this circuit – Schematic created using CircuitLab

A pullup resistor is between sda (or scl) to vcc. The pullup resistor pulls the signal high. You have resistors in the signal, they should not be there. It is not possible to turn off a i2c device and keep the i2c bus working.

@ Jot, Oops. It was my mistake in wiring. I corrected it. Thanks for mentioning.

It is possible to hot-swap I2C devices with a special circuit (for instance TCA4311A, http://www.ti.com/product/TCA4311A#).

What if both devices are connected and powered on all the time, from different power sources. Do I need resistors on both devices?

You can use a single pair of pullup resistors or many everywhere in your circuit, as long as the combined pullup value is within the specifications for the i2c bus.

Please tell us why you want to control both voltage regulators with the enable pin. Have you read the bme280 datasheet for the minimal power usage? Are you trying to save 100nA? (that is 100 nano amps). When you turn off a i2c device, the i2c bus is no longer working, because most sensors have internal protection diodes to vcc.

@ Jot, you're right. Regarding BME280, I will put it on the same power rail as MCU. But asking in this way was more about my curiosity to know how the two  could be controlled separately.

You should consider adding some bus isolation between each slave and the master. The reason being is that the ESD diodes in the SCL/SDA pins of a slave that is powered down could be interfering with the I2C bus as they leech power from the bus to feed through the internals of the slave.  Given the low current imposed by the pullup resistors being the only power source this shouldn't cause any damage to the slave, but it may well cause the I2C bus to be seen as LOW when it shouldn't, causing communication to fail.
You should add a buffer with an "enable" pin of its own between each slave and the bus.  My device of choice is the PCA9306 from Texas Instruments.  It also means that the slave has its own separate pullup resistors powered by its own 3.3V rail, keeping all the power separate.
You would then have sequences such as:

Power up slave
Give short powerup delay (if needed)
Enable PCA9306
Do I2C transactions
Disable PCA9306
Power off slave

The PCA9306 can also be used to connect 3.3V slaves to a 5V MCU if needed.

simulate this circuit – Schematic created using CircuitLab

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

I would include one resistor on each line at the master, powered by the master. That isn't the only option, just what I consider a cleaner simpler option.
The resistance is needed to provide the high seen on the line. The value of the resistance can vary. There is no one correct value. The pull up resistance needs to provide a high in the required time. There are specifications for this.
https://www.i2c-bus.org/specification/
If the lines do not have a lot of capacitance (wire and device capacitance) then a higher value resistance may be sufficient to meet the timing specification. If there is more capacitance then a lower resistance would be required to provide the stronger pull up in order to meet the timing requirements.
As far as multiple resistances. Yes there can be more than one on the line. But the accumulated resistance must be taken into account.
Many I2C devices mounted on a breakout board have pull up resistors. Typically these are around 5K Ohms. So if there are two devices, each with their own resistors, the combined total will still be within the lowest resistance that would be acceptable.
One thing to note. The specification does not list a lowest resistance that can be used. Instead it specifies the minimum sinking requirement of a device that would need to pull the voltage low enough. So a current is specified, and this current can be used to calculate the minimum resistance on the line.
The current spec (somewhere about 3ma I think, or maybe 2ma??) would calculate to being a 1k6 resistance when used with a 5 volt supply. With a 3.3 volt supply the calculated value would be about 1k1 Ohms. (again, this is a rough calculation, close enough for handgrenades)
This is enough of an answer considering what was asked. There are different modes/speeds and different combinations that can be applied and things can get very involved. And then you must spend the time and look at the specifications. But for most Arduino work this rough guide should cover most "normal" situations.
It really is quite an interesting technology.

For the normal i2c bus (100kHz to 400kHz) every device should at least be able to sink 3mA, but is allowed to sink more. Some manufacturers make devices that barely can do 3mA, so the pullup resistor should keep the current to pull the signal low to 3mA or less.

Thanks. Based on your suggestion, I connected a pair of pull up resistors to main power supply (U3), instead of connecting them to U1 and U2. Is it correct?
One of my confusions was that which side to connect resistors? master or slave? and if slave, then what happens if one of devices are absent.

Yes, connect to the main supply. Whatever supply is going to be there. I consider this to be the supply that the master is on. For 5 volt power I will use 2k2 for the pull ups. For 3.3 volts I use 1K-1K5. I have done many products this way, thousands of products shipped without problem. One product has 14 modules talking over I2C.

I wanted to add this as a comment but I ran out of characters, so this isn't an answer, just more comment.
@Majenko "I would never suggest using I2C over anything other than short PCB traces. i2C + wires = no thank you sir."

And that made me write the following.
We had one product that needed an external radio module. I put a connector in to extend the I2C bus. Total length of the additional cable was about 4 feet. Enough to route it outside the box and mount the radio close by.
Much later I am asked to look at why the communications is failing. The engineering manager had the cable extended to 20 feet. It worked for him on the bench when he tested it. No scope check on waveforms. No calculations. (he was a firmware programmer with just enough hardware knowledge to do his job)
I looked at the waveforms with a scope and I was shocked that it worked at all. The I2C lines were cpu to cpu. The radio had a microcontroller that acted as a slave I2C device.
I put a couple of buffers on either end and all was back in spec and it worked reliably after that, in the field and not just on the bench.
We have a bigger control box that uses I2C to communicate to modules in the back of the box. I have a buffer at the CPU end. The cpu is 3.3v, the modules are 5 volts. The buffer does a level conversion and stronger drive than the cpu could handle. The back of the boxes are shown below. Space for 14 modules. The bigger box is about 2 feet wide and 3 feet tall. The I2C lines run vertically down the center of each of the columns on the back of the board.

There also can be a secondary slave box for an additional 14 modules. The same back board. I used a second I2C port with and isolated I2C buffer for driving the lines. The slave boax was to be mounted beside the main box. Again I specified a short cable, this time six feet in length.
So one day I am asked if the cable can be extended. The contractor installing the panels wanted to put the slave boax on the other side of the hall by another electrical panel. I ask how long do they need. I'm told it is ten feet away. Yeah, ten feet line of sight. Once the cable was touted up into the ceiling, across the hall, and then down to the other box, the 10 feet turned into 30 feet.
I did a check with a scope. The rise times were still in spec, it seemed to work, so we made up a cable and told them that it may or may not work. Use at their own risk. I told them this was an exception and it is not to be a part of the product offering. But I'm sure there will be more exceptions.
And while it can work over those kind of distances the following shows how I2C can fail over short distances.
Same equipment. The smaller box in the picture was expanded with an additional larger box. The smaller box was mounted eight inches above the bigger box. (display and main cpu in the front panel of the product) Only temperature input into the modules in the smaller box. The bigger box was loaded with modules with control relays. Four 17 amp relays per module.  Same electronics as in the exception described above. But they were having lots of sporadic behaviour. Pictures of the wiring, the installation, looked clean and well done. I had no idea why it was failing.
After this had been going on for a couple of months I asked our customer service person to ask what they have connected to our relays. Normally it would be motor up to 1 hp. They were controlling bigger motors and they had our relays turning on power contactors in a different panel. Lots of power contactors. All generating voltage spikes when they were turned off. I had them put snubbers across the contactor coils and the problems went away.
So I2C can work over longer distances, and it can fail over shorter distances. The whole picture needs to be taken into account. The problem is the whole picture often is hard to see.


text:
How can I connect my ESP32-WROOM-32 to Arduino IDE?
I'm using this 'ESP32-WROOM-32' but I can't find the correct board in the IDE. I see the esp32-wroom-DA (edit, i took it to the store where i bought it and it worked fine with theirs. they were on windows and im on mac. also they told me to use 'DOIT esp32 devkit' but im getting the same errors) but when I use that with this board it gives errors while compiling.

Arduino: 1.8.18 (Mac OS X), Board: "ESP32-WROOM-DA Module, Default 4MB with spiffs (1.2MB APP/1.5MB SPIFFS), 240MHz (WiFi/BT), QIO, 80MHz, 4MB (32Mb), 921600, Core 1, Core 1, None, Disabled"
[2074] Error loading Python lib '/var/folders/sz/zm5vw9m92t9_07j6scr85q400000gn/T/_MEIDMFx0d/libpython3.8.dylib': dlopen: dlopen(/var/folders/sz/zm5vw9m92t9_07j6scr85q400000gn/T/_MEIDMFx0d/libpython3.8.dylib, 10): Library not loaded: @loader_path/libintl.8.dylib
Referenced from: /var/folders/sz/zm5vw9m92t9_07j6scr85q400000gn/T/_MEIDMFx0d/libpython3.8.dylib
Reason: no suitable image found. Did find:    >/var/folders/sz/zm5vw9m92t9_07j6scr85q400000gn/T/_MEIDMFx0d/libintl.8.dylib: cannot load 'libintl.8.dylib' (load command 0x80000034 is unknown)
/private/var/folders/sz/zm5vw9m92t9_07j6scr85q400000gn/T/_MEIDMFx0d/libintl.8.dylib: cannot load 'libintl.8.dylib' (load command 0x80000034 is unknown)
exit status 255
/private/var/folders/sz/zm5vw9m92t9_07j6scr85q400000gn/T/AppTranslocation/F61C5E6A-0B57-4967-97C2-77C38540CF2B/d/Arduino.app/Contents/Java/arduino-builder returned 255
Error compiling for board ESP32-WROOM-DA Module.
This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.

And when I enabled show verbose output:

Arduino: 1.8.18 (Mac OS X), Board: "ESP32-WROOM-DA Module, Default 4MB with spiffs (1.2MB APP/1.5MB SPIFFS), 240MHz (WiFi/BT), QIO, 80MHz, 4MB (32Mb), 921600, Core 1, Core 1, None, Disabled"
/private/var/folders/sz/zm5vw9m92t9_07j6scr85q400000gn/T/AppTranslocation/F61C5E6A-0B57-4967-97C2-77C38540CF2B/d/Arduino.app/Contents/Java/arduino-builder -dump-prefs -logger=machine -hardware /private/var/folders/sz/zm5vw9m92t9_07j6scr85q400000gn/T/AppTranslocation/F61C5E6A-0B57-4967-97C2-77C38540CF2B/d/Arduino.app/Contents/Java/hardware -hardware /Users/drayeshahakim/Library/Arduino15/packages -tools /private/var/folders/sz/zm5vw9m92t9_07j6scr85q400000gn/T/AppTranslocation/F61C5E6A-0B57-4967-97C2-77C38540CF2B/d/Arduino.app/Contents/Java/tools-builder -tools /private/var/folders/sz/zm5vw9m92t9_07j6scr85q400000gn/T/AppTranslocation/F61C5E6A-0B57-4967-97C2-77C38540CF2B/d/Arduino.app/Contents/Java/hardware/tools/avr -tools /Users/drayeshahakim/Library/Arduino15/packages -built-in-libraries /private/var/folders/sz/zm5vw9m92t9_07j6scr85q400000gn/T/AppTranslocation/F61C5E6A-0B57-4967-97C2-77C38540CF2B/d/Arduino.app/Contents/Java/libraries -libraries /Users/drayeshahakim/Documents/Arduino/libraries -fqbn=esp32:esp32:esp32da:PartitionScheme=default,CPUFreq=240,FlashMode=qio,FlashFreq=80,FlashSize=4M,UploadSpeed=921600,LoopCore=1,EventsCore=1,DebugLevel=none,EraseFlash=none -vid-pid=0000_0000 -ide-version=10818 -build-path /var/folders/sz/zm5vw9m92t9_07j6scr85q400000gn/T/arduino_build_386453 -warnings=none -build-cache /var/folders/sz/zm5vw9m92t9_07j6scr85q400000gn/T/arduino_cache_107457 -prefs=build.warn_data_percentage=75 -prefs=runtime.tools.esptool_py.path=/Users/drayeshahakim/Library/Arduino15/packages/esp32/tools/esptool_py/4.5.1 -prefs=runtime.tools.esptool_py-4.5.1.path=/Users/drayeshahakim/Library/Arduino15/packages/esp32/tools/esptool_py/4.5.1 -prefs=runtime.tools.xtensa-esp32s2-elf-gcc.path=/Users/drayeshahakim/Library/Arduino15/packages/esp32/tools/xtensa-esp32s2-elf-gcc/esp-2021r2-patch5-8.4.0 -prefs=runtime.tools.xtensa-esp32s2-elf-gcc-esp-2021r2-patch5-8.4.0.path=/Users/drayeshahakim/Library/Arduino15/packages/esp32/tools/xtensa-esp32s2-elf-gcc/esp-2021r2-patch5-8.4.0 -prefs=runtime.tools.mklittlefs.path=/Users/drayeshahakim/Library/Arduino15/packages/esp32/tools/mklittlefs/3.0.0-gnu12-dc7f933 -prefs=runtime.tools.mklittlefs-3.0.0-gnu12-dc7f933.path=/Users/drayeshahakim/Library/Arduino15/packages/esp32/tools/mklittlefs/3.0.0-gnu12-dc7f933 -prefs=runtime.tools.xtensa-esp32s3-elf-gcc.path=/Users/drayeshahakim/Library/Arduino15/packages/esp32/tools/xtensa-esp32s3-elf-gcc/esp-2021r2-patch5-8.4.0 -prefs=runtime.tools.xtensa-esp32s3-elf-gcc-esp-2021r2-patch5-8.4.0.path=/Users/drayeshahakim/Library/Arduino15/packages/esp32/tools/xtensa-esp32s3-elf-gcc/esp-2021r2-patch5-8.4.0 -prefs=runtime.tools.xtensa-esp32-elf-gcc.path=/Users/drayeshahakim/Library/Arduino15/packages/esp32/tools/xtensa-esp32-elf-gcc/esp-2021r2-patch5-8.4.0 -prefs=runtime.tools.xtensa-esp32-elf-gcc-esp-2021r2-patch5-8.4.0.path=/Users/drayeshahakim/Library/Arduino15/packages/esp32/tools/xtensa-esp32-elf-gcc/esp-2021r2-patch5-8.4.0 -prefs=runtime.tools.riscv32-esp-elf-gcc.path=/Users/drayeshahakim/Library/Arduino15/packages/esp32/tools/riscv32-esp-elf-gcc/esp-2021r2-patch5-8.4.0 -prefs=runtime.tools.riscv32-esp-elf-gcc-esp-2021r2-patch5-8.4.0.path=/Users/drayeshahakim/Library/Arduino15/packages/esp32/tools/riscv32-esp-elf-gcc/esp-2021r2-patch5-8.4.0 -prefs=runtime.tools.dfu-util.path=/Users/drayeshahakim/Library/Arduino15/packages/arduino/tools/dfu-util/0.11.0-arduino5 -prefs=runtime.tools.dfu-util-0.11.0-arduino5.path=/Users/drayeshahakim/Library/Arduino15/packages/arduino/tools/dfu-util/0.11.0-arduino5 -prefs=runtime.tools.riscv32-esp-elf-gdb.path=/Users/drayeshahakim/Library/Arduino15/packages/esp32/tools/riscv32-esp-elf-gdb/11.2_20220823 -prefs=runtime.tools.riscv32-esp-elf-gdb-11.2_20220823.path=/Users/drayeshahakim/Library/Arduino15/packages/esp32/tools/riscv32-esp-elf-gdb/11.2_20220823 -prefs=runtime.tools.openocd-esp32.path=/Users/drayeshahakim/Library/Arduino15/packages/esp32/tools/openocd-esp32/v0.11.0-esp32-20221026 -prefs=runtime.tools.openocd-esp32-v0.11.0-esp32-20221026.path=/Users/drayeshahakim/Library/Arduino15/packages/esp32/tools/openocd-esp32/v0.11.0-esp32-20221026 -prefs=runtime.tools.xtensa-esp-elf-gdb.path=/Users/drayeshahakim/Library/Arduino15/packages/esp32/tools/xtensa-esp-elf-gdb/11.2_20220823 -prefs=runtime.tools.xtensa-esp-elf-gdb-11.2_20220823.path=/Users/drayeshahakim/Library/Arduino15/packages/esp32/tools/xtensa-esp-elf-gdb/11.2_20220823 -prefs=runtime.tools.mkspiffs.path=/Users/drayeshahakim/Library/Arduino15/packages/esp32/tools/mkspiffs/0.2.3 -prefs=runtime.tools.mkspiffs-0.2.3.path=/Users/drayeshahakim/Library/Arduino15/packages/esp32/tools/mkspiffs/0.2.3 -verbose /private/var/folders/sz/zm5vw9m92t9_07j6scr85q400000gn/T/AppTranslocation/F61C5E6A-0B57-4967-97C2-77C38540CF2B/d/Arduino.app/Contents/Java/examples/01.Basics/Blink/Blink.ino
/private/var/folders/sz/zm5vw9m92t9_07j6scr85q400000gn/T/AppTranslocation/F61C5E6A-0B57-4967-97C2-77C38540CF2B/d/Arduino.app/Contents/Java/arduino-builder -compile -logger=machine -hardware /private/var/folders/sz/zm5vw9m92t9_07j6scr85q400000gn/T/AppTranslocation/F61C5E6A-0B57-4967-97C2-77C38540CF2B/d/Arduino.app/Contents/Java/hardware -hardware /Users/drayeshahakim/Library/Arduino15/packages -tools /private/var/folders/sz/zm5vw9m92t9_07j6scr85q400000gn/T/AppTranslocation/F61C5E6A-0B57-4967-97C2-77C38540CF2B/d/Arduino.app/Contents/Java/tools-builder -tools /private/var/folders/sz/zm5vw9m92t9_07j6scr85q400000gn/T/AppTranslocation/F61C5E6A-0B57-4967-97C2-77C38540CF2B/d/Arduino.app/Contents/Java/hardware/tools/avr -tools /Users/drayeshahakim/Library/Arduino15/packages -built-in-libraries /private/var/folders/sz/zm5vw9m92t9_07j6scr85q400000gn/T/AppTranslocation/F61C5E6A-0B57-4967-97C2-77C38540CF2B/d/Arduino.app/Contents/Java/libraries -libraries /Users/drayeshahakim/Documents/Arduino/libraries -fqbn=esp32:esp32:esp32da:PartitionScheme=default,CPUFreq=240,FlashMode=qio,FlashFreq=80,FlashSize=4M,UploadSpeed=921600,LoopCore=1,EventsCore=1,DebugLevel=none,EraseFlash=none -vid-pid=0000_0000 -ide-version=10818 -build-path /var/folders/sz/zm5vw9m92t9_07j6scr85q400000gn/T/arduino_build_386453 -warnings=none -build-cache /var/folders/sz/zm5vw9m92t9_07j6scr85q400000gn/T/arduino_cache_107457 -prefs=build.warn_data_percentage=75 -prefs=runtime.tools.esptool_py.path=/Users/drayeshahakim/Library/Arduino15/packages/esp32/tools/esptool_py/4.5.1 -prefs=runtime.tools.esptool_py-4.5.1.path=/Users/drayeshahakim/Library/Arduino15/packages/esp32/tools/esptool_py/4.5.1 -prefs=runtime.tools.xtensa-esp32s2-elf-gcc.path=/Users/drayeshahakim/Library/Arduino15/packages/esp32/tools/xtensa-esp32s2-elf-gcc/esp-2021r2-patch5-8.4.0 -prefs=runtime.tools.xtensa-esp32s2-elf-gcc-esp-2021r2-patch5-8.4.0.path=/Users/drayeshahakim/Library/Arduino15/packages/esp32/tools/xtensa-esp32s2-elf-gcc/esp-2021r2-patch5-8.4.0 -prefs=runtime.tools.mklittlefs.path=/Users/drayeshahakim/Library/Arduino15/packages/esp32/tools/mklittlefs/3.0.0-gnu12-dc7f933 -prefs=runtime.tools.mklittlefs-3.0.0-gnu12-dc7f933.path=/Users/drayeshahakim/Library/Arduino15/packages/esp32/tools/mklittlefs/3.0.0-gnu12-dc7f933 -prefs=runtime.tools.xtensa-esp32s3-elf-gcc.path=/Users/drayeshahakim/Library/Arduino15/packages/esp32/tools/xtensa-esp32s3-elf-gcc/esp-2021r2-patch5-8.4.0 -prefs=runtime.tools.xtensa-esp32s3-elf-gcc-esp-2021r2-patch5-8.4.0.path=/Users/drayeshahakim/Library/Arduino15/packages/esp32/tools/xtensa-esp32s3-elf-gcc/esp-2021r2-patch5-8.4.0 -prefs=runtime.tools.xtensa-esp32-elf-gcc.path=/Users/drayeshahakim/Library/Arduino15/packages/esp32/tools/xtensa-esp32-elf-gcc/esp-2021r2-patch5-8.4.0 -prefs=runtime.tools.xtensa-esp32-elf-gcc-esp-2021r2-patch5-8.4.0.path=/Users/drayeshahakim/Library/Arduino15/packages/esp32/tools/xtensa-esp32-elf-gcc/esp-2021r2-patch5-8.4.0 -prefs=runtime.tools.riscv32-esp-elf-gcc.path=/Users/drayeshahakim/Library/Arduino15/packages/esp32/tools/riscv32-esp-elf-gcc/esp-2021r2-patch5-8.4.0 -prefs=runtime.tools.riscv32-esp-elf-gcc-esp-2021r2-patch5-8.4.0.path=/Users/drayeshahakim/Library/Arduino15/packages/esp32/tools/riscv32-esp-elf-gcc/esp-2021r2-patch5-8.4.0 -prefs=runtime.tools.dfu-util.path=/Users/drayeshahakim/Library/Arduino15/packages/arduino/tools/dfu-util/0.11.0-arduino5 -prefs=runtime.tools.dfu-util-0.11.0-arduino5.path=/Users/drayeshahakim/Library/Arduino15/packages/arduino/tools/dfu-util/0.11.0-arduino5 -prefs=runtime.tools.riscv32-esp-elf-gdb.path=/Users/drayeshahakim/Library/Arduino15/packages/esp32/tools/riscv32-esp-elf-gdb/11.2_20220823 -prefs=runtime.tools.riscv32-esp-elf-gdb-11.2_20220823.path=/Users/drayeshahakim/Library/Arduino15/packages/esp32/tools/riscv32-esp-elf-gdb/11.2_20220823 -prefs=runtime.tools.openocd-esp32.path=/Users/drayeshahakim/Library/Arduino15/packages/esp32/tools/openocd-esp32/v0.11.0-esp32-20221026 -prefs=runtime.tools.openocd-esp32-v0.11.0-esp32-20221026.path=/Users/drayeshahakim/Library/Arduino15/packages/esp32/tools/openocd-esp32/v0.11.0-esp32-20221026 -prefs=runtime.tools.xtensa-esp-elf-gdb.path=/Users/drayeshahakim/Library/Arduino15/packages/esp32/tools/xtensa-esp-elf-gdb/11.2_20220823 -prefs=runtime.tools.xtensa-esp-elf-gdb-11.2_20220823.path=/Users/drayeshahakim/Library/Arduino15/packages/esp32/tools/xtensa-esp-elf-gdb/11.2_20220823 -prefs=runtime.tools.mkspiffs.path=/Users/drayeshahakim/Library/Arduino15/packages/esp32/tools/mkspiffs/0.2.3 -prefs=runtime.tools.mkspiffs-0.2.3.path=/Users/drayeshahakim/Library/Arduino15/packages/esp32/tools/mkspiffs/0.2.3 -verbose /private/var/folders/sz/zm5vw9m92t9_07j6scr85q400000gn/T/AppTranslocation/F61C5E6A-0B57-4967-97C2-77C38540CF2B/d/Arduino.app/Contents/Java/examples/01.Basics/Blink/Blink.ino
Using board 'esp32da' from platform in folder: /Users/drayeshahakim/Library/Arduino15/packages/esp32/hardware/esp32/2.0.11
Using core 'esp32' from platform in folder: /Users/drayeshahakim/Library/Arduino15/packages/esp32/hardware/esp32/2.0.11
bash -c "[ ! -f "/private/var/folders/sz/zm5vw9m92t9_07j6scr85q400000gn/T/AppTranslocation/F61C5E6A-0B57-4967-97C2-77C38540CF2B/d/Arduino.app/Contents/Java/examples/01.Basics/Blink"/partitions.csv ] || cp -f "/private/var/folders/sz/zm5vw9m92t9_07j6scr85q400000gn/T/AppTranslocation/F61C5E6A-0B57-4967-97C2-77C38540CF2B/d/Arduino.app/Contents/Java/examples/01.Basics/Blink"/partitions.csv "/var/folders/sz/zm5vw9m92t9_07j6scr85q400000gn/T/arduino_build_386453"/partitions.csv"
bash -c "[ -f "/var/folders/sz/zm5vw9m92t9_07j6scr85q400000gn/T/arduino_build_386453"/partitions.csv ] || [ ! -f "/Users/drayeshahakim/Library/Arduino15/packages/esp32/hardware/esp32/2.0.11/variants/esp32da"/partitions.csv ] || cp "/Users/drayeshahakim/Library/Arduino15/packages/esp32/hardware/esp32/2.0.11/variants/esp32da"/partitions.csv "/var/folders/sz/zm5vw9m92t9_07j6scr85q400000gn/T/arduino_build_386453"/partitions.csv"
bash -c "[ -f "/var/folders/sz/zm5vw9m92t9_07j6scr85q400000gn/T/arduino_build_386453"/partitions.csv ] || cp "/Users/drayeshahakim/Library/Arduino15/packages/esp32/hardware/esp32/2.0.11"/tools/partitions/default.csv "/var/folders/sz/zm5vw9m92t9_07j6scr85q400000gn/T/arduino_build_386453"/partitions.csv"
bash -c "[ -f "/private/var/folders/sz/zm5vw9m92t9_07j6scr85q400000gn/T/AppTranslocation/F61C5E6A-0B57-4967-97C2-77C38540CF2B/d/Arduino.app/Contents/Java/examples/01.Basics/Blink"/bootloader.bin ] && cp -f "/private/var/folders/sz/zm5vw9m92t9_07j6scr85q400000gn/T/AppTranslocation/F61C5E6A-0B57-4967-97C2-77C38540CF2B/d/Arduino.app/Contents/Java/examples/01.Basics/Blink"/bootloader.bin "/var/folders/sz/zm5vw9m92t9_07j6scr85q400000gn/T/arduino_build_386453"/Blink.ino.bootloader.bin || ( [ -f "/Users/drayeshahakim/Library/Arduino15/packages/esp32/hardware/esp32/2.0.11/variants/esp32da"/bootloader.bin ] && cp "/Users/drayeshahakim/Library/Arduino15/packages/esp32/hardware/esp32/2.0.11/variants/esp32da"/bootloader.bin "/var/folders/sz/zm5vw9m92t9_07j6scr85q400000gn/T/arduino_build_386453"/Blink.ino.bootloader.bin || "/Users/drayeshahakim/Library/Arduino15/packages/esp32/tools/esptool_py/4.5.1"/esptool --chip esp32 elf2image --flash_mode dio --flash_freq 80m --flash_size 4MB -o "/var/folders/sz/zm5vw9m92t9_07j6scr85q400000gn/T/arduino_build_386453"/Blink.ino.bootloader.bin "/Users/drayeshahakim/Library/Arduino15/packages/esp32/hardware/esp32/2.0.11/tools/sdk/esp32"/bin/bootloader_qio_80m.elf )"
[2164] Error loading Python lib '/var/folders/sz/zm5vw9m92t9_07j6scr85q400000gn/T/_MEIXurqHc/libpython3.8.dylib': dlopen: dlopen(/var/folders/sz/zm5vw9m92t9_07j6scr85q400000gn/T/_MEIXurqHc/libpython3.8.dylib, 10): Library not loaded: @loader_path/libintl.8.dylib
Referenced from: /var/folders/sz/zm5vw9m92t9_07j6scr85q400000gn/T/_MEIXurqHc/libpython3.8.dylib
Reason: no suitable image found.  Did find:
/var/folders/sz/zm5vw9m92t9_07j6scr85q400000gn/T/_MEIXurqHc/libintl.8.dylib: cannot load 'libintl.8.dylib' (load command 0x80000034 is unknown)
/private/var/folders/sz/zm5vw9m92t9_07j6scr85q400000gn/T/_MEIXurqHc/libintl.8.dylib: cannot load 'libintl.8.dylib' (load command 0x80000034 is unknown)
exit status 255
/private/var/folders/sz/zm5vw9m92t9_07j6scr85q400000gn/T/AppTranslocation/F61C5E6A-0B57-4967-97C2-77C38540CF2B/d/Arduino.app/Contents/Java/arduino-builder returned 255
Error compiling for board ESP32-WROOM-DA Module.

also im using macos 10.13.6, the store i got it from (and it worked fine for them) was on windows

what errors? ... please copy all of the error message and paste it into your question ... do not paste a picture ... do not paste into a comment

What program are you compiling? The blink sketch or one with some special (possibly unsupported) libraries? When you "verify" (compile and link) a program in the Arduino IDE the real hardware does not even need to be connected so there is no possibility for the system to identify a mismatch between the board you select in the IDE and the real board you have in your hand. Only when you attempt to upload the (compiled) program can some rudimentary checks be performed. If the verify fails with the "blink" sketch, suspect an IDE installation problem otherwise suspect your code.

6v6gt I get the same error for any code i try to run, even the blink sketch.


text:
How do I control a BLDC with greater precision using bluetooth?
I am building a quadcopter drone and I have 4 BLDC motors that I can control using an HM10 Bluetooth module and the "Dabble" application.
My problem is that when I use a virtual joystick in the "gamepad" module of the Dabble application to control the speed of the motors, it seems to be limited to 2 or 3 speeds. The joystick module that I am using is supposed to have values of 0 to 7 depending on the distance of the joystick from its center. Yet the motor only moves once the joystick is halfway away from center, and then it only spins at a couple different speeds when I push the joystick further. Here is my code:
#include <Servo.h> //Servo library
#include <Dabble.h> //Dabble library for bluetooth connection

#define INCLUDE_GAMEPAD_MODULE //Includes Dabble Gamepad module
#define CUSTOM_SETTINGS

Servo ESC1; //define the 4 motors
Servo ESC2;
Servo ESC3;
Servo ESC4;

int Speed; //create a variable for speed of motors

void setup() {
  Dabble.begin(9600); //Set the baud rate for the HM10 to 9600
  ESC1.attach(9); //Set the motors to their corresponding pins on the arduino
  ESC2.attach(10);
  ESC3.attach(11);
  ESC4.attach(12);
}

void loop() {
  Dabble.processInput(); //Refresh information from the Dabble application
  Speed = GamePad.getRadius(); //Get a value from the Dabble application corresponding to the distance  of the joystick from center (0 to 7)
  Speed = map(Speed, 0, 7, 0, 180); //translate the value from the Dabble application (0 to 7) into the "language" of the motors (0 to 180)

  ESC1.write(Speed); //Set the motors to the new speed
  ESC2.write(Speed);
  ESC3.write(Speed);
  ESC4.write(Speed);
}

Can you check what values the Dabble application actually sends? That might show us on which side the problem is.

that sounds like a good idea but I am not too sure how to go about that. The dabble app is on my phone and I cannot have my laptop connected to the arduino while this is running as apparently it will fry the USB port

Update: I'm silly, I can simply unplug the motor and then read the data while connected to my laptop. Turns out the arduino is receiving all values 0 through 7 as intended. The problem must be with the BLDC somehow.


text:
OLED and Wifi not working together on ESP8266 Heltec NodeMCU
I have this ESP8266 Heltec NodeMCU board with OLED. The pins are described here.
I have the following problem. The both OLED (with u8g2) and Wifi work fine individually. There is a problem getting them working together.
In particular, the following code works (and shows Hello World, blanks the screen and then repeats):
#include <U8g2lib.h>
U8G2_SSD1306_128X32_UNIVISION_F_HW_I2C u8g2(U8G2_R0, U8X8_PIN_NONE);

void setup() {
  u8g2.begin();
}

void loop() {
  u8g2.setFont(u8g2_font_ncenB14_tr);
  u8g2.firstPage();
  do {
    u8g2.setCursor(0, 20);
    u8g2.print(F("Hello World!"));
  } while ( u8g2.nextPage() );
  delay(2000);
  u8g2.clear();
  delay(2000);
}

Adding the Wifi to the code (the only difference to the code above are the 2 lines in the setup).
#include <ESP8266WiFi.h>
#include <U8g2lib.h>
U8G2_SSD1306_128X32_UNIVISION_F_HW_I2C u8g2(U8G2_R0, U8X8_PIN_NONE);

void setup() {
  u8g2.begin();

  WiFi.begin ( "xxx", "yyy" );
  while ( WiFi.status() != WL_CONNECTED  ) { delay(500); }
}

void loop() {
  u8g2.setFont(u8g2_font_ncenB14_tr);
  u8g2.firstPage();
  do {
    u8g2.setCursor(0, 20);
    u8g2.print(F("Hello World!"));
  } while ( u8g2.nextPage() );
  delay(2000);
  u8g2.clear();
  delay(2000);
}

In this case, "Hello World" appears 3 times and then the screen remains blank.
Edit:
I noticed something which, I believe, is an important piece of information when I turned the debugging of the WiFi on.
The display stops working after the output pm open,type:2 0 of the debugger. I believe that pm refers to powermanagement. Could it be that the system goes sleeping? How to prevent this from happening?

Does the WiFi actually connect, or are things stuck in the while loop in setup()?

It does connect. I just produced a minimal example.

@ocrdu: Interestingly, "Hello world" appears 3 times (deterministically) and then the screen remains blank.

replace all of the OLED code with a blinking LED ... maybe the problem has nothing to do with the OLED

Without the OLED, the WiFi works. So either OLED or WiFi work individually. Together, only the WiFi works. The OLED stops working after some time.

I managed to solve the issue and figure out what the problem is. I put here an answer for reference, if this question appears again. It turns out that the reset of the OLED is important. It is easy to see, if one uses the Adafruit_SSD1306 library. The code
  #define SCREEN_WIDTH 128
  #define SCREEN_HEIGHT 32
  #define OLED_RESET 0
  Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);

produces exactly the issues described in the text. Changing it into
  #define SCREEN_WIDTH 128
  #define SCREEN_HEIGHT 32
  #define OLED_RESET 16
  Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);

solves the issue. Similarly, replacing U8X8_PIN_NONE with 16 in the code above, runs as expected. It looks like the example provided with the board is incorrect.

For me, this solved a critical problem, of a sketch using U8g2lib.h where the OLED always switched off after about 30s. Using 16 instead of U8X8_PIN_NONE in the constructor: U8G2_SSD1306_128X32_UNIVISION_F_HW_I2C u8g2(U8G2_R0, /* reset=*/ 16); solved this issue.


text:
How can I store the received data from nRF24l01+ module in an array (code in description)?
This is my sample RX code for 4 Tx and 1 Rx nRF24l01+ modules. I want to store all the data received from 4 pipes into an array (recArray).
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>

RF24 radio(7, 8);

const uint64_t pipes[4] = {0xF0F0F0F0E1LL, 0xF0F0F0F0E2LL, 0xF0F0F0F0E3LL, 0xF0F0F0F0E4LL};
char text[32] = {0}; #received data
int recArray[4]={0, 0, 0, 0}; # array to store the received bytes

void setup() {
  Serial.begin(9600);
  radio.begin();
  radio.openReadingPipe(1, pipes[0]);
  radio.openReadingPipe(2, pipes[1]);
  radio.openReadingPipe(3, pipes[2]);
  radio.openReadingPipe(4, pipes[3]);
  radio.startListening();
}

void loop() {
  if (radio.available()) {
    radio.read(&text, sizeof(text));
    Serial.println(text);
  }
}

I would suggest to send 2 bytes to this module
the first byte is the pipe number (0xE1,0xE2,0xE3,0xE4)
and in the second byte Data
void loop()
{
  if (radio.available())
 {
  radio.read(&text, sizeof(text));
  for (int i=0; i < 4 ; i ++)
   {
     if( text[0] == ((unsigned char *)(&pipes[i]))[0]
        recArray[i] = text[1];
   }
  Serial.println(text[1]);
 }
}

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


text:
Can I include a header file into a new header file?
Can I include a header file into a new header file that I created? I put #include <MCP23S17.h>. I want to create a another header file.

Can I include a header file into a new header file that I created? Yeah. That's what they are meant to be used.

Just remember to put Include guards to avoid problems... And remember to accept the most useful answer to avoid being bumped to the homepage uselessly...

Why not just include both in the final program?
Happens all the time.
DHT.h needs AdaFruit_Sensor.h, for instance, so you just include both.
First AdaFruit
then DHT

Yes, a header can include another header.  But if you are using the Arduino IDE and the headers aren't in the same folder, then you'll also need an #include line for it in the .ino file.

Wouldn't it have been easier to just try it to begin with instead of asking and waiting?

i want to llink MCP23S17.h file to my own created header file

can you give some suggestion to it

Suggestion to what?

Since Arduino IDE 1.6.6 it's no longer necessary to add includes to the sketch for library-library dependencies.

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


text:
More than 4 MCP23S17 on 1 SPI bus
I would like to use 7 MCP23S17 as output expanders on one SPI bus. Every IC has its own address from 0 to 6. The first MCP23S17 can be written with no problem. The second chip did not work properly. The CS pin of the MCP23S17 is set like at the all other 4 ICs.
Does anybody have experience with more then 4 MCP23S17 on SPI? Could anyone help?
#include <SPI.h>
#include <MCP23S17.h>

MCP A(0, 10);
MCP B(1, 8);
int d = 250;

void setup() {
  A.begin();
  B.begin();
  for (int k = 1; k <= 16; k++) {
    A.pinMode(k, OUTPUT);
    B.pinMode(k, OUTPUT);
  }
}

void loop() {
  //////////// ON THE LIGHT ONE BY ONE  FROM BEGGING
  for (int f = 1; f <= 16; f++) {
    A.digitalWrite(f, HIGH);
    delay(d );
  }
  for (int f = 1; f <= 16; f++) {
    B.digitalWrite(f, HIGH);
    delay(d );
  }
  ////////////  OFF THE LIGHT ONE BY ONE  FROM BEGINNIG
  for (int f = 1; f <= 16; f++) {
    A.digitalWrite(f, LOW);
    delay(d);
  }
  for (int f = 1; f <= 16; f++) {
    B.digitalWrite(f, LOW);
    delay(d);
  }
}

Perhaps you have a wiring, logic, or programming error in your address decoding.   Please edit your question to include a Minimal, Complete, and Verifiable example of code and a  circuit diagram.

view now sir my question

Which library are you using?

Also do you know how the address pins work?

Use my library. It had an example that does exactly what you want. https://github.com/MajenkoLibraries/MCP23S17

The diagram shows only one SS pin going to both chips.  Is that intentional?  If that's the case, then you only need to send things out once since all the chips will receive the same thing.

Have you got the Solution.
Ravi

 MCP A(0, 9);
 MCP B(1, 8);
 MCP C(2, 7);
 MCP D(3, 6);
 MCP E(4, 5);
 MCP F(5, 3);

CS on pin 10 is often used for Ethernet
CS on pin 4 is often used for SD

How is this supposed to solve the problem? As I can see, he is not using an Ethernet or an SD shield.

Hi gre_gor, adress and chipselect 6 time different...

Assuming that the adressing is correct and all the modules work fine individually, there are some things you can do:

try to disable the slave select of the modules that aren’t require to communicate at a certain time, there are examples for that
add a bit of code where you define chip select as an input for all but one and see if you can communicate with that one. Do that for all of them
remove MISO pin from all but one and see if you can communicate with that one. Do that for all of them
use a tri-state buffer through which you connect the MISO pin and use chip select for enabling the buffer. This buffer puts the MISO pin into a state of high impedance when a certain module is not used for communication and prevents fata from being lost


text:
Why is there no smooth value from ADXL335?
I have written this code to read x-acceleration from ADXL335.

Why is the value toggling between 342, 343, 344 even at rest? Is there anything I need to do to get a smooth curve?
How to increase resolution? (I'm using a Mega 2560)

int Xcurr,Ycurr,Zcurr;
int Xpre=0,Ypre=0,Zpre=0;
int res=0;
// these constants describe the pins. They won't change:
const int groundpin = A1;
// analog input pin 4 -- ground
const int powerpin = A0;
// analog input pin 5 -- voltage
const int xpin = A3;
// x-axis of the accelerometer
const int ypin = A2;
// y-axis
const int zpin = A4;
// z-axis (only on 3-axis models)
const int stpin = A5;

void setup() {
  Serial.begin(9600);
  pinMode(groundpin, OUTPUT);
  pinMode(powerpin, OUTPUT);
  digitalWrite(groundpin, LOW);
  digitalWrite(powerpin, HIGH);
  pinMode(stpin, OUTPUT);
  digitalWrite(stpin, LOW);
}

void loop() {
  Xcurr=analogRead(xpin);
  Serial.print(Xcurr);Serial.print("\n");
  delay(100);
}

It's called LSB noise, and it is what the ADC does. Just average the values over time (rolling average) to smooth it.

It is called moving average, the calculations you can use to prevent such problems can be found at wikipedia
In principle, what you do is take the average over the last x measurements to take away the peaks.


text:
Use 5V pH sensor with 3.3V NodeMCU
I'm trying to use a pH probe with NodeMCU, the problem is that NodeMCU is 3.3V and the pH analog sensor requires 5V, at first I thought using the VIN pin but didn't work, then I used the VU pin from NodeMCU V3 (by Lolin) but it didn't give me the right values, like if it missed more power. Is there any other way? Or any esp8266 board which supports 5V into it's analog input?

Try and get a 5V ADC board that you can talk to over I2C and a 5v->3.3V logic level convertor for the I2C bus.

your divider was probably OK after all - some nodeMCU boards don't spit out 5v on VIN. There's not a ton of consistency on nodeMCU devboards but i've found the ones with CH340s to all be deficient in that regard, and all the CP2102s to be good, look for "amica" on the back, and avoid the ones that say "lolin". All the Wemos D1 minis i've tried (about 20 units in 3 variations) work and have 3.3ADCs and 5v VIN, as expected.

Depending on your specific sensor and power supply setup you have following options:

Change supply voltage
Most resistive sensors don't have to power anything and will function just fine when supplied with less than 5V. Study the datasheet and make test measurements to find out whether this is suitable.
Use a voltage divider
Supply the sensor with 5V and use a simple voltage divider before    connecting to your MCU and therefore measure 0-3.3V.
Interface another IC
Get a small external ADC that can handle 5V readings and may be interfaced by any serial protocol supported by your esp8266 (namely UART and I2C).

I would also recommend using an external ADC for example: link

The external ADC is imo the least favourable option as it needs more hardware work (maybe even different casing), MUCH more code and is generally less efficient.

@mistery Thanks for your answer! Well actually I already tried with a voltage divider, from 5V to 3.3V and worked but just in some cases; I'm using NodeMCU VU pin which supposedly gives 5V, but for example, when pH is lower, the sensor needs more power to give an accurate value, and when this happens NodeMCU stops getting those readings, let's say under 4.80 (in a scale of 0-14) it stops reading analog value changes, so I'm thinking probably NodeMCU can't really provide 5V.
My voltage divider is with 1K and 2K, I'm thinking to probably use a Wemos board, it has a 5V pin, what do you think?

I still don't know what exact board you have. my idea was to power the sensor from your power supply, not through the chip. You should really study the sensor's data sheet to get an idea of it's behaviour

The simplest method is just a voltage divider - just as if you were interfacing a 5V logic signal output with a 3.3V input. However it may not work.
A voltage divider will only really be of use if the output of the pH sensor is low impedance. If it's not then you will need a very high impedance voltage divider, and the analog input of the ESP8266 isn't high enough impedance to support a very high impedance voltage divider - it will skew the results horribly.
So you may need to buffer the output of the pH sensor through an op-amp first.
If you use a unity gain non-inverting buffer you can then use a voltage divider to reduce the output voltage.

simulate this circuit – Schematic created using CircuitLab
Alternatively, as others have suggested, use an external 5V ADC chip and logic level conversion to communicate with the ESP8266.

Old topic, but in case it shows up in searches, like the one I was just doing ... I run a 5v ultrasonic SR04 off a Lolin nodemcu, and if you connect to "VU" on the Lolin nodemcu, you will get 5v.

Tested here with a voltmeter and indeed VU gives 5V. Good one!

Part of the problem was also reading 5v from sensor

Have you guys checked the specification of the AiThinker's ESP-12s? There's a piece of description in its Chinese edition document that says if you are hooking up other devices which work in 5v, you have to use the Level converter circuit in between.

the question is about powering, not about Serial comunication


text:
RS422 interfacing with the Arduino
Good day,
I have a sensor which supports serial data output using RS422 which has 4 wires (RX+, RX-, TX+, TX-)
my question is how can I connect this sensor to the Arduino.
I read that i can use 2 max485 chips to do this but uncertain of the exact procedure.
Thanks in advance.

This is not really an arduino question, for of an Electrical Engineering question,    this should help   https://electronics.stackexchange.com/questions/280073/how-to-interface-rs-422-to-uart-on-my-mcu

There are pre-made and very inexpensive Arduino RS-485 modules available on Ebay or Amazon.  Much simpler than building your own circuit.
They look like this:

The MAX490 chip consists of DI (pin 3) and RO (pin 2) pins that connect to the Arduino TX and RX respectively. the rs-422 side of the chip consists of pin 5 (Y / T+), Pin 6 (Z / T-), pin 7 (B / R-) and pin 8 (A / R+)
http://arduinotronics.blogspot.com/2018/09/long-distance-serial-with-rs-422.html


text:
Arduino core libraries
We have worked with a company to design a custom board based on the Arduino Zero and have also had them do some programming for us.
In doing so, they have had to modify the following Arduino core libraries:  variant.cpp, variant.h and wiring_analog.c.
Unfortunately, this causes problems with other projects using Arduino.
Is there a way to keep these libraries local to specific projects without modifying the original files?

you want to use the Arduino SAMD core with your board? create a board package which references the SAMD core

I'm wondering why they didn't define a new board type and use conditional compiling in the first place so that you could just use the new/modified files for everything.

for a mass sold board create a boards package for Boards Manager installation.  For a customized board or a small series put the files in the hardware folder https://arduino.stackexchange.com/questions/54484/adding-a-custom-board-to-the-arduino-ide/60660#60660

@Juraj - Yes, we are using the Arduino SAMD core (Arduino Zero Native USB).  I will check out the link you provided.  Thank you.

it would be better to avoid the change in wiring_analog.c. what change is it?

@Juraj - I am not sure what changes were made.  I have sent an email to the Software Engineer to inquire.  I'll report back when I know.