[Radio] RTTY

This is RTTY (Radioteletype) code that you can use for your C++ application (for instance Arduino). This can be used for the transfer of information through radio (or optics, see below). I have used this for the Space Camera projects (see top menu). So you can use RTTY to give yourself an easy and robust method for transmitting information over the radio. You can use ‘free’ frequencies (Generally 433 MHz, limited to max 10mW power output). If you have a radio-license (like i have) you can use more power and more frequencies.

The code below is tuned to 50baud (transfer speed of 50 bit/s). You understand: this is a very slow communication, about 7 characters per second. Also, it uses 7bit ascii, you can also set it to 8 bit ascii (bit slower but more characters). Also i have the code for baudot (5bit) which is really fast, but with some restrictions. You can find that code here.

Tell me how it works

Easy: a “low beep” is a binary 0, a “high beep” a binary 1. Then if you emit every 0.02 seconds either one of these beeps, you can make up a data string in a “ASCII” way. For instance: “1010100” is the character “T”. Repeating this same method you can make any data transmission you want.

(For more (historic) information see wikipedia)

How i have used this before

The beeps you are hearing (brrrzzz brzzzz) is actually the “RTTY” as i receive it from a radio receiver. Then i put that in the audiojack of my computer, which analyzes the sound and converts the beeps into bits and then into readable characters! That way i knew GPS information of the autonomous balloon.

Also cool: Optic RTTY

This uses the same code as for the radio, but the medium now is not radio waves, but light. You could use light of different wavelengths to separate the data that is transmitted.

Code

So you can either hook up two leds or a radio to the two corresponding pins. For hooking up a radio you can check this page.

  1.  
  2. // Project Hollands Hoogte © July 2010
  3. // RTTY (original i believe by J. Coxon)
  4.  
  5. // Digital Pins
  6. #define RTTY_PIN_1 		5	// RTTY space pin
  7. #define RTTY_PIN_2 		6	// RTTY mark pin
  8. #define RTTY_LED                30      // RTTY busy led
  9.  
  10. // Misc
  11. #define RTTY_ASCII      7       // ASCII set for RTTY (7/8bit)
  12.  
  13. void setup() {
  14.  
  15.  
  16.   Serial.begin(9600);
  17.  
  18.   pinMode(RTTY_LED, OUTPUT);
  19.  
  20.   // Setup for RTTY
  21.   pinMode(RTTY_PIN_1, OUTPUT);
  22.   pinMode(RTTY_PIN_2, OUTPUT);
  23.  
  24. }
  25.  
  26. void loop() {
  27.         TxString("abcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*()");
  28. }
  29.  
  30.  
  31.  
  32. // Calculates the checksum for a given string
  33. // returns as integer
  34. int getCheckSum(char *string) {
  35.   int i;
  36.   int XOR;
  37.   int c;
  38.   // Calculate checksum ignoring any $'s in the string
  39.   for (XOR = 0, i = 0; i < strlen(string); i++) {
  40.     c = (unsigned char)string[i];
  41.     if (c == '*') break;
  42.     if (c != '$') XOR ^= c;
  43.   }
  44.   return XOR;
  45. }
  46.  
  47.  
  48. // ------ RTTY ----------
  49.  
  50. // Transmit a string, log it to SD & produce debug output
  51. void TxString(char *string) {
  52.   digitalWrite(RTTY_LED, HIGH);
  53.  
  54.   // Checksum
  55.   char txSum[4];
  56.   int checkSum = getCheckSum(string);
  57.   sprintf(txSum, "%02X", checkSum);
  58.  
  59.  
  60.  
  61.   rtty_txstring(string);
  62.   rtty_txstring("*");
  63.   rtty_txstring(txSum);
  64.   rtty_txstring("rn");
  65.   digitalWrite(RTTY_LED, LOW);
  66. }
  67.  
  68. // Transmit a string, one char at a time
  69. void rtty_txstring (char *string) {
  70.   for (int i = 0; i < strlen(string); i++) {
  71.     rtty_txbyte(string[i]);
  72.   }
  73. }
  74.  
  75. // Transmit a byte, bit by bit, LSB first
  76. // ASCII_BIT can be either 7bit or 8bit
  77. void rtty_txbyte (char c) {
  78.   int i;
  79.   // Start bit
  80.   rtty_txbit (0);
  81.   // Send bits for for char LSB first
  82.   for (i=0;i<rtty_ASCII;i++) {
  83.     if (c & 1) rtty_txbit(1);
  84.     else rtty_txbit(0);
  85.     c = c >> 1;
  86.   }
  87.   // Stop bit
  88.   rtty_txbit (1);
  89. }
  90.  
  91. // Transmit a bit as a mark or space
  92. void rtty_txbit (int bit) {
  93.   if (bit) {
  94.     // High - mark
  95.     digitalWrite(RTTY_PIN_1, HIGH);
  96.     digitalWrite(RTTY_PIN_2, LOW);
  97.   }
  98.   else {
  99.     // Low - space
  100.     digitalWrite(RTTY_PIN_2, HIGH);
  101.     digitalWrite(RTTY_PIN_1, LOW);
  102.   }
  103.   // Delay, not tuned to 50baud, but you can tune this
  104.   delay(19);
  105.   delayMicroseconds(250);
  106. }

Tim Zaman

MSc Biorobotics. Specialization in computer vision and deep learning. Works at NVIDIA.

You may also like...