text:
Why do my temperature sensor values become inconsistent when additional hardware is added to the board?
I have this strange problem. My TMP 36 sensor works fine when it is the only thing connected to my Arduino Uno board. The voltage measurements, and thus the temperature, are accurate and consistent. However, when I attach an LCD screen to the Uno and have a program print the TMP's measurements to the screen, the values become inconsistent, and can change up to 10 degrees F from one reading to another. (I have the sensor take a measurement every second.) This does not happen when the LCD screen is not plugged in. I decided to remove separate connectors from the screen and see when the measurements became consistent again. I tried this once and found that a ground wire that goes to connection 5 on the screen caused to value to change when I repeatedly inserted and removed it from a ground pin. The TPM values were changing even when there was nothing else connected to the LCD (it wasn't on) except for the ground wire. I don't understand how this is possible, and I don't know if this is a hardware or software issue.
I rewired the LCD screen starting with sensor wires, then ground wires, and then the two 5V connections, with one of them having a 220 ohm resistor. I did this while the circuit was powered, and watched the values for any large changes. The first change was a few seconds after I wired the last 5V wire. The sensor measured 80 degrees F and then 85 degrees F one second later. It then went to 81 for a few seconds, then 87. The values continued to change, but not by as much as previous times. By the way, the temperature in the area that the Arduino is in is about 82 degrees F.
TMP values do not change by more than 3 degrees F when the LCD is not connected to the screen. I don't understand what could be causing this. Has anyone else had this problem before, or know the cause?
Here is the layout.
#include <LiquidCrystal.h>

LiquidCrystal lcd(12,11,5,4,3,2);
const int sensorPin = A5;
const float baselineTemp = 20.0;

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

void loop() {
  int sensorVal = analogRead(sensorPin);
  Serial.print("Sensor value: ");
  Serial.print(sensorVal);
  float voltage = (sensorVal / 1024.0) * 5.0;
  Serial.print(", volts: ");
  Serial.print(voltage);
  Serial.print(", degrees C: ");
  float temperature = (voltage - .5) * 100;
  Serial.print(temperature);
  Serial.print(", degrees F: ");
  float fahrenheit = (temperature * 1.8 + 32);
  Serial.println(fahrenheit);
  delay(1000);
  lcd.begin(16,2);
  lcd.print(fahrenheit);
  lcd.print(" degrees F");
  float averageTemp;
  if(temperature < baselineTemp) {
    lcd.setCursor(0,1);
    lcd.print("Below room temp");
  }
}

You could have any of several issues: electrical noise, sagging power supply under load in a circuit which does not factor that out, or perhaps power consumption of the circuit (the majority of which will end up as heat) causing the assembly to heat a bit above ambient.  Your question is not really answerable without precise details of your setup - schematics, part numbers, and physical layout.

Can you please try putting a Diode (like an LED) between them? That way you'll eliminate the possibility that the LCD may be back feeding. Can you also tell us what Temperature sensor you're using? I've done a similar project (with DS18B20) but it didn't cause funny readings ......

I have added my code just in case, though I highly doubt it has anything to do with this. I will add the layout as well.

Layout is in the post.

Your "layout" is nearly uninterpretable, but try giving the temperature sensor its own leads to the power supply so it does not share with the LCD, and add some bypass capacitors.

Don't take power for LCD from Uno pins. Connect LCD power to separate power source.

+1, Useful suggestion b/c TMP 36 is an analog sensor and power supply noise or sag would affect the reading. Why the drive-by downvote, @someone?

I didn't downvote but this isn't a complete answer at all. It's just general advice without any reasoning written in. It should explain why the LCD power should be from a separate power source, and how it relates to the question.

I had this issue and put a 0.1 µF capacitor across the sensor and got much reduced noise (to within half a degree which is really +- one tick).

For an analog sensor like the TMP36, the Arduino uses the 5V as reference. If the 5V changes (but the TMP36 voltage stays the same), the Arduino thinks that the temperature has changed. The value returned by analogRead() increases. That is why the temperature seems to raise if the 5V is lowered.
The TMP36 (with resistor) outputs a certain voltage. That is different from 'ratiometric' sensors, they output a voltage relative to the 5V, and changes to the 5V have no effect on the result. A 'ratiometric' sensor is for example a wheatstone bridge, or a LDR with resistor.
With the TMP36, you need a good voltage reference to read the actual voltage. The internal voltage reference can be used. Perhaps an extra voltage divider is needed. Or use a power supply to the power barrel jack and let the onboard voltage regulator create a fixed voltage of 5V which can be used as reference.
When using digital temperature sensors, like the DS18B20, all these problems are gone instantly.
The 5V should never be connected to AREF. It is already internally connected to VCC at default, and when the internal voltage reference is selected, the AREF pin changes the voltage. In that case, an internal shortcut is created when AREF is connected to 5V. There is no need to add 100nF to AREF, since the Arduino Uno has already 100nF to AREF and GND.
A breadboard can have bad contacts. Since the current of the LCD uses the same GND and +5V wires, it can have influence on the TMP36. It is better to use seperate wires as already mentioned by Chris Stratton. To reduce noise you could take a number of analogRead() values and use the average. For an analog temperature sensor it is common practice to average a number of samples.

Try powering your circuit using a 9V battery. I have also had this problem and it worked when I used a separate power supply. It seems to be an electrical noise caused by your computer USB. The answer posted by JRobert should be necessary if you want to power from the computer.

I don't see +5v -> Aref (and Aref -> bypass capacitor -> Gnd). Necessary, if you are using the power supply voltage as a reference, as you appear to be.


text:
Pair of nRF24L01s ping/pong example sketch works, but using my own code fails after first successful transmit
I have a pair of nRF24L01s connected to a pair of Arduino Unos and I'm using the RF24 library from here: RF24 library. When I run the pingpair example sketch, the radios transmit and receive back and forth just fine. So I tried to program my own very simple example but I'm running into a problem where the first message transmits successfully (and is received successfully), however, subsequent messages fail to send. The call to radio.write() returns false.
I'm using the following code on the 'sender':
RF24 radio(9,10);
const uint64_t pipes[2] = { 0xF0F0F0F0E1LL, 0xF0F0F0F0D2LL };
uint8_t payload[1];

void setup() {
  Serial.begin(9600);
  radio.begin();
  radio.setRetries(15, 15);
  radio.setPayloadSize(1);
  radio.openWritingPipe(pipes[0]);
}

void loop() {
  payload[0] = 1;
  bool ok = radio.write(payload, 1);
  Serial.println("Status: " + (String) ok);
  delay(200);
}

And the following on the 'receiver':
RF24 radio(9,10);
const uint64_t pipes[2] = { 0xF0F0F0F0E1LL, 0xF0F0F0F0D2LL };
uint8_t payload[1];

void setup() {
  Serial.begin(9600);
  radio.begin();
  radio.setRetries(15, 15);
  radio.setPayloadSize(1);
  radio.openReadingPipe(1, pipes[0]);
  radio.startListening();
  Serial.println("Listening: " );
}

void loop() {
  if (radio.available()) {
    bool done = false;
    while (!done) {
      done = radio.read(payload, 1);
      Serial.println("Got payload: " + (String) payload[0]);
    }
  }
}

I'm guessing the problem has to be with my code because the example sketches work, but I can't figure out what the problem is. Again to summarize, when I reset the Arduino, the first call to radio.write() returns true and the message is transmitted. After that, subsequent calls to radio.write() return false.
Also note that I did try adding a 10uF capacitor across +3.3V and Ground but it did not help.
Thanks for any help.

Do you need to reset both arduinos to make it work or just one?

Which library are you using?

I agree with the answer below to use several Serial.println to figure out where it gets stuck. In the library config file (RF24_config.h) there is a #undefine at line 32 - change that to #define so you get the serial debug strings from the library as well so you can try to figure out where the error is happening. If you still can't figure it out then post the debug output here.

What version of the library are you using? Please make sure you are using the maintained fork by TMRh20. http://tmrh20.github.io/RF24/

Comparing your rx against the example, i would suggest not having the while done statement. You could also throw in a few serial.write debug lines in both sketches, to log different parts of the code, to find where its getting stuck.

I was just having this issue. You need to be able to read and write on both ends. You send up sending an ack package back to the sending arduino like in the test sketch.
You ripped that part out.
You need to read back through the example code and line by line understand what the data is doing and why it's doing it that way before you can start using rf24.
The short of it is that the sender will send data and then finish and wait for a response packet before sending the next one. The reciever works much the same way except it always will be listening for incoming data until the sender message ends. Then it in turn will send a reply packet saying that it recieved the first packet.
Make sure that the reciever isn't looping waiting for packets. It should only respond once it recieves something. The sender should have a timeout on it so that it knows that it's messages are failing. This is also incredibly important for debugging so you can see who failed and why.
This is basically tcp at work.
You can also use noack and that's called udp

You should open a reading pipe on the transmitter end because when the reader receives your message it will reply with an acknowledge packet, which is expected by the writer in order to confirm the packet has been delivered. With your current setup, your writer is sending out a packet and expecting to receive the response on an address which is by default configured as a broadcast address.
On the sender side, you also need to start listening after sending the packet and stop listening before sending the new packet.
The transmission protocol works like this:

the sender sends a packet in the air and starts waiting for the ack
all listeners receive the packet, no matter their receive address
each listener check if the sender address matches with any configured reading pipe address

if the address matches then the listener sends back an acknowledge packet to inform the transmission has been accomplished
if the address does not match it discards the packet

if the sender receives at least one acknowledge packet then it marks the packet as being sent successfully
if the sender doesn't receive the ack packet within the configured time to live then sends the packet again until the retry count has not been reached
if the retry count has been reached then it marks the transmission as failed

So change your sender setup() and loop() functions above with:
void setup() {
  Serial.begin(9600);
  radio.begin();
  radio.setRetries(15, 15);
  radio.setPayloadSize(1);
  radio.openWritingPipe(pipes[0]);
  radio.openReadingPipe(1, pipes[1]); // add this
}

void loop() {
  radio.stopListening(); // add this
  payload[0] = 1;
  bool ok = radio.write(payload, 1);
  radio.startListening(); // add this
  Serial.println("Status: " + (String) ok);
  delay(200);
}

You might also want to set the writing address on the receiver if you plan to use more than 2 radios, otherwise, you will not be able to distinguish who has acknowledged different packets:
radio.openWritingPipe(pipes[1]); // add this to receiver `setup()`

source: Stack Exchange

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

sort: votes


text:
How to improve button turn on/off experience
I have simple circuit turning lights on and off on button click.
It is working quite fine but there is a small issue with button click itself, it is not fully reliable.
Turning lights on is pretty fine but turning them off is tricky.
Basically clicking once almost never works. I need to click in the right moment to turn them off or better keep pressing the button until right moment. If I hold too long it also doesn't work or work wrongly.
Here is the loop code:
void loop() {
    int buttonState = digitalRead(BUTTON_PIN);
    if (buttonState == 1) active = not active;

    if (active) {

       ... led setup

      FastLED.show();
      FastLED.delay(1000 / UPDATES_PER_SECOND);
    } else {
      fill_solid( leds, NUM_LEDS, CRGB::Black);
      FastLED.show();
//      FastLED.clear();
    }
}

What do I need to do to make it working as expected which is:

single click turn light on
another click or hold for a while turns light off for good and they stay off until next click

use the Bounce2 library

It's called "Debouncing" - I think there is even library for it.

I second Juraj. The Bounce2 library handles this very good

I think that you have a couple of things going on here. Debouncing has already been mentioned and I don’t want to discount that at all – there is a ton of information on that subject.
In your case, I think it would be helpful for you to consider 1) how you are defining a button press and 2) how much processing you are doing when you are not checking for a button press.

To demonstrate, I used this simple set up with a switch:
Then I modified an example from the FastLED library to simply toggle one LED (from a 12 LED, generic, neopixel ring [no clock] and ran it on an UNO (I know you are using a nano, but I think it should still work) using this code.
#include <FastLED.h>

#define NUM_LEDS 1

int LEDon = 0;
#define DATA_PIN 6

int switchPin = 8;

CRGB leds[NUM_LEDS];

void setup() {
  // ## Clockless types ##
  FastLED.addLeds<NEOPIXEL, DATA_PIN>(leds, NUM_LEDS);  // GRB ordering is assumed
  pinMode(switchPin, INPUT);
  // start with LED off (not strictly needed)
  leds[0] = CRGB::Black;
  FastLED.show();
}

void loop() {
  if ( digitalRead(switchPin) == HIGH) { // switch is pressed
    if (LEDon == 0) {
      LEDon = 1;
      leds[0] = CRGB::Red;
      FastLED.show();
    }
    else {
      LEDon = 0;
      leds[0] = CRGB::Black;
      FastLED.show();
    }
    while (digitalRead(switchPin) == HIGH); // wait until switch is released
  }
}

I don’t have much experience with this library (it does appear to be very powerful) and don’t know if you can read the state (on/off/color/intensity) of the LEDS – so I just kludged a variable (LEDon) for the example. It works fine. No missed presses and you have to release the button before you can press it again.
Note that I am doing only the minimum amount needed in between looking for a button press.
Libraries are great, but you need to understand a good deal about using them. I think that you are doing time-consuming processing that is causing you to miss presses, which is why you say “I need to click in the right moment to turn them off or better keep pressing the button until right moment”.
I also think that you are ill-defining a press. In the code, I am specifically looking for the button to be released. Because some time is spent processing after the button press is detected, I don’t have to explicitly debounce the switch – for this example. That does not mean that you can always get away with that.
Think about how functionally vague your definition of a press is,
•  single click turn light on
•   another click or hold for a while turns light off for good and they stay off until next click
I would respectfully recommend that you:
Learn as much as you can about the library. Take a look, for example, at this discussion FastLED.delay()  https://github.com/FastLED/FastLED/issues/1206
Do as much as you possibly can in setup().
Do as little as you need to in-between checking for a press (or think about using interrupt).
Hope it helps.

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


text:
ESP8266 + 4x TM1637 == possible?
I'm having trouble getting my NodeMCU connected to 4 x 4 Digit 7 Segment Displays.
So far I've been able to connect 2 & get them to display things from the demo repository.
However, after trying all possible combinations of different pins & looking up the pinout reference I have no idea why I can't get them to work.
Any help would be greatly appreciated.
I'm working with:

ESP8266 NodeMCU ESP-12E (CP2102)

4 Digit 7 Segment Display (TM1637)

As suggested @romkey:
#include <Arduino.h>
#include <TM1637Display.h>

// Module connection pins (Digital Pins)

#define CLK_1 D2
#define DIO_1 D3

#define CLK_2 D5
#define DIO_2 D6

#define CLK_3 13
#define DIO_3 15

// The amount of time (in milliseconds) between tests
#define TEST_DELAY   500

TM1637Display display1(CLK_1, DIO_1);
TM1637Display display2(CLK_2, DIO_2);
TM1637Display display3(CLK_3, DIO_3);

void setup()
{
}

void loop()
{
  int k;
  uint8_t data[] = { 0xff, 0xff, 0xff, 0xff };
  uint8_t blank[] = { 0x00, 0x00, 0x00, 0x00 };
  display1.setBrightness(0x0f);
  display2.setBrightness(0x0f);
  display3.setBrightness(0x0f);

  // Brightness Test
  for(k = 0; k < 4; k++)
    data[k] = 0xff;
  for(k = 0; k < 7; k++) {
    display1.setBrightness(k);
    display1.setSegments(data);
    display2.setBrightness(k);
    display2.setSegments(data);
    display3.setBrightness(k);
    display3.setSegments(data);
    delay(TEST_DELAY);
  }
  while(1);
}

I've tried addressing the CLK_3 & DIO_3 pins as "Dx" but that didn't work as well.
Repos used:

https://github.com/avishorp/TM1637

There’s a lot that can go wrong here. If you share exactly how you connected the most likely to work circuit and a minimal viable example of the code that doesn’t work, someone will be more likely to help you.

use one clock pin for all. avoid boot config pins D3,D4,D8 and RTC pin D0

Try one display at a time but on different pins to make sure that your selection works at all. Only after success merge all together.

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


text:
Arduino IDE won't use selected port
I'm trying to program an ATtiny85, using an AVRISP mkII programmer (this one: https://www.amazon.de/dp/B00IYNAXUC/ref=cm_sw_r_sms_c_api_i_VXOWDb3H3N5ND) with the Arduino IDE (version 1.8.10 on Ubuntu 18.10). For the ATtiny, I've installed https://github.com/damellis/attiny using the board manager, as recommended in countless tutorials.
Now, everything seems to be recognized fine, and I've selected the programmers port in the IDE: /dev/ttyACM0.
But when I try to upload a sketch, the IDE instead trys to pass usb as the port to avrdude. This is only visble when enabling verbose output: (paths abbreviated)
/home/[...]/avrdude -C/home/[...]/avr/etc/avrdude.conf -v -pattiny85 -cstk500v2 -Pusb -Uflash:w:/tmp/arduino_build_728460/sketch.ino.hex:i

avrdude: Version 6.3-20190619
         Copyright (c) 2000-2005 Brian Dean, http://www.bdmicro.com/
         Copyright (c) 2007-2014 Joerg Wunsch

         System wide configuration file is "/home/[...]/avrdude.conf"
         User configuration file is "/home/[...]/.avrduderc"
         User configuration file does not exist or is not a regular file, skipping

         Using Port                    : usb
         Using Programmer              : stk500v2
avrdude: usbdev_open(): did not find any USB device "usb" (0x03eb:0x2104)

avrdude done.  Thank you.

usb isn't even a selectable port in the IDE!
Simply pasting the avrdude command (first line in the output above) to a terminal and changing usb to /dev/ttyACM0 makes it program the IC perfectly (but of course, that's a rather cumbersome workaround).
Also, selecting another programmer in the IDE (like AVR ISP, without the mkII) makes it use the correct port (but of course it won't work, since it's the wrong programmer).
Am I doing something wrong, or is this an actual bug in the Arduino IDE?

upvote for well written question

Did you hold the Shift button while clicking upload?

@Coder_fox I tried that too (uploading with programmer instead of just uploading), but it didn’t seem to have any effect.

You mean that the STK500 v2 programmer uses an emulated serial port
rather than direct USB? Then I guess there is a bug in the Arduino IDE.
The file programmers.txt contains the following lines
describing the programmer:
avrispmkii.name=AVRISP mkII
avrispmkii.communication=usb
avrispmkii.protocol=stk500v2
avrispmkii.program.protocol=stk500v2
avrispmkii.program.tool=avrdude
avrispmkii.program.extra_params=-Pusb

You may locate this file in your Arduino installation and replace the
last line from this snippet by
avrispmkii.program.extra_params=-P{serial.port}

If that works, it would be a good idea to submit a pull request with the
fix to the Arduino team.
Alternatively, you may try selecting “Atmel STK500 development board” as
a programmer. This is supposed to autodetect the version of the STK500
protocol, and uses the correct serial port.
Edit: you may also have to replace
avrispmkii.communication=usb

by
avrispmkii.communication=serial

C.f. this bug report, which seems to cover the exact issue you are
facing.

I would say you have to select  the Arduino as ISP Programmer. Not the mkII ISP. Perhaps the attiny board library can handle connection to attiny dev boards over usb if you use the standard programmer. But that's just a very very rough guess. But selecting the Arduino as ISP is a requirement.
Edit:
No you can not use the Arduino as ISP if you use an STK500 programmer.
D. A. Mellis' tool is designed for an Arduino as a programmer.
But if your work around does the programming, the mkII is the right tool. You have to find out, how the IDE builds the CLI string to start avrdude.
The tool you installed contains a text file called platform.txt:
name=ATtiny Microcontrollers

tools.avrdude.path={runtime.tools.avrdude.path}
tools.avrdude.erase.params.verbose=-v -v -v -v
tools.avrdude.erase.params.quiet=-q -q
tools.avrdude.erase.pattern="{cmd.path}" "-C{config.path}" {erase.verbose} -p{build.mcu} -c{protocol} {program.extra_params} -e -Uefuse:w:{bootloader.extended_fuses}:m -Uhfuse:w:{bootloader.high_fuses}:m -Ulfuse:w:{bootloader.low_fuses}:m

tools.avrdude.bootloader.params.verbose=-v -v -v -v
tools.avrdude.bootloader.params.quiet=-q -q
tools.avrdude.bootloader.pattern="{cmd.path}" "-C{config.path}" {bootloader.verbose} -p{build.mcu} -c{protocol} {program.extra_params}

I would say the entry tools.avrdude.bootloader.pattern does the trick. Especially the variable {program.extra_params}. You have to find out how the IDE is building this variable. One of it's options must be -P<Port>. But why does the IDE use the value usb for <port>?
I'll try to find out. But I have no access to an IDE at the moment. If you (or someone else) find a solution before me, please add an answer and mark it as accepted, so I need not investigate further.

I‘m not trying to use an Arduino as a programmer. I have this one: https://www.amazon.de/dp/B00IYNAXUC/ref=cm_sw_r_sms_c_api_i_VXOWDb3H3N5ND Do I really have to select Arduino?

You do not use a Arduino for programmer as the documentation you pointed us to requires. That's a really interesting information. ;-) I would add it to the question. I'll edit my answer.

My bad, I thought AVRISP mkII was enough info. Question is updated.

The answer of @EdgarBonet gives you the Information, I was looking for.

And you are right, AVRISP mkII should have given me the hint. It was not your fault. Just I was too lazy to think. But it is always a good idea to give as much information as you can, to keep lazy people like me from wrong interpretations. ;-)


text:
What do the TinyGPS++ output parameters mean?
TinyGPS++ give many output parameters. Where can I find explanation what do all output parameters mean? I don't understand what is the meaning of the following parameters:

Course Speed Card  Distance Course Car

UPD
2365 is distance to London
wnw is the direction to London: https://en.wikipedia.org/wiki/Points_of_the_compass#Compass_point_names
0.00 - Vertical speed?
0.06 - Horizontal speed?
294.06 - ???

As you can see when you look at the source code of the FullExample.ino that is part of the TinyGPS++ library, the values you marked are:

Course Speed Card*: The current speed (in km/h), course (in degrees) and cardinal course (which is the course translated to a cardinal direction on a compass, i.e. N,S,E,W, NE, NNW, etc.) of the GPS receiver (i.e. you).
Distance Course Card**: The distance (in km) and course and cardinal course to some location or waypoint (London in this example).

After the information you added in your edit, this means the following:

0.00 is your current course over ground (i.e. due North)
0.06 is current current speed over ground (i.e. as good as stationary)
N is your current cardinal course
2365 is the distance to London (km)
294.06 is the bearing to London from your location
WNW is the cardinal bearing to London

* this is also known as SOG (Speed Over Ground) and COG (Course Over Ground, which is used in (aero)nautical navigation) or Bearing.
** this is also known as DTG and CTS (Distance to Go and Course to Steer) when navigating to a GPS waypoint.

Thank you! The only thing I don't understand is why my GPS module is always moving to North and current course over ground is always 0. My GPS module doesn't move at all, so I understand that variable slow speed 0.06 is due to some errors. In this case the course and direction supposed to change randomly, but they are remain constant: 0.00 and N.

It might be your GPS module is only able to calculate a course if it moves more than a certain distance/speed. What I have seen from various GPS systems, this is normal behaviour.


text:
NEO 6M data is not working properly with uno
I am using a arduino uno and neo 6m gps module. The problem I am facing is quite weird. When I connected the setup the data from neo6M was seen in serial monitor, I even printed it on a Oled display. It was a close room at night. I used tiny gps plus plus library to parse the data. I got both latitude longitude. After disconnected the circuit i tried again and that is when nothing came out in serial monitor. The same sketch did not work for a day. But again at afternoon at some point i got the data properly.
Sometimes the red led is blinking but nothing happens.
While I change the rx and tx pins in software serial it got data but then again same problem and changing pins don't work. I have tested it in front of my window so there must be a good signal.
Can someone tell me what is wrong with the system? I have so far waited long enough like 10 mins to get the data but nothing. I have to present the project by tomorrow in office.
This is the code :
https://pastebin.com/TMRYXFNw

I am using this tutorial https://lastminuteengineers.com/neo6m-gps-arduino-tutorial/

Unless you can format your code properly (select it, then press the {} button in the editor) no one is going to look twice at your question.

Sorry for that. But in my phone i did not have a formatting option.


text:
Counting pulses with interrupt
I have been trying to count pulses from a 12,500 Hz square wave to trigger an output. Here's the code I have so far. When the Arduino is reset it prints 315 to the serial over a 25 ms sample. 315 x 40 = 12600. Which seems to me it's working perfectly.
My only problem is it only returns this number once upon reset of the board. Now if I move that same code down into void loop, it counts consecutively giving me inconstant returns.
I am not understanding what I need to put in the loop section so I can repeatedly and accurately count how many toggles of the input pin I am getting over a period of time so I can do something to the output based off the presence of the 12,500 Hz signal or not.
volatile int IRQcount;
int pin = 2;
int pin_irq = 0; //IRQ that matches to pin 2

void setup() {
   // Put your setup code here, to run once:
  Serial.begin (9600);
  attachInterrupt(pin_irq, IRQcounter, RISING);
  delay(25);
  detachInterrupt(pin);
  Serial.print(F("Counted = "));
  Serial.println(IRQcount);
}

void IRQcounter() {
  IRQcount++;
}

void loop() {
  // Put your main code here, to run repeatedly:
}

Using the above code, every time I press the reset button I get one line in the serial window.
Counted = 441
Counted = 442
Counted = 441
Counted = 441
Counted = 441

Now I want to get the same result, but repeating over and over. That way if the signal drops out I can trigger an output to turn off (LOW). When the signal is present the output will go high.
My attempt was to move the attach interrupt down into void loop, so it would repeat. Here's what it looks like.
volatile int IRQcount;
int pin = 2;
int pin_irq = 0; //IRQ that matches to pin 2

void setup() {
  // Put your setup code here, to run once:
  Serial.begin (9600);
}

void IRQcounter() {
   IRQcount++;
}

void loop() {
  // Put your main code here, to run repeatedly:

  attachInterrupt(pin_irq, IRQcounter, RISING);
  delay(25);
  detachInterrupt(pin);
  Serial.print(F("Counted = "));
  Serial.println(IRQcount);
}

The return I get is self-updating, but the "count" instead of starting from 0 each time starts from the previous count. So it gets larger and larger. I am looking to return a constant value that represents my 12500 Hz signal so that, and only that, will trigger my output.
Counted = 442
Counted = 886
Counted = 1330
Counted = 177
Counted = 2221
Counted = 2667
Counted = 3112
Counted = 3557
Counted = 4002
Counted = 4448
Counted = 4893
Counted = 5338
Counted = 5784
Counted = 6229
Counted = 6674
Counted = 7120
Counted = 7565
Counted = 8010
Counted = 8456
Counted = 8901
Counted = 9347
Counted = 9792
Counted = 10237
Counted = 10683
Counted = 11130
Counted = 11576
Counted = 12022
Counted = 12469
Counted = 12915
Counted = 13361
Counted = 13808
Counted = 14254
Counted = 14700
Counted = 15147
Counted = 15593
Counted = 16040
Counted = 16486
Counted = 16932
Counted = 17378
Counted = 17825
Counted = 18271
Counted = 18717
Counted = 19164
Counted = 19610
Counted = 20056
Counted = 20503
Counted = 20949
Counted = 21395
Counted = 21842
Counted = 22288
Counted = 22735
Counted = 23169
Counted = 23616
Counted = 24062
Counted = 24508
Counted = 24955
Counted = 25401
Counted = 25730
Counted = 25756
Counted = 26200
Counted = 26646
Counted = 27093
Counted = 27539
Counted = 27985
Counted = 28432
Counted = 28878
Counted = 29324
Counted = 29770
Counted = 30217
Counted = 30663
Counted = 31110
Counted = 31556
Counted = 32002
Counted = 32449
Counted = -32641
Counted = -32195
Counted = -31748
Counted = -31302
Counted = -30855
Counted = -30408
Counted = -29962
Counted = -29515
Counted = -29069
Counted = -28622

"Now if i move that same code down into void loop it counts consecutively giving me inconstant returns." means what exactly?

I edited my question to try and better explain myself

You need to reset IRQCount back to 0 before attaching the interrupt again. Otherwise it will just continue counting from where it stopped last time.
I would actually keep the interrupt attached and just reset the variable just before the delay. That way the overhead of attach/detachinterrupt doesn't get added to the 25ms delay.
volatile int IRQcount;
int pin = 2;
int pin_irq = 0; //IRQ that matches to pin 2

void setup() {
  // put your setup code here, to run once:
  Serial.begin (9600);
  attachInterrupt(pin_irq, IRQcounter, RISING);
}

void IRQcounter() {
  IRQcount++;
}

void loop() {
  // put your main code here, to run repeatedly:
  IRQcount = 0;
  delay(25);
  int result = IRQcount;
  Serial.print(F("Counted = "));
  Serial.println(result);
}

Since an int is 2 bytes an interrupt might occur in the middle of setting/reading those two bytes. This might result in an occasional wrong value. To prevent that you should disable interrupt while setting/reading the value
volatile int IRQcount;
int pin = 2;
int pin_irq = 0; //IRQ that matches to pin 2

void setup() {
  // put your setup code here, to run once:
  Serial.begin (9600);
  attachInterrupt(pin_irq, IRQcounter, RISING);
}

void IRQcounter() {
  IRQcount++;
}

void loop() {
  // put your main code here, to run repeatedly:

  cli();//disable interrupts
  IRQcount = 0;
  sei();//enable interrupts

  delay(25);

  cli();//disable interrupts
  int result = IRQcount;
  sei();//enable interrupts

  Serial.print(F("Counted = "));
  Serial.println(result);
}

Thanks Gerben! Using that code i get the occasional junk return. What would be the easiest way to denounce this? Make an out take lets say 3 readings before making a decision on what to do. Or averaging pulses over a span instead of a raw count? Heres an example of the return, i get the anomaly every few seconds.
Counted = 439,
Counted = 438,
Counted = 430,
Counted = 48,
Counted = 318,
Counted = 438,

I lengthened the delay to give a larger sample size. This gives me a workable return from my noisy input source. This seems to work perfect! Thank you!

I assume you used the code with the clis and seis in it. Rather strange having two consecutive wrong values.

Gerben, Yes i used the code with the cli and sei in it.   Do you mean its strange getting the two wrong returns in a row? It seems the returns are correct, it is the incoming signal that is not stable giving junk returns.  If i sample over lets say 100ms it gives plenty of pulses per sample to safely activate or kill the circuit. I really appreciate your help!

But the 48 and 318 you got are both lower that the average of about 435. I don't know the connected circuit, so it could just as well be the circuit, instead of the arduino code. Anyways, as long as you are happy with the end result... Glad to have helped.

I believe the issue is software related to the host computer itself. I have tried several charge pump circuits, and ended using arduino because of the the unsteady signal. I have ran many experiments using many forms of code on the arduino as well as other types of hardware approaches to this. The problem is the instability of the incoming signal, not the arduinos interpretation of it. Every piece of hardware i have used to monitor the signal has showed great variance in it. The arduino {with your help} allowed me to debounce  the charge pump circuit which was giving me fits!

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


text:
Arduino leonardo + OV7670 non-FIFO
I want to transfer image to PC via Arduino leonardo.
OV7670 is non-FIFO, and no SD card connected.

I followed this blog and this youtube video.using this code.
when uplaod, I got errors below:
Arduino: 1.8.5 (Windows 10), Board: "Arduino Leonardo"
error: 'ASSR' was not declared in this scope
error: 'EXCLK' was not declared in this scope
error: 'AS2' was not declared in this scope
error: 'TCCR2A' was not declared in this scope
error: 'COM2A0' was not declared in this scope
error: 'WGM21' was not declared in this scope
error: 'WGM20' was not declared in this scope
error: 'TCCR2B' was not declared in this scope
error: 'WGM22' was not declared in this scope
error: 'CS20' was not declared in this scope
error: 'OCR2A' was not declared in this scope
error: 'UBRR0H' was not declared in this scope
error: 'UBRR0L' was not declared in this scope
error: 'UCSR0A' was not declared in this scope
error: 'UCSR0B' was not declared in this scope
error: 'RXEN0' was not declared in this scope
error: 'TXEN0' was not declared in this scope
error: 'UCSR0C' was not declared in this scope
error: 'UCSR0A' was not declared in this scope

I know that error occurred because this code is only for UNO. But mine is leonardo. Changing settings (Tool->board:uno board) was still compiling error.
I have search this Topic found nothing. I am so confusing, please help.

Did you manage to do it? Also want to do that and having trouble here


text:
Can't send DHT11 temperature data to Xively from Yun
I thought this would be easy but how wrong I am... All I want to do is plot temperature data but I can't seem to get it to work. It reads it out on the serial monitor and says it has sent the data (in the serial monitor) but nothing on the Xively plots! Why?? Below is the code.
I have the API key and feedID from the Xively site. The useragent I'm assuming is the name of the project. My channels are called sensorValue1 and sensorValue2. Please help - this is taking me far too long.
#include <Bridge.h>
#include <Console.h>
#include <Process.h>

#include "DHT.h"
#define DHTPIN 0
#define DHTTYPE DHT11

DHT dht(DHTPIN, DHTTYPE);

 #define APIKEY "BLablablablabla" // your pachube API key
 #define FEEDID blablabla // your feed ID
 #define USERAGENT "SebYun2" // user agent is the project name

// set up net client info:
const unsigned long postingInterval = 60000; //delay between updates to xively.com
unsigned long lastRequest = 0; // when you last made a request
String dataString = "";

void setup() {
  // start serial port:
  Bridge.begin();
  Serial.begin(9600);
  dht.begin();
  while(!Serial); // wait for Network Serial to open
  Serial.println("Xively client");
  // Do a first update immediately
  updateData();
  sendData();
  lastRequest = millis();
}

void loop() {
  // get a timestamp so you can calculate reading and sending intervals:
  long now = millis();
  // if the sending interval has passed since your
  // last connection, then connect again and send data:
  if (now - lastRequest >= postingInterval) {
    updateData();
    sendData();
    lastRequest = now;
  }
}

void updateData() {
  // convert the readings to a String to send it:
  // Reading temperature or humidity takes about 250 milliseconds!
  // Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor)
  dataString = "Temperature,";
  dataString += dht.readTemperature(false);
  delay(250);
  // add pressure:
  dataString += "\nHumidity,";
  dataString += dht.readHumidity();
  int sensorValue1 =  analogRead(A0);
  delay(100);
  int sensorValue2 =  analogRead(A0);
  dataString += "\nVoltage1,";
  dataString += sensorValue1*0.0049;
  Serial.print(sensorValue1);
  dataString += "\nVoltage2,";
  Serial.print(sensorValue2);
  dataString += sensorValue2*0.0049;
  delay(1000);
}

// this method makes a HTTP connection to the server:
void sendData() {
  // form the string for the API header parameter:
  String apiString = "X-ApiKey: ";
  apiString += APIKEY;
  // form the string for the URL parameter:
  String url = "https://api.xively.com/v2/feeds/";
  url += FEEDID;
  url += ".csv";
  // Send the HTTP PUT request
  // It is better to declare the Process here, so when the
  // sendData function finishes the resources are immediately
  // released. Declaring it global works too, BTW.
  Process xively;
  Serial.print("\n\nSending data... ");
  xively.begin("curl");
  xively.addParameter("-k");
  xively.addParameter("--request");
  xively.addParameter("PUT");
  xively.addParameter("--data");
  xively.addParameter(dataString);
  xively.addParameter("--header");
  xively.addParameter(apiString);
  xively.addParameter(url);
  xively.run();
  Serial.println("done!");
  // If there's incoming data from the net connection,
  // send it out the Serial:
  while (xively.available()>0) {
    char c = xively.read();
    Serial.write(c);
  }
}

As long as I checked, this way of uploading data to Xively only works for up to tree pairs of name,data.
If you try with more pairs at the same time the response is "Done", but nothing happens. I finally divide the upload in groups of 3 parameters, and everything is Ok.
I saw your question yesterday when I was looking for a way to upload data to Xively from Yun. It was really helpful for me. Thank you.


text:
How to connect MPU6050 to arduino using only digital pins
I am relatively new to Arduino and microchips, but I am good at electronics. I want to connect MPU6050 accelerometer+gyroscope module to Arduino. I searched on the internet and everywhere it is said to connect the SCL and SDA pins to two analog pins of the Arduino. As far as I know, the MPU6050 is a digital sensor, so why 2 analog pins are required for the sensor?
Also, is there any way to connect the sensor with only digital pins? because I need the analog pins for some other purpose.

The MPU6050 communicates over I2C. I2C uses clock line SCL and data line SDA. I2C pins on Uno are pins A4 and A5.
This is because the ATmega328p MCU used on Uno has the I2C peripheral on the same pins. It has nothing to do with the DAC function of the pins.
Alternatively MPU6050 can communicate over SPI. This are pins 11, 12, 13 on Uno and one more pin for CS. Pin 10 must be output while ATmega328p is SPI master so it is recommended to use it as CS for the SPI slave device.   EDIT Sorry, only MPU6000 has SPI.

I have noticed that there are separate SCL and SDA pins on the Arduino UNO. Can I use those?

@PuspamAdak, see the schematics. those are the same pins of the ATmega

@PuspamAdak, I enhanced the answer with information about SPI

Juraj, A0 and A1 and SCL and SDA are connected to the same pins on the ATmega processor? I would think that would cause confusion, since if you try to use I2C then A0 and A1 won't work as expected. What other pins are duplicates on the UNO? And what about the Mega 2560?

@DuncanC, A4 and A5, not A0/A1. yes it causes confusion. Mega has SDA SCL labels next to labels 20 and 21

Sorry, A4 and A5. Putting 2 different silkscreened labels on the same connector seems like a better idea than providing 2 different pair of connectors that actually map to the same pins internally. I wonder why the designers of the UNO did that?

So, I can't use the A4 and A5 pins while SCL and SDA are connected, isn't it?

@PuspamAdak, does your MPU6050 breakout board support SPI wiring?

How to check that?

what pins does it have?

VCC, GND, SCL, SDA, XDA, XCL, ADO and INT

Sorry, only MPU6000 has SPI.


text:
Cryptic compiler errors
I'm getting the error:
    left_hand:3:20: error: expected ']' before ';' token
     #define HAND_ROWS 5;
                        ^

on this code:
    #include <Keyboard.h>

    #define HAND_ROWS 5;
    #define HAND_COLS 6;
    #define ROW_PINS {9, 8, 7, 6, 5};
    #define COL_PINS {10, 16, 14, 15, 18, 19};
    #define LOOP_SPEED = 10;

    const char keymap[HAND_ROWS][HAND_COLS] = {{0xB1, '1', '2', '3', '4', '5'},
                                               {0xB3, 0x81, 'q', 'w', 'e', 'r'},
                                               {'6', 0x80, 'a', 's', 'd', 'f'},
                                               {'7', 'z', 'x', 'c', 'v', 'b'},
                                               {'h', 'j', 0x82, ' ', 'k', 'l'}};
    boolean pressedKeys;
    int keymapIndex;

help, please? This makes no sense to me...
If I try to use Keyboard.LEFT_SHIFT and equivalent constants for the hex-codes in the keymap, they tell me 'expected unqualified-id before numerical constant'
What does this even mean? I'm so lost...

There's no semicolon needed on a #define.

You mustn't terminate a #define with a ;.  Semicolons are for C and C++ statements. #define is a preprocessor statement.
#define creates a literal string replacement, so when you use it you end up with:
const char keymap[5;][6;] = {...

which is, of course, wrong.

Thank you for catching my beginner mistake!

It's no beginner mistake... I have done it myself from time to time... the fingers go on automatic...

Guess that's the fate of Java programmers who move to C, or at least that's the case for me.

@LowellCamp Or the fate of people that jump between three or four programming languages at once - and do their programming in the wee small hours of the morning ;)


text:
I'm trying to use a CONZIR CO2 sensor to find CO2 concentration
Hey I’m a beginner Arduino user trying to use a CO2/Humidity/Temperature sensor to read in the atmospheric conditions near the sensor and then control a heating pad and solenoid valve to adjust the conditions to what I need. I am having a lot of trouble simply getting realistic values that are usable. It would be awesome if someone could point me in the right direction. I am trying to use sample code provided to me by CO2 meter and am not having any luck having the conditions update in the serial monitor. Any help would be greatly appreciated. Below is the code I am trying to use and linked below is the manual. After figuring out how to simply read the CO2 values, I would like to expand it to temperature and humidity.
(http://co2meters.com/Documentation/Manuals/Manual_GC_0024_0025_0026_Revised8.pdf)
#include <SoftwareSerial.h>

SoftwareSerial mySerial(12, 13); // RX, TX pins on Ardunio

int co2 =0;
double multiplier = 1;// 1 for 2% =20000 PPM, 10 for 20% = 200,000 PPM
uint8_t buffer[25];
uint8_t ind =0;
uint8_t index =0;

int fill_buffer();  // function prototypes here
int format_output();

void setup() {
  Serial.begin(9600);
  Serial.print("\n\n");
  Serial.println("             AN128 Ardunio to Cozir CO2 Sensor - Demonstration code 11/29/2017\n\n");
  mySerial.begin(9600); // Start serial communications with sensor

  // mySerial.println("G");

  pinMode(4, OUTPUT); //heating pad pin
  pinMode(3, OUTPUT); //heating pad pin
  pinMode(5, OUTPUT); //solenoid valve pin
  digitalWrite(4, LOW); //change between HIGH or LOW value to make the valve/heating pads turn on/off
  digitalWrite(3, LOW);
  digitalWrite(5, LOW);

  //mySerial.println("K 0");  // Set Command mode
  // mySerial.println("M 6"); // send Mode for Z and z outputs
  // "Z xxxxx z xxxxx" (CO2 filtered and unfiltered)
  //delay(20);

  mySerial.println("K 1");  // set streaming mode

}

void loop() {

  // Serial.println(" Hello World ");
  fill_buffer();  // function call that reads CO2 sensor and fills buffer

   Serial.print("Buffer contains: ");
  for(int j=0; j<ind; j++)Serial.print(buffer[j],HEX);
  index = 0;
  format_output();
   Serial.print(" Raw PPM        ");

   index = 8;  // In ASCII buffer, filtered value is offset from raw by 8 bytes
   format_output();
   Serial.println(" Filtered PPM\n\n");
}

int fill_buffer(void){

// Fill buffer with sensor ascii data
ind = 0;
while(buffer[ind-1] != 0x0A){  // Read sensor and fill buffer up to 0XA = CR
  if(mySerial.available()){
    buffer[ind] = mySerial.read();
    ind++;
     // Serial.println("Fill loop");
    }
     //Serial.println("Fill loop");
  }
  // buffer() now filled with sensor ascii data
  // ind contains the number of characters loaded into buffer up to 0xA =  CR
  ind = ind -2; // decrement buffer to exactly match last numerical character
  }

 int format_output(void){ // read buffer, extract 6 ASCII chars, convert to PPM and print
   co2 = buffer[15-index]-0x30;
  co2 = co2+((buffer[14-index]-0x30)*10);
  co2 +=(buffer[13-index]-0x30)*100;
  co2 +=(buffer[12-index]-0x30)*1000;
  co2 +=(buffer[11-index]-0x30)*10000;
  Serial.print("\n CO2 = ");
  Serial.print(co2*multiplier,0);
// Serial.print(" PPM,");
//    Serial.print("\n");
   delay(200);
 }

what does this mean? ... trouble simply getting realistic values

So the value I am getting is -9600 ppm (a negative CO2 value),  and after receiving one CO2 reading it won't continue to loop and give me more readings. I was under the impression that it would continue to get buffer readings and thus be able to update and give me new readings


text:
PFC8574 4x4 keypad: correct wiring?
I bought a few PFC8574 and 4x4 keypads for a small project. I'm unclear on the correct wiring of the keypad to the PFC8574.
On the Arduino Playground's site, there are pull-up resistors for each column, but on a few other sites (like this one that I can't read, but I understand a schematic and there's a third example too, but I don't have the reputation to post it), the wiring does straight into the IC.
Does it depend on the library that's being used?  Or what am I missing?
Thanks!

Ok look at this image:

I'm not sure how your keypad is layed out but if you use a probe pin to test your connections via a multimeter, you can mark which ones correspond to the image.
I am ASSUMING you are going to use the code from arduino playground.
This is the format:
Pins of keypad (IN THE IMAGE) - Pins of PFC8547
Here are the pin connections:
1 - nothing
2 - 9
3 - 4
4 - 6
5 - 7
6 - 10
7 - 11
8 - 5
Also include the pull-up resistors.
Your ABCD keys will be ignored
(This is like wiring a bomb...)


text:
Arduino messing up as slave over I2C
I have an Arduino Mega2560 and a Raspberry Pi hooked up through I2C. The Pi is acting as the master, while the Arduino is the slave. While sending data over I2C, the int message gets messed up and will either send the address or the data. Then I can't even receive any useful data from the Arduino.
So if I turn the receiving function off it sends the data just fine, but when I ask the Pi to start receiving data again it slows down the entire bus and data starts conflicting between the Pi and Arduino. Also it only happens with the Arduino. Every other device works flawlessly.
Here's what my code looks like on the Pi side. I'm using SMBus to send and receive bytes. I didn't bother to put up code for it because I don't have the source code for SMBus. I just trust that they work because my other I2C devices work without a hitch.
while True:
    #if alternating == true then get the imu if not then get the motor speed
    if alternating == True:
        try: #need the try because an error will stop the program completely
            ypr = IMU.getYPR()
            yaw = int(ypr['yaw'] * 180 / math.pi)
            savedYaw = yaw
        except:
            yaw = savedYaw
            #print "exception"
            pass
            #write yaw to arduino
            i2c.writeByte(yaw)
            alternating = False
        else:
            #start reading data from arduino
            #readArduino()
            alternating = True
            pass

Then on the Arduino side these are my onReceive and onRequest functions:
void readPI(int byteC) {
    if(Wire.available()) {
        reference = Wire.read();
    }
    pid1.getReference(reference);
    pid2.getReference(reference);
}

void sendPI() {
    int values[] = {(int)out, (int)outReversed  };
    Wire.write(values[count]);
    count++;
    if(count > 1) {
        count = 0;
    }
}

Is there something about the Arduino that I don't know? Maybe it's a timing issue? Is there a way to set up registers? I can either receive or send, but I can't do both, and Googling the problem only leads to an example of someone sending 1 - 9 over the Pi. I can't find examples of anyone actually doing something complicated with an Arduino and a Rasp Pi over I2C. Any and all help would be amazing!

I find your onRequest function obscure:
void sendPI(){
     int values[] = {(int)out, (int)outReversed  };

     Wire.write(values[count]);
     count++;
     if(count > 1){
     count = 0;

     }
 }

Why only send one byte? I think you have a number of problems:

The size of int on the Arduino Uno is 2 bytes, on a Pi it is 4 bytes. So there is a mismatch there for a start.
Wire.write (written like that) sends one byte, so that is only going to be half of your int. So that is even less.
It isn't obvious what the Pi end is doing, but to make the int sizes match, I would be sending the lot in one hit like this:
void sendPI(){
     long values[] = {(int)out, (int)outReversed  };
     Wire.write((byte *) &values, sizeof values);
 }

Now you just read 8 bytes on the Pi (two ints).

well that didn't fix the problem I was having, but it got me on the right track. The i2c library i'm using for the Rpi writes a value as it reads the arduino. I had thought that it had just strictly read or write the i2c bus. So I was writing and reading bad values all over the place. it's now fixed.

If that fixed the problem please accept the answer, so that Stack Exchange doesn't keep throwing it back as an unanswered question. Thanks!


text:
How to avoid report of unsuitable sketch names?
I bought a kit of 37 sensors for Arduino, and downloaded all the example sketches. Now, when I try to start up the Arduino IDE I get a lot of frustrating messages like this:

... and I have to click "OK" on every one in turn before the IDE will start up.
Obviously I do not want to delete the sketches and their accompaniments, so I have tried to rename all the files and directories, with a shell script, to remove non-alphanumerical characters, but my understanding of shell programming is not good enough, so I have had no success.
I have made backups of the files in case things went awry with my scripting, and now see that these messages are repeated, as in the image, for the backup copies as well. I cannot find out how the Arduino IDE finds them, they are not in my Sketchbook folder.
I would be grateful for advice on either how to avoid these messages, or to edit the names so that they do not occur: I would be happy to edit the names of each sketch as I come to try it out, but I baulk at doing the lot at once.
I am using Linux Fedora 20.

Similar question here:  https://arduino.stackexchange.com/questions/33996/how-can-i-use-my-arduino-sketches-on-my-raspberry-pi-ide/33997#33997 but the thing to know is that it is only complaining about the directory names.  But the IDE wants the filenames to match the directory names.  (continued)

See my answer below.  I flesh it out better than I can do in comments.

That message is actually a hang-over from when the IDE was Processing.  The name of a file had to match the name of the Java class within that file, and there are strict rules about what can be in a Java class name.
They just basically haven't got around to deleting that piece of ancient code yet.
So you have 3 options:

Rename all the folders and files.
Edit the IDE's source code to delete that old code
Use a different IDE.

The first option can be long winded if you don't know how to do good scripting, as you have found out.
The second option requires knowledge of Java coding.
So that leaves the third option.  Now, I'm going to be shamelessly advertising my own work here ;)  Why not try a better IDE?  Such as the popular and powerful UECIDE (yes, written by me). It's based on the Arduino IDE, so it will mostly be familiar to you, but the whole of the insides have been ripped out and re-written.  If you're feeling brave you might want to give the beta version a go - it has some really really cool features not found in any other IDE in the history of mankind.

Thanks Majenko for that brilliant answer. I am using Linux Fedora 20, andI have successfully installed UECIDE, using the.zip file, but I haven't time to look into it further today. I'd like to try the beat version, but don't know how to check for or install Java VM. I will report on my progress.

I meant beta not beat, but I took too long to notice and edit the comment.

I got lost in the Plug-in manager in UECIDE, couldn't see how to install the selected plugins, but I will pursue that. Meanwhile I have solved the immediate problem by backing up all the offending files to a USB stick, and will re-name and load those I need, as I come to them.

I caught that jab about long-winded, @Majenko.  Upvote anyway.  I still referenced my answer you probably were referring to, in my answer here, long-winded or not.  At least it is a proven method.  But Windows is a much easier way to do the renaming unless someone really likes running unreadable scripts like mine, and crossing their fingers until they see that it worked..  ;-)

Short answer:  You can't avoid that error in the Linux Arduino IDE until your sketches have allowable naming.
Similar question here: How can I use my Arduino sketches on my Raspberry Pi IDE?
Note that it is only complaining about the directory names. But the IDE wants the filenames to match the directory names.
So your best way to deal with this is to go into Windows IDE then load each sketch and resave it with allowable names, before transferring. Make a separate directory for the saves.
If you have dozens, or if you don't have the Windows IDE available, then the program I wrote (see the link above) will do the job for you on the Linux side. It definitely works.  I had a bunch and it ran through them all in a minute or two.
I suggest you avoid using the program  in favor of the Windows route..  But look at that link to get a feel for how I'm set up.
It is really easier to just use the Windows-based IDE to do the renaming.  One by one, just load them then resave them without the special characters, into a subdirectory to be used to transfer to Linux on a flash drive or FileZilla.
Another issue you will face in the Linux IDE is the libraries.  First put them in a libraries folder under sketchbook.
Then use the IDE menu item "Sketch..Import Library..Add Library" for each library - it then stores them elsewhere in the IDE's guts.
You can do this on an as-needed bases.  Start with the most common ones like Adafruit_sensor.h, (Note that the underscore is OK for that one) which you know will be used by many of the sensors.  SoftwareSerial.h is another good one.  DHT.h if using the temp/humidity sensor.  Wire.h must be in there for a lot of them.
In the end, it works fine, as you can see at the link above.  I rather enjoy sitting at my desk using Remote Desktop via WiFi to the Pis, then remote-reprogramming the Nanos (C++) and/or the Pi (Python, BASH, SCP, etc) to get them calibrated to collect my data.
Have fun with the sensors.  Those will take some time to absorb, but in the end it is all worth it.

Can I suggest you change the title of your question to something like "I have the Arduino 37 Sensor pack - how do I make the sketches work in Fedora Arduino IDE?"


text:
esp32 with Neo6M gps gives no data
I am simply using the following code
void setup() {
  // put your setup code here, to run once:
  Serial.begin(115200);
  // set the data rate for the HardwareSerial port
  Serial2.begin(115200);
}

void loop() {
  while (Serial2.available() > 0)
    Serial.write(Serial2.read());
}

the Connection is as follows
pin 16(D27) of esp32 - > Tx of Neo6M
pin 17(D14) of esp32 - > Rx of Neo6M
Now I am not getting any data in the serial monitor. The same module works with arduino with software serial.
I am completely new in this thing and office is keep asking about the progess.

What exact ESP32 board do you have, and why have you tagged the question "Arduino UNO"? Is there an Uno in the mix as well?

I am using esp32 dev module. I tagged uno as the same pattern worked in uno. No uno is associated.  so let me remove it.  this one I am using : https://lastminuteengineers.com/wp-content/uploads/2018/08/ESP32-Hardware-Specifications-USB-to-TTL-Converter.jpg

The default baud rate for the Neo-6M is 9600, not 115200. Have you reconfigured it to work at 115200 baud?

Did not noticed that. But I just modified the baud rate and still nothing. current baud rate is 9600

The pins you are using are the ones actually labelled TX2 and RX2?

Yes that I can check from the librarary too. But should not they work simply? I mean I lost here completely.

are you suggesting me to connect me the module 6M with TX2 and RX2 ? Sorry for souding dumb but my office is keep asking I am loosing myself too.

The default pins for Serial2 are GPIO16 and GPIO17 (D16 and D17) not pins 16 and pin 17. Those pins are helpfully labelled TX2 and RX2.

okay! so I have connected the Tx of neo6m to rx2 and Rx of neo 6M to tx2. hope this is the wiring?  now the same code in with baudrate 9600 is uploaded. still nothing. I should get NMEA raw data in the serial monitor?

As long as you have power and ground connected too, that should be fine. There are other possible baud rates that could be configured on your module as default - you could try 4800, 38400 or 57600.

I guess the esp32 3.3v is not sufficient to power up the neo6m

It's possible. I am not sure off hand how much it needs. It shoudn't need much, it's receive only.


text:
unable to read RS232 output on Arduino mega with MAX232 shield
I am trying to read data from an RS232 equipped sensor using a serial monitor connected to an Arduino Mega with RS-232 shield but I do not receive any data.
I am unable to detect the exact cause of the problem, as it only occurs when combining sensor and RS232shield/Arduino, while communication works as expected when testing them separately
What works:

Connecting the sensor to a computer with a RS232-USB converter cable.
Passing data from the computer through the USB-RS232 converter cable to RS232 shield and back through Arduino USB output.
Connecting the RS232-pin 2 to port 10 using {SoftwareSerial} library with inverted logic.

What does not work:

Passing data from the sensor to the computer via the MAX232 and Arduino.

The setup:

Arduino Mega 2560
Seeed RS232 shield (MAX232 based)
Sensor with RS232 output (57600 8N1)

I have connected the RS232 output of the sensor to the shield using an M-M gender changer. The shield and Arduino are connected with three wires: GND-GND , 5V-5V, 232_TX-RX1), and the Arduino connects to a Macbook via USB. The serial monitor on the computer is set to 56700 baud.
I use the following sketch to transfer data from the RS232 shield to Serial:
void setup()
{
// Open serial communications at 5700 baud
    Serial.begin(57600);
    Serial1.begin(57600);

// Check whether Serial1 is active
if (Serial1.available())
     while (!Serial1) {
        ;
    }
    Serial.println("Serial 1 is active");
}

void loop()
{
    if (Serial1.available()){
    Serial.write(Serial1.read());
    }

}

Does your sensor require hardware flow control signals that the shield doesn't provide?

I have solved the above and will share the answer as it may be of help to others:
As the Tx indicator LED on the RS232 shield would not light up when connected to the sensor, I checked the voltage difference between pin 2 (Tx) and pin 5 (GND) of the RS232 connector. This turned out to be only 5V, indicating that the protocol used is TTL-RS232 rather than 'true' RS232.
Due to the low voltage, I have connected the RS232 Tx and GND pins directly to the Arduino. With Tx connected to digital port 10, I used the SoftwareSerial library with logic inversion to read the data: SoftwareSerial mySerial(10, 11, 1).
This works!

this is not an answer to the question, because the answer uses information not mentioned in the question. what sensor is it?


text:
How to install several IDE version on my PC
How can i install old version of IDE, without uninstalling the other version?(How can i install several IDE version in same laptop).

Avoid asking multiple questions, https://arduino.stackexchange.com/help/how-to-ask and what research have you done?

Arduino.cc have a guide :
https://www.arduino.cc/en/Guide/PortableIDE
The gist is:

Download the desired version in ZIP format
Unpack the content in the zip file to a folder
Start the arduino.exe in that folder.

Remember that you have to place all libraries, board definitions in that folder.
The folder can be copied to another computer or a USB stick....

Note that it's not required to run in portable mode. If you want each IDE installation to be isolated then that's the thing to do but if you want them to share preferences and hardware packages installed via Boards Manager then you should not use portable mode.


text:
Arduino ISR timing question
Im trying to understand how the Arduino ISR keeps track of timing between pulses stored in a variable, if that variable is latter used.
Say, for example, you have a magnet mounted on a circular object, that passes a reed switch. Using this to trigger the ISR that calls a function that would have something like counts++ in it, then storing that value in a variable.
If that varible is used latter to turn on a motor, for example, according to the count capture, how does the arduino MCU know the freq or timing to output the count or pulses of the magnet passing the reed switch, at the same frequency that the counts were received? For example, a magnet mounted on a 2 inch dia shaft would turn slower past a reed switch than one mounted on a .5 inch shaft, or one could vary the speed of the magnet past the reed as they wish. So how does counter++ keep track of this freq? is it reading the attachinterupt pin (or is the function that is being called, keeping track) or does the ISR time stamp each pulse it receives and store that interval in the declared variable? so when the variable is used again, it has this interval stored in it?
To be more clear, if it takes one second for the magnet to complete one revolution, how does the MCU know it took one second and store this, along with the counts of the revolutions?
Thanks for any help

It doesn't know that. You'd have to code that yourself. You could indeed have the ISR store the millis() value. Even better would be to have the ISR (locally) store the millis() value of the last time the ISR was called. Then when the ISR is called the next time, it could calculate the time that has passed since the last ISR call. If the motor is running faster, this method can get a bit less accurate. In that case you could have the main loop measure the time it takes for the counter to increase by e.g. 20 (i.e. 20 revolutions). The it can calculate the average RPM.

so when people use for ex. the interupt, to call a function, for ex. void Revolutions(){
rev++;
};  and then have an if statement with varibles like if {
revA = rev;
rev=0; to store revolutions, and use that again in another if statement like if revA>rev, analogWrite(motor) the duration of the value stored in revA is not stored? if not, then what is stored?

@Jim When people just count revolutions like that they introduce the concept of time at a later stage. For instance, they will look at (and reset) that count once a second, giving the number of revolutions in that one second window, and hence the number of revolutions per second.

"they will look at (and reset) that count once a second, giving the number of revolutions in that one second window, and hence the number of revolutions per second"     so your saying the "one second" is an arbutrary value? Im just trying to understand what, for ex. counter++ or rev+1 etc is tied too? the interupt calls the function, then 1,2,3,4.....counts pass, its stored, then output according to what time?

perhaps the key thing Im missing is "reset", the interupt is used, calls its function, then resets so that time frame of all the sets/resets corresponds to the amount of total times it took to capture the time you want to turn on a motor, for ex.   meaning that if it took 1 minute to capture 500 set/resets, then you could approx. capture that in a variable?

The key thing you are missing is that the "time" has absolutely nothing to do with the interrupt. It's elsewhere in the program as is written by the programmer of the sketch. It may be as simple as a delay(1000); in the main loop, or it may be done with millis() in a non-blocking fashion.

yes, Ive seen it done in a sketch, without a delay or millis in the interupt function that is called

All the interrupt does is count. It has no concept of time.  For instance:
volatile uint32_t revolutions = 0;
void count() {
    revolutions++;
}
....
attachInterrupt(0, count, FALLING);

will just count up 1 every time the interrupt triggers.
To be able to convert that count into something meaningful you have to manually introduce the concept of time - that is, the count of "revolutions" (for example) between two points in time.  And it's up to your sketch to implement that.
The simplest way may be:
// For anything more than an 8 bit value on an 8 bit machine
// make a critical section to save and reset the count
cli();
uint32_t savedResolutions = revolutions;
revolutions = 0;
sei();

Serial.print(savedRevolutions);
Serial.println(F(" revolutions per second"));

// Introduce the concept of time - this will
// make it get the count once a second.
delay(1000);

Of course, instead of delay() you can use millis() in much the same way as the BlinkWithoutDelay example in the IDE.
It is possible (as long as you're not counting too fast) to incorporate the time element into the interrupt routine by keeping track of the time in a variable:
volatile uint32_t rps = 0;

void count() {
    static uint32_t revolutions = 0;
    static uint32_t timestamp = millis();

    revolutions++;

    if (millis() - timestamp >= 1000) {
        timestamp = millis();
        rps = revolutions;
        revolutions = 0;
    }
}
....
attachInterrupt(0, count, FALLING);

Then you can just reference the rps variable at any time to get the revolutions per second. Again it should really be queried inside a critical section to prevent the value being changed while you're actively reading it...
cli();
uint32_t myRPS = rps;
sei();

Serial.print(myRPS);
Serial.println(F(" revolutions per second"));

Ive seen people use a variable++ or +1 in a function called by the ISR, without any millis or time reference, then use that variable against another variable to capture a peak value, use that to turn something on for that duration, for example.

Sure, if that's what they are doing requires them to do...

"like that they introduce the concept of time at a later stage"                    could you explain what you mean by this perhaps with an example? I dont quite get it

You mean besides the one I already show in my answer?

yes, it would help

I'm not sure I could add anything by doing something I have already done. I have shown you the most simple and basic example possible. What more do you want?

like if he was to use the interrupt to capture a reed interrupt once per second in a rev++ varible, and use it latter like you suggested

Combine the first code block with the second code block (which you wrap in a setup() and loop() combination with the right pinmodes, serial config, etc) and you have your example.

well that clears things right up dude, thanks. Im imagining those code blocks with everything I should put in them right now. it seems you was suggesting there was a way people were using the count not tied to any milis or delay, so I asked for an example

I know how to use the code blocks and declare initialize in the set up and put the attachinterupt there, outside the loop so it runs independantly of the loop I wanted to know how the counter variable ++ can be mapped or relate to any duration when used with an interupt, but your saying it cant without additional millis internal interupt or delay , but Ive seen it done without all that so I dont get it

If you have seen it done without that then you are looking at something else entirely. You can't get X-per-second without introducing the concept of "seconds". The interrupt has nothing whatsoever to do with that unless you explicitly code it in there like my second example.

so what is a counter like ++ or +1? its just a byte in the regisiters memory?

Either. They both mean the same thing. rev++ means "increment rev", rev = rev + 1 means "add 1 to rev and store it in rev". rev+=1 means "add 1 to rev and store it in rev".

no, Im asking, like if it takes 1 sec for a rev to increment the counter ++ or +1, that one second has no relation to the counter? the value of the increment is just an additional byte into memory?

The value of the increment is just a change of a variable in memory. The number of bytes that takes depends on what the variable is. It's just a variable. There's nothing (apart from the volatile flag) that makes it different from any other variable.

yeah I get that, like a float, int, long, etc, the variable size. Im saying time has no relation, its not stored along with the the increment. like, the magnet passes the reed, 1 count, 1 second, another pass, 2 count 2 sec etc?

Unless you create a variable to store that kind of thing, where would it store it? It only ever does precisely what you tell it. There's never any "magic" in the background storing extra data.

ok cool. I thought maybe the function in the interupt was looking at the interupt pin, and timestamping that, the counts along with the time it took. Actually I see allot of code with just a variable ++ then they store that in a variable, and store the total count in another variable, use that for a duration etc. I didnt see any milis etc like you see in blink delay, none of that so was puzzled how it worked

Ok, I think I see what they were doing. They had rev++ in the interupt function to call, stored that count in a varable, rev, intialized to 0, then used another variable to store the total count into revA. when revA is bigger than rev, do something, else do nothing. still seems like it would be based on the time, but...confusing.

they were comparing 2 variables and saving the larger count, then using that condition to turn on a motor, so it wasnt timed to anything, just when one became larger than the other, save that, and that condition became true, turn on the motor...    As for nested "if" statements, if you have an if then a nested if, that is equilivant to an AND, correct? but an if, then an if else is equilivant to a NOT, correct?


text:
Put integer and double into char array
I want to print text and numbers mixed in a table with Serial.print(); from a char array. My problem is the conversion between the different data types. My idea is to print the data of the rows in a for loop with the variable i and the columns in a for loop with the variable j.
I have in the following example two variable, one is type integer and the second is a double. Now i want to add the values of the variables into the char-array, but I can't find a way to do this...
In my main program the variables need to have this data types and should be inserted later into the char array.
Does someone have a solution for this challenge?
Here is a small example code:
int a = random(0, 100);
double b = random(0, 100);

char* myStrings[][6] = {"This is string 1", "This is string 2", "This is string 3",
                        "This is string 4", "This is string 5", "This is string 6"
                       };

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

void loop() {

  //now put the integer and double variables into the char array in the second column

  //Print the values
  for (int i = 0; i < 2; i++)
  {

    for (int j = 0; j < 6; j++)
    {
      Serial.print(myStrings[i][j]);
      Serial.print("  ");
      delay(100);
    }
    Serial.println();
  }

}

Many thanks in advance.
Guss
EDIT:
The output should look like this:
Headline (in this example it is the text "This is string 1", "This is string 2"...)
and then the values of the variables in the next row. It should be like this:
This is String 1     This is String 2     This is String 3

Variable a           Variable b           Variable int

Variable double      Variable double      Variable int

Did I understand you correctly that you want to write an integer value into a char buffer? You can do that using snprintf(). Also, you example code crashes because you access memory out of bounds of the myStrings array. Can you give an example of how the output should look like?

Thanks for your fast answer. I have in edit in my question above. Maybe char array isn't the best way. I'm open for improvements.

Do you need the data tabulated like that, or would one item per line be ok? Tabulating it will be a bit more complicated. Still doable but harder.

It should be tabulated because the column names are different in its length.

First of all, you should decide for a datastructure for you table. There are many options with various advantages and disadvantages. I am choosing a statically allocated table here, with a fixed width for each entry in the table and a fixed number of columns. One may also use pointers to strings which are allocated on the heap or elsewhere, but I find this to be the simplest.
Anyways, the basic problem doesn't change: We want to write a integer value in some string buffer. I am using the C library function snprintf() here. This function is like printf(), just that it writes its output to a given buffer of a maximum size. Thus, we can use simple format strings here and some workarounds for non-working format strings (floating points..)
Here is the code.
#include <Arduino.h>

/* A table is a 2 dimensional array of char buffers.
   The core element is a char buffer of fixed size.
   The number of columns must be fixed at compile time.
   Rows can by dynamically added in the structure without having to
   declare the number of elements.
   You can declare the number of rows at compile time, but do not need to fill them.
   Thus you can dynamically add rows to the table.
 */

#define MAX_ENTRY_SIZE 20
#define NUM_COLUMNS 3
#define COLUMN_PRINT_WIDTH MAX_ENTRY_SIZE

char myTable[][NUM_COLUMNS][MAX_ENTRY_SIZE] = {
        {"Column 1", "Column 2" ,"Column 3"}, //Row 1
        {"Variable a", "Variable b", "Variable int"}, //Row 2
        {"Variable double", "Variable double" ,"Variable double"}, //Row 1
};

char* get_table_entry(int row, int column) {
    char* entry = myTable[row][column];
    return entry;
}

void write_int_to_table(int value, int row, int column) {
    //Get a pointer to where the entry is
    char* entry = get_table_entry(row, column);
    //write a new string inside it
    snprintf(entry, MAX_ENTRY_SIZE, "%d", value);
}

void write_double_to_table(double value, int row, int column) {
    //Same as above, different format string..
    char* entry = get_table_entry(row, column);
    //Formatting floats on an Arduino Uno is tricky. %f formatters don't work (cut out due to size.)
    //use String API instead
    String stringFloat(value);
    const char* cString = stringFloat.c_str();
    strncpy(entry, cString, MAX_ENTRY_SIZE);
}

void print_table() {
    //Get number of Rows
    int numRows = sizeof(myTable) / (MAX_ENTRY_SIZE * NUM_COLUMNS);
    for(int row = 0; row < numRows; row++) {
        //Print all columns of this row
        for(int column = 0; column < NUM_COLUMNS; column++) {
            char* entry = get_table_entry(row, column);
            Serial.print(entry);
            //fill with spaces to the right
            for(unsigned int i=0; i< COLUMN_PRINT_WIDTH - strlen(entry); i++) Serial.print(" ");
        }
        Serial.println();

        //Table header seperator
        if(row == 0)
            Serial.println("============================================");
    }
}

void setup() {
    Serial.begin(9600);
    print_table();
}

void loop() {
    int a = random(0, 100);
    double b = random(0, 100);

    Serial.print("Will write new values for a = ");
    Serial.print(a);
    Serial.print(" and b = ");
    Serial.println(b);

    //write these in the second row (first row after header), first and second column.
    write_int_to_table(a, 1, 0);
    write_double_to_table(b, 1, 1);

    //Print table again
    print_table();
    Serial.println();
    Serial.println();

    delay(5000);
}

Two rounds give the output:
Column 1            Column 2            Column 3
============================================
Variable a          Variable b          Variable int
Variable double     Variable double     Variable double

Will write new values for a = 7 and b = 49.00
Column 1            Column 2            Column 3
============================================
7                   49.00               Variable int
Variable double     Variable double     Variable double

Wow, very impressive. Thanks a lot for this code. One little question, how can I print the table head seperator to the length of the table head automatically?

You can calculate the number of needed characters by doing int num = NUM_COLUMNS * MAX_ENTRY_SIZE, then print the seperator character in a for loop from 0 to num.


text:
Confusion with two Serial.begin() function calls
Why are there two Serial.begin() function calls? What does that signify?
   Here is the minimal code i am working on:
void setup() {
      Serial.begin(115200);
      Serial.begin(9600);
      Serial.println("Pressure Sensor Test"); Serial.println("");
    }

Here is the full Code:
#include <SimpleDHT.h>
#include <Wire.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_BMP085_U.h>

int pinDHT11 = 2;
Adafruit_BMP085_Unified bmp = Adafruit_BMP085_Unified(10085);

void displaySensorDetails(void)
{
  sensor_t sensor;
  bmp.getSensor(&sensor);
  Serial.println("------------------------");
  Serial.print  ("Sensor:       "); Serial.println(sensor.name);
  Serial.print  ("Driver Ver:   "); Serial.println(sensor.version);
  Serial.print  ("Unique ID:    "); Serial.println(sensor.sensor_id);
  Serial.print  ("Max Value:    "); Serial.print(sensor.max_value); Serial.println(" hPa");
  Serial.print  ("Min Value:    "); Serial.print(sensor.min_value); Serial.println(" hPa");
  Serial.print  ("Resolution:   "); Serial.print(sensor.resolution); Serial.println(" hPa");
  Serial.println("----------SDNx real time scientific data---------------");
  Serial.println("");
  delay(500);
}

void setup() {
  Serial.begin(115200);
  Serial.begin(9600);
  Serial.println("Pressure Sensor Test"); Serial.println("");
  if(!bmp.begin())
  {
    /* There was a problem detecting the BMP085 ... check your connections */
    Serial.print("  Ooops, no BMP085 detected ... Check your circuit some errors are there!");
    while(1);
  }

  /* Display some basic information on this sensor */
  displaySensorDetails();

}

void loop() {

  Serial.println("===========");
  Serial.println("Sample DHT11...");

  byte temperature = 0;
  byte humidity = 0;
  byte data[40] = {0};
  if (simple_dht11_read(pinDHT11, &temperature, &humidity, data)) {
    Serial.print("Read DHT11 failed");
    return;
  }

  Serial.print("Sample RAW Bits: ");
  simple_dht11_serial_print(data);

  Serial.print("SDNx says you are genius and every thing is OK: ");
  Serial.print((int)temperature); Serial.print(" *C, ");
  Serial.print((int)humidity); Serial.println(" %");

  // DHT11 sampling rate is 1HZ.
  delay(1000);

  sensors_event_t event;
  bmp.getEvent(&event);

  if (event.pressure)
  {

    Serial.print("Pressure:    ");
    Serial.print(event.pressure);
    Serial.println(" hPa");

    float temperature;
    bmp.getTemperature(&temperature);
    Serial.print("Temperature: ");
    Serial.print(temperature);
    Serial.println(" C");

    float seaLevelPressure = SENSORS_PRESSURE_SEALEVELHPA;
    Serial.print("Altitude:    ");
    Serial.print(bmp.pressureToAltitude(seaLevelPressure,
                                        event.pressure));
    Serial.println(" m");
    Serial.println("");
  }
  else
  {
    Serial.println("Sensor error");
  }
  delay(1000);
}

It signifies that the author of this code has made a mistake of either implementation or understanding.

The first begin() is probably being ignored by the Arduino.

I thought it would be enacted upon and then overwritten by the second.  I know that's the same result, but there might be some subtle difference.

It looks like a mistake, as Chris says.  I can't tell you what will happen but my guess is it will work at 9600.
I would recommend that you delete one of the lines to avoid further confusion.

when i asked the author of this code he said that they were for maximum and minimum value of baud rate. Is there anything like that? PS. Also the arduino was connected to BMP085, DHT11 and a HC06

I think he misunderstands the calls he has made, they aren't.  Serial only refers to the serial communications over pin 0 and 1 on an Arduino.  You can have other objects that refer to other serial ports, but in this case its the serial monitor.

Also the output was taken from a Bluetooth terminal in an Android app

What do you mean by "You can have other objects that refer to other serial ports, but in this case its the serial monitor"

On a Mega you have Serial1 and 2(?). You can create SoftwareSerial objects which create a serial connection out of any pins.  You could even define you own and bitbang a serial port.  Heck you could even have an object that create a virtual serial port over Ethernet, Wifi, Bluetooth, etc, which is what I think you are using.


text:
Can't assign String to Array of String
I have to input 5 words and organize.
In order to organize words, I have to get them into Array of String to compare.
I succeed to get char[buffer] into String in_str but somehow in_str doesn't
get into str[5].
is String str[i]=in_str;  Wrong?? How can I put in_str to Array of String str??
void setup() {
  Serial.begin(9600); }

void loop() {
  int state = 1, len = 0 ,i=0, k=1;
  char buffer[128];
  String str[5];
  while (true) {
    if (state == 1) {
      Serial.print("Enter the ");
      Serial.print(k);
      Serial.print("th Word --> ");
      state = 2;
    }
    while (Serial.available()) {
      char data = Serial.read();
      if (data == '\n') {
        buffer[len] = '\0';
        String in_str = buffer;
        String str[i]=in_str;
        Serial.println(in_str);

        i=i+1;
        k=k+1;
        len = 0;
        if(i>4){state = 3; }
        else {state = 1;}
        break;
      }
      buffer[len++] = data;
    }
  if(state==3){
    Serial.println("After Sorting");
   for (int i = 0; i < 4; i++) {
    for (int j = i + 1; j < 5; j++) {
      int compare = str[i].compareTo(str[j]);
      if (compare > 0) {         String temp = str[i];
        str[i] = str[j];
        str[j] = temp;
      }
    }
  }

   for (int i = 0; i < 5; i++) {
    Serial.println(String(i) + " : " + str[i]);
  }

    break;
  }

  }
}

When you write String str[i]=in_str; that is wrong. You only write the type when you are declaring the variable, once.
When assigning, you need only write the variable name, not the type: str[i]=in_str;

I thought like hours to solve this problem but this was a simple mistake.. thanks for your help


text:
Unable to get response for BLE AT commands in Arduino Uno
I am trying to establish connection between two BLE (BT43) through AT commands from an Arduino Uno. I am not getting any response from the AT commands. The connections are as follows:
Arduino Tx --> BLE Rx
Arduino Rx --> BLE Tx
Arduino 3.3v --> BLEVcc
Arduino Gnd --> BLE Gnd
Can someone please help me with this? Thanks in advance!
this is my code
#include <SoftwareSerial.h>
SoftwareSerial BTserial(6, 7); // RX | TX

const long baudRate = 115200;
char c=' ';
boolean NL = true;

void setup()
{
    Serial.begin(9600);
    Serial.print("Sketch:   ");   Serial.println(__FILE__);
    Serial.print("Uploaded: ");   Serial.println(__DATE__);
    Serial.println(" ");

    BTserial.begin(baudRate);
    Serial.print("BTserial started at "); Serial.println(baudRate);
    Serial.println(" ");
}

void loop()
{

    // Read from the Bluetooth module and send to the Arduino Serial Monitor
    if (BTserial.available())
    {
        c = BTserial.read();
        Serial.write(c);
    }

    // Read from the Serial Monitor and send to the Bluetooth module
    if (Serial.available())
    {
        c = Serial.read();
        BTserial.write(c);

        // Echo the user input to the main window. The ">" character indicates the user entered text.
        if (NL) { Serial.print(">");  NL = false; }
        Serial.write(c);
        if (c==10) { NL = true; }
    }

}

Your wiring appears to be correct, what arduino model are you using? What pins are arduino TX/RX exactly? What does your code look like?

I am using arduino uno and i have connected  ble tx--> arduino 6th pin, ble rx pin--> arduino 7th pin

Thanks mystery for your reply. I have added the code to my question. I  have set the baud rate to 115200 and I am not getting response for the AT commands which i enter in serial monitor.

The Uno only has 1 HW UART interface (your Serial object), which is connected to the usb port. You can't connect the bt module to these  and communicate independently. On the Uno, your only alternative is Software Serial as used in your code. Double check if specified pins (6, 7) are NOT the ones of the hardware serial AND are actually connected to the bt module. Also look up the default baud rate of the bt module (115k seems quite high as initial value).

The pins(6,7) are  connected to my ble module only and regarding the baudrate, 115200 is the default baud rate they have given in the document and i also tried different baud rates of

EDIT
Just found this*:

On Arduino or Genuino 101 the current maximum RX speed is
  57600bps *https://www.arduino.cc/en/Reference/SoftwareSerial

You may be over max speed for Uno.
What are you using to send data via Bluetooth?
Are you sure data is being sent to the device?
Android App
You can try my android app that I created for this specific type of testing.
You can get it at : http://raddev.us/btmessenger.apk
If you point your Android device at that, it will download the app and ask if you want to install it.
In case you're afraid it is malicious you can get the Open Source code to the simple app at GitHub : https://github.com/raddevus/BTMessenger
To use:

pair your bluetooth device
Type a message in top TextEdit box.
Press the [Send] button.

Baud Rate Issues
Generally if you get the baud rate incorrect you'll just see garbage characters.
Here's a write up I just did on setting up Bluetooth devices. It may help you work through some issues.
https://www.codeproject.com/Articles/1254611/Bluetooth-Messenger

You are missing critical info on page 10 datasheet i.e. not connecting CTS and RTS.
It maybe possible handshake is necessary for communicating to this module.
Give it a try using with some board with Synchronous UART.
Also can try grounding CTS. i.e. connect blue-tooth moduls's CTS to 0V.
read this for more clarity.
Hope this solves your problem.

The  module(BT43) I use doesn't have any routing for CTS and RTS pins and that is why i didnt connect CTS and RTS

I don't have this module but if you are using same as shown in datasheet link above you have 11 RTS and 12 pin CTS follow datasheet for pinout

Since these modules are connected to their respective Arduinos to give them BLE capability, Rx and Tx should be connected to the same, not crossed.

According to 2.6 of https://www.ampedrftech.com/datasheets/BT43_Datasheet.pdf this is not true and the lines should be crossed, as usual.


text:
class enum was not declared in this scope
I am programming an Arduino.  In the same .ino file as setup() and loop() I have defined the following:
void setup()
{
  // setup code
}

enum class CYCLE { TypeA, TypeB };

String cycleToString (CYCLE cycle) {
  if (cycle == CYCLE::TypeA) {
    return "TypeA";
  }
  else if (cycle == CYCLE::TypeB) {
    return "TypeB";
  }
  return "Undefined";
}

void loop()
{
  // loop code
}

But on compiling it gives the error:
sketch_v1:37:22: error: 'CYCLE' was not declared in this scope
 String cycleToString (CYCLE cycle) {
                      ^
/Users/.../sketch_v1.ino: In function 'String cycleToString(CYCLE)':
sketch_v1:37:31: error: 'String cycleToString(CYCLE)' redeclared as different kind of symbol
 String cycleToString (CYCLE cycle) {
                                  ^
/Users/.../sketch_v1.ino:37:8: note: previous declaration 'String cycleToString'
 String cycleToString (CYCLE cycle) {
        ^

Note that the enum class is fine and works as intended but if I try to add the function relying on the CYCLE type it then errors.

Arduino builder has problems if structs, enums, classes are not defined before the first function

why do you write enum class instead of just enum?

@chrisl, enum class or enum struct from C++11 is enum where the values can be used only with the enum type name like CYCLE::TypeB.

Could you please provide an example that reproduces this comiler error? I embedded your code in the setup()-loop() template and it works!

Done @SimSon and that was where the "bug" was lurking.  See Juraj's answer.

This is a known bug of Arduino builder, if you have functions before structs, classes or enums in sketch.
The sketch:
void foo() {
}

enum class CYCLE { TypeA, TypeB };

String cycleToString (CYCLE cycle) {
  if (cycle == CYCLE::TypeA) {
    return "TypeA";
  }
  else if (cycle == CYCLE::TypeB) {
    return "TypeB";
  }
  return "Undefined";
}

void setup() {
}

void loop() {
}

is processed to this .cpp file
#include <Arduino.h>
#line 1 "/tmp/arduino_modified_sketch_327776/sketch_jun23a.ino"
#line 1 "/tmp/arduino_modified_sketch_327776/sketch_jun23a.ino"

#line 2 "/tmp/arduino_modified_sketch_327776/sketch_jun23a.ino"
void foo();
#line 7 "/tmp/arduino_modified_sketch_327776/sketch_jun23a.ino"
String cycleToString(CYCLE cycle);
#line 17 "/tmp/arduino_modified_sketch_327776/sketch_jun23a.ino"
void setup();
#line 22 "/tmp/arduino_modified_sketch_327776/sketch_jun23a.ino"
void loop();
#line 2 "/tmp/arduino_modified_sketch_327776/sketch_jun23a.ino"
void foo() {
}

enum class CYCLE { TypeA, TypeB };

String cycleToString (CYCLE cycle) {
  if (cycle == CYCLE::TypeA) {
    return "TypeA";
  }
  else if (cycle == CYCLE::TypeB) {
    return "TypeB";
  }
  return "Undefined";
}

void setup() {
}

void loop() {
}

as you can see the forward declarations of functions are before the first function so before the enum.
The workaround for this bug is to follow good practice and declare all the structs, enums and classes before the first function definition.

please see my answer.  If you can edit yours to include / clarify this I'll delete mine and mark yours as correct.  Many thanks.

@AJP, I know about this bug so I identified it in your Question, but I could not know what function do you have before the enum. I wrote the answer more generic. Now I added something about workaround.

Done.  Thanks @Juraj

+1 for the answer and -1 for the Arduino IDE. Valid C++ should simply compile. I don't want to learn the quirks of another programming language if I can already program C++. I can't believe this hasn't been resolved in the last 4 years.

I don't understand the workaround. I already have my enum declared before the function using it as argument, but I still get the error.

@AgainPsychoX you have to put it before all functions

Note this is not an answer, since your code compiles perfectly. (adding a default/empty setup/loop function).
However, I want to give some improvements that cannot fit in a comment:

(optional) Align { and } under each other. Some put the { behind the line, some on a new line; this is mostly preference. But aligning { and } is mostly more clear.
Put each type/enum value on a new line; this makes it easier to add comments above/after it.
Except for trivial cases, never return from a statement, except the last one. In your case the function is quite simple, but still it's better to keep the return only at the end of a function.
Use a switch statement instead of multiple if statements.

So you get:
enum class CYCLE
{
  TypeA,
  TypeB
};

String cycleToString (CYCLE cycle)
{
  String str;

  switch (cycle)
  {
  case CYCLE::TypeA:
    str = "TypeA";
    break;

  case CYCLE::TypeB:
    str = "TypeB";
    break;

  default:
    str = "Undefined";
    break;
  }

  return str;
}

Thanks Michel.  Completely agree with multiple lines per enum.  I condensed it to aid shortening the question.  I like the idea of putting the { and } in vertical alignment.  I've made that change now and it's good, thanks.  I don't agree with the switch statement as I don't like the fall through bug if you forget break.  Do common C++ IDEs warn you?  As a benefit of switch: does C++ error / warn if you don't handle all enum types?  Only return once pattern: yes completely agree.  Thank you.

You're welcome. An if statement can be as dangerous (using = instead of ==). I don't think you get a warning forgetting a break (you can try easily). C++ does not warn you for not checking all enum values, but that's where the 'default' keyword is for.

Right.  I understand.  In your experience is the if (a = x) more prevalent as a bug than forgetting the break?  I guess it ultimately comes down to practice (?) but I've done the former perhaps 2 times in my life but the later a lot more so I personally eschew switch for that reason.

You might like to read: https://stackoverflow.com/questions/97987/advantage-of-switch-over-if-else-statement   (actually I was curious too). Anyway, a switch is more readable. In all (professional) software projects I have done, a code review would not pass a bunch of if statements above a switch (when comparing against a single variable). Btw, I checked, Arduino IDE does not show any warning (not even with all warnings on).

Even Visual Studio 2019 with warnings on does not show. I have worked with lint (a static C/C++ checker) and I'm fairly sure that application mentions forgotten break. Although in C it is allowed to have multiple case statements (to perform the same action for multiple values). Mostly people put // Fall through behind it, to show the break is forgotten deliberately.

It works if you move the enum class to the top, i.e.:
enum class CYCLE { TypeA, TypeB };

void setup()
{
  // setup code
}

String cycleToString (CYCLE cycle) {
  if (cycle == CYCLE::TypeA) {
    return "TypeA";
  }
  else if (cycle == CYCLE::TypeB) {
    return "TypeB";
  }
  return "Undefined";
}

void loop()
{
  // loop code
}

I found workaround on Arduino forums: Put your enums in separate file (I use enums.hpp), and include it from the main sketch file (.ino) like #include "enums.hpp".

do you have the .hpp included at the same location in the ino where you had originally the enum?