How to write the coding for character encoding for Arduino Uno?

I want to encode text encoding from Arduino A to Arduino B. How should i write the coding? I am the beginner in Arduino project. Spare me. Thanks :blush:

I want to encode text

Why? Encode how? Do you really need to prevent someone from intercepting the text?

Are you talking about encryption, or are you talking about character encoding (unicode, ümlauts, etc)?

If you want encryption, see here.

Maybe have a look at the examples in Serial Input Basics

...R

PaulMurrayCbr:
Are you talking about encryption, or are you talking about character encoding (unicode, ümlauts, etc)?

If you want encryption, see here.

i'm talking about character encoding where there's a limit in sending the message so i need to limit the character encoding that need to be send to the receiver.

PaulS:
Why? Encode how? Do you really need to prevent someone from intercepting the text?

to make it easy, i want to communicate between two Arduino Uno boards by using RF module as the transmitter and receiver, but there's a limitation where the bits that i will be used are 4 bits only. So the characters that want to be send are just 16 characters. So, I want to know, how to do the coding for this project.

I want to communicate between two Arduino Uno boards by using RF module as the transmitter and receiver, but there's a limitation where the bits that i will be used are 4 bits only. So the characters that want to be send are just 16 characters. So, I want to know, how to do the coding for this project.

A Byte has 8 bits in it and it doesn't matter if your data fits in only four or not. You still have to work with 8 bit Bytes.
Since you only Need four bits, you have two Options.
Either you use 8 bits, leaving four of them either at 0 or Setting some of them (which is often done, add 64 to any 4-bit value and you get the characters @ABD...LMNO).
The second Option is a bit more complicated. You can compress two 4 bit values into one 8 bit Byte, transmit it, and decompress it on the other end. Theoretically, you get faster Transmission because you transmit fewer Bytes but the compression/decompression on a relatively slow 16MHz CPU may more than Offset the savings.

JaBa:
the compression/decompression on a relatively slow 16MHz CPU may more than Offset the savings.

Actually if he is using what you suggest, that is shifting the second packet 4 bits into the high part (MSBs) of the first byte, decoding is super fast it's just a binary shift by 4 positions to the right which executes in few cycles in optimized code (load register, LSR 4 times, save register) - with overhead probably Les than 10 cycles which is less than 0,625 micro seconds... If you compare that to 1ms to transfer 1 byte at 9600 bauds you have the time to decode 1600 frames for each byte sent :slight_smile:

Noja:
to make it easy, i want to communicate between two Arduino Uno boards by using RF module as the transmitter and receiver, but there's a limitation where the bits that i will be used are 4 bits only. So the characters that want to be send are just 16 characters. So, I want to know, how to do the coding for this project.

This does not really make sense.

Every system I am aware of sends data as a series of 8-bit bytes.

Please describe what you are trying to achieve in more detail - with some examples of the data and details of the RF modules you are using.

...R

See this other discussion currently in this forum - same type of idea

http://forum.arduino.cc/index.php?topic=408498.0

If you are time sensitive, pack 2 sets of 4 bits into one byte, send and decode the other side
If you are not time bound, just send your 4 bits as part of a byte, you send 4 zeros as part of the byte each time, so it's suboptimal but that's no big deal if time is not really an issue...

Don't double Post. (The link in Reply #7 is for the same OP.)

I will suggest to the Moderator to merge the Threads.

...R

Noja:
I want to encode text encoding from Arduino A to Arduino B. How should i write the coding? I am the beginner in Arduino project. Spare me. Thanks :blush:

I think you should try to formulate what you really want to do, not what you guess you need to do ("encoding"). You are going to send data between two Arduinos? Text data? How and with which constraints?

Encoding can mean many things, depending on context. ASCII is the default binary encoding of text values in the Arduino, which means that every character corresponds to an 8-bit number (a byte). Sending and manipulating text means working with byte values.

:slight_smile: