{"id":467,"date":"2020-07-03T20:55:13","date_gmt":"2020-07-03T20:55:13","guid":{"rendered":"http:\/\/socmaker.com\/?p=467"},"modified":"2020-07-10T19:28:26","modified_gmt":"2020-07-10T19:28:26","slug":"infrared-sending-part-2","status":"publish","type":"post","link":"https:\/\/socmaker.com\/?p=467","title":{"rendered":"Infrared Sending Part 2"},"content":{"rendered":"\n<h4 class=\"wp-block-heading\">Parts<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">In the previous post, I gave you the internals of the PSOC to create the IR transmitter.  I experimented with several IR LED&#8217;s and eventually settled on some LED&#8217;s from Vishay.  Their TSAL6xxx series is a good through hole part, available at Mouser.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The external transistor can be an N channel Mosfet (Metal Oxide Semiconductor, Field Effect Transistor) such as the <a href=\"https:\/\/smile.amazon.com\/gp\/product\/B07BKX255D\/ref=ppx_yo_dt_b_asin_title_o05_s00?ie=UTF8&amp;psc=1\">2n7000<\/a>, available from  Amazon (follow the link) or Mouser.  You can also get a NPN darlington, such as a BC517 in a <a href=\"https:\/\/smile.amazon.com\/dp\/B075RTVMHY\/ref=dp_cerb_2\">kit<\/a> from Amazon, also available at  Mouser.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">To wire up the IR, the following circuit is used for the FET:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"789\" height=\"302\" src=\"https:\/\/socmaker.com\/wp-content\/uploads\/2020\/07\/FET_Driver.jpeg\" alt=\"\" class=\"wp-image-468\" srcset=\"https:\/\/socmaker.com\/wp-content\/uploads\/2020\/07\/FET_Driver.jpeg 789w, https:\/\/socmaker.com\/wp-content\/uploads\/2020\/07\/FET_Driver-300x115.jpeg 300w, https:\/\/socmaker.com\/wp-content\/uploads\/2020\/07\/FET_Driver-768x294.jpeg 768w\" sizes=\"auto, (max-width: 789px) 100vw, 789px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">The gate of the FET goes into the PSOC.  The output pin is configured as a resistive pull up output.  If you wire up a Darlington, the schematic is essentially the same configuration.  That configuration was shown in the previous post, <a href=\"https:\/\/socmaker.com\/?p=442\">Infrared Sending Part 1<\/a>.  The Q1\/Q2 pair is the schematic representation of the darlington transistor.  The &#8220;base&#8221; is attached to the PSOC output pin, the &#8220;emitter&#8221; is ground, and the &#8220;collector&#8221; goes to the LED Cathode.  A 5 ohm resistor to 5 volts limits the current during the transmission phase.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Software<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">To &#8220;Play&#8221; the IR command, an extra line is added to main.c in the for(;;) loop.  The handle_playIR(); routine looks for work to do and starts the interrupt driven process of playing the IR command requested:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/* ========================================\n * Copyright Wade Maxfield, 2020\n * All Rights Reserved\n * LICENSED SOFTWARE.\n *  Under the GPL v3 license\n * This license does not override previous licenses\n * Some information may be Proprietary to \n * Cypress (http:\/\/www.cypress.com) for their\n * PSoC 5LP\u00ae--Cypress Semiconductor and\n * only usable on their devices.\n * PROPERTY OF Wade Maxfield.\n * Commercial license available\n * ========================================\n*\/\n#include \"main.h\"\n\nint16_t TemperatureReadingAvailable;\nfloat temperature;\nint main(void)\n{\n    \/\/ the following two variables are for USBSerial\/Command Parser\n    int16 bufNum;\n    USBSerialMessage *USBRxPtr;\n\n    init_milliseconds();\n    init_leds();\n    \n    CyGlobalIntEnable; \/* Enable global interrupts. *\/\n\n    initUSBSerial();\/\/ setup the USB serial interface.\n    init_parse();\n    init_capture();\/\/ set up the I\/R Capture hardware\n\n    \n    for(;;)\n    {\n        \n        BlinkLed1(100); \/\/ blink 10 times per second (every 100ms)\n\n        \/\/======================\n        \/\/ usb serial port\n        \/\/======================\n        if ((bufNum=handleUSBSerial())>=0){\n            USBRxPtr=&amp;USBRxBuffer&#91;bufNum];\n           parse((char*)(USBRxPtr->msg),(uint16*)&amp;(USBRxPtr->size)); \/\/ handle possible command   \n        }\n        \n        temperature=getTemperatureF(&amp;TemperatureReadingAvailable); \n        if (TemperatureReadingAvailable) {\n             \/\/ write your code here to do something\n        }\n\n        \/\/===========================\n        \/\/ if the user has chosen to \n        \/\/ read the I\/R controller.\n        \/\/===========================\n        handle_capture();\n        \n        \n        handle_playIR(); \/\/ handles scheduling of ir commands\n\n\n    }<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">In order to play the IR command from a user interface, the parseCommands.c file must be added to.  Insert the following routine into the parseCommands.c:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>int16 handlePlayIR() {\n    \n    \/\/ play \n    printMessage(\"For Equipment: \");\n    if (!CurrentEquipmentID)\n       printMessage(\"Fridgidaire\\n\\r\");\n    else \n        printMessage(\"GE\" \"\\n\\r\");\n\n    printMessage(\"Playing IR sequence \");\n    switch (commandBuffer&#91;1]){\n        case 'u':case'U':\n            captureType=upType;\n            printMessage(\"of UP button.\\n\\r\");\n        break;\n        case 'd':case'D':\n            captureType=downType;\n            printMessage(\"of DOWN button.\\n\\r\");\n        break;\n        case 'P':case'p':\n            captureType=powerType;\n            printMessage(\"of POWER button.\\n\\r\");\n        break;\n            \n        case 'h':case 'H':\n            if (CurrentEquipmentID==GE_ID){\n                printMessage(\"Command Not Available for GE\\n\\r\");\n                \/\/goto printSignon;\n                return 1;\n            }\n            captureType=heatType;\n            printMessage(\"of HEAT select button.\\n\\r\");\n        break;\n            \n        case 'm': case 'M':\n            if (CurrentEquipmentID==FRIDGIDAIRE_ID){\n                printMessage(\"MODE Command Not Available for Frigidaire\\n\\r\");\n                \/\/goto printSignon;\n                return 1;\n            }\n            captureType=modeType;\n            printMessage(\"of MODE select button.\\n\\r\");\n        break;\n            \n            \n        case 'c':case 'C':\n            if (CurrentEquipmentID==GE_ID){\n                printMessage(\"Command Not Available for GE\\n\\r\");\n               \/\/ goto printSignon;\n                return 1;\n            }\n            captureType=coolType;\n            printMessage(\"of COOL select button.\\n\\r\");\n        break;\n        \n        default:\n            printMessage(\"\\n\\rCommand not understood\\n\\r\");\n           \/\/ goto printSignon;\n            return 1;\n    }\n    \n    playIRSignal(captureType,CurrentEquipmentID);\n    return 1;\n}\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">In the function parse() in parseCommands.c, in the &#8220;switch(commandBuffer[0])&#8221; { section of code, add the following case statements:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>         case 'p': case 'P':\n             if (handlePlayIR())\n                 goto printSignon;\n                \n         break;\n            \n         case 's': case 'S':{\n             \/\/ select equip\n             if (commandBuffer&#91;1]=='1'){\n                 CurrentEquipmentID = GE_ID;\n                 printMessage(\"GE chosen\\n\\r\");\n             } else {\n                 CurrentEquipmentID = FRIDGIDAIRE_ID;\n                 printMessage(\"Fridgidaire chosen\\n\\r\");\n             }\n             goto printSignon;\n               \n         }break;<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Under the &#8220;case &#8216;v&#8217;:&#8221; selection in parse, where the available commands are printed, add the following printMessage() statements:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>printMessage(\" P&#91;]    -- Play IR &#91;]==U,D,P,H,C (up, down, power, heat, cool)\\n\\r\");\nprintMessage(\" S&#91;]    -- Select equipment 0=FR,1=GE, default 0\\n\\r\");\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">This will give you some options over the serial USB uart that has been created.  Once you hook up the FET or Darlington with an LED and a resistor, you should be able to play an A\/C on\/off command to the unit by pointing the LED to the panel and selecting the command line code.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Don&#8217;t forget to add the include for playIR.h in your main.h file:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>#ifndef _MAIN_H_\n    #define _MAIN_H_\n\/* ========================================\n * Copyright Wade Maxfield, 2020\n * All Rights Reserved\n * LICENSED SOFTWARE.\n *  Under the GPL v3 license\n * This license does not override previous licenses\n * Some information may be Proprietary to \n * Cypress (http:\/\/www.cypress.com) for their\n * PSoC 5LP\u00ae--Cypress Semiconductor and\n * only usable on their devices.\n * PROPERTY OF Wade Maxfield.\n * Commercial license available\n * ========================================\n*\/  \n#include &lt;project.h>\n#include &lt;stdio.h>\n#include \"parseCommands.h\"\n#include \"USBSerial.h\"\n#include \"ds18b20.h\"\n#include \"Milliseconds.h\"\n#include \"Leds.h\"\n#include \"captureIR.h\"\n#include \"playIR.h\"\n    \n#endif<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Now add the playIR.c file (if not already added) .  Go back to the previous post in this series to get the code.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Change Milliseconds.c to add the playIRFlag.  I also added some time flags for future use:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>volatile uint32 milliseconds;\nvolatile uint16 ms,seconds, minutes, hours;\nvolatile int16 MsLedCounter;\nint16 timeFlag1,timeFlag2,playIRFlag;\/\/&lt;---added playIR\n\nCY_ISR(MillisecondInterrupt) {\n    milliseconds++;\n    MsLedCounter++;\n    timeFlag1=timeFlag2=playIRFlag=1; \/\/ set the millisecond flags\n\n    \n    if (++ms>=1000){\n        ms=0;\n        if (++seconds>=60){\n            seconds=0;\n            if (++minutes >=60) {\n                minutes=0;\n                if (++hours>=24){\n                    hours=0;\n                }\n            }\n        }\n    }\n        \n}\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Add the playIRFlag to Milliseconds.h:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>    \/\/ the following counter can be used to start things on 1 millisecond boundaries\nextern volatile uint16 ms,seconds, minutes, hours;    \nextern volatile uint32 milliseconds;\nextern volatile int16 MsLedCounter;\nextern int16 playIRFlag; \/\/&lt;--- added for playir.c\n    \nvoid init_milliseconds();\n\n#endif<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">Next Time<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">If all goes well, next time we will look at the temperature control algorithm.  At that point you have a functional A\/C controller without a GUI (Graphics User Interface), sitting on a breadboard. <\/p>\n\n\n\n<p class=\"wp-block-paragraph\">I created an Eagle Circuit board for this project as a test bed.  I will share that with you after the temperature control is done, plus how to order boards for yourself from OSHPark.  <\/p>\n\n\n\n<p class=\"wp-block-paragraph\">One of my goals for this project is to have a hand buildable project.  You can use a soldering iron and put everything together at your workbench, no special tools needed.  This fits with the maker mentality, use commercially available parts to make something unique.  (That is also why the project is based around the CY8CKIT-059).<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"> We will get into the user interface design and implementation after the circuit board.  For my GUI (Graphics User Interface), I used the Nextion series of displays, available on Amazon or from the website BangGood.com.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Enjoy!<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Parts In the previous post, I gave you the internals of the PSOC to create the IR transmitter. I experimented with several IR LED&#8217;s and eventually settled on some LED&#8217;s from Vishay. Their TSAL6xxx series is a good through hole part, available at Mouser. The external transistor can be an N channel Mosfet (Metal Oxide [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-467","post","type-post","status-publish","format-standard","hentry","category-blogposts"],"_links":{"self":[{"href":"https:\/\/socmaker.com\/index.php?rest_route=\/wp\/v2\/posts\/467","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/socmaker.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/socmaker.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/socmaker.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/socmaker.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=467"}],"version-history":[{"count":10,"href":"https:\/\/socmaker.com\/index.php?rest_route=\/wp\/v2\/posts\/467\/revisions"}],"predecessor-version":[{"id":504,"href":"https:\/\/socmaker.com\/index.php?rest_route=\/wp\/v2\/posts\/467\/revisions\/504"}],"wp:attachment":[{"href":"https:\/\/socmaker.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=467"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/socmaker.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=467"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/socmaker.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=467"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}