text:
Avrdude verification error
I use an Arduino UNO with IDE 1.8.5 and for the last few days it doesn't let me upload any code. When I try, it pops up with the following error:
avrdude: verification error, first mismatch at byte 0x0042
         0x65 != 0x8d
avrdude: verification error; content mismatch
avrdude: verification error; content mismatch

I really don't know what happened it used to work perfectly well. I even tried to upload blank code with nothing wired on and still the same error appears. I also tried with another USB cable, another PC, an older Arduino IDE but still nothing happens.
Any ideas ??
After checking so verbose output during compilation& upload it shows this:
Arduino: 1.8.5 (Windows 10), Board: "Arduino/Genuino Uno"
C:\Program Files (x86)\Arduino\arduino-builder -dump-prefs -logger=machine -hardware C:\Program Files (x86)\Arduino\hardware -hardware C:\Users\kat_t\AppData\Local\Arduino15\packages -tools C:\Program Files (x86)\Arduino\tools-builder -tools C:\Program Files (x86)\Arduino\hardware\tools\avr -tools C:\Users\kat_t\AppData\Local\Arduino15\packages -built-in-libraries C:\Program Files (x86)\Arduino\libraries -libraries C:\Users\kat_t\Documents\Arduino\libraries -fqbn=arduino:avr:uno -vid-pid=0X2341_0X0043 -ide-version=10805 -build-path C:\Users\kat_t\AppData\Local\Temp\arduino_build_834827 -warnings=none -build-cache C:\Users\kat_t\AppData\Local\Temp\arduino_cache_621253 -prefs=build.warn_data_percentage=75 -prefs=runtime.tools.arduinoOTA.path=C:\Users\kat_t\AppData\Local\Arduino15\packages\arduino\tools\arduinoOTA\1.1.1 -prefs=runtime.tools.avrdude.path=C:\Users\kat_t\AppData\Local\Arduino15\packages\arduino\tools\avrdude\6.3.0-arduino9 -prefs=runtime.tools.avr-gcc.path=C:\Users\kat_t\AppData\Local\Arduino15\packages\arduino\tools\avr-gcc\4.9.2-atmel3.5.4-arduino2 -verbose C:\Users\kat_t\AppData\Local\Temp\untitled1895278478.tmp\sketch_may18b\sketch_may18b.ino
C:\Program Files (x86)\Arduino\arduino-builder -compile -logger=machine -hardware C:\Program Files (x86)\Arduino\hardware -hardware C:\Users\kat_t\AppData\Local\Arduino15\packages -tools C:\Program Files (x86)\Arduino\tools-builder -tools C:\Program Files (x86)\Arduino\hardware\tools\avr -tools C:\Users\kat_t\AppData\Local\Arduino15\packages -built-in-libraries C:\Program Files (x86)\Arduino\libraries -libraries C:\Users\kat_t\Documents\Arduino\libraries -fqbn=arduino:avr:uno -vid-pid=0X2341_0X0043 -ide-version=10805 -build-path C:\Users\kat_t\AppData\Local\Temp\arduino_build_834827 -warnings=none -build-cache C:\Users\kat_t\AppData\Local\Temp\arduino_cache_621253 -prefs=build.warn_data_percentage=75 -prefs=runtime.tools.arduinoOTA.path=C:\Users\kat_t\AppData\Local\Arduino15\packages\arduino\tools\arduinoOTA\1.1.1 -prefs=runtime.tools.avrdude.path=C:\Users\kat_t\AppData\Local\Arduino15\packages\arduino\tools\avrdude\6.3.0-arduino9 -prefs=runtime.tools.avr-gcc.path=C:\Users\kat_t\AppData\Local\Arduino15\packages\arduino\tools\avr-gcc\4.9.2-atmel3.5.4-arduino2 -verbose C:\Users\kat_t\AppData\Local\Temp\untitled1895278478.tmp\sketch_may18b\sketch_may18b.ino
Using board 'uno' from platform in folder: C:\Users\kat_t\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.6.21
Using core 'arduino' from platform in folder: C:\Users\kat_t\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.6.21
Detecting libraries used...
"C:\Users\kat_t\AppData\Local\Arduino15\packages\arduino\tools\avr-gcc\4.9.2-atmel3.5.4-arduino2/bin/avr-g++" -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics  -flto -w -x c++ -E -CC -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10805 -DARDUINO_AVR_UNO -DARDUINO_ARCH_AVR   "-IC:\Users\kat_t\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.6.21\cores\arduino" "-IC:\Users\kat_t\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.6.21\variants\standard" "C:\Users\kat_t\AppData\Local\Temp\arduino_build_834827\sketch\sketch_may18b.ino.cpp" -o "nul"
Generating function prototypes...
"C:\Users\kat_t\AppData\Local\Arduino15\packages\arduino\tools\avr-gcc\4.9.2-atmel3.5.4-arduino2/bin/avr-g++" -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics  -flto -w -x c++ -E -CC -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10805 -DARDUINO_AVR_UNO -DARDUINO_ARCH_AVR   "-IC:\Users\kat_t\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.6.21\cores\arduino" "-IC:\Users\kat_t\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.6.21\variants\standard" "C:\Users\kat_t\AppData\Local\Temp\arduino_build_834827\sketch\sketch_may18b.ino.cpp" -o "C:\Users\kat_t\AppData\Local\Temp\arduino_build_834827\preproc\ctags_target_for_gcc_minus_e.cpp"
"C:\Program Files (x86)\Arduino\tools-builder\ctags\5.8-arduino11/ctags" -u --language-force=c++ -f - --c++-kinds=svpf --fields=KSTtzns --line-directives "C:\Users\kat_t\AppData\Local\Temp\arduino_build_834827\preproc\ctags_target_for_gcc_minus_e.cpp"
Compiling sketch...
"C:\Users\kat_t\AppData\Local\Arduino15\packages\arduino\tools\avr-gcc\4.9.2-atmel3.5.4-arduino2/bin/avr-g++" -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -MMD -flto -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10805 -DARDUINO_AVR_UNO -DARDUINO_ARCH_AVR   "-IC:\Users\kat_t\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.6.21\cores\arduino" "-IC:\Users\kat_t\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.6.21\variants\standard" "C:\Users\kat_t\AppData\Local\Temp\arduino_build_834827\sketch\sketch_may18b.ino.cpp" -o "C:\Users\kat_t\AppData\Local\Temp\arduino_build_834827\sketch\sketch_may18b.ino.cpp.o"
Compiling libraries...
Compiling core...
Using precompiled core
Linking everything together...
"C:\Users\kat_t\AppData\Local\Arduino15\packages\arduino\tools\avr-gcc\4.9.2-atmel3.5.4-arduino2/bin/avr-gcc" -w -Os -g -flto -fuse-linker-plugin -Wl,--gc-sections -mmcu=atmega328p  -o "C:\Users\kat_t\AppData\Local\Temp\arduino_build_834827/sketch_may18b.ino.elf" "C:\Users\kat_t\AppData\Local\Temp\arduino_build_834827\sketch\sketch_may18b.ino.cpp.o" "C:\Users\kat_t\AppData\Local\Temp\arduino_build_834827/..\arduino_cache_621253\core\core_arduino_avr_uno_7e7efc521bfa236d1e5438b10f2a9ebf.a" "-LC:\Users\kat_t\AppData\Local\Temp\arduino_build_834827" -lm
"C:\Users\kat_t\AppData\Local\Arduino15\packages\arduino\tools\avr-gcc\4.9.2-atmel3.5.4-arduino2/bin/avr-objcopy" -O ihex -j .eeprom --set-section-flags=.eeprom=alloc,load --no-change-warnings --change-section-lma .eeprom=0  "C:\Users\kat_t\AppData\Local\Temp\arduino_build_834827/sketch_may18b.ino.elf" "C:\Users\kat_t\AppData\Local\Temp\arduino_build_834827/sketch_may18b.ino.eep"
"C:\Users\kat_t\AppData\Local\Arduino15\packages\arduino\tools\avr-gcc\4.9.2-atmel3.5.4-arduino2/bin/avr-objcopy" -O ihex -R .eeprom  "C:\Users\kat_t\AppData\Local\Temp\arduino_build_834827/sketch_may18b.ino.elf" "C:\Users\kat_t\AppData\Local\Temp\arduino_build_834827/sketch_may18b.ino.hex"
Sketch uses 444 bytes (1%) of program storage space. Maximum is 32256 bytes.
Global variables use 9 bytes (0%) of dynamic memory, leaving 2039 bytes for local variables. Maximum is 2048 bytes.
C:\Users\kat_t\AppData\Local\Arduino15\packages\arduino\tools\avrdude\6.3.0-arduino9/bin/avrdude -CC:\Users\kat_t\AppData\Local\Arduino15\packages\arduino\tools\avrdude\6.3.0-arduino9/etc/avrdude.conf -v -patmega328p -carduino -PCOM4 -b115200 -D -Uflash:w:C:\Users\kat_t\AppData\Local\Temp\arduino_build_834827/sketch_may18b.ino.hex:i

avrdude: Version 6.3, compiled on Jan 17 2017 at 12:00:53
         Copyright (c) 2000-2005 Brian Dean, http://www.bdmicro.com/
         Copyright (c) 2007-2014 Joerg Wunsch

         System wide configuration file is "C:\Users\kat_t\AppData\Local\Arduino15\packages\arduino\tools\avrdude\6.3.0-arduino9/etc/avrdude.conf"

         Using Port                    : COM4
         Using Programmer              : arduino
         Overriding Baud Rate          : 115200
         AVR Part                      : ATmega328P
         Chip Erase delay              : 9000 us
         PAGEL                         : PD7
         BS2                           : PC2
         RESET disposition             : dedicated
         RETRY pulse                   : SCK
         serial program mode           : yes
         parallel program mode         : yes
         Timeout                       : 200
         StabDelay                     : 100
         CmdexeDelay                   : 25
         SyncLoops                     : 32
         ByteDelay                     : 0
         PollIndex                     : 3
         PollValue                     : 0x53
         Memory Detail                 :

                                  Block Poll               Page                       Polled
           Memory Type Mode Delay Size  Indx Paged  Size   Size #Pages MinW  MaxW   ReadBack
           ----------- ---- ----- ----- ---- ------ ------ ---- ------ ----- ----- ---------
           eeprom        65    20     4    0 no       1024    4      0  3600  3600 0xff 0xff
           flash         65     6   128    0 yes     32768  128    256  4500  4500 0xff 0xff
           lfuse          0     0     0    0 no          1    0      0  4500  4500 0x00 0x00
           hfuse          0     0     0    0 no          1    0      0  4500  4500 0x00 0x00
           efuse          0     0     0    0 no          1    0      0  4500  4500 0x00 0x00
           lock           0     0     0    0 no          1    0      0  4500  4500 0x00 0x00
           calibration    0     0     0    0 no          1    0      0     0     0 0x00 0x00
           signature      0     0     0    0 no          3    0      0     0     0 0x00 0x00

         Programmer Type : Arduino
         Description     : Arduino
         Hardware Version: 3
         Firmware Version: 4.4
         Vtarget         : 0.3 V
         Varef           : 0.3 V
         Oscillator      : 28.800 kHz
         SCK period      : 3.3 us

avrdude: AVR device initialized and ready to accept instructions

Reading | ################################################## | 100% 0.01s

avrdude: Device signature = 0x1e950f (probably m328p)
avrdude: reading input file "C:\Users\kat_t\AppData\Local\Temp\arduino_build_834827/sketch_may18b.ino.hex"
avrdude: writing flash (444 bytes):

Writing | ################################################## | 100% 0.06s

avrdude: 444 bytes of flash written
avrdude: verifying flash memory against C:\Users\kat_t\AppData\Local\Temp\arduino_build_834827/sketch_may18b.ino.hex:
avrdude: load data flash data from input file C:\Users\kat_t\AppData\Local\Temp\arduino_build_834827/sketch_may18b.ino.hex:
avrdude: input file C:\Users\kat_t\AppData\Local\Temp\arduino_build_834827/sketch_may18b.ino.hex contains 444 bytes
avrdude: reading on-chip flash data:

An error occurred while uploading the sketch
Reading | ################################################## | 100% 0.06s

avrdude: verifying ...
avrdude: verification error, first mismatch at byte 0x0002
         0x6b != 0x34
avrdude: verification error; content mismatch

avrdude done.  Thank you.

Try turning on verbose messages for compiling and uploading. To do so, go to File > Preferences > Show verbose output during: and check both boxes.

i edited my question to show you the results i had after doing this.Thank you

Similar to: https://arduino.stackexchange.com/q/44965/19409 https://arduino.stackexchange.com/q/30946/19409 https://arduino.stackexchange.com/q/59837/19409

I feel there is an issue with the bootloader that you are using with your Arduino, or maybe there is a fuse bit error.
Do you have a programmer with you, such as the usbtiny or the usbasp. IF you have another Arduino which works, than you can use it as a programmer as well.
Read up about it here
https://www.arduino.cc/en/Tutorial/ArduinoToBreadboard
Connect the programmer to the Arduino Board, and your computer.
Go to tools, select the Arduino board. Then tools>programmers>select the programmer you are using.Then tools>burn bootloader.
This will fix any fuse bit issues, while also uploading a fresh version of the Bootloader which works with your Arduino IDE.
I hope this helps.

yes i was thinking of using my second arduino as a programmer following this tutorial [link]https://www.arduino.cc/en/Tutorial/ArduinoISP


text:
Trying to use NodeMCU ESP-12e, a 5v relay AND a solenoid lock on same 12v power wall-wart
Noob here, so be gentle.
Using a 12v-5/3.3v power board, NodeMCU powers relay fine, 100% of the time. Add in the solenoid by soldering a line from the wall wart into the COM spot on the relay, and then 10-15% of the time, the activation of the solenoid resets the NodeMCU. Common ground for all of them obviously.
It should be possible to run them all, yes? But what do I need to add into the chain to keep the reset from happening? A capacitor? Magic? Help.

Can you edit your question to draw a circuit diagram using the schematic tool?

do you have a flyback diode on your coils? if not, get ASAP. a cap might help if undervoltage is what resets the MCU

What is your power board?

source: Stack Exchange

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

sort: votes


text:
Line following robot problems
I am making line following robot using Arduino Uno but every time I connect everything together and upload the code and put the sensors on the line the motor does not work can anyone help me?
I use an L298n motor and Arduino Uno. This is the circuit diagram i am using:

And this is the code:
// First the line following (IR) sensors
const int irLeft = 2; //Left line sensor is on pin A2
const int irRight = 3; //Right line sensor is on pin A3

//Motor A (Right)
int enableA = 11;
int pinA1 = 10;
int pinA2 = 9;

//Motor B (Left)
int enableB = 7;
int pinB1 = 6;
int pinB2 = 5;
//Define Run variable
boolean run;
void setup() {
pinMode(enableA, OUTPUT);
pinMode(pinA1, OUTPUT);
pinMode(pinA2, OUTPUT);
pinMode(enableB, OUTPUT);
pinMode(pinB1, OUTPUT);
pinMode(pinB2, OUTPUT);
}
void loop(){
  int valleft= analogRead(irLeft);
   int leftsensor = analogRead(A2);  //in the side of motor B
  int rightsensor = analogRead(A3);  //in the side of motor A

   if ((leftsensor >= 700) && (rightsensor >= 700))
     forward();
        else if((leftsensor <= 150) && (rightsensor <= 150))
     backward();
     else if((leftsensor <= 150) && (rightsensor >= 700))
     turnright();
     else if((leftsensor >= 700) && (rightsensor <= 150))
     turnleft();
}
//Motors Foward
void forward(){
  digitalWrite(pinA1,HIGH);
  digitalWrite(pinA2,LOW);
  digitalWrite(pinB1,HIGH);
  digitalWrite(pinB2,LOW);
}
// Motors Backward
void backward(){
  digitalWrite(pinA1,LOW);
  digitalWrite(pinA2,HIGH);
  digitalWrite(pinB1,LOW);
  digitalWrite(pinB2,HIGH);
}
// turn left
void turnleft(){
  digitalWrite(pinA1,HIGH);
  digitalWrite(pinA2,LOW);
  digitalWrite(pinB1,LOW);
  digitalWrite(pinB2,HIGH);
}
// turn right
void turnright(){
  digitalWrite(pinA1,LOW);
  digitalWrite(pinA2,HIGH);
  digitalWrite(pinB1,HIGH);
  digitalWrite(pinB2,LOW);
}

You give way not enough information. This is how asking "I have a computer for gaming, but it doesn't work. How can I repair it?" Would you be able to do anything about this? I think not

i will guess .... you have a bad motor, get another one  .... here is another guess .... your program is bad, rewrite it ........... you gave no information, so you will only get guesses, instead of helpful answers

I edit the question

Have you tried a very simple sketch to just run your motors in one direction and not doing anything else? If not, try it. If the motors work then, we can exclude a problem with motor wiring or the driver.

check once individually your IR sensor and driver are working properly

Wire, write and debug just one part of your project at a time.

Can you just run a motor?
Can you run it in either direction?
Can this code do the same for either motor?
Can you run two motors?
Can you set either of them to run forward, reverse, or to
stop, independently of each other?

Then the sensors (forget the motors for now):

Can you read the right sensor and detect light or dark?
Can you adapt the code to read either sensor?

Then using the above pieces and knowledge:

Can you make one of the motors run or stop in response to one of the sensors?

Now you have enough pieces - known working! - to reassemble them into a device that uses sensors and motors to navigate. If it fails at this point, there's a whole lot you don't have to debug, and you can concentrate on whatever you haven't tested yet - your navigation algorithm, any rewiring you've done since you tested each part, and whether you've included the final known-working pieces from your tests, e.g., you used all of the latest and greatest bits of code you developed above.

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


text:
What is the output of A0 - A5?
I'm new to Arduino Uno, When I run this piece of code, I get numbers 340 to 370.
This is my question, why it returns 340 to 370 which correspond to 1.66 to 1.80 actual voltage? since I don't have any input equipment plugged into these pins so it must return zero voltage if i'm right in other words why default values in these pins are in this range of numbers ?
void loop() {
int val = analogRead(A0) ; //A1, A2 ...
Serial.println(val) ;

}

You will get varying values on each read. A pin’s input is said to be floating if nothing is connected, which in simple terms can be explained as it just acting as an antenna for whatever electric noise is present in your environment. Its state is unknown, and utterly meaningless. If you hold a spinning electric motor close to the pin, you can see the values rise and fall more clearly.
Use a high value (10K or more) pull-down or pull-up resistor to partially mitigate this jitter. A pull-down would bring the read value down to around 0, and a pull-up would bring it up to around 1023.
Furthermore, it’s a good idea to always smoothen out analogRead (5-10 reads, ~25-50ms apart, average the values out) to get a good reading if precision is important. This is especially valid if you use longer wires, have an unshielded case, or use a switched mode power supply. Twisting the wires (GND and wiper IIRC, otherwise correct me) to a potentiometer helps.
Edit: You can use pinMode( A0, INPUT_PULLUP ); - it provides a 20-50Kohm pull-up, though I don’t trust this and always use 1/4W resistors instead. It saves space though, and is quite handy.

Thanks for your clear explanation, however as I said I'm new to electronic fields, and I have another question, what does happen when I use a 1 mega ohm resistors. On my case I wanna use knock sensor and I found it in every tutorial to use a 1 m ohm resistor to work properly. but I use 6k ohm resistor and that does not work correctly. and signals are falling up and down accidently and when I plug my 6k resistor to the ground and A0 its voltage goes to 0

@shahingh Get a 1Mohm resistor

@shahingh ... or connect 167 6Kohm resistors in series:/

I think I got : )

Please note that INPUT_PULLDOWN is not available on AVR-based boards. INPUT_PULLUP works both on AVR and SAMD boards.


text:
Arduino reading value from external devices on
For this device it says:
The PC Interface Option has all the features of the standard DC1100, but also has a COM Port interface that allows you to capture the air quality data to a PC for graphing and analysis. A 9pin serial cable or USB-to-COM Port Adapter (not included) links the DC1100 to your PC or laptop which then captures the data as it samples.
Is it possible to connect such a device directly to an Arduino so that measured data are sent through the Serial Interface and Arduino is able to read them and manipulate them?

Yes, with a small converter board it can be connected to an Arduino. The "9 pin serial cable" is very likely an RS-232 interface.

RS-232 is like UART with a few extra connections. Here is what the cable looks like:

Basically UART with flow control and other modem lines. Most likely it hasn't any of them conencted but that standard RXD, TXD and GND. These are all the connections needed for the microcontroller.
The voltage level of RS232 is however specified in a wide range (plus/minus 3V to 25V), so you need a converter chip (e.g. this one with a MAX3232, search for "RS232 to TTL Converter Board"). You need to measure the voltage levels with a multimeter to see what converter for what voltage rage you need.

Then conencting it to an Arduino is as simple as just connecting these 3 wires to the Arduino, either to the Hardware Serial port (D0, D1, GND) or via a software serial port.
Reference project:

http://www.picprojects.net/rs232_communication/

However, receiving the communication data is only half the battle. You still have to figure out what the sent data represents and what commands you can send the device. Without datasheets from the vendor, you are left alone. This is where reverse-engineering starts.
As a starting point, you can "eaves-drop" on the communucation that PC software does with the device by just connecting a USB-RS232 converter to your computer and connecting the RX line line to either the TX or RX line of the the target device's COM port. This allows you to see the entire communication exchange. From this you might be able to see what commands you're supposed to send. But as I said, from there it's unchartered territory.


text:
How to connect a 240x320 37-pin TFT to an Arduino Nano?
I have an old TFT display (extracted from an MP5 player) and I can't figure out how to connect it with an arduino nano, pls help.
here's the datasheet of the TFT:
http://read.pudn.com/downloads137/sourcecode/embed/586271/Varitronix-2.8-lcd/vl-ps-cog-t280mbqi-041.pdf
Thank you.

The datasheet says it all: A ILI9320 display driver with a 16-bit data bus (instead of SPI). Can you show a picture of the display and the connections? It's pretty close to https://learn.adafruit.com/adafruit-3-5-color-320x480-tft-touchscreen-breakout/8-bit-wiring-and-test. (8bit). If no 16-bit parallel driver is available you'll have to look at the ILI9320 datahseet and build one. However, if your objective is just to get a display for an Arduino, just buy a new well-known display with a simple SPI interface for which there are drivers.

Is this datasheet hosted on the end of a 56k dialup modem...?

The Nano isn't a good choice for driving that screen. You need almost all the pins of the Nano to connect to the screen alone, and there's not enough to include the touch-screen as well. And that's when you're not using the serial port of the Arduino (TX/RX pins) for communication with the PC.
You need to connect:

16 data pins
/CS pin
/RS pin
/WR pin
Optionally RD pin, or tie it to 3.3V
/RESET pin

And all those need to be level shifted to 3.3V.
You need to provide 3.3V to VCC1/2 and VCI.  The LED A connects to 5V (since it has more current capacity than the 3.3V) and each LED Kx pin through a suitable resistor (220Ω maybe) to ground.
The touchscreen needs the X- and Y- pins connecting to a digital IO pin, and the X+ and Y+ pins to analog IO pins that can also double as digital IO pins (so not A6/A7 on boards that have them).
And then you need to obtain or write the software to drive the ILI9320 through the 16-bit interface.
Driving the interface is simple enough:
Initially:

Set /CS HIGH
Set /WR HIGH
Set /RD HIGH (if not tied to 3.3V)
Set /RESET HIGH
Short delay
Set /RESET LOW
Short delay
Set /RESET HIGH

Then to transfer a group of 16-bit words:

Set /CS LOW
Set the value to write on the 16 data pins
Pulse /WR LOW then HIGH
Repeat from 2 for each word
Set /CS HIGH

Refer to the ILI9320 datasheet for how to control the chip, or use existing library code (does uTFT or u8glib support it?).
For the touch screen it's a case of setting Y- LOW and Y+ HIGH, and X- and X+ to INPUT, then reading the analog value from X+.  Repeat with X- set LOW and X+ set HIGH, and both Y set to INPUT, and read the analog value from Y+.
You can also get better results by reading multiple inverted settings:

Y- = LOW, Y+ = HIGH, X- = INPUT, Read X+.
Y- = HIGH, Y- = LOW, X- = INPUT, Read X+.
Subtract the second reading from 1023
Add the first and (modified) second reading
Divide by two.
Repeat for X-/X+ reading from Y+.

You can also take multiple readings and average them out to reduce noise and stabilise the output somewhat.
And of course on top of all that you need to find a way to connect to a 0.5mm pitch connector. Normally a 0.5mm pitch FPC socket is used, which means a PCB with one on.  You may be able to find 37 pin adaptor for it, but 37 pins isn't a common format.  Normally 50 pin is more common to accommodate a more general purpose interface including the M0-M2 pins that allow you to select the interface type, as well as an 18-bit data bus to allow full RGB6/6/6 interfacing, and even buffer-less clocking of raw display data for very high speed display updates by MCUs that support such an interface.

I'll try it later (can't do it now because my computer is toast), thank you for your help by the way. i'll tell you later if it worked.


text:
Arduino Nano /Uno USB is not getting recognized
I have multiple Unos and Nano and recently due to some bad configuration the USBs are not getting recognised on my Mac Air Laptop. These were working models for almost 1-2 years. I used it to control motors and something must have happened and it stopped.
But strangely the small boot up LEDs on the Nano/Uno light up when connected so it seems that the connection from the laptop USB to the device is good - but the driver ports are not showing up on the Arduino IDE.
How do I go about resolving that it is not just a software issue and is a hardware issue ?
I reinstalled the CH340G driver.img and yet the device when plugged in - does not show the USB port on the IDE ?
Any thoughts or ideas on how to resolve this.
The Uno/Nano are Chinese Clones and have CH340 chipset on them.
Is there some firmware that may have gone wrong and can be reset ? or new boot loader that can be burnt to bring them back to life.
I want to be able to see the Tools-> Port -> /dev/cu.usbserial1410
and also be able to see /dev/cu.usbserial on the command xterm prompt .

1-2 years is a good lifetime for a CH340G...

Assuming that the atmega328p still works fine, you can still use the Nano. I have solved this a few times by just using a FTDI breakout board (remember to set it to 5V, though 3V3 upload works on a Nano), and connecting RX to TX, TX to RX. Press reset before each upload.

Thanks for the answer - I have a cloned Uno and a Nano. I guess I have to use a different breakout ?
My Uno/Nano has a 340G chipset, not FTDI.

Unos (real or cloned) use a 2nd processor on the board to manage USB communication with your computer. Since that processor or its firmware on your board is not working, @user2497 is suggesting you bypass it with another one on a breakout board or built into a cable. That breakout board or cable will almost certainly use an FTDI chip, regardless of what chip on the clone board has. You'd connect the breakout board or cable directly to the ATmega328p's RX and TX pins, just as its (now non-functional) 2nd processor is.

I have a PL2303 ( I think it's similar to FTDI) and installed the driver and was able to see the driver on Arduino IDE.
PL2303 .   Arduino

PL2303 Tx ->    Arduino Rx

PL2303 Rx ->    Arduino Tx

PL2303 GND -> Arduino GND

I did not connect the 3V3 of the PL2303 and left if open.
What is the Tools-> Board and Tools-> Programmer to use on the IDE ?

I reset the Arduino button  just when I clicked the Upload on the IDE, and it's just uploading .. or timeout with the stk_recv error !

@ShashiKiran Just use the default, and select the right serial port. You press reset just before the upload? The timeout is normal if you don’t press reset in time.

@user2497 - Thanks, So I am not connecting the PL2303's 3v3 to the Arduino's 3.3v - Is that right.
I tried about 3 of the Arduino's so far - and the "Uploading" stays put for a long time ! after I have clicked on the Reset Button of the Uno. !
On a side note - all the 3 Uno's boot-led- near pin 13 lights up when powered by a 5V USB. ( that is before I even try to upload the code )

@ShashiKiran Use 5V, use a levelshifter if you have one.

@user2497- You mean provide Uno's 5V -> to 5V ( or 3.3 using the level shifter) of the PL2303 breakout board.
Is the break out board not getting power from the USB port of my Mac. A really small red light lights up on the PL2303 when I plug in to my Mac USB Port.


text:
Arduino, exit status 1. Can't compile for Arduino Uno
#include <LedControl.h>

void setup() {
// put your setup code here, to run once:
}

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

This is my code: with LedControl.h it gives me exit status 1, can't compile for Arduino Uno. Please help.
If I remove the #include it works normally.
Also Arduino says that the library has been installed.
What I have tried (but didn't work):
Re-installing the library.
Re-downloading Arduino.

"Exit status 1" means "there was an error". You forgot to tell us what that error is.

@Majenko  "exit status 1 can't compile to arduino uno" it's literally in the title

No, that is NOT the error message. Paste in the entirety of what is in the output pane if you don't understand what an error message is.

Don't cross post. You already asked this on Stack Overflow.

@gre_gor I was told on stackoverflow to ask my question here

@nordinleije Did you check the link?

I tried compiling your code with Arduino 1.6.12. As you found, without the #include, it compiles OK. With the #include, it fails. Here is the error message I got:
/var/folders/bl/s5kzhm3s0lb2rcvp3md8c7040000gp/T/untitled1814027053.tmp/sketch_may17a/sketch_may17a.ino:1:24: fatal error: LedControl.h: No such file or directory
 #include <LedControl.h>
                        ^
compilation terminated.
exit status 1
Error compiling for board Arduino/Genuino Uno 115.2.

The error - at least in my case - is that the library, LedControl.h, was not found. Try to find out why not.

also aruino says that the library has been installed.

It's easy to check: "Installing" library foo.h, only means your sketchbook folder contains a library folder called libraries (all lower case); libraries contains a folder foo; and foo contains the file foo.h and any other files necessary for that library, such as a foo.cpp if needed:
- Sketchbook - libraries - foo
                             foo.h
                             foo.cpp
                             anything.else.you.like

Update:
The library documentation is on github and has links to some sample code. Sorry I can't be more help - I haven't used the library or those LED devices.

thank you for you anwer, could you please also show how to use this library properly I kinda need it, because I use a MAX7219 LED.

how to use this library properly ... don't get ahead of yourself .... you don't even know if you have the library installed


text:
Concatenate integers as string
How can i concatenate integers as a single string?
int out1, out2, out3 = 0;

    out1 = digitalRead(r1);
    out2 = digitalRead(r2);
    out3 = digitalRead(r3);

I tried like so, between others, with no luck.
Serial.write(out1 + "" + out2 + "" + out3);

For example the expected result when all outputs are HIGH should be 111, while when only the r3 output is HIGH it should be 001
All i want, is reporting to the sender of the serial command, the pins state

Since you only use 1s and 0s, you could also convert it to a three digit number, and print that Serial.write(out1*100 + out2*10 + out3);

@Gerben: You mean Serial.println().

Correction: Serial.println(out1*100 + out2*10 + out3); (thanks @EdgarBonet)

If you're just outputting to serial you don't need to concatenate - just print each bit separately, such as:
Serial.print(out1);
Serial.print(",");
Serial.print(out2);
Serial.print(",");
Serial.println(out3);

You should avoid using String as it's not good on devices with small amounts of memory like Arduinos. Instead if you really need to concatenate numbers you should use a C string and maybe snprintf to format the numbers into it:
char out[30];
snprintf(out, 30, "%d,%d,%d", out1, out2, out3);

I second Majenko's points about just printing the bits separately if
possible, and avoiding String objects.
However, if you do need to build such a string (not String object, just
plain C string), you don't need sprintf(), which is quite a big
function: you can build the string character by character. For example:
char out[4];  // 3 + 1 char for the termination character
out[0] = out1==HIGH ? '1' : '0';
out[1] = out2==HIGH ? '1' : '0';
out[2] = out3==HIGH ? '1' : '0';
out[3] = '\0';  // add NUL termination
Serial.println(out);

This is using the ternary operator, which here means “if out1 is
HIGH, then use the character '1', otherwise use '0'”.
Now, it just happens that in Arduino HIGH means 1 and LOW means 0.
And single digit numbers can be converted into character by just adding
the numeric code of character “0”, which is 48 but can written as '0'
in C++. Thus you can write:
out[0] = out1 + '0';  // convert number to character

And you can put all together as:
char out[4];  // 3 + 1 char for the termination character
out[0] = digitalRead(r1) + '0';
out[1] = digitalRead(r2) + '0';
out[2] = digitalRead(r3) + '0';
out[3] = '\0';  // add NUL termination
Serial.println(out);

Serial.write(b) prints one byte not a string. Use print() to print strings and numbers.
Serial.print(digitalRead(r1));
Serial.print(digitalRead(r2));
Serial.println(digitalRead(r3));


text:
Reducing Clock Speed increases sketch size?
I just lowered the clock speed of my arduino promini 3.3v - 328p from 8Mhz to 1Mhz on the external clock disabling the brounout detection and when I compiled I my old sketch it wouldn't upload any more because suddenly the size has increased from 31KB to 35KB.
Does anyone know why this could happen. I didn't make any changes in the code and it still loads into the 8Mhz Arduino without any problems.
I used these low power config files: https://github.com/joe-speedboat/Arduino-LowPower

Compare the platform.txt from the Arduino IDE with the one in the low power config files above. There is a vital difference in compiler/linker setting.

@MikaelPatel: You mean -flto?

Does your code have delays in it? If you changed the clock speed, then the compiled assembly for the delays may require more NOP instructions or something similar to achieve the same real-time delay. As a result, the size of the compiled sketch could increase.

Delays are implemented by loops, not by long strings or nops.


text:
Connecting two sensors with bluetooth
I am new with Arduino. Im working in a school project, and I decided to create a glove with shock sensor for goalkeepers and need a ultrasonic sensor next to the ball, so i can know when the ball was kicked.
I need the data from both sensor.
Is this possible with only 1 arduino?, where the arduino is with the ultrasonic sensor and the shock sensor is connected with a bluetooth module to send it to the arduino.
Or, I have to use 2 arduinos?, one with with the glove and the other with the ultrasonic sensor and connect both with bluetooth?
If this is not the best way, can you help me with some ideas to do it? Thank you.

what are you trying to measure? .... how will the device be used?

This to be possible with only 1 Arduino depends in your sensor. It is most likely not possibpe without another microcontroller (not nesessarily an Arduino) because of the following reason.
Most bluetooth modules on the market (linke the HC-05 vor HC-06) are bluetooth serial modules, meaning that they build a serial connection over bluetooth and provide the corresponding two pins (RX and TX). Yet most sensors don't implement an UART interface (the Serial interface in Arduino), but only give an analog or digital output voltage. With much work you might be able to tweak the firmware of the bluetooth chip for reading and sending a digital value, but this would be more work, than the price of a second microcontroller would justify.
So I would try to add a small microcontroller (like an ATTiny85) to the sensors side. It can measure the sensors output voltage and then send it via Serial to the bluetooth module. You might also want to use another Arduino here, though this might be an overkill. Maybe a really small version.

After some thinking I had the idea, that it might be possible to send an analog voltage from the sensor through a audio bluetooth module without using another Arduino. Though I'm not sure if this really would work and which module you need for that.
All in all I still would go for the extra microcontroller and serial interface bluetooth, because it is much easier for a beginner.
EDIT:
Above I mentioned using Serial on an ATTiny85, which is not directly possible, since it does not have a full UART hardware (but only a USI). Though you can use the standard SoftwareSerial library on it. If the rest of your code isn't to big, it should still fit in the small memory of the Tiny.


text:
Sending a character 'A' through blinking led

How do i code to send a character 'A' to the arduino through a blinking led?
   i am doing a project about data transmission. i really need help&some guide.
   Material used are arduino uno r3,white led and a resistor.

MY OUPUT IN SERIAL MONITOR
Insert letter:
01000001 65  - Character A
00001010 10  - when i send/enter
CODE
 int LEDTrans = 13;
int timeWaitOn = 1000; //milisec (1 sec)
int timeWaitOff = 1000; // milisec (1 sec)
byte byteRead;

void setup() {
// Turn the Serial Protocol ON
  Serial.begin(9600);

 Serial.print("Insert letter:");
 Serial.println(" ");
}

void loop() {

digitalWrite(LEDTrans,HIGH); //turn the led on
delay(timeWaitOn); //delay in millisec (1 sec)
digitalWrite(LEDTrans,LOW); //turn the led off
delay(timeWaitOff); //wait a sec

   /*  check if data has been sent from the computer: */
  if (Serial.available()) {

     byteRead = Serial.read();
    // will print the binary representation of 'byteRead' as 8 characters of '1's and '0's, MSB first.
for ( uint8_t bitMask = 128; bitMask != 0; bitMask = bitMask >> 1 ) {

      if ( byteRead & bitMask ) {

    Serial.write('1');
  } else {
    Serial.write('0');
  }
}

Serial.write("    ");
Serial.println(byteRead);    //send back the actual ASCII code
}

}

you forgot to ask a question

There is no code intended to send something over a LED. Try googling something like Arduino light data transmission and similar terms. There are libraries for that

Possible duplicate of transmit a sequence of bit using arduino uno

Huh, I'm confused. You asked this exact  question here https://arduino.stackexchange.com/questions/52352/transmit-a-sequence-of-bit-using-arduino-uno/52363#52363 and the given answer is also the exact functional equivalent, except that the data is coming from the serial monitor..

i'm learning a lot from this website. im a beginner and i want to learn a lot of things. your explanation and help was really helpful :) im really grateful for that. thank you so much.

I want you to state, very clearly, what you want the code to do. For example: When I send "A" I expect a pause of 1 second with the LED off, then the LED to be on for 1 second, then the LED to be off for 5 seconds, then on for one second, and then off for one second (giving a total of 8 seconds to send the letter "A"). If that is not what you want please state what you do want.

Now get it. I saw the LED on and off as you describe above. Therefore it takes only 8 seconds to send letter 'A'. Thank youu veryyy much

Instead of printing '0' or '1' set the LED pin off or on, like this:
const int LEDTrans = 13;
const int timeWaitOn = 1000;  // millisec (1 sec)
const int timeWaitOff = 1000; // millisec (1 sec)

void setup() {
  // Turn the Serial Protocol ON
  Serial.begin(115200);
  Serial.println("Send letter:");
  pinMode (LEDTrans, OUTPUT);
}

void loop() {
  /*  check if data has been sent from the computer: */
  if (Serial.available()) {
    byte byteRead = Serial.read();
    // will print the binary representation of 'byteRead' as 8 characters of '1's and '0's, MSB first.
    for ( uint8_t bitMask = 128; bitMask != 0; bitMask >>= 1 ) {
      if ( byteRead & bitMask ) {
        digitalWrite(LEDTrans, HIGH); //turn the led on
        delay(timeWaitOn); //delay in millisec (1 sec)
        digitalWrite(LEDTrans, LOW); //turn the led off
      } else {
        delay(timeWaitOff); //wait a sec
      } // end of if
    } // end of for loop
  } // end of if something available
} // end of loop

how do i count the flashes? is it based on the binary 01000001?

Here's the problem ... according to what your question seems to ask for, you are wanting an LED to flash for a 1 and be off for a zero. So the results (which my code provides) would look like this:

So, you get two flashes, the first one second after it starts, then there is a gap of 5 seconds, and then another flash. That would be 01000001.
However, how do you know when to start counting flashes? It might be:

That would be 00000001.
Or even:

That would be 10000010.
You can see, can't you, that you can't make any meaningful deduction at the receiving end about what the character is?

So what asynchronous serial (normal serial on an Arduino) does is have a Start Bit which signals when to start counting, like this:

Normally the serial port is high (continuous 1s) and then when a 0 arrives that means "start counting". So, you wait 1½ bits of time and then sample at the known baud rate. In your example, where you want 1 second per bit, the baud rate would be 1 (one bit per second). Thus, you sample every one second. Normally baud rates are somewhat faster than that, like 9600 or 115200 samples per second.
Also there is a Stop Bit which is always a 1. This guarantees that there will be at least a single 1 at the end of each byte, so that we can tell when the next start bit arrives.

There are other ways of doing this, for example a short pulse might represent a zero, and a longer pulse represent a one. In that case, any pulse at all could represent the start of a byte, and then you just measure how many short pulses, and how many long pulses, you get (for some definition of "short" and "long").

thank you soo much the blinking happened. but i am a bit confused. I count the on and off for the led to see the character of 'A' in binary that is 01000001. but it didn't happened.

Really? I changed the baud rate to 115200, I hope you noticed. If I send "A" then I get the LED flashing after 1 second and after 7 seconds, which is right: 01000001. You expect two flashes, one a second in, and one seven seconds in. The rest of the time the LED is off (that is a zero).

Oh. I noticed that,but i tried to change to 9600.Maybe that's why. Do i really must use the baud rate 115200 to achieve 01000001 ?What type of library should I import in this coding?Where can i get the library?This arduino acts as a transmitter to send the character 'A' and the receiver is an application. Do you have any suggestion how can i synchronize both of them?Can i have your email. i have a lot to ask.

The baud rate is only for you to send a character to the sketch from the serial monitor. The rate at which the LED blinks is set in your code, currently one bit per second. There is no library you need. Why do you think you want one? If you have more questions please post them here.

I thought I need one. I went through other projects they import libraries. But I currently don't understand what you mean by >>    flashing after 1 second and after 7 seconds, which is right: 01000001. You expect two flashes, one a second in, and one seven seconds in. The rest of the time the LED is off (that is a zero).

I'm curious to know what you are expecting to happen. Please state how often you expect the LED to blink and at what intervals. Surely 01000001 represents two blinks? (There are two "1"s there). What else could it represent?

I am sorry that I made you confused. How do i count the flashing of the led that you mention before?for 1 how many flash&seconds that it represents?and for 0 how many seconds does the led went off? i want to transmit the 'A' in binary for 10 seconds. If the led is on,does it represent 1?i am a bit confused there.When the led is off it represents 0?

how do i count the flashes? is it based on the binary 01000001?how do i count the flashes? is it based on the binary 01000001?the pins that i connect the jumper to the led should be pin 13 and tx is it right?i want to transmit 'A'.

Nick, I tried to count the blinking of the LED on the arduino board. it shows flashing after 1 seconds and after 7 seconds. but when i attached a white LED using the jumpers,the flahsing is different. i count the flashing, when the LED starts to went off as 0, then it when on as 1. the white led blinks 0 1 0 1 0(5 to 6 sec) 1 0 1.  Or i should count on the second blinking that shows 010000010 ?

the pins that i connect the jumper to the led should be pin 13 and tx is it right - No, pin 13 and Ground, with a current-limiting resistor between the LED and ground, for example 330 ohms.

how do i count the flashes? - what do you mean by that? When you see a flash you count it? You also make a note of the time between the flashes. I am completely unclear, after reading these questions, about what you are expecting the code to do, and if you can't state that then neither I, nor anyone else (including you) can make it do that thing, whatever it is.

Now i understand. I am expecting the arduino to be a transmitter that transmits character 'A' through pin 13 on the arduino.  You helped me a lot Nick. Thank you very very much.


text:
Turn on LEDS one after another
I am trying to turn on LEDs one after the other so that I can start at one end and slowly turn the LEDs until it reaches the middle of the strip. The code works coming from the end of the LED strip, but not when coming from the start of the strip. From the start of the strip, it just turns on all the LEDs up until the midpoint.

int midpoint = 30;
int R = 255;
int G = 0;
int B = 0;
for(int j = 0; j<midpoint; j++){
     //starting from the end, filling towards the middle
        for(int k = NUM_LEDS-j; k < NUM_LEDS; k++){
           leds[k] = CRGB (R, G, B);
        }
//there's some other code here in the interim
FastLED.show();
delay(20);
     //starting from the beginning, filling towards the middle
     //this is the section of code that doesn't work correctly
        for(int l = j - 1; l < midpoint; l++){
           leds[l] = CRGB (R, G, B);
           }
//more interim code
FastLED.show();
delay(20);
}

which number does the for loop start with now? .... change it so that it coun ts in the opposite direction

Ooo I just thought about how l is increasing through the loop instead of decreasing. I solved it by changing it to for(int l = j; l < midpoint & l > -1; l--)

If you have solved it, you can post an answer to your own question. If you don't, the question will stay here, unanswered.

You should fix your indentation. It's very hard to tell what code is inside the outer j loop since some of that code isn't indented.

You need to add more explanation. What framework you're using, and how the leds array relates to your FastLED.show() function. Does it show the LEDs that are in your leds array? What turns the LEDs off again?

Okay so i figured it out. The problem is that the for loop is starting at 0 and counting all the way up to the midpoint. What I wanted is for it to light all the LEDs that are at j and below. So I changed it to iterate down instead of up. Here's the new loop:
for(int l = j; l < midpoint & l > -1; l--){
   leds[l] = CRGB (R, G, B);
}

The extra qualifier l > -1 is to make sure that it doesn't try to go below leds[0]

l >= 0 is more natural than l > -1, the compiler will probably optimise it to the same thing.

+1 for taking the time to post the solution to your problem. Most new members don't do that.


text:
Scan Bluetooth devices using HC-05
Basically, I want to connect the HC-05 to a specific mobile Bluetooth(whose address is known) and when the connection is established I want to turn on a LED on the breadboard.
I am totally clueless how to write the code. Can you please help me with it as it is a part of my project.
I know the various AT commands and have scanned the Bluetooth address with AT+INQ command.

You know how to configure the HC-05 with AT commands (as you wrote). What is the problem with just letting the Arduino send these commands over the Serial? Be more specific in what the actual problem is.

I want to connect the HC-05 to a specific mobile Bluetooth and when the connection is established I want to turn on a LED on the breadboard.
So I want help with its coding.

If you don't have a clue how to start: Start with an empty sketch with setup()? and loop() function. In the setup() function initialize the connection. Send the AT commands over Serial. Do Serial.begin() with the correct baudrate (the same as when you scanned with AT+INQ command). Send all necessary AT commands like Serial.print() or Serial.write(). Check with Serial.read() for the modules answer. If you get an understandable answer, you have a functioning serial connection to the module. Try it and come back, when you have a specific problem, that you cannot solve.

If you are using an Arduino board with HC-05 for AT commands over serial, you can follow the below flow :

Setup HC-05
Check for available nearby devices AT+IRQ
Check the response to check is the desired device is enlisted in the nearby devices
If device is enlisted, use AT+BIND=<Bluetooth address> to connect to the other device
Check the response of the AT+STATE? command until you receive “CONNECTED” (you can go for a while loop here)
Once the connection is successfully established here, you can send a confirmation now as per your requirement.

The above scenario is applicable only when you are sure with the Bluetooth address of the device you want to connect to. If the scenario is something different, comment and let us know with the actual requirement.

I want to connect the HC-05 to a specific mobile Bluetooth(whose address is known) and when the connection is established I want to turn on a LED on the breadboard.
So I want help with its coding.

Then in that case the above procedure might help you to the fullest.

Thanks a lot. It helped me a lot and even I m almost done with the coding part.

Your welcome Shivam Thakur. I just want to remind you that if you find any answer that helped you with your problem, just mark it as Accepted so that the one who helped could earn reputation score & also, it could help others.


text:
Error: "undefined reference to ..." when calling non-void class' functions from within class
I haven't used an Arduino for anything as complicated as this project before (single sketch projects so far), and am struggling getting my code to compile now that I'm creating my own libraries for the project.
I can see that it's the class' methods that return something that cause an issue, those that directly edit the classes variables instead don't appear to cause issues when compiling (i.e. void functions).
I can't share the actual code, but here's an altered and stripped down version that shows the same issue.
The sketch:
//Issues.ino

#include "CmdLib.cpp"

void setup() {
  //Setup USB
  Serial.begin(19200);
  Serial.flush();

  //Setup Bluetooth
  Serial0.begin(9600);
  Serial0.flush();
}

void loop(){
  CheckForPCMessages();       //Parses any messages from USB and Bluetooth
  //All the other things we need to do
}

void CheckForPCMessages(){
  CheckForMessages(&Serial);  //Check USB first
  CheckForMessages(&Serial0); //Then check Bluetooth
}

template <class T> void CheckForMessages(T *port){
  //Using function template so that works for USB and Hardware Serial
  if(port->available() != 0){
    String received_string = port->readStringUntil('\n');
    port->flush();
    Serial.print(received_string);
    Serial.println(" was received.");
    Command received_cmd(received_string);
    //Do stuff with the command (add it to a Q, etc, etc)
  }
}

The Header:
//CmdLib.h

#ifndef CmdLib_h
#define CmdLib_h

#include "Arduino.h"

enum CommandLabel{
  //Not a command
  NO_COMMAND = 0,

  //...
  //A whole bunch of other options that I can't share
  //...
};

enum CommandType{
  NA = 0,
  //...
  //A whole bunch of other options that I can't share
  //...
};

class Command{
  public:
    Command(String msg);
    String GetCmdStringFromMessageString(String full_string);
    CommandLabel GetLabelFromString(String labelstr);
    void SetLabelAndType(String labelstr);
    void SetLabel(CommandLabel label);
    void SetType(CommandLabel label);

  private:
    String _x = "";
    String _y = "";
    String _z = "";
    CommandLabel _label = NO_COMMAND;
    CommandType _type = NA;
};

#endif

The cpp file:
//CmdLib.cpp

#include "CmdLib.h"

Command::Command(String msg){
  String labelstr = Command::GetCmdStringFromMessageString(msg); //Separates label from msg
  Command::SetLabelAndType(labelstr); //Sets _label & _type vars
}

String GetCmdStringFromMessageString(String full_string){
  //Pulls out everything before first comma
  int first_comma = full_string.indexOf(',');
  String output;
  if(first_comma != -1){
    output = full_string.substring(0,first_comma);
  }
  else{
    output = full_string;
  }
  return output;
}

void Command::SetLabelAndType(String labelstr){
  CommandLabel label = GetLabelFromString(labelstr);  //Get label from string
  Command::SetLabel(label);                           //Set label
  Command::SetType(label);                            //Set type based on label
}

CommandLabel GetLabelFromString(String labelstr){
  //...
  //Cleverness to determine which to return...
  //...
  return NO_COMMAND;
}

void Command::SetLabel(CommandLabel label = NO_COMMAND){
  _label = label;
}

void Command::SetType(CommandLabel label){    //Set _type to appropriate type based upon label
  //...
  //Cleverness to determine which to return...
  //...
  _type = NA;
  return;
}

And here's the Error:

sketch\CmdLib.cpp.o: In function `Command::SetLabelAndType(String)':
[REDACTED]/temp/arduino_build_557572/sketch/cmdlib.cpp:24: undefined reference to `Command::GetLabelFromString(String)'
sketch\CmdLib.cpp.o: In function `Command::Command(String)':
[REDACTED]/temp/arduino_build_557572/sketch/cmdlib.cpp:6: undefined reference to `Command::GetCmdStringFromMessageString(String)'
collect2.exe: error: ld returned 255 exit status
exit status 255
  Error compiling for board Fubarino Mini.

I've found previous answers where the same compile error occurred with class variables that were called to without being given an initial value, but can't find similar solutions for the error when created by a call to a function.
Any help would be greatly appreciated.

You forgot to put the function in the class:
CommandLabel GetLabelFromString(String labelstr){

should be:
CommandLabel Command::GetLabelFromString(String labelstr) {

Also, on a side note, if you must use String objects (ugh!) then please pass them as reference so as to avoid needless heap allocation and data copying:
CommandLabel Command::GetLabelFromString(String &labelstr) {

... Damn it. Well, thank you for saving me from myself!
Edit: Good point on the String referencing - in this case I do need to use them, as I won't know the length of the char array being sent in advance

The simplest mistakes are often the hardest to spot. It's called going "code blind".


text:
Find Elapsed Time on Serial Plotter
How do I find out the elapsed time from the serial Plotter graph? I am plotting sensor values from the Arduino Nano and would like to know the time scale on the x-axis in order to calculate settling time of oscillations.
I have tried the suggestions here but they do not seem to work in my case.
For example, in the graph below I would like to find out the time it took for the sensors to record their first movement at around point 190.

I am doing the following to print two values:
   //printData1();
   Serial.print(roll_err);
   Serial.print(" ");
   Serial.println(pitch_err);
   Serial.print(" ");

Baud Rate: 9600
Loop Time: 40ms
If my loop time is 40ms then I was thinking that the total time would be 180*40ms. Is this reasoning correct?
Is there a better way to read the time elapsed in the serial plotter?
EDIT: Trying to get a 10ms 'grid'
As per the suggestion in the answer below I have tried running something similar to the following but the loop does not run at a constant time.

I tried to add Serial.print(((millis()/10)%2)*50); but as can be seen, the loop time is not constant.

The serial plotter in the IDE is pretty basic. The x axis is just the number of y values, and 1 pixel in the x direction. You could try adding Serial.print(((millis()/10)%2)*50);  to fake a 10 ms "grid".
Serial.print(" ");

If my current loop time is 40ms shouldn't I be dividing that by 40 to get a 10ms 'grid' ?

Sorry, I kind of missed that part. I’d probably go with 1000ms. But note that a line could end up being at for example 2038ms instead of 2000ms due to the around 40ms it takes per loop.

Alternative would be to also print the millis value an copy the data to excel. And use that to plot a graph.

It depends on how precise you want your time-base to be. The plotter's x-axis is in sample-count, not time, so you have to emit samples at a fixed rate for it to have time-significance.
Your
loop(){
   yadda();
   zadda();
}

may or may not run at a constant rate, depending on what takes place in each iteration of the loop, as well as on your definition of "constant" (I don't believe I just said that...)
Even if none of your code is conditional, binary to ASCII conversion, clock and Serial interrupts, and other low-level code we don't see, may run slightly differently from iteration to iteration; e.g. the number of interrupts during any given iteration may well vary.
If you need to hold a tighter timebase, stalling at the bottom of the loop until millis() reaches (the previous millis() + an interval constant) will at least get you to within a millisecond of a fixed loop-rate. You could, of course, do the same thing with micros(), as long as you know for a fact that the loop can never take longer to execute than 1/frequency you need it to run at, and even then, it should take a fair slop-factor (that's a technical term! :) less than that, "just in case".
Update:
Though I wrote "stalling" at the end of the loop, a better technique is to call every job (in your case, 1 of them - for now ? ) as frequently as possible and let each job decide whether it needs to execute. So in your case:
loop {
  maybeSampleAndPlot();
  // maybeDoSomeOtherThing();  // not implemented yet...
}

maybeSampleAndPlot(){
  time = millis();
  if time - previousSampleTime >= MSEC_040
    save (time + MSEC_040) as nextSampleTime;
    sample the data;
    plot the data;
  endif
}

Thanks for your answer. I will try to implement this. Is the interval constant used to allow for additions in computational time within the main loop? Updated my question. Would you be kind enough to provide some short pseudo-code on how I should go about implementing the millis() computation? Much appreciated.

Look at the BlinkWithoutDelay example of the Arduino IDE and replace the LED blink code with your measurement code. Then change the interval variable to the value you need.

if time >= nextSampleTime should be replaced by if time - previousSampleTime >= MSEC_040. Otherwise the timing will fail when millis() rolls over. The “Blink without delay” tutorial does it the right way.

Absolutely correct - fixed. Thanks, @EdgarBonet. [face-palm]


text:
Arduino Pro Mini stopped working / broken
I need help, currently I am working in final project about portable monitoring system. I am using Arduino Pro Mini 5V/16MHz as microcontroller and a Li-Po battery to power it up through XL6019 boost converter. I have created the PCB and assembly all components but suddenly when I turned it on, the Arduino Pro Mini suddenly stopped working. Recently I am adding a feature to measure the battery capacity so I connected the battery voltage to arduino pro mini Analog Pin, is that the problem? But I have tested the method of measuring battery capacity using Arduino Uno before and it worked fine. .
I am confused right now about what is the main problem.. and also is there any way to repair the Pro Mini? The Pro Mini used in project can't be reseted and I can't upload any program to it.
Pls help.

What voltage did you connect to the Pro Mini's analog pin? Was it greater than 5 VDC?

The Li-Po battery output voltage, it around 3V - 4.2V (fully charged).

Are you have checked the voltage in the output of XL6019 is 5V?


text:
Input from two microphones to bluetooth
I am a complete noob at arduino, so I apologize if this is a stupid question.
I would like to take input from two microphones and send the output to a bluetooth headset using an Arduino processor? Is this something that can be done with these processors or do I need something more powerful, like a Raspberry Pi?
I don't really need to process the signal at all, simply add the 2 inputs together and divide by 2 to keep the output from clipping.

There are bluetooth audio modules, which have an audio input or output. You have to search for one of these. Keep in mind that you cannot use a bluetooth serial module like HC-05 or HC-06. The audio mixing can be done via electronic components. This should be easier, that first sampling both audio signals to an Arduino and then output the resulting analog voltage again.

Your comment on combining the two inputs before digitizing makes perfect sense. Thanks.

The point was, that the bluetooth audio module should do the digitizing. In this case the Arduino is only used to provide an interface for establishing Bluetooth connections.


text:
Batteries and amps in parralel
So, i am about to buy a brushless motor a ESC and a 18650 batteries for my arduino.
The batteries "specs" is 3.7v and 20a, if i would to put 2 and more in parallel would i get 7.4v 20a or 7.4v 40a?
Thanks.

This has nothing to do with Arduino.

where would i then post it?

The electronics stackexchange. Also what is that battery specification? 3.7V is the loaded battery voltage, but 20A? Maximum continuously deliverable current?

In parallel you'd get 3.7V 40A
What I think you mean is in series. That way you get 7.4V 20A.

Series connection of battery adds voltage not current but parallel connection keeps the voltage same. Current may be increased with some condition.  One things should be remembered 20 a current is huge it is not required by arduino. May be for some welding device it needs that current which can be controlled by high current mosfet


text:
Due timer update
I want to test a BPM counter as a part of larger project rewriting code for a groovesizer synth. In essence i want to read a pot for updating BPM tempo, and then have a LED blink that tempo, displaying BPM value on an LCD screen.
I am using the DueTimer library. The code for reading pot value, LED blinking and showing the BPM value in an LCD display works fine. However, i am stuck figuring out how to update the ISR timer frequency continously. I can only have the LED blink in the tempo value initialized in setup().
I tried adding the Timer1.setPeriod() to the function reading pot value, to no effect:
pot[4] = (analogRead(i) >> 2) + 30 ; // we use >> 2 to reduce the range from 0 - 1023 to 0 - 255 and add 30 for bpm value
bpm = pot[4];
Timer1.setPeriod(60000000 / bpm / 2);

Putting the same Timer1.setPeriod(bpm) in the main loop didn't work either:
void loop() {
checkSwitches(); // gets the current state of the buttons - defined in BUTTONS
getPots(); // update the pot values - defined in POTS
Timer1.setPeriod(60000000 / bpm / 2);
updateDisplay();
}

Not sure where to go from here. (I'm a total beginner in case it isn't obvious).

Do you maybe have to stop the timer peripheral to be able to update it? Can you call Timer1.stop()  and replace your Timer1.setPeriod call with Timer1.start(60000000 / bpm / 2)?

Good idea! Tried it, but nothing changed...

I think that each time you go through loop(), the Timer1.setPeriod() calls Timer1.setFrequency() and re-initializes the timer.  Does loop() happen more often than 1/285th of a second?

@DaveX so essentially, the problem could be that the timer is constantly reinitialized within the loop function? Then i suppose a solution would be to keep the timer clock constant and recalculate bpm in a separate function counting microseconds?

Can you try to maybe create a global variable int oldBpm;, and only do a TImer1.setPeriod() with a oldBpm = bpm; if oldBpm != bpm? (i.e. only update timer period if new BPM value is different from current one)

Given the slow time scale, you could just handle the timing in software, with either millis() or micros(). You could then very easily update the frequency in a phase-continuous manner.

@EdgarBonet Thanks a lot, you're right. I believe i was overcomplicating things! It's working as intended now.


text:
Optimal and Safe Water Pump Control
I'm using an Arduino Micro, a 12 V water pump, and a print relay to water a plant.
A water level switch monitors the the water tank to make sure the water pump does not run dry.
I tried different watering times and figured that when using longer watering times of 90,000 milliseconds and longer, the relay sometimes does not switch correctly and the pumps keeps running. I'm not sure if my code is optimal for that kind of purpose:
const int Power_Water = 3; // Pin to turn the Pump On and Off via relay
const int Watering_Time = 90000; // Time the water's supposed to run
const int Water_Tank = 10; // Water Level Switch

void setup() {
  Serial.begin(9600);
  pinMode(Power_Water,OUTPUT); // Pin that triggers the Relay as Output
  pinMode (Water_Tank,INPUT_PULLUP); // Pin of Water_Level Sensor as internal pullup
}

void loop () {
  unsigned long watering_Start = millis();

  while (millis() - watering_Start <= Watering_Time && (digitalRead (Water_Tank) == LOW)) {
    digitalWrite(Power_Water,HIGH); // Water Pump goes ON
    Serial.println(millis() - watering_Start);
  }

  if (millis() - watering_Start > Watering_Time || (digitalRead (Water_Tank) == HIGH)) {
    Serial.println("Pump OFF");
    digitalWrite(Power_Water,LOW);// Water Pump OFF
   }
   delay(100000000); // example "sleep" time the system is not supposed to water
}

Any suggestions are appreciated.
I changed
const int Power_Water = 3; // Pin to turn the Pump On and Off via relay
const long Watering_Time = 90000; // Time the water's supposed to run
const long Water_Tank = 10; // Water Level Switch

void setup() {
  Serial.begin(9600);
  pinMode(Power_Water,OUTPUT); // Pin that triggers the Relay as Output
  pinMode (Water_Tank,INPUT_PULLUP); // Pin of Water_Level Sensor as internal pullup
}

void loop () {
  unsigned long watering_Start = millis();
  digitalWrite(Power_Water,HIGH);
  while (digitalRead(Power_Water) == HIGH) {
    Serial.println(millis() - watering_Start);
    if (millis() - watering_Start > Watering_Time || (digitalRead (Water_Tank) == HIGH)) {
      Serial.println("Pump OFF");
      digitalWrite(Power_Water,LOW);
    }
  }
  delay(100000000); // example "sleep" time the system is not supposed to water
}

you defined  watering_time as an integer .... read this .... https://www.arduino.cc/reference/en/language/variables/data-types/int/  ........ then read this
... https://www.arduino.cc/reference/en/language/variables/data-types/long/

use unsigned long Watering_Time. maximum value for signed int is 32,767

That delay statement totally defeats the purposes of your millis code.  If you want to enforce a minimum off time then you'll have to do that with millis as well.  Using millis in this way requires that you allow the loop function to repeat many thousands of times per second.  As written you only allow the loop function to run through once every eleven and a half days.

thanks for the input... .. thats an example and here I want the code to repeat every  100000000 ms but when the pump starts I want to monitor it with millis.. the watering part is the important part for me.. I think I found the right code for my needs and added it to my question

The right code for you will not have any use of the delay function.  Using the delay function is breaking your use of millis.  Using millis requires that the loop be free to run.  You can't use blocking calls like delay at the same time you are using millis for timing and expect anything to work out.


text:
Running dual Adafruit GPS at 10Hz on a Teensy 3.2
Excuse the crudity of this question but I'm having quite the trouble trying to run the two Adafruit Ultimate GPS v3 modules at 10Hz on the Teensy 3.2 board. The modules are connected over the hardware serial ports 1 and 3. There is also an IMU (MPU6050) connected over the I2C interface.

Aim:
-To determine the difference between the course over ground and the body attitude (yaw) of a vehicle
Issues:
-By default, the GPS modules only run at 1Hz and at 9600 baud. I'm sending the required PMTK commands over their respective serial ports
  1 and 3 to increase those to 10Hz and 115200 baud. I'm using hardware
  serial because the SoftwareSerial library was messing up the
  interrupts for the I2C interface and wasn't reliable at the baud rate
  required for 10Hz.
-When using the TinyGPS++ library, it seems that the received chars for the GPS 1 and 2 modules were the same, which led me to believe
  that it wasn't behaving correctly, and I was getting no fixes. Since I
  also need to run a Kalman filter for each GPS module at 10Hz (which
  might not work at that speed on the Teensy), I switched to the NeoGPS
  library, which I'm told, requires much less system resources and is
  much faster.
-The NeoGPS library also does not return any successful fix messages due to possibly being misconfigured (I'm using the default
  configuration files)
Below is the code I'm using with the TinyGPS++ library (sans the IMU
  parts)
With this, I'm only getting stars (*), and the same number of received
  characters for both GPS 1 and 2, hence my assumption that it is
  faulty;

#include <TinyGPS++.h>

    static const uint32_t GPSBaud = 115200;

    // The TinyGPS++ object
    TinyGPSPlus gps;

    void setup()
    {
      // The serial connection to the GPS device
      #define GPS_1_Serial Serial1
      #define GPS_2_Serial Serial3
      GPS_1_Serial.begin(9600);
      GPS_1_Serial.write("$PMTK220,100*2F\r\n");
     //switch the GPS baud rate to 115200
      GPS_1_Serial.write("$PMTK251,115200*27\r\n");
     //change baud rate of serial port to 38400
      GPS_1_Serial.flush();
      delay(10);
      GPS_1_Serial.end();

      GPS_2_Serial.begin(9600);
      GPS_2_Serial.write("$PMTK220,100*2F\r\n");
     //switch the GPS baud rate to 115200
      GPS_2_Serial.write("$PMTK251,115200*27\r\n");
     //change baud rate of serial port to 38400
      GPS_2_Serial.flush();
      delay(10);
      GPS_2_Serial.end();

      Serial.begin(115200);

      while (!Serial);
      Serial.println(TinyGPSPlus::libraryVersion());
      Serial.println();
      Serial.println(F("   Fix  Date       Time     Date    Course Speed Card  Chars Sentences Checksum"));
      Serial.println(F("   Age                      Age     --- from GPS ----  RX    RX        Fail"));
      Serial.println(F("----------------------------------------------------------------------------------------------------------------------------------------"));

    }

    void loop()
    {
      static const double LONDON_LAT = 51.508131, LONDON_LON = -0.128002;
    //GPS________________________________________________________GPS_1___________________________________________________________________
      GPS_1_Serial.begin(GPSBaud);
      Serial.println("Listening to GPS_1");

      printDateTime(gps.date, gps.time);

      printFloat(gps.course.deg(), gps.course.isValid(), 7, 2);
      printFloat(gps.speed.kmph(), gps.speed.isValid(), 6, 2);
      printStr(gps.course.isValid() ? TinyGPSPlus::cardinal(gps.course.deg()) : "*** ", 6);

      printInt(gps.charsProcessed(), true, 6);
      printInt(gps.sentencesWithFix(), true, 10);
      printInt(gps.failedChecksum(), true, 9);
      Serial.println();

      if (millis() > 5000 && gps.charsProcessed() < 10)
        Serial.println(F("No GPS data received: check wiring"));
      smartDelay(100);
      GPS_1_Serial.end();
    // ---------------------------------GPS_2----------------------------

      GPS_2_Serial.begin(GPSBaud);

      Serial.println("Listening to GPS_2");

      printDateTime1(gps.date, gps.time);

      printFloat1(gps.course.deg(), gps.course.isValid(), 7, 2);
      printFloat1(gps.speed.kmph(), gps.speed.isValid(), 6, 2);
      printStr1(gps.course.isValid() ? TinyGPSPlus::cardinal(gps.course.deg()) : "*** ", 6);

      printInt1(gps.charsProcessed(), true, 6);
      printInt1(gps.sentencesWithFix(), true, 10);
      printInt1(gps.failedChecksum(), true, 9);
      Serial.println();

      if (millis() > 5000 && gps.charsProcessed() < 10)
        Serial.println(F("No GPS data received: check wiring"));

      smartDelay1(100);
      GPS_2_Serial.end();

    }

    // This custom version of delay() ensures that the gps object
    // is being "fed".
    static void smartDelay(unsigned long ms)
    {
      unsigned long start = millis();
      do
      {
        while (GPS_1_Serial.available())
          gps.encode(GPS_1_Serial.read());
      } while (millis() - start < ms);
    }

    static void smartDelay1(unsigned long ms)
    {
      unsigned long start = millis();
      do
      {
        while (GPS_2_Serial.available())
          gps.encode(GPS_2_Serial.read());

      } while (millis() - start < ms);
    }

    static void printFloat(float val, bool valid, int len, int prec)
    {
      if (!valid)
      {
        while (len-- > 1)
          Serial.print('*');
        Serial.print(' ');
      }
      else
      {
        Serial.print(val, prec);
        int vi = abs((int)val);
        int flen = prec + (val < 0.0 ? 2 : 1); // . and -
        flen += vi >= 1000 ? 4 : vi >= 100 ? 3 : vi >= 10 ? 2 : 1;
        for (int i=flen; i<len; ++i)
          Serial.print(' ');
      }
      smartDelay(0);
    }

    static void printFloat1(float val, bool valid, int len, int prec)
    {
      if (!valid)
      {
        while (len-- > 1)
          Serial.print('*');
        Serial.print(' ');
      }
      else
      {
        Serial.print(val, prec);
        int vi = abs((int)val);
        int flen = prec + (val < 0.0 ? 2 : 1); // . and -
        flen += vi >= 1000 ? 4 : vi >= 100 ? 3 : vi >= 10 ? 2 : 1;
        for (int i=flen; i<len; ++i)
          Serial.print(' ');
      }
      smartDelay1(0);
    }

    static void printInt(unsigned long val, bool valid, int len)
    {
      char sz[32] = "*****************";
      if (valid)
        sprintf(sz, "%ld", val);
      sz[len] = 0;
      for (int i=strlen(sz); i<len; ++i)
        sz[i] = ' ';
      if (len > 0)
        sz[len-1] = ' ';
      Serial.print(sz);
      smartDelay(0);
    }

    static void printInt1(unsigned long val, bool valid, int len)
    {
      char sz[32] = "*****************";
      if (valid)
        sprintf(sz, "%ld", val);
      sz[len] = 0;
      for (int i=strlen(sz); i<len; ++i)
        sz[i] = ' ';
      if (len > 0)
        sz[len-1] = ' ';
      Serial.print(sz);
      smartDelay1(0);
    }

    static void printDateTime(TinyGPSDate &d, TinyGPSTime &t)
    {
      if (!d.isValid())
      {
        Serial.print(F("********** "));
      }
      else
      {
        char sz[32];
        sprintf(sz, "%02d/%02d/%02d ", d.month(), d.day(), d.year());
        Serial.print(sz);
      }

      if (!t.isValid())
      {
        Serial.print(F("******** "));
      }
      else
      {
        char sz[32];
        sprintf(sz, "%02d:%02d:%02d ", t.hour(), t.minute(), t.second());
        Serial.print(sz);
      }

      printInt(d.age(), d.isValid(), 5);
      smartDelay(0);
    }

    static void printDateTime1(TinyGPSDate &d, TinyGPSTime &t)
    {
      if (!d.isValid())
      {
        Serial.print(F("********** "));
      }
      else
      {
        char sz[32];
        sprintf(sz, "%02d/%02d/%02d ", d.month(), d.day(), d.year());
        Serial.print(sz);
      }

      if (!t.isValid())
      {
        Serial.print(F("******** "));
      }
      else
      {
        char sz[32];
        sprintf(sz, "%02d:%02d:%02d ", t.hour(), t.minute(), t.second());
        Serial.print(sz);
      }

      printInt(d.age(), d.isValid(), 5);
      smartDelay1(0);
    }

    static void printStr(const char *str, int len)
    {
      int slen = strlen(str);
      for (int i=0; i<len; ++i)
        Serial.print(i<slen ? str[i] : ' ');
      smartDelay(0);
    }

    static void printStr1(const char *str, int len)
    {
      int slen = strlen(str);
      for (int i=0; i<len; ++i)
        Serial.print(i<slen ? str[i] : ' ');
      smartDelay1(0);
    }

This is the NeoGPS library version I've attempted, which does not
  output any indication that it is working successfully;

#include <NMEAGPS.h>

static const uint32_t GPSBaud = 115200;

// NMEAGPS object
NMEAGPS gps;

void setup()
{

  // The serial connection to the GPS device
  #define GPS_1_Serial Serial1
  #define GPS_2_Serial Serial3
  GPS_1_Serial.begin(9600);
  GPS_1_Serial.write("$PMTK220,100*2F\r\n");
 //switch the GPS baud rate to 115200
  GPS_1_Serial.write("$PMTK251,115200*27\r\n");
 //change baud rate of serial port to 38400
  GPS_1_Serial.flush();
  delay(10);
  GPS_1_Serial.end();
  GPS_1_Serial.begin(GPSBaud);

  GPS_2_Serial.begin(9600);
  GPS_2_Serial.write("$PMTK220,100*2F\r\n");
 //switch the GPS baud rate to 115200
  GPS_2_Serial.write("$PMTK251,115200*27\r\n");
 //change baud rate of serial port to 38400
  GPS_2_Serial.flush();
  delay(10);
  GPS_2_Serial.end();
  GPS_2_Serial.begin(GPSBaud);

  Serial.begin(115200);

  while (!Serial);
  Serial.println();
  //Serial.println(F("  Time     Date    Course Speed Card  Chars Sentences Checksum"));
  //Serial.println(F(""));
  Serial.println(F("----------------------------------------------------------------------------------------------------------------------------------------"));

}

void loop()
{

//GPS________________________________________________________GPS_1___________________________________________________________________

  Serial.println("Listening to GPS_1");
  while (gps.available(GPS_1_Serial)) {
    gps_fix fix_1 = gps.read();
    if (fix_1.valid.location){
      Serial.println("Successful Location");
    }
    if (fix_1.valid.time) {
      Serial.println("Successful Time");

    }
  }

  Serial.println();

// ---------------------------------GPS_2----------------------------

  Serial.println("Listening to GPS_2");
  while (gps.available(GPS_2_Serial)) {
    gps_fix fix_2 = gps.read();
    if (fix_2.valid.location){
      Serial.println("Successful Location");
    }
    if (fix_2.valid.time) {
      Serial.println("Successful Time");

    }
  }

}

I'm still a beginner when it comes to programming with an Arduino, and I appreciate any assistance to get on the right track.
Thank you for reading
Yours faithfully,
Cem Huray

were you successful in running one gps module?

why are you switching the baud rate?

I was able to run both modules at 1Hz at 9600 baud, I need to change the baud rate to ensure that there is no data loss at 10Hz

You just need two instances of the parser, too:
NMEAGPS gps_1, gps_2;

       ...

//___________________GPS_1______________________

  //Serial.println("Listening to GPS_1");  <-- don't print too much!
  while (gps_1.available(GPS_1_Serial)) {
    gps_fix fix_1 = gps_1.read();
          ...

//___________________GPS_2______________________

  //Serial.println("Listening to GPS_2");  <-- don't print too much!
  while (gps_2.available(GPS_2_Serial)) {
    gps_fix fix_2 = gps_2.read();
          ...

Also answered on the Arduino forum here.

Wow, thank you so much, sorry I couldn't reply, I'm trying to smooth some stuff out, but brilliant library I must say

@C.Huray, Thanks!  If this solves your problem, click on the green triangle next to my answer to "accept" it.  Otherwise, your question lingers on, haunting us forever.... ;)

What is processing_style in NMEAGPS ? My understanding is there is a PS_POLLING style that may not work well with two GPSes and PS_INTERRUPT, that I'm not sure can handle Teensy well.
Have you tried to read directly from the Serial without any library ? When it's working, you can try to plug the library back (or parse the strings from GPS, which is quite easy).

No problem for the NeoGPS INTERRUPT processing style: just make sure the separate ISRs call the separate gps1.handle(c) or gps2.handle(c).


text:
limit switch and external interrupt
The INT0 pin of a custom Arduino-like board based on Atmega16 is configured in INPUT_PULLUP mode and connected to a N.O contact of a limit switch, the other end of the switch is connected to GND.
in the main loop an ac motor is activated each hour, and stops when hitting the limit switch:
void loop()
{
.....
.....
if((millis() - lastT) >= ONE_HOUR) {
    GICR &= 0xBF;  //disable INT0 interrupt
    digitalWrite(MOTOR_PIN, HIGH);
    lastT = millis();
  }
delay(5000); //time for motor to quit the limit switch
GICR |= 0x40;  //enable INT0 interrupt
.....
.....
}//end of main loop

disabling the INT0 for few seconds allow the time to the motor to release the limit switch because this motor has unpredictable direction of rotation... then the INT0 is re-enabled waiting for the limit switch to be hitted and the ISR to be excuted as INT0 pin becomes Low:
ISR(INT0_vect){
  digitalWrite(MOTOR_PIN, LOW);
  GICR &= 0xBF;  //disable INT0 interrupt
}

the INT0 is disabled to allow the next cycle of the motor after one hour...
the problem is that the motor stops sometimes in the middle before hitting the limit switch and sometimes it continue turning after hitting the limit switch... and the majority of times it work as expected...
I do not understand the reason for this behavior... and what are the elements to check...
EDIT: the full code
#define LIMIT_SWITCH     2       // pd2 (INT0)
#define HEATER_PIN      29       // pc7
#define MOTOR_PIN       27       // pc5

#define  ONE_HOUR (1*60*60*1000)

Si7021 sensor = Si7021();

unsigned long lastT;

float tmp , Setpoint;

void setup()
{
  Serial.begin(9600);
  Setpoint = 37;
  lastT = millis();
  pinMode(MOTOR_PIN, OUTPUT);
  pinMode(LIMIT_SWITCH, INPUT_PULLUP);
  GICR|=0x40;                        // enable INT0 interrupt
  MCUCR=0;
}

ISR(INT0_vect){
  digitalWrite(MOTOR_PIN, LOW);
  GICR &= 0xBF;                      // disable INT0 interrupt
}

void loop()
{
  tmp = sensor.readTemperature();
  if(tmp>Setpoint + 0.5) digitalWrite(HEATER_PIN, LOW);
  if(tmp<Setpoint - 0.5) digitalWrite(HEATER_PIN, HIGH);
  Serial.println(tmp);

  if((millis() - lastT)>=ONE_HOUR) {
    GICR &= 0xBF;                    // disable INT0 interrupt
    digitalWrite(MOTOR_PIN, HIGH);
    lastT = millis();
  }

  delay(5000);                       // time for motor to quit the limit switch
  GICR |= 0x40;                      // enable INT0 interrupt
}

A race condition? Please post a Minimal, Complete, and Verifiable example

How is the direction of the motor unpredictable?

@chrisl: excuse my late response... it's a microwave turntable ac motor... unpredictable means that it starts turning in a random direction...

I think that the issue comes from the internal pull-up resistor wich i think is insufficient... I connect a 5.5kOhm resistor between INT0 pin and Vcc and until this time everything is OK...


text:
Arduino Micro interference between analog inputs
I'm building a MIDI controller with the Arduino Micro, hooking a bunch of knobs up to the analog inputs. Currently, I'm getting analog in 9 being influenced by analog in 10: analogRead(9) returns a number close to analogRead(10) and doesn't give the voltage that I'm reading with a multimeter.
What could be causing this interference?

I looked around for a while and eventually thought to put the multimeter probe on the top pin instead of on the soldered header, and got no voltage across it.
If you're experiencing a strange interference between two analog inputs, double-check your solder joints again, one of your inputs might be floating (not connected to high or ground).


text:
Atmel atmega32u4 not recognized when connected by usb after attempting to flash new bootloader
I am making a mechanical keyboard using Atmel's pro micro as the controller.  I decided I would try to replace it's bootloader, as the one it ships with doesn't seem compatible with QMK's RESET keycode (which is supposed to put the controller into DFU mode).
Clearly I didn't know what I was doing, as the controller no longer seems to be recognized when I plug it in via USB - MicroUSB.
If I recall correctly, this is the command I used to attempt to flash the bootloader:
"sudo avrdude -p atmega32u4 -P /dev/ttyACM0 -c avr109 -U flash:w:Caterina-promicro16.hex"
At this time, it seems likely to me that the issue is that I over-wrote the bootloader (or some portion of it) and failed to replace it with an appropriate alternative.  Is this correct?  Is there any way to correct my error through a USB-MicroUSB connection at this point, or will I need to buy some sort of programmer?  All the leds light up.

sometimes the USB freaks out and gives up, try rebooting the PC.

You cannot load the bootloader over USB, that job needs to be done with an in-serial-programmer (ISP).  You could have stopped the board working if you wrote the wrong fuses, e.g. different clock frequency.
Flashing the bootloader via ISP can be done with the Arduino IDE and there are lots of tutorials on the web.  Try it, will probably work for you.


text:
how to use mouse.h library for arduino uno
I want to use mouse.h library with arduino but mouse.h library only for Leonardo not UNO . How to use mouse.h for UNO if not
can we convert arduino UNO to Leonardo ?

The only way to use Mouse.h on an Arduino is to use it on a compatible Arduino. You cannot "convert" an Uno into a Leonardo, since you would have to not only replace the MCU on the board (with one that is SMD only), you would have to replace the PCB itself as well. I.e., throw away the Uno and replace it with a Leonardo.
The Mouse.h (and Keyboard.h) requires an MCU with a built-in USB interface, such as the ATMega32U4 that the Leonardo has. The ATMega328p does not have such an interface (note: the "U" in the name kind of gives it away...).
However, all is not lost.  The Uno does have a chip on it with a "U" in the name (as long as it's a genuine Arduino board and not a cheap Chinese clone with a CH340G chip).  That chip, used to interface the ATMega328p to the PC through USB, can be reprogrammed to look like different devices, however doing so can break your ability to then program the Arduino itself.
You can read more about hacking your Arduino to be a mouse here.


text:
4 consecutive bytes in buffer to unsigned long
I wonder if there's a smarter way to get these 4 consecutive bytes from a buffer, concatenated in a unsigned long.
// the timestamp starts at byte 40 of the received packet and is four bytes,
// or two words, long. First, extract the two words:

unsigned long highWord = word(packetBuffer[40], packetBuffer[41]);
unsigned long lowWord = word(packetBuffer[42], packetBuffer[43]);
// combine the four bytes (two words) into a long integer
// this is NTP time (seconds since Jan 1 1900):
unsigned long secsSince1900 = highWord << 16 | lowWord;
Serial.print("Seconds since Jan 1 1900 = ");
Serial.println(secsSince1900);

Seems overkill to me, thinking these 4 bytes are already consecutive in the buffer.
Result should be unchanged i.e. having the value in a variable.

It depends if they are in the same endian order (i.e., little-endian) as the Arduino's long type. Judging by your current method they aren't.

I ended up doing this:
unsigned long ntp_time = 0;
for (byte i = 0; i < 4; i++){
  ntp_time = ntp_time << 8 | (byte) packetBuffer[40 + i];
}

This is what I would have used on a high level language and my first attempt before asking — which failed because it lacked casting to byte.
I still have to understand why it failed, being packetBuffer declared as
const byte *packetBuffer

which to me seems addressing bytes already...
Thanks to Majenko for help, his solution still cast all buffer bytes to 4 bytes, I prefer mine that keeps down to bytes.

The cast to byte is useless. If it failed without the cast, that must be because of some unrelated issue that you fixed around the same time you added the cast. That's the kind of situation when version tracking software can help.

If they were in the same endian order as a long (little-endian on an Arduino, which they don't appear to be) you could just point to them:
uint32_t *l = (uint32_t *)&packetBuffer[40];

Then use *l to access the content as a long.
However since they look to be in a big-endian order it's not that simple. The simplest thing you can do is just re-combine them with bit-shifting:
uint32_t l = ((uint32_t)packetBuffer[40] << 24) | ((uint32_t)packetBuffer[41] << 16) |
             ((uint32_t)packetBuffer[42] << 8) | (uint32_t)packetBuffer[43];

If I add the last line of your code then do Serial.println(secsSince1900, HEX); Serial.println(secsSince1900, HEX); I get DEAAC142 and FFFFC142. Any clue?

Actually, on a little 8-bitter you may need to cast the values to 32 bit before bitshifting to prevent clipping. Been a while since I used little chips like these.

Indeed. If both int and the type of packetBuffer[40] are less than 32 bits, then packetBuffer[40] << 24 invokes undefined behavior.

Thanks for your answers, you helped me finding what was wrong in my code.

An alternative is to use union and struct, and let the compiler do the work:
static inline uint32_t bswap32(uint32_t x)
{
        union {
                uint32_t x;
                struct {
                        uint8_t a;
                        uint8_t b;
                        uint8_t c;
                        uint8_t d;
                } s;
        } in, out;
        in.x = x;
        out.s.a = in.s.d;
        out.s.b = in.s.c;
        out.s.c = in.s.b;
        out.s.d = in.s.a;
        return out.x;
}

uint32_t sinceEpoch = bswap32(*(uint32_t*) &packetBuffer[40]);

Ref. http://lists.nongnu.org/archive/html/avr-gcc-list/2006-12/msg00076.html
A cleaner rewrite for the packet buffer would be:
static inline uint32_t bswap32(uint8_t* buf)
{
        union {
                uint32_t x;
                struct {
                        uint8_t a;
                        uint8_t b;
                        uint8_t c;
                        uint8_t d;
                } s;
        } in, out;
        out.s.a = buf[3];
        out.s.b = buf[2];
        out.s.c = buf[1];
        out.s.d = buf[0];
        return out.x;
}

uint32_t sinceEpoch = bswap32(&packetBuffer[40]);

Here is an AVR machine code version:
inline uint32_t bswap32(uint32_t value)
{
  asm volatile("mov __tmp_reg__, %A0"   "\n\t"
           "mov %A0, %D0"       "\n\t"
           "mov %D0, __tmp_reg__"   "\n\t"
           "mov __tmp_reg__, %B0"   "\n\t"
           "mov %B0, %C0"       "\n\t"
           "mov %C0, __tmp_reg__"   "\n\t"
           : "=r" (value)
           : "0" (value)
           );
  return (value);
}

Ref. Cosa/Types.h, https://github.com/mikaelpatel/Cosa/blob/master/cores/cosa/Cosa/Types.h#L553, and Cosa-NTP/NTP.cpp, https://github.com/mikaelpatel/Cosa-NTP/blob/master/NTP.cpp#L56


text:
How to program a Arduino Nano(Bricked) with a working arduino nano
I corrupted my bootloader on one arduino, luckily I had a spare lying around. Please help as there is not a single tutorial to help my exact state

not a single tutorial to help my exact state .... yes there are tutorials about using an Arduino as an ISP

read somewhere to use a capacitor to hold the reset to high state, in some tutorials, not used

Arduino as ISP and Arduino Bootloaders - https://www.arduino.cc/en/Tutorial/ArduinoISP

I have a page about programming a bootloader using another Arduino.
Basically you grab the code from here and then make up wiring from the good device (which you put the sketch onto) to the device to be programmed, like this:
Arduino Nano        Target Nano

D10 (SS)            Reset
D11 (MOSI)          D11
D12 (MISO)          D12
D13 (SCK)           D13

Gnd                 Gnd
+5V                 +5V