Skip to main content
Share Your Experience: Take the 2024 Developer Survey
9 votes
Accepted

How to pass 'Serial' as an input argument in Arduino function?

The Serial object is the end of a chain of classes, each with a different set of functionality. Print -> Stream -> HardwareSerial => [Serial] Since you are reading from it the best class to ...
Majenko's user avatar
  • 105k
9 votes
Accepted

Non-blocking SoftwareSerial.Write

In short, you don't. The SoftwareSerial implementation for AVR doesn't have an outbound buffer at all. It just turns the interrupts off during each character outbound and it sends them all immediately....
timemage's user avatar
  • 5,299
7 votes
Accepted

WiFiEsp not working on Software Serial, working fine on Hardware Serial

If you're going to talk to your ESP at 9600 baud - and that's about the upper limit for SoftwareSerial - you need to first change the ESP board's baud rate to 9600 baud. It is probably at 115200 right ...
JRobert's user avatar
  • 15.3k
7 votes
Accepted

Create New Serial Class Inheriting from Stream

The Stream class has pure virtual methods which must be implemented in derived not abstract class. The pure virtual method from base class Print is: virtual size_t write(uint8_t) = 0; The pure ...
Juraj's user avatar
  • 18k
6 votes

How to define a SoftwareSerial object inside a class?

Personally I wouldn't go down this route. Instead I would pass a Stream object (as a pointer or a reference) to the constructor and use that. Then it is up to your sketch to define what that Stream ...
Majenko's user avatar
  • 105k
6 votes
Accepted

Is the a low memory alternative to SoftwareSerial?

Simplest thing would probably be to edit your copy of SoftwareSerial.h and replace #define _SS_MAX_RX_BUFF 64 on line 42 by something smaller. If your loop() runs fast enough (no delays, no blocking ...
Edgar Bonet's user avatar
  • 43.3k
6 votes

How to write a library that support both HW and SW Serial communication and allow user to chose which one to use?

The trick here is to go "up a level". Both HardwareSerial and SoftwareSerial inherit from the Stream class. It is that class that provides the majority of the interface that you actually ...
Majenko's user avatar
  • 105k
6 votes

Printing the array using print and serial write function in Arduino Uno

Serial.write(some_byte) writes a byte on the serial output. The Arduino serial monitor tries to interpret the bytes it receives as text: 0x11 is a control character, displayed as โ€œโ–กโ€ 0x22 is the ...
Edgar Bonet's user avatar
  • 43.3k
6 votes

reading device or board specific properties from the Arduino MKR WiFi 1010 device

The IDE shows the serial number so I looked into the SAMD core and found the function which reads the serial number from registers. It is in the CDC.cpp file uint8_t Serial_::getShortName(char* name) {...
Juraj's user avatar
  • 18k
5 votes

SIM808 module GSM working fine, GPS not working (No GPS ready message on power on)

You have a version2 module. Use AT+CGNSxxx instead of AT+CGPSxxx
user24177's user avatar
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

How to chose softserial library use on Arduino project?

I think your problem is that you need 4 serial ports. With software serial that's just not going to happen: SoftwareSerial can only receive on one serial port at any given time. AltSoftSerial is ...
Majenko's user avatar
  • 105k
5 votes
Accepted

What is the best delay to use between characters sent to the serial port

SoftwareSerial has a considerable overhead. It can often send at 115200 successfully but 9600 is about its limit for receiving, and you're trying both send and receive. In addition, for each character ...
JRobert's user avatar
  • 15.3k
5 votes

What is the best delay to use between characters sent to the serial port

Simply put, a serial port implemented in software requires the program to sample the input pin fast enough to detect every transition. To satisfy the Nyquist frequency rate we need the program to ...
st2000's user avatar
  • 7,338
4 votes
Accepted

How can I reduce the redundancy of this code, so one function can perform the task of printing on Serial and Softserial?

Just send your data to a tee: this is a type of pipe fitting where you push the data through one end and it goes out through the other two ends. As it happens, both Serial and Softserial (and almost ...
Edgar Bonet's user avatar
  • 43.3k
4 votes
Accepted

Arduino char showing as 2 characters

do { r = XBee.read(); Serial.print(r); } while (r != -1); Think about it. Since you tested for XBee.available() you will have at least one iteration of this loop. And then you ...
Nick Gammon's user avatar
  • 38.3k
4 votes
Accepted

Strange binary number representation

print never prints leading zeroes (how many should it print anyway?). print doesn't start a new line - you need println for that So you get your 4 in binary printed twice followed by something else (...
Majenko's user avatar
  • 105k
4 votes

Make Sure \n is the last character in serial string

Since you are using all 8 bits of the serial data for your data there is nothing "in band" that you can use for a delimiter. Instead you will have to think outside the box somewhat and create some ...
Majenko's user avatar
  • 105k
4 votes

Can increasing the size of the software RX buffer cause problem in Arduino Uno

The buffer is in the UNO's limited (2K) RAM; you'd be using 1/4 of it for the input buffer. If your app is small enough and simple enough (limited call depth, specifcally), there may still be enough ...
JRobert's user avatar
  • 15.3k
4 votes

Why does SoftwareSerial::read() return int?

The documentation on Arduino's website shows SoftwareSerial::read() as returning a char. No it doesn't. There is nothing in the documentation that tells you the return type. There is only an example ...
Majenko's user avatar
  • 105k
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.3k
4 votes
Accepted

Converting each digit in an integer to its respective ASCII characters

To convert a whole number to a char array in one go use the itoa function. That sounds like what you actually need. To convert one digit from decimal to ascii just add '0', the ascii value for a 0....
Delta_G's user avatar
  • 3,324
4 votes
Accepted

SoftwareSerial read until available is empty only works with delay

Serial does not transmit data as one bunch, but byte by byte. There can easily be some little delays introduced, especially, when transmitted via a packaged protocol like bluetooth, long enough, for ...
chrisl's user avatar
  • 16.3k
4 votes
Accepted

How to read from and write to rs232 device from/to Arduino

You didn't show how you connected the MAX3232, so I cannot say anything about that. But I can write something about your code and how the data gets received on the PC. On the PC: Here it is important ...
chrisl's user avatar
  • 16.3k
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
3 votes

On UNO, when serial.print to UART pin 11, nothing comes out of pin 11

Of course it's only coming out on the serial monitor - you are printing it to the hardware UART which comes out on the serial monitor. You have created a SoftwareSerial object which you are then ...
Majenko's user avatar
  • 105k
3 votes
Accepted

Arduino Leonardo - Using ICSP pins for serial

From packages/arduino/hardware/avr/1.6.*/variants/leonardo/pins_arduino.h: // Map SPI port to 'new' pins D14..D17 #define PIN_SPI_SS (17) #define PIN_SPI_MOSI (16) #define PIN_SPI_MISO (14) #...
Ignacio Vazquez-Abrams's user avatar
3 votes

Arduino Pro Mini Serial Monitor garbage

I had the same issue. The problem was solved in an other forum: https://forum.arduino.cc/index.php?topic=434623.0 I copy the solution here: It appears that in fact your board is not running at 8MHz, ...
pvoj's user avatar
  • 193
3 votes

Use an Arduino to "intercept" transparently serial communication to Grbl?

I finally solved my problem by buying an Arduino Due! It was a problem of speed, not of code. The Uno is just not powerfull enough to read an write to Software Serial at 115200 Bauds, or even 9600, ...
BernardG's user avatar
  • 175
3 votes

AT command is not responding on serial monitor

The ESP's AT firmware is probably configured for a higher baud rate, 115200 is typical. SoftwareSerial only works reliably up to 9600 baud. It can transmit "reliably enough" at 115200 for you to ...
JRobert's user avatar
  • 15.3k

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