{"id":627,"date":"2013-11-18T21:23:20","date_gmt":"2013-11-18T21:23:20","guid":{"rendered":"http:\/\/ava.upuaut.net\/?p=627"},"modified":"2013-11-18T21:23:20","modified_gmt":"2013-11-18T21:23:20","slug":"getting-started-with-the-ntx2b-and-the-arduino-part-2-rtty","status":"publish","type":"post","link":"https:\/\/ava.upuaut.net\/?p=627","title":{"rendered":"Getting started with the NTX2B and the Arduino &#8211; Part 2 RTTY"},"content":{"rendered":"<p>In part 1 of this article I discussed linking the NTX2B to the Arduino and getting a high and low tone out of it. In this article we go one step further and turn this into a transmission of data.<\/p>\n<p>Using the circuit discussed in the previous article upload the following code will transmit a short sentence at 50 baud, 7 bits ASCII 2 stop bits. Also the code adds a CRC checksum at the end of the data string.<\/p>\n<p>The datastring variable is passed to a procedure called rtty_txtstring which takes care of transmitting the data by breaking it down into characters, then it transmits the individual bits of those characters. The key to getting the baud rate correct is the timing. Theoretically 50 baud should be 1\/50th of a second = 20000\u00b5S however the Arduino delayMicroseconds command can only do a maximum delay of 16383\u00b5S. To get round this we do two delays of 10000\u00b5S.<\/p>\n<p>300 baud after some playing seemed to be stable around 3370\u00b5S delay ( 300 baud should be 1\/300s = 3333\u00b5S). You can uncomment the relevant lines out as needed.<\/p>\n<pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\r\n\r\n\/*\r\nDemo Code to Drive NTX2B via PWM\r\n\r\n Written by Anthony Stirk M0UPU\r\n RTTY code from Rob Harrison Icarus Project.\r\n http:\/\/ukhas.org.uk\r\n This example code is in the public domain.\r\n *\/\r\n\r\n#define RADIOPIN 9\r\n\r\n#include &lt;string.h&gt;\r\n#include &lt;util\/crc16.h&gt;\r\n\r\nchar datastring&#x5B;80];\r\n\r\nvoid setup() {\r\n pinMode(RADIOPIN,OUTPUT);\r\n setPwmFrequency(RADIOPIN, 1);\r\n}\r\n\r\nvoid loop() {\r\n snprintf(datastring,80,&quot;RTTY TEST BEACON RTTY TEST BEACON&quot;); \/\/ Puts the text in the datastring\r\n unsigned int CHECKSUM = gps_CRC16_checksum(datastring); \/\/ Calculates the checksum for this datastring\r\n char checksum_str&#x5B;6];\r\n sprintf(checksum_str, &quot;*%04X\\n&quot;, CHECKSUM);\r\n strcat(datastring,checksum_str);\r\n rtty_txstring (datastring);\r\n}\r\n\r\nvoid rtty_txstring (char * string)\r\n{\r\n\r\n\/* Simple function to sent a char at a time to\r\n ** rtty_txbyte function.\r\n ** NB Each char is one byte (8 Bits)\r\n *\/\r\n\r\nchar c;\r\n\r\nc = *string++;\r\n\r\nwhile ( c != '&#92;&#48;')\r\n {\r\n rtty_txbyte (c);\r\n c = *string++;\r\n }\r\n}\r\nvoid rtty_txbyte (char c)\r\n{\r\n \/* Simple function to sent each bit of a char to\r\n ** rtty_txbit function.\r\n ** NB The bits are sent Least Significant Bit first\r\n **\r\n ** All chars should be preceded with a 0 and\r\n ** proceded with a 1. 0 = Start bit; 1 = Stop bit\r\n **\r\n *\/\r\n\r\nint i;\r\n\r\nrtty_txbit (0); \/\/ Start bit\r\n\r\n\/\/ Send bits for for char LSB first\r\n\r\nfor (i=0;i&lt;7;i++) \/\/ Change this here 7 or 8 for ASCII-7 \/ ASCII-8\r\n {\r\n if (c &amp; 1) rtty_txbit(1);\r\n\r\nelse rtty_txbit(0);\r\n\r\nc = c &gt;&gt; 1;\r\n\r\n}\r\n\r\nrtty_txbit (1); \/\/ Stop bit\r\n rtty_txbit (1); \/\/ Stop bit\r\n}\r\n\r\nvoid rtty_txbit (int bit)\r\n{\r\n if (bit)\r\n {\r\n \/\/ high\r\n analogWrite(RADIOPIN,110);\r\n }\r\n else\r\n {\r\n \/\/ low\r\n analogWrite(RADIOPIN,100);\r\n\r\n}\r\n\r\n\/\/ delayMicroseconds(3370); \/\/ 300 baud\r\n delayMicroseconds(10000); \/\/ For 50 Baud uncomment this and the line below.\r\n delayMicroseconds(10150); \/\/ You can't do 20150 it just doesn't work as the\r\n \/\/ largest value that will produce an accurate delay is 16383\r\n \/\/ See : http:\/\/arduino.cc\/en\/Reference\/DelayMicroseconds\r\n\r\n}\r\n\r\nuint16_t gps_CRC16_checksum (char *string)\r\n{\r\n size_t i;\r\n uint16_t crc;\r\n uint8_t c;\r\n\r\ncrc = 0xFFFF;\r\n\r\n\/\/ Calculate checksum ignoring the first two $s\r\n for (i = 2; i &lt; strlen(string); i++)\r\n {\r\n c = string&#x5B;i];\r\n crc = _crc_xmodem_update (crc, c);\r\n }\r\n\r\nreturn crc;\r\n}\r\n\r\nvoid setPwmFrequency(int pin, int divisor) {\r\n byte mode;\r\n if(pin == 5 || pin == 6 || pin == 9 || pin == 10) {\r\n switch(divisor) {\r\n case 1:\r\n mode = 0x01;\r\n break;\r\n case 8:\r\n mode = 0x02;\r\n break;\r\n case 64:\r\n mode = 0x03;\r\n break;\r\n case 256:\r\n mode = 0x04;\r\n break;\r\n case 1024:\r\n mode = 0x05;\r\n break;\r\n default:\r\n return;\r\n }\r\n if(pin == 5 || pin == 6) {\r\n TCCR0B = TCCR0B &amp; 0b11111000 | mode;\r\n }\r\n else {\r\n TCCR1B = TCCR1B &amp; 0b11111000 | mode;\r\n }\r\n }\r\n else if(pin == 3 || pin == 11) {\r\n switch(divisor) {\r\n case 1:\r\n mode = 0x01;\r\n break;\r\n case 8:\r\n mode = 0x02;\r\n break;\r\n case 32:\r\n mode = 0x03;\r\n break;\r\n case 64:\r\n mode = 0x04;\r\n break;\r\n case 128:\r\n mode = 0x05;\r\n break;\r\n case 256:\r\n mode = 0x06;\r\n break;\r\n case 1024:\r\n mode = 0x7;\r\n break;\r\n default:\r\n return;\r\n }\r\n TCCR2B = TCCR2B &amp; 0b11111000 | mode;\r\n }\r\n}\r\n\r\n<\/pre>\n<p>Load this up and you should hear the distinctive warble of RTTY coming out of your radio. Route this audio into DL-FLDIGI and you should see the bars in the center of the waterfall like this :<\/p>\n<p><a href=\"http:\/\/ava.upuaut.net\/wp-content\/uploads\/2013\/11\/ntx2b-6.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-630\" alt=\"ntx2b-6\" src=\"\/\/ava.upuaut.net\/wp-content\/uploads\/2013\/11\/ntx2b-6.jpg\" width=\"1016\" height=\"431\" srcset=\"https:\/\/ava.upuaut.net\/wp-content\/uploads\/2013\/11\/ntx2b-6.jpg 1016w, https:\/\/ava.upuaut.net\/wp-content\/uploads\/2013\/11\/ntx2b-6-300x127.jpg 300w\" sizes=\"auto, (max-width: 1016px) 100vw, 1016px\" \/><\/a><br \/>\nIn DL-FLDIGI click Op Mode -&gt; RTTY -&gt;Custom.<br \/>\nSet carrier shift to 425, baud to 50, 7 bits per character, no parity and 2 stop bits. If everything is ok you should see DL-FLDIGI decoding the RTTY.<\/p>\n<p>Part 3 discusses using a similar method transmit DominoEX.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In part 1 of this article I discussed linking the NTX2B to the Arduino and getting a high and low tone out of it. In this article we go one step further and turn this into a transmission of data. &hellip;<\/p>\n<p class=\"read-more\"><a href=\"https:\/\/ava.upuaut.net\/?p=627\">Read more &raquo;<\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-627","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/ava.upuaut.net\/index.php?rest_route=\/wp\/v2\/posts\/627","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ava.upuaut.net\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ava.upuaut.net\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ava.upuaut.net\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/ava.upuaut.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=627"}],"version-history":[{"count":3,"href":"https:\/\/ava.upuaut.net\/index.php?rest_route=\/wp\/v2\/posts\/627\/revisions"}],"predecessor-version":[{"id":631,"href":"https:\/\/ava.upuaut.net\/index.php?rest_route=\/wp\/v2\/posts\/627\/revisions\/631"}],"wp:attachment":[{"href":"https:\/\/ava.upuaut.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=627"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ava.upuaut.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=627"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ava.upuaut.net\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=627"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}