{"id":1069,"date":"2018-11-19T20:01:51","date_gmt":"2018-11-19T20:01:51","guid":{"rendered":"https:\/\/zhutarduino.wordpress.com\/?page_id=1069"},"modified":"2019-10-20T16:35:52","modified_gmt":"2019-10-20T16:35:52","slug":"arduino-mad-scientist-laboratory-ep7-tea5767-fm-radio-with-lcd-rotary-encoder-presets-30w-amp","status":"publish","type":"page","link":"https:\/\/thezhut.com\/?page_id=1069","title":{"rendered":"Arduino Mad Scientist Laboratory EP#8 TEA5767 FM radio with LCD, Rotary Encoder, Presets &#038; 30w AMP"},"content":{"rendered":"<h1 style=\"text-align: center;\">Today we will be trying to take over the world by building our own Arduino controlled TEA5767 FM radio with LCD display, rotary encoder tuning, presets and an optional 30 watt stereo amplifier.<\/h1>\n<p><iframe loading=\"lazy\" title=\"Arduino Mad Scientist Laboratory EP #8 TEA5767 FM radio with LCD, Rotary Encoder, Presets &amp; 30w AMP\" width=\"640\" height=\"360\" src=\"https:\/\/www.youtube.com\/embed\/OBDC86GtMqg?feature=oembed\" frameborder=\"0\" allow=\"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share\" referrerpolicy=\"strict-origin-when-cross-origin\" allowfullscreen><\/iframe><\/p>\n<p>&nbsp;<\/p>\n<h1><a href=\"https:\/\/www.facebook.com\/zarduino\/\" target=\"_blank\" rel=\"noopener noreferrer\">Check us out on Facebook!<\/a><\/h1>\n<p>&nbsp;<\/p>\n<h2><a href=\"https:\/\/wp.me\/P6TkHi-2N\" target=\"_blank\" rel=\"noopener noreferrer\">How to set up and use a 1602 I2C serial LCD with your ARDUINO<\/a><\/h2>\n<h1><\/h1>\n<h1>Parts List:<\/h1>\n<p>affiliate links<\/p>\n<p><a href=\"https:\/\/www.amazon.com\/gp\/search\/ref=as_li_qf_sp_sr_il_tl?ie=UTF8&amp;tag=zhut01-20&amp;keywords=ARDUINO Pro Mini&amp;index=aps&amp;camp=1789&amp;creative=9325&amp;linkCode=xm2&amp;linkId=f6164945c122dd8cb781ac7a64ad9597\" target=\"_blank\" rel=\"noopener noreferrer\">ARDUINO Pro Mini<\/a><\/p>\n<p><a href=\"https:\/\/www.amazon.com\/gp\/search\/ref=as_li_qf_sp_sr_il_tl?ie=UTF8&amp;tag=zhut01-20&amp;keywords=1602 I2C LCD&amp;index=aps&amp;camp=1789&amp;creative=9325&amp;linkCode=xm2&amp;linkId=9ad890475356b23a6c67050b609227e7\" target=\"_blank\" rel=\"noopener noreferrer\">I2C LCD<\/a><\/p>\n<p><a href=\"https:\/\/www.amazon.com\/gp\/search\/ref=as_li_qf_sp_sr_il_tl?ie=UTF8&amp;tag=zhut01-20&amp;keywords=TEA5767 FM Radio&amp;index=aps&amp;camp=1789&amp;creative=9325&amp;linkCode=xm2&amp;linkId=f0822f530f2f014006b19ea1cb11421b\" target=\"_blank\" rel=\"noopener noreferrer\">TEA5767 FM Radio<\/a><\/p>\n<p><a href=\"https:\/\/www.amazon.com\/gp\/search\/ref=as_li_qf_sp_sr_il_tl?ie=UTF8&amp;tag=zhut01-20&amp;keywords=Rotary Encoder&amp;index=aps&amp;camp=1789&amp;creative=9325&amp;linkCode=xm2&amp;linkId=8b8066d2ea7ce1f2104903aa77d114d2\" target=\"_blank\" rel=\"noopener noreferrer\">Rotary Encoder<\/a><\/p>\n<p><a href=\"https:\/\/www.amazon.com\/gp\/search\/ref=as_li_qf_sp_sr_il_tl?ie=UTF8&amp;tag=zhut01-20&amp;keywords=arduino Push Buttons&amp;index=aps&amp;camp=1789&amp;creative=9325&amp;linkCode=xm2&amp;linkId=abc17355e25b4415a4258f3b130078e7\" target=\"_blank\" rel=\"noopener noreferrer\">Push Buttons<\/a><\/p>\n<p><a href=\"https:\/\/www.amazon.com\/gp\/search\/ref=as_li_qf_sp_sr_il_tl?ie=UTF8&amp;tag=zhut01-20&amp;keywords=2N2222 NPN Transistor&amp;index=aps&amp;camp=1789&amp;creative=9325&amp;linkCode=xm2&amp;linkId=f6dff6683e4411e697a9768d3bcc2f9d\" target=\"_blank\" rel=\"noopener noreferrer\">2N2222 NPN Transistor<\/a><\/p>\n<p><a href=\"https:\/\/www.amazon.com\/gp\/search\/ref=as_li_qf_sp_sr_il_tl?ie=UTF8&amp;tag=zhut01-20&amp;keywords=arduino amplifier&amp;index=aps&amp;camp=1789&amp;creative=9325&amp;linkCode=xm2&amp;linkId=4b5ba78a2aa96add3037de34186f354f\" target=\"_blank\" rel=\"noopener noreferrer\">amplifier<\/a><\/p>\n<h1>Schematic:<\/h1>\n<p><a href=\"https:\/\/thezhut.com\/wp-content\/uploads\/2018\/11\/lcd_radio_schem.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-1078\" src=\"https:\/\/thezhut.com\/wp-content\/uploads\/2018\/11\/lcd_radio_schem.jpg?w=300\" alt=\"\" width=\"636\" height=\"426\" srcset=\"https:\/\/thezhut.com\/wp-content\/uploads\/2018\/11\/lcd_radio_schem.jpg 1602w, https:\/\/thezhut.com\/wp-content\/uploads\/2018\/11\/lcd_radio_schem-300x201.jpg 300w, https:\/\/thezhut.com\/wp-content\/uploads\/2018\/11\/lcd_radio_schem-768x513.jpg 768w, https:\/\/thezhut.com\/wp-content\/uploads\/2018\/11\/lcd_radio_schem-1024x685.jpg 1024w\" sizes=\"auto, (max-width: 636px) 100vw, 636px\" \/><\/a><\/p>\n<h1>Library&#8217;s:<\/h1>\n<h2><a href=\"https:\/\/bitbucket.org\/fmalpartida\/new-liquidcrystal\/downloads\" target=\"_blank\" rel=\"noopener noreferrer\">LCD Library Download<\/a><\/h2>\n<h2>TEA5767 Library can be found in your ARDUINO Manage library&#8217;s tab.<\/h2>\n<h1>ARDUINO Code:<\/h1>\n<p>#include &lt;Wire.h&gt;<br \/>\n#include &lt;TEA5767Radio.h&gt;<br \/>\nTEA5767Radio radio = TEA5767Radio();<br \/>\n#include &lt;LiquidCrystal_I2C.h&gt;<br \/>\nLiquidCrystal_I2C lcd(0x3f, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE); \/\/ Set the LCD I2C address<br \/>\n#define lcdLight 5 \/\/ lcd backlight on off pin<br \/>\n#define encoderPinA 2 \/\/ right<br \/>\n#define encoderPinB 3 \/\/ left<br \/>\n#define lcdButton 8 \/\/ lcd backlight switch button<br \/>\n#define ps1Button 10 \/\/ preset buttons<br \/>\n#define ps2Button 11<br \/>\n#define ps3Button 12<br \/>\nfloat encoderPos = 100; \/\/ a counter for the dial<br \/>\nunsigned int lastReportedPos = 1; \/\/ change management<br \/>\nstatic boolean rotating = false; \/\/ debounce management<br \/>\nboolean A_set = false;<br \/>\nboolean B_set = false;<br \/>\nint state = 0; \/\/ lcd on or off state<\/p>\n<p>void setup() {<\/p>\n<p>Wire.begin();<\/p>\n<p>pinMode(encoderPinA, INPUT_PULLUP); \/\/enabling pullups<br \/>\npinMode(encoderPinB, INPUT_PULLUP);<br \/>\npinMode(lcdButton, INPUT_PULLUP);<br \/>\npinMode(ps1Button, INPUT_PULLUP);<br \/>\npinMode(ps2Button, INPUT_PULLUP);<br \/>\npinMode(ps3Button, INPUT_PULLUP);<br \/>\npinMode(lcdLight, OUTPUT);<\/p>\n<p>attachInterrupt(0, doEncoderA, CHANGE); \/\/pin 2<br \/>\nattachInterrupt(1, doEncoderB, CHANGE); \/\/pin 3<\/p>\n<p>digitalWrite(lcdLight, HIGH);<br \/>\nlcd.begin(16, 2); \/\/ initialize the lcd for 16 chars 2 lines, turn on backlight<br \/>\nlcd.clear();<br \/>\n}<\/p>\n<p>void loop() {<\/p>\n<p>rotating = true; \/\/ reset the debouncer<\/p>\n<p>if (lastReportedPos != encoderPos) {<br \/>\nencoderPos = constrain(encoderPos, 87.5, 107.9);<br \/>\nradio.setFrequency(encoderPos);<br \/>\nlcd.clear();<br \/>\nlcd.setCursor(1, 0);<br \/>\nlcd.print(&#8220;Z-HUT FM RADIO&#8221;);<br \/>\nlcd.setCursor(5, 1);<br \/>\nlcd.print(encoderPos);<br \/>\nlastReportedPos = encoderPos;<\/p>\n<p>}<br \/>\nif (digitalRead(lcdButton) == LOW ) \/\/ LCD light on &amp; off<br \/>\n{<br \/>\nif (state == 0)<br \/>\n{<br \/>\ndigitalWrite(lcdLight, HIGH);<br \/>\nstate = 1;<br \/>\ndelay(500);<br \/>\n}<br \/>\nelse if (state == 1)<br \/>\n{<br \/>\ndigitalWrite(lcdLight, LOW);<br \/>\nstate = 0;<br \/>\ndelay(500);<br \/>\n}<br \/>\n}<\/p>\n<p>\/\/ preset buttons \/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/ add more as needed<\/p>\n<p>if (digitalRead(ps1Button) == LOW ) \/\/ preset #1<br \/>\n{<br \/>\nencoderPos = 93.7;<br \/>\n}<br \/>\nif (digitalRead(ps2Button) == LOW ) \/\/ Preset #2<br \/>\n{<br \/>\nencoderPos = 101.7;<br \/>\n}<br \/>\nif (digitalRead(ps3Button) == LOW ) \/\/ preset #3<br \/>\n{<br \/>\nencoderPos = 104.7;<br \/>\n}<br \/>\n}<\/p>\n<p>\/\/ Interrupt on A changing state<br \/>\nvoid doEncoderA() {<br \/>\n\/\/ debounce<br \/>\nif ( rotating ) delay (1); \/\/ wait a little until the bouncing is done<\/p>\n<p>\/\/ Test transition, did things really change?<br \/>\nif ( digitalRead(encoderPinA) != A_set ) { \/\/ debounce once more<br \/>\nA_set = !A_set;<br \/>\n\/\/ adjust counter + if A leads B<br \/>\nif ( A_set &amp;&amp; !B_set )<br \/>\nencoderPos += .1;<\/p>\n<p>rotating = false; \/\/ no more debouncing until loop() hits again<br \/>\n}<br \/>\n}<\/p>\n<p>\/\/ Interrupt on B changing state<br \/>\nvoid doEncoderB() {<br \/>\nif ( rotating ) delay (1);<br \/>\nif ( digitalRead(encoderPinB) != B_set ) {<br \/>\nB_set = !B_set;<br \/>\n\/\/ adjust counter &#8211; 1 if B leads A<br \/>\nif ( B_set &amp;&amp; !A_set )<br \/>\nencoderPos -= .1;<\/p>\n<p>rotating = false;<br \/>\n}<br \/>\n}<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Today we will be trying to take over the world by building our own Arduino controlled TEA5767 FM radio with LCD display, rotary encoder tuning, presets and an optional 30 watt stereo amplifier. &nbsp; Check us out on Facebook! &nbsp; &hellip; <a href=\"https:\/\/thezhut.com\/?page_id=1069\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"parent":1009,"menu_order":5,"comment_status":"closed","ping_status":"closed","template":"","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":"","_links_to":"","_links_to_target":""},"class_list":["post-1069","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"https:\/\/thezhut.com\/index.php?rest_route=\/wp\/v2\/pages\/1069","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/thezhut.com\/index.php?rest_route=\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/thezhut.com\/index.php?rest_route=\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/thezhut.com\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/thezhut.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1069"}],"version-history":[{"count":1,"href":"https:\/\/thezhut.com\/index.php?rest_route=\/wp\/v2\/pages\/1069\/revisions"}],"predecessor-version":[{"id":1463,"href":"https:\/\/thezhut.com\/index.php?rest_route=\/wp\/v2\/pages\/1069\/revisions\/1463"}],"up":[{"embeddable":true,"href":"https:\/\/thezhut.com\/index.php?rest_route=\/wp\/v2\/pages\/1009"}],"wp:attachment":[{"href":"https:\/\/thezhut.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1069"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}