{"id":9773,"date":"2024-03-25T11:46:39","date_gmt":"2024-03-25T11:46:39","guid":{"rendered":"https:\/\/www.bairesdev.com\/tools\/tessel\/?p=9773"},"modified":"2024-05-09T11:05:55","modified_gmt":"2024-05-09T11:05:55","slug":"module-communication-protocols","status":"publish","type":"post","link":"https:\/\/www.bairesdev.com\/tools\/tessel\/docs\/module-communication-protocols\/","title":{"rendered":"Module Communication Protocols"},"content":{"rendered":"\n<p>Each of the two&nbsp;ports&nbsp;on Tessel 2 exposes ten&nbsp;pins&nbsp;for use in creating custom modules. Two of the&nbsp;pins&nbsp;are for power (3.3V and ground) and the other eight are configurable&nbsp;GPIO&nbsp;(General Purpose Input and Output)&nbsp;pins&nbsp;that can be used to communicate with your module.<\/p>\n\n\n\n<p>All eight communication&nbsp;pins&nbsp;allow for communication through changes in voltage: some through variable voltage between 0V and 3.3V (analog&nbsp;pins), some through simple on\/off (0V\/3.3V) states (digital&nbsp;pins), and some through special&nbsp;digital&nbsp;toggling referred to by their&nbsp;communication protocols.&nbsp;Communication protocols&nbsp;(such as&nbsp;SPI,&nbsp;I2C, and&nbsp;UART) involve a pre-defined set of&nbsp;pins&nbsp;used in a specific way. These protocols are used to encode complex messages. It&#8217;s a lot like&nbsp;<a href=\"http:\/\/en.wikipedia.org\/wiki\/Morse_code\" target=\"_blank\" rel=\"noreferrer noopener\">Morse code<\/a>, but for electronics.<\/p>\n\n\n\n<p>In embedded electronics, there are four common protocols and Tessel&nbsp;supports them all in JavaScript.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"https:\/\/www.bairesdev.com\/tools\/tessel\/doc\/tutorials\/module-communication-protocols\/#GPIO\">GPIO<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/www.bairesdev.com\/tools\/tessel\/doc\/tutorials\/module-communication-protocols\/#spi\">SPI<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/www.bairesdev.com\/tools\/tessel\/doc\/tutorials\/module-communication-protocols\/#i2c\">I2C<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/www.bairesdev.com\/tools\/tessel\/doc\/tutorials\/module-communication-protocols\/#uart\">UART<\/a><\/li>\n<\/ul>\n\n\n\n<p>This guide will provide a brief overview of the protocols and cover some of the strengths and weaknesses of each.<\/p>\n\n\n\n<p>You can see a mapping of which&nbsp;pins&nbsp;can be used for which protocols&nbsp;on the Tessel docs page.<\/p>\n\n\n\n<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_66_1 counter-hierarchy ez-toc-counter ez-toc-grey ez-toc-container-direction\">\n<div class=\"ez-toc-title-container\">\n<p class=\"ez-toc-title \" >Table of Contents<\/p>\n<span class=\"ez-toc-title-toggle\"><a href=\"#\" class=\"ez-toc-pull-right ez-toc-btn ez-toc-btn-xs ez-toc-btn-default ez-toc-toggle\" aria-label=\"Toggle Table of Content\"><span class=\"ez-toc-js-icon-con\"><span class=\"\"><span class=\"eztoc-hide\" style=\"display:none;\">Toggle<\/span><span class=\"ez-toc-icon-toggle-span\"><svg style=\"fill: #999;color:#999\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" class=\"list-377408\" width=\"20px\" height=\"20px\" viewBox=\"0 0 24 24\" fill=\"none\"><path d=\"M6 6H4v2h2V6zm14 0H8v2h12V6zM4 11h2v2H4v-2zm16 0H8v2h12v-2zM4 16h2v2H4v-2zm16 0H8v2h12v-2z\" fill=\"currentColor\"><\/path><\/svg><svg style=\"fill: #999;color:#999\" class=\"arrow-unsorted-368013\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"10px\" height=\"10px\" viewBox=\"0 0 24 24\" version=\"1.2\" baseProfile=\"tiny\"><path d=\"M18.2 9.3l-6.2-6.3-6.2 6.3c-.2.2-.3.4-.3.7s.1.5.3.7c.2.2.4.3.7.3h11c.3 0 .5-.1.7-.3.2-.2.3-.5.3-.7s-.1-.5-.3-.7zM5.8 14.7l6.2 6.3 6.2-6.3c.2-.2.3-.5.3-.7s-.1-.5-.3-.7c-.2-.2-.4-.3-.7-.3h-11c-.3 0-.5.1-.7.3-.2.2-.3.5-.3.7s.1.5.3.7z\"\/><\/svg><\/span><\/span><\/span><\/a><\/span><\/div>\n<nav><ul class='ez-toc-list ez-toc-list-level-1 ' ><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/www.bairesdev.com\/tools\/tessel\/docs\/module-communication-protocols\/#Quick_Reference\" title=\"Quick Reference\">Quick Reference<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/www.bairesdev.com\/tools\/tessel\/docs\/module-communication-protocols\/#A_Note_on_Level_Shifting\" title=\"A Note on Level Shifting\">A Note on Level Shifting<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/www.bairesdev.com\/tools\/tessel\/docs\/module-communication-protocols\/#GPIO\" title=\"GPIO\">GPIO<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/www.bairesdev.com\/tools\/tessel\/docs\/module-communication-protocols\/#SPI\" title=\"SPI\">SPI<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-5\" href=\"https:\/\/www.bairesdev.com\/tools\/tessel\/docs\/module-communication-protocols\/#I2C\" title=\"I2C\">I2C<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-6\" href=\"https:\/\/www.bairesdev.com\/tools\/tessel\/docs\/module-communication-protocols\/#UART\" title=\"UART\">UART<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-7\" href=\"https:\/\/www.bairesdev.com\/tools\/tessel\/docs\/module-communication-protocols\/#TX\" title=\"TX\">TX<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-8\" href=\"https:\/\/www.bairesdev.com\/tools\/tessel\/docs\/module-communication-protocols\/#RX\" title=\"RX\">RX<\/a><\/li><\/ul><\/li><\/ul><\/nav><\/div>\n<h2 class=\"wp-block-heading\" id=\"quick-reference\"><span class=\"ez-toc-section\" id=\"Quick_Reference\"><\/span>Quick Reference<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>Most of the time, you will choose your protocol based on the parts you are using when designing your module. Other things to consider are the&nbsp;pins&nbsp;you have available, as well as your communication speed requirements. The following table can be used as a quick reference for the more detailed explanations of each protocol below.<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>Protocol<\/th><th>#&nbsp;Pins&nbsp;Required<\/th><th>Max Speed<\/th><\/tr><\/thead><tbody><tr><td>GPIO<\/td><td><strong>1<\/strong><\/td><td>1kHz<\/td><\/tr><tr><td>SPI<\/td><td><strong>3+<\/strong>&nbsp;(MOSI,&nbsp;MISO,&nbsp;SCK&nbsp;+ 1&nbsp;GPIO&nbsp;pin)<\/td><td>25MBit\/s<\/td><\/tr><tr><td>I2C<\/td><td><strong>2<\/strong>&nbsp;(SCL&nbsp;and&nbsp;SDA)<\/td><td>100kHz or 400kHz configurable by&nbsp;module port<\/td><\/tr><tr><td>UART<\/td><td><strong>2<\/strong>&nbsp;(TX&nbsp;and&nbsp;RX)<\/td><td>8Mbit\/s<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"a-note-on-level-shifting\"><span class=\"ez-toc-section\" id=\"A_Note_on_Level_Shifting\"><\/span>A Note on Level Shifting<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>All of the diagrams and discussions below regarding&nbsp;communication protocols&nbsp;assume that the hardware modules you are communicating with operate at 3.3V, just like the Tessel.<\/p>\n\n\n\n<p>If you have a device on your custom module that operates at 5V, 1.8V, or any other non-3.3V voltage, be careful! Directly connecting components with different operating voltages can damage the Tessel and\/or your device.<\/p>\n\n\n\n<p>You can use devices which operate at different voltages by employing a technique called &#8216;level shifting&#8217;. Sparkfun has a&nbsp;<a href=\"https:\/\/learn.sparkfun.com\/tutorials\/voltage-dividers\" target=\"_blank\" rel=\"noreferrer noopener\">nice writeup on voltage dividers and level shifting<\/a>&nbsp;that can be used as a starting point.<\/p>\n\n\n\n<p>The easiest way to avoid this complication is by trying to find module components that natively work at 3.3V.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"gpio\"><span class=\"ez-toc-section\" id=\"GPIO\"><\/span>GPIO<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p><strong>Pros:<\/strong>&nbsp;Simple, Requires a single pin<\/p>\n\n\n\n<p><strong>Cons:<\/strong>&nbsp;Not good for sending complex data<\/p>\n\n\n\n<p>By far the simplest form of communication is via General Purpose Input\/Output (GPIO).&nbsp;GPIO&nbsp;isn&#8217;t really a &#8216;protocol&#8217;. It is a rudimentary form of communication where you manually (in code) turn a pin on and off or read its state.<\/p>\n\n\n\n<p>By default, Tessel&#8217;s&nbsp;GPIO&nbsp;pins&nbsp;are configured to be inputs.<\/p>\n\n\n\n<p><a href=\"https:\/\/www.bairesdev.com\/tools\/tessel\/doc\/api\/hardware-api\/\" target=\"_blank\" rel=\"noreferrer noopener\">See which pins support this protocol.<\/a><\/p>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"input\">Input<\/h4>\n\n\n\n<p>When acting as a&nbsp;digital&nbsp;input, a pin can be queried in software and will return a value indicating the current state of the pin: high (1 or true) or low (0 or false).<\/p>\n\n\n\n<p>The following code snippet is an example of querying pin 2 on port A.<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#2e3440ff\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"const tessel = require('tessel'); \/\/ Import tessel\nconst pin = tessel.port.A.pin[2]; \/\/ Select pin 2 on port A\npin.read((error, value) =&gt; {\n  \/\/ Print the pin value to the console\n  console.log(value);\n});\" style=\"color:#d8dee9ff;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki nord\" style=\"background-color: #2e3440ff\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #81A1C1\">const<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #D8DEE9\">tessel<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #81A1C1\">=<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #88C0D0\">require<\/span><span style=\"color: #D8DEE9FF\">(<\/span><span style=\"color: #ECEFF4\">&#39;<\/span><span style=\"color: #A3BE8C\">tessel<\/span><span style=\"color: #ECEFF4\">&#39;<\/span><span style=\"color: #D8DEE9FF\">)<\/span><span style=\"color: #81A1C1\">;<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #616E88\">\/\/ Import tessel<\/span><\/span>\n<span class=\"line\"><span style=\"color: #81A1C1\">const<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #D8DEE9\">pin<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #81A1C1\">=<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #D8DEE9\">tessel<\/span><span style=\"color: #ECEFF4\">.<\/span><span style=\"color: #D8DEE9\">port<\/span><span style=\"color: #ECEFF4\">.<\/span><span style=\"color: #D8DEE9\">A<\/span><span style=\"color: #ECEFF4\">.<\/span><span style=\"color: #D8DEE9\">pin<\/span><span style=\"color: #D8DEE9FF\">[<\/span><span style=\"color: #B48EAD\">2<\/span><span style=\"color: #D8DEE9FF\">]<\/span><span style=\"color: #81A1C1\">;<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #616E88\">\/\/ Select pin 2 on port A<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9\">pin<\/span><span style=\"color: #ECEFF4\">.<\/span><span style=\"color: #88C0D0\">read<\/span><span style=\"color: #D8DEE9FF\">(<\/span><span style=\"color: #ECEFF4\">(<\/span><span style=\"color: #D8DEE9\">error<\/span><span style=\"color: #ECEFF4\">,<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #D8DEE9\">value<\/span><span style=\"color: #ECEFF4\">)<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #81A1C1\">=&gt;<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #ECEFF4\">{<\/span><\/span>\n<span class=\"line\"><span style=\"color: #ECEFF4\">  <\/span><span style=\"color: #616E88\">\/\/ Print the pin value to the console<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">  <\/span><span style=\"color: #D8DEE9\">console<\/span><span style=\"color: #ECEFF4\">.<\/span><span style=\"color: #88C0D0\">log<\/span><span style=\"color: #D8DEE9FF\">(<\/span><span style=\"color: #D8DEE9\">value<\/span><span style=\"color: #D8DEE9FF\">)<\/span><span style=\"color: #81A1C1\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #ECEFF4\">}<\/span><span style=\"color: #D8DEE9FF\">)<\/span><span style=\"color: #81A1C1\">;<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<p>This is great for connecting things like&nbsp;switches, buttons, and even&nbsp;motion detectors. Just remember that the Tessel can only handle signals that are 3.3V or lower.<\/p>\n\n\n\n<h5 class=\"wp-block-heading\" id=\"determining-digital-state\u2013-a-note-for-the-curious\">Determining digital state\u2013 a note for the curious:<\/h5>\n\n\n\n<p>It&#8217;s pretty clear that if an input pin sees 3.3V it would be interpreted as a high state and if the pin is connected to ground it would recognize that as a low state. But what if the pin senses something in between, like 2V?<\/p>\n\n\n\n<p>Your first thought might be that a high state is anything 1.65V (halfway between 0 and 3.3) or higher, and anything lower than that would be considered the low state. However, this is not always the case.<\/p>\n\n\n\n<p>The high\/low threshold is always determined by the processor. In the case of the Tessel 2, that&#8217;s the SAM D21. The&nbsp;documentation on the SAM D21&nbsp;tells us that the Tessel will consider an input to be high if it is at least 55% of the Tessel&#8217;s supply voltage (VDD) which is 3.3V. It also tells us that any signal that is 30% of VDD or lower is guaranteed to be read as a low state. That means anything 1.815V (referenced as VIH) or higher would be considered high, and anything .99V (referenced as VIL) or lower is guaranteed to be interpreted as a low state.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img fetchpriority=\"high\" decoding=\"async\" width=\"707\" height=\"353\" src=\"https:\/\/www.bairesdev.com\/tools\/tessel\/wp-content\/uploads\/2024\/03\/QsfwGSn.png\" alt=\"\" class=\"wp-image-10114\" srcset=\"https:\/\/www.bairesdev.com\/tools\/tessel\/wp-content\/uploads\/2024\/03\/QsfwGSn.png 707w, https:\/\/www.bairesdev.com\/tools\/tessel\/wp-content\/uploads\/2024\/03\/QsfwGSn-300x150.png 300w\" sizes=\"(max-width: 707px) 100vw, 707px\" \/><\/figure>\n\n\n\n<p><em>A screen capture from the electrical characteristics section of [Atmel&#8217;s SAM D21&nbsp;datasheet](http:\/\/www.atmel.com\/Images\/Atmel-42181-SAM-D21_Datasheet.pdf)<\/em><\/p>\n\n\n\n<p>What about the voltages between .99V and 1.815V? The read behavior is undefined and you are not guaranteed to get an accurate result. That&#8217;s one reason why it&#8217;s important to make sure that any module you connect to a Tessel input pin provides a high voltage that is between VIH and 3.3V and a low voltage between ground and VIL.<\/p>\n\n\n\n<p><a href=\"https:\/\/www.bairesdev.com\/tools\/tessel\/doc\/api\/hardware-api\/#digital-pins\" target=\"_blank\" rel=\"noreferrer noopener\">More GPIO example code and information<\/a><\/p>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"output\">Output<\/h4>\n\n\n\n<p>When acting as a&nbsp;digital&nbsp;output, a pin can be set to one of two states: high (on\/1\/true) or low (off\/0\/false). High means the main Tessel board will set that pin to be 3.3V and low means it will set it to 0V.<\/p>\n\n\n\n<p>Digital&nbsp;output is useful for connected hardware that understands simple on\/off states. The following code snippet shows how you can set the state of the pin 2 on port A.<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#2e3440ff\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"const tessel = require('tessel'); \nconst pin = tessel.port.A.pin[2]; \/\/ Select pin 2 on port A\npin.output(1);  \/\/ Turn pin high (on)\npin.read((error, value) =&gt; {\n  \/\/ Print the pin value to the console\n  console.log(value);\n  pin.output(0);  \/\/ Turn pin low (off)\n});\" style=\"color:#d8dee9ff;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki nord\" style=\"background-color: #2e3440ff\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #81A1C1\">const<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #D8DEE9\">tessel<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #81A1C1\">=<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #88C0D0\">require<\/span><span style=\"color: #D8DEE9FF\">(<\/span><span style=\"color: #ECEFF4\">&#39;<\/span><span style=\"color: #A3BE8C\">tessel<\/span><span style=\"color: #ECEFF4\">&#39;<\/span><span style=\"color: #D8DEE9FF\">)<\/span><span style=\"color: #81A1C1\">;<\/span><span style=\"color: #D8DEE9FF\"> <\/span><\/span>\n<span class=\"line\"><span style=\"color: #81A1C1\">const<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #D8DEE9\">pin<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #81A1C1\">=<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #D8DEE9\">tessel<\/span><span style=\"color: #ECEFF4\">.<\/span><span style=\"color: #D8DEE9\">port<\/span><span style=\"color: #ECEFF4\">.<\/span><span style=\"color: #D8DEE9\">A<\/span><span style=\"color: #ECEFF4\">.<\/span><span style=\"color: #D8DEE9\">pin<\/span><span style=\"color: #D8DEE9FF\">[<\/span><span style=\"color: #B48EAD\">2<\/span><span style=\"color: #D8DEE9FF\">]<\/span><span style=\"color: #81A1C1\">;<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #616E88\">\/\/ Select pin 2 on port A<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9\">pin<\/span><span style=\"color: #ECEFF4\">.<\/span><span style=\"color: #88C0D0\">output<\/span><span style=\"color: #D8DEE9FF\">(<\/span><span style=\"color: #B48EAD\">1<\/span><span style=\"color: #D8DEE9FF\">)<\/span><span style=\"color: #81A1C1\">;<\/span><span style=\"color: #D8DEE9FF\">  <\/span><span style=\"color: #616E88\">\/\/ Turn pin high (on)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9\">pin<\/span><span style=\"color: #ECEFF4\">.<\/span><span style=\"color: #88C0D0\">read<\/span><span style=\"color: #D8DEE9FF\">(<\/span><span style=\"color: #ECEFF4\">(<\/span><span style=\"color: #D8DEE9\">error<\/span><span style=\"color: #ECEFF4\">,<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #D8DEE9\">value<\/span><span style=\"color: #ECEFF4\">)<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #81A1C1\">=&gt;<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #ECEFF4\">{<\/span><\/span>\n<span class=\"line\"><span style=\"color: #ECEFF4\">  <\/span><span style=\"color: #616E88\">\/\/ Print the pin value to the console<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">  <\/span><span style=\"color: #D8DEE9\">console<\/span><span style=\"color: #ECEFF4\">.<\/span><span style=\"color: #88C0D0\">log<\/span><span style=\"color: #D8DEE9FF\">(<\/span><span style=\"color: #D8DEE9\">value<\/span><span style=\"color: #D8DEE9FF\">)<\/span><span style=\"color: #81A1C1\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">  <\/span><span style=\"color: #D8DEE9\">pin<\/span><span style=\"color: #ECEFF4\">.<\/span><span style=\"color: #88C0D0\">output<\/span><span style=\"color: #D8DEE9FF\">(<\/span><span style=\"color: #B48EAD\">0<\/span><span style=\"color: #D8DEE9FF\">)<\/span><span style=\"color: #81A1C1\">;<\/span><span style=\"color: #D8DEE9FF\">  <\/span><span style=\"color: #616E88\">\/\/ Turn pin low (off)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #ECEFF4\">}<\/span><span style=\"color: #D8DEE9FF\">)<\/span><span style=\"color: #81A1C1\">;<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<p>Some examples of using a\u00a0GPIO\u00a0pin as an output are\u00a0simple LEDs\u00a0and for turning appliances on and off with a\u00a0<a href=\"https:\/\/www.bairesdev.com\/tools\/tessel\/modules\/relay\/\" target=\"_blank\" rel=\"noreferrer noopener\">relay<\/a>.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full is-resized\"><img decoding=\"async\" width=\"320\" height=\"213\" src=\"https:\/\/www.bairesdev.com\/tools\/tessel\/wp-content\/uploads\/2024\/03\/320px-5mm_Red_LED.jpg\" alt=\"\" class=\"wp-image-10116\" style=\"width:275px;height:auto\" srcset=\"https:\/\/www.bairesdev.com\/tools\/tessel\/wp-content\/uploads\/2024\/03\/320px-5mm_Red_LED.jpg 320w, https:\/\/www.bairesdev.com\/tools\/tessel\/wp-content\/uploads\/2024\/03\/320px-5mm_Red_LED-300x200.jpg 300w\" sizes=\"(max-width: 320px) 100vw, 320px\" \/><\/figure>\n\n\n\n<p><em>An output pin is perfect for controlling an&nbsp;LED. Image is licensed under the [Creative Commons Attribution-Share Alike 2.0 Generic](http:\/\/creativecommons.org\/licenses\/by-sa\/2.0\/deed.en) license.<\/em><\/p>\n\n\n\n<p><a href=\"https:\/\/www.bairesdev.com\/tools\/tessel\/doc\/api\/hardware-api\/#digital-pins\" target=\"_blank\" rel=\"noreferrer noopener\">More GPIO example code and information<\/a><\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"spi\"><span class=\"ez-toc-section\" id=\"SPI\"><\/span>SPI<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p><strong>Pros:<\/strong>&nbsp;Fast, supports multiple devices on a single bus, allows two-way communication<\/p>\n\n\n\n<p><strong>Cons:<\/strong>&nbsp;Requires at least 3&nbsp;pins<\/p>\n\n\n\n<p>SPI&nbsp;stands for&nbsp;<a href=\"http:\/\/en.wikipedia.org\/wiki\/Serial_Peripheral_Interface_Bus\" target=\"_blank\" rel=\"noreferrer noopener\">Serial Peripheral Interface<\/a>. The&nbsp;SPI&nbsp;protocol allows data to be exchanged one byte at a time between the Tessel and a module via two communication lines. This is great for transferring data like sensor readings or sending commands to a module.<\/p>\n\n\n\n<p>The&nbsp;SPI&nbsp;protocol is known as a&nbsp;Master\/Slave&nbsp;protocol, which means that there is always a single&nbsp;master&nbsp;device which controls the flow of communication with one or more&nbsp;slave&nbsp;devices. Think of the&nbsp;master&nbsp;as a traffic cop. It directs all of the connected&nbsp;slave&nbsp;devices so they know when it&#8217;s their turn to communicate.<\/p>\n\n\n\n<p>When you are creating modules, the Tessel will always act as the&nbsp;master&nbsp;device, and your custom module will be a&nbsp;slave&nbsp;device.<\/p>\n\n\n\n<p>The\u00a0SPI\u00a0protocol requires a minimum of three signal connections and usually has four (this is in addition to the power connections). The following diagram shows the connections (arrows indicate flow of data).<\/p>\n\n\n\n<p><em>The red lines constitute the shared bus connections used for talking to the&nbsp;slave&nbsp;devices. The green wire is the shared bus connection used by the slaves to talk to the&nbsp;master. The blue line is the chip select for signaling each&nbsp;slave&nbsp;individually.<\/em><\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" width=\"542\" height=\"180\" src=\"https:\/\/www.bairesdev.com\/tools\/tessel\/wp-content\/uploads\/2024\/03\/Simple_SPI.png\" alt=\"\" class=\"wp-image-10117\" srcset=\"https:\/\/www.bairesdev.com\/tools\/tessel\/wp-content\/uploads\/2024\/03\/Simple_SPI.png 542w, https:\/\/www.bairesdev.com\/tools\/tessel\/wp-content\/uploads\/2024\/03\/Simple_SPI-300x100.png 300w\" sizes=\"(max-width: 542px) 100vw, 542px\" \/><\/figure>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"sck\">SCK<\/h4>\n\n\n\n<p>This is the clock signal that keeps the Tessel and the module synchronized while transferring data. The two devices need to have a mutual understanding of how fast data is to be transferred between them. This is sometimes referred to as the baud or bitrate. The clock signal provides that reference signal for the devices to use when exchanging data.<\/p>\n\n\n\n<p>Without a clock signal to synchronize the devices, the devices would have no way to interpret the signal on the data lines.<\/p>\n\n\n\n<p>One bit of data is transferred with each clock cycle (see the diagram below).<\/p>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"mosi\">MOSI<\/h4>\n\n\n\n<p>MOSI&nbsp;stands for&nbsp;<strong>M<\/strong>aster&nbsp;<strong>O<\/strong>ut&nbsp;<strong>S<\/strong>lave&nbsp;<strong>I<\/strong>n and is the connection used by the Tessel to send data to the module. It&#8217;s on this line that the Tessel will encode its data.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"miso\">MISO<\/h4>\n\n\n\n<p>MISO&nbsp;stands for&nbsp;<strong>M<\/strong>aster&nbsp;<strong>I<\/strong>n&nbsp;<strong>S<\/strong>lave&nbsp;<strong>O<\/strong>ut and is the connection used by the module to send data to the Tessel.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"ss-or-cs\">SS or CS<\/h4>\n\n\n\n<p>This line, normally referred to as the&nbsp;<strong>Slave&nbsp;Select (SS)<\/strong>&nbsp;or&nbsp;<strong>Chip Select (CS)<\/strong>&nbsp;line, is used by the&nbsp;master&nbsp;device to notify a specific&nbsp;slave&nbsp;device that it is about to send data. We normally call it CS, but you may see it either way in datasheets and other references.<\/p>\n\n\n\n<p>When you create a&nbsp;Tessel module&nbsp;which uses the&nbsp;SPI&nbsp;protocol, the CS connection will be handled by one of the&nbsp;GPIO&nbsp;pins&nbsp;on the Tessel port.<\/p>\n\n\n\n<p>The following diagram shows how the various\u00a0pins\u00a0in the\u00a0SPI\u00a0protocol are toggled to create meaningful data. In this case, the\u00a0master\u00a0sends the ASCII character &#8216;S&#8217;, and the\u00a0slave\u00a0responds with &#8216;F&#8217;.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"495\" height=\"318\" src=\"https:\/\/www.bairesdev.com\/tools\/tessel\/wp-content\/uploads\/2024\/03\/spi_diagram.jpg\" alt=\"\" class=\"wp-image-10118\" srcset=\"https:\/\/www.bairesdev.com\/tools\/tessel\/wp-content\/uploads\/2024\/03\/spi_diagram.jpg 495w, https:\/\/www.bairesdev.com\/tools\/tessel\/wp-content\/uploads\/2024\/03\/spi_diagram-300x193.jpg 300w\" sizes=\"(max-width: 495px) 100vw, 495px\" \/><\/figure>\n\n\n\n<p><em>Timing diagram of&nbsp;SPI&nbsp;data exchange. Modified [image](https:\/\/dlnmh9ip6v2uc.cloudfront.net\/assets\/c\/7\/8\/7\/d\/52ddb2dcce395fed638b4567.png) from Sparkfun is [CC BY-NC-SA 3.0](http:\/\/creativecommons.org\/licenses\/by-nc-sa\/3.0\/)<\/em><\/p>\n\n\n\n<p>Remember that the&nbsp;master&nbsp;initiates all communication. When it is ready, the first thing it will do is pull the CS\/SS pin low to let the&nbsp;slave&nbsp;device know that a data transmission is about to begin. The&nbsp;master&nbsp;holds this pin low for the duration of the data exchange as seen in the diagram above.<\/p>\n\n\n\n<p>With the CS\/SS pin low, the&nbsp;master&nbsp;will start to toggle the clock pin (SCK) while simultaneously controlling the&nbsp;MOSI&nbsp;to represent the bits of information it wishes to send to the&nbsp;slave. The numbers in green on the diagram above delineate each bit in the byte being transferred.<\/p>\n\n\n\n<p>It sounds complicated, but remember that the Tessel takes care of all of this pin manipulation for you. All you have to do is write some Javascript like this code snippet, which demonstrates the use of the&nbsp;SPI&nbsp;protocol on port A.<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#2e3440ff\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"'use strict';\nconst tessel = require('tessel');\nconst port = tessel.port.A;\nconst spi = new port.SPI({\n  clockSpeed: 4000000 \/\/ 4MHz\n});\n\nspi.transfer(new Buffer([0xde, 0xad, 0xbe, 0xef]), (error, buffer) =&gt; {\n  console.log(`buffer returned by SPI slave: &lt;${[...buffer]}&gt;`);\n});\" style=\"color:#d8dee9ff;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki nord\" style=\"background-color: #2e3440ff\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #ECEFF4\">&#39;<\/span><span style=\"color: #A3BE8C\">use strict<\/span><span style=\"color: #ECEFF4\">&#39;<\/span><span style=\"color: #81A1C1\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #81A1C1\">const<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #D8DEE9\">tessel<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #81A1C1\">=<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #88C0D0\">require<\/span><span style=\"color: #D8DEE9FF\">(<\/span><span style=\"color: #ECEFF4\">&#39;<\/span><span style=\"color: #A3BE8C\">tessel<\/span><span style=\"color: #ECEFF4\">&#39;<\/span><span style=\"color: #D8DEE9FF\">)<\/span><span style=\"color: #81A1C1\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #81A1C1\">const<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #D8DEE9\">port<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #81A1C1\">=<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #D8DEE9\">tessel<\/span><span style=\"color: #ECEFF4\">.<\/span><span style=\"color: #D8DEE9\">port<\/span><span style=\"color: #ECEFF4\">.<\/span><span style=\"color: #D8DEE9\">A<\/span><span style=\"color: #81A1C1\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #81A1C1\">const<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #D8DEE9\">spi<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #81A1C1\">=<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #81A1C1\">new<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #D8DEE9\">port<\/span><span style=\"color: #ECEFF4\">.<\/span><span style=\"color: #88C0D0\">SPI<\/span><span style=\"color: #D8DEE9FF\">(<\/span><span style=\"color: #ECEFF4\">{<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">  <\/span><span style=\"color: #88C0D0\">clockSpeed<\/span><span style=\"color: #ECEFF4\">:<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #B48EAD\">4000000<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #616E88\">\/\/ 4MHz<\/span><\/span>\n<span class=\"line\"><span style=\"color: #ECEFF4\">}<\/span><span style=\"color: #D8DEE9FF\">)<\/span><span style=\"color: #81A1C1\">;<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9\">spi<\/span><span style=\"color: #ECEFF4\">.<\/span><span style=\"color: #88C0D0\">transfer<\/span><span style=\"color: #D8DEE9FF\">(<\/span><span style=\"color: #81A1C1\">new<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #88C0D0\">Buffer<\/span><span style=\"color: #D8DEE9FF\">([<\/span><span style=\"color: #B48EAD\">0xde<\/span><span style=\"color: #ECEFF4\">,<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #B48EAD\">0xad<\/span><span style=\"color: #ECEFF4\">,<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #B48EAD\">0xbe<\/span><span style=\"color: #ECEFF4\">,<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #B48EAD\">0xef<\/span><span style=\"color: #D8DEE9FF\">])<\/span><span style=\"color: #ECEFF4\">,<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #ECEFF4\">(<\/span><span style=\"color: #D8DEE9\">error<\/span><span style=\"color: #ECEFF4\">,<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #D8DEE9\">buffer<\/span><span style=\"color: #ECEFF4\">)<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #81A1C1\">=&gt;<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #ECEFF4\">{<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">  <\/span><span style=\"color: #D8DEE9\">console<\/span><span style=\"color: #ECEFF4\">.<\/span><span style=\"color: #88C0D0\">log<\/span><span style=\"color: #D8DEE9FF\">(<\/span><span style=\"color: #ECEFF4\">`<\/span><span style=\"color: #A3BE8C\">buffer returned by SPI slave: &lt;<\/span><span style=\"color: #81A1C1\">${<\/span><span style=\"color: #ECEFF4\">[<\/span><span style=\"color: #81A1C1\">...<\/span><span style=\"color: #D8DEE9\">buffer<\/span><span style=\"color: #ECEFF4\">]<\/span><span style=\"color: #81A1C1\">}<\/span><span style=\"color: #A3BE8C\">&gt;<\/span><span style=\"color: #ECEFF4\">`<\/span><span style=\"color: #D8DEE9FF\">)<\/span><span style=\"color: #81A1C1\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #ECEFF4\">}<\/span><span style=\"color: #D8DEE9FF\">)<\/span><span style=\"color: #81A1C1\">;<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<p><a href=\"https:\/\/www.bairesdev.com\/tools\/tessel\/doc\/api\/hardware-api\/#spi\" target=\"_blank\" rel=\"noreferrer noopener\">More SPI example code and information<\/a><\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"i2c\"><span class=\"ez-toc-section\" id=\"I2C\"><\/span>I2C<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p><strong>Pros:<\/strong>&nbsp;Only requires 2&nbsp;pins, multiple devices on a single bus, allows two-way communication<\/p>\n\n\n\n<p><strong>Cons:<\/strong>&nbsp;Devices can have address conflicts, not as fast as&nbsp;SPI<\/p>\n\n\n\n<p>I2C&nbsp;stands for&nbsp;<a href=\"http:\/\/en.wikipedia.org\/wiki\/I%C2%B2C\" target=\"_blank\" rel=\"noreferrer noopener\">Inter-Integrated Circuit<\/a>&nbsp;and is pronounced &#8220;I squared C&#8221;, &#8220;I two C&#8221; or &#8220;I-I-C&#8221;.&nbsp;I2C&nbsp;is a protocol that allows one device to exchange data with one or more connected devices through the use of a single data line and clock signal.<\/p>\n\n\n\n<p>I2C&nbsp;is a&nbsp;Master\/Slave&nbsp;protocol, which means that there is always a single&nbsp;master&nbsp;device which controls the flow of communication with one or more&nbsp;slave&nbsp;devices.<\/p>\n\n\n\n<p>I2C\u00a0only requires two communication connections:<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"274\" height=\"230\" src=\"https:\/\/www.bairesdev.com\/tools\/tessel\/wp-content\/uploads\/2024\/03\/Simple_I2C.png\" alt=\"\" class=\"wp-image-10119\"\/><\/figure>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"scl\">SCL<\/h4>\n\n\n\n<p>This is the clock signal that keeps the Tessel and the module synchronized while transferring data. The two devices need to have a mutual understanding of how fast data is to be transferred between them. This is sometimes referred to as the baud or bitrate. The clock signal provides that reference signal for the devices to use when exchanging data. Without a clock signal to synchronize the devices, they would have no way to interpret the signal on the data lines.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"sda\">SDA<\/h4>\n\n\n\n<p>This is the data line used for exchanging data between the&nbsp;master&nbsp;and slaves. Instead of having separate communication lines for the&nbsp;master&nbsp;and&nbsp;slave&nbsp;devices, they both share a single data connection. The&nbsp;master&nbsp;coordinates the usage of that connection so that only one device is &#8220;talking&#8221; at a time.<\/p>\n\n\n\n<p>Since multiple&nbsp;slave&nbsp;devices can use the same&nbsp;SDA&nbsp;line, the&nbsp;master&nbsp;needs a way to distinguish between them and talk to a single device at a time. The&nbsp;I2C&nbsp;protocol uses the concept of&nbsp;<strong>device addressing<\/strong>&nbsp;to coordinate traffic on the data line.<\/p>\n\n\n\n<p>Every single\u00a0I2C\u00a0device connected to the Tessel will have an internal address that cannot be the same as any other module connected to the Tessel. This address is usually determined by the device manufacturer and listed in the\u00a0datasheet. Sometimes you can configure the address through device-specific tweaks defined by the manufacturer. The Tessel, as the\u00a0master\u00a0device, needs to know the address of each\u00a0slave\u00a0and will use it to notify a device when it wants to communicate with it before transferring data.<\/p>\n\n\n\n<p><em>Flow of data between Tessel and multiple&nbsp;I2C&nbsp;devices.<\/em><\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"536\" height=\"234\" src=\"https:\/\/www.bairesdev.com\/tools\/tessel\/wp-content\/uploads\/2024\/03\/Multi_I2C.png\" alt=\"\" class=\"wp-image-10120\" srcset=\"https:\/\/www.bairesdev.com\/tools\/tessel\/wp-content\/uploads\/2024\/03\/Multi_I2C.png 536w, https:\/\/www.bairesdev.com\/tools\/tessel\/wp-content\/uploads\/2024\/03\/Multi_I2C-300x131.png 300w\" sizes=\"(max-width: 536px) 100vw, 536px\" \/><\/figure>\n\n\n\n<p>The following diagram illustrates how the\u00a0SDA\u00a0and\u00a0SCL\u00a0pins\u00a0are toggled when transferring data with the\u00a0I2C\u00a0protocol.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"229\" src=\"https:\/\/www.bairesdev.com\/tools\/tessel\/wp-content\/uploads\/2024\/03\/i2c_modified_timing-1024x229.png\" alt=\"\" class=\"wp-image-10121\" srcset=\"https:\/\/www.bairesdev.com\/tools\/tessel\/wp-content\/uploads\/2024\/03\/i2c_modified_timing-1024x229.png 1024w, https:\/\/www.bairesdev.com\/tools\/tessel\/wp-content\/uploads\/2024\/03\/i2c_modified_timing-300x67.png 300w, https:\/\/www.bairesdev.com\/tools\/tessel\/wp-content\/uploads\/2024\/03\/i2c_modified_timing-768x172.png 768w, https:\/\/www.bairesdev.com\/tools\/tessel\/wp-content\/uploads\/2024\/03\/i2c_modified_timing.png 1500w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>To begin a data transaction, the&nbsp;master&nbsp;creates what is called a start condition by pulling the&nbsp;SDA&nbsp;pin low before the&nbsp;SCL&nbsp;pin.<\/p>\n\n\n\n<p>The&nbsp;master&nbsp;then broadcasts the address of the device it wishes to communicate with by sending each bit of the 7 bit address. Notice the clock signal (SCL) is toggled for each bit. This toggling is how the slaves know when to read each bit of the address so they can determine with which device the&nbsp;master&nbsp;wants to communicate.<\/p>\n\n\n\n<p>Right after the address, the&nbsp;master&nbsp;sends a read\/write bit which signals whether it will be sending data to the&nbsp;slave&nbsp;or reading data from the&nbsp;slave.<\/p>\n\n\n\n<p>After broadcasting the address, the&nbsp;master&nbsp;either transmits data to the&nbsp;slave&nbsp;or sends the address of a&nbsp;register&nbsp;(internal storage) on the&nbsp;slave&nbsp;from which it wishes to retrieve data.<\/p>\n\n\n\n<p>Finally, the&nbsp;master&nbsp;will issue a stop condition on the bus by pulling&nbsp;SCL&nbsp;high, followed by&nbsp;SDA.<\/p>\n\n\n\n<p>It&#8217;s a little complicated, but the Tessel takes care of all the details for you. Using the&nbsp;I2C&nbsp;pins&nbsp;on port A looks like this:<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#2e3440ff\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"'use strict';\nconst tessel = require('tessel');\nconst port = tessel.port.A;\n\/\/ This is the address of the attached module\/sensor\nconst address = 0xDE; \nconst i2c = new port.I2C(address);\n\ni2c.send(new Buffer([0xde, 0xad, 0xbe, 0xef]), (error) =&gt; {\n  console.log(&quot;I'm done sending the data&quot;);\n  \/\/ Can also use err for error handling\n})\" style=\"color:#d8dee9ff;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki nord\" style=\"background-color: #2e3440ff\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #ECEFF4\">&#39;<\/span><span style=\"color: #A3BE8C\">use strict<\/span><span style=\"color: #ECEFF4\">&#39;<\/span><span style=\"color: #81A1C1\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #81A1C1\">const<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #D8DEE9\">tessel<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #81A1C1\">=<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #88C0D0\">require<\/span><span style=\"color: #D8DEE9FF\">(<\/span><span style=\"color: #ECEFF4\">&#39;<\/span><span style=\"color: #A3BE8C\">tessel<\/span><span style=\"color: #ECEFF4\">&#39;<\/span><span style=\"color: #D8DEE9FF\">)<\/span><span style=\"color: #81A1C1\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #81A1C1\">const<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #D8DEE9\">port<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #81A1C1\">=<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #D8DEE9\">tessel<\/span><span style=\"color: #ECEFF4\">.<\/span><span style=\"color: #D8DEE9\">port<\/span><span style=\"color: #ECEFF4\">.<\/span><span style=\"color: #D8DEE9\">A<\/span><span style=\"color: #81A1C1\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #616E88\">\/\/ This is the address of the attached module\/sensor<\/span><\/span>\n<span class=\"line\"><span style=\"color: #81A1C1\">const<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #D8DEE9\">address<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #81A1C1\">=<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #B48EAD\">0xDE<\/span><span style=\"color: #81A1C1\">;<\/span><span style=\"color: #D8DEE9FF\"> <\/span><\/span>\n<span class=\"line\"><span style=\"color: #81A1C1\">const<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #D8DEE9\">i2c<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #81A1C1\">=<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #81A1C1\">new<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #D8DEE9\">port<\/span><span style=\"color: #ECEFF4\">.<\/span><span style=\"color: #88C0D0\">I2C<\/span><span style=\"color: #D8DEE9FF\">(<\/span><span style=\"color: #D8DEE9\">address<\/span><span style=\"color: #D8DEE9FF\">)<\/span><span style=\"color: #81A1C1\">;<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9\">i2c<\/span><span style=\"color: #ECEFF4\">.<\/span><span style=\"color: #88C0D0\">send<\/span><span style=\"color: #D8DEE9FF\">(<\/span><span style=\"color: #81A1C1\">new<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #88C0D0\">Buffer<\/span><span style=\"color: #D8DEE9FF\">([<\/span><span style=\"color: #B48EAD\">0xde<\/span><span style=\"color: #ECEFF4\">,<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #B48EAD\">0xad<\/span><span style=\"color: #ECEFF4\">,<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #B48EAD\">0xbe<\/span><span style=\"color: #ECEFF4\">,<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #B48EAD\">0xef<\/span><span style=\"color: #D8DEE9FF\">])<\/span><span style=\"color: #ECEFF4\">,<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #ECEFF4\">(<\/span><span style=\"color: #D8DEE9\">error<\/span><span style=\"color: #ECEFF4\">)<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #81A1C1\">=&gt;<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #ECEFF4\">{<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">  <\/span><span style=\"color: #D8DEE9\">console<\/span><span style=\"color: #ECEFF4\">.<\/span><span style=\"color: #88C0D0\">log<\/span><span style=\"color: #D8DEE9FF\">(<\/span><span style=\"color: #ECEFF4\">&quot;<\/span><span style=\"color: #A3BE8C\">I&#39;m done sending the data<\/span><span style=\"color: #ECEFF4\">&quot;<\/span><span style=\"color: #D8DEE9FF\">)<\/span><span style=\"color: #81A1C1\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #ECEFF4\">  <\/span><span style=\"color: #616E88\">\/\/ Can also use err for error handling<\/span><\/span>\n<span class=\"line\"><span style=\"color: #ECEFF4\">}<\/span><span style=\"color: #D8DEE9FF\">)<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<p><a href=\"https:\/\/www.bairesdev.com\/tools\/tessel\/doc\/api\/hardware-api\/#i2c\" target=\"_blank\" rel=\"noreferrer noopener\">More I2C example code and information<\/a><\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"uart\"><span class=\"ez-toc-section\" id=\"UART\"><\/span>UART<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p><strong>Pros:<\/strong>&nbsp;Widely supported, allows two-way communication<\/p>\n\n\n\n<p><strong>Cons:<\/strong>&nbsp;Can&#8217;t share communication lines, slower than&nbsp;SPI&nbsp;and&nbsp;I2C<\/p>\n\n\n\n<p><a href=\"https:\/\/web.archive.org\/web\/20220116195450\/https:\/\/tessel.gitbooks.io\/t2-docs\/content\/GLOSSARY.html#uart\" target=\"_blank\" rel=\"noopener\">UART<\/a>&nbsp;stands for&nbsp;<a href=\"http:\/\/en.wikipedia.org\/wiki\/Universal_asynchronous_receiver\/transmitter\" target=\"_blank\" rel=\"noreferrer noopener\">Universal Asynchronous Receiver\/Transmitter<\/a>&nbsp;and is really just a fancy way of referring to a&nbsp;serial&nbsp;port. It is really easy to understand as it only requires two lines: a transmission line (TX) and a receiving line (RX). The Tessel sends data to connected modules on the&nbsp;TX&nbsp;line and gets data back on the&nbsp;RX&nbsp;line.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"tx\"><span class=\"ez-toc-section\" id=\"TX\"><\/span>TX<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>Used by the Tessel to send data to the module.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"rx\"><span class=\"ez-toc-section\" id=\"RX\"><\/span>RX<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>Used by the module to send data to the Tessel.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"600\" height=\"300\" src=\"https:\/\/www.bairesdev.com\/tools\/tessel\/wp-content\/uploads\/2024\/03\/uart_example.jpg\" alt=\"\" class=\"wp-image-10122\" srcset=\"https:\/\/www.bairesdev.com\/tools\/tessel\/wp-content\/uploads\/2024\/03\/uart_example.jpg 600w, https:\/\/www.bairesdev.com\/tools\/tessel\/wp-content\/uploads\/2024\/03\/uart_example-300x150.jpg 300w\" sizes=\"(max-width: 600px) 100vw, 600px\" \/><\/figure>\n\n\n\n<p>A&nbsp;UART&nbsp;data transmission.<\/p>\n\n\n\n<p>UART&nbsp;transmissions begin with a start bit where the appropriate line (TX&nbsp;or&nbsp;RX) is pulled low by the<\/p>\n\n\n\n<p>Following the data, an optional&nbsp;<a href=\"http:\/\/en.wikipedia.org\/wiki\/Parity_bit\" target=\"_blank\" rel=\"noreferrer noopener\">parity bit<\/a>&nbsp;is sent, followed by 1 or 2 stop bits, where the sending module pulls the pin high.<\/p>\n\n\n\n<p>For this protocol to work, the sender and receiver have to agree on a few things.<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>How many data bits are sent with each packet (5 to 8)?<\/li>\n\n\n\n<li>How fast should the data be sent? This is know as the baud rate.<\/li>\n\n\n\n<li>Is there a parity bit after the data, and is it high or low?<\/li>\n\n\n\n<li>How many stop bits will be sent at the end of each transmission?<\/li>\n<\/ol>\n\n\n\n<p>When you want to interact with a specific module via&nbsp;UART, the answers to these questions are found in the module&#8217;s&nbsp;datasheet. Using that information you can configure the&nbsp;UART&nbsp;in Javascript like this:<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#2e3440ff\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"'use strict';\nconst tessel = require('tessel');\nconst port = tessel.port.A;\nconst uart = new port.UART({\n  dataBits: 8,\n  baudrate: 115200,\n  parity: &quot;none&quot;,\n  stopBits: 1\n});\n\nuart.write('Hello UART');\" style=\"color:#d8dee9ff;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki nord\" style=\"background-color: #2e3440ff\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #ECEFF4\">&#39;<\/span><span style=\"color: #A3BE8C\">use strict<\/span><span style=\"color: #ECEFF4\">&#39;<\/span><span style=\"color: #81A1C1\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #81A1C1\">const<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #D8DEE9\">tessel<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #81A1C1\">=<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #88C0D0\">require<\/span><span style=\"color: #D8DEE9FF\">(<\/span><span style=\"color: #ECEFF4\">&#39;<\/span><span style=\"color: #A3BE8C\">tessel<\/span><span style=\"color: #ECEFF4\">&#39;<\/span><span style=\"color: #D8DEE9FF\">)<\/span><span style=\"color: #81A1C1\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #81A1C1\">const<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #D8DEE9\">port<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #81A1C1\">=<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #D8DEE9\">tessel<\/span><span style=\"color: #ECEFF4\">.<\/span><span style=\"color: #D8DEE9\">port<\/span><span style=\"color: #ECEFF4\">.<\/span><span style=\"color: #D8DEE9\">A<\/span><span style=\"color: #81A1C1\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #81A1C1\">const<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #D8DEE9\">uart<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #81A1C1\">=<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #81A1C1\">new<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #D8DEE9\">port<\/span><span style=\"color: #ECEFF4\">.<\/span><span style=\"color: #88C0D0\">UART<\/span><span style=\"color: #D8DEE9FF\">(<\/span><span style=\"color: #ECEFF4\">{<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">  <\/span><span style=\"color: #88C0D0\">dataBits<\/span><span style=\"color: #ECEFF4\">:<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #B48EAD\">8<\/span><span style=\"color: #ECEFF4\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">  <\/span><span style=\"color: #88C0D0\">baudrate<\/span><span style=\"color: #ECEFF4\">:<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #B48EAD\">115200<\/span><span style=\"color: #ECEFF4\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">  <\/span><span style=\"color: #88C0D0\">parity<\/span><span style=\"color: #ECEFF4\">:<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #ECEFF4\">&quot;<\/span><span style=\"color: #A3BE8C\">none<\/span><span style=\"color: #ECEFF4\">&quot;<\/span><span style=\"color: #ECEFF4\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9FF\">  <\/span><span style=\"color: #88C0D0\">stopBits<\/span><span style=\"color: #ECEFF4\">:<\/span><span style=\"color: #D8DEE9FF\"> <\/span><span style=\"color: #B48EAD\">1<\/span><\/span>\n<span class=\"line\"><span style=\"color: #ECEFF4\">}<\/span><span style=\"color: #D8DEE9FF\">)<\/span><span style=\"color: #81A1C1\">;<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #D8DEE9\">uart<\/span><span style=\"color: #ECEFF4\">.<\/span><span style=\"color: #88C0D0\">write<\/span><span style=\"color: #D8DEE9FF\">(<\/span><span style=\"color: #ECEFF4\">&#39;<\/span><span style=\"color: #A3BE8C\">Hello UART<\/span><span style=\"color: #ECEFF4\">&#39;<\/span><span style=\"color: #D8DEE9FF\">)<\/span><span style=\"color: #81A1C1\">;<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<p><a href=\"https:\/\/www.bairesdev.com\/tools\/tessel\/doc\/api\/hardware-api\/#uart\" target=\"_blank\" rel=\"noreferrer noopener\">More example code using a UART<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Each of the two&nbsp;ports&nbsp;on Tessel 2 exposes ten&nbsp;pins&nbsp;for use in creating custom modules. Two of the&nbsp;pins&nbsp;are for power (3.3V and ground) and the other eight are configurable&nbsp;GPIO&nbsp;(General Purpose Input and Output)&nbsp;pins&nbsp;that can be used to communicate with your module. All eight communication&nbsp;pins&nbsp;allow for communication through changes in voltage: some through variable voltage between 0V and [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4,59],"tags":[],"class_list":["post-9773","post","type-post","status-publish","format-standard","hentry","category-docs","category-tutorials"],"_links":{"self":[{"href":"https:\/\/www.bairesdev.com\/tools\/tessel\/wp-json\/wp\/v2\/posts\/9773","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.bairesdev.com\/tools\/tessel\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.bairesdev.com\/tools\/tessel\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.bairesdev.com\/tools\/tessel\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.bairesdev.com\/tools\/tessel\/wp-json\/wp\/v2\/comments?post=9773"}],"version-history":[{"count":3,"href":"https:\/\/www.bairesdev.com\/tools\/tessel\/wp-json\/wp\/v2\/posts\/9773\/revisions"}],"predecessor-version":[{"id":10123,"href":"https:\/\/www.bairesdev.com\/tools\/tessel\/wp-json\/wp\/v2\/posts\/9773\/revisions\/10123"}],"wp:attachment":[{"href":"https:\/\/www.bairesdev.com\/tools\/tessel\/wp-json\/wp\/v2\/media?parent=9773"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.bairesdev.com\/tools\/tessel\/wp-json\/wp\/v2\/categories?post=9773"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.bairesdev.com\/tools\/tessel\/wp-json\/wp\/v2\/tags?post=9773"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}