text:
How to remove the sketch for the LCD and retaining the sketch for the MPU6050?
I just got this from the internet and I only want to use the sketch for the MPU6050. Can someone help me to remove the code for the LCD? I'm sorry, I'm just noob when it comes to programming.
Here is my source: Earthquake Detector using Arduino and MPU-6050
Here is the sketch:
#include <LiquidCrystal.h>

#include <Wire.h>

#include <MPU6050.h>

#define minval -5

#define maxval 3

MPU6050 mpu;

LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

void setup()

{   lcd.begin(16, 2);

Serial.begin(115200);

pinMode(7,OUTPUT);

pinMode(8,OUTPUT);

lcd.print("   EarthQuake ");

lcd.setCursor(0, 1);

lcd.print("   Detector");

delay (2000);

lcd.clear();

// Initialize MPU6050

Serial.println("Initialize MPU6050");

while(!mpu.begin(MPU6050_SCALE_2000DPS, MPU6050_RANGE_2G))

{ Serial.println("Could not find a valid MPU6050 sensor, check wiring!");

delay(500);}

mpu.setThreshold(3);

// Check settings

checkSettings();

}

void checkSettings()

{

Serial.println();

Serial.print(" * Sleep Mode:        ");

Serial.println(mpu.getSleepEnabled() ? "Enabled" : "Disabled");

Serial.print(" * Clock Source:      ");

switch(mpu.getClockSource())

{case MPU6050_CLOCK_KEEP_RESET:     Serial.println("Stops the clock and
keeps the timing generator in reset"); break;

case MPU6050_CLOCK_EXTERNAL_19MHZ: Serial.println("PLL with external
19.2MHz reference"); break;

case MPU6050_CLOCK_EXTERNAL_32KHZ: Serial.println("PLL with external
32.768kHz reference"); break;

case MPU6050_CLOCK_PLL_ZGYRO:      Serial.println("PLL with Z axis
gyroscope reference"); break;

case MPU6050_CLOCK_PLL_YGYRO:      Serial.println("PLL with Y axis
gyroscope reference"); break;

case MPU6050_CLOCK_PLL_XGYRO:      Serial.println("PLL with X axis
gyroscope reference"); break;

case MPU6050_CLOCK_INTERNAL_8MHZ:  Serial.println("Internal 8MHz
oscillator"); break;

}

Serial.print(" * Gyroscope:         ");

switch(mpu.getScale())

{case MPU6050_SCALE_2000DPS:        Serial.println("2000 dps"); break;

case MPU6050_SCALE_1000DPS:        Serial.println("1000 dps"); break;

case MPU6050_SCALE_500DPS:         Serial.println("500 dps"); break;

case MPU6050_SCALE_250DPS:         Serial.println("250 dps"); break:}

Serial.print(" * Gyroscope offsets: ");

Serial.print(mpu.getGyroOffsetX());

Serial.print(" / ");

Serial.print(mpu.getGyroOffsetY());

Serial.print(" / ");

Serial.println(mpu.getGyroOffsetZ());

Serial.println();}

void loop()

{   Vector rawGyro = mpu.readRawGyro();

Vector normGyro = mpu.readNormalizeGyro();

Serial.print(" Xraw = ");

Serial.print(rawGyro.XAxis);

Serial.print(" Yraw = ");

Serial.print(rawGyro.YAxis);

Serial.print(" Zraw = ");

Serial.println(rawGyro.ZAxis);

if(normGyro.XAxis > maxval || normGyro.XAxis < minval && normGyro.YAxis >
maxval || normGyro.YAxis  < minval && normGyro.ZAxis > maxval ||
normGyro.ZAxis  < minval)

{ digitalWrite(7,HIGH);

digitalWrite(8,HIGH);

delay(300);

digitalWrite(7,HIGH);

digitalWrite(8,HIGH);

delay(300);

lcd.clear();

lcd.print("***EarthQuake***");

delay (1000);

lcd.clear();}

else{digitalWrite(7,LOW);

digitalWrite(8,LOW);}

Serial.print(" Xnorm = ");

Serial.print(normGyro.XAxis);

Serial.print(" Ynorm = ");

Serial.print(normGyro.YAxis);

Serial.print(" Znorm = ");

Serial.println(normGyro.ZAxis);

delay(10);}

Delete all the lines that have "lcd" in them?

As Majenko states, carefully remove all lines with the lcd object in them. Due to the extremely poor formatting and indentation of the code, if you aren't careful you could lose some important syntax, such as the { and }.
Also, there is no need for the LiquidCrystal header file.
In addition, there is a typo in the posted code (it is beyond me why the author would post uncompilable (and hence untested) code), in this line:
case MPU6050_SCALE_250DPS:         Serial.println("250 dps"); break:}

Here is the code with the lcd related lines stripped out, correctly formatted and indented, with the typo fixed:
#include <Wire.h>
#include <MPU6050.h>

#define minval -5
#define maxval 3

MPU6050 mpu;

void setup()
{
  Serial.begin(115200);
  pinMode(7,OUTPUT);
  pinMode(8,OUTPUT);

  delay (2000);

  // Initialize MPU6050
  Serial.println("Initialize MPU6050");

  while(!mpu.begin(MPU6050_SCALE_2000DPS, MPU6050_RANGE_2G))
  {
    Serial.println("Could not find a valid MPU6050 sensor, check wiring!");
    delay(500);
  }

  mpu.setThreshold(3);
  // Check settings
  checkSettings();
}

void checkSettings()
{
  Serial.println();
  Serial.print(" * Sleep Mode:        ");
  Serial.println(mpu.getSleepEnabled() ? "Enabled" : "Disabled");
  Serial.print(" * Clock Source:      ");
  switch(mpu.getClockSource())
  {
    case MPU6050_CLOCK_KEEP_RESET:
      Serial.println("Stops the clock and keeps the timing generator in reset");
      break;
    case MPU6050_CLOCK_EXTERNAL_19MHZ:
      Serial.println("PLL with external 19.2MHz reference");
      break;
    case MPU6050_CLOCK_EXTERNAL_32KHZ:
      Serial.println("PLL with external 32.768kHz reference");
      break;
    case MPU6050_CLOCK_PLL_ZGYRO:
      Serial.println("PLL with Z axis gyroscope reference");
      break;
    case MPU6050_CLOCK_PLL_YGYRO:
      Serial.println("PLL with Y axis gyroscope reference");
      break;
    case MPU6050_CLOCK_PLL_XGYRO:
      Serial.println("PLL with X axis gyroscope reference");
      break;
    case MPU6050_CLOCK_INTERNAL_8MHZ:
      Serial.println("Internal 8MHz oscillator");
      break;
  }

  Serial.print(" * Gyroscope:         ");
  switch(mpu.getScale())
  {
    case MPU6050_SCALE_2000DPS:
      Serial.println("2000 dps");
      break;
    case MPU6050_SCALE_1000DPS:
      Serial.println("1000 dps");
      break;
    case MPU6050_SCALE_500DPS:
       Serial.println("500 dps");
       break;
    case MPU6050_SCALE_250DPS:
       Serial.println("250 dps");
       break;
  }

  Serial.print(" * Gyroscope offsets: ");
  Serial.print(mpu.getGyroOffsetX());
  Serial.print(" / ");
  Serial.print(mpu.getGyroOffsetY());
  Serial.print(" / ");
  Serial.println(mpu.getGyroOffsetZ());
  Serial.println();
}

void loop()
{
  Vector rawGyro = mpu.readRawGyro();
  Vector normGyro = mpu.readNormalizeGyro();
  Serial.print(" Xraw = ");
  Serial.print(rawGyro.XAxis);
  Serial.print(" Yraw = ");
  Serial.print(rawGyro.YAxis);
  Serial.print(" Zraw = ");
  Serial.println(rawGyro.ZAxis);

  if (normGyro.XAxis > maxval ||
      normGyro.XAxis < minval &&
      normGyro.YAxis > maxval ||
      normGyro.YAxis < minval &&
      normGyro.ZAxis > maxval ||
      normGyro.ZAxis < minval)
  {
    digitalWrite(7,HIGH);
    digitalWrite(8,HIGH);
    delay(300);
    digitalWrite(7,HIGH);
    digitalWrite(8,HIGH);
    delay(300);
    delay (1000);
  }
  else
  {
    digitalWrite(7,LOW);
    digitalWrite(8,LOW);
  }
  Serial.print(" Xnorm = ");
  Serial.print(normGyro.XAxis);
  Serial.print(" Ynorm = ");
  Serial.print(normGyro.YAxis);
  Serial.print(" Znorm = ");
  Serial.println(normGyro.ZAxis);
  delay(10);
}

The page that you got your code from does not specify which MPU6050 library to use. It is not the library by Jeff Rowberg, as linked to from the Arduino Playground, MPU-6050 Accelerometer + Gyro. It is in fact this library, MPU6050 Triple Axis Gyroscope & Accelerometer Arduino Library.

Thank you dude! Let me try your recommendation. I'll give some feedback later :D

You're welcome. Please don't forget to upvote and mark the answer as accepted (using the little green tick), if it helps you. Cheers.

@HamdanieImpa - don't forget to upvote


text:
ESP8266-01 wdt reset after uploading code
I'm using code from here: ESP8266 example: Wi-Fi Access point, static IP, web-server and remote GPIO control.
Everything running ok this morning, but now I don't know why wasn't working...
This is what serial monitor display:
Configuring access point...
AP IP address: 42.42.42.42
HTTP server started

Exception (0):
epc1=0x40226744 epc2=0x00000000 epc3=0x00000000 excvaddr=0x00000000 depc=0x00000000

ctx: sys
sp: 3fffed10 end: 3fffffb0 offset: 01a0

>>>stack>>>
3fffeeb0:  00000000 3fffdad0 3ffeefec 00000030
3fffeec0:  3ffe9560 40226dbb 3fff0104 0000d158
3fffeed0:  00000000 40216ec8 3ffedfe8 4020f68c
3fffeee0:  00f20e64 3ffe9374 3ffe9204 3ffef190
3fffeef0:  4020f7c8 3ffef194 3ffe91fc 60000600
3fffef00:  40226731 3ffe9370 3ffee820 00000001
3fffef10:  40226814 3ffe9374 3ffee820 0331cfa4
3fffef20:  3fff0104 40100ab6 00000001 00000000
3fffef30:  4022df51 40100883 00000000 00000000
3fffef40:  4022df96 3fffdab0 00000000 3fffdcb0
3fffef50:  3ffee838 3fffdad0 3ffeefec 402073e3
3fffef60:  40000f49 40000f49 3fffdab0 40000f49
3fffef70:  40000e19 40001878 00000004 00000000
3fffef80:  3fffff10 aa55aa55 000000ed 40104424
3fffef90:  4010442a 00000004 00000000 a9751f68
3fffefa0:  4010000d e45c7604 ffd63db0 ca695611
3fffefb0:  00000000 3fffef4c 00000000 3fffff08
3fffefc0:  3fffffd0 00000000 00000000 feefeffe
3fffefd0:  feefeffe feefeffe feefeffe feefeffe
3fffefe0:  feefeffe feefeffe feefeffe feefeffe
3fffeff0:  feefeffe feefeffe feefeffe feefeffe
3ffff000:  feefeffe feefeffe feefeffe feefeffe
3ffff010:  feefeffe feefeffe feefeffe feefeffe
3ffff020:  feefeffe feefeffe feefeffe feefeffe
3ffff030:  feefeffe feefeffe feefeffe feefeffe
3ffff040:  feefeffe feefeffe feefeffe feefeffe
3ffff050:  feefeffe feefeffe feefeffe feefeffe
3ffff060:  feefeffe feefeffe feefeffe feefeffe
3ffff070:  feefeffe feefeffe feefeffe feefeffe
3ffff080:  feefeffe feefeffe feefeffe feefeffe
3ffff090:  feefeffe feefeffe feefeffe feefeffe
3ffff0a0:  feefeffe feefeffe feefeffe feefeffe
3ffff0b0:  feefeffe feefeffe feefeffe feefeffe
3ffff0c0:  feefeffe feefeffe feefeffe feefeffe
3ffff0d0:  feefeffe feefeffe feefeffe feefeffe
3ffff0e0:  feefeffe feefeffe feefeffe feefeffe
3ffff0f0:  feefeffe feefeffe feefeffe feefeffe
3ffff100:  feefeffe feefeffe feefeffe feefeffe
3ffff110:  feefeffe feefeffe feefeffe feefeffe
3ffff120:  feefeffe feefeffe feefeffe feefeffe
3ffff130:  feefeffe feefeffe feefeffe feefeffe
3ffff140:  feefeffe feefeffe feefeffe feefeffe
3ffff150:  feefeffe feefeffe feefeffe feefeffe
3ffff160:  feefeffe feefeffe feefeffe feefeffe
3ffff170:  feefeffe feefeffe feefeffe feefeffe
3ffff180:  feefeffe feefeffe feefeffe feefeffe
3ffff190:  feefeffe feefeffe feefeffe feefeffe
3ffff1a0:  feefeffe feefeffe feefeffe feefeffe
3ffff1b0:  feefeffe feefeffe feefeffe feefeffe
3ffff1c0:  feefeffe feefeffe feefeffe feefeffe
3ffff1d0:  feefeffe feefeffe feefeffe feefeffe
3ffff1e0:  feefeffe feefeffe feefeffe feefeffe
3ffff1f0:  feefeffe feefeffe feefeffe feefeffe
3ffff200:  feefeffe feefeffe feefeffe feefeffe
3ffff210:  feefeffe feefeffe feefeffe feefeffe
3ffff220:  feefeffe feefeffe feefeffe feefeffe
3ffff230:  feefeffe feefeffe feefeffe feefeffe
3ffff240:  feefeffe feefeffe feefeffe feefeffe
3ffff250:  feefeffe feefeffe feefeffe feefeffe
3ffff260:  feefeffe feefeffe feefeffe feefeffe
3ffff270:  feefeffe feefeffe feefeffe feefeffe
3ffff280:  feefeffe feefeffe feefeffe feefeffe
3ffff290:  feefeffe feefeffe feefeffe feefeffe
3ffff2a0:  feefeffe feefeffe feefeffe feefeffe
3ffff2b0:  feefeffe feefeffe feefeffe feefeffe
3ffff2c0:  feefeffe feefeffe feefeffe feefeffe
3ffff2d0:  feefeffe feefeffe feefeffe feefeffe
3ffff2e0:  feefeffe feefeffe feefeffe feefeffe
3ffff2f0:  feefeffe feefeffe feefeffe feefeffe
3ffff300:  feefeffe feefeffe feefeffe feefeffe
3ffff310:  feefeffe feefeffe feefeffe feefeffe
3ffff320:  feefeffe feefeffe feefeffe feefeffe
3ffff330:  feefeffe feefeffe feefeffe feefeffe
3ffff340:  feefeffe feefeffe feefeffe feefeffe
3ffff350:  feefeffe feefeffe feefeffe feefeffe
3ffff360:  feefeffe feefeffe feefeffe feefeffe
3ffff370:  feefeffe feefeffe feefeffe feefeffe
3ffff380:  feefeffe feefeffe feefeffe feefeffe
3ffff390:  feefeffe feefeffe feefeffe feefeffe
3ffff3a0:  feefeffe feefeffe feefeffe feefeffe
3ffff3b0:  feefeffe feefeffe feefeffe feefeffe
3ffff3c0:  feefeffe feefeffe feefeffe feefeffe
3ffff3d0:  feefeffe feefeffe feefeffe feefeffe
3ffff3e0:  feefeffe feefeffe feefeffe feefeffe
3ffff3f0:  feefeffe feefeffe feefeffe feefeffe
3ffff400:  feefeffe feefeffe feefeffe feefeffe
3ffff410:  feefeffe feefeffe feefeffe feefeffe
3ffff420:  feefeffe feefeffe feefeffe feefeffe
3ffff430:  feefeffe feefeffe feefeffe feefeffe
3ffff440:  feefeffe feefeffe feefeffe feefeffe
3ffff450:  feefeffe feefeffe feefeffe feefeffe
3ffff460:  feefeffe feefeffe feefeffe feefeffe
3ffff470:  feefeffe feefeffe feefeffe feefeffe
3ffff480:  feefeffe feefeffe feefeffe feefeffe
3ffff490:  feefeffe feefeffe feefeffe feefeffe
3ffff4a0:  feefeffe feefeffe feefeffe feefeffe
3ffff4b0:  feefeffe feefeffe feefeffe feefeffe
3ffff4c0:  feefeffe feefeffe feefeffe feefeffe
3ffff4d0:  feefeffe feefeffe feefeffe feefeffe
3ffff4e0:  feefeffe feefeffe feefeffe feefeffe
3ffff4f0:  feefeffe feefeffe feefeffe feefeffe
3ffff500:  feefeffe feefeffe feefeffe feefeffe
3ffff510:  feefeffe feefeffe feefeffe feefeffe
3ffff520:  feefeffe feefeffe feefeffe feefeffe
3ffff530:  feefeffe feefeffe feefeffe feefeffe
3ffff540:  feefeffe feefeffe feefeffe feefeffe
3ffff550:  feefeffe feefeffe feefeffe feefeffe
3ffff560:  feefeffe feefeffe feefeffe feefeffe
3ffff570:  feefeffe feefeffe feefeffe feefeffe
3ffff580:  feefeffe feefeffe feefeffe feefeffe
3ffff590:  feefeffe feefeffe feefeffe feefeffe
3ffff5a0:  feefeffe feefeffe feefeffe feefeffe
3ffff5b0:  feefeffe feefeffe feefeffe feefeffe
3ffff5c0:  feefeffe feefeffe feefeffe feefeffe
3ffff5d0:  feefeffe feefeffe feefeffe feefeffe
3ffff5e0:  feefeffe feefeffe feefeffe feefeffe
3ffff5f0:  feefeffe feefeffe feefeffe feefeffe
3ffff600:  feefeffe feefeffe feefeffe feefeffe
3ffff610:  feefeffe feefeffe feefeffe feefeffe
3ffff620:  feefeffe feefeffe feefeffe feefeffe
3ffff630:  feefeffe feefeffe feefeffe feefeffe
3ffff640:  feefeffe feefeffe feefeffe feefeffe
3ffff650:  feefeffe feefeffe feefeffe feefeffe
3ffff660:  feefeffe feefeffe feefeffe feefeffe
3ffff670:  feefeffe feefeffe feefeffe feefeffe
3ffff680:  feefeffe feefeffe feefeffe feefeffe
3ffff690:  feefeffe feefeffe feefeffe feefeffe
3ffff6a0:  feefeffe feefeffe feefeffe feefeffe
3ffff6b0:  feefeffe feefeffe feefeffe feefeffe
3ffff6c0:  feefeffe feefeffe feefeffe feefeffe
3ffff6d0:  feefeffe feefeffe feefeffe feefeffe
3ffff6e0:  feefeffe feefeffe feefeffe feefeffe
3ffff6f0:  feefeffe feefeffe feefeffe feefeffe
3ffff700:  feefeffe feefeffe feefeffe feefeffe
3ffff710:  feefeffe feefeffe feefeffe feefeffe
3ffff720:  feefeffe feefeffe feefeffe feefeffe
3ffff730:  feefeffe feefeffe feefeffe feefeffe
3ffff740:  feefeffe feefeffe feefeffe feefeffe
3ffff750:  feefeffe feefeffe feefeffe feefeffe
3ffff760:  feefeffe feefeffe feefeffe feefeffe
3ffff770:  feefeffe feefeffe feefeffe feefeffe
3ffff780:  feefeffe feefeffe feefeffe feefeffe
3ffff790:  feefeffe feefeffe feefeffe feefeffe
3ffff7a0:  feefeffe feefeffe feefeffe feefeffe
3ffff7b0:  feefeffe feefeffe feefeffe feefeffe
3ffff7c0:  feefeffe feefeffe feefeffe feefeffe
3ffff7d0:  feefeffe feefeffe feefeffe feefeffe
3ffff7e0:  feefeffe feefeffe feefeffe feefeffe
3ffff7f0:  feefeffe feefeffe feefeffe feefeffe
3ffff800:  feefeffe feefeffe feefeffe feefeffe
3ffff810:  feefeffe feefeffe feefeffe feefeffe
3ffff820:  feefeffe feefeffe feefeffe feefeffe
3ffff830:  feefeffe feefeffe feefeffe feefeffe
3ffff840:  feefeffe feefeffe feefeffe feefeffe
3ffff850:  feefeffe feefeffe feefeffe feefeffe
3ffff860:  feefeffe feefeffe feefeffe feefeffe
3ffff870:  feefeffe feefeffe feefeffe feefeffe
3ffff880:  feefeffe feefeffe feefeffe feefeffe
3ffff890:  feefeffe feefeffe feefeffe feefeffe
3ffff8a0:  feefeffe feefeffe feefeffe feefeffe
3ffff8b0:  feefeffe feefeffe feefeffe feefeffe
3ffff8c0:  feefeffe feefeffe feefeffe feefeffe
3ffff8d0:  feefeffe feefeffe feefeffe feefeffe
3ffff8e0:  feefeffe feefeffe feefeffe feefeffe
3ffff8f0:  feefeffe feefeffe feefeffe feefeffe
3ffff900:  feefeffe feefeffe feefeffe feefeffe
3ffff910:  feefeffe feefeffe feefeffe feefeffe
3ffff920:  feefeffe feefeffe feefeffe feefeffe
3ffff930:  feefeffe feefeffe feefeffe feefeffe
3ffff940:  feefeffe feefeffe feefeffe feefeffe
3ffff950:  feefeffe feefeffe feefeffe feefeffe
3ffff960:  feefeffe feefeffe feefeffe feefeffe
3ffff970:  feefeffe feefeffe feefeffe feefeffe
3ffff980:  feefeffe feefeffe feefeffe feefeffe
3ffff990:  feefeffe feefeffe feefeffe feefeffe
3ffff9a0:  feefeffe feefeffe feefeffe feefeffe
3ffff9b0:  feefeffe feefeffe feefeffe feefeffe
3ffff9c0:  feefeffe feefeffe feefeffe feefeffe
3ffff9d0:  feefeffe feefeffe feefeffe feefeffe
3ffff9e0:  feefeffe feefeffe feefeffe feefeffe
3ffff9f0:  feefeffe feefeffe feefeffe feefeffe
3ffffa00:  feefeffe feefeffe feefeffe feefeffe
3ffffa10:  feefeffe feefeffe feefeffe feefeffe
3ffffa20:  feefeffe feefeffe feefeffe feefeffe
3ffffa30:  feefeffe feefeffe feefeffe feefeffe
3ffffa40:  feefeffe feefeffe feefeffe feefeffe
3ffffa50:  feefeffe feefeffe feefeffe feefeffe
3ffffa60:  feefeffe feefeffe feefeffe feefeffe
3ffffa70:  feefeffe feefeffe feefeffe feefeffe
3ffffa80:  feefeffe feefeffe feefeffe feefeffe
3ffffa90:  feefeffe feefeffe feefeffe feefeffe
3ffffaa0:  feefeffe feefeffe feefeffe feefeffe
3ffffab0:  feefeffe feefeffe feefeffe feefeffe
3ffffac0:  feefeffe feefeffe feefeffe feefeffe
3ffffad0:  feefeffe feefeffe feefeffe feefeffe
3ffffae0:  feefeffe feefeffe feefeffe feefeffe
3ffffaf0:  feefeffe feefeffe feefeffe feefeffe
3ffffb00:  feefeffe feefeffe feefeffe feefeffe
3ffffb10:  feefeffe feefeffe feefeffe feefeffe
3ffffb20:  feefeffe feefeffe feefeffe feefeffe
3ffffb30:  feefeffe feefeffe feefeffe feefeffe
3ffffb40:  feefeffe feefeffe feefeffe feefeffe
3ffffb50:  feefeffe feefeffe feefeffe feefeffe
3ffffb60:  feefeffe feefeffe feefeffe feefeffe
3ffffb70:  feefeffe feefeffe feefeffe feefeffe
3ffffb80:  feefeffe feefeffe feefeffe feefeffe
3ffffb90:  feefeffe feefeffe feefeffe feefeffe
3ffffba0:  feefeffe feefeffe feefeffe feefeffe
3ffffbb0:  feefeffe feefeffe feefeffe feefeffe
3ffffbc0:  feefeffe feefeffe feefeffe feefeffe
3ffffbd0:  feefeffe feefeffe feefeffe feefeffe
3ffffbe0:  feefeffe feefeffe feefeffe feefeffe
3ffffbf0:  feefeffe feefeffe feefeffe feefeffe
3ffffc00:  feefeffe feefeffe feefeffe feefeffe
3ffffc10:  feefeffe feefeffe feefeffe feefeffe
3ffffc20:  feefeffe feefeffe feefeffe feefeffe
3ffffc30:  feefeffe feefeffe feefeffe feefeffe
3ffffc40:  feefeffe feefeffe feefeffe feefeffe
3ffffc50:  feefeffe feefeffe feefeffe feefeffe
3ffffc60:  feefeffe feefeffe feefeffe feefeffe
3ffffc70:  feefeffe feefeffe feefeffe feefeffe
3ffffc80:  feefeffe feefeffe feefeffe feefeffe
3ffffc90:  feefeffe feefeffe feefeffe feefeffe
3ffffca0:  feefeffe feefeffe feefeffe feefeffe
3ffffcb0:  feefeffe feefeffe feefeffe feefeffe
3ffffcc0:  feefeffe feefeffe feefeffe feefeffe
3ffffcd0:  feefeffe feefeffe 40227cb3 00000001
3ffffce0:  ffffffff 00000000 3ffe96b1 00000008
3ffffcf0:  40227d02 3ffeccf8 3ffefadc 00000001
3ffffd00:  3fff07e8 00000000 4010106b 3ffeccf8
3ffffd10:  000000c0 4021a0c2 00000008 3fff06d8
3ffffd20:  40226d70 3ffeccf8 3ffed470 3fff07e8
3ffffd30:  00000000 4021a22b 3ffefd84 feefeffe
3ffffd40:  00000000 00000002 00000001 3ffeccf8
3ffffd50:  00000000 400042db 3fff07e8 3ffeff44
3ffffd60:  40004b31 3fff080c 0000049c 0007e000
3ffffd70:  401057e0 4020dfcd 3ffef154 3ffeff44
3ffffd80:  40106475 3fff080c 0000049c 00000000
3ffffd90:  00000000 00000000 00000020 40100f22
3ffffda0:  00000000 00000000 00000020 40100f22
3ffffdb0:  3ffe9560 40104304 3fff0104 40100f22
3ffffdc0:  00000001 40103523 3ffed6e0 40100f22
3ffffdd0:  40103986 00000000 00000020 40100f22
3ffffde0:  4010346a 0000007f 7fffffff 00000000
3ffffdf0:  4010346a 0000007f 7fffffff 00000000
3ffffe00:  0000007f 00040000 7fffffff 00000000
3ffffe10:  40103269 00040000 7fffffff 00000000
3ffffe20:  00000000 00000000 0000001f 40104bfd
3ffffe30:  00000000 00000000 0000001f 40104bfd
3ffffe40:  4000050c 00000030 00000011 ffffffff
3ffffe50:  00000000 00000000 0000001f 40104bfd
3ffffe60:  4000050c 00000002 03316038 00000000
3ffffe70:  4020386b 00000030 00000010 ffffffff
3ffffe80:  00000000 00000000 0000001f 40104bfd
3ffffe90:  4000050c 00000000 00000000 fffffffe
3ffffea0:  40000ea6 00000030 0000001e ffffffff
3ffffeb0:  40000ea3 00000000 00000001 00000001
3ffffec0:  3fffdab0 00000000 3fffd9d0 3ffeefec
3ffffed0:  00000000 00000000 00000001 3ffeefe4
3ffffee0:  00000000 3fffdad0 3ffeefec 00000030
3ffffef0:  ffffffff 3fffc6fc 00000001 3ffe85e8
3fffff00:  00000000 3fffdad0 3ffeefec 00000030
3fffff10:  00000000 3fffdad0 3ffeefec 00000030
3fffff20:  402077a4 3ffeedfc 000003e8 402074e2
3fffff30:  3ffe8f00 00000000 00000000 40207525
3fffff40:  3ffe8cac 3ffeedfc 3ffeee00 40203fbe
3fffff50:  3fff014c 00ffffff 3ffeef2c 4020671c
3fffff60:  3fffdad0 3ffeedfc 3ffeedfc 40207918
3fffff70:  4020290c 00000000 3ffeedfc 40204f31
3fffff80:  40207b28 00000000 00001388 40207c40
3fffff90:  00000000 00000000 feefeffe feefeffe
3fffffa0:  00000000 00000000 00000001 40207449
<<<stack<<<

 ets Jan  8 2013,rst cause:4, boot mode:(1,7)

wdt reset

 ets Jan  8 2013,rst cause:4, boot mode:(1,7)

wdt reset

Could someone please tell me how can I make it work again?

If reflashing the code doesn't fix it, then it could be a hardware fault. Try another unit.

I tried the sketch you posted and it works.
The most likely problem is the power source for the ESP8266. You have in the title ESP8266-1 so I will assume you have a ESP-01 module.
A lot of people who start with the ESP-01, or any other module without an onboard 3.3v regulator, don't know how demanding the ESP8266 is on the power source. It needs to have a stable 500mA capacity for it to work reliably. Also the regulator must be electrically close to the module. Using long connecting wires is one problem I see often.
The ESP8266 could have enough power to get programmed correctly but when it comes to transmitting it will draw a lot more current and if the power supply is insufficient a voltage dip occurs and then unpredictable behaviour occurs.
Check over any connections that might be poor. Please post what you are using for hardware if you can't get things running again.

note that AP mode uses more power than STA because sleep is disabled by default...

source: Stack Exchange

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

sort: votes


text:
Addressable RGB LED Strip
I am looking to create an addressable RGB LED strip circuit with my NodeMCU v3 Wi-Fi. I am looking at a strip of 150 RGB LEDs, 5 meters long, so 30 LED/m. But I am only going to use about 50 LEDs for the backlight on my desk. My understanding is that if each RGB LED pulls 60 mA on full white, and I'm running 50 LEDs, then I will need at least 60 mA x 50 LEDs = 3000 ms (3 A) of power to sufficiently light all of them. I am thinking about upgrading this in the future, and so I am thinking about going with a 5V 10A power supply. Am I okay to go with a 5 V 10 A power supply? Or will this be too much current for the system.

In your case I would use ledstrips with SPI protocol (like APA102). Using SPI, you can have your resources free (not having to bit bang), transmission speed is higher (no fixed delay) and you can allow more time for calculating the next pixel, so you don't have to store them all in memory. Also, the nodeMCU may not always be "atomic" or do every instruction in order (and has to yield every now and then) so the hard timed bit banging of neopixels may not be glitch free/doesn't seem correct for this application.

I generally double my current needs when looking for supplies and wiring.  So if you think your load is 3A then I would get a 6A power supply.    I'm thinking like @Paul.  You may have problems generating the timing of older addressable LEDs as the ESP8266 is also concerned with WiFi communications.  The more complex the processor's responsibilities, the worse the real time response.   That's why it's difficult to drive these LEDs from a Raspberry Pi.

the current rating of a power supply is how much current you can draw before the power supply overloads ..... the current rating is not how much current is forced into a connected load .... think about 100W light bulb compared to 5W nightlight .... both connected to a 15A 110V AC circuit ..... 100W bulb draws almost 1A .... 5W bulb draws about 50mA .... neither one has 15A forced through it

Each will only draw as much current as they normally would from a 5 volt supply. If you had a 5 volt 100 amp supply they still would not draw any more.
The amount of excess current a power supply can deliver doesn't change what the load will take from that supply.
For example, if you had a 5 volt supply with a 1 ohm resistor as a load the current would be 5 amps. 5 volts / 1 ohm = 5 amps. And if you had a 5 volt 10 amp supply the current would still be 5 amps. Same with a 20 amp supply. As long as the voltage is the same, going up in current capacity is safe.
(LEDs are not resistors but with this application it is much the same)
When you do wire up the LED strips make sure you are using thick enough wires.

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


text:
Using SD library in a ESP-IDF project on ESP32
I just started to move from the Arduino firmware to the esp-idf firmware.
I read that link. I learn that I have to include libraries creating a component files, with a component.mk file, *.c, *.cpp files and an include/ folder for *.h files.
That was ok for most of libraries I had to include, except for the SD card library, more precisely the Sd2PinMap.h header.
It seems that ESP32 is not recognized:
$(IDF-PATH)/Project/components/SD/include/Sd2PinMap.h:510:2: error:
#error Architecture or board not supported.

but with the Arduino firmware, there were no problems.
I checked make menuconfig options, but I didn't find a way to make it work for an ESP32 board... Any ideas ?

So, this question is about non-Arduino hardware running non-Arduino firmware?

It's about moving from Arduino, to another firmware. I was thinking that arduino.stackexchange was more appropriate for this than stackoverflow, which is too broad. Where am I supposed to ask this ?

Don't get me wrong, I wasn't saying you can't ask, I was just clarifying what your issue was

espressif esp32 forum https://www.esp32.com/

Okay, the solution was simple, I just had to pull the update for the SD Card library, mine was outdated. Thank you all.

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


text:
How to tune up a servo and add protective clauses?
I am working with an Arduino Uno, and have recently been given an assignment to use the servo motor.
The requirements are that I tune the pulse widths while comparing the 0 and 180 degrees. Secondly I must put in a protective clause to prevent it from going past the values. Any help at all is greatly appreciated. Thank you.
(Using the servo.attach(pin, minpulse, maxpulse) method, and writeMicroseconds() command.)

You may want to put in protective clauses in your code to prevent accidental driving of the servo beyond its intended range.
Write a simple program to tune up your servo’s min and max pulsewidths corresponding to 0° and 180°. Start by using 900 and 2100 in the attach() command, and perhaps sending the motor to 0°, 90°, and 180° delaying a couple seconds between moves for you to assess the quality of alignment.

My only ideas have been to manually fine tune it by checking when it does not turn any more.

Sounds like homework.  Asking here sounds like cheating.  Well, take a look at all the methods in the Arduino servo library.  See where you can simply write the delay in milliseconds?  See where you can simply read back the angle?  If it works, it's likely only an approximation, but you might be able to do your whole lab with no servo attached at all.  Of course you would have nothing to demonstrate.

You need to create some form of feedback system - something which, when you provide an angle to test will allow the Arduino (or you) to know the actual resulting angle and make the relevant adjustments. Automated could be a potentiometer that feeds back the angle (you will have to calibrate it yourself) or a simple protractor indicating the angle from which you read the value and feed it or the adjustments back in.  It's up to you how complex and automated you make it.

Thank you for your help, I misinterpreted the question, a manual calibration would be enough, though the potentiometer idea sounds pretty cool.

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


text:
Problems with Arduino BT
I have an Arduino BT and I can't connect it to any device I have. I've tried in 3 different situations:
Win7 - If I choose 'Connect without a PIN code', the device seems properly detected but it doesn't appears in Device Manager. In the case of the connection with the PIN code, it throws a timeout error.
Win8 - Don't even ask me for the PIN code. A message 'This isn't working. Try again and verify if the device is still visible' appears.
Android 5.0 - When I try to pair and write the PIN code, I get a message 'Invalid PIN or password'.
The PIN is 12345, by Arduino.cc page.
Another different thing is that in the documentation, the board has the Blink code by default. But the orange light on the board doesn't blink, and don't turn green either. I didn't find anything about the color of the LED in this board.
Can anyone help me?


text:
Getting error 32 in multi-master I2C sketch with library https://github.com/rambo/I2C
I am developing a multi-master scenario sketch with the https://github.com/rambo/I2C library, because this library will handle multi-master data collisions.
I created a setup with two Arduino nano's which act both as master and slave.
My sketch works as long as I use only one master. Sending data from one Arduino to the other works fine. The other receives the data.
But when I sequentially try to send data from the second Arduino to the first, I get an error (32). After that even sending data from the initial Arduino results in error 32.
This is the used sketch for both the Arduino's.
The only difference is that I switch the values of rel_address and own_address when programming the seconds Arduino.
Sending data is done by pressing a button on pin 2 (switchPin)
/**
   atme328 = ATmega328
   SDA --> Pin A4
   SCL --> Pin A5
*/
#include <I2C.h>
#include <Wire.h>

int switchPin = 2;
int relayOnPin = 3;
int relayOffPin = 4;

uint8_t broadcast_address = 0;
uint8_t own_address = 11; // CHANGE FOR EVERY MODULE!!
// rel_address = address of relay to switch; SET to own_address if relay is connected to this chip!
uint8_t rel_address = 10; // CHANGE FOR EVERY MODULE!! SET to own_address if relay is connected to this chip!
uint8_t rpi_address = 1;

unsigned long counter = 0;

void setup() {

   Serial.begin(9600);
   pinMode(switchPin, INPUT_PULLUP);

   pinMode(relayOnPin, OUTPUT);
   pinMode(relayOffPin, OUTPUT);
   // start condition
   digitalWrite(relayOnPin, HIGH);
   digitalWrite(relayOffPin, LOW);

   I2c.begin();
   I2c.timeOut(50);
   // I2c.pullup(true); // done by external 4.7kOhm resistors

   // config Wire library for I2C slave functionality
   Wire.begin( own_address );

   TWAR = (own_address << 1) | 1;  // enable broadcasts to be received!

   // set slave receive callback
   Wire.onReceive( onI2CReceive );

}

void loop() {
   counter = counter + 1;
   if (counter == 20000) {
      digitalWrite(relayOnPin, LOW);
      digitalWrite(relayOffPin, LOW);
   }
   if ( digitalRead(switchPin) == LOW ) {
      sendCmd('d', rel_address); // send command to remote relay
   }
}

void sendCmd(uint8_t cmd, uint8_t address) {
   uint8_t status = I2c.write(address, cmd); //configure device for continuous mode
   if (status > 0) {
      // error codes at https://github.com/rambo/I2C/blob/master/I2C.cpp
      Serial.print(status, DEC);
      Serial.print('!');
      digitalWrite(relayOffPin, HIGH);
      delay(50);
   } else {
      digitalWrite(relayOnPin, HIGH);
      Serial.print('.');
   }
   counter = 0;
}

void onI2CReceive(int howMany) {
   // loops, until all received bytes are read
   while (Wire.available() > 0) {
      digitalWrite(relayOffPin, HIGH);
      Serial.write(Wire.read());
   }
   counter = 0;
}

What do I need to do to be able to send from two units using this library?
Thanks!

Shouldn't you use only one I2C library?

the repeated starts support was added to Wire library some yeas ago, if this is the reason you use the I2C library

@Juraj the I2C library only supports master operations.  I found some dedicated master / dedicated slave example of the I2C library and they also use the Wire library for the slave (https://github.com/Scott216/I2C-Examples)

I use the I2C library to overcome the hanging of the sketch on master send collision. If I use the Wire library, the sketch simply hangs on a collision. Something in the Wire library so it seems...

examples can use Wire for slave, but not in the same sketch. both libraries set the same I2C registers

You cannot use the I2C library and the Wire library at the same time. From the code I guess you wanted the Wire library to do the slaves job and the I2C library to implement the master. But since both libraries use the same hardware, this cannot be divided between them. Combining two libraries for the same hardware isn't that trivial. The I2C library only provides master functionality. So, to reach your goal, you would have to find a library, that provides both master and slave functionality while doing correct bus arbitration (which is the term for correctly handling master data collisions). Or you have to change one of the two libraries yourself, to provide the missing functionality.
And the error you get is defined in #define MT_SLA_NACK    0x20 in I2C.h (0x20 is equal to 32). This means, that you haven't got an acknowledgement from the slave you have addressed. This suggests, that in your current code only the master functionality is working. (But it may have another meaning considering the interaction of the two libraries on the same hardware)

I ended up removing the I2C library and using a modified version of Wire.
I replaced the twi.h and twi.c libraries in C:\Program Files (x86)\Arduino\hardware\arduino\avr\libraries\Wire\src\utility with those from http://liken.otsoa.net/pub/ntwi/. This implementation adds timeouts to the operations, which prevents a hang-up.


text:
Arduino Nano - Unknown USB device
I just bought an Arduino Nano v3.0 (compatible? +- 5$) and I cannot connect it to my computer (Windows 8.1 64bit, Arduino IDE 1.6.8 installed).
The Arduino was bought as a clone but shows GRAVITECH.US on the front.
It has a FTDI FT232RL chip (1412-G B8908572) on the back.
When connecting the Arduino the power leds burns the TX and RX led flash a few times (really shortly) and then die. Then the yellow L leds blinks once per second continiously.(power to the Arduino comes from the USB cable, not from external power)
In the system tray I get a message saying
"The last USB device you connected to this computer malfunctioned,
and Windows does not recognize it."

In the device manager I get a node under Universal Serial Bus Controllers:
Unknown USB Device (Device Descriptor Request Failed).

When examining the properties of the device, the device-status is:
Windows has stopped this device because it has reported problems. (Code 43)
A request for the USB device descriptor failed.

I tried to reset the device
I tried different USB cables
I used another Windows 8.1 PC without Arduino IDE installed
I used an old XP computer

All give same error.
I read about the bricking of clones by the recent FTDI drivers...
I downloaded the FT_Prog tool V3.0.60 to check the PID, but the tool simply does not find the Arduino...
I'm out of ideas... does anyone have some left?
Thanks in advance!
Michiel

I found the issue!
There is a bug in the Arduino hardware:
https://ketturi.kapsi.fi/2014/04/how-to-fix-moody-arduino-nano/
You need to bridge pins 25 and 26 of the FTDI chip (located at the back of the Arduino) to ground the pin 26 TEST signal.
If I connect these pins then it works just fine!

It would be good to summarize the key point - bridging pins 25 and 26 of the FTDI to ground the pin 26 TEST signal, rather than relying on a link for the key element of your answer.

Thanks for the advice, I added the comment to my solution.

I've had this issue before. You can try reuploading the bootloader. If that doesn't work, maybe try re-installing the drivers.


text:
Can anyone identify why this incrementer is losing count?

I am working on a project where the end result is to count the number of cycles of a moving piece of metal using an inductive sensor.
For now I am using an Arduino Uno and have created a breadboard version for testing. The sensor has been replaced by a momentary push button. To check the count data I am viewing the number using Serial Monitor
All the elements of this set-up are working, apart from one major issue. When pressing the button the incrementer (++) occasionally adds 2 instead of 1 from only one button press. As a rough guide to the error frequency, it seems to count 11 for every 10 button presses. The error has never presented as not counting enough.
I am new to software, as such I cannot seem to see the error
Any help and guidance would be greatly appreciated
Here is the code I have written so far:
//Libraries
#include <EEPROM.h>

//Constants
const int counterPin = 2;   //Input from counter (looking for HIGH as external pulldown resistor is used)
const int EEPROMadress = 3; //holds the EEPROM address

//Variables
int counterState = 0;       //current button state
int counterStatePrv = 0;    //previous button state
int storedValue;
int presetCount = 100;

unsigned long countNumber;      //unsigned 32bit variable

void setup() {

    for (int i = 0; i < 255; i++) {
        // this performs as EEPROM.write(i, i)
        EEPROM.update(i, i);
    }
    for (int i = 0; i < 255; i++) {
        // write "presetCount" value to cell "EEPROMaddress" only the first time
        // will not write the cell the remaining 254 times
        EEPROM.update(EEPROMadress, presetCount);
    }

    pinMode(counterState, INPUT);
    Serial.begin(9600);

    countNumber = EEPROM.read(3);   //Start the counter at the presetCount value
}

void loop() {

    counterState = digitalRead(counterPin);   //Read the status of the counter input
    storedValue = EEPROM.read(EEPROMadress);

    if (counterState != counterStatePrv) {      //check that pulse went off
        if (counterState == HIGH) {             //check for pulse
            countNumber++;                      //increment (add 1) to the stored count value
            delay(10);
            Serial.print("Count  Value: ");
            Serial.println(countNumber);

            Serial.print("Stored Value: ");
            Serial.println(storedValue);
            Serial.println();

        }
    }
    counterStatePrv = counterState;

}

You need to debounce the button.

Are you sure you are not writing too much into the EEPROM?

How is it wired? Is there a pull-down resistor?

Buttons bounce (at least they appear to, electrically), meaning that if you're fast enough, you can detect multiple pulses per button-press. Usually we don't count the button as being pressed until we read the same value {n} times in a row or for {m} mSec, or some similar technique.
Because you call EEPROM.read() immediately after testing the button, perhaps most times the bouncing will have ceased when the call returns, but once in a while one last bounce slips through.
Nick Gammon, a regular contributer here, has a good discussion of de-bouncing on his web site. Have a look at that and pick a technique that's compatible with what you're trying to do.

@Nick Gammon your website was very helpful. I have now added the debounce and the count is tracking correctly. Thanks all


text:
How can I stop my Arduino UNO rev 3 from briefly turning on digital output pins on startup or reset?
I am using my Arduino UNO rev 3 to control other devices via the digital output pins. On startup or reset, I find that these pins are all briefly turned on (perhaps as part of a self test). This interferes with my application. How can I suppress this?

Which pins specifically? By default most pins are set to INPUT not OUTPUT.

By default the pins are set to INPUT (except pins 1 which is used by the bootloader for programming). Inputs are however floating, so they don't have any fixed voltage during this stage. The the device attached to the pin might read a HIGH signal. To prevent this add a pull-down (or -up) resistor.

Digital pin 13 will be turned on briefly as part of the bootloading process (it flashes a few times). Thus this is not a good choice of pin for a device like a motor to be connected to. Also if you are uploading a new sketch the Tx pin (digital pin 1) will be turned on and off.
You can change the processor fuses to not use the bootloader, which would avoid these issues, however then you have to change them back to upload a new sketch - unless you upload using ICSP instead of the bootloader.
As Gerben and Majenko have pointed out, any other issues could be from "floating" pins which some devices might interpret as having a HIGH on them, possibly. Pull-down resistors could help there (or pull-up if that is more appropriate).
The ideal thing could be to structure your system in such a way that the two pins (1 and 13) which come on during the bootloading process are connected to something "harmless" (eg. an LED) rather than "harmful" (eg. a motor).


text:
Simple Arduino Code Not Working
When I upload this code LED at pin 13 goes HIGH and that's it. My goal is to make it blink in the order specified in the array. What am I doing wrong?
int Array[] = {1,1,1,0,1,0,0,0,1,0,1,0,1,1,0,0,1,0,1,0,1,1,0,0};
int Data = 13;
int i = 0;

void setup() {
    pinMode(Data, OUTPUT);
}

void loop() {
    int x = Array[i];
    delay(200);
    digitalWrite(Data, x);
    i = i+1;
    if (i==23) {
        i=0;
    }
}

What you're doing wrong is living your life at a normal speed.
The LED will be blinking, but so fast you can't see it change.
Without adding some delays in there you will just see the LED light up.

Still not working after i added 200ms delay

@ArduinoNoob Please don't edit the solution into your question.  Also, if Majenko's answer solved your problem, mark it as accepted by clicking the check mark underneath the answer's score.


text:
serial communication between several arduinos to pc
Is possible the communication between several Arduinos to one serial port in the PC ?
If I have ARD_A, ARD_B,... ARD_Z running with some code like this
void setup()
{
    Serial.begin(9600);
}

void loop()
{
    while (Serial.available() > 0)
    {
       String stringID = Serial.read()
       int nFound = stringID.indexOf("@ARD_01");
                    // ---> Id is unique for each arduino
       if ( nFound > 0 )
          Serial.print("this is @ARD_01 responding sending some data");
     }
}

And in the pc there is an exe sending a string:
"@ARD_01 I want your data"
   process the data
"@ARD_02 I want your data"
   process the data
"@ARD_03 I want your data"
   process the data

Not directly, no.  A PC's serial port - either a "real" one or a USB one, can only communicate with one device.
The Arduino, though, is a USB device, so you can just plug them all into a USB hub or a bunch of hubs - each one will get its own COM port.  Managing all those COM ports can be kind of tricky though, especially when you have a lot of devices.
Another option, one that is more widely used when you want to communicate with a lot of slave devices from one master device is to use a multidrop network.  RS-485 is the most popular of these.  It allows you to connect many slave devices to one set of serial wires and the master sends instructions to a slave, and the slave may respond with data and information on request.
RS-485 requires special hardware to interface normal TTL level RS-232 (UART) ports to the bus.
You can read more about RS-485 here: https://en.wikipedia.org/wiki/RS-485

What If I say yes you can communicate with different Arduino on the same serial port by changing the baud rate for each Arduino :) with simple VB.net API

Then I reply with how do you isolate all the Arduino tx lines from each other so they can talk back to the pc? (btw, I know the answer just testing if you do)

I didn't mean to test you or anything :) I just made that before with 2 arduinos by build a small vb.net API, 2 baud rate each one will receive the data from specific Arduino, if the other Arduino in different baud rate send data too, the API will ignore it simply because the data will not make any sense

It's not a question of not making sense, its a question of preventing physical damage to the arduinos. If one tx is high and the other tx is low you have an effective short circuit that can damage the tx pins of both arduinos. While it is possible to do it you have to know what you are doing, and if you know what you are doing you'll do it properly and use an industry standard solution.

oh It's work but as what you have said, TX,RX pins will be damaged, Thanks for notify me for that :)


text:
Unwanted ghosting with charlieplexed LEDs
I have a very simple PCB that uses 3 GPIO on a ATtiny85 to control 6 LEDs using charlieplexing.
When I try to program certain patterns of lit LEDs (pseudo PWM) I get some LEDs lighting dimly when they should be fully off.
Example where only top or bottom three LEDs should be on alternately:

You can see that LEDs 2 and 5 are dimly glowing rather than being fully off.
I do not have problems when lighting the LEDs one at a time in sequence.
I do not have problems lighting odd and even LEDs alternately.
The schematic is:

The buttons are used to change up and down through 6 modes of operation. Mode 0 lights the LEDs one at a time in sequence. Mode 1 alternates the odd and even LEDs. Mode 2 lights upper or lower three LEDs alternately (and has ghosting problem), the other modes just steadily illuminate the corresponding LED.
The code is split into several files:
main.ino:
Button leftButton = Button(3);
Button rightButton = Button(4);
Sequencer sequencer = Sequencer(200); // ms per step
Alternator alternator = Alternator(0b00101010, 0b00010101);

void setup() {
  pinMode(0, OUTPUT);
  pinMode(1, OUTPUT);
  pinMode(2, OUTPUT);
}

// ------------------------------------------------------------------

const int maxMode = 5;
int mode = 0;

void loop() {
  if (leftButton.wasPressed())  {
    if (++mode > maxMode) { mode = 0; }
    initMode(mode);
  }
  if (rightButton.wasPressed()) {
    if (--mode < 0) { mode = maxMode; }
    initMode(mode);
  }

  switch(mode) {
    case (0): sequencer.check(); break;
    case (1):
    case (2): alternator.check(); break;
    default: lightLED(mode); break;
  }
}

// ------------------------------------------------------------------

void initMode(int mode) {
  switch (mode) {
    case (0): sequencer.reset(); break;
    case (1): alternator = Alternator(0b00101010, 0b00010101); break;
    case (2): alternator = Alternator(0b00111000, 0b00000111); break;
  }
}

Alternator.ino
class Alternator {

  private:
    unsigned long whenChanged = 0;
    int interval = 500; // ms
    byte pattern, pattern1, pattern2; // bitmap
    int count = 0;

  public:
  Alternator(byte pattern1, byte pattern2) {
    this->pattern1 = pattern1;
    this->pattern2 = pattern2;
  }

  void check() {

    if ((millis() - whenChanged) > interval) {
      if (pattern == pattern1) { pattern = pattern2; }
      else                     { pattern = pattern1; }
      whenChanged = millis();
    }

    if (++count > 5) { count = 0; }
    if (((pattern >> count) & 1) == 1) {
      lightLED(count);
    }

  }

};

Sequence.ino
class Sequencer {

  private:
    int seq;                            // LED# 0-5
    unsigned long whenLastStep;         // ms
    int stepTime;                       // ms
    const int aDay = 24 * 3600 * 1000;  // ms

  public:
    Sequencer(int stepTime) {
      if (stepTime < 1) { stepTime = 1; }
      if (stepTime > aDay) { stepTime = aDay; }
      this->stepTime = stepTime;
      this->seq = 0;
      this->whenLastStep = 0;
    }

    void check() {
      if ((millis() - whenLastStep) > stepTime) {
        lightLED(seq++);
        if (seq > 5) { seq = 0; }
        whenLastStep = millis();
      }
    }

    void reset() {
      this->seq = 0;
    }
};

Charlieplex.ino
const int highs[6] = {0,1,2,1,2,0};  // GPIOs for LEDs 0-5
const int lows[6]  = {1,0,1,2,0,2};

// Manipulates 3 GPIO outputs to light one of 6 LEDs.
void lightLED(int i) {
  int h, l;     // pin to set high, low
  if (i < 0 || i >= 6) {
    h = 99; l = 99;  // all LEDS off
  } else {
    h = highs[i];
    l = lows[i];
  }

  for (int j=0; j<=2; j++) {
    if (j==h || j==l) {
      pinMode(j, OUTPUT);
      if (j==h) {
        digitalWrite(h, HIGH);
      } else {
        digitalWrite(l, LOW);
      }
    } else {
      pinMode(j, INPUT); // tri-state
    }
  }
}

Buttons.ino
class Button {

  private:
    int pin;
    const int DebounceDelay = 100;      // milliseconds
    int lastState = HIGH;               // Previous status of button
    unsigned long whenLastPressed = 0;  // Last time button was pressed

  public:
    Button(int pin) {
      this->pin = pin;
      pinMode(pin, INPUT_PULLUP);
    }

    // Was there an up (HIGH) to down (LOW) transition since last call, and still held down?
    bool wasPressed() {
      bool result = false;
      if ((millis() - whenLastPressed) > DebounceDelay) {
        int state = digitalRead(pin);
        if ((state == LOW) && (lastState == HIGH)) {
          result = true;
          whenLastPressed = millis();
        }
        lastState = state;
      }
      return result;
    }

};

I'm not sure where I am going wrong, any ideas?

I'd use direct access to the port (but it's not neccesary). And first set all outputs zero, then all set as inputs (if you left any output high and switch to input mode, there will be internal pull up enabled). After that you can set output mode for correct pins and one of them as HIGH. (for three pins it might be enough just RESET all pins and then set correct output mode and next loop set values)

Charlieplexing code doesn't reset the state of unused pin and if the port value is HIGH + mode INPUT, it means the pull-up is enabled.
Solution is reset all pins to LOW before code starts changing directions. And the last step would be setting correct pin to HIGH.
If you want to do it in single loop, you might observe really short pulses (it might or might not be visible - at the higher frequencies it'll be more obvious)
It could be also much faster than using digitalWrite and pinMode, something like:
  void charlieplex(uint8_t i) {
    constexpr uint8_t clrpins = ~(_BV(PB0) | _BV(PB1) | _BV(PB2));
    constexpr uint8_t dirs[]  = { 0b011, 0b011, 0b110, 0b110, 0b101, 0b101};
    constexpr uint8_t outs[]  = { 0b001, 0b010, 0b010, 0b100, 0b001, 0b100};

    PORTB &= clrpins; // clear output pins
    DDRB  &= clrpins; // clear direction pins (0 == input, 1 == output)
    if (i < 6) {  // such easy condition if you use:  uint8_t i
      DDRB  |= dirs[i]; // And set the correct pins as outputs
      PORTB |= outs[i]; // And set the correct pin as high
    }
  }

It's not tested, but it should be pretty much it

This code works very well. Small fix needed for my particular LED ordering: constexpr uint8_t outs[]  = { 0b001, 0b010, 0b100, 0b010, 0b100, 0b001};

it's possible, I was doing it according to the led numbering, and here and in the original code it looks like 3-4 and 5-6 are swapped

Ah yes, I changed the LEDs around when laying out the PCB to simplify track routing and didn't update the schematic! So my fault. :-)

Simply adding a digitalWrite(pin, 0) before each pinMode(pin, INPUT) in my code fixed the LED ghosting in my charlieplexing badgelife project. Simple and thanks for the explanation, missed the pullup issue in other docs.

A secondary issue is that using millis() to update the timestamps will cause the interval to cumulatively drag.
To keep the interval constant, update:

whenChanged with interval
whenLastStep with stepTime.

Alternator.ino
void check() {

  if ((millis() - whenChanged) > interval) {
    if (pattern == pattern1) { pattern = pattern2; }
    else                     { pattern = pattern1; }
    whenChanged += interval;  // Constant interval.
  }

  if (++count > 5) { count = 0; }
  if (((pattern >> count) & 1) == 1) {
    lightLED(count);
  }

}

Sequence.ino
void check() {
  if ((millis() - whenLastStep) > stepTime) {
    lightLED(seq++);
    if (seq > 5) { seq = 0; }
    whenLastStep += stepTime;  // Constant time step.
  }
}

This subtle difference is explained very well by @edgar-bonet in his answer about polling a sensor at 100 Hz.
Also, Button::wasPressed() is prone to a negative blip occurring at the time of sampling the input pin, i.e. the blip will be interpreted as a continuous press of DebounceDelay (100 ms). Compare with this simple debouncer I put on GitHub.


text:
How to serve multiple connections with an ESP8266 and an Adruino?
I want to make a server using an ESP8266 (12e) and an Arduino Nano.
I have got everything hooked and I created a minimal "Hello World" example, based on a number of samples found on the web, which is working fine... as long as the ESP does not receive multiple requests simultaneously.
I am using SoftwareSerial on pins 8 and 9 of my Arduino Nano.
As long as I send one request at the time, things work fine.
If I use two browsers and send two requests with little interval, things go wrong, and that figures: the sendData() method just reads from the serial connection. It will consume the new request while waiting for an "OK" from the initial request...
Is there any sample code or library (for ESP + Arduino (nano)) that can handle correctly multiple concurrent connections?
Thanks
My code:
/*
  Software serial multple serial test
 */
#include <SoftwareSerial.h>

#define DEBUG true

SoftwareSerial esp8266(8, 9); // RX, TX

void setup() {

  Serial.begin(9600);
  esp8266.begin(9600); // your esp's baud rate might be different : 115200

  Serial.println("Setup...");

  /*
  sendData("AT+RST\r\n",2000,DEBUG); // reset module
  sendData("AT+GMR\r\n",1000,DEBUG); // get version
  sendData("AT+CWMODE=2\r\n",1000,DEBUG); // configure as access point
  sendData("AT+CIFSR\r\n",1000,DEBUG); // get ip address
  sendData("AT+CIPMUX=1\r\n",1000,DEBUG); // configure for multiple connections
  sendData("AT+CIPSERVER=1,80\r\n",1000,DEBUG); // turn on server on port 80
  */

  sendData("AT+RST\r\n", 2000,DEBUG);
  sendData("AT+GMR\r\n", 1000, DEBUG);

  sendData("AT+CWMODE=1\r\n",1000,DEBUG); // configure as station
  sendData("AT+CWJAP=\"******\",\"*******\"\r\n", 6000, DEBUG);
  sendData("AT+CIFSR\r\n",1000,DEBUG); // get ip address
  sendData("AT+CIPMUX=1\r\n",1000,DEBUG); // configure for multiple connections
  sendData("AT+CIPSERVER=1,80\r\n",1000,DEBUG); // turn on server on port 80

  Serial.println("Setup ready.");
}

//WIRE RESET TO HIGH!!?

void loop() { // run over and over

if(esp8266.available()) // check if the esp is sending a message
  {

    if(esp8266.find("+IPD,"))
    {
     delay(1000);

     int connectionId = esp8266.read()-48; // subtract 48 because the read() function returns
                                           // the ASCII decimal value and 0 (the first decimal number) starts at 48

     String webpage = "
Hello World!
";

     String cipSend = "AT+CIPSEND=";
     cipSend += connectionId;
     cipSend += ",";
     cipSend +=webpage.length();
     cipSend +="\r\n";

     sendData(cipSend,1000,DEBUG);
     sendData(webpage,1000,DEBUG);

     String closeCommand = "AT+CIPCLOSE=";
     closeCommand+= connectionId; // append connection id
     closeCommand+="\r\n";

     sendData(closeCommand,250,DEBUG);
    }
  }

}

String sendData(String command, const int timeout, boolean debug)
{
    String response = "?";
    int pos = -5;

    Serial.println("--------------");
    Serial.println(" sending "+command);

    esp8266.print(command); // send the read character to the esp8266

    long int _timeout = timeout + millis();

    while( (_timeout) > millis())
    {
      while(esp8266.available())
      {
        // The esp has data so display its output to the serial window
        char c = esp8266.read(); // read the next character.
        response+=c;
        pos+=1;
        if(pos>=0 && response.substring(pos) == "\r\nOK\r\n"){
          //WE GOT OK -> stop waiting
          _timeout=0;
        }
      }
    }

    if(debug)
    {
      Serial.println(" response: "+response);
    }

    return response;
}

I might not have understood what you are trying to do, but if it is to use the ESP8266 to allow the Nano to connect to WIFI and act as a web server then I believe you are doing this the hard way.
The ESP8266 is an 80 or 160MHz microprocessor with 64KB Program Ram + 96KB data RAM.  You are using a 16/32MHz microprocessor to generate pages and pass them to it.  I would recommend that you investigate using the Arduino IDE to program the ESP8266 in "Arduino C" it comes with a set of examples that include webservers (which is what I think you are trying to do).  Keep the Nano if the ESP8266s 10 digital and one analogue ports aren't enough to interface to you hardware.

I will need more than one analog input... Could I still use the ESP module as "master", as "Server" and query the Arduino's analog ports over serial connection?

@mvermand if your case allows to read in the analog values one by one (not parallel), you could just use a multiplexer to achieve this - I just did that using an ESP and the HCF4051 - you need 3 control pins to address one of the 8 channels, and then open that to the ESPs ADC. Works just fine and stable.

the esp8266 certainly doesn't have 4 MB of RAM, the highest amount of free RAM I've seen was around 40 kB.

@MightyPork - Quoted the wrong number, corrected it now, but its still more than an Arduino Uno.

I had the same experience. When you send data by an AT command and receive something from another connection at the same time, then the ESP chip starts to behave unexpectedly. Sometimes it sends the data but does not respond with OK. Sometimes it does not send. And sometimes it ignores received data (missing +IPD message).
The AT firmware works only well with single telnet-style connections. I mean half-duplex communication where it never happens that more than one sender is "talking" at the same time.
I hoped that this issue becomes solved over time, but the modules that I bought recently (with AT Firmware 1.4) are still not better. However, I did not notice any unexpected auto-reset or hangup anymore in my 2-Week test loop. At least that became better.

The issue has been solved since SDK 1.5.4, which is used by the Arduino ESP8266 core version 2.3.0.


text:
Arduino with nRF24L01
I am using nRF24L01 with Arduino Nano and Mini. I feel they are very useful when we want to connect multiple Arduinos together.
In market we can buy Arduino with WiFi and Bluetooth, why don't they make Arduino model with nRF24L01? Is there any specific valid reason?
Or am I wrong in using nRF24L01 and there is a better cost and power efficient way to connect multiple Arduinos together wirelessly?

I have updated my answer with two "new" alternatives: NRF51 and NRF52.

NordicRF (the company behind nRF24L01) has released two series of SoC devices that are compatible with nRF24: NRF51 and NRF52. Thanks to the effort by Sandeep Mistry and other contributors, they can be programmed using the Arduino IDE and libraries. Instructions are available here: https://github.com/sandeepmistry/arduino-nRF5
I have tested NRF51822, which is the cheapest variant (costing slightly more than Arduino Pro Mini + NRF24L01+ but in a single small and power-efficient package) and it works great.
The BBC Micro:bit is based on NRF51. More information is available at https://forum.mysensors.org/topic/9722/bbc-micro-bit-and-mysensors-a-great-match
Compared to the Atmega328-based Arduino Pro Mini, NRF51822 has 8x larger flash and 8x larger RAM. It also has Bluetooth 5 and BLE support and a 32-bit ARM Cortex M0 CPU.
There is also this alternative: https://www.ebid.net/eu/for-sale/arduino-ide-compatible-controller-with-the-nordic-nrf24l01-radio-transceiver-156695123.htm
Specifications:

Dimensions 59mm x 18mm
The Nordic nRF24L01+ 2.4 GHz Radio transceiver on board
Supply voltage up to 6.5 Volts
The Digital and Analog pins are 5 volts
ATMega328P frequency is 8 Mhz
4 battery connector pins
FTDI header for programming

Full disclosure: I am member of the MySensors core team. A MySensors user (not affiliated with the core team) created and is selling this board.

The link on the ebid website isn't working anymore. Could you share another link? Also is it still recommended to use this board? Cheers

nRF24L01 is a proprietary system, unlike WiFi and Bluetooth. There is only one (official) maker of nRF devices (Nordic Semiconductor).
Yes, they are very nice modules, but why would you spend the time and money developing a generic microcontroller board that has such limited scope as to only be able to communicate with the same board or one with one specific module attached?  You wouldn't - it doesn't make financial sense - especially when it's easy for an end user to add the module to any other board instead.
Bluetooth and WiFi make more financial sense because there is a huge range of devices that they can communicate with which means they can be used for a far greater range of projects thus increasing demand for them.

Thanks @Majenko. Is there any other module like nRF24L01 which is generic and not propriety. Main thing is I want to explore options but till now i can not find any thing like nRF24L01 which is low cost and low battery.

Bluetooth or WiFi. For low power you want BLE (Bluetooth Low Energy).

BLE will be Master and Slave. I want to create network of few devices.

(New BL supports meshes.) Nordic also sells MCUs that have the transceiver built-in (nRF24LU/LE) so you could use those (like many many wireless mice and keyboards do). I think it's just Nordic that doesn't see value in having an another Arduino board on the market and that's why there's none.

@Avamander i have read online too new Bluetooth 4 supports mesh. But i can not fond even single online page with Bluetooth 4 mesh for Arduino. Do you know nay sample example?

@Rahul It's so new, I doubt you can even get chipsets that support it for normal price. You can just wait for now.


text:
Arduino with ATmega32U4 low power but keep Serial1 working
I am looking for a low power solution for my ATmega32U4. It uses Serial1 to communicate with Bluetooth, so I need to have it active. When I receive data from Serial1, I want to power up the Arduino, do some magic, and then power it off...

Have you had a chance to look at the ATmega32U4 datasheet yet?

Yes a little bit, I hope You will have more xp and can recommend me some.

Use the UART interrupt to wake the MCU....?

For Power Down/Standby Mode you would have to use an Interrupt Pin to reactive the MCU. If you do not mind possible loss of the first character you could connect an Interrupt Pin to Serial1 RX and wake up on the first start bit.
The startup delay (i.e. time until UART is up and working) may impact the first character received. You could always start off by sending a number of null character as a "wake up call"; classical break sequence.
Cheers!
Ref. ATmega16/32U4, Chap. 7. Power Management and Sleep Modes.


text:
How do I get LEDs to turn on according to a continuous Python input?
I'm trying to make a tuner. 3 LEDs are connected to the Arduino board, each one corresponding to one situation (too high, low or correct).
Python handles the detecting of a note according to the mic input, and determines which led should be turned on, but as it's a live tuner, Python sends the information pretty fast.
I've figured out how to turn a led on one at a time and keep it on as long as the input doesn't change, but it only works at a low speed when I do it manually, with a Python program like this :
code=1
while code!=0:
    code=input("Code?")
    ser.write(code.encode('utf-8'))

If I try it with a Python code such as :
code= '5'
while 1:
ser.write(code.encode('utf-8'))

then the LEDs just stay off.
Here is my Arduino Code :
int hauteur = 0;

void setup() {
    pinMode (2, OUTPUT); //red pin
    pinMode (6, OUTPUT); //green pin
    pinMode (5, OUTPUT); //yellow pin
    Serial.begin(9600);
}

void loop() {
    if(Serial.available ()) {
        hauteur = Serial.parseInt();

        while (hauteur==2) {
            (digitalWrite(2,HIGH));
            if (Serial.available ()) { hauteur=Serial.parseInt(); }
        }
        digitalWrite(2,LOW);

        while (hauteur==5){
            (digitalWrite(5,HIGH));
            if (Serial.available ()) { hauteur=Serial.parseInt(); }
        }
        digitalWrite(5,LOW);

        while (hauteur==6){
            (digitalWrite(6,HIGH));
            if (Serial.available ()) { hauteur=Serial.parseInt(); }
        }
        digitalWrite(6,LOW);

        Serial.flush();
    }
}

If 2, 5 or 6 are received with enough time in between them, then the board does what it's supposed to do and turns on the according LED. How can I reduce that necessary lapse of time to get a real time change of lights like a live tuner?

Try to not send only the number, but also a trailing non-digit character as a delimiter (like "\n" the newline character)

what for is the Serial.flush()? you don't output anything on Serial in loop()

make two variables. current pin and next pin. read value in next pin and do nothing if next pin is same as current pin. if they are different set next pin high, current pin low and set current pin to next pin value.

your arduino code is very badly formatted, and therefore hard to read .... please correct the indentation ......... your second python snippet is also badly indented and it will not work as expected

You don't need to parseInt for one digit. Use Serial.read().
  hauteur = Serial.read() - 48; // 48 is ascii code of '0'

or better send bytes from python, not digit characters


text:
Generating 200 kHz pulse on Arduino Uno in normal mode
I need to obtain 200 kHz from Arduino Uno. I am using Timer0. I have configured it to run in normal mode and the Prescaler is set to clk/8 (the clock frequency of Arduino is 16 MHz). TCNT0 is set to 0xFB and the code toggles 2 pins of PORTB as timer overflow flag is set.
Here is my code (I am using Atmel Studio 7):
#include <avr/io.h>

int main(void)
{
   DDRB = 0x03;
   PORTB |= 0x02;
   while (1)
   {
       TCNT0 = 0xFB;
       TCCR0A = 0X00;
       TCCR0B = 0x02;
       while ( (TIFR0 & 0x01) == 0 );
       PORTB ^= 0x03;
       TCCR1A = 0x00;
       TCCR1B = 0x00;
       TIFR0 = 0X01;
  }
}

When I check on the oscilloscope, it shows that the pulse is 166 kHz instead of 200 kHz. Although I can use Fast PWM Mode and use interrupts, I am just curious to know why it doesn't work? Did I make any mistake?

You don’t  even need to use interrupts. Just have the timer toggle one of the two associated pins for you.

That's simple enough - you forgot that everything takes time.
Your timeline is:

Configure timer
Set count
Wait for count to overflow (33 ticks)
Toggle pin
Do something with T1 (why...?)
Clear overflow bit
Go back to 1.

Here's how that looks as assembly:
90: 3b ef           ldi r19, 0xFB
92: 42 e0           ldi r20, 0x02
94: 23 e0           ldi r18, 0x03
96: 91 e0           ldi r25, 0x01

while (1) {
98: 36 bd           out 0x26, r19   ; TCNT0 = 0xFB;
9a: 14 bc           out 0x24, r1    ; TCCR0A = 0X00;
9c: 45 bd           out 0x25, r20   ; TCCR0B = 0x02;

while ( (TIFR0 & 0x01) == 0 );
9e: a8 9b           sbis    0x15, 0
a0: fe cf           rjmp    .-4         ; 0x9e <setup+0xe>

PORTB ^= 0x03;
a2: 85 b1           in  r24, 0x05
a4: 82 27           eor r24, r18
a6: 85 b9           out 0x05, r24

a8: 10 92 80 00     sts 0x0080, r1
ac: 10 92 81 00     sts 0x0081, r1
b0: 95 bb           out 0x15, r25

}
b2: f2 cf           rjmp    .-28

So assuming that the waiting for the timer overflow takes 8*4+
1=33 clock cycles, and referencing the datasheet for how long each instruction takes, we can add up everything in the main while loop:
while (1) {
98: 36 bd           out 0x26, r19   ; 1
9a: 14 bc           out 0x24, r1    ; 1
9c: 45 bd           out 0x25, r20   ; 1

while ( (TIFR0 & 0x01) == 0 );
9e: a8 9b           sbis    0x15, 0 ; 2 (at end)
a0: fe cf           rjmp    .-4     ; 33 (while running)

PORTB ^= 0x03;
a2: 85 b1           in  r24, 0x05   ; 1
a4: 82 27           eor r24, r18    ; 1
a6: 85 b9           out 0x05, r24   ; 1

a8: 10 92 80 00     sts 0x0080, r1  ; 2
ac: 10 92 81 00     sts 0x0081, r1  ; 2
b0: 95 bb           out 0x15, r25   ; 1

}
b2: f2 cf           rjmp    .-28    ; 2

You can see that takes 48 clock cycles (We don't care about what is in the inner while except when it comes to finishing, and that's just the SBIS instruction). For 200kHz you want 40 clock cycles. You have 48. 16000000/48 = 333333. Divide by two for your pin toggling, and you get 166666Hz.
If you want to use this kind of method you need to ensure that the timer is completely free running and the overflow flag gets set at a regular interval, not just at 32 ticks after you start it.
You should be operating in CTC mode so it counts up from 0 to your target value and then resets back to 0 whilst setting the overflow flag. Your loop then looks like:
while (1) {
    if ((TIFR0 & 0x01) == 0x01) {
        PORTB ^= 0x03;
    }
}

All the timer configuration is done before the loop and it just runs and runs until you say otherwise.

Thank You, now I think I understood where I made mistake. Can you explain why waiting for the timer overflow takes 8*4+ 1=33 clock cycles??

@PrabhatNarang 8*4 to get to 0xFF, and the flag gets set on the next clock cycle.


text:
Is it possible to make an arbitrary lake bottom generator?
I'm trying to generate an arbitrary lake bottom sonar returns using my Arduino.
I would like to seed a function with a "depth." This would be the starting depth. I would then like to randomize a set of parameters each time the function is called. The output would look something like a time-truncated sine wave. The parameters would include:

Randomized Amplitude of waveform (which wouldn't vary too much)
Randomized Period (or frequency) of waveform (also wouldn't vary too much)
Randomized exit point. Say the period is 10 seconds but function ends at 7 seconds. This would allow for a changing in depth over time even if random.
If possible, I would like to low pass filter the output to smooth any hard transitions.

Any suggestions on where to get started?

Not sure this is even related to Arduino. electronics.stackexchange.com might be better place.

A common method of generating realistic-ish 3d terrain is as follows:
Start with a square (as seen top-down), described by the lengths of it's side (all the same), and the height of each of the corners.
Divide each edge in half; for example, add a new point halfway between the north-west point and the north-east point; it's altitude will be the average of the altitude of the two existing points, plus or minus a random number.
Now add a point in the center of the existing square; it's altitude being the average of the north, east, west and south points you've just created, plus or minus a random number.
You now have 4 smaller squares. Repeat this process on the four smaller squares, then the smaller squares within that, and so forth.
You might want to manually do the first few points, tweaking it to get the shape you want, then leave the details to the algorithm. Your random number for the adjustments of the "middle point" heights should be proportionate to the length of the sides; for example, the random altitude adjustment might be a random number up to X% the length; then subtract half of X% of the length. Adjusting X% will give you an area that is more or less "pointy".


text:
LEDs: difference between common anode and common cathode?
What is the difference in using a common anode and common cathode of the 7 Segment in interfacing with the Arduino? How can you change the code if we need to add another 7 Segment display?
How can you change the code to have a counter in backwards (from 0 to 9)?
const int ANODE = 2;

const int LED1 = 3;
const int LED2 = 4;   // pin for led 2
const int LED3 = 5;   // pin for led 3
const int LED4 = 6;   // pin for led 4

// now bottom row

const int LED5 = 7;
const int LED6 = 8;
const int LED7 = 9;
const int LED8 = 10;

int DELAY = 0;

void setup() {
  pinMode(ANODE, OUTPUT);  // common anode is obviously an output

  pinMode(LED1, OUTPUT);   // led are output for low will be on
  pinMode(LED2, OUTPUT);   // led 2 is output
  pinMode(LED3, OUTPUT);   // led 3 is output
  pinMode(LED4, OUTPUT);   // led 4 is output
  pinMode(LED5, OUTPUT);   // led 5 is output
  pinMode(LED6, OUTPUT);   // led 6 is output
  pinMode(LED7, OUTPUT);   // led 7 is output
  pinMode(LED8, OUTPUT);   // led 8 is output
}

void loop(){

  if (DELAY == 300){
    delay(100000);
  }

  digitalWrite(ANODE, HIGH);

  digitalWrite(LED1, HIGH);
  digitalWrite(LED2, HIGH);
  digitalWrite(LED3, HIGH);
  digitalWrite(LED4, HIGH);
  digitalWrite(LED5, HIGH);
  digitalWrite(LED6, HIGH);
  digitalWrite(LED7, HIGH);
  digitalWrite(LED8, HIGH);

delay(1000);

  digitalWrite(LED1, LOW);
  delay(500);
  digitalWrite(LED1, HIGH);
  digitalWrite(LED2, LOW);
  delay(500);
  digitalWrite(LED2, HIGH);
  digitalWrite(LED3, LOW);
  delay(500);
  digitalWrite(LED3, HIGH);
  digitalWrite(LED4, LOW);
  delay(500);
  digitalWrite(LED4, HIGH);
  digitalWrite(LED5, LOW);
  delay(500);
  digitalWrite(LED5, HIGH);
  digitalWrite(LED6, LOW);
  delay(500);
  digitalWrite(LED6, HIGH);
  digitalWrite(LED7, LOW);
  delay(500);
  digitalWrite(LED7, HIGH);
  digitalWrite(LED8, LOW);
  delay(500);
  digitalWrite(LED8, HIGH);

  delay(100);

  DELAY = DELAY + 150;
}

A 7-segment is a packaged set of 8 LEDs (7 number-segments & 1 decimal point). Common anode means that the anode (positive) side of all of the LEDs are electrically connected at one pin, and each LED cathode has its own pin. So turning on any particular segment will involve running a current from this common anode (positive) pin to the particular cathode (negative) pin for the desired segment.

Common cathode means that the cathodes of all of the LEDs are common and connected to a single pin. The anode for each LED has its own pin. So driving one of these means running a current from the particular anode (positive) pin for the desired segment to the common cathode pin.

The way that you are diving the 7-segment involves using a separate pin to drive each segment, so you use 8 pins of the Arduino to drive the display. You will run out of digital pins if you try to add a second 7-segment. There are a couple of ways to address this. One is to add a 7-segment driver, like the CD4511. This limits you to being able to display only numerical digits, but uses only 4 pins of the Arduino per 7-segment.
Another, more versatile way is to add a serial-in to parallel out chip (74HC595, for example) to drive the 7-segment. This requires only two pins from the Arduino (data & clock), and they can be chained to have multiple 7-segments driven from those same 2 pins.

Here's an example of using the CD4511 driver method: https://123d.circuits.io/circuits/912097
Here's an example of the serial-in to parallel-out (74HC595) method: https://123d.circuits.io/circuits/583641

Spent an hour trying to work it out, seems I have common anode leds.
So you have to connect the anode to the 5V (on arduino),
The voltages are then reversed, so use 255-v instead of v.
I think common cathode will be easier to understand and program for.

Basically you just need to change the HIGH's by LOW's and the LOW's by HIGH's.

To add to the existing answers:

For the arduino with [its] symmetrical ability to source and sink exactly the same amount of current then there is no preferred way.

Grumpy_Mike on Arudino forums

That being said, if you are using a driver circuit like the MAX7219 (which makes interfacing many digits much simpler and requires far fewer pins), use the one specified by the datasheet. For example, the MAX7219 is designed to drive common-cathode LED displays.

You can easily test this in 123D Circuits, check this out:
https://123d.circuits.io/circuits/1019227-7-segment-circuit
Click start simulation and then click on the buttons to light up the corresponding segment.

I'm not convinced this addresses the question at all.


text:
Arduino coding of producing frequency
Im new here. Anyone that could give a code or sample that would generate I wanted to use a frequency in range of 35k-43kHz. Please help me.

Sound a lot like an IR carrier wave.

The code below generates 38 kHz and modulates its duty cycle.
// Example of modulating a 38 kHz frequency duty cycle by reading a potentiometer
// Author: Nick Gammon
// Date: 24 September 2012

const byte POTENTIOMETER = A0;
const byte LED = 10;  // Timer 1 "B" output: OC1B

// Clock frequency divided by 38 kHz frequency desired
const long timer1_OCR1A_Setting = F_CPU / 38000L;

void setup()
 {
  pinMode (LED, OUTPUT);

  // set up Timer 1 - gives us 38.005 kHz
  // Fast PWM top at OCR1A
  TCCR1A = bit (WGM10) | bit (WGM11) | bit (COM1B1); // fast PWM, clear OC1B on compare
  TCCR1B = bit (WGM12) | bit (WGM13) | bit (CS10);   // fast PWM, no prescaler
  OCR1A =  timer1_OCR1A_Setting - 1;                 // zero relative
  }  // end of setup

void loop()
  {
  // alter Timer 1 duty cycle in accordance with pot reading
  OCR1B = (((long) (analogRead (POTENTIOMETER) + 1) * timer1_OCR1A_Setting) / 1024L) - 1;

  // do other stuff here
  }

Just to add; this code works for pin 10, and pin 10 alone.

I connected the output to the ultrasonic transmitter but its not working. here is the transmitter specification that i used (http://www.farnell.com/datasheets/1498178.pdf) and the circuit diagram (https://www.google.com.ph/search?q=ultrasonic+circuit&espv=2&biw=1366&bih=643&source=lnms&tbm=isch&sa=X&ved=0ahUKEwjoivap6-fJAhUK-2MKHdFeAFwQ_AUIBigB#tbm=isch&q=ultrasonic+transmitter+circuit+diagram&imgrc=fLTfT6_BQfBMyM%3A)

Not working? How do you know? Are you getting 38 kHz out of the Arduino or not? You would need an oscilloscope to check.

use the 'tone' function:
arduino tone function
example:
//tone(pinNumber, FrequencyInHertz);
tone(6, 35000); //generate a 35kHz tone on pin 6
delay(10);
tone(6, 43000); //generate a 43kHz tone on pin 6

Could you elaborate a bit? This is basically a link-only answer which would not be helpful if the link went down.

I wanted to generate a set of high frequency at the range of 25k-60k Hz using the arduino uno. Please help me. What function do i use? I'm a newbie on coding and if anyone would share some code it would be a great help. Im very thankful.

@user13535 You now say 25k-60kHz, but your question says 38k-43kHz. Which is it?

The 25k-60k Hz. I change the range.

This is meant to be a comment, but I can't put (pseudo) code in a comment.
A 40 kHz square wave? Simple:
for(;;){
   wait ( 1 / 2 * 40.000 );
   make pin high;
   wait ( 1 / 2 * 40.000 );
   make pin low;
}


text:
Powering arduino and 12V Fan from same supply
I have found a relatively small 12V switching power supply that I want to build into my device, using it to power both the Arduino Pro Mini and a couple of 12V cpu fans.
Am I correct in assuming that I can have the Arduino RAW pin and Fan+ on the same power supply lead? Or do I need to protect the Raw pin in any way? Also, I need to power 2x cpu fans, can this be done with one transistor or do I need one for each fan?
If I stay within the Current specs of my supply (6A) could I keep adding other 12V components on the same +lead as in the diagram below?

Sounds fine.
You can connect the two fans in parallel, as long as they don't use more than 5A combined, as that is the maximum of the TIP120. Though you definitely need to attach a heatsink to the TIP120, if you are using a largish amount of current. Though in that case, I'd suggest using a MOSFET instead of a Darlington Transistor (TIP120), as MOSFETs don't heat up that much.
The diode is not needed if you use the TIP120, as there is already a diode inside the package.
Since you are using 12V as a power supply, the voltage regulator has to convert 7v into heat. Depending on the amount of current you use, this could result in the voltage regulator getting very hot. If you are only powering the ATMega328 and maybe some LEDs from the 5v line, you'll be fine. Just don't connect something like a 5v fan.

I see, thank you. Out of curiosity, if I would want to connect some 5v fan, how would I go about protecting the built in regulator from overheating? Should I but some resistors on the RAW pin to make the 12v line go down to 5v before entering the arduino? I guess that would make the much cheaper resistors handle dissipation?

Just bypass the onboard 5v regulator, and use an external voltage regulator in e.g. a TO-220. Depending on the load, you can easily add a heatsink to this TO-220 package. Connect the 5v output of the external regulator, to the 5v pin on the arduino board.

The board will take 12V, but the regulator will have to dissipate (as in heat) the excess power.
However, how much do you trust your power supply to not exceed the 12V?
The same applies to the other loads.
About max current, you should do the math for both typical case and peak case. Ex: the fan will draw much more current if for any reason it is stopped.
If you use only 1 transistor, you will get both fans to behave in the same way, because you will be using only 1 control line. Is this what you want?

I think I trust the supply, I'm a trusty person :).
I don't need to control the fans separately, in fact the PCR PID system I'm building would benefit from both fans being in sync. I guess that having only one transistor the fans would get max 6V and thus run at half capacity?
Since the Arduino itself really doesnt need the 12V, should I put a resistor on the RAW pin to limit power supply voltage?

Why would the fan get 6V?

Yes, you can put a resistor. You could also put a zener, to clip just the extra voltage.

I was thinking that I had to connect the fans in serial and that it would mean they got half the voltage each. but I guess I could just connect them both to the Collector of the transistor?
But would I need to put a resistor/zener to protect the Arduino, or will it work without it, is it considered good practice?

Why wouldn't you trust a 12v switching power supply? Maximum voltage of the mic5205 is 16Volt (absolute maximum 20Volt). Using a zener is a very crude way to make a voltage regulator. If anything, I'd just add one or two diodes. Those will drop the voltage by around 0.6Volt each. Added bonus is, that it will protect your board in case you accidentally connect the powersupply the wrong way around.

I see. So I would put two diodes in serial on the RAW pin?


text:
Can't add more code to loop() when use server.handleClient
Here's my code
void loop() {
  if (analogRead(A0) > 500)
  {
    statuss = true ;
  }
  if (statuss)
  {
    digitalWrite(D7, HIGH);
    if (millis() - lasttime > 500)
    {
      digitalWrite(D8, etat);
      digitalWrite(D6, etat);
      etat = !etat;
      lasttime = millis();
    }
  }
  server.handleClient();
}

When I use only server.handleClient everything works fine but when I add any type of code to the loop() function the server goes down and I can't see the ESP8266 access point.

what is any type of code ?  .... also,  you have not asked a question.

when i use only server.handleClient .... your code has other commands ... your statement does not make sense

that's the problem with close reason "Unclear what you are asking". for me it is totally clear about what this question is. and I am glad it is not closed yet

@Juraj, i am trying to understand .... if, for example, the OP adds a serial.print() statement to the loop(), then the server goes down ..... how is that clear to you? .... have you had similar experience?

@jsotola, read my answer

that is a specific command, not "any type of code" .... maybe the translation from OP's language is the blame, but it is still unclear what is being asked

@gre_gor, sempaiscuba, VE7JRO, MatsK, per123, you closed this question without evaluating/testing. the Question says: "if I run this code the esp8266 disappears from the WiFi network". and it is true. the question is "why?, what should I change?"

@jsotola, yes, asker didn't do the troubleshooting to reduce the code to minimum. he deserves the downvotes

Voting to re-open and +1 for your answer Juraj.

The problem is analogRead. The esp8266 uses the ADC to evaluate the strength of the WiFi signal. Hard use of analogRead disturbs it and the signal goes down. Use millis() to time analogRead.
unsigned int tempSensRead() {

  const unsigned long MEASURE_INTERVAL = 2L * 1000 * 60; // 2 minutes
  static unsigned long lastMeasureMillis;
  static unsigned int lastValue;

  if (millis() - lastMeasureMillis > MEASURE_INTERVAL) {
    lastMeasureMillis = millis();
    lastValue = analogRead(A0);
  }
  return lastValue;
}

@fakherhabib, some feedback please

Nice answer. Do you know any sources which confirm the statement "esp8266 uses the ADC to evaluate the strength of the WiFi signal"? I couldn't find this on the datasheet

https://arduino-esp8266.readthedocs.io/en/latest/reference.html#analog-input

Excellent resource, thanks.


text:
Arduino Nano PWM pin not functioning
I am building a project using an Arduino Nano. In it, I am using pin 3 as PWM output. However, If I supply values lower than 255 to it, the pin does not output any voltage at all.
According to this diagram, pin 3 is PWM:

I have tested it on two boards, it doesn't function on either one. It's not my sketch, either (I tested it with a simple analogWrite();).
This is the code:
void setup() {
  // put your setup code here, to run once:
  #define E1 3  // Enable Pin for motor 1
  #define E2 10  // Enable Pin for motor 2
  #define I1 4  // Control pin 1 for motor 1
  #define I2 2  // Control pin 2 for motor 1
  #define I3 A1  // Control pin 1 for motor 2
  #define I4 A0  // Control pin 2 for motor 2
}

void loop() {
  // put your main code here, to run repeatedly:
  // I use differential steering, speed is important
  analogWrite(E1, 100); // Run in full speed
  analogWrite(E2, 100); // Run in full speed

  // always go forward
  digitalWrite(I1, LOW);
  digitalWrite(I2, HIGH);
  digitalWrite(I3, LOW);
  digitalWrite(I4, HIGH);
}

What could be the reason of this?

Request this to be moved to the arduino stackexchange

@JorenVaes how do I do this?

No code shown. What in the world are we supposed to speculate about then?

@Bort sorry, added the code.

Try to replace #define E1 3 with #define E1 PD3 and see if that helps.

@Dampmaskin that worked! I do not know why, as i use pin 10 by simply declaring it as "10". Could you post this as an answer so I can close the question?

Try to replace #define E1 3 with #define E1 PD3 and see if that helps.
The PBx, PCx and PDx designations are unambiguous, so using those are pretty much a safe bet.

This is absolutely wrong advice. Arduino functions take Arduino pin numbers. In this case it just happened to work because PD3 is #defined as 3 and the Arduino pin number is also 3. Try using PB2 instead of the Arduino pin number 10 if you don't believe me. They are not even unambiguous. Those designators are just defined as the bit numbers (e.g. PB3 is also 3).

The third pin (pin 3) is not a PWM pin, it is the RESET pin.
The PWM pins are 6, 8, 9, 12, 13 and 14 (for Arduino Nano).
See this image:

Shortened URL redirects to https://images.google.co.in/imgres?imgurl=http%3A%2F%2Fwww.ifuturetech.org%2Fifuture%2Fuploads%2F2014%2F03%2FArduino-nano-Pinout.png&imgrefurl=http%3A%2F%2Fwww.ifuturetech.org%2Fproduct%2Farduino-nano-v3-0%2F&docid=domJNeoO6sP-cM&tbnid=jRej863j-6l5rM%3A&vet=1&w=642&h=377&source=sh%2Fx%2Fim so not much point to replacing it.

@Carolene according to the schematic given by the OP, pin 3 means digital pin 3 = PORTD 3.  The part of your answer "The PWM pins are 6, 8, 9, 12, 13 and 14 (for Arduino Nano)" is completely misleading.

Use pinMode(NNN, OUTPUT) at setup()?

Hi Denis, and welcome to Stack Exchange! Whilst you may be correct, please expand upon your answer, because as it stands it would be more suited as a comment. Please read How do I write a good answer?

This is a good answer, the PIN MODE is missing.

Replace digitalWrite with analogWrite(pin, value)

I'm not sure why you think this would work. Did you read the accepted answer above or the comments under the question?