{"id":539,"date":"2014-04-15T03:05:49","date_gmt":"2014-04-15T02:05:49","guid":{"rendered":"http:\/\/phoenixgamedevelopment.com\/blog\/?p=539"},"modified":"2014-04-15T03:07:17","modified_gmt":"2014-04-15T02:07:17","slug":"datavault-concept-example-code","status":"publish","type":"post","link":"https:\/\/phoenixgamedevelopment.com\/blog\/datavault-concept-example-code\/","title":{"rendered":"DataVault Concept: Example Code"},"content":{"rendered":"<p>I\u00a0 have created two programs which transmit a string over a wire, from one arduino to another. The transmitter converts the string into characters, and then converts those into 8 bits, which is sends to the receiver by using digitalWrite().<br \/>\nAn Ascii lookup table is available <a href=\"http:\/\/www.nthelp.com\/ascii.htm\"> here<\/a>.<\/p>\n<p>The hardware for this is a simple wire connecting two arduino microcontrollers (I am using a Due and a Nano), both using pin 13.<\/p>\n<p>This is a concept test, with a very slow transmission speed. The speed can be changed by altering the &#8220;delaytime&#8221; variable.<\/p>\n<p>This setup is the absolute simplest that a serial interface could realistically be. There is no data compression, or or data redundancy, CRC checks, hashes, etc. I have not used any libraries.<\/p>\n<p>The way the code works, is that for each byte:<\/p>\n<p>First, the line is set to low, by sending a stream of 1&#8217;s.<\/p>\n<p>Then a single one is sent, to indicate that a message is on the way. This is neccessary because if the message begins with a 0, the receiver will not be able to differentiate it from the stream of 1&#8217;s.<\/p>\n<p>After this, 8 bits are sent, corresponding to the binary value of an Ascii character.<\/p>\n<p>I have notices that increasing the speed of transmission even a moderate amount results in data corruption. This is the reason why complex algorithms are used when transmitting data. However, if these algorithms were to become obsolete in the future, they data may be impossible to decode.<\/p>\n<p>This system is so simple, that, assuming binary and Ascii formats are still in use in years to come, the data being sent by the transmitter could easily be parsed and understood.<\/p>\n<p>&nbsp;<\/p>\n<p>This is the code for the Transmitter:<\/p>\n<p><code><br \/>\nint SENDpin = 13;<br \/>\nString message = \"DataVault Code Example Concept Test2\";<br \/>\nint delaytime = 100;<\/code><\/p>\n<p>void setup() {<br \/>\npinMode(SENDpin,OUTPUT);<br \/>\nSerial.begin(9600);<br \/>\n}<\/p>\n<p>void sendByte(byte bmsg){<\/p>\n<p>digitalWrite(SENDpin,0); \/\/Set Line Low<br \/>\ndelay(delaytime*10);<\/p>\n<p>digitalWrite(SENDpin,1); \/\/Send Message Indicator<br \/>\ndelay(delaytime);<\/p>\n<p>for(int i = 0; i &lt; 8; i++){ \/\/Send individual bits from byte<br \/>\nif(bitRead(bmsg,i)==1){<br \/>\ndigitalWrite(SENDpin,1);<br \/>\nSerial.print(1);<br \/>\n}<br \/>\nelse{<br \/>\ndigitalWrite(SENDpin,0);<br \/>\nSerial.print(0);<br \/>\n}<br \/>\ndelay(delaytime);<br \/>\n}<br \/>\nSerial.println(&#8220;&#8221;);<br \/>\n}<\/p>\n<p>void loop() {<\/p>\n<p>for(int s = 0; s &lt; message.length();s++){ \/\/read each character from the message string<br \/>\nbyte bmsg = message[s];<br \/>\nsendByte(bmsg);<br \/>\nSerial.println(bmsg);<br \/>\n}<\/p>\n<p>}<\/p>\n<p>&nbsp;<\/p>\n<p>This is the code for the Receiver:<\/p>\n<p><code><br \/>\nint recvpin = 13;<br \/>\nbyte msg = 0;<br \/>\nboolean messagereceived = 0;<br \/>\nint delaytime = 100; \/\/This must be the same on the transmitter and the receiver<\/code><\/p>\n<p>void setup() {<br \/>\npinMode(recvpin, INPUT);<br \/>\nSerial.begin(9600);<br \/>\n}<\/p>\n<p>void loop() {<\/p>\n<p>if(digitalRead(recvpin) == 1){<br \/>\nmessagereceived = 1;<br \/>\nmsg = 0;<br \/>\n}<br \/>\ndelay(delaytime);<\/p>\n<p>if(messagereceived){<br \/>\nfor(int i = 0; i &lt; 8; i++){<br \/>\nboolean val = digitalRead(recvpin); \/\/ read the input pin<br \/>\nbitWrite(msg,(i),val);<br \/>\n\/\/Serial.print(val);<br \/>\ndelay(delaytime);<br \/>\n}<br \/>\nSerial.print((char)msg);<br \/>\n\/\/Serial.println(&#8220;&#8221;);<br \/>\nmessagereceived = 0;<br \/>\n}<br \/>\n}<\/p>\n<p>}<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I\u00a0 have created two programs which transmit a string over a wire, from one arduino to another. The transmitter converts the string into characters, and then converts those into 8 bits, which is sends to the receiver by using digitalWrite(). An Ascii lookup table is available here. The hardware for this is a simple wire [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[6,10],"tags":[],"class_list":["post-539","post","type-post","status-publish","format-standard","hentry","category-inventions","category-software-and-games","has-post-title","has-post-date","has-post-category","has-post-tag","has-post-comment","has-post-author",""],"aioseo_notices":[],"builder_content":"","_links":{"self":[{"href":"https:\/\/phoenixgamedevelopment.com\/blog\/wp-json\/wp\/v2\/posts\/539"}],"collection":[{"href":"https:\/\/phoenixgamedevelopment.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/phoenixgamedevelopment.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/phoenixgamedevelopment.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/phoenixgamedevelopment.com\/blog\/wp-json\/wp\/v2\/comments?post=539"}],"version-history":[{"count":10,"href":"https:\/\/phoenixgamedevelopment.com\/blog\/wp-json\/wp\/v2\/posts\/539\/revisions"}],"predecessor-version":[{"id":549,"href":"https:\/\/phoenixgamedevelopment.com\/blog\/wp-json\/wp\/v2\/posts\/539\/revisions\/549"}],"wp:attachment":[{"href":"https:\/\/phoenixgamedevelopment.com\/blog\/wp-json\/wp\/v2\/media?parent=539"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/phoenixgamedevelopment.com\/blog\/wp-json\/wp\/v2\/categories?post=539"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/phoenixgamedevelopment.com\/blog\/wp-json\/wp\/v2\/tags?post=539"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}