Can't set Serial config?

Hi. I've made a IR receiver and transmitter and I'm using the UART to send the data. This is working great, but if the distance between the two is more than a couple of meters, I start getting some bit errors. I thought it would be a good idea to add a parity bit to my packages, but I can't seem to compile if I try to do this. Check out the explanation of Serial.begin: Serial.begin() - Arduino Reference. It says "Serial.begin(speed, config)" where valid config parameters are SERIAL_5N1, SERIAL_6N1 etc. Typing "Serial.begin(1200, SERIAL_8E1);" Does not work, why is that?

Typing "Serial.begin(1200, SERIAL_8E1);" Does not work, why is that?

What does "Does not work" mean? Are your fingers having issues typing that statement? Does the compiler not like it? Does it compile, link, and upload, but not have the desired effect at run time?

If it's the latter, how do you know?

I said that it did not compile, it says "SERIAL_8N2" was not declared in this scope.

This test program:

void setup ()
  {
  Serial.begin(1200, SERIAL_8E1);
  }
void loop () {}

Gives:

sketch_jun17a.cpp: In function 'void setup()':
sketch_jun17a:2: error: 'SERIAL_8E1' was not declared in this scope

IDE 1.0, compiled for Uno.

According to the linked page:

speed: in bits per second (baud) - long
config: sets data, parity, and stop bits. Valid values are :
SERIAL_5N1
...
SERIAL_8E1

So there seems to be a problem.

I said that it did not compile

No, you didn't.

it says "SERIAL_8N2" was not declared in this scope.

Why would it say anything about 8N2 if you typed 8E1?

Post your code AND the EXACT error messages.

Also, what version of the IDE are you using?

I thought it would be a good idea to add a parity bit to my packages, but I can't seem to compile if I try to do this.

Code:

void setup() {
  Serial.begin(1200, SERIAL_8E1);

}

void loop() {
  
}

Error message:

BareMinimum.cpp: In function 'void setup()':
BareMinimum:1: error: 'SERIAL_8E1' was not declared in this scope

Compiles OK under 1.0.4 of the IDE.

Also 1.0.2. Looks like a bug in older versions.

Using that code on 1.0.5, for a Mega:

Binary sketch size: 3,272 bytes (of a 258,048 byte maximum)

Compiles for a Uno, too.

Plecto:
I thought it would be a good idea to add a parity bit to my packages ...

I'm not sure how much, if at all, the libraries detect parity errors. Might be safer to use some sort of CRC check.

eg.

Updating the arduino software did the trick :smiley: I think I could have done that without making a forum threat, sorry :stuck_out_tongue:

CRC check means that I have a couple of bits at the beginning of the packages that are constant, like an address? If these bits aren't correct, it discards the data? I was thinking about this also, but I thought it would be fun to try parity bit also to see what effects it has (I'm pretty new to serial communication).

CRC check means that I have a couple of bits at the beginning of the packages that are constant, like an address? If these bits aren't correct, it discards the data?

Not exactly. Better read my page, and also Google "CRC check".

Building in parity bits is only of any use if the receiving end interprets them, and even then, what does it do if parity is wrong?

For example, if you send "12345" and two bytes have bad parity, eg, "12x4x" what do you do then? Discard the lot? Discarding the individual bytes is hardly helpful because then you receive "124" which is not exactly what you sent.

Plecto:
(I'm pretty new to serial communication).

Better read this too, then:

I read a little bit about CRC, not enough to fully understand the concept, but I think I get the basic idea. I decided to add a three bit "address" to my packages (I need a way to distinguish between the three bytes that I'm sending anyway) and this made a decent difference. I'm getting a few bit errors at about four meters distance. I will add another IR led as well as up the LED current a little bit, I think this will make sure that there are no bit errors as 4-5 meters (it will probably not be used further than 3 meters away anyway).