<?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>Raspberry Pi Archives - Nerd Corner</title>
	<atom:link href="https://nerd-corner.com/tag/raspberry-pi-en/feed/" rel="self" type="application/rss+xml" />
	<link>https://nerd-corner.com/tag/raspberry-pi-en/</link>
	<description>Craft your dreams!</description>
	<lastBuildDate>Thu, 29 Jul 2021 10:00:00 +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>Raspberry Pi Archives - Nerd Corner</title>
	<link>https://nerd-corner.com/tag/raspberry-pi-en/</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>Review Battery Shield V3 &#8211; DIY Powerbank with LiPo 18650</title>
		<link>https://nerd-corner.com/review-battery-shield-v3-diy-powerbank-with-lipo-18650/</link>
					<comments>https://nerd-corner.com/review-battery-shield-v3-diy-powerbank-with-lipo-18650/#comments</comments>
		
		<dc:creator><![CDATA[Nerds]]></dc:creator>
		<pubDate>Mon, 26 Jul 2021 19:00:46 +0000</pubDate>
				<category><![CDATA[Arduino projects]]></category>
		<category><![CDATA[Hardware]]></category>
		<category><![CDATA[18650]]></category>
		<category><![CDATA[Akku]]></category>
		<category><![CDATA[Arduino]]></category>
		<category><![CDATA[Battery management system]]></category>
		<category><![CDATA[Battery shield V3]]></category>
		<category><![CDATA[DIY Powerbank]]></category>
		<category><![CDATA[Power Managment]]></category>
		<category><![CDATA[Powerbank]]></category>
		<category><![CDATA[Raspberry Pi]]></category>
		<category><![CDATA[USB]]></category>
		<guid isPermaLink="false">https://nerd-corner.com/de/?p=1044</guid>

					<description><![CDATA[<p>I was looking for a battery with a battery management system for my outdoor projects (weather station, irrigation system, etc.).  While browsing online stores, I &#8230; </p>
<p>The post <a href="https://nerd-corner.com/review-battery-shield-v3-diy-powerbank-with-lipo-18650/">Review Battery Shield V3 &#8211; DIY Powerbank with LiPo 18650</a> appeared first on <a href="https://nerd-corner.com">Nerd Corner</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>I was looking for a battery with a battery management system for my outdoor projects (weather station, irrigation system, etc.).  While browsing online stores, I came across a cheap module for the power supply of my outdoor projects. Normally several components are necessary for an independent power supply (LiPo charger, battery holder, step down, step up, solar panel). However, the &#8220;Battery Shield V3&#8221; takes over most of these tasks. For my use cases (Ardunio + sensors) the provided 5V and 3V outputs are ideal! Here is my review of the Battery Shield V3.</p>
<p><em><strong>This might also be interesting for you:</strong> <a href="https://nerd-corner.com/step-down-modul-dc-dc-lm2596s/" target="_blank" rel="noopener">Development of a step-down module</a></em></p>
<p><img fetchpriority="high" decoding="async" class="aligncenter wp-image-1019" src="https://nerd-corner.com/wp-content/uploads/2021/07/both.jpg" alt="Battery shield v3" width="940" height="534" srcset="https://nerd-corner.com/wp-content/uploads/2021/07/both.jpg 952w, https://nerd-corner.com/wp-content/uploads/2021/07/both-300x170.jpg 300w, https://nerd-corner.com/wp-content/uploads/2021/07/both-768x436.jpg 768w" sizes="(max-width: 940px) 100vw, 940px" /></p>
<h2>List of components:</h2>
<ul>
<li>1x Battery Shield V3</li>
<li>1x LiPo 18650</li>
</ul>
<p><img decoding="async" class="aligncenter wp-image-1023" src="https://nerd-corner.com/wp-content/uploads/2021/07/PowerbankPur.gif" alt="DIY Powerbank LiPo mit BMS" width="345" height="176" /></p>
<h2>Analysis of the Battery Shield V3</h2>
<p>After the Battery Shield V3 arrived, the first thing I had to do was examine its properties in detail.  I thought about the tests beforehand and they were primarily based on my use cases. Since I am of course not a research institute, I kept the tests as simple as possible.</p>
<p><img decoding="async" class="aligncenter wp-image-1025" src="https://nerd-corner.com/wp-content/uploads/2021/07/Test1-scaled.jpg" alt="Battery shield v3 test lipo akku bms" width="2550" height="1436" srcset="https://nerd-corner.com/wp-content/uploads/2021/07/Test1-scaled.jpg 2560w, https://nerd-corner.com/wp-content/uploads/2021/07/Test1-300x169.jpg 300w, https://nerd-corner.com/wp-content/uploads/2021/07/Test1-1024x577.jpg 1024w, https://nerd-corner.com/wp-content/uploads/2021/07/Test1-768x432.jpg 768w, https://nerd-corner.com/wp-content/uploads/2021/07/Test1-1536x865.jpg 1536w, https://nerd-corner.com/wp-content/uploads/2021/07/Test1-2048x1153.jpg 2048w" sizes="(max-width: 2550px) 100vw, 2550px" /></p>
<p>First, I tested the main function, which is charging a LiPo battery. The charging process on the module is indicated by a LED. Red means that the battery is charging and green signifies that charging is complete. Unfortunately, the LEDs are located on the bottom of the module and are therefore not easily visible.</p>
<p>According to the information provided by the manufacturer or the online retailer, the charging voltage is 4.2 V and the charging current is 500 mA. To verify these values, I measured and noted the state of charge of the inserted battery. The state of charge was approximately at 1100 mAh. The total capacity of the battery is 3000 mAh. It appears that the difference between fully charged and partially charged is 1900 mAh. To get the expected charging time, this value is divided by the 500 mA specified by the manufacturer. The calculated charging time is therefore 4 h. A standard power supply with 5V and 1A charging current is used as the power supply. In reality, the duration of charging was 4 h and 15 min. This is close to the theoretical value and thus okay.</p>
<p><strong>Please note:</strong> Never use a brand new LiPo battery for this test, instead use one that already has some charge cycles completed. Otherwise, the result is not very meaningful.</p>
<h3>Voltage testing in the Review Baterry Shield V3</h3>
<p>In the second test, the different voltages provided by the module were examined. I divided this test into two phases. In the first phase (picture test 2_1) the module is used without a LiPo battery. Afterwards in the second phase a LiPo battery is used.</p>
<p>Of course, it is important to choose the right components to make the test as realistic as possible. For the USB-A connection I selected a load resistor with 1 A as well as with 2 A. This ceramic load resistor is ideal because a USB interface is available and the LED lights up green when 5 watts are consumed. At 10 watts the LED lights red.</p>
<p>For the 3 x 5 V outputs, I soldered 5V LED strips to two outputs and the third 5V output has a step-down module LM2596S which I constructed and set to 2V to power a 10 mm RGB Led. 3 V LEDs were soldered to each of the 3 x 3 V outputs. For this test a 5 V (18 Watt) power supply was used.</p>
<h4>The module operating without LiPo battery</h4>
<p><img loading="lazy" decoding="async" class="aligncenter wp-image-1028 zoooom" src="https://nerd-corner.com/wp-content/uploads/2021/07/TEST2_1.jpg" alt="Review: Battery Shield V3" width="1675" height="1017" srcset="https://nerd-corner.com/wp-content/uploads/2021/07/TEST2_1.jpg 1682w, https://nerd-corner.com/wp-content/uploads/2021/07/TEST2_1-300x182.jpg 300w, https://nerd-corner.com/wp-content/uploads/2021/07/TEST2_1-1024x622.jpg 1024w, https://nerd-corner.com/wp-content/uploads/2021/07/TEST2_1-768x466.jpg 768w, https://nerd-corner.com/wp-content/uploads/2021/07/TEST2_1-1536x932.jpg 1536w" sizes="auto, (max-width: 1675px) 100vw, 1675px" /></p>
<p>After connecting the consumers and the power supply, not much happened. Only the module-internal LED lit up red. Only when I deactivated the ceramic load resistor one of the 5 V LED strips and the RGB diode connected to the step-down (marked yellow in picture Test2_1) lit up.</p>
<p>Subsequent measurement of the outputs revealed the following values: A voltage of 3.24 V was measured for the 5 V outputs and 2.28 V for the 3 V outputs. The total current supply of the module without the LiPo battery inserted is about 11 mA. This should be sufficient for a small LED.</p>
<h4>The module with LiPo battery</h4>
<p><img loading="lazy" decoding="async" class="aligncenter wp-image-1029 zoooom" src="https://nerd-corner.com/wp-content/uploads/2021/07/Test2_2.jpg" alt="Review: Battery Shield V3" width="1640" height="996" srcset="https://nerd-corner.com/wp-content/uploads/2021/07/Test2_2.jpg 1654w, https://nerd-corner.com/wp-content/uploads/2021/07/Test2_2-300x182.jpg 300w, https://nerd-corner.com/wp-content/uploads/2021/07/Test2_2-1024x622.jpg 1024w, https://nerd-corner.com/wp-content/uploads/2021/07/Test2_2-768x467.jpg 768w, https://nerd-corner.com/wp-content/uploads/2021/07/Test2_2-1536x933.jpg 1536w" sizes="auto, (max-width: 1640px) 100vw, 1640px" /></p>
<p>For phase 2 all consumers were removed and a LiPo battery (SAMSUNG INR18650-35E SDI KL59) was inserted into the module. As shown in the pictures, connectors were attached. This is because this module does not have a switch for the LiPo battery, so the load is immediately applied to the LiPo battery. It is simply uncomfortable to insert or plug in a battery under load.</p>
<p>All loads are in full mode in phase 2 and work fine. In addition, even the LiPo battery is charged. Questionable are the 4A amperage specifications of the 5V outputs. Given the amp numbers of the LiPo battery, this is possible, but it seems very high for a USB Micro supply. My recommendation would be to use the module with less than 4 amps.</p>
<h4>Deep discharge protection</h4>
<p>The third and last test is rather trivial. To test the deep discharge protection, only the ceramic load resistor with 5 watts was activated and no power supply was connected. This discharged the LiPo battery and if the deep discharge protection of the module terminates the discharge process on its own, the test was successful. This was the case. There was enough remaining capacity. However, such stress situations for the LiPo battery should still be avoided.</p>
<h2>Casing for the Battery Shield V3</h2>
<p><img loading="lazy" decoding="async" class="zoooom aligncenter wp-image-1031" src="https://nerd-corner.com/wp-content/uploads/2021/07/Wlc.jpg" alt="Review Battery Shield V3" width="1250" height="426" srcset="https://nerd-corner.com/wp-content/uploads/2021/07/Wlc.jpg 1253w, https://nerd-corner.com/wp-content/uploads/2021/07/Wlc-300x102.jpg 300w, https://nerd-corner.com/wp-content/uploads/2021/07/Wlc-1024x349.jpg 1024w, https://nerd-corner.com/wp-content/uploads/2021/07/Wlc-768x262.jpg 768w" sizes="auto, (max-width: 1250px) 100vw, 1250px" /></p>
<p>Of course I couldn&#8217;t resist to build a case for the Battery Shield V3 module. Beside the normal 5V USB output, which can be switched on and off by an extra switch, I also constructed a constant 3V output with a 5,5 x 2,1 socket into the case.</p>
<p><img loading="lazy" decoding="async" class="aligncenter wp-image-1032 zoooom" src="https://nerd-corner.com/wp-content/uploads/2021/07/Top-1.jpg" alt="Review Battery Shiled V3" width="1160" height="370" srcset="https://nerd-corner.com/wp-content/uploads/2021/07/Top-1.jpg 1173w, https://nerd-corner.com/wp-content/uploads/2021/07/Top-1-300x96.jpg 300w, https://nerd-corner.com/wp-content/uploads/2021/07/Top-1-1024x326.jpg 1024w, https://nerd-corner.com/wp-content/uploads/2021/07/Top-1-768x245.jpg 768w" sizes="auto, (max-width: 1160px) 100vw, 1160px" /></p>
<p>The housing can be downloaded in STL format at the end of the blog post.</p>
<p><img loading="lazy" decoding="async" class="zoooom aligncenter wp-image-1033" src="https://nerd-corner.com/wp-content/uploads/2021/07/PowerbankPurKpl.jpg" alt="Review DIY Powerbank" width="1500" height="681" srcset="https://nerd-corner.com/wp-content/uploads/2021/07/PowerbankPurKpl.jpg 2166w, https://nerd-corner.com/wp-content/uploads/2021/07/PowerbankPurKpl-300x136.jpg 300w, https://nerd-corner.com/wp-content/uploads/2021/07/PowerbankPurKpl-1024x465.jpg 1024w, https://nerd-corner.com/wp-content/uploads/2021/07/PowerbankPurKpl-768x349.jpg 768w, https://nerd-corner.com/wp-content/uploads/2021/07/PowerbankPurKpl-1536x698.jpg 1536w, https://nerd-corner.com/wp-content/uploads/2021/07/PowerbankPurKpl-2048x930.jpg 2048w" sizes="auto, (max-width: 1500px) 100vw, 1500px" /></p>
<p><img loading="lazy" decoding="async" class="aligncenter wp-image-1051 zoooom" src="https://nerd-corner.com/wp-content/uploads/2021/07/Abm.jpg" alt="CAD plan with size for the battery shield v3" width="1500" height="925" srcset="https://nerd-corner.com/wp-content/uploads/2021/07/Abm.jpg 1678w, https://nerd-corner.com/wp-content/uploads/2021/07/Abm-300x185.jpg 300w, https://nerd-corner.com/wp-content/uploads/2021/07/Abm-1024x632.jpg 1024w, https://nerd-corner.com/wp-content/uploads/2021/07/Abm-768x474.jpg 768w, https://nerd-corner.com/wp-content/uploads/2021/07/Abm-1536x947.jpg 1536w" sizes="auto, (max-width: 1500px) 100vw, 1500px" /></p>
<h2>Minor disadvantages</h2>
<p>The On/OFF switch only switches the USB port. The 3 x 3 V and 3 x 5 V solder pins cannot be switched on and off by this switch.</p>
<p>For my electronic projects this disadvantage is not really dramatic, because I use mostly the USB port. Besides, additional switches can be soldered to the soldering points.</p>
<h2>Downloading files:</h2>
<ul>
<li><a  data-e-Disable-Page-Transition="true" class="download-link" title="" href="https://nerd-corner.com/download/1039/?tmstv=1756260355" rel="nofollow" id="download-link-1039" data-redirect="false" >
	Datenblatt Battery Shield V3 (von AZ Delivery)</a>
</li>
<li><a href="https://www.thingiverse.com/thing:4917764" target="_blank" rel="noopener">STL Files for the housing</a></li>
</ul>
<p>The post <a href="https://nerd-corner.com/review-battery-shield-v3-diy-powerbank-with-lipo-18650/">Review Battery Shield V3 &#8211; DIY Powerbank with LiPo 18650</a> appeared first on <a href="https://nerd-corner.com">Nerd Corner</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://nerd-corner.com/review-battery-shield-v3-diy-powerbank-with-lipo-18650/feed/</wfw:commentRss>
			<slash:comments>3</slash:comments>
		
		
			</item>
		<item>
		<title>Upgrade: Data transfer via VLC and LiFi &#8211; Pi to Pi transfer</title>
		<link>https://nerd-corner.com/upgrade-data-transfer-via-vlc-and-lifi-pi-to-pi-transfer/</link>
					<comments>https://nerd-corner.com/upgrade-data-transfer-via-vlc-and-lifi-pi-to-pi-transfer/#comments</comments>
		
		<dc:creator><![CDATA[Nerds]]></dc:creator>
		<pubDate>Thu, 08 Jul 2021 14:27:07 +0000</pubDate>
				<category><![CDATA[Handcrafted]]></category>
		<category><![CDATA[Hardware]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[3D print]]></category>
		<category><![CDATA[CAD]]></category>
		<category><![CDATA[CAD design]]></category>
		<category><![CDATA[cyclic redundancy check]]></category>
		<category><![CDATA[data transfer]]></category>
		<category><![CDATA[fan]]></category>
		<category><![CDATA[LiFi]]></category>
		<category><![CDATA[LiFI Router]]></category>
		<category><![CDATA[Light Fidelity]]></category>
		<category><![CDATA[LM393]]></category>
		<category><![CDATA[pi]]></category>
		<category><![CDATA[precise]]></category>
		<category><![CDATA[Raspberry Pi]]></category>
		<category><![CDATA[Timer]]></category>
		<category><![CDATA[visible Light communication]]></category>
		<category><![CDATA[visible light communication project]]></category>
		<category><![CDATA[VLC Raspberry Pi project]]></category>
		<guid isPermaLink="false">https://nerd-corner.com/de/?p=985</guid>

					<description><![CDATA[<p>After I already transferred simple text messages via light signals from a Raspberry Pi to an Arduino Uno ( Link: https://nerd-corner.com/sending-text-messages-with-visible-light-communication/ ), I wanted to &#8230; </p>
<p>The post <a href="https://nerd-corner.com/upgrade-data-transfer-via-vlc-and-lifi-pi-to-pi-transfer/">Upgrade: Data transfer via VLC and LiFi &#8211; Pi to Pi transfer</a> appeared first on <a href="https://nerd-corner.com">Nerd Corner</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>After I already transferred simple text messages via light signals from a Raspberry Pi to an Arduino Uno ( Link: <a href="https://nerd-corner.com/sending-text-messages-with-visible-light-communication/" target="_blank" rel="noopener">https://nerd-corner.com/sending-text-messages-with-visible-light-communication/</a> ), I wanted to improve this system to be able to transfer any file formats in both directions. Since a Raspberry Pi uses Linux, this system can be transferred to any Linux device for data transfer via VLC (visual light communication). The software code and STL files can be downloaded at the end of the blog entry.</p>
<p><em><strong>This might also be interesting for you:</strong> <a href="https://nerd-corner.com/sending-text-messages-with-visible-light-communication/" target="_blank" rel="noopener">Sending text messages with light signals</a></em></p>
<p><em><strong>Closely related to this article:</strong> <a href="https://nerd-corner.com/cyclic-redundancy-check-in-c-code/" target="_blank" rel="noopener">Error detection during data transmission</a></em></p>
<p><em><strong>Also relevant:</strong> <a href="https://nerd-corner.com/how-to-program-a-highly-precise-timer-in-c-for-linux/" target="_blank" rel="noopener">Precise Timer in C for data transfer</a></em></p>
<h2>List of components</h2>
<ul>
<li>2x Raspberry Pi 4</li>
<li>2x 5V Solar cell</li>
<li>2x 5V Laser diode</li>
<li>Jumper cables</li>
<li>3D printer</li>
<li>Filament</li>
<li>2x 5V Fan</li>
<li>NPN Transistor</li>
<li>2x ADC Board with a LM393 dual comparator</li>
</ul>
<p><img loading="lazy" decoding="async" class="zoooom aligncenter wp-image-966" src="https://nerd-corner.com/wp-content/uploads/2021/07/Assembly-parts-scaled.jpg" alt="Datenübertragung mit Licht Einzelteile Data transfer via VLC" width="2500" height="1681" srcset="https://nerd-corner.com/wp-content/uploads/2021/07/Assembly-parts-scaled.jpg 2560w, https://nerd-corner.com/wp-content/uploads/2021/07/Assembly-parts-300x202.jpg 300w, https://nerd-corner.com/wp-content/uploads/2021/07/Assembly-parts-1024x689.jpg 1024w, https://nerd-corner.com/wp-content/uploads/2021/07/Assembly-parts-768x516.jpg 768w, https://nerd-corner.com/wp-content/uploads/2021/07/Assembly-parts-1536x1033.jpg 1536w, https://nerd-corner.com/wp-content/uploads/2021/07/Assembly-parts-2048x1377.jpg 2048w" sizes="auto, (max-width: 2500px) 100vw, 2500px" /></p>
<h2>Wiring</h2>
<p>Unlike the wiring in the last article, where text messages were sent from a Pi to an Arduino via light signals ( Link: <a href="https://nerd-corner.com/sending-text-messages-with-visible-light-communication/" target="_blank" rel="noopener">https://nerd-corner.com/sending-text-messages-with-visible-light-communication/</a> ), there is now no defined receiver and no defined transmitter. Instead, two identical stations are set up that can both send and receive data.</p>
<p><img loading="lazy" decoding="async" class="aligncenter wp-image-965 zoooom" src="https://nerd-corner.com/wp-content/uploads/2021/07/FritzingPiTransceiver_Steckplatine.png" alt="Fritzing Pi VLC LiFI" width="2250" height="1459" srcset="https://nerd-corner.com/wp-content/uploads/2021/07/FritzingPiTransceiver_Steckplatine.png 2270w, https://nerd-corner.com/wp-content/uploads/2021/07/FritzingPiTransceiver_Steckplatine-300x195.png 300w, https://nerd-corner.com/wp-content/uploads/2021/07/FritzingPiTransceiver_Steckplatine-1024x664.png 1024w, https://nerd-corner.com/wp-content/uploads/2021/07/FritzingPiTransceiver_Steckplatine-768x498.png 768w, https://nerd-corner.com/wp-content/uploads/2021/07/FritzingPiTransceiver_Steckplatine-1536x996.png 1536w, https://nerd-corner.com/wp-content/uploads/2021/07/FritzingPiTransceiver_Steckplatine-2048x1328.png 2048w" sizes="auto, (max-width: 2250px) 100vw, 2250px" /></p>
<p>For this reason, the Raspberry Pi&#8217;s are connected to both a 5V laser and a 5V solar cell. For the laser the GPIO18 pin was chosen, which corresponds to pin 1 in the &#8220;wiringPi&#8221; library. The &#8220;wiringPi&#8221; library is used in the program code. Directly below GPIO18 is a ground, which is connected to the negative pole of the laser.</p>
<p><img loading="lazy" decoding="async" class="aligncenter wp-image-967 zoooom" src="https://nerd-corner.com/wp-content/uploads/2021/07/GPIO.png" alt="Datenübertragung mittels Licht Pi" width="1500" height="1125" srcset="https://nerd-corner.com/wp-content/uploads/2021/07/GPIO.png 1600w, https://nerd-corner.com/wp-content/uploads/2021/07/GPIO-300x225.png 300w, https://nerd-corner.com/wp-content/uploads/2021/07/GPIO-1024x768.png 1024w, https://nerd-corner.com/wp-content/uploads/2021/07/GPIO-768x576.png 768w, https://nerd-corner.com/wp-content/uploads/2021/07/GPIO-1536x1152.png 1536w" sizes="auto, (max-width: 1500px) 100vw, 1500px" /></p>
<p>The solar cell provides a corresponding voltage value depending on the light intensity. But since the digital pins of the Raspberry Pi can only recognize 1 and 0, the analog value of the solar cell must be converted into a digital value with the help of a comparator. The process is explained in more detail in the section &#8220;ADC Board with an LM393 Comparator&#8221;. For the wiring, the plus and minus pole of the solar cell is connected to the plus and minus contacts of the ADC board. Then the ground of the ADC board is connected to a Raspberry Pi ground and for the power supply the plus pole of the ADC board is connected to 5V of the Pi. The D0 pin of the ADC board provides the digital value 0 or 1, depending on the light intensity of the solar cell. I connected this pin to GPIO17, which corresponds to pin 0 in the &#8220;wiringPi&#8221; library.</p>
<p>Since I noticed that the Pi gets very hot during operation, I connected a fan. So that the fan is not permanently in operation, which would have a negative effect on the performance of the laser, the fan can be switched on and off by a NPN transistor. Connect the positive pole of the fan directly to a 5V pin of the Raspberry Pi and the negative pole of the fan to the emitter of the NPN transistor. The collector of the transistor is connected to a ground of the Pi. To switch the fan on and off via the transistor, the transistor base is connected to a GPIO pin. For example I chose GPIO27 (corresponds to pin 2 in the &#8220;wiringPi&#8221; library). In the following table the pins of the Pi are compared to the numbering of the &#8220;wiringPi&#8221; library.</p>
<p><img loading="lazy" 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 Datenübertragung mit Licht" width="599" height="295" 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="auto, (max-width: 599px) 100vw, 599px" /></p>
<h2>ADC Board with a LM393 camparator</h2>
<p><img loading="lazy" decoding="async" class="aligncenter wp-image-968 zoooom" src="https://nerd-corner.com/wp-content/uploads/2021/07/ADC-LM393.jpg" alt="ADC Board mit LM393 Komparator" width="450" height="319" srcset="https://nerd-corner.com/wp-content/uploads/2021/07/ADC-LM393.jpg 771w, https://nerd-corner.com/wp-content/uploads/2021/07/ADC-LM393-300x213.jpg 300w, https://nerd-corner.com/wp-content/uploads/2021/07/ADC-LM393-768x545.jpg 768w, https://nerd-corner.com/wp-content/uploads/2021/07/ADC-LM393-120x85.jpg 120w" sizes="auto, (max-width: 450px) 100vw, 450px" /></p>
<p>The solar cell returns a voltage value depending on the light intensity. Unfortunately the Raspberry Pi has no analog pins to read this voltage value. Therefore the analog signal has to be converted into a digital signal. This is possible with the help of the LM393 comparator. The comparator is often used on ADC boards. Here I simply replaced the original sensor (it was a photoresistor) through a solar cell. With the help of a potentiometer the comparator can be adjusted. That means, as soon as the voltage value of the solar cell, which depends on the light intensity, exceeds the adjusted value of the potentiometer, a digital 1 is measured, otherwise a digital 0.</p>
<h2>Structure of the data frame</h2>
<p><img loading="lazy" decoding="async" class="zoooom aligncenter wp-image-969" src="https://nerd-corner.com/wp-content/uploads/2021/07/MultipleFrames-1.jpg" alt="Aufbau Datenframe Lichtübertragung Daten Datentransfer mittels VLC" width="1300" height="469" srcset="https://nerd-corner.com/wp-content/uploads/2021/07/MultipleFrames-1.jpg 1409w, https://nerd-corner.com/wp-content/uploads/2021/07/MultipleFrames-1-300x108.jpg 300w, https://nerd-corner.com/wp-content/uploads/2021/07/MultipleFrames-1-1024x369.jpg 1024w, https://nerd-corner.com/wp-content/uploads/2021/07/MultipleFrames-1-768x277.jpg 768w" sizes="auto, (max-width: 1300px) 100vw, 1300px" /></p>
<p>The data frame for sending the text messages using visual light communication (Link: <a href="https://nerd-corner.com/sending-text-messages-with-visible-light-communication/" target="_blank" rel="noopener">https://nerd-corner.com/sending-text-messages-with-visible-light-communication/ </a>) consisted of a preamble, the length of the text message, the text content and the cyclic redundancy check. However, to be able to send all kinds of data instead of text messages, the file name, the file extension, the total number of packets and the number of the current packet must be specified instead of the length of the text message. Then the data content and the code of the cyclic redundancy check can be added.</p>
<h2>Software code for data transfer via VLC</h2>
<p>Basically, the receiver and sender scripts from the previous project on sending text messages using visual light communication (link: https://nerd-corner.com/de/textnachrichten-mittels-lichtsignale-senden-pi-zu-arduino/ ) were further developed and combined into one single script. Which is applied on both Raspberry Pi&#8217;s. For example, a &#8220;ReadFile&#8221; and &#8220;WriteFile&#8221; function was added, which can read files and combine and save received data packets to a file. The program was written in C again, because a high speed of data transfer should be achieved. Details about precise programming in C for fast data transfer are given in this article: <a href="https://nerd-corner.com/how-to-program-a-highly-precise-timer-in-c-for-linux/" target="_blank" rel="noopener">https://nerd-corner.com/how-to-program-a-highly-precise-timer-in-c-for-linux/</a> .</p>
<p>The complete software code for data transfer using VLC can be downloaded at the end of the article. The core of the program is again a state machine with the help of which can be selected whether data should be sent or received. In addition, the program automatically turns on the fan when no data transfer is taking place. Important: When compiling please do not forget the &#8220;wiringPi&#8221; library and the &#8220;math.h&#8221; library! The command is: &#8220;gcc -o transceiver transceiver.c -lwiringPi -lm&#8221;.</p>
<pre class="EnlighterJSRAW" data-enlighter-language="c" data-enlighter-group="transceiver" data-enlighter-title="transceiver.c">while(1)
    {
        digitalWrite (2, HIGH);
        printf("Press the R button for Receiver Mode or any other key for Sender Moden");
        scanf(" %c",&amp;mode);
        
        if (mode=='R'||mode=='r')
        {
            digitalWrite(2,LOW);
            modeReceiver=true;
        }
        
        if (mode!='R'&amp;&amp;mode!='r')
        {
            digitalWrite(2,LOW);
            modeReceiver=false;
            
            char dataName[NAME_MAX];
            char dataExtension[NAME_MAX];
            
               
            printf("n Name of file WITHOUT extension: ");
            scanf("%s",dataName);

            printf("n Extension: ");
            scanf("%s",dataExtension);

            if (read_file(dataName, dataExtension, file_content) != OK)
            {
                printf("File read error, size exceeds array sizen");
                return -1;
            }
            BuildDataFrame(dataName, dataExtension, file_content);
        }
        
        
        
        while(modeReceiver)
        {
            gettimeofday(&amp;tval_after, NULL);
            timersub(&amp;tval_after, &amp;tval_before, &amp;tval_result);
            double time_elapsed = (double)tval_result.tv_sec + ((double)tval_result.tv_usec/1000000.0f);
            
            while(time_elapsed &lt; 0.001)
            {
                gettimeofday(&amp;tval_after, NULL);
                timersub(&amp;tval_after, &amp;tval_before, &amp;tval_result);
                time_elapsed = (double)tval_result.tv_sec + ((double)tval_result.tv_usec/1000000.0f);
            }
            gettimeofday(&amp;tval_before, NULL);
            
            int data = digitalRead(0);
            
            
            switch (state)
            {
                case 0:
                    //looking for preamble pattern
                    synchro_Done=false;
                    LookForSynchro(data);
                    
                    if (synchro_Done==true)
                    {
                        state=1;
                    }
                    break;
                    
                case 1:
                    //receive the actual data
                    receiveData_Done=false;
                    senderState=false;
                    ReceiveData(data);
                    
                    if(receiveData_Done&amp;&amp;senderState==false)
                    {
                        state=0;
                    }
                    if(senderState==true){
                        senderState=false;
                        state=0;
                        modeReceiver=false;
                        }
                    break;
                  
            }
            
        }
    }</pre>
<h2>Housing</h2>
<p>In order to be able to hold the components in place, a housing was constructed in CAD. This also has the advantage that no complicated alignment of the lasers and the solar cells is necessary for the data transmission. For beginners, <a href="https://www.tinkercad.com/" target="_blank" rel="noopener">TinkerCAD</a> is suitable for housing design. TinkerCAD is free and can be used directly in the browser. Alternatively, the STL files for the 3D printer can also be downloaded here.</p>
<p><img loading="lazy" decoding="async" class="zoooom aligncenter wp-image-970" src="https://nerd-corner.com/wp-content/uploads/2021/07/gehaeuse-CAD.jpg" alt="Datenübertragung per Licht Gehäuse Datentransfer mittels VLC" width="600" height="530" srcset="https://nerd-corner.com/wp-content/uploads/2021/07/gehaeuse-CAD.jpg 682w, https://nerd-corner.com/wp-content/uploads/2021/07/gehaeuse-CAD-300x265.jpg 300w" sizes="auto, (max-width: 600px) 100vw, 600px" /></p>
<p>The housing for data transfer via VLC has an opening for the solar cell and the laser. In addition, an exhaust vent for the fan was constructed and space was also left free for a Raspberry Pi housing. The following picture shows the installation of the components.</p>
<p><img loading="lazy" decoding="async" class="aligncenter wp-image-971 zoooom" src="https://nerd-corner.com/wp-content/uploads/2021/07/assembly-end-scaled.jpg" alt="Datenübertragung per Licht Lifi VLC" width="2500" height="1875" srcset="https://nerd-corner.com/wp-content/uploads/2021/07/assembly-end-scaled.jpg 2560w, https://nerd-corner.com/wp-content/uploads/2021/07/assembly-end-300x225.jpg 300w, https://nerd-corner.com/wp-content/uploads/2021/07/assembly-end-1024x768.jpg 1024w, https://nerd-corner.com/wp-content/uploads/2021/07/assembly-end-768x576.jpg 768w, https://nerd-corner.com/wp-content/uploads/2021/07/assembly-end-1536x1152.jpg 1536w, https://nerd-corner.com/wp-content/uploads/2021/07/assembly-end-2048x1536.jpg 2048w" sizes="auto, (max-width: 2500px) 100vw, 2500px" /></p>
<h2>Conclusion about data transfer via VLC</h2>
<p>The existing system for sending text messages by means of visual light signals was further developed so that all types of data can now be sent and received. The system works amazingly successfully. It is very robust and achieves a data rate of 1 kbps to 10 kbps. All incoming data packets can be directly assigned due to the intelligent structure of the data frame. Only an acknowledgement signal would be a useful addition. Such a signal would be a feedback from the receiver to the sender to inform the sender that all packets have arrived, or possibly a certain packet was faulty and must be sent again.</p>
<p>Also interesting for the future would be to investigate other types of modulation. In particular, I would like to explore color shift keying, which is specifically designed for visual light communication, and compare the resulting data rates.</p>
<p><img loading="lazy" decoding="async" class="zoooom aligncenter wp-image-972" src="https://nerd-corner.com/wp-content/uploads/2021/07/Assembly-finish-scaled.jpg" alt="Datenübertragung per Licht Gehäuse Lifi VLC Datentransfer mittels VLC" width="2500" height="1125" srcset="https://nerd-corner.com/wp-content/uploads/2021/07/Assembly-finish-scaled.jpg 2560w, https://nerd-corner.com/wp-content/uploads/2021/07/Assembly-finish-300x135.jpg 300w, https://nerd-corner.com/wp-content/uploads/2021/07/Assembly-finish-1024x461.jpg 1024w, https://nerd-corner.com/wp-content/uploads/2021/07/Assembly-finish-768x346.jpg 768w, https://nerd-corner.com/wp-content/uploads/2021/07/Assembly-finish-1536x691.jpg 1536w, https://nerd-corner.com/wp-content/uploads/2021/07/Assembly-finish-2048x922.jpg 2048w" sizes="auto, (max-width: 2500px) 100vw, 2500px" /></p>
<h2>Download files:</h2>
<ul>
<li><a  data-e-Disable-Page-Transition="true" class="download-link" title="" href="https://nerd-corner.com/download/977/?tmstv=1756260355" rel="nofollow" id="download-link-977" data-redirect="false" >
	Softwarecode Transceiver</a>
</li>
<li><a href="https://cults3d.com/en/3d-model/various/visible-light-communication-pi-housing" target="_blank" rel="noopener">STL files housing</a></li>
<li><a  data-e-Disable-Page-Transition="true" class="download-link" title="" href="https://nerd-corner.com/download/991/?tmstv=1756260355" rel="nofollow" id="download-link-991" data-redirect="false" >
	Pi Case with free pins (Creative Common License from Thingiverse)</a>
</li>
</ul>
<p>&nbsp;</p>
<p>The post <a href="https://nerd-corner.com/upgrade-data-transfer-via-vlc-and-lifi-pi-to-pi-transfer/">Upgrade: Data transfer via VLC and LiFi &#8211; Pi to Pi transfer</a> appeared first on <a href="https://nerd-corner.com">Nerd Corner</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://nerd-corner.com/upgrade-data-transfer-via-vlc-and-lifi-pi-to-pi-transfer/feed/</wfw:commentRss>
			<slash:comments>8</slash:comments>
		
		
			</item>
		<item>
		<title>How to program a highly precise timer in C for Linux</title>
		<link>https://nerd-corner.com/how-to-program-a-highly-precise-timer-in-c-for-linux/</link>
					<comments>https://nerd-corner.com/how-to-program-a-highly-precise-timer-in-c-for-linux/#comments</comments>
		
		<dc:creator><![CDATA[Nerds]]></dc:creator>
		<pubDate>Sat, 27 Feb 2021 13:42:40 +0000</pubDate>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[C]]></category>
		<category><![CDATA[C programming]]></category>
		<category><![CDATA[C Timer]]></category>
		<category><![CDATA[communication technique]]></category>
		<category><![CDATA[data transfer]]></category>
		<category><![CDATA[precise]]></category>
		<category><![CDATA[Raspberry Pi]]></category>
		<category><![CDATA[Timer]]></category>
		<category><![CDATA[Timer in C]]></category>
		<guid isPermaLink="false">https://nerd-corner.com/?p=831</guid>

					<description><![CDATA[<p>I wanted to program a timer in C for my Raspberry Pi, which executes precise work instructions for 1 ms as well as for 0.1 &#8230; </p>
<p>The post <a href="https://nerd-corner.com/how-to-program-a-highly-precise-timer-in-c-for-linux/">How to program a highly precise timer in C for Linux</a> appeared first on <a href="https://nerd-corner.com">Nerd Corner</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>I wanted to program a timer in C for my Raspberry Pi, which executes precise work instructions for 1 ms as well as for 0.1 ms. Unfortunately, since Python is compiled at runtime, Python was way too slow for this purpose. For this reason, the program was written in C. The 1 ms and 0.1 ms were confirmed after programming with the help of an oscilloscope.</p>
<p>In the following is an explanation why the library &#8220;sys/time.h&#8221; was used, as well as a code example with subsequent explanation. This code example is very well suited for bit-wise data transmission in communication technology.</p>
<p><em><strong>This might also be interesting for you:</strong> <a href="https://nerd-corner.com/arduino-timer-interrupts-how-to-program-arduino-registers/" target="_blank" rel="noopener">How to program a highly precise Arduino Timer</a></em></p>
<h2>List of components</h2>
<ul>
<li>Linux operating system (for example Raspberry Pi)</li>
<li>Editor for C &#8211; Programming</li>
</ul>
<p><img loading="lazy" decoding="async" class="aligncenter wp-image-848 zoooom" src="https://nerd-corner.com/wp-content/uploads/2021/02/proxy-image-3-1.jpg" alt="Timer in C" width="484" height="392" srcset="https://nerd-corner.com/wp-content/uploads/2021/02/proxy-image-3-1.jpg 1084w, https://nerd-corner.com/wp-content/uploads/2021/02/proxy-image-3-1-300x243.jpg 300w, https://nerd-corner.com/wp-content/uploads/2021/02/proxy-image-3-1-1024x830.jpg 1024w, https://nerd-corner.com/wp-content/uploads/2021/02/proxy-image-3-1-768x623.jpg 768w" sizes="auto, (max-width: 484px) 100vw, 484px" /></p>
<p>&nbsp;</p>
<h2>The library „sys/time.h“</h2>
<p>Functions like &#8220;usleep()&#8221; or &#8220;nanosleep()&#8221; would stop the complete program. For simple applications this might be sufficient, but for my purposes this was too imprecise. I wanted a timer that really works exactly in a 1 ms or 0.1 ms cycle. So instead of &#8220;usleep()&#8221; or &#8220;nanosleep()&#8221; another solution was chosen. The library &#8220;sys/time.h&#8221;. This library is able to read and compare the current &#8220;System Clock Time&#8221;.</p>
<h2>Code example for a precise timer in C</h2>
<pre class="EnlighterJSRAW" data-enlighter-language="c">#include &lt;sys/time.h&gt;

int main()
{
    struct timeval tval_before, tval_after, tval_result;
    int counter=0;
    bool stop=false;
   
    gettimeofday(&amp;tval_before, NULL);
    while(stop!=true)
    {
        gettimeofday(&amp;tval_after, NULL);
        timersub(&amp;tval_after, &amp;tval_before, &amp;tval_result);
        double time_elapsed = (double)tval_result.tv_sec + ((double)tval_result.tv_usec/1000000.0f);
        
        while(time_elapsed &lt; 0.001)  //1ms; you can change your desired time interval here
        {
            gettimeofday(&amp;tval_after, NULL);
            timersub(&amp;tval_after, &amp;tval_before, &amp;tval_result);
            time_elapsed = (double)tval_result.tv_sec + ((double)tval_result.tv_usec/1000000.0f);
        }
        gettimeofday(&amp;tval_before, NULL);
        
        if (counter==10000)
        {
            stop=true;
        }
            
        else 
        {
            counter++;
        }
    }
    return 0;
}
</pre>
<h2>Explanation of the code example:</h2>
<p>A function &#8220;gettimeofday&#8221; writes the current system time into the variable &#8220;tval_before&#8221;. A While loop will then be executed until the actual task is completed.</p>
<p>Within the While loop the system time is stored again into a variable &#8220;tval_after&#8221;. Then the time difference between &#8220;tval_after&#8221; and &#8220;tval_before&#8221; is measured and stored in &#8220;tval_result&#8221;.</p>
<p>The next step of the timer in C is not immediately obvious: &#8220;tv_result&#8221; consists by definition of 2 parts. On the one hand a seconds part &#8220;.tv_sec&#8221; and on the other hand a microseconds part &#8220;.tv_usec&#8221;. This microsecond part has to be divided by one million to get the value in seconds. Afterwards, the microsecond part can be added to the second part.</p>
<p>The added value is called &#8220;time_elapsed&#8221;. If this value is less than one millisecond, another inner While loop is opened, which recalculates the value for &#8220;time_elapsed&#8221; until exactly 1 ms has passed. Afterwards, the value for &#8220;tval_before&#8221; is redefined using the &#8220;gettimeofday&#8221; function.</p>
<p>Since exactly 1 ms has passed at this point, the timer can now perform its actual operation. In this simple code example the variable &#8220;counter&#8221; is incremented by 1. That means for each interval step (in the code example 1 ms) the counter increases by 1. As soon as a fixed value for counter was reached the program stops. In this case the defined value is 10000. Then the While loop will be terminated. But this part of the code can be easily changed for your own purposes.</p>
<p>My measurements with an oscilloscope detected an exact frequency of 1 ms, even 0.1 ms was measured exactly. This code example is therefore also very suitable for an exact <a href="https://en.wikipedia.org/wiki/Data_transmission" target="_blank" rel="noopener">data transmission</a> in the communication technology.</p>
<h2>Download files</h2>
<ul>
<li><a  data-e-Disable-Page-Transition="true" class="download-link" title="" href="https://nerd-corner.com/download/835/?tmstv=1756260355" rel="nofollow" id="download-link-835" data-redirect="false" >
	Downloadfile Timer in C</a>
</li>
</ul>
<p>The post <a href="https://nerd-corner.com/how-to-program-a-highly-precise-timer-in-c-for-linux/">How to program a highly precise timer in C for Linux</a> appeared first on <a href="https://nerd-corner.com">Nerd Corner</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://nerd-corner.com/how-to-program-a-highly-precise-timer-in-c-for-linux/feed/</wfw:commentRss>
			<slash:comments>2</slash:comments>
		
		
			</item>
	</channel>
</rss>
