<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>text messages from Pi to Arduino Archives - Nerd Corner</title>
	<atom:link href="https://nerd-corner.com/tag/text-messages-from-pi-to-arduino/feed/" rel="self" type="application/rss+xml" />
	<link>https://nerd-corner.com/tag/text-messages-from-pi-to-arduino/</link>
	<description>Craft your dreams!</description>
	<lastBuildDate>Wed, 08 Sep 2021 19:45:47 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.8.2</generator>

<image>
	<url>https://nerd-corner.com/wp-content/uploads/2019/10/cropped-LogoNerdCorner-2-32x32.png</url>
	<title>text messages from Pi to Arduino Archives - Nerd Corner</title>
	<link>https://nerd-corner.com/tag/text-messages-from-pi-to-arduino/</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>Sending text messages with visible light communication or LiFi &#8211; Pi to Arduino</title>
		<link>https://nerd-corner.com/sending-text-messages-with-visible-light-communication/</link>
					<comments>https://nerd-corner.com/sending-text-messages-with-visible-light-communication/#comments</comments>
		
		<dc:creator><![CDATA[Nerds]]></dc:creator>
		<pubDate>Sun, 20 Jun 2021 23:31:03 +0000</pubDate>
				<category><![CDATA[Arduino projects]]></category>
		<category><![CDATA[Hardware]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[cyclic redundancy check]]></category>
		<category><![CDATA[data transfer]]></category>
		<category><![CDATA[data transfer with light]]></category>
		<category><![CDATA[LiFi]]></category>
		<category><![CDATA[LiFi Arduino project]]></category>
		<category><![CDATA[LiFI Router]]></category>
		<category><![CDATA[Light Fidelity]]></category>
		<category><![CDATA[text messages]]></category>
		<category><![CDATA[text messages from Pi to Arduino]]></category>
		<category><![CDATA[visible Light communication]]></category>
		<category><![CDATA[visible light communication project]]></category>
		<category><![CDATA[VLC]]></category>
		<category><![CDATA[VLC Arduino project]]></category>
		<category><![CDATA[VLC Raspberry Pi project]]></category>
		<guid isPermaLink="false">https://nerd-corner.com/de/?p=962</guid>

					<description><![CDATA[<p>I like the idea of sending data via visible light. In general, Li-Fi (Light Fidelity) and VLC (Visible Light Communication) are heavily discussed at the &#8230; </p>
<p>The post <a href="https://nerd-corner.com/sending-text-messages-with-visible-light-communication/">Sending text messages with visible light communication or LiFi &#8211; Pi to Arduino</a> appeared first on <a href="https://nerd-corner.com">Nerd Corner</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>I like the idea of sending data via visible light. In general, Li-Fi (Light Fidelity) and VLC (Visible Light Communication) are heavily discussed at the moment. VLC is a visible light communication, which means it is primarily a cable replacement, while LiFi is a similarity to WiFi. A LiFi device would be a kind of Internet-enabled router that transmits data via light signals instead of radio frequency signals. Currently, however, no company has developed or is selling a Li-Fi router. VLC technology is used prominently at the moment by Elon Musk&#8217;s StarLink project. This allows satellites to exchange data using laser beams. I have replicated that in a simplified way in this blog article.</p>
<p>At first, I only want to transmit individual text messages in one direction. In a next step this can then be extended to transmit whole files bidirectionally. To receive the messages, I chose an Ardunio, because unlike the Raspberry Pi, it has analog inputs and can thus be easily connected to analog sensors. For sending, a Raspberry Pi is suitable, since only digital pins are needed here and a Pi can generally transmit data more efficiently and faster. This has already been tested in the previous posts about defining a clock frequency for the Arduino and the Raspberry Pi. All scripts to run the VLC communication can be downloaded at the end of the article. The following three blogposts are directly related to this project:</p>
<p><span style="color: #ff0000;"><strong>===&gt; UPGRADE: </strong></span><em><a href="https://nerd-corner.com/upgrade-data-transfer-via-vlc-and-lifi-pi-to-pi-transfer/" target="_blank" rel="noopener">SENDING ALL KINDS OF DATA WITH VISIBLE LIGHT COMMUNICATION</a></em></p>
<p><em><strong>How to program the clock frequency of the Arduino:</strong> <a href="https://nerd-corner.com/arduino-timer-interrupts-how-to-program-arduino-registers/">Use timer interrupts as clock frequency.</a></em></p>
<p><em><strong>How to program the clock frequency of the Pi:</strong> <a href="https://nerd-corner.com/how-to-program-a-highly-precise-timer-in-c-for-linux/">Precise timer function in C for the Pi.</a></em></p>
<p><em><strong>How to prevent errors in data transmission:</strong> <a href="https://nerd-corner.com/cyclic-redundancy-check-in-c-code/">Using CRC to detect corrupted packets.</a></em></p>
<h2>List of components</h2>
<ul>
<li>Arduino Uno</li>
<li>Raspberry Pi</li>
<li>5V Solarcell</li>
<li>5V Laserdiode</li>
<li>Jumper cables</li>
</ul>
<h2>Wiring for the visible light communication</h2>
<p><img fetchpriority="high" decoding="async" class="zoooom aligncenter wp-image-939" src="https://nerd-corner.com/wp-content/uploads/2021/06/FritzingPi_Arduino.png" alt="Textnachrichten VLC Fritzing Verkabelung für Visuelle Lichtkommunikation" width="2770" height="1130" srcset="https://nerd-corner.com/wp-content/uploads/2021/06/FritzingPi_Arduino.png 2772w, https://nerd-corner.com/wp-content/uploads/2021/06/FritzingPi_Arduino-300x122.png 300w, https://nerd-corner.com/wp-content/uploads/2021/06/FritzingPi_Arduino-1024x418.png 1024w, https://nerd-corner.com/wp-content/uploads/2021/06/FritzingPi_Arduino-768x313.png 768w, https://nerd-corner.com/wp-content/uploads/2021/06/FritzingPi_Arduino-1536x627.png 1536w, https://nerd-corner.com/wp-content/uploads/2021/06/FritzingPi_Arduino-2048x836.png 2048w" sizes="(max-width: 2770px) 100vw, 2770px" /></p>
<p>The wiring is rather simple. The 5V solar cell is very well suited to detect light signals. Therefore the solar cell is connected to the receiver, which is the Arduino. The ground of the solar cell is connected to a ground of the Arduino. The positive line of the solar cell is connected to an analog pin of the Arduino. Here, for example, A0 is suitable.</p>
<p>From the Raspberry Pi the messages are transmitted to the Arduino via light signals of the laser. For this, the ground of a 5V laser diode is connected to a ground pin of the Pi (see graphic). Then the positive line of the laser diode is connected to one of the digital pins of the Raspberry Pi. Here I chose the GPIO17 pin, which corresponds to pin 0 in the &#8220;wiringPi&#8221; library (see graphic).</p>
<p><img decoding="async" class="aligncenter wp-image-940 zoooom" src="https://nerd-corner.com/wp-content/uploads/2021/06/pinbelegung-Pi.png" alt="VLC Textnachrichten visuelle Lichtkommunikation wiringPi" width="598" height="294" srcset="https://nerd-corner.com/wp-content/uploads/2021/06/pinbelegung-Pi.png 600w, https://nerd-corner.com/wp-content/uploads/2021/06/pinbelegung-Pi-300x148.png 300w" sizes="(max-width: 598px) 100vw, 598px" /></p>
<p>As an alternative to the laser and the solar cell combination, an LED and a photoresistor can also be used. However, a laser is better suited for faster and more precise data transmission. In addition, a solar cell offers a large area to detect the laser beams.</p>
<h2>Modulationtechnique On-Off-Keying</h2>
<p>The text messages are transmitted in binary code as &#8220;1&#8221; or &#8220;0&#8221;. There are different ways to modulate this data. One of the simplest possibilities is to set an identical clock frequency for the transmitter and receiver. Then either a &#8220;1&#8221; or a &#8220;0&#8221; is transmitted in each clock pulse.</p>
<p>The procedure is called aplitude shift keying. If the laser diode illuminates the solar plate particularly strongly, this is detected by the receiver as a binary &#8220;1&#8221;. If the laser diode shines only weakly, it will be detected as binary &#8220;0&#8221;.</p>
<p>In fact it makes sense not to let the laser diode shine at all for a binary &#8220;0&#8221;. This is called On-Off keying. This is a simplification of amplitude shift keying. The following graphic illustrates the difference between amplitude shift keying and on-off keying.</p>
<p><img decoding="async" class="aligncenter wp-image-942 zoooom" src="https://nerd-corner.com/wp-content/uploads/2021/06/OOK-ASK-1.jpg" alt="Modulationstechnik Visuelle Lichtkommunikation" width="848" height="587" srcset="https://nerd-corner.com/wp-content/uploads/2021/06/OOK-ASK-1.jpg 850w, https://nerd-corner.com/wp-content/uploads/2021/06/OOK-ASK-1-300x208.jpg 300w, https://nerd-corner.com/wp-content/uploads/2021/06/OOK-ASK-1-768x531.jpg 768w" sizes="(max-width: 848px) 100vw, 848px" /></p>
<p>That means, whenever the solar cell detects light, a corresponding voltage value is passed to the analog pin of the Arduino. If this voltage value exceeds a predefined value, the Arduino registers it as a binary &#8220;1&#8221;, otherwise as a binary &#8220;0&#8221;. It makes sense to adjust the predefined value to the daylight. Possibly with the help of an additional light sensor.</p>
<h2>Arduino code to receive messages</h2>
<pre class="EnlighterJSRAW" data-enlighter-language="c" data-enlighter-group="Receiver" data-enlighter-title="Receiver.ino" data-enlighter-theme="beyond">//This is the "real" loop function
  switch (state)
  {
    case 0:
      //looking for synchronization sequence
      synchro_Done=false;
      lookForSynchro(data);

      if (synchro_Done== true)
      {
        state=1;
      }
      break;
    case 1:
      //receive Data
      receiveData_Done =false;
      receiveData(data);

      if (receiveData_Done==true)
      {
        state=0; 
      }
      break;
  }</pre>
<p>The software of the Arduino is basically built as a state machine. There are two states. One state for synchronization and one for reading the text message. In the state synchronization the receiver waits for a fixed bit sequence (preamble) for example &#8220;101010101111111111&#8221;. This sequence means that the receiver must listen now because a text message follows. The complete Arduino code can be downloaded at the end of the article. The following graphic shows the exact structure of the data packets.</p>
<p><img loading="lazy" decoding="async" class="aligncenter wp-image-943 zoooom" src="https://nerd-corner.com/wp-content/uploads/2021/06/FrameVariableDataLength.jpg" alt="Aufbau Textnachrichten VLC" width="953" height="554" srcset="https://nerd-corner.com/wp-content/uploads/2021/06/FrameVariableDataLength.jpg 955w, https://nerd-corner.com/wp-content/uploads/2021/06/FrameVariableDataLength-300x174.jpg 300w, https://nerd-corner.com/wp-content/uploads/2021/06/FrameVariableDataLength-768x446.jpg 768w" sizes="auto, (max-width: 953px) 100vw, 953px" /></p>
<p>As soon as the preamble is recognized, the receiver automatically switches to the second state and receives the actual message. However, the first 16 bits of the text message correspond to a decimal number, which tells the receiver how many characters the incoming text message contains. When this number is reached, the text is printed in the Serial Monitor of the Arduino and the state changes back again. Now the synchronization sequence is awaited again. The complete software code can be downloaded at the end of the blog article. To improve the transmission quality, a cyclic redundancy check (CRC) can be performed as shown in the following graphic.</p>
<p><img loading="lazy" decoding="async" class="aligncenter wp-image-944 zoooom" src="https://nerd-corner.com/wp-content/uploads/2021/06/FrameVariableDataLengthAndCRC.jpg" alt="CRC Datenpakete Aufbau VLC" width="1264" height="555" srcset="https://nerd-corner.com/wp-content/uploads/2021/06/FrameVariableDataLengthAndCRC.jpg 1266w, https://nerd-corner.com/wp-content/uploads/2021/06/FrameVariableDataLengthAndCRC-300x132.jpg 300w, https://nerd-corner.com/wp-content/uploads/2021/06/FrameVariableDataLengthAndCRC-1024x450.jpg 1024w, https://nerd-corner.com/wp-content/uploads/2021/06/FrameVariableDataLengthAndCRC-768x337.jpg 768w" sizes="auto, (max-width: 1264px) 100vw, 1264px" /></p>
<h2>Raspberry Pi code to send messages</h2>
<pre class="EnlighterJSRAW" data-enlighter-language="c" data-enlighter-group="simpleLaser" data-enlighter-title="simpleLaser.c">//Read message
        char msg[3000]; 
        int len, k, length;
       
        printf("n Enter the Message: ");
        scanf("%[^'n']",msg);
        
        len=strlen(msg);
        
        
        int2bin(len*8, 16); //len*8, because 8 bits are one byte
        
        for(k=0;k&lt;len;k++)
        {
                chartobin(msg[k]);            
        }</pre>
<p>The program code of the Raspberry Pi must be written in C. Python would be too slow and would not achieve a stable clock frequency for sending the data. The complete program code can be downloaded at the end of the article. In order for the Pi to control the laser diode the &#8220;wiringPi.h&#8221; library is needed. With &#8220;digitalWrite(0, HIGH)&#8221; the diode can be switched on and with &#8220;digitalWrite(0, LOW)&#8221; it can be switched off. Important: Please don&#8217;t forget the &#8220;<a href="http://wiringpi.com/" target="_blank" rel="noopener">wiringPi</a>&#8221; library when compiling! The command is: &#8220;gcc -o simpleLaser simpleLaser.c -lwiringPi&#8221;.</p>
<p>At the beginning the program asks for a text message using the printf function. This is read in and stored by a scanf function. Then each letter is converted to binary code and stored in an array. The conversion is shown in the following graphic. At the end, the binary code is transmitted from the array in a fixed clock pulse. The laser diode is switched on for a binary &#8220;1&#8221; and off again for a binary &#8220;0&#8221;.</p>
<p><img loading="lazy" decoding="async" class="aligncenter wp-image-945 zoooom" src="https://nerd-corner.com/wp-content/uploads/2021/06/BinToDec.jpg" alt="Character to binary conversion" width="750" height="389" srcset="https://nerd-corner.com/wp-content/uploads/2021/06/BinToDec.jpg 758w, https://nerd-corner.com/wp-content/uploads/2021/06/BinToDec-300x156.jpg 300w" sizes="auto, (max-width: 750px) 100vw, 750px" /></p>
<h2>Conclusion on the Visible Light Communication for Arduino</h2>
<p>The transmission of text messages by means of visual light communication works excellently. Thanks to the cyclic redundancy check, it is also absolutely error-free. However, the benefit of one-dimensional message communication is rather low. It would be better if any kind of files could be transmitted and that in both directions. An update will probably follow soon.</p>
<p><img loading="lazy" decoding="async" class="zoooom aligncenter wp-image-953" src="https://nerd-corner.com/wp-content/uploads/2021/06/SetUp-Arduino-Pi-scaled.jpg" alt="Set Up VLC Arduino Pi Visuelle Lichtkommunikation" width="2550" height="1913" srcset="https://nerd-corner.com/wp-content/uploads/2021/06/SetUp-Arduino-Pi-scaled.jpg 2560w, https://nerd-corner.com/wp-content/uploads/2021/06/SetUp-Arduino-Pi-300x225.jpg 300w, https://nerd-corner.com/wp-content/uploads/2021/06/SetUp-Arduino-Pi-1024x768.jpg 1024w, https://nerd-corner.com/wp-content/uploads/2021/06/SetUp-Arduino-Pi-768x576.jpg 768w, https://nerd-corner.com/wp-content/uploads/2021/06/SetUp-Arduino-Pi-1536x1152.jpg 1536w, https://nerd-corner.com/wp-content/uploads/2021/06/SetUp-Arduino-Pi-2048x1536.jpg 2048w" sizes="auto, (max-width: 2550px) 100vw, 2550px" /></p>
<h2>Download files</h2>
<ul>
<li><a  data-e-Disable-Page-Transition="true" class="download-link" title="" href="https://nerd-corner.com/download/946/?tmstv=1756338555" rel="nofollow" id="download-link-946" data-redirect="false" >
	Arduino Code VLC to receive text messages</a>
</li>
<li><a  data-e-Disable-Page-Transition="true" class="download-link" title="" href="https://nerd-corner.com/download/949/?tmstv=1756338555" rel="nofollow" id="download-link-949" data-redirect="false" >
	Raspberry Pi code to send text messages with VLC</a>
</li>
</ul>
<p>&nbsp;</p>
<p>The post <a href="https://nerd-corner.com/sending-text-messages-with-visible-light-communication/">Sending text messages with visible light communication or LiFi &#8211; Pi to Arduino</a> appeared first on <a href="https://nerd-corner.com">Nerd Corner</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://nerd-corner.com/sending-text-messages-with-visible-light-communication/feed/</wfw:commentRss>
			<slash:comments>10</slash:comments>
		
		
			</item>
	</channel>
</rss>
