Skip to main content
8 votes
Accepted

Sending serial data in an interrupt

You cannot use Serial inside an interrupt. Transmitting Serial relies on interrupts being available, and from inside an interrupt they aren't. All Serial communication must be done from loop(). So ...
Majenko's user avatar
  • 105k
6 votes
Accepted

Read serial with header and end marker

The short answer to your question is “yes, there is a way”. Multiple ways actually. You could write a blocking function, which follows more or less the logic of the example you show, blocking while ...
Edgar Bonet's user avatar
  • 43.1k
5 votes

getting error 'Serial' was not declared in this scope

I learned that I needed to include Arduino.h header file apart from that I learned .ino files and .cpp files is that the .ino files transparently include particle.h for you. The other difference is ...
Ciasto piekarz's user avatar
5 votes
Accepted

How to send multiple data over serial in one byte?

You should learn how to use bitwise operators. These are needed to do what you want. We can save the state of each switch in one bit each. For this we first define our global variable that will hold ...
chrisl's user avatar
  • 16.3k
5 votes
Accepted

My Atlas Scientific sensors measurement give zero values at first reading

Each time you call receive_reading() you pass it one sensor to read the value from. But each time you call receive_reading() you print out all three sensors. So you: Read EC and print EC PC TEMP Read ...
Majenko's user avatar
  • 105k
4 votes
Accepted

Arduino reading value from external devices on

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 ...
Maximilian Gerhardt's user avatar
4 votes

How do I import data from serial monitor to excel document without copying and pasting?

The Arduino IDE's serial monitor is just one of many tools that can open a serial port and collect information from it. The first step is to make sure the data you are writing to the Serial object in ...
jose can u c's user avatar
  • 6,974
4 votes
Accepted

Serial.availableForWrite versus Serial.flush

The line while (Serial.availableForWrite() <= 0) {} waits until the serial output buffer is not full. Whereas Serial.flush(); waits until the serial output buffer is empty.
Edgar Bonet's user avatar
  • 43.1k
4 votes
Accepted

which is the best way to declare Serial while creating Arduino library?

As regards the use of Stream: I usually use Stream instead of HardwareSerial because: It allows the use of other serial devices, like SoftwareSerial or USBSerial that aren't "Hardware" ...
Majenko's user avatar
  • 105k
4 votes

String() vs char for simple flow control

Using Serial.readString() will make your program very slow. This is because readString() does not know when to stop reading. When the serial input buffer gets empty, it will wait just in case more ...
Edgar Bonet's user avatar
  • 43.1k
4 votes
Accepted

How to ignore garbage values in serial communication between arduino and python

The effect that you see is type promotion, in the C++ standard called "integral promotion", which happens implicitly. Values of type char are cast to int. Commonly, and in your case too, the ...
the busybee's user avatar
  • 2,002
4 votes
Accepted

Why I always see while(serial.available() > 0) as the standard way of reading serial data?

what guarantees that the incoming bytes are being pushed into the queue faster than the consuming process? Nothing. In the code handling the transmitted data you need to account for that. The fact, ...
chrisl's user avatar
  • 16.3k
3 votes
Accepted

Is it possible to use Serial window for debug statements while using the hardware serial port for GPS module?

Is it possible to print the debug statements in the Serial window while the GPS module is connected to the hardware serial ports? Yes, that works. If you connect the Arduino TX pin 1 to the GPS RX, ...
slash-dev's user avatar
  • 2,029
3 votes

Arduino Bluetooth communication is slowing down because of the 'for' loop!

Your chief problem is that FastLED turns off interrupts when sending the data. It does that because timing is critical, and with interrupts turned on that timing will get completely messed up. So ...
Majenko's user avatar
  • 105k
3 votes

Getting issues while using SoftwareSerial

SoftwareSerial only works on a few select GPIO pins on the Mega. Specifically those pins that have PCINT on them. But that is irrelevant. There is no reason to use SoftwareSerial on a Mega except in ...
Majenko's user avatar
  • 105k
3 votes
Accepted

Purpose of LED indicator

If you do not configure the pins, they are initialized as pinMode(xx,INPUT) which is a floating high impedance state. Per the Arduino Uno R3 schematic, that pin is on PB5/SCK/13 which is run through ...
Dave X's user avatar
  • 2,332
3 votes

Will an Arduino Nano work instead of Teensy 3.2?

No, you can't use Adruino Nano, because in this project the Teensy board has been used as an USB Keayboard and Nano has separate communication chip (FTDI or CH430) that can't emulate USB keyboard. ...
KIIV's user avatar
  • 4,752
2 votes
Accepted

How to call 5 different functions in a loop based on serial input?

This answer isn't going to give you the code to solve your problem, it is just ideas that you can look at and see what suits you best. You should be able to find an example on how to read from a ...
Code Gorilla's user avatar
  • 5,637
2 votes

How to call more than 10 different functions based on serial input?

First, you could use a string for the commands. You just need to ensure there is some special char to mark the end of a command - like the newline char. Read the input from the port one char at a time,...
001's user avatar
  • 953
2 votes

Receiving hex data from terminal

First, you have to understand what “hex” means. Basically, you are representing binary data as text, where each byte is represented as two characters. For example, the number 42 is represented as ...
Edgar Bonet's user avatar
  • 43.1k
2 votes

What causes Serial.available() to become false after Serial.read() gets data?

It is an internal buffer and only the pointer gets increased. It it visible in the source code off the project, located on github: // Read data from buffer int SoftwareSerial::read() { if (!...
Stefan M's user avatar
  • 141
2 votes

Help with Serial.print()

Serial.print() feeds the data into the TX buffer one character at a time (through the Print class's inherited .write() function which HardwareSerial implements). If there isn't enough room in the TX ...
Majenko's user avatar
  • 105k
2 votes

Broken serial connection corrupting Arduino values

You could consider writing/reading the value to/from the EEPROM. http://arduino.cc/en/Reference/EEPROM This allows the board to be reset, or even turned off, and retain the value previously set. What ...
computercarguy's user avatar
2 votes
Accepted

Read one value from continuous data stream at a lower frequency

You're thinking backwards. You don't want to read slower (which is what delay does), you want to only send every 10th entry. That is, count the lines as they come in. When you hit 10 you print one ...
Majenko's user avatar
  • 105k
2 votes

Question on how "f" value is calculated in converting Morse Code to laser audio from this tutorial

This is not a good tutorial. The receiver works by assuming 14 dotLen time periods for each character. There is a loop that runs 14 times, with a 200ms delay between each iteration. If the laser is ...
jose can u c's user avatar
  • 6,974
2 votes

Method to iterate over the bits in a byte sent over serial

In all the examples below, value is the value of the byte LSB -> MSB - so 00001111 would turn ON the first 4 devices and turn OFF the last 4 for(int i = 0, mask = 1; i < 8; i++, mask = mask <&...
Jaromanda X's user avatar
2 votes

How to parse multi line serial data with an unknown number of lines?

This is an overly broad question which borders "write me the code" - this isn't a coding service - and if anything belongs on StackOverflow since it regards processing. That being said, this question ...
RamblinRose's user avatar
2 votes

Fast data logging

Read the values into an array big enough to store them Write the array with the write(const uint8_t *buffer, size_t size) method. Each write then gives you a block of binary data (512 values, 1024 ...
Majenko's user avatar
  • 105k

Only top scored, non community-wiki answers of a minimum length are eligible