Serial.begin(speed, config) not compiling for Leonardo Board - arduino

I would like to configure my serial communication to have no parity, 1 start- and 2 stop-bits. The documentation for Serial.begin(speed, config) states:
(...) An optional second argument configures the data, parity, and stop bits. The default is 8 data bits, no parity, one stop bit.
The documentation also lists the possible configuration-values. According to my (limited) understanding, I need SERIAL_7N2 or SERIAL_8N2 to meet my requirements. (I'm not sure how the data-bits relate to the the 1-start-bit that I need.)
However, I can't even compile because I have no idea how to supply that configuration value to the begin method. (I don't have much Arduino/C++ experience).
In my code, I've tried the following two variants:
Serial.begin(9600, SERIAL_8N2);
Serial.begin(9600, "SERIAL_8N2");
Am I missing something?
Additional information:
Serial.begin(speed, config) has been introduced with the latest Arduino 1.0.2 IDE version.
The code defining/implementing the begin methods can be found:
HardwareSerial.h
HardwareSerial.cpp
Edit:
According to the replies from PeterJ and borges, the following variant is correct.
Serial.begin(9600, SERIAL_8N2);
However, it's still not working.
I found that the compile error doesn't occur if I change the configured board from my Arduino Leonardo to Arduino Uno.
Therefore, it could be a bug occurring only with a subset of boards ... or maybe it's not supported?!
Edit 2:
It's now solved :) The answer of borges pointed me to the right solution!

You mentioned in a comment: (edit: and now is in the title)
I don't get the compile error if I change the board from my "Arduino Leonardo" to "Arduino Uno".
The Arduino Leonardo has some peculiarities regarding serial communication:
Leonardo has a microcontroller (ATmega32U4) that has native USB communication. To maintain compatibility as the entire ecosystem already established, the Leonardo virtualizes a serial communication over USB. You have access to this communication using Serial in the code. Physically you have access to that communication via the USB plug.
To use the "real" serial communication (AKA serial TTL), you need to use pins 0 (RX) and 1 (TX). In the code you would use Serial1 (notice the number 1!).
An example:
void setup() {
Serial1.begin(9600, SERIAL_8N2);
Serial1.println("Hello?");
}
void loop() {
}
For more information (recommended):
Arduino Leonardo
Guide to the Arduino Leonardo

The first method should be OK, so you have a compiler configuration or include problem. Make sure you have the following include at the top of your file:
#include <HardwareSerial.h>
Also while SERIAL_8N2 is valid it's an odd setting rarely used. You'll most likely want SERIAL_8N1.

Related

How to get Arduino/ESP32 device details in code?

I'm working on a project in which there is a server and several clients (ESP32). In short, It's client-server communication over WIFI. Right now, I'm using ESP32-wroom-32D. In future, for a client device, I might use some other Arduino device or other ESP32 module or a combination of both. For code simplicity, I shall be using the same code for both types of devices (Arduino/ ESP32) as they support a common Arduino platform. Therefore, I want to know if there is a way which I can get the device's information.
Eg.
Function: Get_device_details( ) or Get_device_id( ).
Output: "ESP32-Wroom-32D" or "Arduino Mega 2560"
The Arduino defines to identify a board are in form of ARDUINO_<board>, where <board> is the value from <x>.build.board from boards.txt for board <x>
For example for Arduino AVR boards, in the boards.txt file is uno.build.board=AVR_UNO so the define is ARDUINO_AVR_UNO.
And Arduino has 'architecture' identification define too. This has form of ARDUINO_ARCH_<arch.name>. The <arch.name> is the uppercase version of the folder name with the boards package version. For example AVR for packages/arduino/hardware/avr/1.6.21.
For esp boards, you can use the following arduino code to get chip ID,
#ifdef ESP8266
int chip_id = ESP.getChipId();
#elif defined(ESP32)
int chip_id = ESP.getEfuseMac();
#endif

Arduino RF Receiver picking up some 433MHz signals but not others

I have an Arduino and a 433MHz receiver running the code below, using the RCSwitch Library. The code is working fine when I use a remote like the "BN-LINK ES1513-5-2 Wireless Remote". The bits/signal prints to the window and everyone is happy.
But when I try to pick up the signal from a dog collar(No-Shock) remote 433HMz, I get nothing.
Both remotes say they are transmitting at 433MHz.
I have multiple "BN-LINK ES1513-5-2 Wireless Remote" and I can see signal from these remotes. If i hook up another Arduino with a RF transmitter i can pick up the signal.
Any ideas why I can see signals from some but not the other?
#include <RCSwitch.h>
RCSwitch mySwitch = RCSwitch();
void setup() {
Serial.begin(9600);
mySwitch.enableReceive(0); // Receiver on interrupt 0 => that is pin #2
}
void loop() {
if (mySwitch.available()) {
output(mySwitch.getReceivedValue(), mySwitch.getReceivedBitlength(), mySwitch.getReceivedDelay(), mySwitch.getReceivedRawdata(),mySwitch.getReceivedProtocol());
mySwitch.resetAvailable();
}
}
Transmitting at 433 Mhz is only one part of the infrastructure, the other issue is at what protocol the transmission is done and that would probably be different from a remote control to a dog collar.
In the ReadMe section of the rc-switch library you can find a list of supported chipsets. EV1527 for example is one of the common and can be found on many the low-cost 433Mhz devices including remote controls. You could look for information about that, however, to my opinion, if you are to use a device/chipset/protocol supported by this lib, you should no longer worry about low-level communication.

Is it possible to factory reset an arduino from hardware to remove bad user code?

I was troubleshooting why Serial1 was always throwing undefined errors in sketches I was trying to run when I found a solution posted online for a slightly different board that suggested this line:
HardwareSerial Serial1(2);
I uploaded it and now the Arduino doesn't show up in the IDE, did I remap it's serial communications? Why is this possible!
Is there any hardware factory reset option available on these boards? Did I just brick my device?
edit: It seems the STM32Cube programmer app can be used to communicate with the device but I'm not sure where to get the original firmware to flash. https://imgur.com/a/LbiHenf
Assuming from the tag in your question, I guess you have an STM32 – (BluePill) Development Board (STM32F103C8).
If you think that your board is not handling serial communication properly then you might consider burning bootloader to your board. This will reset the complete configuration of your board.
There are many ways in which you can burn bootloader to your board.
Using another Arduino board like Uno / Nano / Mega
Using an FTDI USB to TTL Serial Adapter.
You might want to go through tutorials list below:
Getting Started with STM32 using Arduino IDE: Blinking LED
Programming STM32F103C8 Board using USB Port

PWM/PPM Output misses some edges

I am using ESP8266 (NODEMCU 3.0 or something) to make a quadcopter. Ive connected ardu pro mini to RC receiver so I am reading PPM values from it. Pro mini sends data with tx to ESP8266. ESP reads it with software serial with 115200 baudrate. I am communicating with MPU9255 (Waveshire) via I2C either.
My problem is that I cant fully controll my brushless motors. When I was using arduino instead of ESP8266, servo library was the best and reliable. But ESP's servo library is different, since its not AVR, and problems occurs. First of the servo library didnt want to work on most frequencies. I mean default is 50Hz (20000uS) and in this state ESC of motors did armed but unfortunatelly when changes was fast and short (1250-> 1370 -> 1250) it did miss that change like nothing happnd... This makes my D value in PID controller useless...
Sometimes on 100Hz freq all was working fine, but sometimes not...
When Ive started to use analogWrite only 500Hz was working fine, rest of freq didnt want to arm ESCs.
PS. I am using 3.3V to 5V converter for PPM/PWM pins so I am sure that the signal is fine for ESCs.
PS2. I dont have any osciloscope unfortunately.
The ESP82266 present on your module is a RF transceiver integrated circuit that can handle WiFi communication, both configured as a slave to a microcontroller such as the ones present on various Arduino boards, or as a standalone chip by having it's on-board Tensilica L106 32-bit processor programmed via an external SPI flash memory. If used as a slave, the communication between, for example, an Arduino an the ESP82266 can be done using different protocols such as SPI / SDIO or I2C / UART interfaces. Googling a comprehensive Tensilica L106 user guide on the internet doesn't seem an easy task, and it looks as if some people have already failed to find it. If you're seeking to add Wi-Fi capabilities to your quadcopter the solution I suggest is having the Arduino take control over the servos, motors, etc. and hand off messages via SPI to your ESP82266 module. If this isn't the answer you are looking for, please try to be clearer about it, maybe find someone to do as an English translator for you.
However, if this is what you're concerned about, and you would like to use the ESP82266 module as as standalone solution, please link its built-in processor datasheet and the relevant parts of the quadcopters code that might need debugging.

The SoftwareSerial Library of Arduino, why it needs PCINT (pin change inturrupt feature.)?

The SoftwareSerial Library of Arduino don't work with clones made of ATMEGA32 as this do not have PCINT feature. How serial communication is linked with PCINT? can the INT pins of ATMEGA32/16 be someway used by the modification of SoftwareSerial.cpp file?
Prior to IDE 1.0.+ the SoftwareSerial used to be a polling of the Rx Pins. This was blockin, requiring constant checking the service of the RX and limited the quality of the baud rate. Since NewSoftSerial replaced the former older Polled SoftwareSerial, using PCint's. Which creates an interrupt on the change of the RX Pin and then checks the time. This is no longer blocking and better emulates the Hardware Serial port, require less (none) servicing (or polling).
One can go back to the older IDE's SoftwareSerial from before 1.+ and attempt to either port it forward or try to use the ATmega32 in the older IDE. I thought I had seen a DEFINE switch somewhere that would allow it to run in polled mode. But I am unable to find it in current releases. Likely did not make it into the released IDE.
Or you can try to find an alternative to SoftwareSerial. Such as tinyserial Where I see that dates back to 2010 and will likely need some updating. Especially on 1.5.8. May have better luck trying it on 1.0.6

Resources