text:
ATmega328, arduino nano v3 code error saying insufficient ram memory
the code error says this and im not sure what to do please i need urgent help :(`
// Easy bluetooth controlled scrolling text

// by Yoruk for Instructable

// 26 02 15 : first code
// 03 03 15 : buffer updating
// 04 03 15 : faster version, both buffers
// 05 03 15 : cleaning and help

/*
WIRING :
 pin 12 - DataIn of the first led matrix module
 pin 11 - CLK of the first led matrix module
 pin 10 - CS of the first led matrix module

 pin 9 : RX pin of the bluetooth module
 pin 8 : TX pin of the bluetooth module

 5V : 5v of the matrix module, 5v of the bluetooth module
 GND : the two GND signals of the matrix modules and the bluetooth module

 WARNING : Use a 3v3 arduino card (nano...) or a level converter !!!

 Wire the matrix modules in serie. See the Instructable steps.

 */

//Librairie for the LEDs matrix
#include "LedControl.h"

// virtual serial lib, used with bluetooth
#include <SoftwareSerial.h>

//How many matrixes we have ?
int MatrixNumber =5;

//virtual serial port bluetooth configuration
SoftwareSerial BT(8, 9);   //pin 8 : virtual RX    pin 9 :  virtual TX

// the delay between each screen display (ms)
int SpeedDelay = 12;

//total string lenght. The first message is 25 characters long (including spaces)
int LongueurChaine=25;

char incomingByte; //incoming data from the BT link

// the two pixels arrays
char Buffer[200];   //contient tout les pixels de TOUTE LA PHRASE
char Buffer_inverse[200]; //contient tout les pixels de TOUTE LA PHRASE, mais symetrises pour affichage sur ecran inverses

// the message array
char Phrase[50];

//here we set up the led matrix
LedControl lc=LedControl(12,11,10,MatrixNumber);

// character lib
int fontDefinitions[480] = {
    0x00,0x00,0x00,0x00,0x00,/*space*/ // is 32 in ASCII
    0x00,0xF6,0xF6,0x00,0x00,/*!*/
    0x00,0xE0,0x00,0xE0,0x00,/*"*/
    0x28,0xFE,0x28,0xFE,0x28,/*#*/
    0x00,0x64,0xD6,0x54,0x08,/*$*/
    0xC2,0xCC,0x10,0x26,0xC6,/*%*/
    0x4C,0xB2,0x92,0x6C,0x0A,/*&*/
    0x00,0x00,0xE0,0x00,0x00,/*'*/
    0x00,0x38,0x44,0x82,0x00,/*(*/
    0x00,0x82,0x44,0x38,0x00,/*)*/
    0x88,0x50,0xF8,0x50,0x88,/***/
    0x08,0x08,0x3E,0x08,0x08,/*+*/
    0x00,0x00,0x05,0x06,0x00,/*,*/
    0x08,0x08,0x08,0x08,0x08,/*-*/
    0x00,0x00,0x06,0x06,0x00,/*.*/
    0x02,0x0C,0x10,0x60,0x80,/*/*/
    0x7C,0x8A,0x92,0xA2,0x7C,/*0*/
    0x00,0x42,0xFE,0x02,0x00,/*1*/
    0x42,0x86,0x8A,0x92,0x62,/*2*/
    0x44,0x82,0x92,0x92,0x6C,/*3*/
    0x10,0x30,0x50,0xFE,0x10,/*4*/
    0xE4,0xA2,0xA2,0xA2,0x9C,/*5*/
    0x3C,0x52,0x92,0x92,0x0C,/*6*/
    0x80,0x86,0x98,0xE0,0x80,/*7*/
    0x6C,0x92,0x92,0x92,0x6C,/*8*/
    0x60,0x92,0x92,0x94,0x78,/*9*/
    0x00,0x00,0x36,0x36,0x00,/*:*/
    0x00,0x00,0x35,0x36,0x00,/*;*/
    0x10,0x28,0x44,0x82,0x00,/*<*/
    0x28,0x28,0x28,0x28,0x28,/*=*/
    0x00,0x82,0x44,0x28,0x10,/*>*/
    0x40,0x80,0x8A,0x90,0x60,/*?*/
    0x7C,0x82,0xBA,0xBA,0x62,/*@*/
    0x3E,0x48,0x88,0x48,0x3E,/*A*/
    0xFE,0x92,0x92,0x92,0x6C,/*B*/
    0x7C,0x82,0x82,0x82,0x44,/*C*/
    0xFE,0x82,0x82,0x82,0x7C,/*D*/
    0xFE,0x92,0x92,0x92,0x82,/*E*/
    0xFE,0x90,0x90,0x90,0x80,/*F*/
    0x7C,0x82,0x82,0x8A,0x4E,/*G*/
    0xFE,0x10,0x10,0x10,0xFE,/*H*/
    0x82,0x82,0xFE,0x82,0x82,/*I*/
    0x84,0x82,0xFC,0x80,0x80,/*J*/
    0xFE,0x10,0x28,0x44,0x82,/*K*/
    0xFE,0x02,0x02,0x02,0x02,/*L*/
    0xFE,0x40,0x20,0x40,0xFE,/*M*/
    0xFE,0x60,0x10,0x0C,0xFE,/*N*/
    0x7C,0x82,0x82,0x82,0x7C,/*O*/
    0xFE,0x90,0x90,0x90,0x60,/*P*/
    0x7C,0x82,0x82,0x86,0x7E,/*Q*/
    0xFE,0x90,0x98,0x94,0x62,/*R*/
    0x64,0x92,0x92,0x92,0x4C,/*S*/
    0x80,0x80,0xFE,0x80,0x80,/*T*/
    0xFC,0x02,0x02,0x02,0xFC,/*U*/
    0xF8,0x04,0x02,0x04,0xF8,/*V*/
    0xFC,0x02,0x0C,0x02,0xFC,/*W*/
    0xC6,0x28,0x10,0x28,0xC6,/*X*/
    0xC0,0x20,0x1E,0x20,0xC0,/*Y*/
    0x86,0x8A,0x92,0xA2,0xC2,/*Z*/
    0x00,0x00,0xFE,0x82,0x00,/*[*/
    0x00,0x00,0x00,0x00,0x00,/*this should be / */
    0x80,0x60,0x10,0x0C,0x02,/*]*/
    0x20,0x40,0x80,0x40,0x20,/*^*/
    0x01,0x01,0x01,0x01,0x01,/*_*/
    0x80,0x40,0x20,0x00,0x00,/*`*/
    0x04,0x2A,0x2A,0x2A,0x1E,/*a*/
    0xFE,0x12,0x22,0x22,0x1C,/*b*/
    0x1C,0x22,0x22,0x22,0x14,/*c*/
    0x1C,0x22,0x22,0x12,0xFE,/*d*/
    0x1C,0x2A,0x2A,0x2A,0x18,/*e*/
    0x10,0x7E,0x90,0x80,0x40,/*f*/
    0x18,0x25,0x25,0x25,0x1E,/*g*/
    0xFE,0x10,0x10,0x10,0x0E,/*h*/
    0x00,0x12,0x5E,0x02,0x00,/*i*/
    0x02,0x01,0x01,0x11,0x5E,/*j*/
    0xFE,0x08,0x08,0x14,0x22,/*k*/
    0x00,0x82,0xFE,0x02,0x00,/*l*/
    0x3E,0x20,0x1C,0x20,0x1E,/*m*/
    0x3E,0x20,0x20,0x20,0x1E,/*n*/
    0x1C,0x22,0x22,0x22,0x1C,/*o*/
    0x3F,0x24,0x24,0x24,0x18,/*p*/
    0x18,0x24,0x24,0x3F,0x01,/*q*/
    0x3E,0x10,0x20,0x20,0x10,/*r*/
    0x12,0x2A,0x2A,0x2A,0x04,/*s*/
    0x00,0x10,0x3C,0x12,0x04,/*t*/
    0x3C,0x02,0x02,0x02,0x3E,/*u*/
    0x30,0x0C,0x02,0x0C,0x30,/*v*/
    0x38,0x06,0x18,0x06,0x38,/*w*/
    0x22,0x14,0x08,0x14,0x22,/*x*/
    0x38,0x05,0x05,0x05,0x3E,/*y*/
    0x22,0x26,0x2A,0x32,0x22,/*z*/
    0x00,0x10,0x6C,0x82,0x82,/*{*/
    0x00,0x00,0xFF,0x00,0x00,/*|*/
    0x04,0x02,0xFF,0x02,0x04,/*|, arrow*/
    0x82,0x82,0x6C,0x10,0x00,/*}*/
    0x08,0x10,0x18,0x08,0x10/*~*/
};

void setup() {

    //matrix modules init
    for(int adresse=0;adresse<MatrixNumber;adresse++) {
        /*The MAX72XX is in power-saving mode on startup*/
        lc.shutdown(adresse,false);
        /* Set the brightness to a medium values */
        lc.setIntensity(adresse,4);
        /* and clear the display */
        lc.clearDisplay(adresse);
    }

//    BufferBuilding("Hi ! Sent me a message...", 25);   //first message on the led screen

    BufferBuilding("text", 4);   //first message on the led screen

    Serial.begin(9600); //we also set the normal serial link, for debug

    BT.begin(9600);      // bluetooth initialisation

    //we sent a message on the phone to tell the user that he can do someting...
    BT.println("Hi ! I'm waiting for a message. Type it and press SEND.");

}

void loop() {

    DrawText( LongueurChaine); //draw the message, in a loop

    //or, if we get something on the virtual bluetooth port...
    if (BT.available() > 0) {

        LongueurChaine = BT.available(); //incoming string lenght

        for  (int i = 0; i < LongueurChaine; i++) {

            // read the incoming byte:
            incomingByte = BT.read();

            Phrase[i] = incomingByte; ///store the character into the string array

        }

        //debug features, to check :
        Serial.print("Display: ");
        Serial.println(Phrase);
        Serial.print("Length : ");
        Serial.println(LongueurChaine);

        //buffers cleaning, to store the new message
        for(int k = 0; k < 200; k++) {
            Buffer[k]=0;
            Buffer_inverse[k]=0;

        }

        //we create the new buffers, so the new message will be drawn when leaving the sub
        BufferBuilding(Phrase, LongueurChaine);
    }

}

void BufferBuilding(char * stringToDisplay, byte stringLength)
{
    int i =0;

    //loop on every characters (on the string)
    for(int k = 0; k < stringLength; k++) {
        //here we call the characters library
        int caract= k;
        Buffer[i+0] =  fontDefinitions[((stringToDisplay[caract] - 32) * 5) + 0];
        Buffer[i+1] =  fontDefinitions[((stringToDisplay[caract] - 32) * 5) + 1];
        Buffer[i+2] =  fontDefinitions[((stringToDisplay[caract] - 32) * 5) + 2];
        Buffer[i+3] =  fontDefinitions[((stringToDisplay[caract] - 32) * 5) + 3];
        Buffer[i+4] =  fontDefinitions[((stringToDisplay[caract] - 32) * 5) + 4];
        Buffer[i+5] =  B00000000;  //one blank column of leds between two characters
        i=i+6;
    }

    // here, we create a second buffer, to display the message on the switched matrixes
    for(int k = 0; k < stringLength*6; k++) {
        for(int i = 0; i < 8; i++) {
            bitWrite(  Buffer_inverse[k] ,i,  bitRead(Buffer[k] ,7-i) )   ;
        }
    }
}

void DrawText( byte stringLength) {

    for(int k = 0; k < stringLength*6; k++) {

        delay(SpeedDelay);

//delay(10000);
        //k is the column

        //buffer drawing
        for (int m = 0; m < MatrixNumber; m++) {  //loop on the matrix
            if (m % 2 ==  0) //check is the module is upside-down or not...
            {
                //here, the matrix is flipped upside-down
                for (int i = 0; i < 8; i++) {  //loop on the columns

                      lc.setRow(m,7-i,Buffer[i+k+8*m]);
                }
            }
            else
            {
                //classical
                for (int i = 0; i < 8; i++) {  //loop on the columns

                       lc.setRow(m,i,Buffer_inverse[i+k+8*m]);
                }
            }
        }
    }

}

It means you are using too much RAM on the microcontroller.  Follow Juraj suggestion.

"im not sure what to do": You need to reduce the amount of RAM space (variables, strings, constants, large or numerous arrays) by moving constants, especially large ones like strings, to program memory. But without seeing your code, we can only guess. With only 5K of code and nearly 2K of globals, it does seem likely that you have used a lot of space for strings, and those are often easy to move to program memory. Show us the code if it isn't too huge, or at least gives us some clues from which to help you better.

Please provide source code if you want help.

how do i post the code here? its too long to be posted in the comments

Edit your question and format it correctly by selecting the code portion and click the {} button, or press Ctrl+k

thanks and i have edited the code in the question

first try to change int fontDefinitions[480] to const byte fontDefinitions[480]

The font definition table takes 960 bytes of RAM - nearly 1/2 of the the total usage. You can regain 480 bytes just by declaring that array as uint8_t; 1 byte each entry instead of 2 bytes each for ints. You can regain the remaining 480 if you still need to, by moving that table to program memory. The Arduino.cc site has a good discussion with examples. Just pay attention to the data-types you use if you do that; the functions to read data out of program memory each return one specific type.

You can free up RAM by moving large arrays and strings into Flash.  By default all strings and arrays are placed into RAM.  The disadvantage to putting data into Flash is that you will not be able to modify it at runtime.
To place an array in Flash use the PROGMEM compiler directive:
static const unsigned char PROGMEM my_array[] = { 0x00, 0x01, 0x02 ... };

When doing this your likely to notice, besides more available RAM, that many library functions can longer access the array you've placed into FLASH.  The AVR microcontrollers have to use special instructions to read data out of Flash memory.  Some library functions handle this automatically but many do not.  In order to access the data you'll have to implement a function that copies the data out of Flash and into RAM.
Here is an example of a function to copy Flash data into RAM:
char *Get_Flash_String(const char *FlashString)
{
    static char buff[MAX_FLASH_STRING_LENGTH+1];
    int i, len;

    len = strlen_P(FlashString);
    for (i = 0; i <= len; i++)
        buff[i] = pgm_read_byte_near(FlashString + i);

    return(buff);
}

Note that the function above assumes you're reading a NULL terminated string out of flash.  If you're reading an array you don't want to use strlen() to determine the length.

this answer is too general but not general. confusing. show him how to use it for his case.

Perhaps it's better to teach a hungry man to fish, rather than hand him a fish?

from this answer he learns nothing. the link in JRobert's answer is usefull. first I added it as comment, but then I deleted it, to not to confuse OP. changing the type of array item gains him memory for now

And you've been granted permission to speak for another person?

no. I always comment why I down-vote


text:
A library issue with ArduinoOTA for MKR1400GSM
For the past years I've been using ArduinoOTA along with ArduinoHttpClient on MKR1400 for updating the bin on the fly from a remote web server.
Even without ArduinoOTA's official support for GSM, it has been working like a charm. All it took was adding a condition to ArduinoOTA.h to accept MGRGSM (thanks Juraj) and some playing around with the code to ensure successful operation:
#elif defined(_MKRGSM_H_INCLUDED)
ArduinoOTAClass <GSMServer, GSMClient> ArduinoOTA;

Unfortunately, the other day I went ahead and updated by IDE's libraries without first backing them up and now I lost the ability to perform successful OTA.
What I have done so far is to step back with libraries versions and check the dates of the lib updates (I found a point in time when I knew I compiled a good version before the lib has been updated) but so far nothing, the OTA process starts and it bricks the board.
Any idea? Thanks!

Arduino made changes in platform.txt files for IDE 2.0 pluggable monitor system, which is a system to detect COM ports, network ports and other means to upload to Arduino.
While they did the changes they forgot to test the OTA support with IDE 1 so they broke OTA in AVR and SAMD core. The affected versions of core are AVR 1.8.4 and SAMD 1.8.12.
Arduino already fixed the error in platform.txt in both cores and AVR core already has a new release 1.8.5 with the fix. The SAMD core doesn't have a new release yet. You can apply the fix to your 1.8.12 installation, or return to 1.8.11 version. EDIT: SAMD core 1.8.13 is already available too.
EDIT: Or you can use the 'fake programmer' method which doesn't require network port to be detected by the IDE and has a separate configuration.

Thanks for the information, I tried the fix and returning to 1.8.11, nighter worked, but I was able to get progress with an old backup of the libraries folder and rolling back IDE to 1.81 (I assume newer versions would work as well but didn't have the time to test). For now I can do OTA updates of most types, some do not work like updating an older bin over a new one but what do works may ends up as enough.

@Nino SAMD core 1.8.13 is available

Cool! I can confirm, a fresh new installation works like a charm, thanks a lot Juraj.

I tried all over again, IMHO it's not possible to get a large bin file uncorrupted directly on a SD card. The only way i see is first into the internal memory of the modem and then on the SD card. I made a example:
https://github.com/CptHolzschnauz/Arduino-MKR-1400-OTA-Update

this is not an answer to the Question

source: Stack Exchange

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

sort: votes


text:
Why is the server.on() function from "ESPAsyncWebServer.h" executed in the setup() side and not on the loop() side?
I'm implementing an example in which 2 ESP32's communicate each other using the HTTP Protocol. One acts as Server the other as Client. In the examples provided, I am curious about the declaration on the server, as its implementation is declared in the setup() function (I am using the standard Arduino IDE), which is supposed to have code that executes only once, rather than the loop() function (at least in this example), which is supposed to refresh the call every cycle, yet it remains empty:
  Complete project details at https://RandomNerdTutorials.com/esp32-client-server-wi-fi/

  Permission is hereby granted, free of charge, to any person obtaining a copy
  of this software and associated documentation files.

  The above copyright notice and this permission notice shall be included in all
  copies or substantial portions of the Software.
*/

// Import required libraries
#include "WiFi.h"
#include "ESPAsyncWebServer.h"

#include <Wire.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_BME280.h>

// Set your access point network credentials
const char* ssid = "ESP32-Access-Point";
const char* password = "123456789";

/*#include <SPI.h>
#define BME_SCK 18
#define BME_MISO 19
#define BME_MOSI 23
#define BME_CS 5*/

Adafruit_BME280 bme; // I2C
//Adafruit_BME280 bme(BME_CS); // hardware SPI
//Adafruit_BME280 bme(BME_CS, BME_MOSI, BME_MISO, BME_SCK); // software SPI

// Create AsyncWebServer object on port 80
AsyncWebServer server(80);

String readTemp() {
  return String(bme.readTemperature());
  //return String(1.8 * bme.readTemperature() + 32);
}

String readHumi() {
  return String(bme.readHumidity());
}

String readPres() {
  return String(bme.readPressure() / 100.0F);
}

void setup(){
  // Serial port for debugging purposes
  Serial.begin(115200);
  Serial.println();

  // Setting the ESP as an access point
  Serial.print("Setting AP (Access Point)…");
  // Remove the password parameter, if you want the AP (Access Point) to be open
  WiFi.softAP(ssid, password);

  IPAddress IP = WiFi.softAPIP();
  Serial.print("AP IP address: ");
  Serial.println(IP);

  server.on("/temperature", HTTP_GET, [](AsyncWebServerRequest *request){
    request->send_P(200, "text/plain", readTemp().c_str());
  });
  server.on("/humidity", HTTP_GET, [](AsyncWebServerRequest *request){
    request->send_P(200, "text/plain", readHumi().c_str());
  });
  server.on("/pressure", HTTP_GET, [](AsyncWebServerRequest *request){
    request->send_P(200, "text/plain", readPres().c_str());
  });

  bool status;

  // default settings
  // (you can also pass in a Wire library object like &Wire2)
  status = bme.begin(0x76);
  if (!status) {
    Serial.println("Could not find a valid BME280 sensor, check wiring!");
    while (1);
  }

  // Start server
  server.begin();
}

void loop(){

}

You can see the "server.on(....)" declarations in the setup() side of the code, and the empty loop() function in the end.
server.on("/temperature", HTTP_GET, [](AsyncWebServerRequest *request){
    request->send_P(200, "text/plain", readTemp().c_str());
  });

So, my assumption is that the server is already running in the background when executing server.begin() and does not need to be explicitly called, but it still confuses me because there is no explicit declaration on the loop() such as server.loop() or something similar.
Can you explain how this works and why it is not necessary to explicitly declare the function on the loop()?
Thanks
-EZ

The construct with a lambda function
server.on("/temperature", HTTP_GET, [](AsyncWebServerRequest *request){
    request->send_P(200, "text/plain", readTemp().c_str());
  });

is same as
server.on("/temperature", HTTP_GET, onGetTemperature);

where onGetTemperature is a function defined before void setup()
void onGetTemperature(AsyncWebServerRequest *request) {
  request->send_P(200, "text/plain", readTemp().c_str());
}

Would you in this case ask why it is "executed in the setup()?"

Well, it seems to me that you are just separating the lambda function outside of the setup() scope and calling it from inside setup(), but my question would not be "why is it executed in the setup" but rather, why the server.on function is not explicitly called from within the loop function? Which I believe Majenko just confirmed it is a callback() and thus not required to be explicitly called, as it is triggered by the server and compared to match one of the multiple "on" functions that could be listed in setup().

The function is not "called" inside setup(). The function pointer is merely registered with the web server in setup() for later use.

Server.on() sets a callback function. That registers a function to be executed when a certain event happens at a later date. In this case it's when a certain URL is requested with a GET method.
Any time a request is made to the web server a list of "on" registered events is examined for one that matches the request, then the associated function (in this case a lambda function) is executed.
And all that is done asynchronously (hence the name) in the background in another thread so you don't need to explicitly do anything.

Thanks, I figured as much, but  I wanted confirmation. The Asynchronous part seems to be doing the trick for the callback operation without the explicit mention.

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


text:
Arduino Nano 33 BLE Sense starts in bootloader mode on power up
I'm facing a lot of issues with Arduino Nano BLE Sense.
I'm aware about the port switching between bootloader (when the yellow LED pulses) and application.
First issue
Sometime when I power up the board (i.e. pluggin in the USB cable or turn on the PC) it starts in bootloader mode, even if there's a working sketch inside.
This is very bad, because I didn't find a way to recover from this situation without pressing the reset button, and of course this is not doable in a real environment.
Second issue
Even when it starts the application and I can successfully open the serial port, it does not receive or send any data. To recover, again, I need to press the reset button. The sketch is very simple and I also tried with default examples. Anyway, here how I open the serial port i Arduino:
void setup()
{
  Serial.begin(115200);
  while (!Serial);
  Serial.setTimeout(10);
  Serial.flush();
}

Please note, that once it starts in the correct way it works without any problem!
Questions:

is there a way to software reset the board to force the application to start when in bootloader mode? I tried with ard-reset-arduino.py --caterina /dev/ttyACM1 with no luck (i.e. it remains in bootloader mode).

do you have any suggestion how to avoid the serial issues I'm facing? I tried with several Arduino boards (I have 10 on my desk) and 3 different PCs.

Are you sure it's in bootloader mode and not just waiting for that while(!Serial) to become true? That will never happen until you open the serial port from the PC.

@PMF, even if I don't open the port on PC side usually the yellow LED is off (application mode). Sometimes instead it pulses on power up. Resetting the board leads to turn off the LED. Furthermore, when the LED pulses I can upload the firmware but I cannot exchange serial data with my application. When the LED is off I can (unless issue #2).

So, yes, I'm pretty sure it's in bootloader mode for issue #1.


text:
Why LCD 16x2 cannot display "water leaking" when rain sensor detects water?
#include <SoftwareSerial.h>
#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
SoftwareSerial mySerial(0, 1);

int gas_sensor = A5;
int water_sensor = 8;
int buzzer = 9;
int fan = 13;
int sms_count = 0;

void setup() {
  pinMode(gas_sensor, INPUT);
  pinMode(water_sensor, INPUT);
  pinMode(buzzer, OUTPUT);
  pinMode(fan, OUTPUT);
  mySerial.begin(9600);
  Serial.begin(9600);
  lcd.begin(16, 2);
  delay(500);
}

void loop() {
  if (digitalRead(water_sensor) == LOW && analogRead(gas_sensor)) {
    CheckWater_and_Gas();
  }
  else if (digitalRead(water_sensor) == LOW) {
    CheckWater();
  }
  else if (analogRead(gas_sensor)) {
    CheckGas();
  }
  else {
  }
}

void CheckWater_and_Gas() {
  int sensorValue = analogRead(gas_sensor);
  Serial.println(sensorValue);
  delay(1000);
  if ( digitalRead(water_sensor) == LOW && sensorValue > 150 ) {
    digitalWrite(buzzer, HIGH);
    digitalWrite(fan, HIGH);
    lcd.clear();
    lcd.setCursor(0, 0);
    lcd.print(" Water and ");
    lcd.setCursor(0, 1);
    lcd.print(" Gas Leaking ! ");
    SetAlertWater_and_Gas();
  }
  else {
    digitalWrite(buzzer, LOW);
    digitalWrite(fan, LOW);
    lcd.clear();
  }
}

void CheckWater() {
  if ( digitalRead(water_sensor) == LOW ) {
    digitalWrite(buzzer, HIGH);
    lcd.clear();
    lcd.setCursor(0, 1);
    lcd.print(" Water Leaking ! ");
    SetAlertWater();
  }
  else {
    digitalWrite(buzzer, LOW);
    lcd.clear();
  }
}

void CheckGas() {
  int sensorValue = analogRead(gas_sensor);
  Serial.println(sensorValue);
  delay(1000);
  if (sensorValue > 150) {
    digitalWrite(buzzer, HIGH);
    digitalWrite(fan, HIGH);
    lcd.clear();
    lcd.setCursor(0, 1);
    lcd.print("Gas Leaking !");
    SetAlertGas();
  }
  else {
    digitalWrite(buzzer, LOW);
    digitalWrite(fan, LOW);
    lcd.clear();
  }
}

how do you know that the rain sensor is detecting water?

i check it from online

actually i can detect water using this sensor but lcd cannot display 'water leaking' if i use the code

please format your code ..... select all of the code and click {} button

leave everything connected and load an LCD "Hello World" sketch ..... does it work?

i think lcd should be no problem because lcd can display gas leaking when mq6 gas sensor detects lpg gas. lcd can display water and gas leaking also when mq6 gas sensor and rain sensor detect lpg gas and water simultaneously. but i don't know why it cannot display water leaking when rain sensor detect water.

I guess analogRead(gas_sensor) is never zero so the first if is activated if digitalRead(water_sensor) is LOW

yep, it always has value

and is it the problem? that it shows "Water and Gas Leaking"?

You schould start searching the root cause for your error: code, display, sensor, … step by step.
Check if your display is working by 1.) reducing your loop() to
void loop() {
    CheckWater();
}

and 2.) change
void CheckWater() {
  if ( digitalRead(water_sensor) == LOW ) {
    digitalWrite(buzzer, HIGH);
    ...

to
void CheckWater() {
  if ( true ) {
    digitalWrite(buzzer, HIGH);
   ...

This allows you to check if your LCD is working properly. If not, start looking for the fault in wiring or maybe you are using a different LCD which has to be setup in a different mode as the sketch from online.
If this works, search for the rootcause in the sensor. Go back to the orignial code and put the input of the rain sensor to low. If your display shows: Water Leaking! something with your water sensor or it's Connection to your board seems to be wrong.

i will try it, thanks for answering me.

fine. if you gone through this, please edit your question adding the results and refining the question


text:
What is the default baud rate without calling Serial.begin?
I cannot find the answer from official document and also surprised no one asked the same question.
What is the default baud rates if I didn't call Serial.begin?

There is no default baud rate. When the sketch starts, the serial port
is disabled (thus non-functional). Calling Serial.begin() enables the
port.

Really appreciate! I just found even though I use Serial.println in loop function. The TX LED light won't blink unless I added Serial.begin in setup function.

Just for completeness: On some alternative boards that are also compatible with Arduino IDE (like e.g. ESP8266 and ESP32 boards), some information is transmitted on serial before your sketch even starts. The default baud rate then is dependent on the chip and/or board.


text:
What prescaler to use for finer control?
I'm using a UNO to generate a 10 kHz PWM signal. I need finer duty cycle variation.
The prescalers supported are 1, 8, 32, and 64.
void setup()
{
  pinMode(3,OUTPUT);
  TCCR2A = bit (WGM20) | bit (WGM21) | bit (COM2B1); // fast PWM, clear OC2A on compare
  TCCR2B = bit (WGM22) | bit (CS22); // fast PWM, prescaler of 64
  OCR2A = 63; // prescaler 32 with 10Khz
  OCR2B = ((64 + 1)/2) - 1; // 50% duty cycle
}

void loop()
{
}

Why is this question closed? It is perfectly valid.

From the layout and the comments, this code is clearly from my page about timers which is gratifying, that it is useful to people.

The lower prescalers will give you finer control. The bigger prescalers necessarily have coarser control.
From my web page about timers is this table of prescalers:
  n  -- Prescale 1   --  -- Prescale 8   --  -- Prescale 64  --  -- Prescale 256 --  -- Prescale 1024--
     Freq (Hz) Per (µs)  Freq (Hz) Per (µs)  Freq (Hz) Per (µs)  Freq (Hz) Per (µs)  Freq (Hz) Per (µs)
  1: 8,000,000*   0.125  1,000,000    1.000    125,000    8.000     31,250   32.000      7,813  128.000
  2: 5,333,333    0.188    666,667    1.500     83,333   12.000     20,833   48.000      5,208  192.000
  3: 4,000,000    0.250    500,000    2.000     62,500   16.000     15,625   64.000      3,906  256.000
  4: 3,200,000    0.313    400,000    2.500     50,000   20.000     12,500   80.000      3,125  320.000
  5: 2,666,667    0.375    333,333    3.000     41,667   24.000     10,417   96.000      2,604  384.000
  6: 2,285,714    0.438    285,714    3.500     35,714   28.000      8,929  112.000      2,232  448.000
  7: 2,000,000    0.500    250,000    4.000     31,250   32.000      7,813  128.000      1,953  512.000
  8: 1,777,778    0.563    222,222    4.500     27,778   36.000      6,944  144.000      1,736  576.000
  9: 1,600,000    0.625    200,000    5.000     25,000   40.000      6,250  160.000      1,563  640.000
 10: 1,454,545    0.688    181,818    5.500     22,727   44.000      5,682  176.000      1,420  704.000
 11: 1,333,333    0.750    166,667    6.000     20,833   48.000      5,208  192.000      1,302  768.000
 12: 1,230,769    0.813    153,846    6.500     19,231   52.000      4,808  208.000      1,202  832.000
 13: 1,142,857    0.875    142,857    7.000     17,857   56.000      4,464  224.000      1,116  896.000
 14: 1,066,667    0.937    133,333    7.500     16,667   60.000      4,167  240.000      1,042  960.000
 15: 1,000,000    1.000    125,000    8.000     15,625   64.000      3,906  256.000        977 1024.000
 16:   941,176    1.063    117,647    8.500     14,706   68.000      3,676  272.000        919 1088.000
 17:   888,889    1.125    111,111    9.000     13,889   72.000      3,472  288.000        868 1152.000
 18:   842,105    1.187    105,263    9.500     13,158   76.000      3,289  304.000        822 1216.000
 19:   800,000    1.250    100,000   10.000     12,500   80.000      3,125  320.000        781 1280.000
 20:   761,905    1.313     95,238   10.500     11,905   84.000      2,976  336.000        744 1344.000
 21:   727,273    1.375     90,909   11.000     11,364   88.000      2,841  352.000        710 1408.000
 22:   695,652    1.438     86,957   11.500     10,870   92.000      2,717  368.000        679 1472.000
 23:   666,667    1.500     83,333   12.000     10,417   96.000      2,604  384.000        651 1536.000
 24:   640,000    1.562     80,000   12.500     10,000  100.000      2,500  400.000        625 1600.000
 25:   615,385    1.625     76,923   13.000      9,615  104.000      2,404  416.000        601 1664.000
 26:   592,593    1.688     74,074   13.500      9,259  108.000      2,315  432.000        579 1728.000
 27:   571,429    1.750     71,429   14.000      8,929  112.000      2,232  448.000        558 1792.000
 28:   551,724    1.813     68,966   14.500      8,621  116.000      2,155  464.000        539 1856.000
 29:   533,333    1.875     66,667   15.000      8,333  120.000      2,083  480.000        521 1920.000
 30:   516,129    1.938     64,516   15.500      8,065  124.000      2,016  496.000        504 1984.000
 31:   500,000    2.000     62,500   16.000      7,813  128.000      1,953  512.000        488 2048.000
 32:   484,848    2.062     60,606   16.500      7,576  132.000      1,894  528.000        473 2112.000
 33:   470,588    2.125     58,824   17.000      7,353  136.000      1,838  544.000        460 2176.000
 34:   457,143    2.188     57,143   17.500      7,143  140.000      1,786  560.000        446 2240.000
 35:   444,444    2.250     55,556   18.000      6,944  144.000      1,736  576.000        434 2304.000
 36:   432,432    2.313     54,054   18.500      6,757  148.000      1,689  592.000        422 2368.000
 37:   421,053    2.375     52,632   19.000      6,579  152.000      1,645  608.000        411 2432.000
 38:   410,256    2.438     51,282   19.500      6,410  156.000      1,603  624.000        401 2496.000
 39:   400,000    2.500     50,000   20.000      6,250  160.000      1,563  640.000        391 2560.000
 40:   390,244    2.563     48,780   20.500      6,098  164.000      1,524  656.000        381 2624.000
 41:   380,952    2.625     47,619   21.000      5,952  168.000      1,488  672.000        372 2688.000
 42:   372,093    2.687     46,512   21.500      5,814  172.000      1,453  688.000        363 2752.000
 43:   363,636    2.750     45,455   22.000      5,682  176.000      1,420  704.000        355 2816.000
 44:   355,556    2.812     44,444   22.500      5,556  180.000      1,389  720.000        347 2880.000
 45:   347,826    2.875     43,478   23.000      5,435  184.000      1,359  736.000        340 2944.000
 46:   340,426    2.938     42,553   23.500      5,319  188.000      1,330  752.000        332 3008.000
 47:   333,333    3.000     41,667   24.000      5,208  192.000      1,302  768.000        326 3072.000
 48:   326,531    3.063     40,816   24.500      5,102  196.000      1,276  784.000        319 3136.000
 49:   320,000    3.125     40,000   25.000      5,000  200.000      1,250  800.000        313 3200.000
 50:   313,725    3.188     39,216   25.500      4,902  204.000      1,225  816.000        306 3264.000
 51:   307,692    3.250     38,462   26.000      4,808  208.000      1,202  832.000        300 3328.000
 52:   301,887    3.313     37,736   26.500      4,717  212.000      1,179  848.000        295 3392.000
 53:   296,296    3.375     37,037   27.000      4,630  216.000      1,157  864.000        289 3456.000
 54:   290,909    3.437     36,364   27.500      4,545  220.000      1,136  880.000        284 3520.000
 55:   285,714    3.500     35,714   28.000      4,464  224.000      1,116  896.000        279 3584.000
 56:   280,702    3.562     35,088   28.500      4,386  228.000      1,096  912.000        274 3648.000
 57:   275,862    3.625     34,483   29.000      4,310  232.000      1,078  928.000        269 3712.000
 58:   271,186    3.688     33,898   29.500      4,237  236.000      1,059  944.000        265 3776.000
 59:   266,667    3.750     33,333   30.000      4,167  240.000      1,042  960.000        260 3840.000
 60:   262,295    3.813     32,787   30.500      4,098  244.000      1,025  976.000        256 3904.000
 61:   258,065    3.875     32,258   31.000      4,032  248.000      1,008  992.000        252 3968.000
 62:   253,968    3.938     31,746   31.500      3,968  252.000        992 1008.000        248 4032.000
 63:   250,000    4.000     31,250   32.000      3,906  256.000        977 1024.000        244 4096.000
 64:   246,154    4.063     30,769   32.500      3,846  260.000        962 1040.000        240 4160.000
 65:   242,424    4.125     30,303   33.000      3,788  264.000        947 1056.000        237 4224.000
 66:   238,806    4.188     29,851   33.500      3,731  268.000        933 1072.000        233 4288.000
 67:   235,294    4.250     29,412   34.000      3,676  272.000        919 1088.000        230 4352.000
 68:   231,884    4.313     28,986   34.500      3,623  276.000        906 1104.000        226 4416.000
 69:   228,571    4.375     28,571   35.000      3,571  280.000        893 1120.000        223 4480.000
 70:   225,352    4.437     28,169   35.500      3,521  284.000        880 1136.000        220 4544.000
 71:   222,222    4.500     27,778   36.000      3,472  288.000        868 1152.000        217 4608.000
 72:   219,178    4.563     27,397   36.500      3,425  292.000        856 1168.000        214 4672.000
 73:   216,216    4.625     27,027   37.000      3,378  296.000        845 1184.000        211 4736.000
 74:   213,333    4.688     26,667   37.500      3,333  300.000        833 1200.000        208 4800.000
 75:   210,526    4.750     26,316   38.000      3,289  304.000        822 1216.000        206 4864.000
 76:   207,792    4.813     25,974   38.500      3,247  308.000        812 1232.000        203 4928.000
 77:   205,128    4.875     25,641   39.000      3,205  312.000        801 1248.000        200 4992.000
 78:   202,532    4.938     25,316   39.500      3,165  316.000        791 1264.000        198 5056.000
 79:   200,000    5.000     25,000   40.000      3,125  320.000        781 1280.000        195 5120.000
 80:   197,531    5.062     24,691   40.500      3,086  324.000        772 1296.000        193 5184.000
 81:   195,122    5.125     24,390   41.000      3,049  328.000        762 1312.000        191 5248.000
 82:   192,771    5.188     24,096   41.500      3,012  332.000        753 1328.000        188 5312.000
 83:   190,476    5.250     23,810   42.000      2,976  336.000        744 1344.000        186 5376.000
 84:   188,235    5.312     23,529   42.500      2,941  340.000        735 1360.000        184 5440.000
 85:   186,047    5.375     23,256   43.000      2,907  344.000        727 1376.000        182 5504.000
 86:   183,908    5.438     22,989   43.500      2,874  348.000        718 1392.000        180 5568.000
 87:   181,818    5.500     22,727   44.000      2,841  352.000        710 1408.000        178 5632.000
 88:   179,775    5.563     22,472   44.500      2,809  356.000        702 1424.000        176 5696.000
 89:   177,778    5.625     22,222   45.000      2,778  360.000        694 1440.000        174 5760.000
 90:   175,824    5.687     21,978   45.500      2,747  364.000        687 1456.000        172 5824.000
 91:   173,913    5.750     21,739   46.000      2,717  368.000        679 1472.000        170 5888.000
 92:   172,043    5.813     21,505   46.500      2,688  372.000        672 1488.000        168 5952.000
 93:   170,213    5.875     21,277   47.000      2,660  376.000        665 1504.000        166 6016.000
 94:   168,421    5.937     21,053   47.500      2,632  380.000        658 1520.000        164 6080.000
 95:   166,667    6.000     20,833   48.000      2,604  384.000        651 1536.000        163 6144.000
 96:   164,948    6.063     20,619   48.500      2,577  388.000        644 1552.000        161 6208.000
 97:   163,265    6.125     20,408   49.000      2,551  392.000        638 1568.000        159 6272.000
 98:   161,616    6.188     20,202   49.500      2,525  396.000        631 1584.000        158 6336.000
 99:   160,000    6.250     20,000   50.000      2,500  400.000        625 1600.000        156 6400.000
100:   158,416    6.313     19,802   50.500      2,475  404.000        619 1616.000        155 6464.000
101:   156,863    6.375     19,608   51.000      2,451  408.000        613 1632.000        153 6528.000
102:   155,340    6.438     19,417   51.500      2,427  412.000        607 1648.000        152 6592.000
103:   153,846    6.500     19,231   52.000      2,404  416.000        601 1664.000        150 6656.000
104:   152,381    6.562     19,048   52.500      2,381  420.000        595 1680.000        149 6720.000
105:   150,943    6.625     18,868   53.000      2,358  424.000        590 1696.000        147 6784.000
106:   149,533    6.688     18,692   53.500      2,336  428.000        584 1712.000        146 6848.000
107:   148,148    6.750     18,519   54.000      2,315  432.000        579 1728.000        145 6912.000
108:   146,789    6.813     18,349   54.500      2,294  436.000        573 1744.000        143 6976.000
109:   145,455    6.875     18,182   55.000      2,273  440.000        568 1760.000        142 7040.000
110:   144,144    6.938     18,018   55.500      2,252  444.000        563 1776.000        141 7104.000
111:   142,857    7.000     17,857   56.000      2,232  448.000        558 1792.000        140 7168.000
112:   141,593    7.063     17,699   56.500      2,212  452.000        553 1808.000        138 7232.000
113:   140,351    7.125     17,544   57.000      2,193  456.000        548 1824.000        137 7296.000
114:   139,130    7.187     17,391   57.500      2,174  460.000        543 1840.000        136 7360.000
115:   137,931    7.250     17,241   58.000      2,155  464.000        539 1856.000        135 7424.000
116:   136,752    7.313     17,094   58.500      2,137  468.000        534 1872.000        134 7488.000
117:   135,593    7.375     16,949   59.000      2,119  472.000        530 1888.000        132 7552.000
118:   134,454    7.437     16,807   59.500      2,101  476.000        525 1904.000        131 7616.000
119:   133,333    7.500     16,667   60.000      2,083  480.000        521 1920.000        130 7680.000
120:   132,231    7.563     16,529   60.500      2,066  484.000        517 1936.000        129 7744.000
121:   131,148    7.625     16,393   61.000      2,049  488.000        512 1952.000        128 7808.000
122:   130,081    7.687     16,260   61.500      2,033  492.000        508 1968.000        127 7872.000
123:   129,032    7.750     16,129   62.000      2,016  496.000        504 1984.000        126 7936.000
124:   128,000    7.813     16,000   62.500      2,000  500.000        500 2000.000        125 8000.000
125:   126,984    7.875     15,873   63.000      1,984  504.000        496 2016.000        124 8064.000
126:   125,984    7.938     15,748   63.500      1,969  508.000        492 2032.000        123 8128.000
127:   125,000    8.000     15,625   64.000      1,953  512.000        488 2048.000        122 8192.000
128:   124,031    8.063     15,504   64.500      1,938  516.000        484 2064.000        121 8256.000
129:   123,077    8.125     15,385   65.000      1,923  520.000        481 2080.000        120 8320.000
130:   122,137    8.188     15,267   65.500      1,908  524.000        477 2096.000        119 8384.000
131:   121,212    8.250     15,152   66.000      1,894  528.000        473 2112.000        118 8448.000
132:   120,301    8.313     15,038   66.500      1,880  532.000        470 2128.000        117 8512.000
133:   119,403    8.375     14,925   67.000      1,866  536.000        466 2144.000        117 8576.000
134:   118,519    8.438     14,815   67.500      1,852  540.000        463 2160.000        116 8640.000
135:   117,647    8.500     14,706   68.000      1,838  544.000        460 2176.000        115 8704.000
136:   116,788    8.563     14,599   68.500      1,825  548.000        456 2192.000        114 8768.000
137:   115,942    8.625     14,493   69.000      1,812  552.000        453 2208.000        113 8832.000
138:   115,108    8.688     14,388   69.500      1,799  556.000        450 2224.000        112 8896.000
139:   114,286    8.750     14,286   70.000      1,786  560.000        446 2240.000        112 8960.000
140:   113,475    8.812     14,184   70.500      1,773  564.000        443 2256.000        111 9024.000
141:   112,676    8.875     14,085   71.000      1,761  568.000        440 2272.000        110 9088.000
142:   111,888    8.938     13,986   71.500      1,748  572.000        437 2288.000        109 9152.000
143:   111,111    9.000     13,889   72.000      1,736  576.000        434 2304.000        109 9216.000
144:   110,345    9.063     13,793   72.500      1,724  580.000        431 2320.000        108 9280.000
145:   109,589    9.125     13,699   73.000      1,712  584.000        428 2336.000        107 9344.000
146:   108,844    9.188     13,605   73.500      1,701  588.000        425 2352.000        106 9408.000
147:   108,108    9.250     13,514   74.000      1,689  592.000        422 2368.000        106 9472.000
148:   107,383    9.313     13,423   74.500      1,678  596.000        419 2384.000        105 9536.000
149:   106,667    9.375     13,333   75.000      1,667  600.000        417 2400.000        104 9600.000
150:   105,960    9.437     13,245   75.500      1,656  604.000        414 2416.000        103 9664.000
151:   105,263    9.500     13,158   76.000      1,645  608.000        411 2432.000        103 9728.000
152:   104,575    9.563     13,072   76.500      1,634  612.000        408 2448.000        102 9792.000
153:   103,896    9.625     12,987   77.000      1,623  616.000        406 2464.000        101 9856.000
154:   103,226    9.688     12,903   77.500      1,613  620.000        403 2480.000        101 9920.000
155:   102,564    9.750     12,821   78.000      1,603  624.000        401 2496.000        100 9984.000
156:   101,911    9.813     12,739   78.500      1,592  628.000        398 2512.000        100 10048.000
157:   101,266    9.875     12,658   79.000      1,582  632.000        396 2528.000         99 10112.000
158:   100,629    9.938     12,579   79.500      1,572  636.000        393 2544.000         98 10176.000
159:   100,000   10.000     12,500   80.000      1,563  640.000        391 2560.000         98 10240.000
160:    99,379   10.062     12,422   80.500      1,553  644.000        388 2576.000         97 10304.000
161:    98,765   10.125     12,346   81.000      1,543  648.000        386 2592.000         96 10368.000
162:    98,160   10.188     12,270   81.500      1,534  652.000        383 2608.000         96 10432.000
163:    97,561   10.250     12,195   82.000      1,524  656.000        381 2624.000         95 10496.000
164:    96,970   10.313     12,121   82.500      1,515  660.000        379 2640.000         95 10560.000
165:    96,386   10.375     12,048   83.000      1,506  664.000        377 2656.000         94 10624.000
166:    95,808   10.438     11,976   83.500      1,497  668.000        374 2672.000         94 10688.000
167:    95,238   10.500     11,905   84.000      1,488  672.000        372 2688.000         93 10752.000
168:    94,675   10.563     11,834   84.500      1,479  676.000        370 2704.000         92 10816.000
169:    94,118   10.625     11,765   85.000      1,471  680.000        368 2720.000         92 10880.000
170:    93,567   10.687     11,696   85.500      1,462  684.000        365 2736.000         91 10944.000
171:    93,023   10.750     11,628   86.000      1,453  688.000        363 2752.000         91 11008.000
172:    92,486   10.813     11,561   86.500      1,445  692.000        361 2768.000         90 11072.000
173:    91,954   10.875     11,494   87.000      1,437  696.000        359 2784.000         90 11136.000
174:    91,429   10.938     11,429   87.500      1,429  700.000        357 2800.000         89 11200.000
175:    90,909   11.000     11,364   88.000      1,420  704.000        355 2816.000         89 11264.000
176:    90,395   11.063     11,299   88.500      1,412  708.000        353 2832.000         88 11328.000
177:    89,888   11.125     11,236   89.000      1,404  712.000        351 2848.000         88 11392.000
178:    89,385   11.188     11,173   89.500      1,397  716.000        349 2864.000         87 11456.000
179:    88,889   11.250     11,111   90.000      1,389  720.000        347 2880.000         87 11520.000
180:    88,398   11.312     11,050   90.500      1,381  724.000        345 2896.000         86 11584.000
181:    87,912   11.375     10,989   91.000      1,374  728.000        343 2912.000         86 11648.000
182:    87,432   11.438     10,929   91.500      1,366  732.000        342 2928.000         85 11712.000
183:    86,957   11.500     10,870   92.000      1,359  736.000        340 2944.000         85 11776.000
184:    86,486   11.563     10,811   92.500      1,351  740.000        338 2960.000         84 11840.000
185:    86,022   11.625     10,753   93.000      1,344  744.000        336 2976.000         84 11904.000
186:    85,561   11.688     10,695   93.500      1,337  748.000        334 2992.000         84 11968.000
187:    85,106   11.750     10,638   94.000      1,330  752.000        332 3008.000         83 12032.000
188:    84,656   11.813     10,582   94.500      1,323  756.000        331 3024.000         83 12096.000
189:    84,211   11.875     10,526   95.000      1,316  760.000        329 3040.000         82 12160.000
190:    83,770   11.937     10,471   95.500      1,309  764.000        327 3056.000         82 12224.000
191:    83,333   12.000     10,417   96.000      1,302  768.000        326 3072.000         81 12288.000
192:    82,902   12.063     10,363   96.500      1,295  772.000        324 3088.000         81 12352.000
193:    82,474   12.125     10,309   97.000      1,289  776.000        322 3104.000         81 12416.000
194:    82,051   12.188     10,256   97.500      1,282  780.000        321 3120.000         80 12480.000
195:    81,633   12.250     10,204   98.000      1,276  784.000        319 3136.000         80 12544.000
196:    81,218   12.313     10,152   98.500      1,269  788.000        317 3152.000         79 12608.000
197:    80,808   12.375     10,101   99.000      1,263  792.000        316 3168.000         79 12672.000
198:    80,402   12.437     10,050   99.500      1,256  796.000        314 3184.000         79 12736.000
199:    80,000   12.500     10,000  100.000      1,250  800.000        313 3200.000         78 12800.000
200:    79,602   12.562      9,950  100.500      1,244  804.000        311 3216.000         78 12864.000
201:    79,208   12.625      9,901  101.000      1,238  808.000        309 3232.000         77 12928.000
202:    78,818   12.688      9,852  101.500      1,232  812.000        308 3248.000         77 12992.000
203:    78,431   12.750      9,804  102.000      1,225  816.000        306 3264.000         77 13056.000
204:    78,049   12.813      9,756  102.500      1,220  820.000        305 3280.000         76 13120.000
205:    77,670   12.875      9,709  103.000      1,214  824.000        303 3296.000         76 13184.000
206:    77,295   12.938      9,662  103.500      1,208  828.000        302 3312.000         75 13248.000
207:    76,923   13.000      9,615  104.000      1,202  832.000        300 3328.000         75 13312.000
208:    76,555   13.062      9,569  104.500      1,196  836.000        299 3344.000         75 13376.000
209:    76,190   13.125      9,524  105.000      1,190  840.000        298 3360.000         74 13440.000
210:    75,829   13.187      9,479  105.500      1,185  844.000        296 3376.000         74 13504.000
211:    75,472   13.250      9,434  106.000      1,179  848.000        295 3392.000         74 13568.000
212:    75,117   13.313      9,390  106.500      1,174  852.000        293 3408.000         73 13632.000
213:    74,766   13.375      9,346  107.000      1,168  856.000        292 3424.000         73 13696.000
214:    74,419   13.438      9,302  107.500      1,163  860.000        291 3440.000         73 13760.000
215:    74,074   13.500      9,259  108.000      1,157  864.000        289 3456.000         72 13824.000
216:    73,733   13.563      9,217  108.500      1,152  868.000        288 3472.000         72 13888.000
217:    73,394   13.625      9,174  109.000      1,147  872.000        287 3488.000         72 13952.000
218:    73,059   13.687      9,132  109.500      1,142  876.000        285 3504.000         71 14016.000
219:    72,727   13.750      9,091  110.000      1,136  880.000        284 3520.000         71 14080.000
220:    72,398   13.812      9,050  110.500      1,131  884.000        283 3536.000         71 14144.000
221:    72,072   13.875      9,009  111.000      1,126  888.000        282 3552.000         70 14208.000
222:    71,749   13.938      8,969  111.500      1,121  892.000        280 3568.000         70 14272.000
223:    71,429   14.000      8,929  112.000      1,116  896.000        279 3584.000         70 14336.000
224:    71,111   14.063      8,889  112.500      1,111  900.000        278 3600.000         69 14400.000
225:    70,796   14.125      8,850  113.000      1,106  904.000        277 3616.000         69 14464.000
226:    70,485   14.188      8,811  113.500      1,101  908.000        275 3632.000         69 14528.000
227:    70,175   14.250      8,772  114.000      1,096  912.000        274 3648.000         69 14592.000
228:    69,869   14.312      8,734  114.500      1,092  916.000        273 3664.000         68 14656.000
229:    69,565   14.375      8,696  115.000      1,087  920.000        272 3680.000         68 14720.000
230:    69,264   14.437      8,658  115.500      1,082  924.000        271 3696.000         68 14784.000
231:    68,966   14.500      8,621  116.000      1,078  928.000        269 3712.000         67 14848.000
232:    68,670   14.563      8,584  116.500      1,073  932.000        268 3728.000         67 14912.000
233:    68,376   14.625      8,547  117.000      1,068  936.000        267 3744.000         67 14976.000
234:    68,085   14.688      8,511  117.500      1,064  940.000        266 3760.000         66 15040.000
235:    67,797   14.750      8,475  118.000      1,059  944.000        265 3776.000         66 15104.000
236:    67,511   14.813      8,439  118.500      1,055  948.000        264 3792.000         66 15168.000
237:    67,227   14.875      8,403  119.000      1,050  952.000        263 3808.000         66 15232.000
238:    66,946   14.937      8,368  119.500      1,046  956.000        262 3824.000         65 15296.000
239:    66,667   15.000      8,333  120.000      1,042  960.000        260 3840.000         65 15360.000
240:    66,390   15.062      8,299  120.500      1,037  964.000        259 3856.000         65 15424.000
241:    66,116   15.125      8,264  121.000      1,033  968.000        258 3872.000         65 15488.000
242:    65,844   15.188      8,230  121.500      1,029  972.000        257 3888.000         64 15552.000
243:    65,574   15.250      8,197  122.000      1,025  976.000        256 3904.000         64 15616.000
244:    65,306   15.313      8,163  122.500      1,020  980.000        255 3920.000         64 15680.000
245:    65,041   15.375      8,130  123.000      1,016  984.000        254 3936.000         64 15744.000
246:    64,777   15.438      8,097  123.500      1,012  988.000        253 3952.000         63 15808.000
247:    64,516   15.500      8,065  124.000      1,008  992.000        252 3968.000         63 15872.000
248:    64,257   15.562      8,032  124.500      1,004  996.000        251 3984.000         63 15936.000
249:    64,000   15.625      8,000  125.000      1,000 1000.000        250 4000.000         63 16000.000
250:    63,745   15.687      7,968  125.500        996 1004.000        249 4016.000         62 16064.000
251:    63,492   15.750      7,937  126.000        992 1008.000        248 4032.000         62 16128.000
252:    63,241   15.812      7,905  126.500        988 1012.000        247 4048.000         62 16192.000
253:    62,992   15.875      7,874  127.000        984 1016.000        246 4064.000         62 16256.000
254:    62,745   15.937      7,843  127.500        980 1020.000        245 4080.000         61 16320.000
255:    62,500   16.000      7,813  128.000        977 1024.000        244 4096.000         61 16384.000

A prescaler of one, being the finest, will not be adequate because you cannot get a frequency of 10 kHz (from the above table). In other words, dividing the Uno clock of 16 MHz by 256 only gives you a frequency of 62500 Hz (16000000 / 256).
Using a prescaler of 8 and a counter of 199 gives you 10 kHz: 16000000 / 8 / 200 = 10000. I say a counter of 199, and not 200, because the  counters are zero-relative.
This is the finest prescaler, and thus would give you the finest duty cycle control. You still only have 256 steps of duty cycle because this is an 8-bit timer. For finer control use Timer 1, which is a 16-bit timer.


text:
Which Arduino CMake Toolchain should be used?
I am working on an Arduino UNO board and I want to build my Arduino sketch with CMake.
It looks to me there is no official Arduino toolchain version to go by, and I found at least three available toolchains that can be used:

https://github.com/a9183756-gh/Arduino-CMake-Toolchain (last updated 4 years ago)
https://github.com/technyon/Arduino-CMake-Toolchain (a fork of the preceding one)
https://github.com/queezythegreat/arduino-cmake (last updated a long time ago, but referenced in this tutorial)

Which one should be used?

I've had good luck with this one, which has been updated recently and provides a solid CMake setup for building Arduino programs. Specifically, it includes toolchains for the Arduino UNO, as well as a couple of other Arduino boards.
It also includes some screenshots with instructions for how to utilize it with VSCode's CMake extension, if that is of interest to you.


text:
Can any Arduino Due pin be used for PWM?
Arduino Due has 54 pins. It says that it has 12 PWM pins. I know it uses a more powerful chip than other Arduinos.
Can the number of PWM be increased?
Can any of its pin be used for PWM?

Any number of its pins can support PWM depending on how much work you're willing to put in.

If you can explain how that would be nice

@Programmer it's a joke, the work needed includes modifying the silicon inside the microcontroller by adding the pwm hardware and adding the registers needed to control them and modifying the compiler to make use of them.

According to the manual:
"The Arduino Due supports analogWrite() on pins 2 through 13, plus pins DAC0 and DAC1. Unlike the PWM pins, DAC0 and DAC1 are Digital to Analog converters, and act as true analog outputs."
https://www.arduino.cc/en/Reference/AnalogWrite

You could do software pwm but the frequency will be several orders of magnitude less than the clock frequency.
The hardware pwm pins have a counter a register and a comparator where every tick it increments the counter, compares the value of the counter to the value in the register and setting the pin to the corresponding value.
If you need more analogue outputs then it's easier to use an external DAC module.

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


text:
Do I have to use an external power supply when connecting an ultrasonic sensor to Arduino?
This might be a very stupid question but please bear with me. So I am using an HC-SR04 Ultrasonic sensor model (5 V) and I want to connect it to Arduino Uno. Do I have to use an external power supply for the ultrasonic sensor (just like with the motors) in order to connect it to the Arduino? Or can I just use the 5 V pin?

It is a low current device so yes you can connect it to the 5V pin, also consult the datasheet for setup stuff and current draw.

From the question I assume you power your Arduino via USB in which case you don't need an external supply. The HC-SR04 draws 15 mA with is far below the specifications for USB. I did this myself some time ago:

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


text:
Which external programmers work reliably with Arduino Mega?
When looking for alternate external programmers (ISPs), I am noticing that many are not Arduino Mega 2560 compatible (e.g. Pocket AVR Programmer, USBtinyISP).
I am looking for a reliable external programmer for the Arduino Mega that is compatible with the Arduino IDE. What are my options? Currently I have been struggling with the retired ArduinoISP programmer, which doesn't look like its going to work. Does anyone have proven experience with a given programmer and a Mega?
The suggested AVR-mkII doesn't seem to be available anymore either.

I always use USBasp.

Voting to be "opinion based", basically any ICSP programmer for AVR should work. I also like the USBasp and have never had any troubles with it (even when bought for around 5$ from e-bay). It's very much of a shopping question, is very broad (since there are a lot of programmers, and ways to program) and opinion based, since everyone has his own thoughts on reliability of some programmers.

Yes, to some extent; however, I was hoping for a certain type of answer. For example, a "Use A because it offers X, Y, Z, even though it suffers from U, V, and W."

Currently the Arduino.cc page has nothing about why I should choose one programmer over the other, or even which programmers are actually compatible with their boards (it looks like most of the time the MEGA, as specifically addressed in this question, isn't compatible).

I have successfully used Arduino as ISP (not to be confused with Arduino ISP) on a Mega clone that has a funky FTDI-clone onboard, and would not let me upload bootloader through serial. This worked fine, and is cheap.

a test would be if any of those programmers mentioned about could program a big file (64KB+).
if I were you, I would look into that instead.


text:
Is it possible to use a USB camera with Arduino?
It is necessary to recognize the motion and record video live.
Update
Save enough on your memory card.
PS
Maybe I'll repeat the question, but I am not guided in English.
Sorry for my English.

An Arduino is not a powerful processor and can not do much image processing.  I doubt that there is a USB camera that could be connected to the Arduino.
There are a range of OVO cameras that can connect to the Arduino, but I don't think you will be able to record live video on an Arduino with these, where would you store the file for starters?
There is a PIXY camera system, this has its own microprocessor and interfaces with an Arduino.  It can record video and do object recognition.
http://charmedlabs.com/default/pixy-cmucam5/
Hope that helps.

It looks interesting)) How to get/buy it?

Found http://charmedlabs.com/default/where-to-order-pixy/


text:
Do I connect multiple I2C units to the microcontroler in series or parallel?
I have a project (still planning) with three I2C sensors: GPS, 3-axis gyro+accelerometer, and OLED. Do I connect SDA/SCL in series, or do I connect them in parallel?

Use the Wikipedia page on the protocol as an introduction to your learning curve on I2C. I may cite:

At the physical layer, both SCL and SDA lines are [a ...] bus design, [...]

This means that all devices connect in parallel (image from the same page, public domain):

Rp are pull-up resistors, Rs are optional series resistors. (Emphasis by me)

Connect the three I2C devices in parallel.


text:
GPS module Serial.begin value
I've disassembled a drone and found a GPS module. I want to use it. I haven't found any information about the architecture and the Serial.begin value I have to use. Could I break it if I tried different values of Serial.begin as 4800, 9600 and different types of architecture like NMEA with TinyGPS?
The module: https://www.aliexpress.us/item/3256805691773977.html
I've tried this sketch and ss.available() is constantly false, why aren't any chars available?
#include <SoftwareSerial.h>

#include <TinyGPS.h>

/* This sample code demonstrates the normal use of a TinyGPS object.
   It requires the use of SoftwareSerial, and assumes that you have a
   4800-baud serial GPS device hooked up on pins 4(rx) and 3(tx).
*/

TinyGPS gps;
SoftwareSerial ss(4, 3);

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

  Serial.print("Simple TinyGPS library v. "); Serial.println(TinyGPS::library_version());
  Serial.println("by Mikal Hart");
  Serial.println();
}

void loop()
{
  bool newData = false;
  unsigned long chars;
  unsigned short sentences, failed;

  // For one second we parse GPS data and report some key values
  for (unsigned long start = millis(); millis() - start < 1000;)
  {
    while (ss.available())
    {
      char c = ss.read();
      // Serial.write(c); // uncomment this line if you want to see the GPS data flowing
      if (gps.encode(c)) // Did a new valid sentence come in?
        newData = true;
    }
  }

  if (newData)
  {
    float flat, flon;
    unsigned long age;
    gps.f_get_position(&flat, &flon, &age);
    Serial.print("LAT=");
    Serial.print(flat == TinyGPS::GPS_INVALID_F_ANGLE ? 0.0 : flat, 6);
    Serial.print(" LON=");
    Serial.print(flon == TinyGPS::GPS_INVALID_F_ANGLE ? 0.0 : flon, 6);
    Serial.print(" SAT=");
    Serial.print(gps.satellites() == TinyGPS::GPS_INVALID_SATELLITES ? 0 : gps.satellites());
    Serial.print(" PREC=");
    Serial.print(gps.hdop() == TinyGPS::GPS_INVALID_HDOP ? 0 : gps.hdop());
  }

  gps.stats(&chars, &sentences, &failed);
  Serial.print(" CHARS=");
  Serial.print(chars);
  Serial.print(" SENTENCES=");
  Serial.print(sentences);
  Serial.print(" CSUM ERR=");
  Serial.println(failed);
  if (chars == 0)
    Serial.println("** No characters received from GPS: check wiring **");
}

No, the module will not break because of an incorrect baudrate.

thanks, what about the protocol ?

What do you mean? Do you want an explanation of the modules protocol? We also can only google for the datasheet of the module. Without a part number that is also impossible. Though such modules often send human readable data (in ASCII format) over serial. So you can look at the data in the Serial Monitor and check, how to read it. Thats something, that you need to test yourself (we don't have your module)

Probably a nice clear picture of this GPS module would help. FWIW, the GPS modules I have worked with start out running at either 9600 or 15200. If you want to learn about GPS it may be better to get a known good GPS module from the likes of sparkfun or adafruit.  Either supplier/manufacturer have good web presence, support and community.  All good assets for people w/lots of questions.

BTW, serial protocols such as RS232 have been around likely before you were born (no offense). Back when a few things had to be everything to everybody.  It's been called "the standard that isn't". That said, the major knobs are speed, number of data bits, number of stop bits and parity. You should be able to fiddle w/all that w/little concern about damaging what is connected. The thing you need to worry about: True RS232 swings from -12 Volts to 12 Volts. That will certainly be cause for alarm. But most Arduinos will pump out RS232 like pulses that swing from 0 to 5 Volts or 0 to 3 Volts.

ok thanks, last thing, the gps module is connected correctly but no data is available with the SoftwareSerial library, i've modified the question why that happens, should i pass some data to the tx pin of the module before receiving data at the rx?

How did you connect the module? Usually for serial connections, you would connect the Arduino's RX pin to the module's TX pin and vice versa.

i've done so and it didn't worked it is possible that i have to pass some data at the module before he can start

The GPS module you link to is UART-I2C dual mode. You switch between these 2 modes by (de)soldering resistors. Check first which mode the module is in.
Most GPS these days are in 9600 baud, when in UART mode. Try that too.


text:
Declaration of global variables in separate file: compiler conflict
So I have:
1/ My myapp.ino file, that includes src.h (implemented in src.cpp). Compiled for Arduino Uno.
2/ I also have a unit-tests.cpp file that is meant to test functions in src.cpp. Compiled for desktop/MacOS.
I don't understand where to declare global variables. They have to be accessed by those three files (I know it's not 100% good practice but it's a simple app).
Simplified example:
src.h
#ifndef CHAOS_SRC_H
#define CHAOS_SRC_H

extern float min_delta;
extern float max_delta;
extern float min_val;
extern float max_val;
extern float rescale_power;

#endif

src.cpp
#include "src.h"

//float min_delta;
//float max_delta;
//float min_val;
//float max_val;
float rescale_power;

myapp.ino
#include "src.h"

float presets[4][5] =  {
  // MIN_DELTA, MAX_DELTA, MIN_VAL, MAX_VAL
  {0, 500, 0, 30, 1}, // Old tape
  {200, 2000, 0, 255, 1}, // Broken tape
  {0, 500, 90, 100, 3}, // New broken tape (delay time at ~ min)
  {0, 100, 90, 140, 3}, //
};

float min_delta = presets[PRESET][0];
float max_delta = presets[PRESET][1];
float min_val = presets[PRESET][2];
float max_val = presets[PRESET][3];
float rescale_power = presets[PRESET][4];

unit-tests.cpp
#include "src.h"

int main()
{
}

When I compile myapp.ino for Arduino, the compiler complains rescale_power has multiple definitions. So I remove it in src.cpp and it works.
But then, when I compile unit-tests.cpp for desktop, that one compiler complains about Undefined symbols for architecture x86_64:  "_rescale_power".
Re-adding it solves it.
And so on.
What is the way to go please? Any kind of logic?

Why downvote please?

Not sure, but recently questions have been downvoted than usual.. The question is up for closure, probably on the grounds that it's more of a C++ question than an Arduino one. I can't tell which thing you're confused about. Error will point out each of the multiple definitions. You've been using extern. Do you understand the significance of extern in the way that you're using it?

Isn't it the only way to make the variable accessible from outside?

And Arduino and g++ compilers and not reacting similarly, so I'm guessing there must be something specific about Arduino.

Defining a variable multiple times as you have in the shown code will break g++ (or any other c++ compiler for that matter) whether it is launched from the build process or from a more traditional non-Arduino build system. To be clear, I am only telling you that this the wrong tree to bark up. Check Edgar Bonet's answer again, with an understanding that extern will cause variables to be only declared and not also defined as they are by default.

When you have a header/implementation pair of files, the general rule is
that the implementation defines everything that the header declares.
Thus, you keep the definition of rescale_power in src.cpp. Since every
variable should be defined only once, you have to remove the definition
from myapp.ino.
If for some reason src.cpp cannot know the initial value you would want
to give to rescale_power, then live it default-initialized, and assign
the value you want in myapp.ino:
void setup() {
    rescale_power = presets[PRESET][4];
}

Edit: In a comment, you wrote:

I don't get why I can't put rescale_power = 4 in myapp.ino outside
a function ?

Because it's an assignment. Assignments are statements: they are
executed at run time, and can only be written within functions. For
reference, here are the syntaxes for a declaration, a definition and an
assignment:
// Declaration:
extern float rescale_power;

// Definitions:
float rescale_power;      // implicitly zero-initialized
float rescale_power = 2;  // with explicit initialization

// Assignment:
rescale_power = 4;

Thanks for your answer. I removed the declaration from everywhere except src.php. It works for unit-tests.cpp ; but it doesn't work for myapp.ino: error: 'rescale_power' was not declared in this scope.

@theredled: Did you keep the declaration of rescale_power in src.h? Is this file still included in myapp.ino?

No, I removed it. Now I have a declaration in src.h extern float rescale_power;, a definition in src.cpp float rescale_power = 2;.
Now it works! But I don't get why I can't put rescale_power = 4 in myapp.ino outside a function ?

Edited----------


text:
Trying to compile code on UNO using ccs811 and LCD
Complete newbie here. I'm really hoping to get something like this to work, and then learn from it. I have a generic UNO board and an LCD/CCS811 on order. I'm trying to do exactly this: (https://create.arduino.cc/projecthub/partsoven/air-quality-monitor-live-display-ad028a) but I'm receiving the following error upon compiling the code. I believe I have all the libraries installed, etc.. but for some reason, I can't get this sketch to upload.. sorry for the crap formatting on this, the {} never works for me and I can't space or indent past a certain point for some reason.... sorry for the long post.
Arduino: 1.8.1 (Windows 7), Board: "Arduino/Genuino Uno"

C:\Users\Guy\Documents\Arduino\sketch_jan25a\sketch_jan25a.ino:9:32:
warning: invalid conversion from 'int' to 't_backlighPol' [-fpermissive]

LiquidCrystal_I2C lcd(0x3F,16,2);  // set the LCD address to 0x3F for a 16 chars and 2 line display

                                ^

 In file included from
 C:\Users\Guy\Documents\Arduino\sketch_jan25a\sketch_jan25a.ino:5:0:
 C:\Users\Guy\Documents\Arduino\libraries\jm_LiquidCrystal_I2C/LiquidCrystal_I2C.h:55:2: note: initializing argument 3 of 'LiquidCrystal_I2C::LiquidCrystal_I2C(uint8_t, uint8_t, t_backlighPol)'

  LiquidCrystal_I2C (uint8_t lcd_Addr, uint8_t backlighPin, t_backlighPol pol);

  ^

libraries\jm_Wire\jm_Wire.cpp.o (symbol from plugin): In function `TwoWire::available()':

(.text+0x0): multiple definition of `TwoWire::available()'

libraries\Wire\Wire.cpp.o (symbol from plugin):(.text+0x0): first defined here

libraries\jm_Wire\jm_Wire.cpp.o (symbol from plugin): In function `TwoWire::available()':

(.text+0x0): multiple definition of `TwoWire::rxBufferLength'

libraries\Wire\Wire.cpp.o (symbol from plugin):(.text+0x0): first defined here

libraries\jm_Wire\jm_Wire.cpp.o (symbol from plugin): In function `TwoWire::available()':

(.text+0x0): multiple definition of `TwoWire::rxBufferIndex'

libraries\Wire\Wire.cpp.o (symbol from plugin):(.text+0x0): first defined here

libraries\jm_Wire\jm_Wire.cpp.o (symbol from plugin): In function `TwoWire::available()':

(.text+0x0): multiple definition of `TwoWire::read()'

libraries\Wire\Wire.cpp.o (symbol from plugin):(.text+0x0): first defined here

libraries\jm_Wire\jm_Wire.cpp.o (symbol from plugin): In function `TwoWire::available()':

(.text+0x0): multiple definition of `TwoWire::rxBuffer'

libraries\Wire\Wire.cpp.o (symbol from plugin):(.text+0x0): first defined here

libraries\jm_Wire\jm_Wire.cpp.o (symbol from plugin): In function `TwoWire::available()':

(.text+0x0): multiple definition of `TwoWire::peek()'

libraries\Wire\Wire.cpp.o (symbol from plugin):(.text+0x0): first defined here

libraries\jm_Wire\jm_Wire.cpp.o (symbol from plugin): In function `TwoWire::available()':

(.text+0x0): multiple definition of `TwoWire::flush()'

libraries\Wire\Wire.cpp.o (symbol from plugin):(.text+0x0): first defined here

libraries\jm_Wire\jm_Wire.cpp.o (symbol from plugin): In function `TwoWire::available()':

(.text+0x0): multiple definition of `TwoWire::onReceiveService(unsigned char*, int)'

libraries\Wire\Wire.cpp.o (symbol from plugin):(.text+0x0): first defined here

libraries\jm_Wire\jm_Wire.cpp.o (symbol from plugin): In function `TwoWire::available()':

(.text+0x0): multiple definition of `TwoWire::user_onReceive'

libraries\Wire\Wire.cpp.o (symbol from plugin):(.text+0x0): first defined here

libraries\jm_Wire\jm_Wire.cpp.o (symbol from plugin): In function `TwoWire::available()':

(.text+0x0): multiple definition of `TwoWire::onRequestService()'

libraries\Wire\Wire.cpp.o (symbol from plugin):(.text+0x0): first defined here

libraries\jm_Wire\jm_Wire.cpp.o (symbol from plugin): In function `TwoWire::available()':

(.text+0x0): multiple definition of `TwoWire::user_onRequest'

libraries\Wire\Wire.cpp.o (symbol from plugin):(.text+0x0): first defined here

libraries\jm_Wire\jm_Wire.cpp.o (symbol from plugin): In function `TwoWire::available()':

(.text+0x0): multiple definition of `TwoWire::txBufferIndex'

libraries\Wire\Wire.cpp.o (symbol from plugin):(.text+0x0): first defined here

libraries\jm_Wire\jm_Wire.cpp.o (symbol from plugin): In function `TwoWire::available()':

(.text+0x0): multiple definition of `TwoWire::txBufferLength'

libraries\Wire\Wire.cpp.o (symbol from plugin):(.text+0x0): first defined here

libraries\jm_Wire\jm_Wire.cpp.o (symbol from plugin): In function `TwoWire::available()':

(.text+0x0): multiple definition of `TwoWire::write(unsigned char const*, unsigned int)'

libraries\Wire\Wire.cpp.o (symbol from plugin):(.text+0x0): first defined here

libraries\jm_Wire\jm_Wire.cpp.o (symbol from plugin): In function `TwoWire::available()':

(.text+0x0): multiple definition of `TwoWire::transmitting'

libraries\Wire\Wire.cpp.o (symbol from plugin):(.text+0x0): first defined here

libraries\jm_Wire\jm_Wire.cpp.o (symbol from plugin): In function `TwoWire::available()':

(.text+0x0): multiple definition of `TwoWire::write(unsigned char)'

libraries\Wire\Wire.cpp.o (symbol from plugin):(.text+0x0): first defined here

libraries\jm_Wire\jm_Wire.cpp.o (symbol from plugin): In function `TwoWire::available()':

(.text+0x0): multiple definition of `TwoWire::txBuffer'

libraries\Wire\Wire.cpp.o (symbol from plugin):(.text+0x0): first defined here

libraries\jm_Wire\jm_Wire.cpp.o (symbol from plugin): In function `TwoWire::available()':

(.text+0x0): multiple definition of `TwoWire::TwoWire()'

libraries\Wire\Wire.cpp.o (symbol from plugin):(.text+0x0): first defined here

libraries\jm_Wire\jm_Wire.cpp.o (symbol from plugin): In function `TwoWire::available()':

(.text+0x0): multiple definition of `TwoWire::TwoWire()'

libraries\Wire\Wire.cpp.o (symbol from plugin):(.text+0x0): first defined here

libraries\jm_Wire\jm_Wire.cpp.o (symbol from plugin): In function `TwoWire::available()':

(.text+0x0): multiple definition of `Wire'

libraries\Wire\Wire.cpp.o (symbol from plugin):(.text+0x0): first defined here

libraries\jm_Wire\jm_Wire.cpp.o (symbol from plugin): In function `TwoWire::available()':

(.text+0x0): multiple definition of `TwoWire::begin()'

libraries\Wire\Wire.cpp.o (symbol from plugin):(.text+0x0): first defined here

libraries\jm_Wire\jm_Wire.cpp.o (symbol from plugin): In function `TwoWire::available()':

(.text+0x0): multiple definition of `TwoWire::begin(unsigned char)'

libraries\Wire\Wire.cpp.o (symbol from plugin):(.text+0x0): first defined here

libraries\jm_Wire\jm_Wire.cpp.o (symbol from plugin): In function `TwoWire::available()':

(.text+0x0): multiple definition of `TwoWire::begin(int)'

libraries\Wire\Wire.cpp.o (symbol from plugin):(.text+0x0): first defined here

libraries\jm_Wire\jm_Wire.cpp.o (symbol from plugin): In function `TwoWire::available()':

(.text+0x0): multiple definition of `TwoWire::end()'

libraries\Wire\Wire.cpp.o (symbol from plugin):(.text+0x0): first defined here

libraries\jm_Wire\jm_Wire.cpp.o (symbol from plugin): In function `TwoWire::available()':

(.text+0x0): multiple definition of `TwoWire::setClock(unsigned long)'

libraries\Wire\Wire.cpp.o (symbol from plugin):(.text+0x0): first defined here

libraries\jm_Wire\jm_Wire.cpp.o (symbol from plugin): In function `TwoWire::available()':

(.text+0x0): multiple definition of `TwoWire::beginTransmission(unsigned char)'

libraries\Wire\Wire.cpp.o (symbol from plugin):(.text+0x0): first defined here

libraries\jm_Wire\jm_Wire.cpp.o (symbol from plugin): In function `TwoWire::available()':

(.text+0x0): multiple definition of `TwoWire::txAddress'

libraries\Wire\Wire.cpp.o (symbol from plugin):(.text+0x0): first defined here

libraries\jm_Wire\jm_Wire.cpp.o (symbol from plugin): In function `TwoWire::available()':

(.text+0x0): multiple definition of `TwoWire::beginTransmission(int)'

libraries\Wire\Wire.cpp.o (symbol from plugin):(.text+0x0): first defined here

libraries\jm_Wire\jm_Wire.cpp.o (symbol from plugin): In function `TwoWire::available()':

(.text+0x0): multiple definition of `TwoWire::endTransmission(unsigned char)'

libraries\Wire\Wire.cpp.o (symbol from plugin):(.text+0x0): first defined here

libraries\jm_Wire\jm_Wire.cpp.o (symbol from plugin): In function `TwoWire::available()':

(.text+0x0): multiple definition of `TwoWire::requestFrom(unsigned char, unsigned char, unsigned long, unsigned char, unsigned char)'

libraries\Wire\Wire.cpp.o (symbol from plugin):(.text+0x0): first defined here

libraries\jm_Wire\jm_Wire.cpp.o (symbol from plugin): In function `TwoWire::available()':

(.text+0x0): multiple definition of `TwoWire::requestFrom(unsigned char, unsigned char, unsigned char)'

libraries\Wire\Wire.cpp.o (symbol from plugin):(.text+0x0): first defined here

libraries\jm_Wire\jm_Wire.cpp.o (symbol from plugin): In function `TwoWire::available()':

(.text+0x0): multiple definition of `TwoWire::requestFrom(unsigned char, unsigned char)'

libraries\Wire\Wire.cpp.o (symbol from plugin):(.text+0x0): first defined here

libraries\jm_Wire\jm_Wire.cpp.o (symbol from plugin): In function `TwoWire::available()':

(.text+0x0): multiple definition of `TwoWire::requestFrom(int, int)'

libraries\Wire\Wire.cpp.o (symbol from plugin):(.text+0x0): first defined here

libraries\jm_Wire\jm_Wire.cpp.o (symbol from plugin): In function `TwoWire::available()':

(.text+0x0): multiple definition of `TwoWire::requestFrom(int, int, int)'

libraries\Wire\Wire.cpp.o (symbol from plugin):(.text+0x0): first defined here

libraries\jm_Wire\jm_Wire.cpp.o (symbol from plugin): In function `TwoWire::available()':

(.text+0x0): multiple definition of `TwoWire::endTransmission()'

libraries\Wire\Wire.cpp.o (symbol from plugin):(.text+0x0): first defined here

libraries\jm_Wire\jm_Wire.cpp.o (symbol from plugin): In function `TwoWire::available()':

(.text+0x0): multiple definition of `TwoWire::onReceive(void (*)(int))'

libraries\Wire\Wire.cpp.o (symbol from plugin):(.text+0x0): first defined here

libraries\jm_Wire\jm_Wire.cpp.o (symbol from plugin): In function `TwoWire::available()':

(.text+0x0): multiple definition of `TwoWire::onRequest(void (*)())'

libraries\Wire\Wire.cpp.o (symbol from plugin):(.text+0x0): first defined here

libraries\jm_Wire\utility\jm_twi.c.o (symbol from plugin): In function `twi_readFrom':

(.text+0x0): multiple definition of `twi_readFrom'

libraries\Wire\utility\twi.c.o (symbol from plugin):(.text+0x0): first defined here

libraries\jm_Wire\utility\jm_twi.c.o (symbol from plugin): In function `twi_readFrom':

(.text+0x0): multiple definition of `twi_writeTo'

libraries\Wire\utility\twi.c.o (symbol from plugin):(.text+0x0): first defined here

libraries\jm_Wire\utility\jm_twi.c.o (symbol from plugin): In function `twi_readFrom':

(.text+0x0): multiple definition of `twi_transmit'

libraries\Wire\utility\twi.c.o (symbol from plugin):(.text+0x0): first defined here

libraries\jm_Wire\utility\jm_twi.c.o (symbol from plugin): In function `twi_readFrom':

(.text+0x0): multiple definition of `twi_init'

libraries\Wire\utility\twi.c.o (symbol from plugin):(.text+0x0): first defined here

libraries\jm_Wire\utility\jm_twi.c.o (symbol from plugin): In function `twi_readFrom':

(.text+0x0): multiple definition of `twi_disable'

libraries\Wire\utility\twi.c.o (symbol from plugin):(.text+0x0): first defined here

libraries\jm_Wire\utility\jm_twi.c.o (symbol from plugin): In function `twi_readFrom':

(.text+0x0): multiple definition of `twi_setAddress'

libraries\Wire\utility\twi.c.o (symbol from plugin):(.text+0x0): first defined here

libraries\jm_Wire\utility\jm_twi.c.o (symbol from plugin): In function `twi_readFrom':

(.text+0x0): multiple definition of `twi_setFrequency'

libraries\Wire\utility\twi.c.o (symbol from plugin):(.text+0x0): first defined here

libraries\jm_Wire\utility\jm_twi.c.o (symbol from plugin): In function `twi_readFrom':

(.text+0x0): multiple definition of `twi_attachSlaveRxEvent'

libraries\Wire\utility\twi.c.o (symbol from plugin):(.text+0x0): first defined here

libraries\jm_Wire\utility\jm_twi.c.o (symbol from plugin): In function `twi_readFrom':

(.text+0x0): multiple definition of `twi_attachSlaveTxEvent'

libraries\Wire\utility\twi.c.o (symbol from plugin):(.text+0x0): first defined here

libraries\jm_Wire\utility\jm_twi.c.o (symbol from plugin): In function `twi_readFrom':

(.text+0x0): multiple definition of `twi_reply'

libraries\Wire\utility\twi.c.o (symbol from plugin):(.text+0x0): first defined here

libraries\jm_Wire\utility\jm_twi.c.o (symbol from plugin): In function `twi_readFrom':

(.text+0x0): multiple definition of `twi_stop'

libraries\Wire\utility\twi.c.o (symbol from plugin):(.text+0x0): first defined here

libraries\jm_Wire\utility\jm_twi.c.o (symbol from plugin): In function `twi_readFrom':

(.text+0x0): multiple definition of `twi_releaseBus'

libraries\Wire\utility\twi.c.o (symbol from plugin):(.text+0x0): first defined here

libraries\jm_Wire\utility\jm_twi.c.o (symbol from plugin): In function `twi_readFrom':

(.text+0x0): multiple definition of `__vector_24'

libraries\Wire\utility\twi.c.o (symbol from plugin):(.text+0x0): first defined here

collect2.exe: error: ld returned 1 exit status

exit status 1
Error compiling for board Arduino/Genuino Uno.

This report would have more information with "Show verbose output during compilation" option enabled in File -> Preferences.

Below is the sketch I'm attempting to upload:
/*
 * Displays Sparkfun CCS811 data on a Serial enabled LCD sent over I2C.
 */
#include <Wire.h>
#include <LiquidCrystal_I2C.h>

#define I2C_ADDR 0x3F
LiquidCrystal_I2C lcd(0x3F,16,2);  // set the LCD address to 0x3F for a 16 chars and 2 line display

#include "SparkFunCCS811.h"

#define CCS811_ADDR 0x5B // CCS811 Default I2C Address
//#define CCS811_ADDR 0x5A //Alternate I2C Address

CCS811 mySensor(CCS811_ADDR);

void setup()
{
  lcd.init();                      // initialize the lcd
  lcd.backlight();                //turn on backlight
  Serial.begin(9600);

}

void loop()
{
  //Check to see if data is ready with .dataAvailable()
  if (mySensor.dataAvailable())
  {
    //If so, have the sensor read and calculate the results.
    //Get them later
    mySensor.readAlgorithmResults();

  }

  delay(100); //Don't spam the I2C bus

    // clear the screen
    lcd.clear();
    // go to first row and send CO2 data to the display
    lcd.setCursor(0,0);
    lcd.print("CO2 [");
    lcd.print(mySensor.getCO2());
    lcd.print("] ppb");
      // go to second row and send tVOC data to the display
    lcd.setCursor(0,1);
    lcd.print("tVOC [");
    lcd.print(mySensor.getTVOC());
    lcd.print("] ppm");

}

The first error seems, as if the library wants another parameter type for it's constructor. For more help you should provide your code and the library you used for this (when not buildin of the Arduino IDE please provide a link)

This worked for you? I'll have to see what version of Arduino I'm running.

I am assuming you are using this library, which is the only one I can find using that t_backlighPol datatype
You need to set the I2C address when you instantiate the object:
LiquidCrystal_I2C lcd(0x38);  // Set the LCD I2C address

And define the LCD size when you call the begin() function. Note that init() is a private function of the object:
lcd.begin(16,2);               // initialize the lcd

Thank you, Jose. I will change these two lines when I get home and see what happens!


text:
Running python script using Arduino
I am trying to use Process.h library to run a shell command. Here is my code. I am using Arduino Uno.
#include <Process.h>
#include <Bridge.h>

void setup() {
  // Initialize Bridge
  //Bridge.begin(115200);

  // Initialize Serial
  Serial.begin(115200);

  // Wait until a Serial Monitor is connected.
  while (!Serial);

  // run various example processes
  runPythonFunction();
}

void loop() {
  // Do nothing here.
}

void runPythonFunction() {

  Process p;        // Create a process and call it "p"
  //p.begin("/usr/bin/python /home/kairos/Arduino/codes/sketch_jan26a/tweet.py");
  p.runShellCommandAsynchronously("/usr/bin/python -U /path/to/tweet.py");      // Run the process and wait for its termination
  //p.run();
  // Print command output on the SerialUSB.
  // A process output can be read with the stream methods
  while(p.available() > 0) {
     char c = p.read();
    Serial.print(c);
  }
  // Ensure the last bit of data is sent.
  Serial.flush();
  delay(300000);
}

If I do not comment the Bridge.begin() line, then in monitor display reverse question marks are displayed. And after commenting that, I am getting some garbage on the serial monitor. Also, my python script makes a new file in the same directory, which runs fine if I run it using a terminal. But if I run it using Arduino code, I am not able to see that new file being generated.
Even using p.begin() and p.run()it does not run. Nor using p.runShellCommandAsynchronously().
So how can I run that python script?

Do you have a Yun shield on your Uno?

I am actually using SparkFun Redboard, same as this https://www.robotshop.com/en/sparkfun-inventors-kit-v40.html?gclid=EAIaIQobChMIx8S-n9f42AIVS7jACh16PgRVEAQYAyABEgJc5fD_BwE

Do you have a Yun shield plugged into your SparkFun Redboard?

No, I have directly connected the board to the computer.

Was your intention to make your Arduino trigger the execution of a Python script which is on your computer?

yes, that was what I wanted to

The Uno cannot run python.
The Bridge library is intended for communication either between the two MCUs of the Yun, or between an Arduino board and the MCU on a Yun shield.
It is literally a Bridge between the two systems - Arduino and the Linux system in the Yun.

Is there any way I can run a python script?

I knew you were going to ask that. Buy a Yun.

Don't buy a Yún, it is an endless source of troubles. Buy a Raspberry Pi, and you have a full linux operating system for less money.

Tried it with Rpi, completed it in 20min, the same task that I was trying from two days #hackathon


text:
Send custom 802.11 data frame with ESP8266
I would like to send raw 802.11 data frames in order to transmit pictures with the ESP8266.
I have the Espressif SDK 1.3 and so far I have tried to construct a packet and send it with wifi_send_pkt_freedom, but it didn't work. I cannot pick it up with wireshark or airodump-ng on Kali.
here is the code:
wifi_set_channel(5);

uint8_t packetH[36]={
0x80, 0x00, //Frame Control
0x00, 0x00, //Duration
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, //Receiver Address= Destination Address
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, //Transmitter Address= Source Address
0x01, 0x02, 0x03, 0x04, 0x05, 0x06, //BSSID
0x00, 0x00,                         //Sequence control
0x01, 0x02, 0x02, 0x03,0x03,0x03,0x04,0x04, //Body
0x05, 0x03, 0x02, 0x01 //FCS
};

wifi_send_pkt_freedom(packetH,sizeof(packetH),0);

For testing I just wanted to send some numbers in the Frame body, but later it should send pictures. The goal is to receive unidirectional video transmittion. One ESP8266 should send and the other one should receive. Both have their wireless card in monitor mode.
My guess is that the packet construction is complete wrong. Can someone help me understand how to "build" a proper packet?

For a bigger exposure on your good question I'd recommend you to post this question on Espressif's esp8266 forum at https://bbs.espressif.com/ instead. Also, maybe look at https://github.com/pulkin/esp8266-injection-example .

Thank you, thats a good idea. I have already looked at that example but I cannot find a way to insert data frames

Why do you think you want to craft custom frames to do this? What's wrong with a normal higher level protocol, like UDP?

I think this is what CNLohr did in his latest video. He's using this SDK

Wow CNLohr has really interesting projects. UDP is also a good option!