text:
Seeburg Consolette Jukebox
I am working on a Seeburg Jukebox wall unit, I have it playing one track at a time form a SD card no problem. But what I need help with being new to programming is:
1. The code is long because it can play 160 songs.
2. would be nice to have it line up the next selection if possible.
Any help with this code would be appreciated.
#include <SD.h>
#include <SPI.h>
#include <Adafruit_VS1053.h>

#define BREAKOUT_RESET  9      // VS1053 reset pin (output)
#define BREAKOUT_CS     10     // VS1053 chip select pin (output)
#define BREAKOUT_DCS    8      // VS1053 Data/command select pin (output)
#define SHIELD_RESET  -1      // VS1053 reset pin (unused!)
#define SHIELD_CS     7      // VS1053 chip select pin (output)
#define SHIELD_DCS    6      // VS1053 Data/command select pin (output)
#define CARDCS 4     // Card chip select pin
#define DREQ 3       // VS1053 Data request, ideally an Interrupt pin
Adafruit_VS1053_FilePlayer musicPlayer =
Adafruit_VS1053_FilePlayer(SHIELD_RESET, SHIELD_CS, SHIELD_DCS, DREQ, CARDCS);

int opto = 18;

void setup() {
  Serial.begin(9600);
  if (! musicPlayer.begin()) {}
  if (!SD.begin(CARDCS)) {}

  musicPlayer.setVolume(1,1);

  pinMode(opto, INPUT); //initialize the digital pin as an input from the opto-isolator.
  digitalWrite(opto, HIGH);} //turns on the internal pull up resistor.

void loop() {

  int number = 0;  // counts the alphabet pulses
  int letter = 0;  // counts the digit pulses.
  int buffer[4] = {1,1,1,1}; // buffer for reading input. If 4 reads in a row are all the same it is valid input.
  int buffndx = 0;
  int pausecnt = 0; // counts the number of HIGHs read in.
  int maxpause = 30; // when pausecnt reaches maxpause we are at the pause between alpa and numeric or else we are at the end of transmission.
  int countpause = false;
  buffer[0] = 1;
  buffer[1] = 1;
  buffer[2] = 1;
  buffer[3] = 1;

Serial.println("SEEBURG CONSOLETTE JUKEBOX");

  //Number loop//
  while( pausecnt < maxpause ) {
     buffer[buffndx] = digitalRead(opto); // read the input pin
     if(buffer[buffndx] != 1){}
    delay(8); // space out the reads a little.
     buffndx++;
     if (buffndx == 4) buffndx = 0; // rotate the buffer index.
     if ((buffer[0] == 0) && (buffer[1] == 0) && (buffer[2] == 0) && (buffer[3] == 0) ){ // we got valid input so proccess it.
        pausecnt = 0; // we got our pulse so restart the clock for the next one.
        number++; //increment the number counter.
        while(! ((buffer[0] == 1 ) && (buffer[1] == 1) && (buffer[2] == 1) && (buffer[3] == 1)) ) { //Loop until we get a valid HIGH
        buffer[buffndx] = digitalRead(opto); // read the input pin
        buffndx++; // rotate the buffer index
    if (buffndx == 4) buffndx = 0;} // rotate the buffer index.
        countpause = true; //we are receiving input so start counting pauses instead of looping forever.
        continue;}else{
    if (countpause == true) pausecnt++;}} // else no valid input

  // Letter Loop//
    pausecnt = 0;   // Reset the pausent counter. Ready for the next stream of pulses to arrive.
    countpause = false; // loop forever until a pulse is recieved.
    while( pausecnt < maxpause ) { // Begin the digit loop
    buffer[buffndx] = digitalRead(opto); // read the input pin
    delay(8);
    buffndx++;
    if (buffndx == 4) buffndx = 0; // rotate the buffer index.
    if ((buffer[0] == 0) && (buffer[1] == 0) && (buffer[2] == 0) && (buffer[3] == 0) ){ // we got valid input so proccess it.
        pausecnt = 0; // we got our pulse so restart the clock for the next one.
        letter++; //increment the aphabet counter.
        while(! ((buffer[0] == 1) && (buffer[1] == 1) && (buffer[2] == 1) && (buffer[3] == 1)) ) { //Loop until we get a valid HIGH
        buffer[buffndx] = digitalRead(opto); // read the input pin
        buffndx++; // rotate the buffer index
    if (buffndx == 4) buffndx = 0;} // rotate the buffer index.
        countpause = true; //we are receiving input so start counting pauses instead of looping forever.
        continue;}else{
     if (countpause == true) pausecnt++;} // else no valid input// else no valid input

  }

 //change signal//
    {number = 10 - number;
    letter = 21 - letter;}

  String signal = "";

  if(letter == 1) signal += "A";
  if(letter == 2) signal += "B";
  if(letter == 3) signal += "C";
  if(letter == 4) signal += "D";
  if(letter == 5) signal += "E";
  if(letter == 6) signal += "F";
  if(letter == 7) signal += "G";
  if(letter == 8) signal += "H";
  if(letter == 9) signal += "J";
  if(letter == 10) signal += "K";
  if(letter == 11) signal += ("L");
  if(letter == 12) signal += ("M");
  if(letter == 13) signal += ("N");
  if(letter == 14) signal += ("P");
  if(letter == 15) signal += ("Q");
  if(letter == 16) signal += ("R");
  if(letter == 17) signal += ("S");
  if(letter == 18) signal += ("T");
  if(letter == 19) signal += ("U");
  if(letter == 20) signal += ("V");

  signal += String(number);
  Serial.println(signal);
  delay(1000);

        //////////A////////////
   if(letter == 1 && number == 1);
   {musicPlayer.playFullFile("A1.mp3");}

   if(letter == 1 && number == 2);
   {musicPlayer.playFullFile("A2.mp3");}

   if(letter == 1 && number == 3);
   {musicPlayer.playFullFile("A3.mp3");}

   if(letter == 1 && number == 4);
  {musicPlayer.playFullFile("A4.mp3");}

   if(letter == 1 && number == 5);
  {musicPlayer.playFullFile("A5.mp3");}

   if(letter == 1 && number == 6);
  {musicPlayer.playFullFile("A6.mp3");}

   if(letter == 1 && number == 7);
  {musicPlayer.playFullFile("A7.mp3");}

   if(letter == 1 && number == 8);
   {musicPlayer.playFullFile("A8.mp3");}

           //////////B////////////
   if(letter == 2 && number == 1);
   {musicPlayer.playFullFile("B1.mp3");}

   if(letter == 2 && number == 2);
   {musicPlayer.playFullFile("B2.mp3");}

   if(letter == 2 && number == 3);
   {musicPlayer.playFullFile("B3.mp3");}

   if(letter == 2 && number == 4);
   {musicPlayer.playFullFile("B4.mp3");}

   if(letter == 2 && number == 5);
   {musicPlayer.playFullFile("B5.mp3");}

   if(letter == 2 && number == 6);
  {musicPlayer.playFullFile("B6.mp3");}

   if(letter == 2 && number == 7);
   {musicPlayer.playFullFile("B7.mp3");}

   if(letter == 2 && number == 8);
   {musicPlayer.playFullFile("B8.mp3");}

    //////////C////////////
   if(letter == 3 && number == 1);
   {musicPlayer.playFullFile("C1.mp3");}

   if(letter == 3 && number == 2);
   {musicPlayer.playFullFile("C2.mp3");}

   if(letter == 3 && number == 3);
   {musicPlayer.playFullFile("C3.mp3");}

   if(letter == 3 && number == 4);
   {musicPlayer.playFullFile("C4.mp3");}

   if(letter == 3 && number == 5);
   {musicPlayer.playFullFile("C5.mp3");}

   if(letter == 3 && number == 6);
    {musicPlayer.playFullFile("C6.mp3");}

   if(letter == 3 && number == 7);
    {musicPlayer.playFullFile("C7.mp3");}

   if(letter == 3 && number == 8);
    {musicPlayer.playFullFile("C8.mp3");}

       //////////D////////////
   if(letter == 4 && number == 1);
   {musicPlayer.playFullFile("D1.mp3");}

   if(letter == 4 && number == 2);
   {musicPlayer.playFullFile("D2.mp3");}

   if(letter == 4 && number == 3);
   {musicPlayer.playFullFile("D3.mp3");}

   if(letter == 4 && number == 4);
   {musicPlayer.playFullFile("D4.mp3");}

   if(letter == 4 && number == 5);
   {musicPlayer.playFullFile("D5.mp3");}

   if(letter == 4 && number == 6);
   {musicPlayer.playFullFile("D6.mp3");}

   if(letter == 4 && number == 7);
   {musicPlayer.playFullFile("D7.mp3");}

   if(letter == 4 && number == 8);
   {musicPlayer.playFullFile("D8.mp3");}

       //////////E////////////
   if(letter == 5 && number == 1);
   {musicPlayer.playFullFile("E1.mp3");}

   if(letter == 5 && number == 2);
   {musicPlayer.playFullFile("E2.mp3");}

   if(letter == 5 && number == 3);
   {musicPlayer.playFullFile("E3.mp3");}

   if(letter == 5 && number == 4);
   {musicPlayer.playFullFile("E4.mp3");}

   if(letter == 5 && number == 5);
   {musicPlayer.playFullFile("E5.mp3");}

   if(letter == 5 && number == 6);
   {musicPlayer.playFullFile("E6.mp3");}

   if(letter == 5 && number == 7);
   {musicPlayer.playFullFile("E7.mp3");}

   if(letter == 5 && number == 8);
   {musicPlayer.playFullFile("E8.mp3");}

          //////////F////////////
   if(letter == 6 && number == 1);
   {musicPlayer.playFullFile("F1.mp3");}

   if(letter == 6 && number == 2);
   {musicPlayer.playFullFile("F2.mp3");}

   if(letter == 6 && number == 3);
   {musicPlayer.playFullFile("F3.mp3");}

   if(letter == 6 && number == 4);
   {musicPlayer.playFullFile("F4.mp3");}

   if(letter == 6 && number == 5);
   {musicPlayer.playFullFile("F5.mp3");}

   if(letter == 6 && number == 6);
   {musicPlayer.playFullFile("F6.mp3");}

   if(letter == 6 && number == 7);
   {musicPlayer.playFullFile("F7.mp3");}

   if(letter == 6 && number == 8);
   {musicPlayer.playFullFile("F8.mp3");}

          //////////G////////////
   if(letter == 7 && number == 1);
  {musicPlayer.playFullFile("G1.mp3");}

  if(letter == 7 && number == 2);
  {musicPlayer.playFullFile("G2.mp3");}

  if(letter == 7 && number == 3);
  {musicPlayer.playFullFile("G3.mp3");}

  if(letter == 7 && number == 4);
  {musicPlayer.playFullFile("G4.mp3");}

  if(letter == 7 && number == 5);
  {musicPlayer.playFullFile("G5.mp3");}

  if(letter == 7 && number == 6);
  {musicPlayer.playFullFile("G6.mp3");}

  if(letter == 7 && number == 7);
  {musicPlayer.playFullFile("G7.mp3");}

  if(letter == 7 && number == 8);
  {musicPlayer.playFullFile("G8.mp3");}

            //////////H//////////;//
   if(letter == 8 && number == 1);
  {musicPlayer.playFullFile("H1.mp3");}

  if(letter == 8 && number == 2);
  {musicPlayer.playFullFile("H2.mp3");}

  if(letter == 8 && number == 3);
  {musicPlayer.playFullFile("H3.mp3");}

  if(letter == 8 && number == 4);
  {musicPlayer.playFullFile("H4.mp3");}

  if(letter == 8 && number == 5);
  {musicPlayer.playFullFile("H5.mp3");}

  if(letter == 8 && number == 6);
  {musicPlayer.playFullFile("H6.mp3");}

  if(letter == 8 && number == 7);
  {musicPlayer.playFullFile("H7.mp3");}

  if(letter == 8 && number == 8);
  {musicPlayer.playFullFile("H8.mp3");}

            //////////J//////////;//
   if(letter == 9 && number == 1);
  {musicPlayer.playFullFile("J1.mp3");}

  if(letter == 9 && number == 2);
  {musicPlayer.playFullFile("J2.mp3");}

  if(letter == 9 && number == 3);
  {musicPlayer.playFullFile("J3.mp3");}

  if(letter == 9 && number == 4);
  {musicPlayer.playFullFile("J4.mp3");}

  if(letter == 9 && number == 5);
  {musicPlayer.playFullFile("J5.mp3");}

  if(letter == 9 && number == 6);
  {musicPlayer.playFullFile("J6.mp3");}

  if(letter == 9 && number == 7);
  {musicPlayer.playFullFile("J7.mp3");}

  if(letter == 9 && number == 8);
  {musicPlayer.playFullFile("J8.mp3");}

            //////////K////////////
   if(letter == 10 && number == 1);
  {musicPlayer.playFullFile("K1.mp3");}

  if(letter == 10 && number == 2);
  {musicPlayer.playFullFile("K2.mp3");}

  if(letter == 10 && number == 3);
  {musicPlayer.playFullFile("K3.mp3");}

  if(letter == 10 && number == 4);
  {musicPlayer.playFullFile("K4.mp3");}

  if(letter == 10 && number == 5);
  {musicPlayer.playFullFile("K5.mp3");}

  if(letter == 10 && number == 6);
  {musicPlayer.playFullFile("K6.mp3");}

  if(letter == 10 && number == 7);
  {musicPlayer.playFullFile("K7.mp3");}

  if(letter == 10 && number == 8);
  {musicPlayer.playFullFile("K8.mp3");}

              //////////L////////////
   if(letter == 11 && number == 1);
  {musicPlayer.playFullFile("L1.mp3");}

  if(letter == 11 && number == 2);
  {musicPlayer.playFullFile("L2.mp3");}

  if(letter == 11 && number == 3);
  {musicPlayer.playFullFile("L3.mp3");}

  if(letter == 11 && number == 4);
  {musicPlayer.playFullFile("L4.mp3");}

  if(letter == 11 && number == 5);
  {musicPlayer.playFullFile("L5.mp3");}

  if(letter == 11 && number == 6);
  {musicPlayer.playFullFile("L6.mp3");}

  if(letter == 11 && number == 7);
  {musicPlayer.playFullFile("L7.mp3");}

  if(letter == 11 && number == 8);
  {musicPlayer.playFullFile("L8.mp3");}

              //////////M////////////
   if(letter == 12 && number == 1);
  {musicPlayer.playFullFile("M1.mp3");}

  if(letter == 12 && number == 2);
  {musicPlayer.playFullFile("M2.mp3");}

  if(letter == 12 && number == 3);
  {musicPlayer.playFullFile("M3.mp3");}

  if(letter == 12 && number == 4);
  {musicPlayer.playFullFile("M4.mp3");}

  if(letter == 12 && number == 5);
  {musicPlayer.playFullFile("M5.mp3");}

  if(letter == 12 && number == 6);
  {musicPlayer.playFullFile("M6.mp3");}

  if(letter == 12 && number == 7);
  {musicPlayer.playFullFile("M7.mp3");}

  if(letter == 12 && number == 8);
  {musicPlayer.playFullFile("M8.mp3");}

              //////////N////////////
   if(letter == 13 && number == 1);
  {musicPlayer.playFullFile("N1.mp3");}

  if(letter == 13 && number == 2);
  {musicPlayer.playFullFile("N2.mp3");}

  if(letter == 13 && number == 3);
  {musicPlayer.playFullFile("N3.mp3");}

  if(letter == 13 && number == 4);
  {musicPlayer.playFullFile("N4.mp3");}

  if(letter == 13 && number == 5);
  {musicPlayer.playFullFile("N5.mp3");}

  if(letter == 13 && number == 6);
  {musicPlayer.playFullFile("N6.mp3");}

  if(letter == 13 && number == 7);
  {musicPlayer.playFullFile("N7.mp3");}

  if(letter == 13 && number == 8);
  {musicPlayer.playFullFile("N8.mp3");}

              //////////P////////////
   if(letter == 14 && number == 1);
  {musicPlayer.playFullFile("P1.mp3");}

  if(letter == 14 && number == 2);
  {musicPlayer.playFullFile("P2.mp3");}

  if(letter == 14 && number == 3);
  {musicPlayer.playFullFile("P3.mp3");}

  if(letter == 14 && number == 4);
  {musicPlayer.playFullFile("P4.mp3");}

  if(letter == 14 && number == 5);
  {musicPlayer.playFullFile("P5.mp3");}

  if(letter == 14 && number == 6);
  {musicPlayer.playFullFile("P6.mp3");}

  if(letter == 14 && number == 7);
  {musicPlayer.playFullFile("P7.mp3");}

  if(letter == 14 && number == 8);
  {musicPlayer.playFullFile("P8.mp3");}

              //////////Q////////////
   if(letter == 15 && number == 1);
  {musicPlayer.playFullFile("Q1.mp3");}

  if(letter == 15 && number == 2);
  {musicPlayer.playFullFile("Q2.mp3");}

  if(letter == 15 && number == 3);
  {musicPlayer.playFullFile("Q3.mp3");}

  if(letter == 15 && number == 4);
  {musicPlayer.playFullFile("Q4.mp3");}

  if(letter == 15 && number == 5);
  {musicPlayer.playFullFile("Q5.mp3");}

  if(letter == 15 && number == 6);
  {musicPlayer.playFullFile("Q6.mp3");}

  if(letter == 15 && number == 7);
  {musicPlayer.playFullFile("Q7.mp3");}

  if(letter == 15 && number == 8);
  {musicPlayer.playFullFile("Q8.mp3");}

              //////////R////////////
   if(letter == 16 && number == 1);
  {musicPlayer.playFullFile("R1.mp3");}

  if(letter == 16 && number == 2);
  {musicPlayer.playFullFile("R2.mp3");}

  if(letter == 16 && number == 3);
  {musicPlayer.playFullFile("R3.mp3");}

  if(letter == 16 && number == 4);
  {musicPlayer.playFullFile("R4.mp3");}

  if(letter == 16 && number == 5);
  {musicPlayer.playFullFile("R5.mp3");}

  if(letter == 16 && number == 6);
  {musicPlayer.playFullFile("R6.mp3");}

  if(letter == 16 && number == 7);
  {musicPlayer.playFullFile("R7.mp3");}

  if(letter == 16 && number == 8);
  {musicPlayer.playFullFile("R8.mp3");}

              //////////S////////////
   if(letter == 17 && number == 1);
  {musicPlayer.playFullFile("S1.mp3");}

  if(letter == 17 && number == 2);
  {musicPlayer.playFullFile("S2.mp3");}

  if(letter == 17 && number == 3);
  {musicPlayer.playFullFile("S3.mp3");}

  if(letter == 17 && number == 4);
  {musicPlayer.playFullFile("S4.mp3");}

  if(letter == 17 && number == 5);
  {musicPlayer.playFullFile("S5.mp3");}

  if(letter == 17 && number == 6);
  {musicPlayer.playFullFile("S6.mp3");}

  if(letter == 17 && number == 7);
  {musicPlayer.playFullFile("S7.mp3");}

  if(letter == 17 && number == 8);
  {musicPlayer.playFullFile("S8.mp3");}

              //////////T////////////
   if(letter == 18 && number == 1);
  {musicPlayer.playFullFile("T1.mp3");}

  if(letter == 18 && number == 2);
  {musicPlayer.playFullFile("T2.mp3");}

  if(letter == 18 && number == 3);
  {musicPlayer.playFullFile("T3.mp3");}

  if(letter == 18 && number == 4);
  {musicPlayer.playFullFile("T4.mp3");}

  if(letter == 18 && number == 5);
  {musicPlayer.playFullFile("T5.mp3");}

  if(letter == 18 && number == 6);
  {musicPlayer.playFullFile("T6.mp3");}

  if(letter == 18 && number == 7);
  {musicPlayer.playFullFile("T7.mp3");}

  if(letter == 18 && number == 8);
  {musicPlayer.playFullFile("T8.mp3");}

              //////////U////////////
   if(letter == 19 && number == 1);
  {musicPlayer.playFullFile("U1.mp3");}

  if(letter == 19 && number == 2);
  {musicPlayer.playFullFile("U2.mp3");}

  if(letter == 19 && number == 3);
  {musicPlayer.playFullFile("U3.mp3");}

  if(letter == 19 && number == 4);
  {musicPlayer.playFullFile("U4.mp3");}

  if(letter == 19 && number == 5);
  {musicPlayer.playFullFile("U5.mp3");}

  if(letter == 19 && number == 6);
  {musicPlayer.playFullFile("U6.mp3");}

  if(letter == 19 && number == 7);
  {musicPlayer.playFullFile("U7.mp3");}

  if(letter == 19 && number == 8);
  {musicPlayer.playFullFile("U8.mp3");}

            //////////V////////////
   if(letter == 20 && number == 1);
  {musicPlayer.playFullFile("V1.mp3");}

  if(letter == 20 && number == 2);
  {musicPlayer.playFullFile("V2.mp3");}

  if(letter == 20 && number == 3);
  {musicPlayer.playFullFile("V3.mp3");}

  if(letter == 20 && number == 4);
  {musicPlayer.playFullFile("V4.mp3");}

  if(letter == 20 && number == 5);
  {musicPlayer.playFullFile("V5.mp3");}

  if(letter == 20 && number == 6);
  {musicPlayer.playFullFile("V6.mp3");}

  if(letter == 20 && number == 7);
  {musicPlayer.playFullFile("V7.mp3");}

  if(letter == 20 && number == 8);
  {musicPlayer.playFullFile("V8.mp3");}
}

I'm trying to start a similar project - I'm wondering if you could point me to where you got your hardware interface information? Thanks in advance!

This answer only involves help for the first problem:

The code is long because it can play 160 songs

Also, you can align your code by selecting it and press Ctrl-K.
I will go part by part to improve it (leaving the manual work to you):
Align code
#define BREAKOUT_RESET  9      // VS1053 reset pin (output)
#define BREAKOUT_CS     10     // VS1053 chip select pin (output)
#define BREAKOUT_DCS    8      // VS1053 Data/command select pin (output)
#define SHIELD_RESET  -1      // VS1053 reset pin (unused!)

Align this code, making all the values under each other nicely and comments starting at the same column.
Use for loop
  buffer[0] = 1;
  buffer[1] = 1;
  buffer[2] = 1;
  buffer[3] = 1;

You can use a for loop, like:
for (int n = 0; n < 4; n++)
{
    buffer[n] = 1;
}

However, you can remove this code, since the values are already initialized in:
int buffer[4] = {1,1,1,1}; // buffer for reading input. If 4 reads in a row are all the same it is valid input.

Prevent almost identical duplicate code
In the number/letter loop part:
//Number loop//
  while( pausecnt < maxpause ) {
     buffer[buffndx] = digitalRead(opto); // read the input pin
     if(buffer[buffndx] != 1){}
    delay(8); // space out the reads a little.
     buffndx++;
     if (buffndx == 4) buffndx = 0; // rotate the buffer index.
     if ((buffer[0] == 0) && (buffer[1] == 0) && (buffer[2] == 0) && (buffer[3] == 0) ){ // we got valid input so proccess it.
        pausecnt = 0; // we got our pulse so restart the clock for the next one.
        number++; //increment the number counter.
        while(! ((buffer[0] == 1 ) && (buffer[1] == 1) && (buffer[2] == 1) && (buffer[3] == 1)) ) { //Loop until we get a valid HIGH
        buffer[buffndx] = digitalRead(opto); // read the input pin
        buffndx++; // rotate the buffer index
    if (buffndx == 4) buffndx = 0;} // rotate the buffer index.
        countpause = true; //we are receiving input so start counting pauses instead of looping forever.
        continue;}else{
    if (countpause == true) pausecnt++;}} // else no valid input

  // Letter Loop//
    pausecnt = 0;   // Reset the pausent counter. Ready for the next stream of pulses to arrive.
    countpause = false; // loop forever until a pulse is recieved.
    while( pausecnt < maxpause ) { // Begin the digit loop
    buffer[buffndx] = digitalRead(opto); // read the input pin
    delay(8);
    buffndx++;
    if (buffndx == 4) buffndx = 0; // rotate the buffer index.
    if ((buffer[0] == 0) && (buffer[1] == 0) && (buffer[2] == 0) && (buffer[3] == 0) ){ // we got valid input so proccess it.
        pausecnt = 0; // we got our pulse so restart the clock for the next one.
        letter++; //increment the aphabet counter.
        while(! ((buffer[0] == 1) && (buffer[1] == 1) && (buffer[2] == 1) && (buffer[3] == 1)) ) { //Loop until we get a valid HIGH
        buffer[buffndx] = digitalRead(opto); // read the input pin
        buffndx++; // rotate the buffer index
    if (buffndx == 4) buffndx = 0;} // rotate the buffer index.
        countpause = true; //we are receiving input so start counting pauses instead of looping forever.
        continue;}else{
     if (countpause == true) pausecnt++;} // else no valid input// else no valid input

  }

First add brackets and align them (I do it for the Number part):
 while( pausecnt < maxpause )
 {
   buffer[buffndx] = digitalRead(opto); // read the input pin

   if(buffer[buffndx] != 1)
   {
   }

   delay(8); // space out the reads a little.
   buffndx++;

   if (buffndx == 4)
   {
     buffndx = 0; // rotate the buffer index.
   }

   if ((buffer[0] == 0) && (buffer[1] == 0) && (buffer[2] == 0) && (buffer[3] == 0) )
   {
     // we got valid input so proccess it.
     pausecnt = 0; // we got our pulse so restart the clock for the next one.
     number++; //increment the number counter.
     while(! ((buffer[0] == 1 ) && (buffer[1] == 1) && (buffer[2] == 1) && (buffer[3] == 1)) )
     {
        //Loop until we get a valid HIGH
        buffer[buffndx] = digitalRead(opto); // read the input pin
        buffndx++; // rotate the buffer index

        if (buffndx == 4)
        {
          buffndx = 0;
        }
      } // rotate the buffer index.

      countpause = true; //we are receiving input so start counting pauses instead of looping forever.
      continue;
    }
    else
    {
      if (countpause == true)
      {
        pausecnt++;
      }
    } // else no valid input

Note it is longer, but much clearer (clear code is more important than short code).
Now because the code starting from:
buffer[buffndx] = digitalRead(opto); // read the input pin
...

Until the end of the number loop code is almost equal to the letter loop code, try to find the differences between the two parts: only the number and letter variable. So you make a new function (e.g. processKey), you pass the number or the letter (so for the number call processKey(number) and for the letter call processKey(letter). Note that both are integers. The new function will be:
int processKey(int key) // Item is a number or letter
{
    ...
    return key;
}

You return a key (which is the possibly increased value (because of number++ in the original code. A slightly advanced way is to pass it as pointer:
void processKey(int* key) // Item is a number or letter

and change the key with (*key)++; and call the functions with processKey(&number) and processKey(&letter).
Use define
Note that instead of 4, it's better to use a #define.
     if(buffer[buffndx] != 1){}

Remove dead code
This line does not anything; to make this clear, always align brackets:
     if(buffer[buffndx] != 1)
     {
     }

Always use brackets { }
if (buffndx == 4) buffndx = 0; // rotate the buffer index.

Use:
if (buffndx == 4)
{
    buffndx = 0; // rotate the buffer index.
}

Avoid code duplication
     if ((buffer[0] == 0) && (buffer[1] == 0) && (buffer[2] == 0) && (buffer[3] == 0) ){ // we got valid input so proccess it.
        pausecnt = 0; // we got our pulse so restart the clock for the next one.
        number++; //increment the number counter.
        while(! ((buffer[0] == 1 ) && (buffer[1] == 1) && (buffer[2] == 1) && (buffer[3] == 1)) ) { //Loop until we get a valid HIGH

In this part you check twice to see if values are 0 or 1, make a function for this (e.g. areAllValues(buffer, 0) for the first call and areAllValues(buffer, 1) for the next.
If 0 and 1 are the only values use a boolean (True/False).
    if (buffndx == 4) buffndx = 0;} // rotate the buffer index.

Use here the same #define that I proposed above.
Do not check against true/false
    if (countpause == true) pausecnt++;}} // else no valid input

It is not needed to check against true:
    if (countpause) ...

Use correct casing
Also it's better to use always correct casing, so countPause instead of countpause.
Avoid repetition of if statements (1)
  if(letter == 1) signal += "A";
  if(letter == 2) signal += "B";
  if(letter == 3) signal += "C";
  if(letter == 4) signal += "D";
  if(letter == 5) signal += "E";
  if(letter == 6) signal += "F";
  if(letter == 7) signal += "G";
  if(letter == 8) signal += "H";
  if(letter == 9) signal += "J";
  if(letter == 10) signal += "K";
  if(letter == 11) signal += ("L");
  if(letter == 12) signal += ("M");
  if(letter == 13) signal += ("N");
  if(letter == 14) signal += ("P");
  if(letter == 15) signal += ("Q");
  if(letter == 16) signal += ("R");
  if(letter == 17) signal += ("S");
  if(letter == 18) signal += ("T");
  if(letter == 19) signal += ("U");
  if(letter == 20) signal += ("V");

Instead of this, use the ASCII character value.
 if ((letter >= 1) && (letter <= 20))
 {
     signal += (char) ((int)('A') + letter - 1);
 {

Avoid repetition of if statements (2)
For your largest part:
 if(letter == 1 && number == 1);
   {musicPlayer.playFullFile("A1.mp3");}

   if(letter == 1 && number == 2);
   {musicPlayer.playFullFile("A2.mp3");}

 ...

Use two if statements, filling in the first and second character of the file name.
char[] fileName = "XX.mp3";

if ((letter >= 1) && (letter <= 20))
{
    if ((number >= 1) && (number <= 8))
    {
       fileName[0] = (char) ((int)('A') + letter - 1);
       fileName[1] = (char) ((int)('0') + number - 1);
       musicPlayer.playFullFile(fileName);
    }
}

Start with 0
Btw, for software engineers, it is more common to start arrays/counters etc. with 0 instead of 1; that saves some - 1 conversions.

My interpretation of would be nice to have it line up the next selection if possible was to have the next song start playing once the current one is finished :-)

I only addressed the first problem; I will add this in the answer.


text:
WT8266-S1 WiFi module
WT8266-S1 WiFi module in my hand I want to encode this module with Ardino IDE. I have a coded program for Arduino NodeMCU 1.0. How can I convert it to the WT8266-S1 WiFi module? Do you have the WT8266-S1 WiFi module source code? Firebase connection to do the application to turn off the LED. Below is a sample code share.
#include <SoftwareSerial.h>

SoftwareSerial esp01(9,11);

void setup()
{
  Serial.begin(9600);
  esp01.begin(9600);

  pinMode(4,OUTPUT);
  digitalWrite(4,LOW);

  pinMode(12,OUTPUT);
  digitalWrite(12,LOW);

  pinMode(13,OUTPUT);
  digitalWrite(13,LOW);

  sendData("AT+RST\r\n",2000);
  sendData("AT+CWMODE=2\r\n",1000);
  sendData("AT+CIFSR\r\n",1000);
  sendData("AT+CIPMUX=1\r\n",1000);
  sendData("AT+CIPSERVER=1,80\r\n",1000);
}

void loop()
{
  if(esp01.available())
  {
    if(esp01.find("+IPD,"))
    {
     delay(1000);

     // odczytanie ID połączenia
     int connectionId = esp01.read()-48;

     esp01.find("pin=");

     int pinNumber = (esp01.read()-48)*10;
     pinNumber += (esp01.read()-48);
     digitalWrite(pinNumber, !digitalRead(pinNumber));
      String closeCommand = "AT+CIPCLOSE=";
     closeCommand+=connectionId;
     closeCommand+="\r\n";

     sendData(closeCommand,1000);
    }
  }
}

String sendData(String command, const int timeout)
{
    String response = "";

    esp01.print(command);

    long int time = millis();

    while( (time+timeout) > millis())
    {
      while(esp01.available())
      {
        char c = esp01.read();
        response += c;
      }
    }
    Serial.print(response);
    return response;
}

Warning: espcomm_sync failed when I install this thread
error: espcomm_open failed
error: espcomm_upload_mem failed
error: espcomm_upload_mem failed
 getting the error

what did you try?

I shared a sample code on the subject.

this a sketch for an MCU with external esp8266 module with AT firmware  wired to Serial interface. you try to upload it to the esp8266?

Is it possible that I want to load code into module WT8266? I wrote code for NodeMCU 1.0 and I want to edit it for the wt8266 module. @Juraj

Can I write code for wt8266 as same as esp8266? Is this possible? @Juraj

don't know. but sure is, you can't use the esp8266 AT firmware 'from inside'. because if you upload your sketch, it replaces the AT firmware as the application running on the esp8266. how did you wire the WT8266 and do you put it into flashing mode before upload?

I understood thank you. Connected to computer with USB TTL cable. Yes is currently running in flashing mode. @Juraj

has it AT firmware? can you execute AT command on in from computer? for example from Serial Monitor of the Arduino IDE?

source: Stack Exchange

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

sort: votes


text:
expected `}' at end of input
int scvVal = 6;
int drvVal = 9;
int sensorVal = A1;
void setup() {
    Serial.begin(9600);
    pinMode(6, OUTPUT);
    pinMode(9, OUTPUT);
 }
void loop(){
 sensorVal = analogRead(A1);

 Serial.print("Sensor Value: ");
 Serial.print(sensorVal);

 float voltage = (sensorVal*5.0)/1024.0;
    Serial.print("Volts: ");
    Serial.print(voltage);

 float pressure_pascal = (400.0*((float)voltage-0.5))*1000000.0;
 float pressure_bar = pressure_pascal/10e5;
   Serial.print("Pressure = ");
   Serial.print(pressure_bar);
   Serial.println(" bars");
   Serial.print("Pressure = ");
   {
 for(int a = 255; a>=0;a--)
 {
   analogWrite(6,a);
 if (pressure_bar = 1600){
   analogWrite (6, a);
 if (pressure_bar > 1600){
   analogWrite (6, a);
 }
 for(int a = 0; a<256; a++)
 {
  analogWrite(6, a);
 {
 if(pressure_bar < 1600){
  analogWrite (6, a);
 }
 for(int b = 255; b>=0;b--)
 {
 analogWrite(9, b);
 {
 if (pressure_bar == 1600){
   analogWrite (9, b);
 if(pressure_bar < 1600){
   analogWrite (9, b);
}
 for(int b = 0; b<256; b++)
 {
   analogWrite(9, b);
 {
if (pressure_bar > 1600){
   analogWrite (9, b);
   }
  }

Welcome to Arduino:SE.  Your life would be so much easier if you indented your code correctly.  It would then be fairly obvious where the missing } should be.

do you help me?

@Duc Hoang: Are you formatting your code correctly, that it is readable? Select in in the question editor and click on the {} button

Never before have I see such random use of brackets... ;)

do you help me? .... you have to start by helping yourself ..... read and understand the answers below ..... do not copy and paste code without thinking

also, what text editor/IDE are you using? Some of them highlight matching brackets abut not Arduino's one

Some guidelines for programming:
Start each statement on a new line
int scvVal = 6;
int drvVal = 9;
int sensorVal = A1;
void setup() {
Serial.begin(9600);
pinMode(6, OUTPUT);
pinMode(9, OUTPUT);
} void loop(){
sensorVal = analogRead(A1);

Serial.print("Sensor Value: "); Serial.print(sensorVal);

float voltage = (sensorVal*5.0)/1024.0; Serial.print("Volts: "); Serial.print(voltage);

float pressure_pascal = (400.0*((float)voltage-0.5))*1000000.0;
float pressure_bar = pressure_pascal/10e5;
Serial.print("Pressure = ");
Serial.print(pressure_bar);
Serial.println(" bars");
Serial.print("Pressure = "); {
for(int a = 255; a>=0;a--) {
analogWrite(6,a);
if (pressure_bar = 1600){
analogWrite (6, a);
if (pressure_bar > 1600){
analogWrite (6, a); }
for(int a = 0; a<256; a++) {
analogWrite(6, a); {
if(pressure_bar < 1600){
analogWrite (6, a); }
for(int b = 255; b>=0;b--) {
analogWrite(9, b); {
if (pressure_bar == 1600){
analogWrite (9, b);
if(pressure_bar < 1600){
analogWrite (9, b); }
for(int b = 0; b<256; b++) {
analogWrite(9, b); {
if (pressure_bar > 1600){
analogWrite (9, b);
} }

Use brackets and align them
.. so each pair of { and } is on the same column and align code with brackets to be indented 2, 3 or 4 spaces
int scvVal = 6;
int drvVal = 9;
int sensorVal = A1;
void setup()
{
  Serial.begin(9600);
  pinMode(6, OUTPUT);
  pinMode(9, OUTPUT);
}
void loop()
{
  sensorVal = analogRead(A1);

  Serial.print("Sensor Value: ");
  Serial.print(sensorVal);

  float voltage = (sensorVal*5.0)/1024.0; Serial.print("Volts: ");
  Serial.print(voltage);

  float pressure_pascal = (400.0*((float)voltage-0.5))*1000000.0;
  float pressure_bar = pressure_pascal/10e5;
  Serial.print("Pressure = ");
  Serial.print(pressure_bar);
  Serial.println(" bars");
  Serial.print("Pressure = ");
  {
    for(int a = 255; a>=0;a--)
    {
      analogWrite(6,a);
      if (pressure_bar = 1600)
      {
        analogWrite (6, a);
        if (pressure_bar > 1600)
        {
          analogWrite (6, a);
        }
        for(int a = 0; a<256; a++)
        {
          analogWrite(6, a);
          {
            if(pressure_bar < 1600)
            {
              analogWrite (6, a);
            }
            for(int b = 255; b>=0;b--)
            {
              analogWrite(9, b);
              {
                if (pressure_bar == 1600)
                {
                  analogWrite (9, b);
                  if(pressure_bar < 1600)
                  {
                    analogWrite (9, b);
                  }
                  for(int b = 0; b<256; b++)
                  {
                    analogWrite(9, b);
                    {
                      if (pressure_bar > 1600)
                      {
                        analogWrite (9, b);
                      }
                    }

Remove superfluous brackets
As you can see, you are having some superfluous/missing brackets. What you want is probably something like:
int scvVal = 6;
int drvVal = 9;
int sensorVal = A1;
void setup()
{
  Serial.begin(9600);
  pinMode(6, OUTPUT);
  pinMode(9, OUTPUT);
}
void loop()
{
  sensorVal = analogRead(A1);

  Serial.print("Sensor Value: ");
  Serial.print(sensorVal);

  float voltage = (sensorVal*5.0)/1024.0; Serial.print("Volts: ");
  Serial.print(voltage);

  float pressure_pascal = (400.0*((float)voltage-0.5))*1000000.0;
  float pressure_bar = pressure_pascal/10e5;
  Serial.print("Pressure = ");
  Serial.print(pressure_bar);
  Serial.println(" bars");
  Serial.print("Pressure = ");

  for(int a = 255; a>=0;a--)
  {
    analogWrite(6,a);
    if (pressure_bar = 1600)
    {
      analogWrite (6, a);
    }
    if (pressure_bar > 1600)
    {
      analogWrite (6, a);
    }
  }
  for(int a = 0; a<256; a++)
  {
    analogWrite(6, a);
    if(pressure_bar < 1600)
    {
      analogWrite (6, a);
    }
  }
  for(int b = 255; b>=0;b--)
  {
    analogWrite(9, b);
    if (pressure_bar == 1600)
    {
      analogWrite (9, b);
    }
    if(pressure_bar < 1600)
    {
      analogWrite (9, b);
    }
  }
  for(int b = 0; b<256; b++)
  {
    analogWrite(9, b);
    if (pressure_bar > 1600)
    {
      analogWrite (9, b);
    }
  }
}

Remove duplicate code
In the if statement, you perform twice the same code (both you send an analogWrite with the same value, so the code (from the for loops can be reduced to:
  for(int a = 255; a>=0;a--)
  {
    analogWrite(6,a);
    if (pressure_bar >= 1600)
    {
      analogWrite (6, a);
    }
  }
  for(int a = 0; a<256; a++)
  {
    analogWrite(6, a);
    if(pressure_bar <= 1600)
    {
      analogWrite (6, a);
    }
  }
  for(int b = 255; b>=0;b--)
  {
    analogWrite(9, b);
    if (pressure_bar <= 1600)
    {
      analogWrite (9, b);
    }
  }
  for(int b = 0; b<256; b++)
  {
    analogWrite(9, b);
    if (pressure_bar >= 1600)
    {
      analogWrite (9, b);
    }
  }
}

Unclear
What is unclear why you first write an analog value, and directly afterward (in each if) you write the same value. I'm not sure what you really want here. Either you want to write to a different pin, or you want a delay (to have the value having some effect), I'm just not sure.

Look at your open brackets { vs closing brackets, }. You need the same number of each. If have this in the Arduino IDE and use CTRL-T, they are somewhat easy to find.  I just looked, and I can spot them pretty easily.
int scvVal = 6;
int drvVal = 9;
int sensorVal = A1;
void setup()
{
Serial.begin(9600);
pinMode(6, OUTPUT);
pinMode(9, OUTPUT);
}
void loop()
{
sensorVal = analogRead(A1);
Serial.print("Sensor Value: ");
Serial.print(sensorVal);
float voltage = (sensorVal*5.0)/1024.0;
Serial.print("Volts: ");
Serial.print(voltage);
float pressure_pascal = (400.0*((float)voltage-0.5))*1000000.0;
float pressure_bar = pressure_pascal/10e5;
Serial.print("Pressure = ");
Serial.print(pressure_bar);
Serial.println(" bars");
Serial.print("Pressure = ");
{                            << bracket for what?
for(int a = 255; a>=0;a--) { << missing closing bracket
  analogWrite(6,a);
  if (pressure_bar = 1600){   << missing closing bracket
   analogWrite (6, a);
     if (pressure_bar > 1600){
     analogWrite (6, a);
     }
  for(int a = 0; a<256; a++) {
    analogWrite(6, a);
    {                      << wrong direction
    if(pressure_bar < 1600){
       analogWrite (6, a);
    }
  for(int b = 255; b>=0;b--) {
    analogWrite(9, b);
   {                           << wrong direction
    if (pressure_bar == 1600){ << missing closing bracket
      analogWrite (9, b);
      if(pressure_bar < 1600){ << missing closing bracket
        analogWrite (9, b);
    }
   for(int b = 0; b<256; b++) {
     analogWrite(9, b);
   {                            << wrong direction
   if (pressure_bar > 1600){
     analogWrite (9, b);
   }
}  << closing bracket for loop

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


text:
Please answer this
what is the difference between transmitting and receiving leds(circled) connected to sensor board and ir emitter and receiver diode shown in second pic?Will the output change it i replace the former leds by latter?if yes then how?
Second pic is from https://www.amazon.in/CENTIoT-Universal-Infrared-Emission-Receiver/dp/B071NK3KD4/ref=sr_1_10?keywords=ir+leds&qid=1554913735&s=gateway&sr=8-10

Please don't re-post the same question

only one of those is a LED .... the other is most likely a photo-transistor

@sempaiscuba this is not same question, i think u did not get my question or maybe i didn't explain it clearly but still i got my answer.

The dark coated LED has a filter, that filters out other wavelengths except for the one, that it is specified for. The clear one doesn't have this coating, since it is used for sending. If you replace the coated one by an uncoated version, the results may get worse, when other IR sources are present (like the sun).
Also the specifications of the LEDs might be different, we can only speculate about that without knowing the part numbers of the used LEDs.
All in all it might not be a good idea to exchange the LEDs for one another. You haven't stated, why you want to do this.


text:
What is the purpose of Serial.println() without an argument?
I am attempting to control a stepper motor with Sparkfun's Big Easy Driver, and I see the line "Serial.println();" they put in the example code. Why is there no argument and what function does this serve?
//Declare pin functions on Arduino
#define stp 2
#define dir 3
#define MS1 4
#define MS2 5
#define MS3 6
#define EN  7

//Declare variables for functions
char user_input;
int x;
int y;
int state;

void setup() {
  pinMode(stp, OUTPUT);
  pinMode(dir, OUTPUT);
  pinMode(MS1, OUTPUT);
  pinMode(MS2, OUTPUT);
  pinMode(MS3, OUTPUT);
  pinMode(EN, OUTPUT);
  resetBEDPins(); //Set step, direction, microstep and enable pins to default states
  Serial.begin(9600); //Open Serial connection for debugging
  Serial.println("Begin motor control");
  Serial.println();
  //Print function list for user selection
  Serial.println("Enter number for control option:");
  Serial.println("1. Turn at default microstep mode.");
  Serial.println("2. Reverse direction at default microstep mode.");
  Serial.println("3. Turn at 1/16th microstep mode.");
  Serial.println("4. Step forward and reverse directions.");
  Serial.println();
}

prints everything in the argument, followed by a newline .... in other words, prints just a newline

when you post  code in a question, select all of the code and press ctrl-k or click the {} button .... all of the code will be indented by 4 spaces, which causes  it to be displayed as code ...... upvote for being concerned with code formatting

That's simple. Thanks! So if you had printed text (surrounded by quotation marks) before, the same effect would be achieved by putting in a "\n", correct?

yes, serial.print("\n"); gives same result as serial.println();

@jsotola: No, Serial.println() outputs a '\r' before the '\n', which Serial.print("\n") doesn't.

It simply prints a newline to the serial monitor. Just for spacing.

To complement jose can u c's answer: the Arduino Serial object uses
CRLF as the end-of-line marker. That's an ASCII CR (carriage return,
or '\r' in C) followed by ASCII LF (line feed, '\n' in C). Thus,
Serial.println();

is equivalent to
Serial.print("\r\n");

This is a cool expansion on some fundamental formatting stuff. Thank you for the info


text:
Write faster on AT24C32
I'm using AT24C32 EEPROM chip from ATmel. I found code that will write and read bytes from chip.
Code writes and reads bytes correctly and without any problem.
But I have to write few 8-byte values often(every 10-15 seconds). I did "cut" those variables to 48 bit(so 6-byte variable) and with that I speeded up saving but it's still slow.
Is there any chance to speed up saving proccess? Code is below
void EEPROMClass::write48(int16_t address, uint64_t value)
{
    uint8_t byteValue = (value & 0xFF);
    write8(address, byteValue);

    byteValue = ((value >> 8) & 0xFF);
    write8(address + 1, byteValue);

    byteValue = ((value >> 16) & 0xFF);
    write8(address + 2, byteValue);

    byteValue = ((value >> 24) & 0xFF);
    write8(address + 3, byteValue);

    byteValue = ((value >> 32) & 0xFF);
    write8(address + 4, byteValue);

    byteValue = ((value >> 40) & 0xFF);
    write8(address + 5, byteValue);
}

void EEPROMClass::write8(int16_t const address, uint8_t const value)
{
    Wire.beginTransmission(AT24C32);

    Wire.write(highAddressByte(address));
    Wire.write(lowAddressByte(address));

    Wire.write(value);
    delay(2);
    Wire.endTransmission();
}

delay of 2ms is required otherwise EEPROM will write different value. Code has 4 "6-byte" variables(total of 24 bytes). Every byte is minimum 2ms, so total time to save only "6-byte" variables is 48ms(round to 50ms). That is too slow for me. How to speed up write function?

What type of speed do your application require? Please see benchmarks; https://github.com/mikaelpatel/Arduino-Storage

after writing a value to EEPROM, and terminating the I2C connection with a STOP, the EEPROM enters a self writing mode to write what you have sent to it, to it's internal memory. (you don't actually write the values to the memory section; you write them to a buffer, and then the internal controller writes them to its memory section).
this "self writing mode" takes about 5ms, and you cant do nothing about it. but you can use "page writing" instead of byte writing. that 32K model, has a 32 bytes page buffer. you have to send all the bytes (as long as they are under 32 bytes) at once in one I2C transaction. this time, the chip fills its page buffer and then after a STOP, writes it all at once on its memory. in your code, you just write one byte in your buffer each time in a single transaction. like sending a bus with just one passenger at a time.
remember in this mode, you only set the address of the first byte. the next bytes automatically settle in the next addresses.

Does exists "readpage" way to read faster?

And does read action requires delay?

the reading doesn't have the limitation of "page". you can read all the chip in one transaction (it can even rollover the memory bank and resend it). and it doesn't need a delay neither (it's as brief as microseconds so it's negligible). @SilvioCro

Can I write 18 bytes of data starting from eg. address 24? It will pass 32 byte. Will it corrupt data?  And, how much bytes I can use? Is all 32 bytes for data or 30 bytes for data and 2 bytes for address?

the 32 bytes is all data. the address is set the way you set it before, but only for the first item. and remember, in the page write mode, you write to a whole page. as your chip has 32bytes pages ( 128 * 32 bytes = 4096 bytes = 32Kbits), you can write a whole 32 bytes at one of the pages (1~128). to write properly, first 32 bytes settle to address 0 to 31, the next batch at 32 to 63 … .

and in the case you write to 18 bytes to address 24 (you don't have to send exactly 32 bytes. as I said, a maximum of 32 bytes), your data will rollover.
byte0 -> 24
/byte1 -> 25
/byte2 -> 26
/byte3 -> 27
/byte4 -> 28
/byte5 -> 29
/byte6 -> 30
/byte7 -> 31
/byte8 -> 0 (still in the first page. it does not go to next page)
/byte9 -> 1 (still in the first page. it does not go to next page)

Thanks a lot for help

Mostly the best speed you get, is if you use the 'page' size, which is 32 bytes. It will take longer than 4 bytes, but less then 4 times 8 bytes.
You could do a check to see if using one page write (of 32 bytes) is faster than 6 times a one byte write.
However, it depends if you can change your design so it writes 32 bytes at a time.
E.g. by writing 60 seconds 4 times 8 bytes (32 bytes) in one page write, instead of every 15 seconds 8 bytes. This will be much faster.

I never let processor wait a process to finish. I call a procedure do whatever could be done put a mark where I got and return to do other stuff. Next scan I pick up from where I left and continue if the conditions allow, if not i leave it for the next scan. I would never put a waiting time in a loop. In your case I would open the communication, send as many bytes as I can, put a mark how far I got, close the communication and return. Next scans(when the data are transferred from the buffer to the EEPROM) I would repeat the same process for the rest of the data. At any scan I invest a few hundreds of microseconds.

This is so old I even don't use Arduino anymore. But thanks!


text:
Can I daisychain multiple Arduino Nanos to a single USB port (specialized purpose)
I need to have several Nanos on one USB port. They will have separate power, so power constraints won't be a concern. I need them all to go through the same serial port. They will never get anything sent to them, and should never send data simultaneously. Each one is connected to a switch, and upon pressing the switch, will send an 8-digit serial number over serial. I want to have a VB.NET application which listens over this shared serial COM for numbers, and collects them all, displaying them in a history list. Can this work?

No, they can't all share one data line.  What you'll need to do is either connect all of the switches to one Arduino or connect all of the Arduinos to one "master" arduino which will communicate with the computer.

The single Master Arduino is what I'll go with. "Master" and "Slave" boards, reminds me of IDE drives lol

For a USB topology to operate one needs a USB controller which knows about all the different USB protocols necessary to communicate with all the different USB peripherals (this is why a USB controller is usually a fully capable computer) all connected through a USB hub.  It is unlikely a USB network could be created using only peripheral USB devices which were wired directly together.
To communicate between several Arduinos and a computer it would be much easier to use a serial bus made for multiple drops like RS485. There are many RS485 to USB converters available like this one for computers that do not have an RS485 port.


text:
Measure cycle count and time of Digital Input
I am currently working on a project which is read a digital input signal from a machine. The machine operation is as below:
when the mold close, the machine gives the "HIGH" signal, when mold is open the machine gives "LOW" signal. A cycle is counted as one cycle when from the mold close --> open --> close.
My goal is to count the cycle and cycle time of each cycle. I am struggling when the Input comes from HIGH to LOW. Appreciate your help to give me some guildance on this project.
int MoldInput = 2;
int MoldState = 0;
int lastMoldState = 0;
int CycleTimeCounter = 0;
int CycleCount = 0;
unsigned long CycleTime;
volatile unsigned long TimeTemp1 = 0;
volatile unsigned long TimeTemp2 = 0;
void setup() {
  // put your setup code here, to run once:
  pinMode (MoldInput,INPUT);
  attachInterrupt(0, RealTimeMoldClose, RISING);
  Serial.begin(115200);
}

void loop() {
  // put your main code here, to run repeatedly:
  Serial.println(CycleTime);
}
void RealTimeMoldClose(){
  unsigned long t = millis();
  TimeTemp2 = t;
  CycleTime = TimeTemp2 - TimeTemp1;
  TimeTemp1 = TimeTemp2;
}

What is connected to pin 5 and what is connected to pin 2? For the cycle time store the millis value and the next time the MoldState turns HIGH, substract the previous millis value from the current millis value.

This is my mistake. Only digital signal connected to pin 2.

Not sure, but pulseIn seems to be appropriate

upvote for presenting properly formatted code listing

I have updated a new code from myself after remember the attachInterrupt function. Appreciate your guys comment on this.

You don't need to do anything on HIGH to LOW. For example, if you are counting how often a door opens you don't also need to count how often it closes, because it must close before it re-opens.
I don't see the point of the interrupt since your code is doing nothing else than checking if the interrupt occurred, so it may as well be checking if the input has changed anyway. This code is simpler:
const int MoldInput = 2;

int lastMoldState = 0;
unsigned long startTime = 0;
unsigned long TotalTime = 0;
unsigned long CycleTimeCounter = 0;

void setup() {
  pinMode (MoldInput, INPUT);
  Serial.begin(115200);
}

unsigned long lastReportedCycleCount = 0;

void loop() {
  int MoldState = digitalRead(MoldInput);
  if (MoldState != lastMoldState) {
    if (MoldState == HIGH) {
      CycleTimeCounter++;  // count times it was high
      TotalTime += millis() - startTime;  // add up time interval
      startTime = millis ();
      delay (100);    // debounce
    }  // end of state being HIGH
    lastMoldState = MoldState;
  }   // end of state change

  if (CycleTimeCounter % 10 == 0 && CycleTimeCounter != lastReportedCycleCount)
    {
    Serial.print (F("Average time after "));
    Serial.print (CycleTimeCounter);
    Serial.print (F(" cycles is "));
    Serial.print (TotalTime / CycleTimeCounter);
    Serial.println (F(" milliseconds"));
    lastReportedCycleCount = CycleTimeCounter;
    }
} // end of loop


text:
Problem in integrating speed sensor LM393 with L298N
I am currently working on a project that has an automatic support wheel for bicycle.
The mechanism of this project is when the speed sensor is detecting the RPM of the rear bicycle wheel it will triggered the support wheel. The support wheel is oriented by the motor power. Basically, when the bicycle reaches a certain speed limit, it will activate the support wheel whether to move upwards or downwards. I have done some coding for this.
int sensor = 11;
unsigned long start_time = 0;
unsigned long end_time = 0;
int steps=0;
float steps_old=0;
float temp=0;
float rpm=0;
int motorPin = 9;

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

  pinMode(sensor,INPUT_PULLUP);
}
}

void loop()
{
 start_time=millis();
 end_time=start_time+1000;
 while(millis()<end_time)
 {
   if(digitalRead(sensor))
   {
    steps=steps+1;
    while(digitalRead(sensor));
   }

 }
    temp=steps-steps_old;
    steps_old=steps;
    rpm=(temp/5)/60;
    Serial.print("RPM = ");
      Serial.println(rpm,DEC);
      delay (1000);
      //Restart the interrupt processing

    if (rpm==0)
    {
      digitalWrite(8, HIGH);
      digitalWrite(7,LOW);
      analogWrite(motorPin, 255);
      delay(1000);

    }

   if (rpm>0.02)
   {
      digitalWrite(8, HIGH);
      digitalWrite(7,LOW);
      analogWrite(motorPin, 255);
      delay(1000);
      digitalWrite(8, LOW);
      digitalWrite(7,LOW);
      analogWrite(motorPin, 255);

   }

   }

The problem with this code is that I do not know how to stop the motor when the rpm>0 until the sensor read rpm=0. I want to make the motor rotate backwards for a few seconds and stop completely as long as the rpm is above zero (my coding will make the motor rotate forward when rpm>0 again and again, the same goes for when rpm=0) and it will only rotate forward for few seconds when the rpm=0 and stop completely until the sensor read rpm>0. The process continues looping.
Please help me, I'm new to Arduino and sorry for my English as I'm not really fluent in English.

the l298n can be made to go backwards by swapping the polarities of the direction pins. For e.g., if pin 8 and 7 are high and low respectively to go forwards, then make 8 low and 7 high to reverse direction. However it seems from your question you want to counteract the forwards movement as soon as it starts moving? How would this ever move the bike?


text:
exit status 1, cant compile , please help
/***************************************************
  This is our GFX example for the Adafruit ILI9341 Breakout and Shield
  ----> http://www.adafruit.com/products/1651

  Check out the links above for our tutorials and wiring diagrams
  These displays use SPI to communicate, 4 or 5 pins are required to
  interface (RST is optional)
  Adafruit invests time and resources providing this open source code,
  please support Adafruit and open-source hardware by purchasing
  products from Adafruit!

  Written by Limor Fried/Ladyada for Adafruit Industries.
  MIT license, all text above must be included in any redistribution
 ****************************************************/
#define ILI9341_BLACK       0x0000  ///<   0,   0,   0
#define ILI9341_NAVY        0x000F  ///<   0,   0, 123
#define ILI9341_DARKGREEN   0x03E0  ///<   0, 125,   0
#define ILI9341_DARKCYAN    0x03EF  ///<   0, 125, 123
#define ILI9341_MAROON      0x7800  ///< 123,   0,   0
#define ILI9341_PURPLE      0x780F  ///< 123,   0, 123
#define ILI9341_OLIVE       0x7BE0  ///< 123, 125,   0
#define ILI9341_LIGHTGREY   0xC618  ///< 198, 195, 198
#define ILI9341_DARKGREY    0x7BEF  ///< 123, 125, 123
#define ILI9341_BLUE        0x001F  ///<   0,   0, 255
#define ILI9341_GREEN       0x07E0  ///<   0, 255,   0
#define ILI9341_CYAN        0x07FF  ///<   0, 255, 255
#define ILI9341_RED         0xF800  ///< 255,   0,   0
#define ILI9341_MAGENTA     0xF81F  ///< 255,   0, 255
#define ILI9341_YELLOW      0xFFE0  ///< 255, 255,   0
#define ILI9341_WHITE       0xFFFF  ///< 255, 255, 255
#define ILI9341_ORANGE      0xFD20  ///< 255, 165,   0
#define ILI9341_GREENYELLOW 0xAFE5  ///< 173, 255,  41
#define ILI9341_PINK        0xFC18  ///< 255, 130, 198

#include "SPI.h"
#include "Adafruit_GFX.h"
#include "Adafruit_ILI9341.h"

// For the Adafruit shield, these are the default.
#define TFT_CLK 13
#define TFT_MISO 12
#define TFT_MOSI 11
#define TFT_DC 9
#define TFT_CS 10
#define TFT_RST 8
// Use hardware SPI (on Uno, #13, #12, #11) and the above for CS/DC
//Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC);
// If using the breakout, change pins as desired
Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC, TFT_MOSI, TFT_CLK, TFT_RST, TFT_MISO);

void setup() {
  Serial.begin(9600);
  Serial.println("ILI9341 Test!");

  tft.begin();

  // read diagnostics (optional but can help debug problems)
  uint8_t x = tft.readcommand8(ILI9341_RDMODE);
  Serial.print("Display Power Mode: 0x"); Serial.println(x, HEX);
  x = tft.readcommand8(ILI9341_RDMADCTL);
  Serial.print("MADCTL Mode: 0x"); Serial.println(x, HEX);
  x = tft.readcommand8(ILI9341_RDPIXFMT);
  Serial.print("Pixel Format: 0x"); Serial.println(x, HEX);
  x = tft.readcommand8(ILI9341_RDIMGFMT);
  Serial.print("Image Format: 0x"); Serial.println(x, HEX);
  x = tft.readcommand8(ILI9341_RDSELFDIAG);
  Serial.print("Self Diagnostic: 0x"); Serial.println(x, HEX);
  /*
  Serial.println(F("Benchmark                Time (microseconds)"));
  delay(10);
  Serial.print(F("Screen fill              "));
  Serial.println(testFillScreen());
  delay(500);

  Serial.print(F("Text                     "));
  Serial.println(testText());
  delay(3000);

  Serial.print(F("Lines                    "));
  Serial.println(testLines(ILI9341_CYAN));
  delay(500);

  Serial.print(F("Horiz/Vert Lines         "));
  Serial.println(testFastLines(ILI9341_RED, ILI9341_BLUE));
  delay(500);

  Serial.print(F("Rectangles (outline)     "));
  Serial.println(testRects(ILI9341_GREEN));
  delay(500);

  Serial.print(F("Rectangles (filled)      "));
  Serial.println(testFilledRects(ILI9341_YELLOW, ILI9341_MAGENTA));
  delay(500);

  Serial.print(F("Circles (filled)         "));
  Serial.println(testFilledCircles(10, ILI9341_MAGENTA));

  Serial.print(F("Circles (outline)        "));
  Serial.println(testCircles(10, ILI9341_WHITE));
  delay(500);

  Serial.print(F("Triangles (outline)      "));
  Serial.println(testTriangles());
  delay(500);

  Serial.print(F("Triangles (filled)       "));
  Serial.println(testFilledTriangles());
  delay(500);

  Serial.print(F("Rounded rects (outline)  "));
  Serial.println(testRoundRects());
  delay(500);

  Serial.print(F("Rounded rects (filled)   "));
  Serial.println(testFilledRoundRects());
  delay(500);

  Serial.println(F("Done!"));
*/
}

void loop(void) {
  tft.fillScreen(ILI9341_NAVY);
  tft.setCursor(0, 0);
  tft.setTextColor(ILI9341_WHITE);  tft.setTextSize(1);
  tft.println("Hello World!");
  tft.setTextColor(ILI9341_YELLOW); tft.setTextSize(2);
  tft.println(1234.56);
  tft.setTextColor(ILI9341_RED);    tft.setTextSize(3);
  tft.println(0xDEADBEEF, HEX);
  tft.println();
  tft.setTextColor(ILI9341_GREEN);
  tft.setTextSize(5);
  tft.println("Groop");
  tft.setTextSize(2);
  tft.println("I implore thee,");
  tft.setTextSize(1);
  tft.println("my foonting turlingdromes.");
  tft.println("And hooptiously drangle me");
  tft.println("with crinkly bindlewurdles,");
  tft.println("Or I will rend thee");
  tft.println("in the gobberwarts");
  tft.println("with my blurglecruncheon,");
  tft.println("see if I don't!");
  delay(5000);

}

unsigned long testFillScreen() {
  unsigned long start = micros();
  tft.fillScreen(ILI9341_BLACK);
  yield();
  tft.fillScreen(ILI9341_RED);
  yield();
  tft.fillScreen(ILI9341_GREEN);
  yield();
  tft.fillScreen(ILI9341_BLUE);
  yield();
  tft.fillScreen(ILI9341_BLACK);
  yield();
  return micros() - start;
}

unsigned long testText() {
  tft.fillScreen(ILI9341_BLACK);
  unsigned long start = micros();
  tft.setCursor(0, 0);
  tft.setTextColor(ILI9341_WHITE);  tft.setTextSize(1);
  tft.println("Hello World!");
  tft.setTextColor(ILI9341_YELLOW); tft.setTextSize(2);
  tft.println(1234.56);
  tft.setTextColor(ILI9341_RED);    tft.setTextSize(3);
  tft.println(0xDEADBEEF, HEX);
  tft.println();
  tft.setTextColor(ILI9341_GREEN);
  tft.setTextSize(5);
  tft.println("Groop");
  tft.setTextSize(2);
  tft.println("I implore thee,");
  tft.setTextSize(1);
  tft.println("my foonting turlingdromes.");
  tft.println("And hooptiously drangle me");
  tft.println("with crinkly bindlewurdles,");
  tft.println("Or I will rend thee");
  tft.println("in the gobberwarts");
  tft.println("with my blurglecruncheon,");
  tft.println("see if I don't!");
  return micros() - start;
}

unsigned long testLines(uint16_t color) {
  unsigned long start, t;
  int           x1, y1, x2, y2,
                w = tft.width(),
                h = tft.height();

  tft.fillScreen(ILI9341_BLACK);
  yield();

  x1 = y1 = 0;
  y2    = h - 1;
  start = micros();
  for(x2=0; x2<w; x2+=6) tft.drawLine(x1, y1, x2, y2, color);
  x2    = w - 1;
  for(y2=0; y2<h; y2+=6) tft.drawLine(x1, y1, x2, y2, color);
  t     = micros() - start; // fillScreen doesn't count against timing

  yield();
  tft.fillScreen(ILI9341_BLACK);
  yield();

  x1    = w - 1;
  y1    = 0;
  y2    = h - 1;
  start = micros();
  for(x2=0; x2<w; x2+=6) tft.drawLine(x1, y1, x2, y2, color);
  x2    = 0;
  for(y2=0; y2<h; y2+=6) tft.drawLine(x1, y1, x2, y2, color);
  t    += micros() - start;

  yield();
  tft.fillScreen(ILI9341_BLACK);
  yield();

  x1    = 0;
  y1    = h - 1;
  y2    = 0;
  start = micros();
  for(x2=0; x2<w; x2+=6) tft.drawLine(x1, y1, x2, y2, color);
  x2    = w - 1;
  for(y2=0; y2<h; y2+=6) tft.drawLine(x1, y1, x2, y2, color);
  t    += micros() - start;

  yield();
  tft.fillScreen(ILI9341_BLACK);
  yield();

  x1    = w - 1;
  y1    = h - 1;
  y2    = 0;
  start = micros();
  for(x2=0; x2<w; x2+=6) tft.drawLine(x1, y1, x2, y2, color);
  x2    = 0;
  for(y2=0; y2<h; y2+=6) tft.drawLine(x1, y1, x2, y2, color);

  yield();
  return micros() - start;
}

unsigned long testFastLines(uint16_t color1, uint16_t color2) {
  unsigned long start;
  int           x, y, w = tft.width(), h = tft.height();

  tft.fillScreen(ILI9341_BLACK);
  start = micros();
  for(y=0; y<h; y+=5) tft.drawFastHLine(0, y, w, color1);
  for(x=0; x<w; x+=5) tft.drawFastVLine(x, 0, h, color2);

  return micros() - start;
}

unsigned long testRects(uint16_t color) {
  unsigned long start;
  int           n, i, i2,
                cx = tft.width()  / 2,
                cy = tft.height() / 2;

  tft.fillScreen(ILI9341_BLACK);
  n     = min(tft.width(), tft.height());
  start = micros();
  for(i=2; i<n; i+=6) {
    i2 = i / 2;
    tft.drawRect(cx-i2, cy-i2, i, i, color);
  }

  return micros() - start;
}

unsigned long testFilledRects(uint16_t color1, uint16_t color2) {
  unsigned long start, t = 0;
  int           n, i, i2,
                cx = tft.width()  / 2 - 1,
                cy = tft.height() / 2 - 1;

  tft.fillScreen(ILI9341_BLACK);
  n = min(tft.width(), tft.height());
  for(i=n; i>0; i-=6) {
    i2    = i / 2;
    start = micros();
    tft.fillRect(cx-i2, cy-i2, i, i, color1);
    t    += micros() - start;
    // Outlines are not included in timing results
    tft.drawRect(cx-i2, cy-i2, i, i, color2);
    yield();
  }

  return t;
}

unsigned long testFilledCircles(uint8_t radius, uint16_t color) {
  unsigned long start;
  int x, y, w = tft.width(), h = tft.height(), r2 = radius * 2;

  tft.fillScreen(ILI9341_BLACK);
  start = micros();
  for(x=radius; x<w; x+=r2) {
    for(y=radius; y<h; y+=r2) {
      tft.fillCircle(x, y, radius, color);
    }
  }

  return micros() - start;
}

unsigned long testCircles(uint8_t radius, uint16_t color) {
  unsigned long start;
  int           x, y, r2 = radius * 2,
                w = tft.width()  + radius,
                h = tft.height() + radius;

  // Screen is not cleared for this one -- this is
  // intentional and does not affect the reported time.
  start = micros();
  for(x=0; x<w; x+=r2) {
    for(y=0; y<h; y+=r2) {
      tft.drawCircle(x, y, radius, color);
    }
  }

  return micros() - start;
}

unsigned long testTriangles() {
  unsigned long start;
  int           n, i, cx = tft.width()  / 2 - 1,
                      cy = tft.height() / 2 - 1;

  tft.fillScreen(ILI9341_BLACK);
  n     = min(cx, cy);
  start = micros();
  for(i=0; i<n; i+=5) {
    tft.drawTriangle(
      cx    , cy - i, // peak
      cx - i, cy + i, // bottom left
      cx + i, cy + i, // bottom right
      tft.color565(i, i, i));
  }

  return micros() - start;
}

unsigned long testFilledTriangles() {
  unsigned long start, t = 0;
  int           i, cx = tft.width()  / 2 - 1,
                   cy = tft.height() / 2 - 1;

  tft.fillScreen(ILI9341_BLACK);
  start = micros();
  for(i=min(cx,cy); i>10; i-=5) {
    start = micros();
    tft.fillTriangle(cx, cy - i, cx - i, cy + i, cx + i, cy + i,
      tft.color565(0, i*10, i*10));
    t += micros() - start;
    tft.drawTriangle(cx, cy - i, cx - i, cy + i, cx + i, cy + i,
      tft.color565(i*10, i*10, 0));
    yield();
  }

  return t;
}

unsigned long testRoundRects() {
  unsigned long start;
  int           w, i, i2,
                cx = tft.width()  / 2 - 1,
                cy = tft.height() / 2 - 1;

  tft.fillScreen(ILI9341_BLACK);
  w     = min(tft.width(), tft.height());
  start = micros();
  for(i=0; i<w; i+=6) {
    i2 = i / 2;
    tft.drawRoundRect(cx-i2, cy-i2, i, i, i/8, tft.color565(i, 0, 0));
  }

  return micros() - start;
}

unsigned long testFilledRoundRects() {
  unsigned long start;
  int           i, i2,
                cx = tft.width()  / 2 - 1,
                cy = tft.height() / 2 - 1;

  tft.fillScreen(ILI9341_BLACK);
  start = micros();
  for(i=min(tft.width(), tft.height()); i>20; i-=6) {
    i2 = i / 2;
    tft.fillRoundRect(cx-i2, cy-i2, i, i, i/8, tft.color565(0, i, 0));
    yield();
  }

  return micros() - start;
}

Did you install these libraries in the same folder that your sketch is in?
include "SPI.h"
include "Adafruit_GFX.h"
include "Adafruit_ILI9341.h"

yes but still i am getting the same error i am just a beginner please help

What's the exact text that compiler displays?

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

@prashant And rest of the error message? Add it to the question and not to the comment. Example here: https://arduino.stackexchange.com/questions/45860/error-compiling-code-for-arduino-genuino-uno

that issue is fixed thanks for your help, but now the problem is my LCD has white light only no display please help.

Did yoy try to change co trast with potentiometer?

yes did that already but still white screen only, even i am using the program code of graphics test still white display please help


text:
How to do a HTTPS post on ESP8266
I am trying to do a HTTPS post on ESP8266 as shown in Postman below

But I keep getting: 'HTTP/1.1 401 Unauthorized'.
Can someone please help me with how to build up the headers correctly in the HTTPS POST? And maybe also give a link to some documentation? I cant seem to find any...
My code is:
const char* host = "api.dgs.com";
const int httpsPort = 443;
String url = "/ccs-int/v1/applicationdatalogging/1.0";
String msg = "";

WiFiClientSecure client;

Serial.print("connecting to : '");
Serial.print(host);
Serial.println("'");
Serial.printf("Using fingerprint '%s'\n", fingerprint);
client.setFingerprint(fingerprint);

client.connect(host, httpsPort);

Serial.print("requesting URL: '");
Serial.print(url);
Serial.println("'");

client.print(String("POST ") + url + " HTTP/1.1\r\n" +
    "Host: " + host + "\r\n" +
    "Connection: close\r\n" +
    "Content-Type: application/json" +
    "Authorization: Bearer " + authorization_code + "\r\n" +
    "Content-Length: " + msg.length() + "\r\n" +
    "\r\n" +
    msg + "\r\n");

Serial.println("request sent");
unsigned long timeout = millis();
while (client.available() == 0) {
    if (millis() - timeout > 5000) {
        Serial.println(">>> Client Timeout !");
        client.stop();
        return;
    }
}

Unauthorized says it all. I can't see anything for authorization in your code

And the documentation you've asked https://httpstatuses.com/401

If you're getting to the point that you get a 401 back, HTTPS is succeeding. 'Unauthorized' should mean that there's an issue with your authorization code. Do you have access to a computer that can run curl? If you do, try doing this post from that. It would be something like curl -X POST --header "Authorization: Bearer AUTHCODE" --header "Content-Length: 0" https://api.dgs.com/ccs-int/v1/applicationdatalogging/1.0 replacing AUTHCODE with your authorization code. This may help you debug what's going on with it.

I moved the autorization part up earlier in the 'client.print', which fixed the problem. However now I get a 411 error (Content-length has to be specified). Any idea what might be my new problem? I have specified the content length and I have also tried different values with no success.

@T.Krebs...can you share the full code example, It's a bit difficult to figure out which portion is setup and which is loop.


text:
Using Arduino Mega with multiple HC05 Modules as masters, communicating to multiple HC05 Modules as slaves, each connected to separate Arduino
So I have not actually experimented with the HC05 Bluetooth Module yet, but I have read up about it and watched some videos. From what I understand, you cannot use one module (master) to communicate with more than one other module (slaves), or at least its pretty difficult. But, you can use a module hooked up to an arduino to communicate to to another module hooked up to another arduino (I believe pretty simply).
However, I thought it might be possible to use an Arduino Mega (because it has multiple TX/RX pins) with 3 HC05 Bluetooth modules, to each communicate to 3 separate HC05s which would each be hooked up to an arduino nano. I know this might have to do something with running multiple Software Serials (I have no idea what that is to be honest)?
The project involves using the master arduino to "listen" for a button pressed on the slave arduino (across the room without connecting wires), then listening for another button press from one of the other slaves in some sort of sequence and within a certain time frame.
Does anyone have any idea about how this might be done, even if it doesn't use the HC05 Bluetooth Module?
Thanks!

Yes, this is possible. According to arduino.cc, the Arduino Mega has 4 hardware serial ports, so you can connect 3 HC-05 modules and still have 1 serial interface left. The Mega is a good choice, when you need this many serial interfaces, so at this point you don't even need SoftwareSerial. You will have to configure the HC-05 modules correctly from the master and command them to connect to the correct slave modules.
About SoftwareSerial: The serial interfaces mentioned above are "hardware" interfaces, meaning, that the itself microcontroller contains hardware, that does the main part of the receiving/transmitting by itself, without any need for code. The Serial library then only adds a bigger buffer for the data, wrapper functions to write to it and reacts to the interrupts, that come from the hardware interface. But since most microcontrollers only have a very limited number of hardware serial interfaces (often only 1 or even none), the SoftwareSerial library comes in handy. It emulates the UART protocol (which is a more professional term for the Serial interface from the Arduino world) with software (and some help from interrupts). This means, that you can use it with any pair of pins and you can even define multiple interfaces with it. But it also has drawbacks. For example: Only 1 SoftwareSerial interface can listen at once, you cannot use high baudrates, it uses interrupts, that you might need for an application.

That said, I don't think, that Bluetooth is the best way to go, if you only want to test a small number of buttons per slave. It is simply too much hassle to configure the modules and establish the connections correctly. Instead you can use 433MHz radio modules. They don't involve such a complex protocol like Bluetooth does, so it's a very simple solution. In the simplest case, you only need transmitters for the slaves and a receiver for the master. Every slave can send a short identifier, if the button was pressed. The master can then receive this data. Of course, if more than one slave sends simultaneously, the data will be garbage. But as long, as this is not a problem, you can keep it that simple.
There are many tutorials on the web, that explain how to use these modules. You can even find libraries, that are ready to use.

Great answer! This is great because I originally tried tackling this project using the nRF24L01 module but it was by no means easy to jump into as an arduino beginner. I did a quick Google search and found this article about 433MHz modules: https://dronebotworkshop.com/433mhz-rf-modules-arduino/ I think this might be a lot better for my application!


text:
String does not name a type
I'm using Arduino IDE for ESP32 WROOM board. I am testing the OTA feature with the ESP32httpUpdate library. I am using the example sketch of the library with the name httpUpdate.ino
However, as soon as I change the update url with a string pointer that I declare globally, it is throwing a compile error that String does not name a type. Any ideas?
/**
 * httpUpdate.ino
 *
 *  Created on: 27.11.2015
 *
 */
String* FIRMWARE_UPDATE_VERSION = "1000";

String* updateURL = "XYZ.php";

#include <Arduino.h>

#include <WiFi.h>

#include <HTTPClient.h>
#include <ESP32httpUpdate.h>

#define USE_SERIAL Serial

void setup() {

    USE_SERIAL.begin(115200);
    // USE_SERIAL.setDebugOutput(true);

    USE_SERIAL.println();
    USE_SERIAL.println();
    USE_SERIAL.println();

    for(uint8_t t = 4; t > 0; t--) {
        USE_SERIAL.printf("[SETUP] WAIT %d...\n", t);
        USE_SERIAL.flush();
        delay(1000);
    }

    WiFi.begin("SSID", "PASSWORD");

}

void loop() {
    // wait for WiFi connection
    Serial.println("Yolo");
    if((WiFi.status() == WL_CONNECTED)) {

        t_httpUpdate_return ret = ESPhttpUpdate.update(updateURL, FIRMWARE_UPDATE_VERSION);

        switch(ret) {
            case HTTP_UPDATE_FAILED:
                USE_SERIAL.printf("HTTP_UPDATE_FAILD Error (%d): %s", ESPhttpUpdate.getLastError(), ESPhttpUpdate.getLastErrorString().c_str());
                break;

            case HTTP_UPDATE_NO_UPDATES:
                USE_SERIAL.println("HTTP_UPDATE_NO_UPDATES");
                break;

            case HTTP_UPDATE_OK:
                USE_SERIAL.println("HTTP_UPDATE_OK");
                break;
        }
    }
}

https://docs.google.com/document/d/1G28416DlDBxZEHrLdYylUgBE80ePzbWDJtMKpQ6lJKk/edit?usp=sharing

link to the code

Code, that is this short, should be copied directly into the question and formatted correctly as code by selecting it and pressing the {} button in the editor. I've done this for you now, but please remind it for the next question.

Hey thanks. I did try to add the code in the question itself but it got weird and I couldn't do the formatting clearly so I gave a link.

what is String* updateURL = "XYZ.php";? you assign a pointer to constant char array to a pointer to String object. Where did you see something like this? It should be const char* updateURL = "XYZ.php"; or String updateURL = "XYZ.php";

I initially started with String updateURL = "XYZ.php" but the same error came up. Then I saw in the http library that the httpUpdate function accepts a pointer value so I was trying out with a string pointer

String is included by Arduino.h. Before #include <Arduino.h> String is not defined. Move #include <Arduino.h> to the top of the file or remove it. If you remove it, the Arduino builder adds it.

Thank you. It worked!/


text:
Interfacing Uno to Logitech Attack3 Joystick
I bought a Logitech Attack3 joystick at a garage sale for a couple of bucks and now I want to use it for something useful, like controlling a car or my small robotic arm. This joystick has 11 buttons and three sliders. I plugged it into a Sparkfun USB shield on top of an Arduino UNO and found some code online to get it up and running. It outputs hex values that tell me the slider values and the states of all the buttons. Where I am having difficulty is that I don't know C++ at all and the event handler and serial output commands are coming from the cpp file. I think that if I can get the output from the cpp file into the main loop in the ino file, I'll be able to do what I want with the data more easily. I plan to use a radio like XBee or Bluetooth to send commands based on the joystick output.
I cut down the code as much as I thought I could get away with. I'm hoping that someone can show me how to organize the code to allow me to do all my logic in the ino file.
Here is the INO file.

#include <usbhid.h>
#include <hiduniversal.h>
#include <usbhub.h>
#include <SPI.h>
#include "hidjoystickrptparser.h"

USB Usb;
USBHub Hub(&Usb);
HIDUniversal Hid(&Usb);
JoystickEvents JoyEvents;
JoystickReportParser Joy(&JoyEvents);

void setup() {
  Serial.begin(115200);
  pinMode(7, OUTPUT);
  digitalWrite(7, HIGH);
  if (Usb.Init() == -1)
    Serial.println("OSC did not start.");
  delay(200);
  if (!Hid.SetReportParser(0, &Joy))
    ErrorMessage<uint8_t > (PSTR("SetReportParser"), 1);
}

void loop() {
  Usb.Task();
  delay(10);
}

and the cpp file
#include "hidjoystickrptparser.h"

JoystickReportParser::JoystickReportParser(JoystickEvents *evt) :
joyEvents(evt),
oldButtons(0) {
        for (uint8_t i = 0; i < RPT_GEMEPAD_LEN; i++)
                oldPad[i] = 0xD;
}

void JoystickReportParser::Parse(USBHID *hid, bool is_rpt_id, uint8_t len, uint8_t *buf) {
        bool match = true;

        // Checking if there are changes in report since the method was last called
        for (uint8_t i = 0; i < RPT_GEMEPAD_LEN; i++)
                if (buf[i] != oldPad[i]) {
                        match = false;
                        break;
                }

        // Calling Game Pad event handler
        if (!match && joyEvents) {
                joyEvents->OnGamePadChanged((const GamePadEventData*)buf);
                for (uint8_t i = 0; i < RPT_GEMEPAD_LEN; i++) oldPad[i] = buf[i];
        }

        uint16_t buttons = (0x0000 | buf[6]);
        buttons <<= 4;
        buttons |= (buf[5] >> 4);
        uint16_t changes = (buttons ^ oldButtons);

}

void JoystickEvents::OnGamePadChanged(const GamePadEventData *evt) {
        Serial.print("Joystick X: ");
        PrintHex<uint8_t > (evt->X, 0x80);
        Serial.print("\tJoystick Y: ");
        PrintHex<uint8_t > (evt->Y, 0x80);
        Serial.print("\tTrim: ");
        PrintHex<uint8_t > (evt->Z1, 0x80);
        Serial.print("\tSW1-8: ");
        PrintHex<uint8_t > (evt->Z2, 0x80);
        Serial.print("  SW9-11: ");
        PrintHex<uint8_t > (evt->Rz, 0x80);
        Serial.println("\t");

and the header file
#if !defined(__HIDJOYSTICKRPTPARSER_H__)
#define __HIDJOYSTICKRPTPARSER_H__

#include <usbhid.h>

struct GamePadEventData {
        uint8_t X, Y, Z1, Z2, Rz;
};

class JoystickEvents {
public:
        virtual void OnGamePadChanged(const GamePadEventData *evt);
};

#define RPT_GEMEPAD_LEN     5

class JoystickReportParser : public HIDReportParser {
        JoystickEvents *joyEvents;

        uint8_t oldPad[RPT_GEMEPAD_LEN];
        uint8_t oldHat;
        uint16_t oldButtons;

public:
        JoystickReportParser(JoystickEvents *evt);

        virtual void Parse(USBHID *hid, bool is_rpt_id, uint8_t len, uint8_t *buf);
};

#endif

Here is what the output looks like in the serial monitor
Joystick X: 80  Joystick Y: 82  Trim: 7A    SW1-8: 00  SW9-11: 00
Joystick X: 7B  Joystick Y: 80  Trim: 7A    SW1-8: 00  SW9-11: 00
Joystick X: 7B  Joystick Y: 7F  Trim: 7A    SW1-8: 00  SW9-11: 00
Joystick X: 7B  Joystick Y: 7F  Trim: 7A    SW1-8: 00  SW9-11: 01
Joystick X: 7B  Joystick Y: 7F  Trim: 7A    SW1-8: 00  SW9-11: 00

An Arduino Sketch's .ino is C++ code. It just doesn't define or use any C++ classes by default. It's vanilla C, which is a subset of C++. It isn't clear to me what your Usb.Task(); line does, or how that invokes code in the joystick C++ file you posted. Is there documentation on the joystick library you're using?

The sample I'm showing is exactly as I found online, except that I took out unneeded some code and tweaked the Serial.print lines in the cpp file. I also don't know exactly what routine Usb.Task() does. I'll get back to you with more information.


text:
Arduino uno holder
Arduino sells a holder for the UNO board, but without much documentation or detailed specifications, see this link.  Can anyone give the diameter of four small holes, two located on the top edge and one each on the left/right edges?   What size of screw will fit?  They are smaller than M3 / 4-40 apparently.
Also, does anyone know what material is the holder made from?

If you can read the recycle logo on the plastic, you should be able to determine the material. The image is too unclear to determine from the post.

** Self answer:
I obtained several of these holders from Arduino starter kits.  They are made from a clear, colorless plastic that seems to have been injection molded.  However, it is hard to tell exactly which plastic, since these does not have any recycle logo!  The image posted in the original question is perhaps a newer version.
The four smaller holes can accept M2.5 screws, I checked.

Arduino UNO holes are just over 3mm in diameter. Both 4-40 and M3 bolts will work well, giving you a bit of wiggle room. You will have to file down the width of the bolt head to fit against the 6 pin header near D13.
As far as the holder material, I don't know. I 3D print my own.

The holes I asked about are smaller than M3 (i.e. while on the Arduino PCB they may be M3, on the holder M3 screws are too large and do not fit), sounds like a design flaw.

Probably M2.5. The Arduino Uno is full of design flaws. Idiotic design "decisions" that normal people would never have made.


text:
Burning Arduino Bootloader
I'm trying to use an atmega chip from an arduino on a breadboard, with minimal hardware (using the internal 8mhz clock).  I am using the article in the link provided.  When I reach the final step (burning the bootloader), I get an error telling me the device signature is wrong-
Arduino: 1.8.5 (Windows 10), Board: "ATmega328 on a breadboard (8 MHz internal clock)"
avrdude: Yikes!  Invalid device signature.
         Double check connections and try again, or use -F to override
         this check.
Error while burning bootloader.
I am assuming the error is because the chip is from a uno clone, and uses an atmega328p-pu chip.  How am I able to override this check using -F, as described in the error message?  Or is there maybe some other way i can fix this?  Thanks in advance.
https://www.arduino.cc/en/Tutorial/ArduinoToBreadboard

One of the parameters that you have to give avrdude is the microcontroller you are using, and then it checks the signature of the micro to ensuere that everthing is ok. this parameter is passed through -p flag
avrdude -p <microcontroller name>

For ATmega328 this parameter should be m328 and in your case, with ATmega328p this parameter should be m328p. All options avalible can be checked in man page.

Ok thanks.  How do I access and change the flag?

If you are using Arduino IDE to load micro, you will have to select what micro you are using in Tools > Board Menu or something like this. Anyway you can use terminal also.


text:
Arduino Smoothing does not work as expected
I using the standard example of smoothing:

/*
  Smoothing

  Reads repeatedly from an analog input, calculating a running average and
  printing it to the computer. Keeps ten readings in an array and continually
  averages them.

  The circuit:
  - analog sensor (potentiometer will do) attached to analog input 0

  created 22 Apr 2007
  by David A. Mellis  <dam@mellis.org>
  modified 9 Apr 2012
  by Tom Igoe

  This example code is in the public domain.

  http://www.arduino.cc/en/Tutorial/Smoothing
*/

// Define the number of samples to keep track of. The higher the number, the
// more the readings will be smoothed, but the slower the output will respond to
// the input. Using a constant rather than a normal variable lets us use this
// value to determine the size of the readings array.
const int numReadings = 10;

int readings[numReadings];      // the readings from the analog input
int readIndex = 0;              // the index of the current reading
int total = 0;                  // the running total
int average = 0;                // the average

int inputPin = A0;

void setup() {
  // initialize serial communication with computer:
  Serial.begin(9600);
  // initialize all the readings to 0:
  for (int thisReading = 0; thisReading < numReadings; thisReading++) {
    readings[thisReading] = 0;
  }
}

void loop() {
  // subtract the last reading:
  total = total - readings[readIndex];
  // read from the sensor:
  readings[readIndex] = analogRead(inputPin);
  // add the reading to the total:
  total = total + readings[readIndex];
  // advance to the next position in the array:
  readIndex = readIndex + 1;

  // if we're at the end of the array...
  if (readIndex >= numReadings) {
    // ...wrap around to the beginning:
    readIndex = 0;
  }

  // calculate the average:
  average = total / numReadings;
  // send it to the computer as ASCII digits
  Serial.println(average);
  delay(1);        // delay in between reads for stability
}

to calculate power consumption for a load which changes it's value frequently (sometimes it stops and the consumption goes down to couple of watts).
My only modification of the above code is to pass a calculated power (V*I) value to it instead of the analogRead(inputPin);. The input value for the power calculation works fine because without this code I get the exact good values for power. I have also increased the numreadings from 10->100 and probably will needed to be increased a lot more since I need the average for 1 minute.
There are 2 major issues with this code:
1, When a constant load is attached, which let's say draws 500W the value generated by the code is floating around 312W and never reaches 500.
2, When the load is disconnected it and the current power consumption is 1-2watts standby this code jumps to -312W. I could cast it to be an unsigned integer on the first place but that's not really a good solution.
Anyone knows how to fix this?
Thanks

Consider the size of your array, the size of the Arduino RAM, and the number of items you will need in the array if you want to use this to generate an average over a minute or more.  Will it all fit?

Are your power readings int or float?

Ten analogRead values summed together can easily overflow int total.

@AnT how did you figure the sum of ten analogReads can overflow an integer? Even if they were the maximum (1023) that would surely easily fit into an integer- even if it were a 16 bit int. I am a bit confused by your comment..

@GMc: Frankly, I have no idea why I said that. A sum of ten should fit into a 16-bit int.

no problemo, at least it is cleared up now :)

Yes, change the variable type to something that can hold larger numbers, because now adding up 100 measurements will overflow your variable.


text:
How can I scan for a HIGH signal on digitalRead during the main loop, while running other things?
I'm working on a program which listens for certain bytes on serial through an if/then/elseif ladder. I want to also check if a pin (say, A15) has been given a HIGH state, by another Arduino with shared ground. The slave Arduino will turn a digital pin to HIGH and I want the MEGA2560 to check every time it loops if a HIGH is present from the other board. A "While button not pressed do nothing statement won't work, because that won't let the loop go. I tried doing an if statement, using something to the effect of this:
if (digitalRead(A15)==HIGH) {
  //things to do
}

But it seems no matter what I put, be it HIGH, LOW, != HIGH, != LOW, etc. or either input pinmodes, pullup or not, it always thinks the board is transmitting HIGH. In fact, it only doesn't think it's HIGH when it actually is HIGH. I'm pretty stumped on this. If you ask me, digitalRead is really odd with what's HIGH and what's LOW.

Do you declare A15 as INPUT in Setup(), pinMode(A15, INPUT);? Could you show us the entire sketch you are using?

I tried both that and input_pullup as well. I can include the whole sketch. EDIT: Actually ,unfortunately, I just looked and it looks like, because the previous sketch bricked the board, I edited it back to before this was added and neglected to save a copy of the broken code.

Do you have a custom atmega2560 pcb or a real arduino mega 2560 board or a clone? Maybe some gnd or vcc pins of the atmega2560 are not soldered. Is the arduino mega 2560 running at 5.0v? It starts to do weird things at 4.5v or lower.

It's an Elago clone of the MEGA2560 board. I have it connected to a desktop's USB port, so I doubt there's power failure.

Simplify, and show your setup code.
First, do you have a pinMode call in your setup function:
void setup() {
  pinMode(A15, INPUT_PULLUP);
  Serial.begin(115200);
}

Then use test code like this:
void loop() {
   if (digitalRead(A15) == HIGH) {
      Serial.println("Pin A15 is HIGH");
   } else {
      Serial.println("Pin A15 is LOW");
   }
}

Connect your A15 pin directly to ground with a jumper and run the sketch above. Open the serial monitor and see what is output. It should be LOW. Then disconnect the jumper and check again. It should now be HIGH. Finally, connect the jumper between A15 and +5V and check the output again. It should still show HIGH.
That lets you troubleshoot just the software piece. Once you get that working, connect pin A15 to the remote Arduino's output pin and try again.

I'll try this as soon as I get to the board tomorrow.


text:
DHT11 + ESP plus Arduino
Someone could help me?
I want to use dht11 with arduino and esp. Both will read data from dht11
the problem is that simultaneously cannot be done. So the solution will be to set one as a master and the other one as a slave.
the control will be done like so...
another wire from arduino pin->set as output ->esp pin->set as input.
if wire == 1 then dht11 will be read by arduino
if wire == 0 then esp will read dht.
with some delay ofcourse. but the problem is that i dk how to stop the communication between one board and the sensor when the other board will read it. so does it not exist any conflict

Please add your sketch (so far).

I've added it already

Disclaimer:
I've never used an ESP chip based board I know almost nothing about them. I am going to assume that it works, in software terms, like an Arduino, and base my answer on Arduino code. If the esp chip works differently, you'll need to adapt my suggestion.

Try something like this:
Connect a GPIO line between the microcontrollers. Also connect that line - through a 10K resistor - to +5V.
Have both microcontrollers set up it's GPIO as an input.
(We'll call the GPIO pin on both microcontrollers the "DHT_available" line. It will be HIGH when the DHT sensor is not being used by the other controller.)
When one of the microcontrollers wants to read the DHT11, have it check the GPIO line. If it's HIGH switch the GPIO line to an output and pull it low, then take a reading. When the reading is complete, switch the GPIO line back to an input.
If the GPIO line is LOW, wait and check again.

Alternately you could attach each of the microcontroller's GPIO lines to interrupt handlers on a rising edge. Then have the interrupt handler set the GPIO line to an output, pull it to LOW, and set a flag that means "begin reading".
Have your loop function check the "begin reading" flag, and if true, trigger a read from the DHT, and once it's complete, set the GPIO back to an input.
With the first option, each microcontroller would need to poll the "DHT_available" line continuously until it goes HIGH before beginning reading.
With the second option, as soon as one of your microcontrollers is done taking a reading, it would stop pulling the communications line LOW, the other one's rising edge interrupt would fire, and the other one would immediately begin reading.

I don;t know how to write code for all of that stuff. i am a beginner in microcontrollers

So use 2 separate DHT11 sensors, one for each microcontroller. They're cheap.

Also.. i would see a problem there. Lets say so..
Sensor data.
Gnd.
Vcc
uC 2560
uC Esp
If sensor data is linked to both uC
And  use a line dht_available btween 2560 and esp to handle the uC reading.. then..
If dht_available == HIGH then 2560 read after switch dht line to Low
If dht_available == LOW then esp read after reading dhtline》 HIGH
But the sensor wil continue to send data to both.. regqrding the dhtline is high or low.
I dk how to say to sensor.. if dhtline is LOW stop sending data to 2560 because is esp time to read.