1<!DOCTYPE html> 2<html lang="en-GB"> 3<head> 4 <meta charset="UTF-8"> 5 <meta http-equiv="X-UA-Compatible" content="IE=edge"> 6 <meta name="viewport" content="width=device-width, initial-scale=1"> 7 <link rel="profile" href="http://gmpg.org/xfn/11"/> 8 <link rel="alternate" type="application/rss+xml" title="ESP32 Learning RSS Feed" 9 href="https://www.esp32learning.com/feed"/> 10 <link rel="alternate" type="application/atom+xml" title="ESP32 Learning Atom Feed" 11 href="https://www.esp32learning.com/feed/atom"/> 12 <link rel="pingback" href="https://www.esp32learning.com/xmlrpc.php"/> 13 <!--[if lt IE 9]> 14
14<script src="https://www.esp32learning.com/wp-content/themes/soledad/js/html5.js"></script>
14 15 <![endif]--> 16 <link rel='preconnect' href='https://fonts.googleapis.com' /> 17<link rel='preconnect' href='https://fonts.gstatic.com' /> 18<meta http-equiv='x-dns-prefetch-control' content='on'> 19<link rel='dns-prefetch' href='//fonts.googleapis.com' /> 20<link rel='dns-prefetch' href='//fonts.gstatic.com' /> 21<link rel='dns-prefetch' href='//s.gravatar.com' /> 22<link rel='dns-prefetch' href='//www.google-analytics.com' /> 23<meta name='robots' content='index, follow, max-image-preview:large, max-snippet:-1, max-video-preview:-1' /> 24 <style>img:is([sizes="auto" i], [sizes^="auto," i]) { contain-intrinsic-size: 3000px 1500px }</style> 25 26 <!-- This site is optimized with the Yoast SEO Premium plugin v24.1 (Yoast SEO v28.6) - https://yoast.com/product/yoast-seo-premium-wordpress/ --> 27 <title>Code Archives - ESP32 Learning</title> 28 <link rel="canonical" href="https://www.esp32learning.com/category/code" /> 29 <link rel="next" href="https://www.esp32learning.com/category/code/page/2" /> 30 <meta property="og:locale" content="en_GB" /> 31 <meta property="og:type" content="article" /> 32 <meta property="og:title" content="Code Archives" /> 33 <meta property="og:url" content="https://www.esp32learning.com/category/code" /> 34 <meta property="og:site_name" content="ESP32 Learning" /> 35 <meta name="twitter:card" content="summary_large_image" /> 36
36<script type="application/ld+json" class="yoast-schema-graph">{"@context":"https:\/\/schema.org","@graph":[{"@type":"CollectionPage","@id":"https:\/\/www.esp32learning.com\/category\/code","url":"https:\/\/www.esp32learning.com\/category\/code","name":"Code Archives - ESP32 Learning","isPartOf":{"@id":"https:\/\/www.esp32learning.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.esp32learning.com\/category\/code#primaryimage"},"image":{"@id":"https:\/\/www.esp32learning.com\/category\/code#primaryimage"},"thumbnailUrl":"https:\/\/www.esp32learning.com\/wp-content\/uploads\/2023\/12\/ESP32-and-STS35_bb.jpg","breadcrumb":{"@id":"https:\/\/www.esp32learning.com\/category\/code#breadcrumb"},"inLanguage":"en-GB"},{"@type":"ImageObject","inLanguage":"en-GB","@id":"https:\/\/www.esp32learning.com\/category\/code#primaryimage","url":"https:\/\/www.esp32learning.com\/wp-content\/uploads\/2023\/12\/ESP32-and-STS35_bb.jpg","contentUrl":"https:\/\/www.esp32learning.com\/wp-content\/uploads\/2023\/12\/ESP32-and-STS35_bb.jpg","width":606,"height":609},{"@type":"BreadcrumbList","@id":"https:\/\/www.esp32learning.com\/category\/code#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.esp32learning.com\/"},{"@type":"ListItem","position":2,"name":"Code"}]},{"@type":"WebSite","@id":"https:\/\/www.esp32learning.com\/#website","url":"https:\/\/www.esp32learning.com\/","name":"ESP32 Learning","description":"","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.esp32learning.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-GB"}]}</script>
36 37 <!-- / Yoast SEO Premium plugin. --> 38 39 40<link rel='dns-prefetch' href='//static.addtoany.com' /> 41<link rel='preconnect' href='https://esp32learning.b-cdn.net' /> 42<link rel="alternate" type="application/rss+xml" title="ESP32 Learning » Feed" href="https://www.esp32learning.com/feed" /> 43<link rel='stylesheet' id='wp-block-library-css' href='https://www.esp32learning.com/wp-includes/css/dist/block-library/style.min.css?ver=6.7.9' type='text/css' media='all' /> 44<style id='wp-block-library-theme-inline-css' type='text/css'> 45.wp-block-audio :where(figcaption){color:#555;font-size:13px;text-align:center}.is-dark-theme .wp-block-audio :where(figcaption){color:#ffffffa6}.wp-block-audio{margin:0 0 1em}.wp-block-code{border:1px solid #ccc;border-radius:4px;font-family:Menlo,Consolas,monaco,monospace;padding:.8em 1em}.wp-block-embed :where(figcaption){color:#555;font-size:13px;text-align:center}.is-dark-theme .wp-block-embed :where(figcaption){color:#ffffffa6}.wp-block-embed{margin:0 0 1em}.blocks-gallery-caption{color:#555;font-size:13px;text-align:center}.is-dark-theme .blocks-gallery-caption{color:#ffffffa6}:root :where(.wp-block-image figcaption){color:#555;font-size:13px;text-align:center}.is-dark-theme :root :where(.wp-block-image figcaption){color:#ffffffa6}.wp-block-image{margin:0 0 1em}.wp-block-pullquote{border-bottom:4px solid;border-top:4px solid;color:currentColor;margin-bottom:1.75em}.wp-block-pullquote cite,.wp-block-pullquote footer,.wp-block-pullquote__citation{color:currentColor;font-size:.8125em;font-style:normal;text-transform:uppercase}.wp-block-quote{border-left:.25em solid;margin:0 0 1.75em;padding-left:1em}.wp-block-quote cite,.wp-block-quote footer{color:currentColor;font-size:.8125em;font-style:normal;position:relative}.wp-block-quote:where(.has-text-align-right){border-left:none;border-right:.25em solid;padding-left:0;padding-right:1em}.wp-block-quote:where(.has-text-align-center){border:none;padding-left:0}.wp-block-quote.is-large,.wp-block-quote.is-style-large,.wp-block-quote:where(.is-style-plain){border:none}.wp-block-search .wp-block-search__label{font-weight:700}.wp-block-search__button{border:1px solid #ccc;padding:.375em .625em}:where(.wp-block-group.has-background){padding:1.25em 2.375em}.wp-block-separator.has-css-opacity{opacity:.4}.wp-block-separator{border:none;border-bottom:2px solid;margin-left:auto;margin-right:auto}.wp-block-separator.has-alpha-channel-opacity{opacity:1}.wp-block-separator:not(.is-style-wide):not(.is-style-dots){width:100px}.wp-block-separator.has-background:not(.is-style-dots){border-bottom:none;height:1px}.wp-block-separator.has-background:not(.is-style-wide):not(.is-style-dots){height:2px}.wp-block-table{margin:0 0 1em}.wp-block-table td,.wp-block-table th{word-break:normal}.wp-block-table :where(figcaption){color:#555;font-size:13px;text-align:center}.is-dark-theme .wp-block-table :where(figcaption){color:#ffffffa6}.wp-block-video :where(figcaption){color:#555;font-size:13px;text-align:center}.is-dark-theme .wp-block-video :where(figcaption){color:#ffffffa6}.wp-block-video{margin:0 0 1em}:root :where(.wp-block-template-part.has-background){margin-bottom:0;margin-top:0;padding:1.25em 2.375em} 46</style> 47<style id='block-soledad-style-inline-css' type='text/css'> 48.pchead-e-block{--pcborder-cl:#dedede;--pcaccent-cl:#6eb48c}.heading1-style-1>h1,.heading1-style-2>h1,.heading2-style-1>h2,.heading2-style-2>h2,.heading3-style-1>h3,.heading3-style-2>h3,.heading4-style-1>h4,.heading4-style-2>h4,.heading5-style-1>h5,.heading5-style-2>h5{padding-bottom:8px;border-bottom:1px solid var(--pcborder-cl);overflow:hidden}.heading1-style-2>h1,.heading2-style-2>h2,.heading3-style-2>h3,.heading4-style-2>h4,.heading5-style-2>h5{border-bottom-width:0;position:relative}.heading1-style-2>h1:before,.heading2-style-2>h2:before,.heading3-style-2>h3:before,.heading4-style-2>h4:before,.heading5-style-2>h5:before{content:'';width:50px;height:2px;bottom:0;left:0;z-index:2;background:var(--pcaccent-cl);position:absolute}.heading1-style-2>h1:after,.heading2-style-2>h2:after,.heading3-style-2>h3:after,.heading4-style-2>h4:after,.heading5-style-2>h5:after{content:'';width:100%;height:2px;bottom:0;left:20px;z-index:1;background:var(--pcborder-cl);position:absolute}.heading1-style-3>h1,.heading1-style-4>h1,.heading2-style-3>h2,.heading2-style-4>h2,.heading3-style-3>h3,.heading3-style-4>h3,.heading4-style-3>h4,.heading4-style-4>h4,.heading5-style-3>h5,.heading5-style-4>h5{position:relative;padding-left:20px}.heading1-style-3>h1:before,.heading1-style-4>h1:before,.heading2-style-3>h2:before,.heading2-style-4>h2:before,.heading3-style-3>h3:before,.heading3-style-4>h3:before,.heading4-style-3>h4:before,.heading4-style-4>h4:before,.heading5-style-3>h5:before,.heading5-style-4>h5:before{width:10px;height:100%;content:'';position:absolute;top:0;left:0;bottom:0;background:var(--pcaccent-cl)}.heading1-style-4>h1,.heading2-style-4>h2,.heading3-style-4>h3,.heading4-style-4>h4,.heading5-style-4>h5{padding:10px 20px;background:#f1f1f1}.heading1-style-5>h1,.heading2-style-5>h2,.heading3-style-5>h3,.heading4-style-5>h4,.heading5-style-5>h5{position:relative;z-index:1}.heading1-style-5>h1:before,.heading2-style-5>h2:before,.heading3-style-5>h3:before,.heading4-style-5>h4:before,.heading5-style-5>h5:before{content:"";position:absolute;
48left:0;bottom:0;width:200px;height:50%;transform:skew(-25deg) translateX(0);background:var(--pcaccent-cl);z-index:-1;opacity:.4}.heading1-style-6>h1,.heading2-style-6>h2,.heading3-style-6>h3,.heading4-style-6>h4,.heading5-style-6>h5{text-decoration:underline;text-underline-offset:2px;text-decoration-thickness:4px;text-decoration-color:var(--pcaccent-cl)} 49</style> 50<style id='classic-theme-styles-inline-css' type='text/css'> 51/*! This file is auto-generated */ 52.wp-block-button__link{color:#fff;background-color:#32373c;border-radius:9999px;box-shadow:none;text-decoration:none;padding:calc(.667em + 2px) calc(1.333em + 2px);font-size:1.125em}.wp-block-file__button{background:#32373c;color:#fff;text-decoration:none} 53</style> 54<style id='global-styles-inline-css' type='text/css'> 55:root{--wp--preset--aspect-ratio--square: 1;--wp--preset--aspect-ratio--4-3: 4/3;--wp--preset--aspect-ratio--3-4: 3/4;--wp--preset--aspect-ratio--3-2: 3/2;--wp--preset--aspect-ratio--2-3: 2/3;--wp--preset--aspect-ratio--16-9: 16/9;--wp--preset--aspect-ratio--9-16: 9/16;--wp--preset--color--black: #000000;--wp--preset--color--cyan-bluish-gray: #abb8c3;--wp--preset--color--white: #ffffff;--wp--preset--color--pale-pink: #f78da7;--wp--preset--color--vivid-red: #cf2e2e;--wp--preset--color--luminous-vivid-orange: #ff6900;--wp--preset--color--luminous-vivid-amber: #fcb900;--wp--preset--color--light-green-cyan: #7bdcb5;--wp--preset--color--vivid-green-cyan: #00d084;--wp--preset--color--pale-cyan-blue: #8ed1fc;--wp--preset--color--vivid-cyan-blue: #0693e3;--wp--preset--color--vivid-purple: #9b51e0;--wp--preset--gradient--vivid-cyan-blue-to-vivid-purple: linear-gradient(135deg,rgba(6,147,227,1) 0%,rgb(155,81,224) 100%);--wp--preset--gradient--light-green-cyan-to-vivid-green-cyan: linear-gradient(135deg,rgb(122,220,180) 0%,rgb(0,208,130) 100%);--wp--preset--gradient--luminous-vivid-amber-to-luminous-vivid-orange: linear-gradient(135deg,rgba(252,185,0,1) 0%,rgba(255,105,0,1) 100%);--wp--preset--gradient--luminous-vivid-orange-to-vivid-red: linear-gradient(135deg,rgba(255,105,0,1) 0%,rgb(207,46,46) 100%);--wp--preset--gradient--very-light-gray-to-cyan-bluish-gray: linear-gradient(135deg,rgb(238,238,238) 0%,rgb(169,184,195) 100%);
55--wp--preset--gradient--cool-to-warm-spectrum: linear-gradient(135deg,rgb(74,234,220) 0%,rgb(151,120,209) 20%,rgb(207,42,186) 40%,rgb(238,44,130) 60%,rgb(251,105,98) 80%,rgb(254,248,76) 100%);--wp--preset--gradient--blush-light-purple: linear-gradient(135deg,rgb(255,206,236) 0%,rgb(152,150,240) 100%);--wp--preset--gradient--blush-bordeaux: linear-gradient(135deg,rgb(254,205,165) 0%,rgb(254,45,45) 50%,rgb(107,0,62) 100%);--wp--preset--gradient--luminous-dusk: linear-gradient(135deg,rgb(255,203,112) 0%,rgb(199,81,192) 50%,rgb(65,88,208) 100%);--wp--preset--gradient--pale-ocean: linear-gradient(135deg,rgb(255,245,203) 0%,rgb(182,227,212) 50%,rgb(51,167,181) 100%);--wp--preset--gradient--electric-grass: linear-gradient(135deg,rgb(202,248,128) 0%,rgb(113,206,126) 100%);--wp--preset--gradient--midnight: linear-gradient(135deg,rgb(2,3,129) 0%,rgb(40,116,252) 100%);--wp--preset--font-size--small: 12px;--wp--preset--font-size--medium: 20px;--wp--preset--font-size--large: 32px;--wp--preset--font-size--x-large: 42px;--wp--preset--font-size--normal: 14px;--wp--preset--font-size--huge: 42px;--wp--preset--spacing--20: 0.44rem;--wp--preset--spacing--30: 0.67rem;--wp--preset--spacing--40: 1rem;--wp--preset--spacing--50: 1.5rem;--wp--preset--spacing--60: 2.25rem;--wp--preset--spacing--70: 3.38rem;--wp--preset--spacing--80: 5.06rem;--wp--preset--shadow--natural: 6px 6px 9px rgba(0, 0, 0, 0.2);--wp--preset--shadow--deep: 12px 12px 50px rgba(0, 0, 0, 0.4);--wp--preset--shadow--sharp: 6px 6px 0px rgba(0, 0, 0, 0.2);--wp--preset--shadow--outlined: 6px 6px 0px -3px rgba(255, 255, 255, 1), 6px 6px rgba(0, 0, 0, 1);--wp--preset--shadow--crisp: 6px 6px 0px rgba(0, 0, 0, 1);}:where(.is-layout-flex){gap: 0.5em;}:where(.is-layout-grid){gap: 0.5em;}body .is-layout-flex{display: flex;}.is-layout-flex{flex-wrap: wrap;align-items: center;}.is-layout-flex > :is(*, div){margin: 0;}body .is-layout-grid{display: grid;}.is-layout-grid > :is(*, div){margin: 0;}:where(.wp-block-columns.is-layout-flex){gap: 2em;}:where(.wp-block-columns.is-layout-grid){gap: 2em;}:where(.wp-block-post-template.is-layout-flex){gap: 1.25em;}:where(.wp-block-post-template.is-layout-grid){gap: 1.25em;}.has-black-color{color: var(--wp--preset--color--black) !important;}.has-cyan-bluish-gray-color{color: var(--wp--preset--color--cyan-bluish-gray) !important;}.has-white-color{color: var(--wp--preset--color--white) !important;}.has-pale-pink-color{color: var(--wp--preset--color--pale-pink) !important;}.has-vivid-red-color{color: var(--wp--preset--color--vivid-red) !important;}.has-luminous-vivid-orange-color{color: var(--wp--preset--color--luminous-vivid-orange) !important;}.has-luminous-vivid-amber-color{color: var(--wp--preset--color--luminous-vivid-amber) !important;}.has-light-green-cyan-color{color: var(--wp--preset--color--light-green-cyan) !important;}.has-vivid-green-cyan-color{color: var(--wp--preset--color--vivid-green-cyan) !important;}.has-pale-cyan-blue-color{color: var(--wp--preset--color--pale-cyan-blue) !important;}.has-vivid-cyan-blue-color{color: var(--wp--preset--color--vivid-cyan-blue) !important;}.has-vivid-purple-color{color: var(--wp--preset--color--vivid-purple) !important;}.has-black-background-color{background-color: var(--wp--preset--color--black) !important;}.has-cyan-bluish-gray-background-color{background-color: var(--wp--preset--color--cyan-bluish-gray) !important;}.has-white-background-color{background-color: var(--wp--preset--color--white) !important;}.has-pale-pink-background-color{background-color: var(--wp--preset--color--pale-pink) !important;}.has-vivid-red-background-color{background-color: var(--wp--preset--color--vivid-red) !important;}.has-luminous-vivid-orange-background-color{background-color: var(--wp--preset--color--luminous-vivid-orange) !important;}.has-luminous-vivid-amber-background-color{background-color: var(--wp--preset--color--luminous-vivid-amber) !important;}.has-light-green-cyan-background-color{background-color: var(--wp--preset--color--light-green-cyan) !important;}.has-vivid-green-cyan-background-color{background-color: var(--wp--preset--color--vivid-green-cyan) !important;}.has-pale-cyan-blue-background-color{background-color: var(--wp--preset--color--pale-cyan-blue) !important;}.has-vivid-cyan-blue-background-color{background-color: var(--wp--preset--color--vivid-cyan-blue) !important;}.has-vivid-purple-background-color{background-color: var(--wp--preset--color--vivid-purple) !important;}.has-black-border-color{border-color: var(--wp--preset--color--black) !important;}.has-cyan-bluish-gray-border-color{border-color: var(--wp--preset--color--cyan-bluish-gray) !important;}.has-white-border-color{border-color: var(--wp--preset--color--white) !important;}.has-pale-pink-border-color{border-color: var(--wp--preset--color--pale-pink) !important;}.has-vivid-red-border-color{border-color: var(--wp--preset--color--vivid-red) !important;}.has-luminous-vivid-orange-border-color{border-color: var(--wp--preset--color--luminous-vivid-orange) !important;}.has-luminous-vivid-amber-border-color{border-color: var(--wp--preset--color--luminous-vivid-amber) !important;}.has-light-green-cyan-border-color{border-color: var(--wp--preset--color--light-green-cyan) !important;}.has-vivid-green-cyan-border-color{border-color: var(--wp--preset--color--vivid-green-cyan) !important;}.has-pale-cyan-blue-border-color{border-color: var(--wp--preset--color--pale-cyan-blue) !important;}.has-vivid-cyan-blue-border-color{border-color: var(--wp--preset--color--vivid-cyan-blue) !important;}.has-vivid-purple-border-color{border-color: var(--wp--preset--color--vivid-purple) !important;}.has-vivid-cyan-blue-to-vivid-purple-gradient-background{background: var(--wp--preset--gradient--vivid-cyan-blue-to-vivid-purple) !important;}.has-light-green-cyan-to-vivid-green-cyan-gradient-background{background: var(--wp--preset--gradient--light-green-cyan-to-vivid-green-cyan) !important;}.has-luminous-vivid-amber-to-luminous-vivid-orange-gradient-background{background: var(--wp--preset--gradient--luminous-vivid-amber-to-luminous-vivid-orange) !important;}.has-luminous-vivid-orange-to-vivid-red-gradient-background{background: var(--wp--preset--gradient--luminous-vivid-orange-to-vivid-red) !important;}
55.has-very-light-gray-to-cyan-bluish-gray-gradient-background{background: var(--wp--preset--gradient--very-light-gray-to-cyan-bluish-gray) !important;}.has-cool-to-warm-spectrum-gradient-background{background: var(--wp--preset--gradient--cool-to-warm-spectrum) !important;}.has-blush-light-purple-gradient-background{background: var(--wp--preset--gradient--blush-light-purple) !important;}.has-blush-bordeaux-gradient-background{background: var(--wp--preset--gradient--blush-bordeaux) !important;}.has-luminous-dusk-gradient-background{background: var(--wp--preset--gradient--luminous-dusk) !important;}.has-pale-ocean-gradient-background{background: var(--wp--preset--gradient--pale-ocean) !important;}.has-electric-grass-gradient-background{background: var(--wp--preset--gradient--electric-grass) !important;}.has-midnight-gradient-background{background: var(--wp--preset--gradient--midnight) !important;}.has-small-font-size{font-size: var(--wp--preset--font-size--small) !important;}.has-medium-font-size{font-size: var(--wp--preset--font-size--medium) !important;}.has-large-font-size{font-size: var(--wp--preset--font-size--large) !important;}.has-x-large-font-size{font-size: var(--wp--preset--font-size--x-large) !important;} 56:where(.wp-block-post-template.is-layout-flex){gap: 1.25em;}:where(.wp-block-post-template.is-layout-grid){gap: 1.25em;} 57:where(.wp-block-columns.is-layout-flex){gap: 2em;}:where(.wp-block-columns.is-layout-grid){gap: 2em;} 58:root :where(.wp-block-pullquote){font-size: 1.5em;line-height: 1.6;} 59</style> 60<style id='esp32-deep-sleep-style-inline-css' type='text/css'> 61 62 .esp32-sleep-tool{max-width:1100px;margin:30px auto;font-family:Arial,sans-serif;line-height:1.6} 63 .esp32-sleep-tool h2,.esp32-sleep-tool h3{margin-top:0} 64 .esp32-sleep-intro{font-size:1.05rem;margin-bottom:22px} 65 .esp32-sleep-grid{display:grid;grid-template-columns:1fr 1fr;gap:20px} 66 .esp32-sleep-card{background:#fff;border:1px solid #ddd;border-radius:14px;padding:22px;margin-bottom:20px;box-shadow:0 3px 12px rgba(0,0,0,.05)} 67 .esp32-sleep-card label{display:block;font-weight:bold;margin-top:13px;margin-bottom:6px} 68 .esp32-sleep-card input,.esp32-sleep-card select{width:100%;padding:10px;border:1px solid #bbb;border-radius:8px;font-size:15px} 69 .esp32-row{display:grid;grid-template-columns:2fr 1fr;gap:10px} 70 .esp32-btn{margin-top:18px;padding:12px 18px;background:#1f6feb;color:#fff;border:0;border-radius:8px;cursor:pointer;font-weight:bold} 71 .esp32-btn:hover{background:#174ea6} 72 .result-line{display:flex;justify-content:space-between;border-bottom:1px solid #eee;padding:9px 0;gap:15px} 73 .result-line strong{text-align:right} 74 .esp32-good{background:#e7f6ec;border-left:5px solid #28a745;padding:10px;border-radius:8px;margin:10px 0} 75 .esp32-warn{background:#fff3cd;border-left:5px solid #ffc107;padding:10px;border-radius:8px;margin:10px 0} 76 .esp32-danger{background:#fde8e8;border-left:5px solid #dc3545;padding:10px;border-radius:8px;margin:10px 0} 77 .esp32-table{width:100%;border-collapse:collapse;margin-top:12px} 78 .esp32-table th,.esp32-table td{border:1px solid #ddd;padding:10px;text-align:left} 79 .esp32-table th{background:#f5f5f5} 80 .battery-bar-wrap{background:#eee;border-radius:999px;
80height:22px;overflow:hidden;margin-top:12px} 81 .battery-bar{height:100%;width:50%;background:#28a745;transition:.3s} 82 .esp32-code{background:#111827;color:#e5e7eb;padding:16px;border-radius:10px;overflow:auto;font-size:14px} 83 .copy-btn{background:#1f6feb;color:white;border:0;border-radius:8px;padding:10px 14px;cursor:pointer;margin-bottom:10px} 84 @media(max-width:800px){.esp32-sleep-grid{grid-template-columns:1fr}.result-line{flex-direction:column}.result-line strong{text-align:left}} 85 86</style> 87<style id='esp32-pinout-explorer-style-inline-css' type='text/css'> 88 89 .esp32-tool{max-width:1200px;margin:30px auto;font-family:Arial,sans-serif;line-height:1.6} 90 .esp32-tool h2,.esp32-tool h3{margin-top:0} 91 .esp32-intro{font-size:1.05rem;margin-bottom:20px} 92 .esp32-panel{background:#fff;border:1px solid #ddd;border-radius:14px;padding:20px;margin-bottom:20px;box-shadow:0 3px 12px rgba(0,0,0,.05)} 93 .esp32-grid{display:grid;grid-template-columns:repeat(4,1fr);gap:14px} 94 .esp32-grid-2{display:grid;grid-template-columns:1fr 1fr;gap:20px} 95 .esp32-tool label{font-weight:bold;display:block;margin-bottom:6px} 96 .esp32-tool select,.esp32-tool input{width:100%;padding:10px;border:1px solid #bbb;border-radius:8px;font-size:15px} 97 .esp32-badges{display:flex;flex-wrap:wrap;gap:8px;margin:12px 0} 98 .esp32-badge{display:inline-block;padding:5px 9px;border-radius:999px;background:#eef2ff;font-size:13px} 99 .esp32-safe{background:#e7f6ec;border-left:5px solid #28a745;padding:10px;border-radius:8px;margin:8px 0} 100 .esp32-warn{background:#fff3cd;border-left:5px solid #ffc107;padding:10px;border-radius:8px;margin:8px 0} 101 .esp32-danger{background:#fde8e8;border-left:5px solid #dc3545;padding:10px;border-radius:8px;margin:8px 0} 102 .esp32-table-wrap{overflow-x:auto} 103 .esp32-table{width:100%;border-collapse:collapse;font-size:14px} 104 .esp32-table th,.esp32-table td{border:1px solid #ddd;padding:9px;text-align:left;vertical-align:top} 105 .esp32-table th{background:#f5f5f5;position:sticky;top:0} 106 .pin-good{background:#e7f6ec} 107 .pin-caution{background:#fff8db} 108 .pin-bad{background:#fde8e8} 109 .esp32-small{font-size:13px;color:#555} 110 .esp32-code{background:#111827;color:#e5e7eb;padding:16px;border-radius:10px;overflow:auto;font-size:13px} 111 .esp32-copy{background:#1f6feb;color:#fff;border:0;border-radius:8px;padding:10px 14px;cursor:pointer;margin-bottom:10px} 112 .esp32-copy:hover{background:#174ea6} 113 .esp32-note-list li{margin-bottom:7px} 114 @media(max-width:900px){.esp32-grid,.esp32-grid-2{grid-template-columns:1fr}} 115 116</style> 117<link rel='stylesheet' id='penci-main-style-css' href='https://www.esp32learning.com/wp-content/themes/soledad/main.css?ver=8.5.4' type='text/css' media='all' /> 118<link rel='stylesheet' id='penci-swiper-bundle-css' href='https://www.esp32learning.com/wp-content/themes/soledad/css/swiper-bundle.min.css?ver=8.5.4' type='text/css' media='all' /> 119<link rel='stylesheet' id='penci-font-awesomeold-css' href='https://www.esp32learning.com/wp-content/themes/soledad/css/font-awesome.4.7.0.swap.min.css?ver=4.7.0' type='text/css' media='all' /> 120<link rel='stylesheet' id='penci_icon-css' href='https://www.esp32learning.com/wp-content/themes/soledad/css/penci-icon.css?ver=8.5.4' type='text/css' media='all' /> 121<link rel='stylesheet' id='penci_style-css' href='https://www.esp32learning.com/wp-content/themes/soledad/style.css?ver=8.5.4' type='text/css' media='all' /> 122<link rel='stylesheet' id='penci_social_counter-css' href='https://www.esp32learning.com/wp-content/themes/soledad/css/social-counter.css?ver=8.5.4' type='text/css' media='all' /> 123<link rel='stylesheet' id='lebox-css' href='https://www.esp32learning.com/wp-content/plugins/halfdata-green-box/css/style.css?ver=3.07' type='text/css' media='all' /> 124<link rel='stylesheet' id='addtoany-css' href='https://www.esp32learning.com/wp-content/plugins/add-to-any/addtoany.min.css?ver=1.16' type='text/css' media='all' /> 125<link rel='stylesheet' id='enlighterjs-css' href='https://www.esp32learning.com/wp-content/plugins/enlighter/cache/enlighterjs.min.css?ver=5a3iNMCZFdqvAqB' type='text/css' media='all' />
126<script type="text/javascript" id="addtoany-core-js-before"> 127/* <![CDATA[ */ 128window.a2a_config=window.a2a_config||{};a2a_config.callbacks=[];a2a_config.overlays=[];a2a_config.templates={};a2a_localize = { 129 Share: "Share", 130 Save: "Save", 131 Subscribe: "Subscribe", 132 Email: "Email", 133 Bookmark: "Bookmark", 134 ShowAll: "Show All", 135 ShowLess: "Show less", 136 FindServices: "Find service(s)", 137 FindAnyServiceToAddTo: "Instantly find any service to add to", 138 PoweredBy: "Powered by", 139 ShareViaEmail: "Share via email", 140 SubscribeViaEmail: "Subscribe via email", 141 BookmarkInYourBrowser: "Bookmark in your browser", 142 BookmarkInstructions: "Press Ctrl+D or \u2318+D to bookmark this page", 143 AddToYourFavorites: "Add to your favourites", 144 SendFromWebOrProgram: "Send from any email address or email program", 145 EmailProgram: "Email program", 146 More: "More…", 147 ThanksForSharing: "Thanks for sharing!", 148 ThanksForFollowing: "Thanks for following!" 149}; 150 151a2a_config.callbacks.push({ready:function(){document.querySelectorAll(".a2a_s_undefined").forEach(function(emptyIcon){emptyIcon.parentElement.style.display="none";})}}); 152/* ]]> */ 153</script>
vendor: 1 bytes, line 153
153
154<script type="text/javascript" defer src="https://static.addtoany.com/menu/page.js" id="addtoany-core-js"></script>
vendor: 1 bytes, line 154
154
155<script type="text/javascript" src="https://www.esp32learning.com/wp-includes/js/jquery/jquery.min.js?ver=3.7.1" id="jquery-core-js"></script>
vendor: 1 bytes, line 155
155
156<script type="text/javascript" src="https://www.esp32learning.com/wp-includes/js/jquery/jquery-migrate.min.js?ver=3.4.1" id="jquery-migrate-js"></script>
vendor: 1 bytes, line 156
156
157<script type="text/javascript" defer src="https://www.esp32learning.com/wp-content/plugins/add-to-any/addtoany.min.js?ver=1.1" id="addtoany-jquery-js"></script>
vendor: 1 bytes, line 157
157
158<script type="text/javascript" src="https://www.esp32learning.com/wp-content/plugins/halfdata-green-box/js/lebox.js?ver=3.07" id="lebox-js"></script>
158 159 160<!-- This site is using AdRotate v5.19.2 to display their advertisements - https://ajdg.solutions/ --> 161<!-- AdRotate CSS --> 162<style type="text/css" media="screen"> 163 .g { margin:0px; padding:0px; overflow:hidden; line-height:1; zoom:1; } 164 .g img { height:auto; } 165 .g-col { position:relative; float:left; } 166 .g-col:first-child { margin-left: 0; } 167 .g-col:last-child { margin-right: 0; } 168 .g-1 { min-width:7px; max-width:314px; } 169 .b-1 { margin:7px; } 170 .g-2 { margin:0px 0px 0px 0px;width:100%; max-width:300px; height:100%; max-height:250px; } 171 .g-3 { min-width:4px; max-width:358px; } 172 .b-3 { margin:4px; } 173 .g-4 { margin:0px; width:100%; max-width:300px; height:100%; max-height:600px; } 174 .g-5 { min-width:3px; max-width:306px; } 175 .b-5 { margin:3px; } 176 @media only screen and (max-width: 480px) { 177 .g-col, .g-dyn, .g-single { width:100%; margin-left:0; margin-right:0; } 178 } 179</style> 180<!-- /AdRotate CSS --> 181
182<script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
vendor: 2 bytes, line 182
182
183<script> 184 (adsbygoogle = window.adsbygoogle || []).push({ 185 google_ad_client: "ca-pub-3520634452456567", 186 enable_page_level_ads: true 187 }); 188</script>
vendor: 2 bytes, line 188
188
189<script data-ad-client="ca-pub-3520634452456567" async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
189 190<style id="penci-custom-style" type="text/css">body{ --pcbg-cl: #fff; --pctext-cl: #313131; --pcborder-cl: #dedede; --pcheading-cl: #313131; --pcmeta-cl: #888888; --pcaccent-cl: #6eb48c; --pcbody-font: 'PT Serif', serif; --pchead-font: 'Raleway', sans-serif; --pchead-wei: bold; --pcava_bdr:10px;--pcajs_fvw:470px;--pcajs_fvmw:220px; } .single.penci-body-single-style-5 #header, .single.penci-body-single-style-6 #header, .single.penci-body-single-style-10 #header, .single.penci-body-single-style-5 .pc-wrapbuilder-header, .single.penci-body-single-style-6 .pc-wrapbuilder-header, .single.penci-body-single-style-10 .pc-wrapbuilder-header { --pchd-mg: 40px; } .fluid-width-video-wrapper > div { position: absolute; left: 0; right: 0; top: 0; width: 100%; height: 100%; } .yt-video-place { position: relative; text-align: center; } .yt-video-place.embed-responsive .start-video { display: block; top: 0; left: 0; bottom: 0; right: 0; position: absolute; transform: none; } .yt-video-place.embed-responsive .start-video img { margin: 0; padding: 0; top: 50%; display: inline-block; position: absolute; left: 50%; transform: translate(-50%, -50%); width: 68px; height: auto; } .mfp-bg { top: 0; left: 0; width: 100%; height: 100%; z-index: 9999999; overflow: hidden; position: fixed; background: #0b0b0b; opacity: .8; filter: alpha(opacity=80) } .mfp-wrap { top: 0; left: 0; width: 100%; height: 100%; z-index: 9999999; position: fixed; outline: none !important; -webkit-backface-visibility: hidden } .penci-hide-tagupdated{ display: none !important; } .featured-area .penci-image-holder, .featured-area .penci-slider4-overlay, .featured-area .penci-slide-overlay .overlay-link, .featured-style-29 .featured-slider-overlay, .penci-slider38-overlay{ border-radius: ; -webkit-border-radius: ; } .penci-featured-content-right:before{ border-top-right-radius: ; border-bottom-right-radius: ; } .penci-flat-overlay .penci-slide-overlay .penci-mag-featured-content:before{ border-bottom-left-radius: ; border-bottom-right-radius: ; } .container-single .post-image{ border-radius: ; -webkit-border-radius: ; } .penci-mega-thumbnail .penci-image-holder{ border-radius: ; -webkit-border-radius: ; } #penci-login-popup:before{ opacity: ; } .penci-header-signup-form { padding-top: px; padding-bottom: px; } .penci-slide-overlay .overlay-link, .penci-slider38-overlay, .penci-flat-overlay .penci-slide-overlay .penci-mag-featured-content:before, .slider-40-wrapper .list-slider-creative .item-slider-creative .img-container:before { opacity: ; } .penci-item-mag:hover .penci-slide-overlay .overlay-link, .featured-style-38 .item:hover .penci-slider38-overlay, .penci-flat-overlay .penci-item-mag:hover .penci-slide-overlay .penci-mag-featured-content:before { opacity: ; } .penci-featured-content .featured-slider-overlay { opacity: ; } .slider-40-wrapper .list-slider-creative .item-slider-creative:hover .img-container:before { opacity:; } .featured-style-29 .featured-slider-overlay { opacity: ; } .penci-grid li.typography-style .overlay-typography { opacity: ; } .penci-grid li.typography-style:hover .overlay-typography { opacity: ; } #footer-copyright * { font-size: 17px; } #footer-copyright * { font-style: normal; } .home-featured-cat-content .mag-photo .mag-overlay-photo { opacity: ; } .home-featured-cat-content .mag-photo:hover .mag-overlay-photo { opacity: ; } .inner-item-portfolio:hover .penci-portfolio-thumbnail a:after { opacity: ; } .penci_header.penci-header-builder.main-builder-header{}.penci-header-image-logo,.penci-header-text-logo{}.pc-logo-desktop.penci-header-image-logo img{}@media only screen and (max-width: 767px){.penci_navbar_mobile .penci-header-image-logo img{}}.penci_builder_sticky_header_desktop .penci-header-image-logo img{}.penci_navbar_mobile .penci-header-text-logo{}.penci_navbar_mobile .penci-header-image-logo img{}.penci_navbar_mobile .sticky-enable .penci-header-image-logo img{}.pb-logo-sidebar-mobile{}.pc-builder-element.pb-logo-sidebar-mobile img{}.pc-logo-sticky{}.pc-builder-element.pc-logo-sticky.pc-logo img{}.pc-builder-element.pc-main-menu{}.pc-builder-element.pc-second-menu{}.pc-builder-element.pc-third-menu{}.penci-builder.penci-builder-button.button-1{}.penci-builder.penci-builder-button.button-1:hover{}.penci-builder.penci-builder-button.button-2{}.penci-builder.penci-builder-button.button-2:hover{}.penci-builder.penci-builder-button.button-3{}.penci-builder.penci-builder-button.button-3:hover{}.penci-builder.penci-builder-button.button-mobile-1{}.penci-builder.penci-builder-button.button-mobile-1:hover{}.penci-builder.penci-builder-button.button-mobile-2{}.penci-builder.penci-builder-button.button-mobile-2:hover{}.penci-builder-mobile-sidebar-nav.penci-menu-hbg{border-width:0;}.pc-builder-menu.pc-dropdown-menu{}.pc-builder-element.pc-logo.pb-logo-mobile{}.pc-header-element.penci-topbar-social .pclogin-item a{}.pc-header-element.penci-topbar-social-mobile .pclogin-item a{}body.penci-header-preview-layout .wrapper-boxed{min-height:1500px}
190.penci_header_overlap .penci-desktop-topblock,.penci-desktop-topblock{border-width:0;}.penci_header_overlap .penci-desktop-topbar,.penci-desktop-topbar{border-width:0;}.penci_header_overlap .penci-desktop-midbar,.penci-desktop-midbar{border-width:0;}.penci_header_overlap .penci-desktop-bottombar,.penci-desktop-bottombar{border-width:0;}.penci_header_overlap .penci-desktop-bottomblock,.penci-desktop-bottomblock{border-width:0;}.penci_header_overlap .penci-sticky-top,.penci-sticky-top{border-width:0;}.penci_header_overlap .penci-sticky-mid,.penci-sticky-mid{border-width:0;}.penci_header_overlap .penci-sticky-bottom,.penci-sticky-bottom{border-width:0;}.penci_header_overlap .penci-mobile-topbar,.penci-mobile-topbar{border-width:0;}.penci_header_overlap .penci-mobile-midbar,.penci-mobile-midbar{border-width:0;}.penci_header_overlap .penci-mobile-bottombar,.penci-mobile-bottombar{border-width:0;} body { --pcdm_btnbg: rgba(0, 0, 0, .1); --pcdm_btnd: #666; --pcdm_btndbg: #fff; --pcdm_btnn: var(--pctext-cl); --pcdm_btnnbg: var(--pcbg-cl); } body.pcdm-enable { --pcbg-cl: #000000; --pcbg-l-cl: #1a1a1a; --pcbg-d-cl: #000000; --pctext-cl: #fff; --pcborder-cl: #313131; --pcborders-cl: #3c3c3c; --pcheading-cl: rgba(255,255,255,0.9); --pcmeta-cl: #999999; --pcl-cl: #fff; --pclh-cl: #6eb48c; --pcaccent-cl: #6eb48c; background-color: var(--pcbg-cl); color: var(--pctext-cl); } body.pcdark-df.pcdm-enable.pclight-mode { --pcbg-cl: #fff; --pctext-cl: #313131; --pcborder-cl: #dedede; --pcheading-cl: #313131; --pcmeta-cl: #888888; --pcaccent-cl: #6eb48c; }</style>
190<script> 191var penciBlocksArray=[]; 192var portfolioDataJs = portfolioDataJs || [];var PENCILOCALCACHE = {}; 193 (function () { 194 "use strict"; 195 196 PENCILOCALCACHE = { 197 data: {}, 198 remove: function ( ajaxFilterItem ) { 199 delete PENCILOCALCACHE.data[ajaxFilterItem]; 200 }, 201 exist: function ( ajaxFilterItem ) { 202 return PENCILOCALCACHE.data.hasOwnProperty( ajaxFilterItem ) && PENCILOCALCACHE.data[ajaxFilterItem] !== null; 203 }, 204 get: function ( ajaxFilterItem ) { 205 return PENCILOCALCACHE.data[ajaxFilterItem]; 206 }, 207 set: function ( ajaxFilterItem, cachedData ) { 208 PENCILOCALCACHE.remove( ajaxFilterItem ); 209 PENCILOCALCACHE.data[ajaxFilterItem] = cachedData; 210 } 211 }; 212 } 213 )();function penciBlock() { 214 this.atts_json = ''; 215 this.content = ''; 216 }</script>
vendor: 1 bytes, line 216
216
217<script type="application/ld+json">{ 218 "@context": "https:\/\/schema.org\/", 219 "@type": "organization", 220 "@id": "#organization", 221 "logo": { 222 "@type": "ImageObject", 223 "url": "https:\/\/esp32learning.b-cdn.net\/wp-content\/uploads\/2017\/11\/logo272.png" 224 }, 225 "url": "https:\/\/www.esp32learning.com\/", 226 "name": "ESP32 Learning", 227 "description": "" 228}</script>
228<script type="application/ld+json">{ 229 "@context": "https:\/\/schema.org\/", 230 "@type": "WebSite", 231 "name": "ESP32 Learning", 232 "alternateName": "", 233 "url": "https:\/\/www.esp32learning.com\/" 234}</script>
234<script>var lebox_ajax_url = "https://www.esp32learning.com/wp-admin/admin-ajax.php";</script>
234 235</head> 236 237<body class="archive category category-code category-14 penci-disable-desc-collapse soledad-ver-8-5-4 pclight-mode pcmn-drdw-style-slide_down pchds-default"> 238<div id="soledad_wrapper" class="wrapper-boxed header-style-header-3 header-search-style-default"> 239 <div class="penci-header-wrap"><header id="header" class="header-header-3 has-bottom-line" itemscope="itemscope" itemtype="https://schema.org/WPHeader"> 240 <div class="inner-header penci-header-second"> 241 <div class="container container-1400 align-left-logo"> 242 <div id="logo"> 243 <a href="https://www.esp32learning.com/"><img 244 class="penci-mainlogo penci-limg" src="https://esp32learning.b-cdn.net/wp-content/uploads/2017/11/logo272.png" alt="ESP32 Learning" 245 width="272" 246 height="90"></a> 247 </div> 248 249 </div> 250 </div> 251 <nav id="navigation" class="header-layout-bottom header-3 menu-style-1" role="navigation" itemscope itemtype="https://schema.org/SiteNavigationElement"> 252 <div class="container container-1400"> 253 <div class="button-menu-mobile header-3"><svg width=18px height=18px viewBox="0 0 512 384" version=1.1 xmlns=http://www.w3.org/2000/svg xmlns:xlink=http://www.w3.org/1999/xlink><g stroke=none stroke-width=1 fill-rule=evenodd><g transform="translate(0.000000, 0.250080)"><rect x=0 y=0 width=512 height=62></rect><rect x=0 y=161 width=512 height=62></rect><rect x=0 y=321 width=512 height=62></rect></g></g></svg></div> 254 <ul id="menu-topmenu" class="menu"><li id="menu-item-73" class="menu-item menu-item-type-taxonomy menu-item-object-category current-menu-item menu-item-73"><a href="https://www.esp32learning.com/category/code">Code</a></li> 255<li id="menu-item-36" class="menu-item menu-item-type-taxonomy menu-item-object-category menu-item-36"><a href="https://www.esp32learning.com/category/information">Information</a></li> 256<li id="menu-item-37" class="menu-item menu-item-type-taxonomy menu-item-object-category menu-item-37"><a href="https://www.esp32learning.com/category/hardware">Hardware</a></li> 257<li id="menu-item-866" class="menu-item menu-item-type-taxonomy menu-item-object-category menu-item-866"><a href="https://www.esp32learning.com/category/micropython">Micropython</a></li> 258<li id="menu-item-35" class="menu-item menu-item-type-taxonomy menu-item-object-category menu-item-35"><a href="https://www.esp32learning.com/category/tutorials">Tutorials</a></li> 259</ul><div id="top-search" class="penci-top-search pcheader-icon top-search-classes"> 260 <a href="#" class="search-click" aria-label="Search"> 261 <i class="penciicon-magnifiying-glass"></i> 262 </a> 263 <div class="show-search pcbds-default"> 264 <form role="search" method="get" class="pc-searchform" 265 action="https://www.esp32learning.com/"> 266 <div class="pc-searchform-inner"> 267 <input type="text" class="search-input" 268 placeholder="Type and hit enter..." name="s"/> 269 <i class="penciicon-magnifiying-glass"></i> 270 <button type="submit" 271 class="searchsubmit">Search</button> 272 </div> 273 </form> 274 <a href="#" aria-label="Search" class="search-click close-search"><i class="penciicon-close-button"></i></a> 275 </div> 276</div> 277 278 </div> 279 </nav><!-- End Navigation --> 280 281</header> 282<!-- end #header --> 283</div> 284 <div class="container penci-breadcrumb"><span><span><a href="https://www.esp32learning.com/">Home</a></span> » <span class="breadcrumb_last" aria-current="page">Code</span></span></div> 285 286 287<div class="container penci_sidebar right-sidebar"> 288 <div id="main" 289 class="penci-layout-standard"> 290 <div class="theiaStickySidebar"> 291 292 293 294 <div class="archive-box"> 295 <div class="title-bar"> 296 <span>Category:</span> <h1 style="">Code</h1> 297 </div> 298 </div> 299 300 301 302 303 304 <article id="post-937" class="standard-article standard-pitem post-937 post type-post status-publish format-standard has-post-thumbnail hentry category-code tag-esp32 tag-sts35"> 305 306 307 308 <div class="standard-post-image"> 309 <a 310 href="https://www.esp32learning.com/code/connect-an-sts35-temperature-sensor-to-an-esp32.php"> 311 <img 312 class="attachment-penci-full-thumb size-penci-full-thumb penci-lazy wp-post-image" 313 width="606" 314 height="609" 315 src="data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%20606%20609'%3E%3C/svg%3E" alt="" title="ESP32 and STS35_bb" data-src="https://www.esp32learning.com/wp-content/uploads/2023/12/ESP32-and-STS35_bb.jpg"> </a> 316 </div> 317 318 319 <div class="header-standard 320 "> 321 <div class="penci-standard-cat"><span class="cat"><a style="" class="penci-cat-name penci-cat-14" href="https://www.esp32learning.com/category/code" rel="category tag"><span style="">Code</span></a></span></div> 322 323 <h2 class="penci-entry-title entry-title entry-title"><a 324 href="https://www.esp32learning.com/code/connect-an-sts35-temperature-sensor-to-an-esp32.php">Connect an STS35 temperature sensor to an ESP32</a></h2> 325 <div class="penci-hide-tagupdated"> 326 <span class="author-italic author vcard">by <a class="author-url url fn n" 327 href="https://www.esp32learning.com/author/shedboy71">shedboy71</a> 328 </span> 329 <time class="entry-date published" datetime="2024-12-22T13:02:48+00:00">22nd December 2024</time> </div> 330 </div> 331 332 <div class="standard-content"> 333 <div class="standard-main-content entry-content"> 334 <div class="post-entry standard-post-entry classic-post-entry blockquote-style-1 "> 335 <p>
335In this article we look at a temperature and pressure sensor, the STS35 temperature sensor from Sensirion, and connect it to an ESP32</p> 336<h3>Sensor Information</h3> 337<div id="productTogetherApp" class="lineFrame"> 338<div class="productLineFrame"> 339<div class="frequentlyFrame"> 340<div class="list"> 341<div class="btnFrame">The STS3x-DIS is Sensirion’s new high accuracy digital temperature sensor. It relies on the industry proven CMOSens® technology, providing for increased intelligence, reliability and improved accuracy specifications compared to its predecessors. Its functionality includes enhanced signal processing, two distinctive and user selectable I2C addresses and communication speeds of up to 1 MHz.</div> 342</div> 343</div> 344</div> 345</div> 346<div class="lineFrame"> 347<div class="productLineFrame"> 348<div class="leftBox"> 349<div class="desc"> 350<h4>FEATURES</h4> 351<div class="desCon"> 352<ul> 353<li>Factory calibrated, accurate digital output</li> 354<li>High accuracy, ±0.1℃ temperature error</li> 355<li>Fast startup time, 0.5ms</li> 356<li>High reliability, long-term stability</li> 357</ul> 358</div> 359<h4>SPECIFICATION</h4> 360<div class="desCon"> 361<ul> 362<li>Operating Voltage: 2.15~5.5V DC</li> 363<li>Heating Power Consumption: 3.6~33mW</li> 364<li>Output Signal: I2C</li> 365<li>Measuring Range: -40~125℃</li> 366<li>Accuracy: ±0.1℃</li> 367<li>Resolution: 0.01℃</li> 368<li>Preheat: ≤1.5ms (Typical, 0.5ms)</li> 369<li>Response Time: >2s</li> 370<li>Operating Temperature: -40~125℃</li> 371</ul> 372<p> </p> 373</div> 374</div> 375</div> 376</div> 377</div> 378<div class="product-feature-category" data-module-component="product-features"> 379<div class="feature-category-label-column"> 380<div class="pcrstb-wrap"><table> 381<thead> 382<tr> 383<th align="left">
383Num</th> 384<th align="left">Label</th> 385<th align="left">Description</th> 386</tr> 387</thead> 388<tbody> 389<tr> 390<td align="left">1</td> 391<td align="left">RST</td> 392<td align="left">Reset pin (pull down to reset)</td> 393</tr> 394<tr> 395<td align="left">2</td> 396<td align="left">ADDR</td> 397<td align="left">I2C address pin (default to be 0x4B, pull-down address is 0x4A)</td> 398</tr> 399<tr> 400<td align="left">3</td> 401<td align="left">SDA</td> 402<td align="left">I2C data line</td> 403</tr> 404<tr> 405<td align="left">4</td> 406<td align="left">SCL</td> 407<td align="left">I2C clock line</td> 408</tr> 409<tr> 410<td align="left">5</td> 411<td align="left">GND</td> 412<td align="left">Gnd</td> 413</tr> 414<tr> 415<td align="left">6</td> 416<td align="left">VCC</td> 417<td align="left"><span style="letter-spacing: 0px;">3.3 to 5v</span></td> 418</tr> 419</tbody> 420</table></div> 421<p><span style="font-family: Raleway, sans-serif; font-size: 20px; font-weight: bold; letter-spacing: 0px;">Parts Required</span></p> 422<p>You can connect to the sensor using DuPont-style jumper wire.</p> 423<p>The sensor costs about $7.50</p> 424<div class="pcrstb-wrap"><table> 425<tbody> 426<tr style="height: 21px;"> 427<td style="width: 15.8442%; height: 21px;"><strong>Name</strong></td> 428<td style="width: 40.1299%; height: 21px;"><strong>Link</strong></td> 429<td style="width: 44.4156%;"></td> 430</tr> 431<tr style="height: 55px;"> 432<td style="width: 15.8442%; height: 55px;">ESP32</td> 433<td style="width: 40.1299%;"><a href="https://s.click.aliexpress.com/e/_DkIPPqt" target="_blank" rel="noopener"><img decoding="async" src="//ae01.alicdn.com/kf/Sbf885b40323a45178795fde862d61c3cT.jpg_140x140.jpg"" /></a></td> 434<td style="width: 44.4156%; height: 55px;"> 435<ul> 436<li><a href="https://s.click.aliexpress.com/e/_DkIPPqt" target="_blank" rel="noopener">Aliexpress link</a></li> 437<li><a href="https://www.amazon.com/s?k=esp32&ref=nb_sb_ss_ts-doa-p_1_11&_encoding=UTF8&linkId=b0663f9ccf4a4bf9c4a082212a1636de&camp=1789&creative=9325" target="_blank" rel="noopener">Amazon</a></li> 438<li><a href="https://www.ebay.com/sch/i.html?_from=R40&_trksid=p4432023.m570.l1313&_nkw=esp32&_sacat=0" target="_blank" rel="noopener">Ebay</a></li> 439</ul> 440</td> 441</tr> 442<tr style="height: 55px;"> 443<td style="width: 15.8442%; height: 55px;">STS35</td> 444<td style="width: 40.1299%;"></td> 445<td style="width: 44.4156%; height: 55px;"> 446<ul> 447<li><a href="https://s.click.aliexpress.com/e/_DD4BCvx" target="_blank" rel="noopener">Aliexpress link</a></li> 448<li><a href="https://www.dfrobot.com/product-2548.html?tracking=pIXaPCCrC8xmOAAZsuRSwgx4S4qi6jbAnH5EbM8tR250BwwkAVSXi6d0rO1PfX3C" target="_blank" rel="noopener">DFRobot link</a></li> 449</ul> 450</td> 451</tr> 452<tr style="height: 21px;"> 453<td style="width: 15.8442%; height: 21px;">Connecting cables</td> 454<td style="width: 40.1299%;"><img decoding="async" class="alignnone size-thumbnail wp-image-13" src="http://www.arduinocode.com/wp-content/uploads/2023/07/dupont-150x150.jpg" alt="" width="150" height="150" /></td> 455<td style="width: 44.4156%; height: 21px;"> 456<ul> 457<li><a href="https://s.click.aliexpress.com/e/_Dnk1xwF" target="_blank" rel="noopener">Aliexpress link</a></li> 458<li><a href="https://amzn.to/3Y5vMOO" target="_blank" rel="noopener">Amazon</a></li> 459<li><a href="https://www.ebay.com/sch/i.html?_from=R40&_trksid=p4432023.m570.l1313&_nkw=dupont+cables&_sacat=0" target="_blank" rel="noopener">Ebay</a></li> 460</ul> 461</td> 462</tr> 463</tbody> 464</table></div> 465<p> </p> 466<h3>Schematic/Connection</h3> 467<p><img decoding="async" class="alignnone size-full wp-image-939" src="https://www.esp32learning.com/wp-content/uploads/2023/12/ESP32-and-STS35_bb.jpg" alt="" width="606" height="609" srcset="https://www.esp32learning.com/wp-content/uploads/2023/12/ESP32-and-STS35_bb.jpg 606w, https://www.esp32learning.com/wp-content/uploads/2023/12/ESP32-and-STS35_bb-300x300.jpg 300w, https://www.esp32learning.com/wp-content/uploads/2023/12/ESP32-and-STS35_bb-150x150.jpg 150w" sizes="(max-width: 606px) 100vw, 606px" /></p> 468<h3>Code Example</h3> 469<p>Download the library from github – <a href="https://github.com/DFRobot/DFRobot_STS3X/tree/main" target="_blank" rel="noopener">https://github.com/DFRobot/DFRobot_STS3X/tree/main</a></p> 470<p>Import the zip file into the Arduino IDE, this is one of the default examples</p> 471<pre class="EnlighterJSRAW" data-enlighter-language="cpp">#include "DFRobot_STS3X.h" 472 473/** 474 * Determine I2C address according to the ADDR pin pull-up or pull-down 475 * ADDR pin pull-down: STS3X_I2C_ADDRESS_A 0x4A 476 * ADDR pin or pull-up: STS3X_I2C_ADDRESS_B 0x4B 477 */ 478DFRobot_STS3X sts(&Wire, STS3X_I2C_ADDRESS_B); 479 480 481void setup(void) 482{ 483 Serial.begin(9600); 484 /* Wait for the chip to be initialized completely, and then exit */ 485 while(sts.begin() != true){
486 Serial.println("Failed to init chip, please check if the chip connection is fine. "); 487 delay(1000); 488 } 489 Serial.println("Begin ok!"); 490 491 /** 492 * Set measurement frequency 493 * freq: Select e2S, e1Hz, e2Hz, e4Hz and e10Hz mode in the enumeration variable eFreq_t 494 */ 495 sts.setFreq(sts.e10Hz); 496 497} 498 499void loop() { 500 Serial.print(sts.getTemperaturePeriodC()); 501 Serial.println(" ℃"); 502 delay(1000); 503}</pre> 504<p> </p> 505<p> </p> 506</div> 507<div class="feature-category-label-column"> 508<h4>Output</h4> 509<p>When run you will see something like this in the serial monitor window, this was doing the typical ‘touch the sensor’ test so you can see the temperature rising</p> 510<p>15.80 ℃<br /> 51115.80 ℃<br /> 51215.82 ℃<br /> 51315.84 ℃<br /> 51415.77 ℃<br /> 51515.79 ℃<br /> 51615.82 ℃</p> 517<h3>Links</h3> 518<p><a href="https://sensirion.com/media/documents/1DA31AFD/61641F76/Sensirion_Temperature_Sensors_STS3x_Datasheet.pdf" target="_blank" rel="noopener">https://sensirion.com/media/documents/1DA31AFD/61641F76/Sensirion_Temperature_Sensors_STS3x_Datasheet.pdf</a></p> 519</div> 520</div> 521<div class="addtoany_share_save_container addtoany_content addtoany_content_bottom"><div class="a2a_kit a2a_kit_size_32 addtoany_list" data-a2a-url="https://www.esp32learning.com/code/connect-an-sts35-temperature-sensor-to-an-esp32.php" data-a2a-title="Connect an STS35 temperature sensor to an ESP32"><a class="a2a_button_facebook" href="https://www.addtoany.com/add_to/facebook?linkurl=https%3A%2F%2Fwww.esp32learning.com%2Fcode%2Fconnect-an-sts35-temperature-sensor-to-an-esp32.php&linkname=Connect%20an%20STS35%20temperature%20sensor%20to%20an%20ESP32" title="Facebook" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_twitter" href="https://www.addtoany.com/add_to/twitter?linkurl=https%3A%2F%2Fwww.esp32learning.com%2Fcode%2Fconnect-an-sts35-temperature-sensor-to-an-esp32.php&linkname=Connect%20an%20STS35%20temperature%20sensor%20to%20an%20ESP32" title="Twitter" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_threads" href="https://www.addtoany.com/add_to/threads?linkurl=https%3A%2F%2Fwww.esp32learning.com%2Fcode%2Fconnect-an-sts35-temperature-sensor-to-an-esp32.php&linkname=Connect%20an%20STS35%20temperature%20sensor%20to%20an%20ESP32" title="Threads" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_pinterest" href="https://www.addtoany.com/add_to/pinterest?linkurl=https%3A%2F%2Fwww.esp32learning.com%2Fcode%2Fconnect-an-sts35-temperature-sensor-to-an-esp32.php&linkname=Connect%20an%20STS35%20temperature%20sensor%20to%20an%20ESP32" title="Pinterest" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_tumblr" href="https://www.addtoany.com/add_to/tumblr?linkurl=https%3A%2F%2Fwww.esp32learning.com%2Fcode%2Fconnect-an-sts35-temperature-sensor-to-an-esp32.php&linkname=Connect%20an%20STS35%20temperature%20sensor%20to%20an%20ESP32" title="Tumblr" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_reddit" href="https://www.addtoany.com/add_to/reddit?linkurl=https%3A%2F%2Fwww.esp32learning.com%2Fcode%2Fconnect-an-sts35-temperature-sensor-to-an-esp32.php&linkname=Connect%20an%20STS35%20temperature%20sensor%20to%20an%20ESP32" title="Reddit" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_linkedin" href="https://www.addtoany.com/add_to/linkedin?linkurl=https%3A%2F%2Fwww.esp32learning.com%2Fcode%2Fconnect-an-sts35-temperature-sensor-to-an-esp32.php&linkname=Connect%20an%20STS35%20temperature%20sensor%20to%20an%20ESP32" title="LinkedIn" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_digg" href="https://www.addtoany.com/add_to/digg?linkurl=https%3A%2F%2Fwww.esp32learning.com%2Fcode%2Fconnect-an-sts35-temperature-sensor-to-an-esp32.php&linkname=Connect%20an%20STS35%20temperature%20sensor%20to%20an%20ESP32" title="Digg" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_pocket" href="https://www.addtoany.com/add_to/pocket?linkurl=https%3A%2F%2Fwww.esp32learning.com%2Fcode%2Fconnect-an-sts35-temperature-sensor-to-an-esp32.php&linkname=Connect%20an%20STS35%20temperature%20sensor%20to%20an%20ESP32" title="Pocket" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_sina_weibo" href="https://www.addtoany.com/add_to/sina_weibo?linkurl=https%3A%2F%2Fwww.esp32learning.com%2Fcode%2Fconnect-an-sts35-temperature-sensor-to-an-esp32.php&linkname=Connect%20an%20STS35%20temperature%20sensor%20to%20an%20ESP32" title="Sina Weibo" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_wordpress" href="https://www.addtoany.com/add_to/wordpress?linkurl=https%3A%2F%2Fwww.esp32learning.com%2Fcode%2Fconnect-an-sts35-temperature-sensor-to-an-esp32.php&linkname=Connect%20an%20STS35%20temperature%20sensor%20to%20an%20ESP32" title="WordPress" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_blogger" href="https://www.addtoany.com/add_to/blogger?linkurl=https%3A%2F%2Fwww.esp32learning.com%2Fcode%2Fconnect-an-sts35-temperature-sensor-to-an-esp32.php&linkname=Connect%20an%20STS35%20temperature%20sensor%20to%20an%20ESP32" title="Blogger" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_sms" href="https://www.addtoany.com/add_to/sms?linkurl=https%3A%2F%2Fwww.esp32learning.com%2Fcode%2Fconnect-an-sts35-temperature-sensor-to-an-esp32.php&linkname=Connect%20an%20STS35%20temperature%20sensor%20to%20an%20ESP32" title="Message" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_whatsapp" href="https://www.addtoany.com/add_to/whatsapp?linkurl=https%3A%2F%2Fwww.esp32learning.com%2Fcode%2Fconnect-an-sts35-temperature-sensor-to-an-esp32.php&linkname=Connect%20an%20STS35%20temperature%20sensor%20to%20an%20ESP32" title="WhatsApp" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_telegram" href="https://www.addtoany.com/add_to/telegram?linkurl=https%3A%2F%2Fwww.esp32learning.com%2Fcode%2Fconnect-an-sts35-temperature-sensor-to-an-esp32.php&linkname=Connect%20an%20STS35%20temperature%20sensor%20to%20an%20ESP32" title="Telegram" rel="nofollow noopener" target="_blank"></a><a class="a2a_dd addtoany_share_save addtoany_share" href="https://www.addtoany.com/share"></a></div></div> </div> 522 </div> 523 524 <div class="penci-post-box-meta 525 center-inner "> 526 <div class="penci-post-share-box"> 527 <a href="#" class="penci-post-like" aria-label="Like this post" data-post_id="937" title="Like" data-like="Like" data-unlike="Unlike"><i class="penci-faicon fa fa-heart-o" ></i><span class="dt-share">0</span></a> <a class="new-ver-share post-share-item post-share-facebook" aria-label="Share on Facebook" target="_blank" rel="noreferrer" href="https://www.facebook.com/sharer/sharer.php?u=https://www.esp32learning.com/code/connect-an-sts35-temperature-sensor-to-an-esp32.php"><i class="penci-faicon fa fa-facebook" ></i><span class="dt-share">Facebook</span></a><a class="new-ver-share post-share-item post-share-twitter" aria-label="Share on Twitter" target="_blank" rel="noreferrer" href="https://twitter.com/intent/tweet?text=Check%20out%20this%20article:%20Connect%20an%20STS35%20temperature%20sensor%20to%20an%20ESP32%20-%20https://www.esp32learning.com/code/connect-an-sts35-temperature-sensor-to-an-esp32.php"><i class="penci-faicon penciicon-x-twitter" ></i><span class="dt-share">Twitter</span></a><a class="new-ver-share post-share-item post-share-pinterest" aria-label="Pin to Pinterest" data-pin-do="none" rel="noreferrer" target="_blank" href="https://www.pinterest.com/pin/create/button/?url=https%3A%2F%2Fwww.esp32learning.com%2Fcode%2Fconnect-an-sts35-temperature-sensor-to-an-esp32.php&media=https%3A%2F%2Fwww.esp32learning.com%2Fwp-content%2Fuploads%2F2023%2F12%2FESP32-and-STS35_bb.jpg&description=Connect+an+STS35+temperature+sensor+to+an+ESP32"><i class="penci-faicon fa fa-pinterest" ></i><span class="dt-share">Pinterest</span></a><a class="new-ver-share post-share-item post-share-email" target="_blank" aria-label="Share via Email" rel="noreferrer" href="mailto:?subject=Connect%20an%20STS35%20temperature%20sensor%20to%20an%20ESP32&BODY=https://www.esp32learning.com/code/connect-an-sts35-temperature-sensor-to-an-esp32.php"><i class="penci-faicon fa fa-envelope" ></i><span class="dt-share">Email</span></a> </div> 528 </div> 529 </div> 530 531</article> 532 533<article id="post-933" class="standard-article standard-pitem post-933 post type-post status-publish format-standard has-post-thumbnail hentry category-code tag-esp32 tag-is31fl3741"> 534 535 536 537 <div class="standard-post-image"> 538 <a 539 href="https://www.esp32learning.com/code/connect-an-is31fl3741-led-matrix-module-to-an-esp32.php"> 540 <img 541 class="attachment-penci-full-thumb size-penci-full-thumb penci-lazy wp-post-image" 542 width="1026" 543 height="645" 544 src="data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%201026%20645'%3E%3C/svg%3E" alt="" title="ESP32 and IS31FL3741_bb" data-src="https://www.esp32learning.com/wp-content/uploads/2023/12/ESP32-and-IS31FL3741_bb.jpg"> </a> 545 </div> 546 547 548 <div class="header-standard 549 "> 550 <div class="penci-standard-cat"><span class="cat"><a style="" class="penci-cat-name penci-cat-14" href="https://www.esp32learning.com/category/code" rel="category tag"><span style="">Code</span></a></span></div> 551 552 <h2 class="penci-entry-title entry-title entry-title"><a 553 href="https://www.esp32learning.com/code/connect-an-is31fl3741-led-matrix-module-to-an-esp32.php">Connect an IS31FL3741 LED matrix module to an ESP32</a></h2> 554 <div class="penci-hide-tagupdated"> 555 <span class="author-italic author vcard">by <a class="author-url url fn n" 556 href="https://www.esp32learning.com/author/shedboy71">shedboy71</a> 557 </span> 558 <time class="entry-date published" datetime="2024-03-22T16:43:20+00:00">22nd March 2024</time> </div> 559 </div> 560 561 <div class="standard-content"> 562 <div class="standard-main-content entry-content"> 563 <div class="post-entry standard-post-entry classic-post-entry blockquote-style-1 "> 564 <p>
564In this article we look at a module with lots of LEDs on it, its an IS31FL3741 LED matrix module from adafruit</p> 565<h3>Module Information</h3> 566<p>At the centre of the module is the IS31FL3741</p> 567<p>The IS31FL3741 is a general purpose 39×9 LED Matrix programmed via an I2C compatible interface.</p> 568<p>Each LED can be dimmed individually with 8-bit PWM data and 8-bit scaling data which allowing 256 steps of linear PWM dimming and 256 steps of DC current adjustable level.</p> 569<p>Additionally each LED open and short state can be detected, IS31FL3741 store the open or short information in Open-Short Registers. The Open-Short Registers allowing MCU to read out via I2C compatible interface. Inform MCU whether there are LEDs open or short and the locations of open or short LEDs.</p> 570<p>The IS31FL3741 operates from 2.7V to 5.5V and features a very low shutdown and operational current.</p> 571<h4>FEATURES</h4> 572<p>Supply voltage range: 2.7V ~ 5.5V<br /> 5739 Current Sink × 9 SW matrix size: drive up to 351 LEDs or 117 RGBs<br /> 574Individual 256 PWM control steps<br /> 575Individual 256 DC current steps<br /> 576Global 255 current setting<br /> 577SDB rising edge reset I2C module<br /> 578Programmable H/L logic: 1.4/0.4, 2.4/0.6<br /> 57929kHz PWM frequency<br /> 5801MHz I2C-compatible interface<br /> 581interrupt and state lookup registers<br /> 582Individual open and short error detect function</p> 583<p>The adafruit module features a 13×9 RGB LED matrix breakout for a grand total of 117 RGB LEDs</p> 584<div class="product-feature-category" data-module-component="product-features"> 585<div class="feature-category-label-column"> 586<h3>Parts Required</h3> 587<div class="pcrstb-wrap"><table> 588<tbody> 589<tr style="height: 21px;"> 590<td style="width: 15.8442%; height: 21px;"><strong>Name</strong></td> 591<td style="width: 40.1299%; height: 21px;"><strong>Link</strong></td> 592<td style="width: 44.4156%;"></td> 593</tr> 594<tr style="height: 55px;"> 595<td style="width: 15.8442%; height: 55px;">ESP32</td> 596<td style="width: 40.1299%;"><a href="https://s.click.aliexpress.com/e/_DkIPPqt" target="_blank" rel="noopener"><img decoding="async" src="//ae01.alicdn.com/kf/Sbf885b40323a45178795fde862d61c3cT.jpg_140x140.jpg"" /></a></td> 597<td style="width: 44.4156%; height: 55px;"> 598<ul> 599<li><a href="https://s.click.aliexpress.com/e/_DkIPPqt" target="_blank" rel="noopener">Aliexpress link</a></li> 600<li><a href="https://www.amazon.com/s?k=esp32&ref=nb_sb_ss_ts-doa-p_1_11&_encoding=UTF8&linkId=b0663f9ccf4a4bf9c4a082212a1636de&camp=1789&creative=9325" target="_blank" rel="noopener">Amazon</a></li> 601<li><a href="https://www.ebay.com/sch/i.html?_from=R40&_trksid=p4432023.m570.l1313&_nkw=esp32&_sacat=0" target="_blank" rel="noopener">Ebay</a></li> 602</ul> 603</td> 604</tr> 605<tr style="height: 55px;"> 606<td style="width: 15.8442%; height: 55px;">IS31FL3741</td> 607<td style="width: 40.1299%;"></td> 608<td style="width: 44.4156%; height: 55px;"> 609<ul> 610<li><a href="https://www.amazon.com/s?k=is31fl3741&_encoding=UTF8&camp=1789&creative=9325&linkId=b0663f9ccf4a4bf9c4a082212a1636de&ref=nb_sb_ss_ts-doa-p_1_11" target="_blank" rel="noopener">Amazon link</a></li> 611<li><a href="https://www.ebay.com/sch/i.html?_from=R40&_trksid=p4432023.m570.l1313&_nkw=is31fl3741&_sacat=0" target="_blank" rel="noopener">Ebay link</a></li> 612</ul> 613</td> 614</tr> 615<tr style="height: 21px;"> 616<td style="width: 15.8442%; height: 21px;">Connecting cables</td> 617<td style="width: 40.1299%;"><img decoding="async" class="alignnone size-thumbnail wp-image-13" src="http://www.arduinocode.com/wp-content/uploads/2023/07/dupont-150x150.jpg" alt="" width="150" height="150" /></td> 618<td style="width: 44.4156%; height: 21px;"> 619<ul> 620<li><a href="https://s.click.aliexpress.com/e/_Dnk1xwF" target="_blank" rel="noopener">Aliexpress link</a></li> 621<li><a href="https://amzn.to/3Y5vMOO" target="_blank" rel="noopener">Amazon</a></li> 622<li><a href="https://www.ebay.com/sch/i.html?_from=R40&_trksid=p4432023.m570.l1313&_nkw=dupont+cables&_sacat=0" target="_blank" rel="noopener">Ebay</a></li> 623</ul> 624</td> 625</tr> 626</tbody> 627</table></div> 628<h3>Schematic/Connection</h3> 629<p> </p> 630<p><img decoding="async" class="alignnone size-large wp-image-935" src="https://www.esp32learning.com/wp-content/uploads/2023/12/ESP32-and-IS31FL3741_bb-1024x644.jpg" alt="" width="1024" height="644" srcset="https://www.esp32learning.com/wp-content/uploads/2023/12/ESP32-and-IS31FL3741_bb-1024x644.jpg 1024w, https://www.esp32learning.com/wp-content/uploads/2023/12/ESP32-and-IS31FL3741_bb-300x189.jpg 300w, https://www.esp32learning.com/wp-content/uploads/2023/12/ESP32-and-IS31FL3741_bb-768x483.jpg 768w, https://www.esp32learning.com/wp-content/uploads/2023/12/ESP32-and-IS31FL3741_bb.jpg 1026w" sizes="(max-width: 1024px) 100vw, 1024px" /></p> 631<h3>Code Example</h3> 632</div> 633</div> 634<p>You can install the Adafruit IS31FL3741 library for Arduino using the Library Manager in the Arduino IDE.</p> 635<p>Click Manage Libraries, search for IS31FL3741 , and select the Adafruit IS31FL3741 library, and install the latest version:</p> 636<p>You may be asked about dependencies if this is the first time you have installed an Adafruit library, click “Install all” to install them as well.</p> 637<p>The library has several example – this one scrolls text on the matrix and we have toned the brightness down as well – they are bright leds</p> 638<p> </p> 639<pre class="EnlighterJSRAW" data-enlighter-language="cpp">#include <Adafruit_IS31FL3741.h> 640 641Adafruit_IS31FL3741_QT matrix; 642// If colors appear wrong on matrix, try invoking constructor like so: 643// Adafruit_IS31FL3741_QT matrix(IS3741_RBG); 644 645// Some boards have just one I2C interface, but some have more... 646TwoWire *i2c = &Wire; // e.g. change this to &
646Wire1 for QT Py RP2040 647 648char text[] = "esp32learning!"; // A message to scroll 649int text_x = matrix.width(); // Initial text position = off right edge 650int text_y = 1; 651int text_min; // Pos. where text resets (calc'd later) 652 653void setup() { 654 Serial.begin(115200); 655 Serial.println("Adafruit QT RGB Matrix Scrolling Text Test"); 656 657 if (! matrix.begin(IS3741_ADDR_DEFAULT, i2c)) { 658 Serial.println("IS41 not found"); 659 while (1); 660 } 661 662 Serial.println("IS41 found!"); 663 664 // By default the LED controller communicates over I2C at 400 KHz. 665 // Arduino Uno can usually do 800 KHz, and 32-bit microcontrollers 1 MHz. 666 i2c->setClock(800000); 667 668 // Set brightness to max and bring controller out of shutdown state 669 matrix.setLEDscaling(0x10); 670 matrix.setGlobalCurrent(0x10); 671 Serial.print("Global current set to: "); 672 Serial.println(matrix.getGlobalCurrent()); 673 674 matrix.fill(0); 675 matrix.enable(true); // bring out of shutdown 676 matrix.setRotation(0); 677 matrix.setTextWrap(false); 678 679 // Get text dimensions to determine X coord where scrolling resets 680 uint16_t w, h; 681 int16_t ignore; 682 matrix.getTextBounds(text, 0, 0, &ignore, &ignore, &w, &h); 683 text_min = -w; // Off left edge this many pixels 684} 685 686void loop() { 687 matrix.setCursor(text_x, text_y); 688 for (int i = 0; i < (int)strlen(text); i++) { 689 // set the color thru the rainbow 690 uint32_t color888 = matrix.ColorHSV(65536 * i / strlen(text));
691 uint16_t color565 = matrix.color565(color888); 692 matrix.setTextColor(color565, 0); // backound is '0' to erase previous text! 693 matrix.print(text[i]); // write the letter 694 } 695 696 if (--text_x < text_min) { 697 text_x = matrix.width(); 698 } 699 700 delay(25); 701}</pre> 702<p> </p> 703<div class="product-feature-category" data-module-component="product-features"> 704<div class="feature-category-label-column"> 705<h4></h4> 706</div> 707</div> 708<div class="addtoany_share_save_container addtoany_content addtoany_content_bottom"><div class="a2a_kit a2a_kit_size_32 addtoany_list" data-a2a-url="https://www.esp32learning.com/code/connect-an-is31fl3741-led-matrix-module-to-an-esp32.php" data-a2a-title="Connect an IS31FL3741 LED matrix module to an ESP32"><a class="a2a_button_facebook" href="https://www.addtoany.com/add_to/facebook?linkurl=https%3A%2F%2Fwww.esp32learning.com%2Fcode%2Fconnect-an-is31fl3741-led-matrix-module-to-an-esp32.php&linkname=Connect%20an%20IS31FL3741%20LED%20matrix%20module%20to%20an%20ESP32" title="Facebook" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_twitter" href="https://www.addtoany.com/add_to/twitter?linkurl=https%3A%2F%2Fwww.esp32learning.com%2Fcode%2Fconnect-an-is31fl3741-led-matrix-module-to-an-esp32.php&linkname=Connect%20an%20IS31FL3741%20LED%20matrix%20module%20to%20an%20ESP32" title="Twitter" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_threads" href="https://www.addtoany.com/add_to/threads?linkurl=https%3A%2F%2Fwww.esp32learning.com%2Fcode%2Fconnect-an-is31fl3741-led-matrix-module-to-an-esp32.php&linkname=Connect%20an%20IS31FL3741%20LED%20matrix%20module%20to%20an%20ESP32" title="Threads" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_pinterest" href="https://www.addtoany.com/add_to/pinterest?linkurl=https%3A%2F%2Fwww.esp32learning.com%2Fcode%2Fconnect-an-is31fl3741-led-matrix-module-to-an-esp32.php&linkname=Connect%20an%20IS31FL3741%20LED%20matrix%20module%20to%20an%20ESP32" title="Pinterest" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_tumblr" href="https://www.addtoany.com/add_to/tumblr?linkurl=https%3A%2F%2Fwww.esp32learning.com%2Fcode%2Fconnect-an-is31fl3741-led-matrix-module-to-an-esp32.php&linkname=Connect%20an%20IS31FL3741%20LED%20matrix%20module%20to%20an%20ESP32" title="Tumblr" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_reddit" href="https://www.addtoany.com/add_to/reddit?linkurl=https%3A%2F%2Fwww.esp32learning.com%2Fcode%2Fconnect-an-is31fl3741-led-matrix-module-to-an-esp32.php&linkname=Connect%20an%20IS31FL3741%20LED%20matrix%20module%20to%20an%20ESP32" title="Reddit" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_linkedin" href="https://www.addtoany.com/add_to/linkedin?linkurl=https%3A%2F%2Fwww.esp32learning.com%2Fcode%2Fconnect-an-is31fl3741-led-matrix-module-to-an-esp32.php&linkname=Connect%20an%20IS31FL3741%20LED%20matrix%20module%20to%20an%20ESP32" title="LinkedIn" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_digg" href="https://www.addtoany.com/add_to/digg?linkurl=https%3A%2F%2Fwww.esp32learning.com%2Fcode%2Fconnect-an-is31fl3741-led-matrix-module-to-an-esp32.php&linkname=Connect%20an%20IS31FL3741%20LED%20matrix%20module%20to%20an%20ESP32" title="Digg" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_pocket" href="https://www.addtoany.com/add_to/pocket?linkurl=https%3A%2F%2Fwww.esp32learning.com%2Fcode%2Fconnect-an-is31fl3741-led-matrix-module-to-an-esp32.php&linkname=Connect%20an%20IS31FL3741%20LED%20matrix%20module%20to%20an%20ESP32" title="Pocket" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_sina_weibo" href="https://www.addtoany.com/add_to/sina_weibo?linkurl=https%3A%2F%2Fwww.esp32learning.com%2Fcode%2Fconnect-an-is31fl3741-led-matrix-module-to-an-esp32.php&linkname=Connect%20an%20IS31FL3741%20LED%20matrix%20module%20to%20an%20ESP32" title="Sina Weibo" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_wordpress" href="https://www.addtoany.com/add_to/wordpress?linkurl=https%3A%2F%2Fwww.esp32learning.com%2Fcode%2Fconnect-an-is31fl3741-led-matrix-module-to-an-esp32.php&linkname=Connect%20an%20IS31FL3741%20LED%20matrix%20module%20to%20an%20ESP32" title="WordPress" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_blogger" href="https://www.addtoany.com/add_to/blogger?linkurl=https%3A%2F%2Fwww.esp32learning.com%2Fcode%2Fconnect-an-is31fl3741-led-matrix-module-to-an-esp32.php&linkname=Connect%20an%20IS31FL3741%20LED%20matrix%20module%20to%20an%20ESP32" title="Blogger" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_sms" href="https://www.addtoany.com/add_to/sms?linkurl=https%3A%2F%2Fwww.esp32learning.com%2Fcode%2Fconnect-an-is31fl3741-led-matrix-module-to-an-esp32.php&linkname=Connect%20an%20IS31FL3741%20LED%20matrix%20module%20to%20an%20ESP32" title="Message" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_whatsapp" href="https://www.addtoany.com/add_to/whatsapp?linkurl=https%3A%2F%2Fwww.esp32learning.com%2Fcode%2Fconnect-an-is31fl3741-led-matrix-module-to-an-esp32.php&linkname=Connect%20an%20IS31FL3741%20LED%20matrix%20module%20to%20an%20ESP32" title="WhatsApp" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_telegram" href="https://www.addtoany.com/add_to/telegram?linkurl=https%3A%2F%2Fwww.esp32learning.com%2Fcode%2Fconnect-an-is31fl3741-led-matrix-module-to-an-esp32.php&linkname=Connect%20an%20IS31FL3741%20LED%20matrix%20module%20to%20an%20ESP32" title="Telegram" rel="nofollow noopener" target="_blank"></a><a class="a2a_dd addtoany_share_save addtoany_share" href="https://www.addtoany.com/share"></a></div></div> </div> 709 </div> 710 711 <div class="penci-post-box-meta 712 center-inner "> 713 <div class="penci-post-share-box"> 714 <a href="#" class="penci-post-like" aria-label="Like this post" data-post_id="933" title="Like" data-like="Like" data-unlike="Unlike"><i class="penci-faicon fa fa-heart-o" ></i><span class="dt-share">3</span></a> <a class="new-ver-share post-share-item post-share-facebook" aria-label="Share on Facebook" target="_blank" rel="noreferrer" href="https://www.facebook.com/sharer/sharer.php?u=https://www.esp32learning.com/code/connect-an-is31fl3741-led-matrix-module-to-an-esp32.php"><i class="penci-faicon fa fa-facebook" ></i><span class="dt-share">Facebook</span></a><a class="new-ver-share post-share-item post-share-twitter" aria-label="Share on Twitter" target="_blank" rel="noreferrer" href="https://twitter.com/intent/tweet?text=Check%20out%20this%20article:%20Connect%20an%20IS31FL3741%20LED%20matrix%20module%20to%20an%20ESP32%20-%20https://www.esp32learning.com/code/connect-an-is31fl3741-led-matrix-module-to-an-esp32.php"><i class="penci-faicon penciicon-x-twitter" ></i><span class="dt-share">Twitter</span></a><a class="new-ver-share post-share-item post-share-pinterest" aria-label="Pin to Pinterest" data-pin-do="none" rel="noreferrer" target="_blank" href="https://www.pinterest.com/pin/create/button/?url=https%3A%2F%2Fwww.esp32learning.com%2Fcode%2Fconnect-an-is31fl3741-led-matrix-module-to-an-esp32.php&media=https%3A%2F%2Fwww.esp32learning.com%2Fwp-content%2Fuploads%2F2023%2F12%2FESP32-and-IS31FL3741_bb.jpg&description=Connect+an+IS31FL3741+LED+matrix+module+to+an+ESP32"><i class="penci-faicon fa fa-pinterest" ></i><span class="dt-share">Pinterest</span></a><a class="new-ver-share post-share-item post-share-email" target="_blank" aria-label="Share via Email" rel="noreferrer" href="mailto:?subject=Connect%20an%20IS31FL3741%20LED%20matrix%20module%20to%20an%20ESP32&BODY=https://www.esp32learning.com/code/connect-an-is31fl3741-led-matrix-module-to-an-esp32.php"><i class="penci-faicon fa fa-envelope" ></i><span class="dt-share">Email</span></a> </div> 715 </div> 716 </div> 717 718</article> 719 720<article id="post-929" class="standard-article standard-pitem post-929 post type-post status-publish format-standard has-post-thumbnail hentry category-code tag-adxl313"> 721 722 723 724 <div class="standard-post-image"> 725 <a 726 href="https://www.esp32learning.com/code/connect-a-adxl313-accelerometer-sensor-to-an-esp32.php"> 727 <img 728 class="attachment-penci-full-thumb size-penci-full-thumb penci-lazy wp-post-image" 729 width="600" 730 height="639" 731 src="data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%20600%20639'%3E%3C/svg%3E" alt="" title="ESP32 and ADXL313_bb" data-src="https://www.esp32learning.com/wp-content/uploads/2023/12/ESP32-and-ADXL313_bb.jpg"> </a> 732 </div> 733 734 735 <div class="header-standard 736 "> 737 <div class="penci-standard-cat"><span class="cat"><a style="" class="penci-cat-name penci-cat-14" href="https://www.esp32learning.com/category/code" rel="category tag"><span style="">Code</span></a></span></div> 738 739 <h2 class="penci-entry-title entry-title entry-title"><a 740 href="https://www.esp32learning.com/code/connect-a-adxl313-accelerometer-sensor-to-an-esp32.php">Connect a ADXL313 accelerometer sensor to an ESP32</a></h2> 741 <div class="penci-hide-tagupdated"> 742 <span class="author-italic author vcard">by <a class="author-url url fn n" 743 href="https://www.esp32learning.com/author/shedboy71">shedboy71</a> 744 </span> 745 <time class="entry-date published" datetime="2024-02-22T16:20:31+00:00">22nd February 2024</time> </div> 746 </div> 747 748 <div class="standard-content"> 749 <div class="standard-main-content entry-content"> 750 <div class="post-entry standard-post-entry classic-post-entry blockquote-style-1 "> 751 <p>
751In this article we connect the ever popular ADXL313 accelerometer to a raspberry Pi Pico and we will then display readings via the serial monitor window. We are using the Arduino IDE.</p> 752<p>Lets look at the sensor first</p> 753<h2>Features</h2> 754<p>The ADXL313 is a small, thin, low power, 3-axis accelerometer with high resolution (13-bit) measurement up to ±4<em>g</em>. Digital output data is formatted as 16-bit twos complement and is accessible through either a serial port interface (SPI) (3-wire or 4-wire) or I<sup>2</sup>C digital interface.</p> 755<div class="st-container"> 756<div class="st-text-and-title"></div> 757</div> 758<div class="col-md-6 RTEColBorder"> 759<ul> 760<li>Ultralow power (scales automatically with data rate) 761<ul> 762<li>As low as 30 μA in measurement mode (V<sub>S</sub> = 3.3 V)</li> 763<li>As low as 0.1 μA in standby mode (V<sub>S</sub> = 3.3 V)</li> 764</ul> 765</li> 766<li>Low noise performance 767<ul> 768<li>150 μ<em>g</em>/√Hz typical for X- and Y-axes</li> 769<li>250 μ<em>g</em>/√Hz typical for the Z-axis</li> 770</ul> 771</li> 772<li>Embedded, patent pending FIFO technology minimizes host processor load</li> 773<li>User-selectable resolution 774<ul> 775<li>Fixed 10-bit resolution for any <em>g</em> range</li> 776<li>Fixed 1024 LSB/<em>g</em> sensitivity for any <em>g</em> range</li> 777<li>Resolution scales from 10-bit at ±0.5 <em>g</em> to 13-bit at ±4 <em>g</em></li> 778</ul> 779</li> 780</ul> 781</div> 782<div class="col-md-6 RTEColBorder"> 783<ul> 784<li>Built-in motion detection functions for activity/inactivity monitoring</li> 785<li>Supply and I/O voltage range: 2.0 V to 3.6 V</li> 786<li>SPI (3-wire and 4-wire) and I<sup>2</sup>C digital interfaces</li> 787<li>Flexible interrupt modes mappable to two interrupt pins</li> 788<li>Measurement range selectable via serial command</li> 789<li>Bandwidth selectable via serial command</li> 790<li>Wide temperature range (−40°C to +105°C)</li> 791<li>10,000 <em>g</em> shock survival</li> 792</ul> 793</div> 794<p><span style="font-family: Raleway, sans-serif; font-size: 22px; font-weight: bold; letter-spacing: 0px;">Parts Required</span></p> 795<div class="pcrstb-wrap"><table style="width: 100%;"> 796<tbody> 797<tr style="height: 21px;"> 798<td style="width: 15.8442%; height: 21px;"><strong>Name</strong></td> 799<td style="width: 40.1299%; height: 21px;"><strong>Link</strong></td> 800<td style="width: 44.4156%;"></td> 801</tr> 802<tr style="height: 55px;"> 803<td style="width: 15.8442%; height: 55px;">ESP32</td> 804<td style="width: 40.1299%;"><a href="https://s.click.aliexpress.com/e/_DkIPPqt" target="_blank" rel="noopener"><img decoding="async" src="//ae01.alicdn.com/kf/Sbf885b40323a45178795fde862d61c3cT.jpg_140x140.jpg"" /></a></td> 805<td style="width: 44.4156%; height: 55px;"> 806<ul> 807<li><a href="https://s.click.aliexpress.com/e/_DkIPPqt" target="_blank" rel="noopener">Aliexpress link</a></li> 808<li><a href="https://www.amazon.com/s?k=esp32&ref=nb_sb_ss_ts-doa-p_1_11&_encoding=UTF8&linkId=b0663f9ccf4a4bf9c4a082212a1636de&camp=1789&creative=9325" target="_blank" rel="noopener">Amazon</a></li> 809<li><a href="https://www.ebay.com/sch/i.html?_from=R40&_trksid=p4432023.m570.l1313&_nkw=esp32&_sacat=0" target="_blank" rel="noopener">Ebay</a></li> 810</ul> 811</td> 812</tr> 813<tr style="height: 55px;"> 814<td style="width: 15.8442%; height: 55px;">ADXL313</td> 815<td style="width: 40.1299%;"><a href="https://s.click.aliexpress.com/e/_DBGAdG5" target="_blank" rel="noopener"><img decoding="async" src="//ae01.alicdn.com/kf/S0bfcf4357c9747c6ae8081d5a1c3bcbes.jpg_140x140.jpg"" /></a></td> 816<td style="width: 44.4156%; height: 55px;"> 817<ul> 818<li><a href="https://s.click.aliexpress.com/e/_DBGAdG5" target="_blank" rel="noopener">Aliexpress link</a></li> 819<li>Ebay link</li> 820</ul> 821</td> 822</tr> 823<tr style="height: 21px;"> 824<td style="width: 15.8442%; height: 21px;">Connecting cables</td> 825<td style="width: 40.1299%;"><img decoding="async" class="alignnone size-thumbnail wp-image-13" src="http://www.arduinocode.com/wp-content/uploads/2023/07/dupont-150x150.jpg" alt="" width="150" height="150" /></td> 826<td style="width: 44.4156%; height: 21px;"> 827<ul> 828<li><a href="https://s.click.aliexpress.com/e/_Dnk1xwF" target="_blank" rel="noopener">Aliexpress link</a></li> 829<li><a href="https://amzn.to/3Y5vMOO" target="_blank" rel="noopener">Amazon</a></li> 830<li><a href="https://www.ebay.com/sch/i.html?_from=R40&_trksid=p4432023.m570.l1313&_nkw=dupont+cables&_sacat=0" target="_blank" rel="noopener">Ebay</a></li> 831</ul> 832</td> 833</tr> 834</tbody> 835</table></div> 836<p> </p> 837<h2>Schematic/Connection</h2> 838<p>Here is a layout in fritzing to show this</p> 839<p><img decoding="async" class="alignnone size-full wp-image-931" src="https://www.esp32learning.com/wp-content/uploads/2023/12/ESP32-and-ADXL313_bb.jpg" alt="" width="600" height="639" srcset="https://www.esp32learning.com/wp-content/uploads/2023/12/ESP32-and-ADXL313_bb.jpg 600w, https://www.esp32learning.com/wp-content/uploads/2023/12/ESP32-and-ADXL313_bb-282x300.jpg 282w" sizes="(max-width: 600px) 100v
839w, 600px" /></p> 840<h2>Code Example</h2> 841<p>I used the Sparkfun ADXL313 library and this is the default example which worked, there are several examples to experiment with</p> 842<p>The library needs updated to work with the Raspberry Pi Pico – this issue is detailed here – <a href="https://github.com/sparkfun/SparkFun_ADXL313_Arduino_Library/issues/5" target="_blank" rel="noopener">https://github.com/sparkfun/SparkFun_ADXL313_Arduino_Library/issues/5</a></p> 843<p>Look for the following in SparkFunADXL313.cpp</p> 844<pre class="EnlighterJSRAW" data-enlighter-language="cpp">//Initializes the sensor with basic settings via SPI 845//Returns false if sensor is not detected 846boolean ADXL313::beginSPI(uint8_t CS_pin, SPIClass &spiPort) 847{ 848 _CS = CS_pin; 849 _spiPort = &spiPort; 850 I2C = false; 851//_spiPort->begin(_CS); // throws a compile error, no such function 852_spiPort->begin(); 853//_spiPort->setDataMode(SPI_MODE3); // old way of doing SPI settings, now you must pass in an SPISettings object 854_spiPort->beginTransaction(SPISettings(2000000, MSBFIRST, SPI_MODE3)); 855 pinMode(_CS, OUTPUT); 856 digitalWrite(_CS, HIGH); 857 858 // since we can't simply check for an "ACK" like in I2C, 859 // we will check PART ID, to verify that it's there and working 860 if (checkPartId() == false) // Check for sensor Part ID 861 return (false); 862 863 return (true); //We're all setup! 864}</pre> 865<p>And the basic example</p> 866<pre class="EnlighterJSRAW" data-enlighter-language="cpp">#include <Wire.h> 867#include "SparkFunADXL313.h" //Click here to get the library: http://librarymanager/All#SparkFun_ADXL313 868ADXL313 myAdxl; 869 870void setup() 871{ 872 Serial.begin(115200); 873 Serial.println("Example 1 - Reading values from ADXL313"); 874 875 Wire.begin(); 876 877 if (myAdxl.begin() == false) //Begin communication over I2C 878 { 879 Serial.println("The sensor did not respond. Please check wiring."); 880 while(1); //Freeze 881 } 882 Serial.print("Sensor is connected properly."); 883 884 myAdxl.measureModeOn(); // wakes up the sensor from standby and puts it into measurement mode 885} 886 887void loop() 888{ 889 if(myAdxl.dataReady()) // check data ready interrupt, note, this clears all other int bits in INT_SOURCE reg 890 { 891 myAdxl.readAccel(); // read all 3 axis, they are stored in class variables: myAdxl.x, myAdxl.y and myAdxl.z 892 Serial.print("x: "); 893 Serial.print(myAdxl.x); 894 Serial.print("\ty: "); 895 Serial.print(myAdxl.y); 896 Serial.print("\tz: "); 897 Serial.print(myAdxl.z); 898 Serial.println(); 899 } 900 else 901 { 902 Serial.println("Waiting for dataReady."); 903 } 904 delay(250); 905}</pre> 906<p> </p> 907<h2>Output</h2> 908<p>x: 511 y: 261 z: 511<br /> 909x: 136 y: 511 z: 212<br /> 910x: -195 y: 511 z: -491<br /> 911x: -253 y: 511 z: -512<br /> 912x: -311 y: 457 z: -512<br /> 913x: -499 y: 165 z: -512<br /> 914x: -512 y: -175 z: -512</p> 915<h2>Links</h2> 916<p><a href="https://www.analog.com/media/en/technical-documentation/data-sheets/adxl313.pdf" target="_blank" rel="noopener">https://www.analog.com/media/en/technical-documentation/data-sheets/adxl313.pdf</a></p> 917<p><a href="https://github.com/sparkfun/SparkFun_ADXL313_Arduino_Library" target="_blank" rel="noopener">https://github.com/sparkfun/SparkFun_ADXL313_Arduino_Library</a></p> 918<div class="addtoany_share_save_container addtoany_content addtoany_content_bottom"><div class="a2a_kit a2a_kit_size_32 addtoany_list" data-a2a-url="https://www.esp32learning.com/code/connect-a-adxl313-accelerometer-sensor-to-an-esp32.php" data-a2a-title="Connect a ADXL313 accelerometer sensor to an ESP32"><a class="a2a_button_facebook" href="https://www.addtoany.com/add_to/facebook?linkurl=https%3A%2F%2Fwww.esp32learning.com%2Fcode%2Fconnect-a-adxl313-accelerometer-sensor-to-an-esp32.php&linkname=Connect%20a%20ADXL313%20accelerometer%20sensor%20to%20an%20ESP32" title="Facebook" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_twitter" href="https://www.addtoany.com/add_to/twitter?linkurl=https%3A%2F%2Fwww.esp32learning.com%2Fcode%2Fconnect-a-adxl313-accelerometer-sensor-to-an-esp32.php&linkname=Connect%20a%20ADXL313%20accelerometer%20sensor%20to%20an%20ESP32" title="Twitter" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_threads" href="https://www.addtoany.com/add_to/threads?linkurl=https%3A%2F%2Fwww.esp32learning.com%2Fcode%2Fconnect-a-adxl313-accelerometer-sensor-to-an-esp32.php&linkname=Connect%20a%20ADXL313%20accelerometer%20sensor%20to%20an%20ESP32" title="Threads" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_pinterest" href="https://www.addtoany.com/add_to/pinterest?linkurl=https%3A%2F%2Fwww.esp32learning.com%2Fcode%2Fconnect-a-adxl313-accelerometer-sensor-to-an-esp32.php&linkname=Connect%20a%20ADXL313%20accelerometer%20sensor%20to%20an%20ESP32" title="Pinterest" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_tumblr" href="https://www.addtoany.com/add_to/tumblr?linkurl=https%3A%2F%2Fwww.esp32learning.com%2Fcode%2Fconnect-a-adxl313-accelerometer-sensor-to-an-esp32.php&linkname=Connect%20a%20ADXL313%20accelerometer%20sensor%20to%20an%20ESP32" title="Tumblr" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_reddit" href="https://www.addtoany.com/add_to/reddit?linkurl=https%3A%2F%2Fwww.esp32learning.com%2Fcode%2Fconnect-a-adxl313-accelerometer-sensor-to-an-esp32.php&linkname=Connect%20a%20ADXL313%20accelerometer%20sensor%20to%20an%20ESP32" title="Reddit" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_linkedin" href="https://www.addtoany.com/add_to/linkedin?linkurl=https%3A%2F%2Fwww.esp32learning.com%2Fcode%2Fconnect-a-adxl313-accelerometer-sensor-to-an-esp32.php&linkname=Connect%20a%20ADXL313%20accelerometer%20sensor%20to%20an%20ESP32" title="LinkedIn" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_digg" href="https://www.addtoany.com/add_to/digg?linkurl=https%3A%2F%2Fwww.esp32learning.com%2Fcode%2Fconnect-a-adxl313-accelerometer-sensor-to-an-esp32.php&linkname=Connect%20a%20ADXL313%20accelerometer%20sensor%20to%20an%20ESP32" title="Digg" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_pocket" href="https://www.addtoany.com/add_to/pocket?linkurl=https%3A%2F%2Fwww.esp32learning.com%2Fcode%2Fconnect-a-adxl313-accelerometer-sensor-to-an-esp32.php&linkname=Connect%20a%20ADXL313%20accelerometer%20sensor%20to%20an%20ESP32" title="Pocket" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_sina_weibo" href="https://www.addtoany.com/add_to/sina_weibo?linkurl=https%3A%2F%2Fwww.esp32learning.com%2Fcode%2Fconnect-a-adxl313-accelerometer-sensor-to-an-esp32.php&linkname=Connect%20a%20ADXL313%20accelerometer%20sensor%20to%20an%20ESP32" title="Sina Weibo" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_wordpress" href="https://www.addtoany.com/add_to/wordpress?linkurl=https%3A%2F%2Fwww.esp32learning.com%2Fcode%2Fconnect-a-adxl313-accelerometer-sensor-to-an-esp32.php&linkname=Connect%20a%20ADXL313%20accelerometer%20sensor%20to%20an%20ESP32" title="WordPress" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_blogger" href="https://www.addtoany.com/add_to/blogger?linkurl=https%3A%2F%2Fwww.esp32learning.com%2Fcode%2Fconnect-a-adxl313-accelerometer-sensor-to-an-esp32.php&linkname=Connect%20a%20ADXL313%20accelerometer%20sensor%20to%20an%20ESP32" title="Blogger" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_sms" href="https://www.addtoany.com/add_to/sms?linkurl=https%3A%2F%2Fwww.esp32learning.com%2Fcode%2Fconnect-a-adxl313-accelerometer-sensor-to-an-esp32.php&linkname=Connect%20a%20ADXL313%20accelerometer%20sensor%20to%20an%20ESP32" title="Message" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_whatsapp" href="https://www.addtoany.com/add_to/whatsapp?linkurl=https%3A%2F%2Fwww.esp32learning.com%2Fcode%2Fconnect-a-adxl313-accelerometer-sensor-to-an-esp32.php&linkname=Connect%20a%20ADXL313%20accelerometer%20sensor%20to%20an%20ESP32" title="WhatsApp" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_telegram" href="https://www.addtoany.com/add_to/telegram?linkurl=https%3A%2F%2Fwww.esp32learning.com%2Fcode%2Fconnect-a-adxl313-accelerometer-sensor-to-an-esp32.php&linkname=Connect%20a%20ADXL313%20accelerometer%20sensor%20to%20an%20ESP32" title="Telegram" rel="nofollow noopener" target="_blank"></a><a class="a2a_dd addtoany_share_save addtoany_share" href="https://www.addtoany.com/share"></a></div></div> </div> 919 </div> 920 921 <div class="penci-post-box-meta 922 center-inner "> 923 <div class="penci-post-share-box"> 924 <a href="#" class="penci-post-like" aria-label="Like this post" data-post_id="929" title="Like" data-like="Like" data-unlike="Unlike"><i class="penci-faicon fa fa-heart-o" ></i><span class="dt-share">1</span></a> <a class="new-ver-share post-share-item post-share-facebook" aria-label="Share on Facebook" target="_blank" rel="noreferrer" href="https://www.facebook.com/sharer/sharer.php?u=https://www.esp32learning.com/code/connect-a-adxl313-accelerometer-sensor-to-an-esp32.php"><i class="penci-faicon fa fa-facebook" ></i><span class="dt-share">Facebook</span></a><a class="new-ver-share post-share-item post-share-twitter" aria-label="Share on Twitter" target="_blank" rel="noreferrer" href="https://twitter.com/intent/tweet?text=Check%20out%20this%20article:%20Connect%20a%20ADXL313%20accelerometer%20sensor%20to%20an%20ESP32%20-%20https://www.esp32learning.com/code/connect-a-adxl313-accelerometer-sensor-to-an-esp32.php"><i class="penci-faicon penciicon-x-twitter" ></i><span class="dt-share">Twitter</span></a><a class="new-ver-share post-share-item post-share-pinterest" aria-label="Pin to Pinterest" data-pin-do="none" rel="noreferrer" target="_blank" href="https://www.pinterest.com/pin/create/button/?url=https%3A%2F%2Fwww.esp32learning.com%2Fcode%2Fconnect-a-adxl313-accelerometer-sensor-to-an-esp32.php&media=https%3A%2F%2Fwww.esp32learning.com%2Fwp-content%2Fuploads%2F2023%2F12%2FESP32-and-ADXL313_bb.jpg&description=Connect+a+ADXL313+accelerometer+sensor+to+an+ESP32"><i class="penci-faicon fa fa-pinterest" ></i><span class="dt-share">Pinterest</span></a><a class="new-ver-share post-share-item post-share-email" target="_blank" aria-label="Share via Email" rel="noreferrer" href="mailto:?subject=Connect%20a%20ADXL313%20accelerometer%20sensor%20to%20an%20ESP32&BODY=https://www.esp32learning.com/code/connect-a-adxl313-accelerometer-sensor-to-an-esp32.php"><i class="penci-faicon fa fa-envelope" ></i><span class="dt-share">Email</span></a> </div> 925 </div> 926 </div> 927 928</article> 929 930<article id="post-941" class="standard-article standard-pitem post-941 post type-post status-publish format-standard has-post-thumbnail hentry category-code tag-accelerometer tag-bma220"> 931 932 933 934 <div class="standard-post-image"> 935 <a 936 href="https://www.esp32learning.com/code/connect-an-bma220-triple-axis-accelerometer-to-an-esp32.php"> 937 <img 938 class="attachment-penci-full-thumb size-penci-full-thumb penci-lazy wp-post-image" 939 width="573" 940 height="609" 941 src="data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%20573%20609'%3E%3C/svg%3E" alt="" title="ESP32 and BMA220_bb" data-src="https://www.esp32learning.com/wp-content/uploads/2023/12/ESP32-and-BMA220_bb.jpg"> </a> 942 </div> 943 944 945 <div class="header-standard 946 "> 947 <div class="penci-standard-cat"><span class="cat"><a style="" class="penci-cat-name penci-cat-14" href="https://www.esp32learning.com/category/code" rel="category tag"><span style="">Code</span></a></span></div> 948 949 <h2 class="penci-entry-title entry-title entry-title"><a 950 href="https://www.esp32learning.com/code/connect-an-bma220-triple-axis-accelerometer-to-an-esp32.php">Connect an BMA220 Triple Axis Accelerometer to an ESP32</a></h2> 951 <div class="penci-hide-tagupdated"> 952 <span class="author-italic author vcard">by <a class="author-url url fn n" 953 href="https://www.esp32learning.com/author/shedboy71">shedboy71</a> 954 </span> 955 <time class="entry-date published" datetime="2024-01-22T17:09:47+00:00">22nd January 2024</time> </div> 956 </div> 957 958 <div class="standard-content"> 959 <div class="standard-main-content entry-content"> 960 <div class="post-entry standard-post-entry classic-post-entry blockquote-style-1 "> 961 <p>
961In this article we look at a sensor, the BMA220 Triple Axis Accelerometer from Bosch Sensortec, and connect it to an ESP32</p> 962<h3>Sensor Information</h3> 963<p>The BMA220 Triple Axis Accelerometer by Bosch is an ultra small triaxial, low-g acceleration sensor breakboard with SPI and I2C interface, aiming for low power consumer market applications. It allows measurement of accelerations in 3 perpendicular axes and thus senses tilt, motion, shock and vibration in cell phones, handhelds, computer peripherals, man-machine interfaces, virtual reality features and game controllers.</p> 964<p>The Tri-Axis Accelerometer integrates a multitude of features that acilitates its use especially in the area of motion detection applications, such as device orientation detection, gaming, HMI and menu browser control</p> 965<p>It can be used in sensing tilt, motion and shock vibration in mobile devices, handhelds, digital peripherals, man-machine interfaces, virtual reality features and game consoles.</p> 966<h4>Specification</h4> 967<p>Power supply: 2.0-3.6V<br /> 968Interface: I2C<br /> 969Acceleration range:±2g/±4g/±8g/±16g<br /> 970Ultra Low Power<br /> 971LED power indication</p> 972<p> </p> 973<div class="product-feature-category" data-module-component="product-features"> 974<div class="feature-category-label-column"> 975<h3>Parts Required</h3> 976<p>You can connect to the sensor using DuPont-style jumper wire.</p> 977<div class="pcrstb-wrap"><table> 978<tbody> 979<tr style="height: 21px;"> 980<td style="width: 15.8442%; height: 21px;"><strong>Name</strong></td> 981<td style="width: 40.1299%; height: 21px;"><strong>Link</strong></td> 982<td style="width: 44.4156%;"></td> 983</tr> 984<tr style="height: 55px;"> 985<td style="width: 15.8442%; height: 55px;">ESP32</td> 986<td style="width: 40.1299%;"><a href="https://s.click.aliexpress.com/e/_DkIPPqt" target="_blank" rel="noopener"><img decoding="async" src="//ae01.alicdn.com/kf/Sbf885b40323a45178795fde862d61c3cT.jpg_140x140.jpg"" /></a></td> 987<td style="width: 44.4156%; height: 55px;"> 988<ul> 989<li><a href="https://s.click.aliexpress.com/e/_DdKOnXT" target="_blank" rel="noopener">Aliexpress link</a></li> 990<li><a href="https://www.amazon.com/s?k=esp32&ref=nb_sb_ss_ts-doa-p_1_11&_encoding=UTF8&linkId=b0663f9ccf4a4bf9c4a082212a1636de&camp=1789&creative=9325" target="_blank" rel="noopener">Amazon</a></li> 991<li><a href="https://www.ebay.com/sch/i.html?_from=R40&_trksid=p4432023.m570.l1313&_nkw=esp32&_sacat=0" target="_blank" rel="noopener">Ebay</a></li> 992</ul> 993</td> 994</tr> 995<tr style="height: 55px;"> 996<td style="width: 15.8442%; height: 55px;">BMA220</td> 997<td style="width: 40.1299%;"></td> 998<td style="width: 44.4156%; height: 55px;"> 999<ul> 1000<li><a href="https://s.click.aliexpress.com/e/_DkiDfdT" target="_blank" rel="noopener">Aliexpress link</a></li> 1001</ul> 1002</td> 1003</tr> 1004<tr style="height: 21px;"> 1005<td style="width: 15.8442%; height: 21px;">Connecting cables</td> 1006<td style="width: 40.1299%;"><img decoding="async" class="alignnone size-thumbnail wp-image-13" src="http://www.arduinocode.com/wp-content/uploads/2023/07/dupont-150x150.jpg" alt="" width="150" height="150" /></td> 1007<td style="width: 44.4156%; height: 21px;"> 1008<ul> 1009<li><a href="https://s.click.aliexpress.com/e/_Dnk1xwF" target="_blank" rel="noopener">Aliexpress link</a></li> 1010<li><a href="https://amzn.to/3Y5vMOO" target="_blank" rel="noopener">Amazon</a></li> 1011<li><a href="https://www.ebay.com/sch/i.html?_from=R40&_trksid=p4432023.m570.l1313&_nkw=dupont+cables&_sacat=0" target="_blank" rel="noopener">Ebay</a></li> 1012</ul> 1013</td> 1014</tr> 1015</tbody> 1016</table></div> 1017<h3>Schematic/Connection</h3> 1018<p>I used 3.3v rather than 5v</p> 1019<p><img decoding="async" class="alignnone size-full wp-image-943" src="https://www.esp32learning.com/wp-content/uploads/2023/12/ESP32-and-BMA220_bb.jpg" alt="" width="573" height="609" srcset="https://www.esp32learning.com/wp-content/uploads/2023/12/ESP32-and-BMA220_bb.jpg 573w, https://www.esp32learning.com/wp-content/uploads/2023/12/ESP32-and-BMA220_bb-282x300.jpg 282w" sizes="(max-width: 573px) 100vw, 573px" /></p> 1020<h3>Code Example</h3> 1021<p>This requires no library</p> 1022<pre class="EnlighterJSRAW" data-enlighter-language="cpp">#include <Wire.h> 1023 1024byte Version[3]; 1025int8_t x_data; 1026int8_t y_data; 1027int8_t z_data; 1028 1029void setup() 1030{ 1031 Serial.begin(9600); 1032 Wire.begin(); 1033 Wire.beginTransmission(0x0A); // address of the accelerometer 1034 // low pass filter, range settings 1035 Wire.write(0x20); 1036 Wire.write(0x05); 1037 Wire.endTransmission(); 1038 1039} 1040 1041void AccelerometerInit() 1042{ 1043 Wire.beginTransmission(0x0A); // address of the accelerometer 1044 // reset the accelerometer 1045 Wire.write(0x04); // Y data 1046 Wire.endTransmission(); 1047 Wire.requestFrom(0x0A,1); // request 6 bytes from slave device #2 1048 while(Wire.available()) // slave may send less than requested 1049 { 1050 Version[0] = Wire.read(); // receive a byte as characte 1051 } 1052 x_data=(int8_t)Version[0]>>2; 1053 1054 Wire.beginTransmission(0x0A); // address of the accelerometer 1055 // reset the accelerometer 1056 Wire.write(0x06); // Y data 1057 Wire.endTransmission(); 1058 Wire.requestFrom(0x0A,1); // request 6 bytes from slave device #2 1059 while(Wire.available()) // slave may send less than requested 1060 { 1061 Version[1] = Wire.read(); // receive a byte as characte 1062 } 1063 y_data=(int8_t)Version[1]>>2; 1064 1065 Wire.beginTransmission(0x0A); // address of the accelerometer 1066 // reset the accelerometer 1067 Wire.write(0x08); // Y data 1068 Wire.endTransmission(); 1069 Wire.requestFrom(0x0A,1); // request 6 bytes from slave device #2 1070 while(Wire.available()) // slave may send less than requested 1071 { 1072 Version[2] = Wire.read(); // receive a byte as characte 1073 } 1074 z_data=(int8_t)Version[2]>>2; 1075 1076 Serial.print("X="); 1077 Serial.print(x_data); // print the character 1078 Serial.print(" "); 1079 Serial.print("Y="); 1080 Serial.print(y_data); // print the character 1081 Serial.print(" "); 1082 Serial.print("Z="); 1083 Serial.println(z_data); 1084} 1085 1086void loop() 1087{ 1088 AccelerometerInit(); 1089 delay(100); 1090 1091}</pre> 1092<p> </p> 1093<p> </p> 1094</div> 1095<div class="feature-category-label-column"> 1096<h4>Output</h4> 1097<p>When run you will see something like this in the serial monitor window,</p> 1098<p> </p> 1099<h3>Links</h3> 1100<p> </p> 1101</div> 1102</div> 1103<div class="addtoany_share_save_container addtoany_content addtoany_content_bottom"><div class="a2a_kit a2a_kit_size_32 addtoany_list" data-a2a-url="https://www.esp32learning.com/code/connect-an-bma220-triple-axis-accelerometer-to-an-esp32.php" data-a2a-title="Connect an BMA220 Triple Axis Accelerometer to an ESP32"><a class="a2a_button_facebook" href="https://www.addtoany.com/add_to/facebook?linkurl=https%3A%2F%2Fwww.esp32learning.com%2Fcode%2Fconnect-an-bma220-triple-axis-accelerometer-to-an-esp32.php&linkname=Connect%20an%20BMA220%20Triple%20Axis%20Accelerometer%20to%20an%20ESP32" title="Facebook" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_twitter" href="https://www.addtoany.com/add_to/twitter?linkurl=https%3A%2F%2Fwww.esp32learning.com%2Fcode%2Fconnect-an-bma220-triple-axis-accelerometer-to-an-esp32.php&linkname=Connect%20an%20BMA220%20Triple%20Axis%20Accelerometer%20to%20an%20ESP32" title="Twitter" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_threads" href="https://www.addtoany.com/add_to/threads?linkurl=https%3A%2F%2Fwww.esp32learning.com%2Fcode%2Fconnect-an-bma220-triple-axis-accelerometer-to-an-esp32.php&linkname=Connect%20an%20BMA220%20Triple%20Axis%20Accelerometer%20to%20an%20ESP32" title="Threads" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_pinterest" href="https://www.addtoany.com/add_to/pinterest?linkurl=https%3A%2F%2Fwww.esp32learning.com%2Fcode%2Fconnect-an-bma220-triple-axis-accelerometer-to-an-esp32.php&linkname=Connect%20an%20BMA220%20Triple%20Axis%20Accelerometer%20to%20an%20ESP32" title="Pinterest" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_tumblr" href="https://www.addtoany.com/add_to/tumblr?linkurl=https%3A%2F%2Fwww.esp32learning.com%2Fcode%2Fconnect-an-bma220-triple-axis-accelerometer-to-an-esp32.php&linkname=Connect%20an%20BMA220%20Triple%20Axis%20Accelerometer%20to%20an%20ESP32" title="Tumblr" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_reddit" href="https://www.addtoany.com/add_to/reddit?linkurl=https%3A%2F%2Fwww.esp32learning.com%2Fcode%2Fconnect-an-bma220-triple-axis-accelerometer-to-an-esp32.php&linkname=Connect%20an%20BMA220%20Triple%20Axis%20Accelerometer%20to%20an%20ESP32" title="Reddit" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_linkedin" href="https://www.addtoany.com/add_to/linkedin?linkurl=https%3A%2F%2Fwww.esp32learning.com%2Fcode%2Fconnect-an-bma220-triple-axis-accelerometer-to-an-esp32.php&linkname=Connect%20an%20BMA220%20Triple%20Axis%20Accelerometer%20to%20an%20ESP32" title="LinkedIn" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_digg" href="https://www.addtoany.com/add_to/digg?linkurl=https%3A%2F%2Fwww.esp32learning.com%2Fcode%2Fconnect-an-bma220-triple-axis-accelerometer-to-an-esp32.php&linkname=Connect%20an%20BMA220%20Triple%20Axis%20Accelerometer%20to%20an%20ESP32" title="Digg" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_pocket" href="https://www.addtoany.com/add_to/pocket?linkurl=https%3A%2F%2Fwww.esp32learning.com%2Fcode%2Fconnect-an-bma220-triple-axis-accelerometer-to-an-esp32.php&linkname=Connect%20an%20BMA220%20Triple%20Axis%20Accelerometer%20to%20an%20ESP32" title="Pocket" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_sina_weibo" href="https://www.addtoany.com/add_to/sina_weibo?linkurl=https%3A%2F%2Fwww.esp32learning.com%2Fcode%2Fconnect-an-bma220-triple-axis-accelerometer-to-an-esp32.php&linkname=Connect%20an%20BMA220%20Triple%20Axis%20Accelerometer%20to%20an%20ESP32" title="Sina Weibo" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_wordpress" href="https://www.addtoany.com/add_to/wordpress?linkurl=https%3A%2F%2Fwww.esp32learning.com%2Fcode%2Fconnect-an-bma220-triple-axis-accelerometer-to-an-esp32.php&linkname=Connect%20an%20BMA220%20Triple%20Axis%20Accelerometer%20to%20an%20ESP32" title="WordPress" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_blogger" href="https://www.addtoany.com/add_to/blogger?linkurl=https%3A%2F%2Fwww.esp32learning.com%2Fcode%2Fconnect-an-bma220-triple-axis-accelerometer-to-an-esp32.php&linkname=Connect%20an%20BMA220%20Triple%20Axis%20Accelerometer%20to%20an%20ESP32" title="Blogger" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_sms" href="https://www.addtoany.com/add_to/sms?linkurl=https%3A%2F%2Fwww.esp32learning.com%2Fcode%2Fconnect-an-bma220-triple-axis-accelerometer-to-an-esp32.php&linkname=Connect%20an%20BMA220%20Triple%20Axis%20Accelerometer%20to%20an%20ESP32" title="Message" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_whatsapp" href="https://www.addtoany.com/add_to/whatsapp?linkurl=https%3A%2F%2Fwww.esp32learning.com%2Fcode%2Fconnect-an-bma220-triple-axis-accelerometer-to-an-esp32.php&linkname=Connect%20an%20BMA220%20Triple%20Axis%20Accelerometer%20to%20an%20ESP32" title="WhatsApp" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_telegram" href="https://www.addtoany.com/add_to/telegram?linkurl=https%3A%2F%2Fwww.esp32learning.com%2Fcode%2Fconnect-an-bma220-triple-axis-accelerometer-to-an-esp32.php&linkname=Connect%20an%20BMA220%20Triple%20Axis%20Accelerometer%20to%20an%20ESP32" title="Telegram" rel="nofollow noopener" target="_blank"></a><a class="a2a_dd addtoany_share_save addtoany_share" href="https://www.addtoany.com/share"></a></div></div> </div> 1104 </div> 1105 1106 <div class="penci-post-box-meta 1107 center-inner "> 1108 <div class="penci-post-share-box"> 1109 <a href="#" class="penci-post-like" aria-label="Like this post" data-post_id="941" title="Like" data-like="Like" data-unlike="Unlike"><i class="penci-faicon fa fa-heart-o" ></i><span class="dt-share">1</span></a> <a class="new-ver-share post-share-item post-share-facebook" aria-label="Share on Facebook" target="_blank" rel="noreferrer" href="https://www.facebook.com/sharer/sharer.php?u=https://www.esp32learning.com/code/connect-an-bma220-triple-axis-accelerometer-to-an-esp32.php"><i class="penci-faicon fa fa-facebook" ></i><span class="dt-share">Facebook</span></a><a class="new-ver-share post-share-item post-share-twitter" aria-label="Share on Twitter" target="_blank" rel="noreferrer" href="https://twitter.com/intent/tweet?text=Check%20out%20this%20article:%20Connect%20an%20BMA220%20Triple%20Axis%20Accelerometer%20to%20an%20ESP32%20-%20https://www.esp32learning.com/code/connect-an-bma220-triple-axis-accelerometer-to-an-esp32.php"><i class="penci-faicon penciicon-x-twitter" ></i><span class="dt-share">Twitter</span></a><a class="new-ver-share post-share-item post-share-pinterest" aria-label="Pin to Pinterest" data-pin-do="none" rel="noreferrer" target="_blank" href="https://www.pinterest.com/pin/create/button/?url=https%3A%2F%2Fwww.esp32learning.com%2Fcode%2Fconnect-an-bma220-triple-axis-accelerometer-to-an-esp32.php&media=https%3A%2F%2Fwww.esp32learning.com%2Fwp-content%2Fuploads%2F2023%2F12%2FESP32-and-BMA220_bb.jpg&description=Connect+an+BMA220+Triple+Axis+Accelerometer+to+an+ESP32"><i class="penci-faicon fa fa-pinterest" ></i><span class="dt-share">Pinterest</span></a><a class="new-ver-share post-share-item post-share-email" target="_blank" aria-label="Share via Email" rel="noreferrer" href="mailto:?subject=Connect%20an%20BMA220%20Triple%20Axis%20Accelerometer%20to%20an%20ESP32&BODY=https://www.esp32learning.com/code/connect-an-bma220-triple-axis-accelerometer-to-an-esp32.php"><i class="penci-faicon fa fa-envelope" ></i><span class="dt-share">Email</span></a> </div> 1110 </div> 1111 </div> 1112 1113</article> 1114 1115<article id="post-902" class="standard-article standard-pitem post-902 post type-post status-publish format-standard has-post-thumbnail hentry category-code tag-esp32"> 1116 1117 1118 1119 <div class="standard-post-image"> 1120 <a 1121 href="https://www.esp32learning.com/code/connect-an-ltr-329-ambient-light-sensor-to-an-esp32.php"> 1122 <img 1123 class="attachment-penci-full-thumb size-penci-full-thumb penci-lazy wp-post-image" 1124 width="717" 1125 height="795" 1126 src="data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%20717%20795'%3E%3C/svg%3E" alt="" title="esp32 and LTR329_bb" data-src="https://www.esp32learning.com/wp-content/uploads/2023/07/esp32-and-LTR329_bb.png"> </a> 1127 </div> 1128 1129 1130 <div class="header-standard 1131 "> 1132 <div class="penci-standard-cat"><span class="cat"><a style="" class="penci-cat-name penci-cat-14" href="https://www.esp32learning.com/category/code" rel="category tag"><span style="">Code</span></a></span></div> 1133 1134 <h2 class="penci-entry-title entry-title entry-title"><a 1135 href="https://www.esp32learning.com/code/connect-an-ltr-329-ambient-light-sensor-to-an-esp32.php">Connect an LTR-329 Ambient Light sensor to an ESP32</a></h2> 1136 <div class="penci-hide-tagupdated"> 1137 <span class="author-italic author vcard">by <a class="author-url url fn n" 1138 href="https://www.esp32learning.com/author/shedboy71">shedboy71</a> 1139 </span> 1140 <time class="entry-date published" datetime="2023-12-20T09:41:48+00:00">20th December 2023</time> </div> 1141 </div> 1142 1143 <div class="standard-content"> 1144 <div class="standard-main-content entry-content"> 1145 <div class="post-entry standard-post-entry classic-post-entry blockquote-style-1 "> 1146 <p>
1146In this article we look at an Ambient Light sensor, the LTR-329 and connect it to an ESP32</p> 1147<h3>Sensor Information</h3> 1148<p>The LTR-329 provides 16-bit light measurements for both Infrared and Visible+IR spectrums. Subtract one from the other to get human-visible light. Thanks to configurable gain and integration time settings, the LTR-329 can measure from 0 to 65K+ lux.</p> 1149<p>I bought an Adafruit breakout board, so the LTR-329 comes integrated with a voltage regulator and level-shifting circuitry to allow it to be used with 3.3V devices or 5V devices.</p> 1150<p>Along with a header, there is a SparkFun Qwiic compatible STEMMA QT connectors for the I2C bus so you just need to fit a suitable cable</p> 1151<h4>Features</h4> 1152<p>I2C interface with up to Fast Mode @ 400kbit/s with address 0x29<br /> 1153Ultra-small 4-pin ChipLED package 2.0mm(L), 2.0mm(B), 0.7mm(H)<br /> 1154Built-in temperature compensation circuit<br /> 1155Low active power consumption with standby mode<br /> 1156Supply voltage range from 2.4V to 3.6V capable of 1.7V logic voltage<br /> 1157Operating temperature range from -30C to +70C<br /> 1158RoHS and Halogen free compliant<br /> 1159Close to human eye spectral response<br /> 1160Immunity to IR / UV Light Source<br /> 1161Automatically rejects 50 / 60 Hz lightings flicker<br /> 1162Full dynamic range from 0.01 lux to 64k lux<br /> 116316-bit effective resolution</p> 1164<div class="product-feature-category" data-module-component="product-features"> 1165<div class="feature-category-label-column"> 1166<h3>Parts Required</h3> 1167<p>You can connect to the sensor using dupont style jumper wire.</p> 1168<p> </p> 1169<div class="pcrstb-wrap"><table> 1170<tbody> 1171<tr style="height: 21px;"> 1172<td style="width: 15.8442%; height: 21px;"><strong>Name</strong></td> 1173<td style="width: 40.1299%; height: 21px;"><strong>Link</strong></td> 1174<td style="width: 44.4156%;"></td> 1175</tr> 1176<tr style="height: 55px;"> 1177<td style="width: 15.8442%; height: 55px;">ESP32</td> 1178<td style="width: 40.1299%;"><a href="https://s.click.aliexpress.com/e/_DkIPPqt" target="_blank" rel="noopener"><img decoding="async" src="//ae01.alicdn.com/kf/Sbf885b40323a45178795fde862d61c3cT.jpg_140x140.jpg"" /></a></td> 1179<td style="width: 44.4156%; height: 55px;"> 1180<ul> 1181<li><a href="https://s.click.aliexpress.com/e/_DdKOnXT" target="_blank" rel="noopener">Aliexpress link</a></li> 1182<li><a href="https://www.amazon.com/s?k=ESP32%22&camp=1789&creative=9325&linkCode=ur2&linkId=cac24da38498a0be29dcff978e974b54&tag=basicvisualbasic" target="_blank" rel="noopener">Amazon</a></li> 1183<li><a href="https://www.ebay.com/sch/i.html?_from=R40&_trksid=p2334524.m570.l1313&_nkw=ESP32&_sacat=0&_odkw=ESP32&_osacat=0&mkcid=1&mkrid=711-53200-19255-0&siteid=0&campid=5338725476&customid=&toolid=10001&mkevt=1" target="_blank" rel="noopener">Ebay</a></li> 1184</ul> 1185</td> 1186</tr> 1187<tr style="height: 55px;"> 1188<td style="width: 15.8442%; height: 55px;">LTR329</td> 1189<td style="width: 40.1299%;"></td> 1190<td style="width: 44.4156%; height: 55px;"> </p> 1191<ul> 1192<li><a href="https://www.ebay.com/sch/i.html?_from=R40&_trksid=p2334524.m570.l1313&_nkw=LTR329&_sacat=0&_odkw=LTR329&_osacat=0&mkcid=1&mkrid=711-53200-19255-0&siteid=0&campid=5338725476&customid=&toolid=10001&mkevt=1" target="_blank" rel="noopener">Ebay link</a></li> 1193</ul> 1194</td> 1195</tr> 1196<tr style="height: 21px;"> 1197<td style="width: 15.8442%; height: 21px;">Connecting cables</td> 1198<td style="width: 40.1299%;"><img decoding="async" class="alignnone size-thumbnail wp-image-13" src="http://www.arduinocode.com/wp-content/uploads/2023/07/dupont-150x150.jpg" alt="" width="150" height="150" /></td> 1199<td style="width: 44.4156%; height: 21px;"> 1200<ul> 1201<li><a href="https://s.click.aliexpress.com/e/_Dnk1xwF" target="_blank" rel="noopener">Aliexpress link</a></li> 1202<li><a href="https://www.amazon.com/s?k=dupont+cables%22&camp=1789&creative=9325&linkCode=ur2&linkId=cac24da38498a0be29dcff978e974b54&tag=basicvisualbasic" target="_blank" rel="noopener">Amazon</a></li> 1203<li><a href="https://www.ebay.com/sch/i.html?_from=R40&_trksid=p2334524.m570.l1313&_nkw=dupont+cables&_sacat=0&_odkw=dupont+cables&_osacat=0&mkcid=1&mkrid=711-53200-19255-0&siteid=0&campid=5338725476&
1203customid=&toolid=10001&mkevt=1" target="_blank" rel="noopener">Ebay</a></li> 1204</ul> 1205</td> 1206</tr> 1207</tbody> 1208</table></div> 1209<p> </p> 1210<h3>Schematic/Connection</h3> 1211<p>I used 3.3v from the ESP32 and the stemma/qwic connector</p> 1212<p><img decoding="async" class="alignnone size-full wp-image-899" src="https://www.esp32learning.com/wp-content/uploads/2023/07/esp32-and-LTR303_bb.png" alt="" width="732" height="756" srcset="https://www.esp32learning.com/wp-content/uploads/2023/07/esp32-and-LTR303_bb.png 732w, https://www.esp32learning.com/wp-content/uploads/2023/07/esp32-and-LTR303_bb-290x300.png 290w" sizes="(max-width: 732px) 100vw, 732px" /></p> 1213<p> </p> 1214<h3>Code Example</h3> 1215<p>I installed the Adafruit library using the Arduino ide which also installed the dependency library</p> 1216<p>Click the <strong>Manage Libraries …</strong> menu item, search for <strong>LTR329_LTR303</strong>, and select the <strong>Adafruit LTR329 LTR303</strong> library</p> 1217<p>If asked about dependencies, click on the “Install all” option</p> 1218<p>If the Dependencies window does appear, you already have the required dependencies installed.</p> 1219<p>If the dependencies are already installed, make sure that you have the latest ones installed using the Arduino Library Manager</p> 1220<p>This is the default ltr329_simpletest example with the delay set to 1000ms rather than 100ms which seemed a bit too short a delay for simple testing. I also removed code from the setup routine which basically displayed the settings that you can change in the setup.</p> 1221<p>These are</p> 1222<p>ltr.setGain(LTR3XX_GAIN_2);<br /> 1223ltr.setIntegrationTime(LTR3XX_INTEGTIME_100);<br /> 1224ltr.setMeasurementRate(LTR3XX_MEASRATE_200);</p> 1225<pre class="EnlighterJSRAW" data-enlighter-language="cpp">#include "Adafruit_LTR329_LTR303.h" 1226 1227Adafruit_LTR329 ltr = Adafruit_LTR329(); 1228 1229void setup() { 1230 Serial.begin(115200); 1231 Serial.println("Adafruit LTR-329 advanced test"); 1232 1233 if ( ! ltr.begin() ) { 1234 Serial.println("Couldn't find LTR sensor!"); 1235 while (1) delay(10); 1236 } 1237 Serial.println("Found LTR sensor!"); 1238 1239 ltr.setGain(LTR3XX_GAIN_2); 1240 ltr.setIntegrationTime(LTR3XX_INTEGTIME_100); 1241 ltr.setMeasurementRate(LTR3XX_MEASRATE_200); 1242 1243} 1244 1245void loop() { 1246 bool valid; 1247 uint16_t visible_plus_ir, infrared; 1248 1249 if (ltr.newDataAvailable()) { 1250 valid = ltr.readBothChannels(visible_plus_ir, infrared); 1251 if (valid) { 1252 Serial.print("CH0 Visible + IR: "); 1253 Serial.print(visible_plus_ir); 1254 Serial.print("\t\tCH1 Infrared: "); 1255 Serial.println(infrared); 1256 } 1257 } 1258 1259 delay(1000); 1260}</pre> 1261<p> </p> 1262<h4>Output</h4> 1263<p>Here is an example of what I saw in the serial monitor window – you may see some different results</p> 1264<p>This was covering and uncovering the sensor</p> 1265<p>CH0 Visible + IR: 4 CH1 Infrared: 5<br /> 1266CH0 Visible + IR: 4 CH1 Infrared: 5<br /> 1267CH0 Visible + IR: 4 CH1 Infrared: 5<br /> 1268CH0 Visible + IR: 3 CH1 Infrared: 4<br /> 1269CH0 Visible + IR: 22 CH1 Infrared: 30<br /> 1270CH0 Visible + IR: 20 CH1 Infrared: 29<br /> 1271CH0 Visible + IR: 20 CH1 Infrared: 29</p> 1272<h3>Links</h3> 1273<p><a href="https://optoelectronics.liteon.com/upload/download/DS86-2014-0006/LTR-329ALS-01_DS_V1.5.PDF" target="_blank" rel="noopener">https://optoelectronics.liteon.com/upload/download/DS86-2014-0006/LTR-329ALS-01_DS_V1.5.PDF</a></p> 1274</div> 1275</div> 1276<div class="addtoany_share_save_container addtoany_content addtoany_content_bottom"><div class="a2a_kit a2a_kit_size_32 addtoany_list" data-a2a-url="https://www.esp32learning.com/code/connect-an-ltr-329-ambient-light-sensor-to-an-esp32.php" data-a2a-title="Connect an LTR-329 Ambient Light sensor to an ESP32"><a class="a2a_button_facebook" href="https://www.addtoany.com/add_to/facebook?linkurl=https%3A%2F%2Fwww.esp32learning.com%2Fcode%2Fconnect-an-ltr-329-ambient-light-sensor-to-an-esp32.php&linkname=Connect%20an%20LTR-329%20Ambient%20Light%20sensor%20to%20an%20ESP32" title="Facebook" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_twitter" href="https://www.addtoany.com/add_to/twitter?linkurl=https%3A%2F%2Fwww.esp32learning.com%2Fcode%2Fconnect-an-ltr-329-ambient-light-sensor-to-an-esp32.php&linkname=Connect%20an%20LTR-329%20Ambient%20Light%20sensor%20to%20an%20ESP32" title="Twitter" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_threads" href="https://www.addtoany.com/add_to/threads?linkurl=https%3A%2F%2Fwww.esp32learning.com%2Fcode%2Fconnect-an-ltr-329-ambient-light-sensor-to-an-esp32.php&linkname=Connect%20an%20LTR-329%20Ambient%20Light%20sensor%20to%20an%20ESP32" title="Threads" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_pinterest" href="https://www.addtoany.com/add_to/pinterest?linkurl=https%3A%2F%2Fwww.esp32learning.com%2Fcode%2Fconnect-an-ltr-329-ambient-light-sensor-to-an-esp32.php&linkname=Connect%20an%20LTR-329%20Ambient%20Light%20sensor%20to%20an%20ESP32" title="Pinterest" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_tumblr" href="https://www.addtoany.com/add_to/tumblr?linkurl=https%3A%2F%2Fwww.esp32learning.com%2Fcode%2Fconnect-an-ltr-329-ambient-light-sensor-to-an-esp32.php&linkname=Connect%20an%20LTR-329%20Ambient%20Light%20sensor%20to%20an%20ESP32" title="Tumblr" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_reddit" href="https://www.addtoany.com/add_to/reddit?linkurl=https%3A%2F%2Fwww.esp32learning.com%2Fcode%2Fconnect-an-ltr-329-ambient-light-sensor-to-an-esp32.php&linkname=Connect%20an%20LTR-329%20Ambient%20Light%20sensor%20to%20an%20ESP32" title="Reddit" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_linkedin" href="https://www.addtoany.com/add_to/linkedin?linkurl=https%3A%2F%2Fwww.esp32learning.com%2Fcode%2Fconnect-an-ltr-329-ambient-light-sensor-to-an-esp32.php&linkname=Connect%20an%20LTR-329%20Ambient%20Light%20sensor%20to%20an%20ESP32" title="LinkedIn" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_digg" href="https://www.addtoany.com/add_to/digg?linkurl=https%3A%2F%2Fwww.esp32learning.com%2Fcode%2Fconnect-an-ltr-329-ambient-light-sensor-to-an-esp32.php&linkname=Connect%20an%20LTR-329%20Ambient%20Light%20sensor%20to%20an%20ESP32" title="Digg" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_pocket" href="https://www.addtoany.com/add_to/pocket?linkurl=https%3A%2F%2Fwww.esp32learning.com%2Fcode%2Fconnect-an-ltr-329-ambient-light-sensor-to-an-esp32.php&linkname=Connect%20an%20LTR-329%20Ambient%20Light%20sensor%20to%20an%20ESP32" title="Pocket" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_sina_weibo" href="https://www.addtoany.com/add_to/sina_weibo?linkurl=https%3A%2F%2Fwww.esp32learning.com%2Fcode%2Fconnect-an-ltr-329-ambient-light-sensor-to-an-esp32.php&linkname=Connect%20an%20LTR-329%20Ambient%20Light%20sensor%20to%20an%20ESP32" title="Sina Weibo" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_wordpress" href="https://www.addtoany.com/add_to/wordpress?linkurl=https%3A%2F%2Fwww.esp32learning.com%2Fcode%2Fconnect-an-ltr-329-ambient-light-sensor-to-an-esp32.php&linkname=Connect%20an%20LTR-329%20Ambient%20Light%20sensor%20to%20an%20ESP32" title="WordPress" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_blogger" href="https://www.addtoany.com/add_to/blogger?linkurl=https%3A%2F%2Fwww.esp32learning.com%2Fcode%2Fconnect-an-ltr-329-ambient-light-sensor-to-an-esp32.php&linkname=Connect%20an%20LTR-329%20Ambient%20Light%20sensor%20to%20an%20ESP32" title="Blogger" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_sms" href="https://www.addtoany.com/add_to/sms?linkurl=https%3A%2F%2Fwww.esp32learning.com%2Fcode%2Fconnect-an-ltr-329-ambient-light-sensor-to-an-esp32.php&linkname=Connect%20an%20LTR-329%20Ambient%20Light%20sensor%20to%20an%20ESP32" title="Message" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_whatsapp" href="https://www.addtoany.com/add_to/whatsapp?linkurl=https%3A%2F%2Fwww.esp32learning.com%2Fcode%2Fconnect-an-ltr-329-ambient-light-sensor-to-an-esp32.php&linkname=Connect%20an%20LTR-329%20Ambient%20Light%20sensor%20to%20an%20ESP32" title="WhatsApp" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_telegram" href="https://www.addtoany.com/add_to/telegram?linkurl=https%3A%2F%2Fwww.esp32learning.com%2Fcode%2Fconnect-an-ltr-329-ambient-light-sensor-to-an-esp32.php&linkname=Connect%20an%20LTR-329%20Ambient%20Light%20sensor%20to%20an%20ESP32" title="Telegram" rel="nofollow noopener" target="_blank"></a><a class="a2a_dd addtoany_share_save addtoany_share" href="https://www.addtoany.com/share"></a></div></div> </div> 1277 </div> 1278 1279 <div class="penci-post-box-meta 1280 center-inner "> 1281 <div class="penci-post-share-box"> 1282 <a href="#" class="penci-post-like" aria-label="Like this post" data-post_id="902" title="Like" data-like="Like" data-unlike="Unlike"><i class="penci-faicon fa fa-heart-o" ></i><span class="dt-share">2</span></a> <a class="new-ver-share post-share-item post-share-facebook" aria-label="Share on Facebook" target="_blank" rel="noreferrer" href="https://www.facebook.com/sharer/sharer.php?u=https://www.esp32learning.com/code/connect-an-ltr-329-ambient-light-sensor-to-an-esp32.php"><i class="penci-faicon fa fa-facebook" ></i><span class="dt-share">Facebook</span></a><a class="new-ver-share post-share-item post-share-twitter" aria-label="Share on Twitter" target="_blank" rel="noreferrer" href="https://twitter.com/intent/tweet?text=Check%20out%20this%20article:%20Connect%20an%20LTR-329%20Ambient%20Light%20sensor%20to%20an%20ESP32%20-%20https://www.esp32learning.com/code/connect-an-ltr-329-ambient-light-sensor-to-an-esp32.php"><i class="penci-faicon penciicon-x-twitter" ></i><span class="dt-share">Twitter</span></a><a class="new-ver-share post-share-item post-share-pinterest" aria-label="Pin to Pinterest" data-pin-do="none" rel="noreferrer" target="_blank" href="https://www.pinterest.com/pin/create/button/?url=https%3A%2F%2Fwww.esp32learning.com%2Fcode%2Fconnect-an-ltr-329-ambient-light-sensor-to-an-esp32.php&media=https%3A%2F%2Fwww.esp32learning.com%2Fwp-content%2Fuploads%2F2023%2F07%2Fesp32-and-LTR329_bb.png&description=Connect+an+LTR-329+Ambient+Light+sensor+to+an+ESP32"><i class="penci-faicon fa fa-pinterest" ></i><span class="dt-share">Pinterest</span></a><a class="new-ver-share post-share-item post-share-email" target="_blank" aria-label="Share via Email" rel="noreferrer" href="mailto:?subject=Connect%20an%20LTR-329%20Ambient%20Light%20sensor%20to%20an%20ESP32&BODY=https://www.esp32learning.com/code/connect-an-ltr-329-ambient-light-sensor-to-an-esp32.php"><i class="penci-faicon fa fa-envelope" ></i><span class="dt-share">Email</span></a> </div> 1283 </div> 1284 </div> 1285 1286</article> 1287 1288<article id="post-897" class="standard-article standard-pitem post-897 post type-post status-publish format-standard has-post-thumbnail hentry category-code tag-esp32"> 1289 1290 1291 1292 <div class="standard-post-image"> 1293 <a 1294 href="https://www.esp32learning.com/code/connect-an-ltr-303-ambient-light-sensor-to-an-esp32.php"> 1295 <img 1296 class="attachment-penci-full-thumb size-penci-full-thumb penci-lazy wp-post-image" 1297 width="732" 1298 height="756" 1299 src="data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%20732%20756'%3E%3C/svg%3E" alt="" title="esp32 and LTR303_bb" data-src="https://www.esp32learning.com/wp-content/uploads/2023/07/esp32-and-LTR303_bb.png"> </a> 1300 </div> 1301 1302 1303 <div class="header-standard 1304 "> 1305 <div class="penci-standard-cat"><span class="cat"><a style="" class="penci-cat-name penci-cat-14" href="https://www.esp32learning.com/category/code" rel="category tag"><span style="">Code</span></a></span></div> 1306 1307 <h2 class="penci-entry-title entry-title entry-title"><a 1308 href="https://www.esp32learning.com/code/connect-an-ltr-303-ambient-light-sensor-to-an-esp32.php">Connect an LTR-303 Ambient Light sensor to an ESP32</a></h2> 1309 <div class="penci-hide-tagupdated"> 1310 <span class="author-italic author vcard">by <a class="author-url url fn n" 1311 href="https://www.esp32learning.com/author/shedboy71">shedboy71</a> 1312 </span> 1313 <time class="entry-date published" datetime="2023-11-20T09:23:23+00:00">20th November 2023</time> </div> 1314 </div> 1315 1316 <div class="standard-content"> 1317 <div class="standard-main-content entry-content"> 1318 <div class="post-entry standard-post-entry classic-post-entry blockquote-style-1 "> 1319 <p>
1319In this article, we look at an Ambient Light sensor, the LTR-303, and connect it to an ESP32 board</p> 1320<h3>Sensor Information</h3> 1321<p>The LTR-303ALS is a low-cost, small, I2C Ambient Light sensor. The LTR-303ALS comes in a 2.0×2.0×0.7mm 6-pin DFN package.</p> 1322<p>The LTR-303ALS has an operating voltage of 2.4-3.6V with I2C operation down to 1.7V. The LTR-303ALS provides a full dynamic range from 0.01-64K lux while providing a close-to-the-eye spectral response with immunity to IR/UV light sources and automatically rejects 50/60Hz light flicker.</p> 1323<p>There are 6 gain settings available 1X, 2X, 3X, 4X, 8X, 48X, and 96X) to the user and provides a 16-bit effective resolution output.</p> 1324<h4>Features</h4> 1325<p>I2C interface (Fast Mode @ 400kbit/s)<br /> 1326Ultra-small 6-pin ChipLED package 2.0mm(L), 2.0mm(B), 0.7mm(H)<br /> 1327Built-in temperature compensation circuit<br /> 1328Low active power consumption with standby mode<br /> 1329Supply voltage range from 2.4V to 3.6V capable of 1.7V logic voltage<br /> 1330Operating temperature range from -30C to +70C<br /> 1331RoHS and Halogen free compliant<br /> 1332Close to human eye spectral response<br /> 1333Immunity to IR / UV Light Source<br /> 1334Automatically rejects 50 / 60 Hz lightings flicker<br /> 1335Full dynamic range from 0.01 lux to 64k lux<br /> 133616-bit effective resolution</p> 1337<div class="product-feature-category" data-module-component="product-features"> 1338<div class="feature-category-label-column"> 1339<h3>Parts Required</h3> 1340<p>You can connect to the sensor using dupont style jumper wire.</p> 1341<p> </p> 1342<div class="pcrstb-wrap"><table> 1343<tbody> 1344<tr style="height: 21px;"> 1345<td style="width: 15.8442%; height: 21px;"><strong>Name</strong></td> 1346<td style="width: 40.1299%; height: 21px;"><strong>Link</strong></td> 1347<td style="width: 44.4156%;"></td> 1348</tr> 1349<tr style="height: 55px;"> 1350<td style="width: 15.8442%; height: 55px;">ESP32</td> 1351<td style="width: 40.1299%;"><a href="https://s.click.aliexpress.com/e/_DkIPPqt" target="_blank" rel="noopener"><img decoding="async" src="//ae01.alicdn.com/kf/Sbf885b40323a45178795fde862d61c3cT.jpg_140x140.jpg"" /></a></td> 1352<td style="width: 44.4156%; height: 55px;"> 1353<ul> 1354<li><a href="https://s.click.aliexpress.com/e/_DdKOnXT" target="_blank" rel="noopener">Aliexpress link</a></li> 1355<li><a href="https://www.amazon.com/s?k=ESP32%22&camp=1789&creative=9325&linkCode=ur2&linkId=cac24da38498a0be29dcff978e974b54&tag=basicvisualbasic" target="_blank" rel="noopener">Amazon</a></li> 1356<li><a href="https://www.ebay.com/sch/i.html?_from=R40&_trksid=p2334524.m570.l1313&_nkw=ESP32&_sacat=0&_odkw=ESP32&_osacat=0&mkcid=1&mkrid=711-53200-19255-0&siteid=0&campid=5338725476&customid=&toolid=10001&mkevt=1" target="_blank" rel="noopener">Ebay</a></li> 1357</ul> 1358</td> 1359</tr> 1360<tr style="height: 55px;"> 1361<td style="width: 15.8442%; height: 55px;">LTR303</td> 1362<td style="width: 40.1299%;"></td> 1363<td style="width: 44.4156%; height: 55px;"> 1364<ul> 1365<li><a href="https://s.click.aliexpress.com/e/_DkiDfdT" target="_blank" rel="noopener">Aliexpress link</a></li> 1366<li><a href="https://www.ebay.com/sch/i.html?_from=R40&_trksid=p2334524.m570.l1313&_nkw=LTR-303&_sacat=0&_odkw=LTR-303%2C&_osacat=0" target="_blank" rel="noopener">Ebay link</a></li> 1367<li><a href="https://www.amazon.com/s?k=LTR-303&crid=1SC5X4U4FZNC9&sprefix=ltr-303%2Caps%2C147&ref=nb_sb_noss" target="_blank" rel="noopener">Amazon Link</a></li> 1368</ul> 1369</td> 1370</tr> 1371<tr style="height: 21px;"> 1372<td style="width: 15.8442%; height: 21px;">Connecting cables</td> 1373<td style="width: 40.1299%;"><img decoding="async" class="alignnone size-thumbnail wp-image-13" src="http://www.arduinocode.com/wp-content/uploads/2023/07/dupont-150x150.jpg" alt="" width="150" height="150" /></td> 1374<td style="width: 44.4156%; height: 21px;"> 1375<ul> 1376<li><a href="https://s.click.aliexpress.com/e/_Dnk1xwF" target="_blank" rel="noopener">Aliexpress link</a></li> 1377<li><a href="https://www.amazon.com/s?k=dupont+cables%22&camp=1789&creative=9325&linkCode=ur2&linkId=cac24da38498a0be29dcff978e974b54&tag=basicvisualbasic" target="_blank" rel="noopener">Amazon</a></li> 1378<li><a href="https://www.ebay.com/sch/i.html?_from=R40&_trksid=p2334524.m570.l1313&_nkw=dupont+cables&_sacat=0&_odkw=dupont+cables&_osacat=0&mkcid=1&mkrid=711-53200-19255-0&siteid=0&campid=5338725476&
1378customid=&toolid=10001&mkevt=1" target="_blank" rel="noopener">Ebay</a></li> 1379</ul> 1380</td> 1381</tr> 1382</tbody> 1383</table></div> 1384<p> </p> 1385<h3>Schematic/Connection</h3> 1386<p>I used 3.3v from the ESP32 and connected using the qwic sensor</p> 1387<p><img decoding="async" class="alignnone size-full wp-image-900" src="https://www.esp32learning.com/wp-content/uploads/2023/07/esp32-and-LTR303_bb-1.png" alt="" width="732" height="756" srcset="https://www.esp32learning.com/wp-content/uploads/2023/07/esp32-and-LTR303_bb-1.png 732w, https://www.esp32learning.com/wp-content/uploads/2023/07/esp32-and-LTR303_bb-1-290x300.png 290w" sizes="(max-width: 732px) 100vw, 732px" /></p> 1388<p> </p> 1389<h3>Code Example</h3> 1390<p>I installed the Adafruit library using the Arduino ide which also installed the dependency library</p> 1391<p>Click the <strong>Manage Libraries …</strong> menu item, search for <strong>LTR329_LTR303</strong>, and select the <strong>Adafruit LTR329 LTR303</strong> library</p> 1392<p>If asked about dependencies, click on the “Install all” option</p> 1393<p>If the Dependencies window does appear, then you already have the required dependencies already installed.</p> 1394<p>If the dependencies are already installed, make sure that you have the latest ones installed using the Arduino Library Manager</p> 1395<p>This is the default example with the delay set to 1000ms rather than 100ms which seemed a bit too short a delay for simple testing</p> 1396<pre class="EnlighterJSRAW" data-enlighter-language="cpp">#include "Adafruit_LTR329_LTR303.h" 1397 1398Adafruit_LTR303 ltr = Adafruit_LTR303(); 1399 1400void setup() { 1401 Serial.begin(115200); 1402 while (!Serial) { 1403 delay(10); // wait for serial port to open 1404 } 1405 Serial.println("Adafruit LTR-303 simple test"); 1406 1407 if ( ! ltr.begin() ) { 1408 Serial.println("Couldn't find LTR sensor!"); 1409 while (1) delay(10); 1410 } 1411 Serial.println("Found LTR sensor!"); 1412 1413 // Set gain of 1 (see advanced demo for all options! 1414 ltr.setGain(LTR3XX_GAIN_1); 1415 // Set integration time of 50ms (see advanced demo for all options! 1416 ltr.setIntegrationTime(LTR3XX_INTEGTIME_50); 1417 // Set measurement rate of 50ms (see advanced demo for all options! 1418 ltr.setMeasurementRate(LTR3XX_MEASRATE_50); 1419} 1420 1421void loop() { 1422 bool valid; 1423 uint16_t visible_plus_ir, infrared; 1424 1425 if (ltr.newDataAvailable()) { 1426 valid = ltr.readBothChannels(visible_plus_ir, infrared); 1427 if (valid) { 1428 Serial.print("CH0 Visible + IR: "); 1429 Serial.print(visible_plus_ir); 1430 Serial.print("\t\tCH1 Infrared: "); 1431 Serial.println(infrared); 1432 } 1433 } 1434 1435 delay(1000); 1436}</pre> 1437<p> </p> 1438<h4>Output</h4> 1439<p>Here is an example of what I saw in the serial monitor window – you may see some different results</p> 1440<p>This was covering and uncovering the sensor</p> 1441<p>CH0 Visible + IR: 1 CH1 Infrared: 2<br /> 1442CH0 Visible + IR: 7 CH1 Infrared: 6<br /> 1443CH0 Visible + IR: 6 CH1 Infrared: 6<br /> 1444CH0 Visible + IR: 6 CH1 Infrared: 7<br /> 1445CH0 Visible + IR: 1 CH1 Infrared: 2</p> 1446<h3>Links</h3> 1447<p><a href="https://optoelectronics.liteon.com/upload/download/DS86-2013-0004/LTR-303ALS-01_DS_V1.pdf" target="_blank" rel="noopener">https://optoelectronics.liteon.com/upload/download/DS86-2013-0004/LTR-303ALS-01_DS_V1.pdf</a></p> 1448<p> </p> 1449<p> </p> 1450<p> </p> 1451</div> 1452</div> 1453<div class="addtoany_share_save_container addtoany_content addtoany_content_bottom"><div class="a2a_kit a2a_kit_size_32 addtoany_list" data-a2a-url="https://www.esp32learning.com/code/connect-an-ltr-303-ambient-light-sensor-to-an-esp32.php" data-a2a-title="Connect an LTR-303 Ambient Light sensor to an ESP32"><a class="a2a_button_facebook" href="https://www.addtoany.com/add_to/facebook?linkurl=https%3A%2F%2Fwww.esp32learning.com%2Fcode%2Fconnect-an-ltr-303-ambient-light-sensor-to-an-esp32.php&linkname=Connect%20an%20LTR-303%20Ambient%20Light%20sensor%20to%20an%20ESP32" title="Facebook" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_twitter" href="https://www.addtoany.com/add_to/twitter?linkurl=https%3A%2F%2Fwww.esp32learning.com%2Fcode%2Fconnect-an-ltr-303-ambient-light-sensor-to-an-esp32.php&linkname=Connect%20an%20LTR-303%20Ambient%20Light%20sensor%20to%20an%20ESP32" title="Twitter" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_threads" href="https://www.addtoany.com/add_to/threads?linkurl=https%3A%2F%2Fwww.esp32learning.com%2Fcode%2Fconnect-an-ltr-303-ambient-light-sensor-to-an-esp32.php&linkname=Connect%20an%20LTR-303%20Ambient%20Light%20sensor%20to%20an%20ESP32" title="Threads" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_pinterest" href="https://www.addtoany.com/add_to/pinterest?linkurl=https%3A%2F%2Fwww.esp32learning.com%2Fcode%2Fconnect-an-ltr-303-ambient-light-sensor-to-an-esp32.php&linkname=Connect%20an%20LTR-303%20Ambient%20Light%20sensor%20to%20an%20ESP32" title="Pinterest" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_tumblr" href="https://www.addtoany.com/add_to/tumblr?linkurl=https%3A%2F%2Fwww.esp32learning.com%2Fcode%2Fconnect-an-ltr-303-ambient-light-sensor-to-an-esp32.php&linkname=Connect%20an%20LTR-303%20Ambient%20Light%20sensor%20to%20an%20ESP32" title="Tumblr" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_reddit" href="https://www.addtoany.com/add_to/reddit?linkurl=https%3A%2F%2Fwww.esp32learning.com%2Fcode%2Fconnect-an-ltr-303-ambient-light-sensor-to-an-esp32.php&linkname=Connect%20an%20LTR-303%20Ambient%20Light%20sensor%20to%20an%20ESP32" title="Reddit" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_linkedin" href="https://www.addtoany.com/add_to/linkedin?linkurl=https%3A%2F%2Fwww.esp32learning.com%2Fcode%2Fconnect-an-ltr-303-ambient-light-sensor-to-an-esp32.php&linkname=Connect%20an%20LTR-303%20Ambient%20Light%20sensor%20to%20an%20ESP32" title="LinkedIn" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_digg" href="https://www.addtoany.com/add_to/digg?linkurl=https%3A%2F%2Fwww.esp32learning.com%2Fcode%2Fconnect-an-ltr-303-ambient-light-sensor-to-an-esp32.php&linkname=Connect%20an%20LTR-303%20Ambient%20Light%20sensor%20to%20an%20ESP32" title="Digg" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_pocket" href="https://www.addtoany.com/add_to/pocket?linkurl=https%3A%2F%2Fwww.esp32learning.com%2Fcode%2Fconnect-an-ltr-303-ambient-light-sensor-to-an-esp32.php&linkname=Connect%20an%20LTR-303%20Ambient%20Light%20sensor%20to%20an%20ESP32" title="Pocket" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_sina_weibo" href="https://www.addtoany.com/add_to/sina_weibo?linkurl=https%3A%2F%2Fwww.esp32learning.com%2Fcode%2Fconnect-an-ltr-303-ambient-light-sensor-to-an-esp32.php&linkname=Connect%20an%20LTR-303%20Ambient%20Light%20sensor%20to%20an%20ESP32" title="Sina Weibo" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_wordpress" href="https://www.addtoany.com/add_to/wordpress?linkurl=https%3A%2F%2Fwww.esp32learning.com%2Fcode%2Fconnect-an-ltr-303-ambient-light-sensor-to-an-esp32.php&linkname=Connect%20an%20LTR-303%20Ambient%20Light%20sensor%20to%20an%20ESP32" title="WordPress" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_blogger" href="https://www.addtoany.com/add_to/blogger?linkurl=https%3A%2F%2Fwww.esp32learning.com%2Fcode%2Fconnect-an-ltr-303-ambient-light-sensor-to-an-esp32.php&linkname=Connect%20an%20LTR-303%20Ambient%20Light%20sensor%20to%20an%20ESP32" title="Blogger" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_sms" href="https://www.addtoany.com/add_to/sms?linkurl=https%3A%2F%2Fwww.esp32learning.com%2Fcode%2Fconnect-an-ltr-303-ambient-light-sensor-to-an-esp32.php&linkname=Connect%20an%20LTR-303%20Ambient%20Light%20sensor%20to%20an%20ESP32" title="Message" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_whatsapp" href="https://www.addtoany.com/add_to/whatsapp?linkurl=https%3A%2F%2Fwww.esp32learning.com%2Fcode%2Fconnect-an-ltr-303-ambient-light-sensor-to-an-esp32.php&linkname=Connect%20an%20LTR-303%20Ambient%20Light%20sensor%20to%20an%20ESP32" title="WhatsApp" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_telegram" href="https://www.addtoany.com/add_to/telegram?linkurl=https%3A%2F%2Fwww.esp32learning.com%2Fcode%2Fconnect-an-ltr-303-ambient-light-sensor-to-an-esp32.php&linkname=Connect%20an%20LTR-303%20Ambient%20Light%20sensor%20to%20an%20ESP32" title="Telegram" rel="nofollow noopener" target="_blank"></a><a class="a2a_dd addtoany_share_save addtoany_share" href="https://www.addtoany.com/share"></a></div></div> </div> 1454 </div> 1455 1456 <div class="penci-post-box-meta 1457 center-inner "> 1458 <div class="penci-post-share-box"> 1459 <a href="#" class="penci-post-like" aria-label="Like this post" data-post_id="897" title="Like" data-like="Like" data-unlike="Unlike"><i class="penci-faicon fa fa-heart-o" ></i><span class="dt-share">4</span></a> <a class="new-ver-share post-share-item post-share-facebook" aria-label="Share on Facebook" target="_blank" rel="noreferrer" href="https://www.facebook.com/sharer/sharer.php?u=https://www.esp32learning.com/code/connect-an-ltr-303-ambient-light-sensor-to-an-esp32.php"><i class="penci-faicon fa fa-facebook" ></i><span class="dt-share">Facebook</span></a><a class="new-ver-share post-share-item post-share-twitter" aria-label="Share on Twitter" target="_blank" rel="noreferrer" href="https://twitter.com/intent/tweet?text=Check%20out%20this%20article:%20Connect%20an%20LTR-303%20Ambient%20Light%20sensor%20to%20an%20ESP32%20-%20https://www.esp32learning.com/code/connect-an-ltr-303-ambient-light-sensor-to-an-esp32.php"><i class="penci-faicon penciicon-x-twitter" ></i><span class="dt-share">Twitter</span></a><a class="new-ver-share post-share-item post-share-pinterest" aria-label="Pin to Pinterest" data-pin-do="none" rel="noreferrer" target="_blank" href="https://www.pinterest.com/pin/create/button/?url=https%3A%2F%2Fwww.esp32learning.com%2Fcode%2Fconnect-an-ltr-303-ambient-light-sensor-to-an-esp32.php&media=https%3A%2F%2Fwww.esp32learning.com%2Fwp-content%2Fuploads%2F2023%2F07%2Fesp32-and-LTR303_bb.png&description=Connect+an+LTR-303+Ambient+Light+sensor+to+an+ESP32"><i class="penci-faicon fa fa-pinterest" ></i><span class="dt-share">Pinterest</span></a><a class="new-ver-share post-share-item post-share-email" target="_blank" aria-label="Share via Email" rel="noreferrer" href="mailto:?subject=Connect%20an%20LTR-303%20Ambient%20Light%20sensor%20to%20an%20ESP32&BODY=https://www.esp32learning.com/code/connect-an-ltr-303-ambient-light-sensor-to-an-esp32.php"><i class="penci-faicon fa fa-envelope" ></i><span class="dt-share">Email</span></a> </div> 1460 </div> 1461 </div> 1462 1463</article> 1464 1465<article id="post-894" class="standard-article standard-pitem post-894 post type-post status-publish format-standard has-post-thumbnail hentry category-code tag-esp32 tag-kx134"> 1466 1467 1468 1469 <div class="standard-post-image"> 1470 <a 1471 href="https://www.esp32learning.com/code/connect-a-kx134-triple-axis-accelerometer-to-an-esp32-example.php"> 1472 <img 1473 class="attachment-penci-full-thumb size-penci-full-thumb penci-lazy wp-post-image" 1474 width="690" 1475 height="852" 1476 src="data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%20690%20852'%3E%3C/svg%3E" alt="" title="esp32 and KX13x_bb" data-src="https://www.esp32learning.com/wp-content/uploads/2023/07/esp32-and-KX13x_bb.png"> </a> 1477 </div> 1478 1479 1480 <div class="header-standard 1481 "> 1482 <div class="penci-standard-cat"><span class="cat"><a style="" class="penci-cat-name penci-cat-14" href="https://www.esp32learning.com/category/code" rel="category tag"><span style="">Code</span></a></span></div> 1483 1484 <h2 class="penci-entry-title entry-title entry-title"><a 1485 href="https://www.esp32learning.com/code/connect-a-kx134-triple-axis-accelerometer-to-an-esp32-example.php">Connect a KX134 Triple Axis Accelerometer to an ESP32 example</a></h2> 1486 <div class="penci-hide-tagupdated"> 1487 <span class="author-italic author vcard">by <a class="author-url url fn n" 1488 href="https://www.esp32learning.com/author/shedboy71">shedboy71</a> 1489 </span> 1490 <time class="entry-date published" datetime="2023-10-19T22:29:34+01:00">19th October 2023</time> </div> 1491 </div> 1492 1493 <div class="standard-content"> 1494 <div class="standard-main-content entry-content"> 1495 <div class="post-entry standard-post-entry classic-post-entry blockquote-style-1 "> 1496 <p>
1496In this article we look at another Triple-axis Magnetometer, the KX134 Triple Axis Accelerometer, and connect it to an ESP32 board</p> 1497<p>This is very similar to the KX132 we wrote about previously in an article</p> 1498<h3>Sensor Information</h3> 1499<p>This KX134 is a digital accelerometer from Kionix. We will use the KX134 breakout from Sparkfun</p> 1500<p>The KX134 is a low-power, 16-bit resolution three-axis accelerometer capable of measuring ±8g/16g/32g/64g (user-selectable) and has up to a 10kHz output data rate making it ideal for high-g measurements as well as high-speed applications such as vibration sensing</p> 1501<p>The KX134 includes a host of features including Freefall detection, Directional Tap™ and Double-Tap™ detection, tilt orientation detection and more. The Qwiic KX134 can interface with controllers using both I2C and SPI at high speeds so you can use it in an existing Qwiic chain or on an SPI bus.</p> 1502<p>This is what the breakout looks like</p> 1503<p><a href="https://s.click.aliexpress.com/e/_DD6oqpx" target="_blank" rel="noopener"><img decoding="async" class="" src="//ae01.alicdn.com/kf/S8bb5c331940b45c5b90b5317c9f297abm.jpg_140x140.jpg"" width="248" height="248" /></a></p> 1504<h3>Features</h3> 1505<ul> 1506<li>Measurement Range: ±8g, ±16g, ±32g, ±64g (User Selectable)</li> 1507<li>High Resolution (8 or 16-bit)</li> 1508<li>User-Configurable Output Data Rate (ODR) up to 25600Hz</li> 1509<li>User-Configurable 3-stage Advanced Data Path featuring low-pass filter, low-pass/high-pass filter and RMS calculation engine</li> 1510<li>Wide range of built-in sensing functions 1511<ul> 1512<li>Free Fall</li> 1513<li>Directional-Tap<sup>™</sup> / Double-Tap<sup>™</sup></li> 1514<li>Device Orientation & Activity Algorithms</li> 1515</ul> 1516</li> 1517<li>Low Noise: 130µg/√Hz (varies based on ODR, power mode & other settings)</li> 1518<li>High-Resolution Wake-Up & Back-to-Sleep Detection with a configurable threshold as low as 3.9mg</li> 1519<li>512-byte FIFO buffer that continues recording data while being read</li> 1520<li>Selectable Low-Power or High-Performance operating modes</li> 1521<li>Low Power with Integrated Voltage Regulator 1522<ul> 1523<li>High-Performance Operating Current Consumption (400Hz ODR + Wake-Up Detection): 148µA</li> 1524<li>Low Power Operating Current Consumption (0.781Hz ODR + Wake-Up Detection): 0.53µA</li> 1525<li>Standby Current Consumption: 0.5µA</li> 1526</ul> 1527</li> 1528<li>Self-Test Functionality</li> 1529<li>Digital I<sup>2</sup>C up to 3.4MHz and Digital SPI up to 10MHz</li> 1530<li>2x Qwiic Connectors</li> 1531<li>SPI available on PTH Header Pins</li> 1532<li>I<sup>2</sup>C Address: 0x1E (0x1F can be used as an alternate but requires soldering abridge across 2 pads on the underside of the board)</li> 1533</ul> 1534<div class="product-feature-category" data-module-component="product-features"> 1535<div class="feature-category-label-column"> 1536<h3>Parts Required</h3> 1537<p>You can connect to the sensor using DuPont style jumper wire.</p> 1538<p> </p> 1539<div class="pcrstb-wrap"><table> 1540<tbody> 1541<tr style="height: 21px;"> 1542<td style="width: 15.8442%; height: 21px;"><strong>Name</strong></td> 1543<td style="width: 40.1299%; height: 21px;"><strong>Link</strong></td> 1544<td style="width: 44.4156%;"></td> 1545</tr> 1546<tr style="height: 55px;"> 1547<td style="width: 15.8442%; height: 55px;">ESP32</td> 1548<td style="width: 40.1299%;"><a href="https://s.click.aliexpress.com/e/_DkIPPqt" target="_blank" rel="noopener"><img decoding="async" src="//ae01.alicdn.com/kf/Sbf885b40323a45178795fde862d61c3cT.jpg_140x140.jpg"" /></a></td> 1549<td style="width: 44.4156%; height: 55px;"> 1550<ul> 1551<li><a href="https://s.click.aliexpress.com/e/_DdKOnXT" target="_blank" rel="noopener">Aliexpress link</a></li> 1552<li><a href="https://www.amazon.com/s?k=ESP32%22&camp=1789&creative=9325&linkCode=ur2&linkId=cac24da38498a0be29dcff978e974b54&tag=basicvisualbasic" target="_blank" rel="noopener">Amazon</a></li> 1553<li><a href="https://www.ebay.com/sch/i.html?_from=R40&_trksid=p2334524.m570.l1313&_nkw=ESP32&_sacat=0&_odkw=ESP32&_osacat=0&mkcid=1&mkrid=711-53200-19255-0&siteid=0&campid=5338725476&
1553customid=&toolid=10001&mkevt=1" target="_blank" rel="noopener">Ebay</a></li> 1554</ul> 1555</td> 1556</tr> 1557<tr style="height: 55px;"> 1558<td style="width: 15.8442%; height: 55px;">KX134</td> 1559<td style="width: 40.1299%;"></td> 1560<td style="width: 44.4156%; height: 55px;"> 1561<ul> 1562<li><a href="https://s.click.aliexpress.com/e/_DD6oqpx" target="_blank" rel="noopener">Aliexpress link</a></li> 1563</ul> 1564</td> 1565</tr> 1566<tr style="height: 21px;"> 1567<td style="width: 15.8442%; height: 21px;">Connecting cables</td> 1568<td style="width: 40.1299%;"><img decoding="async" class="alignnone size-thumbnail wp-image-13" src="http://www.arduinocode.com/wp-content/uploads/2023/07/dupont-150x150.jpg" alt="" width="150" height="150" /></td> 1569<td style="width: 44.4156%; height: 21px;"> 1570<ul> 1571<li><a href="https://s.click.aliexpress.com/e/_Dnk1xwF" target="_blank" rel="noopener">Aliexpress link</a></li> 1572<li><a href="https://www.amazon.com/s?k=dupont+cables%22&camp=1789&creative=9325&linkCode=ur2&linkId=cac24da38498a0be29dcff978e974b54&tag=basicvisualbasic" target="_blank" rel="noopener">Amazon</a></li> 1573<li><a href="https://www.ebay.com/sch/i.html?_from=R40&_trksid=p2334524.m570.l1313&_nkw=dupont+cables&_sacat=0&_odkw=dupont+cables&_osacat=0&mkcid=1&mkrid=711-53200-19255-0&siteid=0&campid=5338725476&customid=&toolid=10001&mkevt=1" target="_blank" rel="noopener">Ebay</a></li> 1574</ul> 1575</td> 1576</tr> 1577</tbody> 1578</table></div> 1579<p> </p> 1580<h3>Schematic/Connection</h3> 1581<p>I used 3.3v from the ESP32</p> 1582<p>I also used a Qwiic cable, but if you do not have one, there is an unpopulated set of pins you can solder a header to. This is how you would wire this up</p> 1583<p><img decoding="async" class="alignnone size-full wp-image-892" src="https://www.esp32learning.com/wp-content/uploads/2023/07/esp32-and-KX13x_bb.png" alt="" width="690" height="852" srcset="https://www.esp32learning.com/wp-content/uploads/2023/07/esp32-and-KX13x_bb.png 690w, https://www.esp32learning.com/wp-content/uploads/2023/07/esp32-and-KX13x_bb-243x300.png 243w" sizes="(max-width: 690px) 100vw, 690px" /></p> 1584<p> </p> 1585<h3>Code Example</h3> 1586<p>I installed the Sparkfun library using the Arduino ide</p> 1587<p>Click the <strong>Manage Libraries …</strong> menu item, search for KX134, and select the Sparkfun KX13x library like this</p> 1588</div> 1589<p>This is one of the examples that gets installed with the library, with a few comments and unused lines removed.</p> 1590<pre class="EnlighterJSRAW" data-enlighter-language="cpp">#include <Wire.h> 1591#include <SparkFun_KX13X.h> 1592 1593SparkFun_KX134 kxAccel; 1594 1595outputData myData; // Struct for the accelerometer's data 1596 1597void setup() 1598{ 1599 1600 Wire.begin(); 1601 Serial.begin(115200); 1602 1603 // Wait for the Serial monitor to be opened. 1604 while (!Serial) 1605 delay(50); 1606 1607 if (!kxAccel.begin()) 1608 { 1609 Serial.println("Could not communicate with the the KX13X"); 1610 while (1) 1611 ; 1612 } 1613 Serial.println("Ready."); 1614 1615 if (kxAccel.softwareReset()) 1616 Serial.println("Reset."); 1617 1618 // Give some time for the accelerometer to reset. 1619 // It needs two, but give it five for good measure. 1620 delay(5); 1621 1622 // Many settings for KX13X can only be 1623 // applied when the accelerometer is powered down. 1624 // However there are many that can be changed "on-the-fly" 1625 // check datasheet for more info, or the comments in the 1626 // "...regs.h" file which specify which can be changed when. 1627 kxAccel.enableAccel(false); 1628 1629 kxAccel.setRange(SFE_KX134_RANGE16G); // 16g for the KX134 1630 1631 kxAccel.enableDataEngine(); // Enables the bit that indicates data is ready. 1632 // kxAccel.setOutputDataRate(); // Default is 50Hz 1633 kxAccel.enableAccel(); 1634} 1635 1636void loop() 1637{ 1638 // Check if data is ready. 1639 if (kxAccel.dataReady()) 1640 { 1641 kxAccel.getAccelData(&myData); 1642 Serial.print("X: "); 1643 Serial.print(myData.xData, 4); 1644 Serial.print(" Y: "); 1645 Serial.print(myData.yData, 4); 1646 Serial.print(" Z: "); 1647 Serial.print(myData.zData, 4); 1648 Serial.println(); 1649 } 1650 delay(500); // Delay should be 1/ODR (Output Data Rate), default is 1/50ODR 1651}</pre> 1652<p> </p> 1653<div class="feature-category-label-column"> 1654<h4>Output</h4> 1655<p>When run and the sensor was moved around</p> 1656<p>Ready.<br /> 1657Reset.<br /> 1658X: 0.3035 Y: -0.0088 Z: -0.9189<br /> 1659X: -0.0044 Y: 0.6022 Z: -1.2317<br /> 1660X: -1.3576 Y: -0.2172 Z: -0.2381<br /> 1661X: -0.0693 Y: -0.0176 Z: 0.6759</p> 1662<h3>Links</h3> 1663<p>
1663<a href="https://kionixfs.azureedge.net/en/datasheet/kx134-1211-e.pdf" target="_blank" rel="noopener">https://kionixfs.azureedge.net/en/datasheet/kx134-1211-e.pdf</a></p> 1664</div> 1665</div> 1666<div class="addtoany_share_save_container addtoany_content addtoany_content_bottom"><div class="a2a_kit a2a_kit_size_32 addtoany_list" data-a2a-url="https://www.esp32learning.com/code/connect-a-kx134-triple-axis-accelerometer-to-an-esp32-example.php" data-a2a-title="Connect a KX134 Triple Axis Accelerometer to an ESP32 example"><a class="a2a_button_facebook" href="https://www.addtoany.com/add_to/facebook?linkurl=https%3A%2F%2Fwww.esp32learning.com%2Fcode%2Fconnect-a-kx134-triple-axis-accelerometer-to-an-esp32-example.php&linkname=Connect%20a%20KX134%20Triple%20Axis%20Accelerometer%20to%20an%20ESP32%20example" title="Facebook" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_twitter" href="https://www.addtoany.com/add_to/twitter?linkurl=https%3A%2F%2Fwww.esp32learning.com%2Fcode%2Fconnect-a-kx134-triple-axis-accelerometer-to-an-esp32-example.php&linkname=Connect%20a%20KX134%20Triple%20Axis%20Accelerometer%20to%20an%20ESP32%20example" title="Twitter" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_threads" href="https://www.addtoany.com/add_to/threads?linkurl=https%3A%2F%2Fwww.esp32learning.com%2Fcode%2Fconnect-a-kx134-triple-axis-accelerometer-to-an-esp32-example.php&linkname=Connect%20a%20KX134%20Triple%20Axis%20Accelerometer%20to%20an%20ESP32%20example" title="Threads" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_pinterest" href="https://www.addtoany.com/add_to/pinterest?linkurl=https%3A%2F%2Fwww.esp32learning.com%2Fcode%2Fconnect-a-kx134-triple-axis-accelerometer-to-an-esp32-example.php&linkname=Connect%20a%20KX134%20Triple%20Axis%20Accelerometer%20to%20an%20ESP32%20example" title="Pinterest" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_tumblr" href="https://www.addtoany.com/add_to/tumblr?linkurl=https%3A%2F%2Fwww.esp32learning.com%2Fcode%2Fconnect-a-kx134-triple-axis-accelerometer-to-an-esp32-example.php&linkname=Connect%20a%20KX134%20Triple%20Axis%20Accelerometer%20to%20an%20ESP32%20example" title="Tumblr" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_reddit" href="https://www.addtoany.com/add_to/reddit?linkurl=https%3A%2F%2Fwww.esp32learning.com%2Fcode%2Fconnect-a-kx134-triple-axis-accelerometer-to-an-esp32-example.php&linkname=Connect%20a%20KX134%20Triple%20Axis%20Accelerometer%20to%20an%20ESP32%20example" title="Reddit" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_linkedin" href="https://www.addtoany.com/add_to/linkedin?linkurl=https%3A%2F%2Fwww.esp32learning.com%2Fcode%2Fconnect-a-kx134-triple-axis-accelerometer-to-an-esp32-example.php&linkname=Connect%20a%20KX134%20Triple%20Axis%20Accelerometer%20to%20an%20ESP32%20example" title="LinkedIn" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_digg" href="https://www.addtoany.com/add_to/digg?linkurl=https%3A%2F%2Fwww.esp32learning.com%2Fcode%2Fconnect-a-kx134-triple-axis-accelerometer-to-an-esp32-example.php&linkname=Connect%20a%20KX134%20Triple%20Axis%20Accelerometer%20to%20an%20ESP32%20example" title="Digg" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_pocket" href="https://www.addtoany.com/add_to/pocket?linkurl=https%3A%2F%2Fwww.esp32learning.com%2Fcode%2Fconnect-a-kx134-triple-axis-accelerometer-to-an-esp32-example.php&linkname=Connect%20a%20KX134%20Triple%20Axis%20Accelerometer%20to%20an%20ESP32%20example" title="Pocket" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_sina_weibo" href="https://www.addtoany.com/add_to/sina_weibo?linkurl=https%3A%2F%2Fwww.esp32learning.com%2Fcode%2Fconnect-a-kx134-triple-axis-accelerometer-to-an-esp32-example.php&linkname=Connect%20a%20KX134%20Triple%20Axis%20Accelerometer%20to%20an%20ESP32%20example" title="Sina Weibo" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_wordpress" href="https://www.addtoany.com/add_to/wordpress?linkurl=https%3A%2F%2Fwww.esp32learning.com%2Fcode%2Fconnect-a-kx134-triple-axis-accelerometer-to-an-esp32-example.php&linkname=Connect%20a%20KX134%20Triple%20Axis%20Accelerometer%20to%20an%20ESP32%20example" title="WordPress" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_blogger" href="https://www.addtoany.com/add_to/blogger?linkurl=https%3A%2F%2Fwww.esp32learning.com%2Fcode%2Fconnect-a-kx134-triple-axis-accelerometer-to-an-esp32-example.php&linkname=Connect%20a%20KX134%20Triple%20Axis%20Accelerometer%20to%20an%20ESP32%20example" title="Blogger" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_sms" href="https://www.addtoany.com/add_to/sms?linkurl=https%3A%2F%2Fwww.esp32learning.com%2Fcode%2Fconnect-a-kx134-triple-axis-accelerometer-to-an-esp32-example.php&linkname=Connect%20a%20KX134%20Triple%20Axis%20Accelerometer%20to%20an%20ESP32%20example" title="Message" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_whatsapp" href="https://www.addtoany.com/add_to/whatsapp?linkurl=https%3A%2F%2Fwww.esp32learning.com%2Fcode%2Fconnect-a-kx134-triple-axis-accelerometer-to-an-esp32-example.php&linkname=Connect%20a%20KX134%20Triple%20Axis%20Accelerometer%20to%20an%20ESP32%20example" title="WhatsApp" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_telegram" href="https://www.addtoany.com/add_to/telegram?linkurl=https%3A%2F%2Fwww.esp32learning.com%2Fcode%2Fconnect-a-kx134-triple-axis-accelerometer-to-an-esp32-example.php&linkname=Connect%20a%20KX134%20Triple%20Axis%20Accelerometer%20to%20an%20ESP32%20example" title="Telegram" rel="nofollow noopener" target="_blank"></a><a class="a2a_dd addtoany_share_save addtoany_share" href="https://www.addtoany.com/share"></a></div></div> </div> 1667 </div> 1668 1669 <div class="penci-post-box-meta 1670 center-inner "> 1671 <div class="penci-post-share-box"> 1672 <a href="#" class="penci-post-like" aria-label="Like this post" data-post_id="894" title="Like" data-like="Like" data-unlike="Unlike"><i class="penci-faicon fa fa-heart-o" ></i><span class="dt-share">0</span></a> <a class="new-ver-share post-share-item post-share-facebook" aria-label="Share on Facebook" target="_blank" rel="noreferrer" href="https://www.facebook.com/sharer/sharer.php?u=https://www.esp32learning.com/code/connect-a-kx134-triple-axis-accelerometer-to-an-esp32-example.php"><i class="penci-faicon fa fa-facebook" ></i><span class="dt-share">Facebook</span></a><a class="new-ver-share post-share-item post-share-twitter" aria-label="Share on Twitter" target="_blank" rel="noreferrer" href="https://twitter.com/intent/tweet?text=Check%20out%20this%20article:%20Connect%20a%20KX134%20Triple%20Axis%20Accelerometer%20to%20an%20ESP32%20example%20-%20https://www.esp32learning.com/code/connect-a-kx134-triple-axis-accelerometer-to-an-esp32-example.php"><i class="penci-faicon penciicon-x-twitter" ></i><span class="dt-share">Twitter</span></a><a class="new-ver-share post-share-item post-share-pinterest" aria-label="Pin to Pinterest" data-pin-do="none" rel="noreferrer" target="_blank" href="https://www.pinterest.com/pin/create/button/?url=https%3A%2F%2Fwww.esp32learning.com%2Fcode%2Fconnect-a-kx134-triple-axis-accelerometer-to-an-esp32-example.php&media=https%3A%2F%2Fwww.esp32learning.com%2Fwp-content%2Fuploads%2F2023%2F07%2Fesp32-and-KX13x_bb.png&description=Connect+a+KX134+Triple+Axis+Accelerometer+to+an+ESP32+example"><i class="penci-faicon fa fa-pinterest" ></i><span class="dt-share">Pinterest</span></a><a class="new-ver-share post-share-item post-share-email" target="_blank" aria-label="Share via Email" rel="noreferrer" href="mailto:?subject=Connect%20a%20KX134%20Triple%20Axis%20Accelerometer%20to%20an%20ESP32%20example&BODY=https://www.esp32learning.com/code/connect-a-kx134-triple-axis-accelerometer-to-an-esp32-example.php"><i class="penci-faicon fa fa-envelope" ></i><span class="dt-share">Email</span></a> </div> 1673 </div> 1674 </div> 1675 1676</article> 1677 1678<article id="post-890" class="standard-article standard-pitem post-890 post type-post status-publish format-standard has-post-thumbnail hentry category-code tag-esp32 tag-kx132"> 1679 1680 1681 1682 <div class="standard-post-image"> 1683 <a 1684 href="https://www.esp32learning.com/code/connecting-a-kx132-triple-axis-accelerometer-to-an-esp32-board-example.php"> 1685 <img 1686 class="attachment-penci-full-thumb size-penci-full-thumb penci-lazy wp-post-image" 1687 width="690" 1688 height="852" 1689 src="data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%20690%20852'%3E%3C/svg%3E" alt="" title="esp32 and KX13x_bb" data-src="https://www.esp32learning.com/wp-content/uploads/2023/07/esp32-and-KX13x_bb.png"> </a> 1690 </div> 1691 1692 1693 <div class="header-standard 1694 "> 1695 <div class="penci-standard-cat"><span class="cat"><a style="" class="penci-cat-name penci-cat-14" href="https://www.esp32learning.com/category/code" rel="category tag"><span style="">Code</span></a></span></div> 1696 1697 <h2 class="penci-entry-title entry-title entry-title"><a 1698 href="https://www.esp32learning.com/code/connecting-a-kx132-triple-axis-accelerometer-to-an-esp32-board-example.php">Connecting a KX132 Triple Axis Accelerometer to an ESP32 board example</a></h2> 1699 <div class="penci-hide-tagupdated"> 1700 <span class="author-italic author vcard">by <a class="author-url url fn n" 1701 href="https://www.esp32learning.com/author/shedboy71">shedboy71</a> 1702 </span> 1703 <time class="entry-date published" datetime="2023-09-19T22:25:43+01:00">19th September 2023</time> </div> 1704 </div> 1705 1706 <div class="standard-content"> 1707 <div class="standard-main-content entry-content"> 1708 <div class="post-entry standard-post-entry classic-post-entry blockquote-style-1 "> 1709 <p>
1709In this article we look at one of 2 similar Triple-axis Magnetometer that I recently purchased, the KX132 Triple Axis Accelerometer, and connect it to an ESP32</p> 1710<h3>Sensor Information</h3> 1711<p>The KX132 is a digital accelerometer from Kionix.</p> 1712<p>The KX132 is a low-power, 16-bit resolution three-axis accelerometer with four user-selectable acceleration measurement ranges of ±2g/4g/8g/16g and has up to a 10kHz (max) output data rate making it ideal for a wide range of acceleration measurements as well as high-speed applications such as vibration and tap sensing.</p> 1713<p>The KX132 includes a host of features including Freefall detection, Directional Tap™ and Double-Tap™ detection, tilt orientation detection and more.</p> 1714<p>The Qwiic KX132 can interface with controllers using both I2C and SPI at high speeds so you can use it in an existing Qwiic/I2C chain or on a SPI bus.</p> 1715<p><a href="https://s.click.aliexpress.com/e/_DmGT1hX" target="_blank" rel="noopener"><img decoding="async" class="" src="//ae01.alicdn.com/kf/S3a5de56ef86b429db58193d802a3ac93y.jpg_80x80.jpg"" width="239" height="239" /></a></p> 1716<h3>Features</h3> 1717<p>Measurement Range: ±2g, ±4g, ±8g, ±16g (User Selectable)<br /> 1718High Resolution (8 or 16-bit)<br /> 1719User-Configurable Output Data Rate (ODR) up to 25600Hz<br /> 1720User-Configurable 3-stage Advanced Data Path featuring low-pass filter, low-pass/high-pass filter, and RMS calculation engine<br /> 1721Wide range of built-in sensing functions</p> 1722<ul> 1723<li>Free Fall</li> 1724<li>Directional-Tap™ / Double-Tap™</li> 1725<li>Device Orientation & Activity Algorithms</li> 1726</ul> 1727<p>Low Noise: 130µg/√Hz (varies based on ODR, power mode & other settings)<br /> 1728High-Resolution Wake-Up & Back-to-Sleep Detection with a configurable threshold as low as 3.9mg<br /> 1729512-byte FIFO buffer that continues recording data while being read<br /> 1730Selectable Low-Power or High-Performance operating modes<br /> 1731Low Power with Integrated Voltage Regulator</p> 1732<ul> 1733<li>High Performance Operating Current Consumption (400Hz ODR + Wake-Up Detection): 148µA</li> 1734<li>Low Power Operating Current Consumption (0.781Hz ODR + Wake-Up Detection): 0.53µA</li> 1735<li>Standby Current Consumption: 0.5µA</li> 1736</ul> 1737<p>Self-Test Functionality<br /> 1738Digital I2C up to 3.4MHz and Digital SPI up to 10MHz<br /> 17392x Qwiic Connectors<br /> 1740SPI available on PTH Header Pins<br /> 1741I2C Address: 0x1E (0x1F can be used as an alternate)</p> 1742<div class="product-feature-category" data-module-component="product-features"> 1743<div class="feature-category-label-column"> 1744<h3>Parts Required</h3> 1745<p>You can connect to the sensor using DuPont style jumper wire.</p> 1746<p> </p> 1747<div class="pcrstb-wrap"><table> 1748<tbody> 1749<tr style="height: 21px;"> 1750<td style="width: 15.8442%; height: 21px;"><strong>Name</strong></td> 1751<td style="width: 40.1299%; height: 21px;"><strong>Link</strong></td> 1752<td style="width: 44.4156%;"></td> 1753</tr> 1754<tr style="height: 55px;"> 1755<td style="width: 15.8442%; height: 55px;">ESP32</td> 1756<td style="width: 40.1299%;"><a href="https://s.click.aliexpress.com/e/_DkIPPqt" target="_blank" rel="noopener"><img decoding="async" src="//ae01.alicdn.com/kf/Sbf885b40323a45178795fde862d61c3cT.jpg_140x140.jpg"" /></a></td> 1757<td style="width: 44.4156%; height: 55px;"> 1758<ul> 1759<li><a href="https://s.click.aliexpress.com/e/_DdKOnXT" target="_blank" rel="noopener">Aliexpress link</a></li> 1760<li><a href="https://www.amazon.com/s?k=ESP32%22&camp=1789&creative=9325&linkCode=ur2&linkId=cac24da38498a0be29dcff978e974b54&tag=basicvisualbasic" target="_blank" rel="noopener">Amazon</a></li> 1761<li><a href="https://www.ebay.com/sch/i.html?_from=R40&_trksid=p2334524.m570.l1313&_nkw=ESP32&_sacat=0&_odkw=ESP32&_osacat=0&mkcid=1&mkrid=711-53200-19255-0&siteid=0&campid=5338725476&customid=&toolid=10001&mkevt=1" target="_blank" rel="noopener">Ebay</a></li> 1762</ul> 1763</td> 1764</tr> 1765<tr style="height: 55px;"> 1766<td style="width: 15.8442%; height: 55px;">KX132</td> 1767<td style="width: 40.1299%;"></td> 1768<td style="width: 44.4156%; height: 55px;"> 1769<ul> 1770<li><a href="https://s.click.aliexpress.com/e/_DCDLLTT" target="_blank" rel="noopener">Aliexpress link</a></li> 1771</ul> 1772</td> 1773</tr> 1774<tr style="height: 21px;"> 1775<td style="width: 15.8442%; height: 21px;">Connecting cables</td> 1776<td style="width: 40.1299%;"><img decoding="async" class="alignnone size-thumbnail wp-image-13" src="http://www.arduinocode.com/wp-content/uploads/2023/07/dupont-150x150.jpg" alt="" width="150" height="150" /></td> 1777<td style="width: 44.4156%; height: 21px;"> 1778<ul> 1779<li><a href="https://s.click.aliexpress.com/e/_Dnk1xwF" target="_blank" rel="noopener">Aliexpress link</a></li> 1780<li><a href="https://www.amazon.com/s?k=dupont+cables%22&camp=1789&creative=9325&linkCode=ur2&linkId=cac24da38498a0be29dcff978e974b54&tag=basicvisualbasic" target="_blank" rel="noopener">Amazon</a></li> 1781<li><a href="https://www.ebay.com/sch/i.html?_from=R40&_trksid=p2334524.m570.l1313&_nkw=dupont+cables&_sacat=0&_odkw=dupont+cables&_osacat=0&mkcid=1&mkrid=711-53200-19255-0&siteid=0&campid=5338725476&
1781customid=&toolid=10001&mkevt=1" target="_blank" rel="noopener">Ebay</a></li> 1782</ul> 1783</td> 1784</tr> 1785</tbody> 1786</table></div> 1787<p> </p> 1788<h3>Schematic/Connection</h3> 1789<p>I used 3.3v from the ESP32 Lolin board I used for testing</p> 1790<p>I also used a Qwiic cable but if you do not have one of them there is an unpopulated set of pins you can solder a header to. This is how you would wire this up</p> 1791<p><img decoding="async" class="alignnone size-full wp-image-892" src="https://www.esp32learning.com/wp-content/uploads/2023/07/esp32-and-KX13x_bb.png" alt="" width="690" height="852" srcset="https://www.esp32learning.com/wp-content/uploads/2023/07/esp32-and-KX13x_bb.png 690w, https://www.esp32learning.com/wp-content/uploads/2023/07/esp32-and-KX13x_bb-243x300.png 243w" sizes="(max-width: 690px) 100vw, 690px" /></p> 1792<p> </p> 1793<h3>Code Example</h3> 1794<p>I installed the Sparkfun library using the Arduino ide</p> 1795<p>Click the <strong>Manage Libraries …</strong> menu item, search for KX132, and select the Sparkfun KX13x library like this</p> 1796</div> 1797<p>This is one of the examples that gets installed with the library, with a few comments and unused lines removed.</p> 1798<div class="feature-category-label-column"> 1799<pre class="EnlighterJSRAW" data-enlighter-language="cpp">#include <Wire.h> 1800#include <SparkFun_KX13X.h> 1801 1802SparkFun_KX132 kxAccel; 1803 1804outputData myData; // Struct for the accelerometer's data 1805 1806void setup() 1807{ 1808 1809 Wire.begin(); 1810 Serial.begin(115200); 1811 1812 // Wait for the Serial monitor to be opened. 1813 while (!Serial) 1814 delay(50); 1815 1816 if (!kxAccel.begin()) 1817 { 1818 Serial.println("Could not communicate with the the KX13X"); 1819 while (1) 1820 ; 1821 } 1822 Serial.println("Ready."); 1823 1824 if (kxAccel.softwareReset()) 1825 Serial.println("Reset."); 1826 1827 // Give some time for the accelerometer to reset. 1828 delay(5); 1829 1830 // Many settings for KX13X can only be 1831 // applied when the accelerometer is powered down. 1832 kxAccel.enableAccel(false); 1833 1834 kxAccel.setRange(SFE_KX132_RANGE16G); // 16g Range 1835 kxAccel.enableDataEngine(); // Enables the bit that indicates data is ready. 1836 kxAccel.enableAccel(); 1837} 1838 1839void loop() 1840{ 1841 // Check if data is ready. 1842 if (kxAccel.dataReady()) 1843 { 1844 kxAccel.getAccelData(&myData); 1845 Serial.print("X: "); 1846 Serial.print(myData.xData, 4); 1847 Serial.print(" Y: "); 1848 Serial.print(myData.yData, 4); 1849 Serial.print(" Z: "); 1850 Serial.print(myData.zData, 4); 1851 Serial.println(); 1852 } 1853 delay(500); 1854}</pre> 1855<p> </p> 1856<h4>Output</h4> 1857<p>When run and the sensor was moved around</p> 1858<p>Welcome.<br /> 1859Ready.<br /> 1860Reset.<br /> 1861X: 0.0005 Y: -0.6676 Z: -0.7608<br /> 1862X: 0.0464 Y: -0.6598 Z: -0.7544<br /> 1863X: 0.0600 Y: -0.6324 Z: -0.8428<br /> 1864X: 0.1459 Y: -0.6759 Z: -0.8589</p> 1865<h3>Links</h3> 1866<p><a href="https://www.kionix.com/product/KX132-1211" target="_blank" rel="noopener">https://www.kionix.com/product/KX132-1211</a></p> 1867</div> 1868</div> 1869<div class="addtoany_share_save_container addtoany_content addtoany_content_bottom"><div class="a2a_kit a2a_kit_size_32 addtoany_list" data-a2a-url="https://www.esp32learning.com/code/connecting-a-kx132-triple-axis-accelerometer-to-an-esp32-board-example.php" data-a2a-title="Connecting a KX132 Triple Axis Accelerometer to an ESP32 board example"><a class="a2a_button_facebook" href="https://www.addtoany.com/add_to/facebook?linkurl=https%3A%2F%2Fwww.esp32learning.com%2Fcode%2Fconnecting-a-kx132-triple-axis-accelerometer-to-an-esp32-board-example.php&linkname=Connecting%20a%20KX132%20Triple%20Axis%20Accelerometer%20to%20an%20ESP32%20board%20example" title="Facebook" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_twitter" href="https://www.addtoany.com/add_to/twitter?linkurl=https%3A%2F%2Fwww.esp32learning.com%2Fcode%2Fconnecting-a-kx132-triple-axis-accelerometer-to-an-esp32-board-example.php&linkname=Connecting%20a%20KX132%20Triple%20Axis%20Accelerometer%20to%20an%20ESP32%20board%20example" title="Twitter" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_threads" href="https://www.addtoany.com/add_to/threads?linkurl=https%3A%2F%2Fwww.esp32learning.com%2Fcode%2Fconnecting-a-kx132-triple-axis-accelerometer-to-an-esp32-board-example.php&linkname=Connecting%20a%20KX132%20Triple%20Axis%20Accelerometer%20to%20an%20ESP32%20board%20example" title="Threads" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_pinterest" href="https://www.addtoany.com/add_to/pinterest?linkurl=https%3A%2F%2Fwww.esp32learning.com%2Fcode%2Fconnecting-a-kx132-triple-axis-accelerometer-to-an-esp32-board-example.php&linkname=Connecting%20a%20KX132%20Triple%20Axis%20Accelerometer%20to%20an%20ESP32%20board%20example" title="Pinterest" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_tumblr" href="https://www.addtoany.com/add_to/tumblr?linkurl=https%3A%2F%2Fwww.esp32learning.com%2Fcode%2Fconnecting-a-kx132-triple-axis-accelerometer-to-an-esp32-board-example.php&linkname=Connecting%20a%20KX132%20Triple%20Axis%20Accelerometer%20to%20an%20ESP32%20board%20example" title="Tumblr" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_reddit" href="https://www.addtoany.com/add_to/reddit?linkurl=https%3A%2F%2Fwww.esp32learning.com%2Fcode%2Fconnecting-a-kx132-triple-axis-accelerometer-to-an-esp32-board-example.php&linkname=Connecting%20a%20KX132%20Triple%20Axis%20Accelerometer%20to%20an%20ESP32%20board%20example" title="Reddit" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_linkedin" href="https://www.addtoany.com/add_to/linkedin?linkurl=https%3A%2F%2Fwww.esp32learning.com%2Fcode%2Fconnecting-a-kx132-triple-axis-accelerometer-to-an-esp32-board-example.php&linkname=Connecting%20a%20KX132%20Triple%20Axis%20Accelerometer%20to%20an%20ESP32%20board%20example" title="LinkedIn" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_digg" href="https://www.addtoany.com/add_to/digg?linkurl=https%3A%2F%2Fwww.esp32learning.com%2Fcode%2Fconnecting-a-kx132-triple-axis-accelerometer-to-an-esp32-board-example.php&linkname=Connecting%20a%20KX132%20Triple%20Axis%20Accelerometer%20to%20an%20ESP32%20board%20example" title="Digg" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_pocket" href="https://www.addtoany.com/add_to/pocket?linkurl=https%3A%2F%2Fwww.esp32learning.com%2Fcode%2Fconnecting-a-kx132-triple-axis-accelerometer-to-an-esp32-board-example.php&linkname=Connecting%20a%20KX132%20Triple%20Axis%20Accelerometer%20to%20an%20ESP32%20board%20example" title="Pocket" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_sina_weibo" href="https://www.addtoany.com/add_to/sina_weibo?linkurl=https%3A%2F%2Fwww.esp32learning.com%2Fcode%2Fconnecting-a-kx132-triple-axis-accelerometer-to-an-esp32-board-example.php&linkname=Connecting%20a%20KX132%20Triple%20Axis%20Accelerometer%20to%20an%20ESP32%20board%20example" title="Sina Weibo" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_wordpress" href="https://www.addtoany.com/add_to/wordpress?linkurl=https%3A%2F%2Fwww.esp32learning.com%2Fcode%2Fconnecting-a-kx132-triple-axis-accelerometer-to-an-esp32-board-example.php&linkname=Connecting%20a%20KX132%20Triple%20Axis%20Accelerometer%20to%20an%20ESP32%20board%20example" title="WordPress" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_blogger" href="https://www.addtoany.com/add_to/blogger?linkurl=https%3A%2F%2Fwww.esp32learning.com%2Fcode%2Fconnecting-a-kx132-triple-axis-accelerometer-to-an-esp32-board-example.php&linkname=Connecting%20a%20KX132%20Triple%20Axis%20Accelerometer%20to%20an%20ESP32%20board%20example" title="Blogger" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_sms" href="https://www.addtoany.com/add_to/sms?linkurl=https%3A%2F%2Fwww.esp32learning.com%2Fcode%2Fconnecting-a-kx132-triple-axis-accelerometer-to-an-esp32-board-example.php&linkname=Connecting%20a%20KX132%20Triple%20Axis%20Accelerometer%20to%20an%20ESP32%20board%20example" title="Message" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_whatsapp" href="https://www.addtoany.com/add_to/whatsapp?linkurl=https%3A%2F%2Fwww.esp32learning.com%2Fcode%2Fconnecting-a-kx132-triple-axis-accelerometer-to-an-esp32-board-example.php&linkname=Connecting%20a%20KX132%20Triple%20Axis%20Accelerometer%20to%20an%20ESP32%20board%20example" title="WhatsApp" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_telegram" href="https://www.addtoany.com/add_to/telegram?linkurl=https%3A%2F%2Fwww.esp32learning.com%2Fcode%2Fconnecting-a-kx132-triple-axis-accelerometer-to-an-esp32-board-example.php&linkname=Connecting%20a%20KX132%20Triple%20Axis%20Accelerometer%20to%20an%20ESP32%20board%20example" title="Telegram" rel="nofollow noopener" target="_blank"></a><a class="a2a_dd addtoany_share_save addtoany_share" href="https://www.addtoany.com/share"></a></div></div> </div> 1870 </div> 1871 1872 <div class="penci-post-box-meta 1873 center-inner "> 1874 <div class="penci-post-share-box"> 1875 <a href="#" class="penci-post-like" aria-label="Like this post" data-post_id="890" title="Like" data-like="Like" data-unlike="Unlike"><i class="penci-faicon fa fa-heart-o" ></i><span class="dt-share">2</span></a> <a class="new-ver-share post-share-item post-share-facebook" aria-label="Share on Facebook" target="_blank" rel="noreferrer" href="https://www.facebook.com/sharer/sharer.php?u=https://www.esp32learning.com/code/connecting-a-kx132-triple-axis-accelerometer-to-an-esp32-board-example.php"><i class="penci-faicon fa fa-facebook" ></i><span class="dt-share">Facebook</span></a><a class="new-ver-share post-share-item post-share-twitter" aria-label="Share on Twitter" target="_blank" rel="noreferrer" href="https://twitter.com/intent/tweet?text=Check%20out%20this%20article:%20Connecting%20a%20KX132%20Triple%20Axis%20Accelerometer%20to%20an%20ESP32%20board%20example%20-%20https://www.esp32learning.com/code/connecting-a-kx132-triple-axis-accelerometer-to-an-esp32-board-example.php"><i class="penci-faicon penciicon-x-twitter" ></i><span class="dt-share">Twitter</span></a><a class="new-ver-share post-share-item post-share-pinterest" aria-label="Pin to Pinterest" data-pin-do="none" rel="noreferrer" target="_blank" href="https://www.pinterest.com/pin/create/button/?url=https%3A%2F%2Fwww.esp32learning.com%2Fcode%2Fconnecting-a-kx132-triple-axis-accelerometer-to-an-esp32-board-example.php&media=https%3A%2F%2Fwww.esp32learning.com%2Fwp-content%2Fuploads%2F2023%2F07%2Fesp32-and-KX13x_bb.png&description=Connecting+a+KX132+Triple+Axis+Accelerometer+to+an+ESP32+board+example"><i class="penci-faicon fa fa-pinterest" ></i><span class="dt-share">Pinterest</span></a><a class="new-ver-share post-share-item post-share-email" target="_blank" aria-label="Share via Email" rel="noreferrer" href="mailto:?subject=Connecting%20a%20KX132%20Triple%20Axis%20Accelerometer%20to%20an%20ESP32%20board%20example&BODY=https://www.esp32learning.com/code/connecting-a-kx132-triple-axis-accelerometer-to-an-esp32-board-example.php"><i class="penci-faicon fa fa-envelope" ></i><span class="dt-share">Email</span></a> </div> 1876 </div> 1877 </div> 1878 1879</article> 1880 1881<article id="post-884" class="standard-article standard-pitem post-884 post type-post status-publish format-standard has-post-thumbnail hentry category-code tag-esp32"> 1882 1883 1884 1885 <div class="standard-post-image"> 1886 <a 1887 href="https://www.esp32learning.com/code/connecting-a-stts22h-temperature-sensor-to-an-esp32-example.php"> 1888 <img 1889 class="attachment-penci-full-thumb size-penci-full-thumb penci-lazy wp-post-image" 1890 width="660" 1891 height="861" 1892 src="data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%20660%20861'%3E%3C/svg%3E" alt="esp32 and STTS22H_bb" title="esp32 and STTS22H_bb" data-src="https://www.esp32learning.com/wp-content/uploads/2023/07/esp32-and-STTS22H_bb.png"> </a> 1893 </div> 1894 1895 1896 <div class="header-standard 1897 "> 1898 <div class="penci-standard-cat"><span class="cat"><a style="" class="penci-cat-name penci-cat-14" href="https://www.esp32learning.com/category/code" rel="category tag"><span style="">Code</span></a></span></div> 1899 1900 <h2 class="penci-entry-title entry-title entry-title"><a 1901 href="https://www.esp32learning.com/code/connecting-a-stts22h-temperature-sensor-to-an-esp32-example.php">Connecting a STTS22H temperature sensor to an ESP32 example</a></h2> 1902 <div class="penci-hide-tagupdated"> 1903 <span class="author-italic author vcard">by <a class="author-url url fn n" 1904 href="https://www.esp32learning.com/author/shedboy71">shedboy71</a> 1905 </span> 1906 <time class="entry-date published" datetime="2023-08-19T21:40:54+01:00">19th August 2023</time> </div> 1907 </div> 1908 1909 <div class="standard-content"> 1910 <div class="standard-main-content entry-content"> 1911 <div class="post-entry standard-post-entry classic-post-entry blockquote-style-1 "> 1912 <p>
1912In this article we look at a temperature sensor, the STTS22H sensor from ST and connect it to an ESP32 board</p> 1913<h3>Sensor Information</h3> 1914<p>The STTS22H is an ultralow-power, high-accuracy, digital temperature sensor offering high performance over the entire operating temperature range.</p> 1915<p>The STTS22H Temperature Sensor is an ultralow-power, high-accuracy, digital temperature sensor from ST Microelectronics and is housed in our standard Qwiic form factor. Thanks to its factory calibration the STTS22H offers high-end accuracy performance over the entire operating temperature range, reaching as low as ±0.5°C without requiring any further calibration at the application level.</p> 1916<p>The sensor operating mode is user-configurable and allows selecting between different ODRs (down to 1Hz) or the one-shot mode for battery saving. In one-shot mode, the sensor current consumption falls to 1.75µA. Peripheral addresses are also user-configurable and allow up to four different addresses to be specified by manipulating the jumpers on the back of the breakout. In addition, an interrupt pin is available to signal the application whenever the user-selectable high or low threshold has been exceeded.</p> 1917<h3>Features</h3> 1918<ul> 1919<li>Uses I<sup>2</sup>C interface (Qwiic-enabled)</li> 1920<li>Four selectable addresses 1921<ul> 1922<li><strong>0x3C (default)</strong>, 0x3E, 0x38, 0x3F</li> 1923</ul> 1924</li> 1925<li>Operating temperature: -40°C to +125°C</li> 1926<li>Temperature accuracy (max): ± 0.5°C (-10°C to +60°C)</li> 1927<li>Operating voltage: 1.5V to 3.6V 1928<ul> 1929<li>Typically <strong>3.3V</strong> if using the Qwiic cable</li> 1930</ul> 1931</li> 1932<li>Ultralow current: 1.75µA in one-shot mode</li> 1933<li>Programmable thresholds with interrupt pin</li> 1934<li>Programmable operating modes 1935<ul> 1936<li>Freerun, one-shot, and Low-ODR</li> 1937</ul> 1938</li> 1939<li>NIST traceability</li> 1940<li></li> 1941</ul> 1942<div class="product-feature-category" data-module-component="product-features"> 1943<div class="feature-category-label-column"> 1944<h3>Parts Required</h3> 1945<p>You can connect to the sensor using DuPont-style jumper wire.</p> 1946<p>I use an ESP32 board from Wemos, the Lolin32 – it should work with any ESP32 board</p> 1947<p> </p> 1948<div class="pcrstb-wrap"><table> 1949<tbody> 1950<tr style="height: 21px;"> 1951<td style="width: 15.8442%; height: 21px;"><strong>Name</strong></td> 1952<td style="width: 40.1299%; height: 21px;"><strong>Link</strong></td> 1953<td style="width: 44.4156%;"></td> 1954</tr> 1955<tr style="height: 55px;"> 1956<td style="width: 15.8442%; height: 55px;">ESP32</td> 1957<td style="width: 40.1299%;"><a href="https://s.click.aliexpress.com/e/_DkIPPqt" target="_blank" rel="noopener"><img decoding="async" src="//ae01.alicdn.com/kf/Sbf885b40323a45178795fde862d61c3cT.jpg_140x140.jpg"" /></a></td> 1958<td style="width: 44.4156%; height: 55px;"> 1959<ul> 1960<li><a href="https://s.click.aliexpress.com/e/_DdKOnXT" target="_blank" rel="noopener">Aliexpress link</a></li> 1961<li><a href="https://www.amazon.com/s?k=ESP32%22&camp=1789&creative=9325&linkCode=ur2&linkId=cac24da38498a0be29dcff978e974b54&tag=basicvisualbasic" target="_blank" rel="noopener">Amazon</a></li> 1962<li><a href="https://www.ebay.com/sch/i.html?_from=R40&_trksid=p2334524.m570.l1313&_nkw=ESP32&_sacat=0&_odkw=ESP32&_osacat=0&mkcid=1&mkrid=711-53200-19255-0&siteid=0&campid=5338725476&customid=&toolid=10001&mkevt=1" target="_blank" rel="noopener">Ebay</a></li> 1963</ul> 1964</td> 1965</tr> 1966<tr style="height: 55px;"> 1967<td style="width: 15.8442%; height: 55px;">STTS22H</td> 1968<td style="width: 40.1299%;"></td> 1969<td style="width: 44.4156%; height: 55px;"> </p> 1970<ul> 1971<li><a href="https://www.amazon.com/s?k=STTS22H%22&camp=1789&creative=9325&linkCode=ur2&linkId=cac24da38498a0be29dcff978e974b54&tag=basicvisualbasic" target="_blank" rel="noopener">Amazon Link</a></li> 1972</ul> 1973</td> 1974</tr> 1975<tr style="height: 21px;"> 1976<td style="width: 15.8442%; height: 21px;">Connecting cables</td> 1977<td style="width: 40.1299%;"><img decoding="async" class="alignnone size-thumbnail wp-image-13" src="http://www.arduinocode.com/wp-content/uploads/2023/07/dupont-150x150.jpg" alt="" width="150" height="150" /></td> 1978<td style="width: 44.4156%; height: 21px;"> 1979<ul> 1980<li><a href="https://s.click.aliexpress.com/e/_Dnk1xwF" target="_blank" rel="noopener">Aliexpress link</a></li> 1981<li><a href="https://www.amazon.com/s?k=dupont+cables%22&camp=1789&creative=9325&linkCode=ur2&linkId=cac24da38498a0be29dcff978e974b54&tag=basicvisualbasic" target="_blank" rel="noopener">Amazon</a></li> 1982<li><a href="https://www.ebay.com/sch/i.html?_from=R40&_trksid=p2334524.m570.l1313&_nkw=dupont+cables&_sacat=0&_odkw=dupont+cables&_osacat=0&mkcid=1&mkrid=711-53200-19255-0&siteid=0&campid=5338725476&
1982customid=&toolid=10001&mkevt=1" target="_blank" rel="noopener">Ebay</a></li> 1983</ul> 1984</td> 1985</tr> 1986</tbody> 1987</table></div> 1988<p> </p> 1989<h3>Schematic/Connection</h3> 1990<p>I used 3.3v from the ESP32 board</p> 1991<p>I also used a Qwiic cable, but if you do not have one, there is an unpopulated set of pins you can solder a header to. This is how you would wire this up</p> 1992<div id="attachment_886" style="width: 670px" class="wp-caption alignnone"><img decoding="async" aria-describedby="caption-attachment-886" class="size-full wp-image-886" src="https://www.esp32learning.com/wp-content/uploads/2023/07/esp32-and-STTS22H_bb.png" alt="esp32 and STTS22H_bb" width="660" height="861" srcset="https://www.esp32learning.com/wp-content/uploads/2023/07/esp32-and-STTS22H_bb.png 660w, https://www.esp32learning.com/wp-content/uploads/2023/07/esp32-and-STTS22H_bb-230x300.png 230w" sizes="(max-width: 660px) 100vw, 660px" /><p id="caption-attachment-886" class="wp-caption-text">esp32 and STTS22H_bb</p></div> 1993<p> </p> 1994<h3>Code Example</h3> 1995<p>I installed the Sparkfun library using the Arduino ide</p> 1996<p>Click the <strong>Manage Libraries …</strong> menu item, search for STTS22H, and select the Sparkfun STTS22H library like this</p> 1997</div> 1998<p>This is one of the examples that gets installed with the library, with a few comments and unused lines removed.</p> 1999<pre class="EnlighterJSRAW" data-enlighter-language="cpp">#include <Wire.h> 2000#include "SparkFun_STTS22H.h" 2001 2002SparkFun_STTS22H mySTTS; 2003 2004float temp; 2005 2006void setup() 2007{ 2008 2009 Wire.begin(); 2010 2011 Serial.begin(115200); 2012 2013 if( !mySTTS.begin() ) 2014 { 2015 Serial.println("Did not begin."); 2016 while(1); 2017 } 2018 2019 Serial.println("Ready"); 2020 2021 // Other output data rates can be found in the description 2022 // above. To change the ODR or mode, the device must first be 2023 // powered down. 2024 mySTTS.setDataRate(STTS22H_POWER_DOWN); 2025 delay(10); 2026 mySTTS.setDataRate(STTS22H_1Hz); 2027 2028 // Enables incrementing register behavior for the IC. 2029 // It is not enabled by default as the datsheet states and 2030 // is vital for reading the two temperature registers. 2031 mySTTS.enableAutoIncrement(); 2032 2033 delay(100); 2034} 2035 2036void loop() 2037{ 2038 2039 // Only use data ready for one-shot mode or 1Hz output. 2040 if( mySTTS.dataReady() ) 2041 { 2042 // Temperature in different units can be retrieved 2043 // using the following functions. 2044 //mySTTS.getTemperatureC(&temp); 2045 mySTTS.getTemperatureK(&temp); 2046 Serial.print("Temp: "); 2047 Serial.print(temp); 2048 Serial.println("F"); 2049 } 2050 delay(1000); 2051 2052}</pre> 2053<p> </p> 2054<h2>Output</h2> 2055<div class="feature-category-label-column"> 2056<p>When run you will see something like this in the serial monitor window</p> 2057<p>Temp: 68.68F<br /> 2058Temp: 68.67F<br /> 2059Temp: 68.74F<br /> 2060Temp: 68.70F<br /> 2061Temp: 68.72F<br /> 2062Temp: 68.72F</p> 2063<p> </p> 2064<h3>Links</h3> 2065<p><a href="https://www.st.com/resource/en/datasheet/stts22h.pdf" target="_blank" rel="noopener">https://www.st.com/resource/en/datasheet/stts22h.pdf</a></p> 2066</div> 2067</div> 2068<div class="addtoany_share_save_container addtoany_content addtoany_content_bottom"><div class="a2a_kit a2a_kit_size_32 addtoany_list" data-a2a-url="https://www.esp32learning.com/code/connecting-a-stts22h-temperature-sensor-to-an-esp32-example.php" data-a2a-title="Connecting a STTS22H temperature sensor to an ESP32 example"><a class="a2a_button_facebook" href="https://www.addtoany.com/add_to/facebook?linkurl=https%3A%2F%2Fwww.esp32learning.com%2Fcode%2Fconnecting-a-stts22h-temperature-sensor-to-an-esp32-example.php&linkname=Connecting%20a%20STTS22H%20temperature%20sensor%20to%20an%20ESP32%20example" title="Facebook" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_twitter" href="https://www.addtoany.com/add_to/twitter?linkurl=https%3A%2F%2Fwww.esp32learning.com%2Fcode%2Fconnecting-a-stts22h-temperature-sensor-to-an-esp32-example.php&linkname=Connecting%20a%20STTS22H%20temperature%20sensor%20to%20an%20ESP32%20example" title="Twitter" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_threads" href="https://www.addtoany.com/add_to/threads?linkurl=https%3A%2F%2Fwww.esp32learning.com%2Fcode%2Fconnecting-a-stts22h-temperature-sensor-to-an-esp32-example.php&linkname=Connecting%20a%20STTS22H%20temperature%20sensor%20to%20an%20ESP32%20example" title="Threads" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_pinterest" href="https://www.addtoany.com/add_to/pinterest?linkurl=https%3A%2F%2Fwww.esp32learning.com%2Fcode%2Fconnecting-a-stts22h-temperature-sensor-to-an-esp32-example.php&linkname=Connecting%20a%20STTS22H%20temperature%20sensor%20to%20an%20ESP32%20example" title="Pinterest" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_tumblr" href="https://www.addtoany.com/add_to/tumblr?linkurl=https%3A%2F%2Fwww.esp32learning.com%2Fcode%2Fconnecting-a-stts22h-temperature-sensor-to-an-esp32-example.php&linkname=Connecting%20a%20STTS22H%20temperature%20sensor%20to%20an%20ESP32%20example" title="Tumblr" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_reddit" href="https://www.addtoany.com/add_to/reddit?linkurl=https%3A%2F%2Fwww.esp32learning.com%2Fcode%2Fconnecting-a-stts22h-temperature-sensor-to-an-esp32-example.php&linkname=Connecting%20a%20STTS22H%20temperature%20sensor%20to%20an%20ESP32%20example" title="Reddit" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_linkedin" href="https://www.addtoany.com/add_to/linkedin?linkurl=https%3A%2F%2Fwww.esp32learning.com%2Fcode%2Fconnecting-a-stts22h-temperature-sensor-to-an-esp32-example.php&linkname=Connecting%20a%20STTS22H%20temperature%20sensor%20to%20an%20ESP32%20example" title="LinkedIn" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_digg" href="https://www.addtoany.com/add_to/digg?linkurl=https%3A%2F%2Fwww.esp32learning.com%2Fcode%2Fconnecting-a-stts22h-temperature-sensor-to-an-esp32-example.php&linkname=Connecting%20a%20STTS22H%20temperature%20sensor%20to%20an%20ESP32%20example" title="Digg" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_pocket" href="https://www.addtoany.com/add_to/pocket?linkurl=https%3A%2F%2Fwww.esp32learning.com%2Fcode%2Fconnecting-a-stts22h-temperature-sensor-to-an-esp32-example.php&linkname=Connecting%20a%20STTS22H%20temperature%20sensor%20to%20an%20ESP32%20example" title="Pocket" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_sina_weibo" href="https://www.addtoany.com/add_to/sina_weibo?linkurl=https%3A%2F%2Fwww.esp32learning.com%2Fcode%2Fconnecting-a-stts22h-temperature-sensor-to-an-esp32-example.php&linkname=Connecting%20a%20STTS22H%20temperature%20sensor%20to%20an%20ESP32%20example" title="Sina Weibo" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_wordpress" href="https://www.addtoany.com/add_to/wordpress?linkurl=https%3A%2F%2Fwww.esp32learning.com%2Fcode%2Fconnecting-a-stts22h-temperature-sensor-to-an-esp32-example.php&linkname=Connecting%20a%20STTS22H%20temperature%20sensor%20to%20an%20ESP32%20example" title="WordPress" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_blogger" href="https://www.addtoany.com/add_to/blogger?linkurl=https%3A%2F%2Fwww.esp32learning.com%2Fcode%2Fconnecting-a-stts22h-temperature-sensor-to-an-esp32-example.php&linkname=Connecting%20a%20STTS22H%20temperature%20sensor%20to%20an%20ESP32%20example" title="Blogger" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_sms" href="https://www.addtoany.com/add_to/sms?linkurl=https%3A%2F%2Fwww.esp32learning.com%2Fcode%2Fconnecting-a-stts22h-temperature-sensor-to-an-esp32-example.php&linkname=Connecting%20a%20STTS22H%20temperature%20sensor%20to%20an%20ESP32%20example" title="Message" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_whatsapp" href="https://www.addtoany.com/add_to/whatsapp?linkurl=https%3A%2F%2Fwww.esp32learning.com%2Fcode%2Fconnecting-a-stts22h-temperature-sensor-to-an-esp32-example.php&linkname=Connecting%20a%20STTS22H%20temperature%20sensor%20to%20an%20ESP32%20example" title="WhatsApp" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_telegram" href="https://www.addtoany.com/add_to/telegram?linkurl=https%3A%2F%2Fwww.esp32learning.com%2Fcode%2Fconnecting-a-stts22h-temperature-sensor-to-an-esp32-example.php&linkname=Connecting%20a%20STTS22H%20temperature%20sensor%20to%20an%20ESP32%20example" title="Telegram" rel="nofollow noopener" target="_blank"></a><a class="a2a_dd addtoany_share_save addtoany_share" href="https://www.addtoany.com/share"></a></div></div> </div> 2069 </div> 2070 2071 <div class="penci-post-box-meta 2072 center-inner "> 2073 <div class="penci-post-share-box"> 2074 <a href="#" class="penci-post-like" aria-label="Like this post" data-post_id="884" title="Like" data-like="Like" data-unlike="Unlike"><i class="penci-faicon fa fa-heart-o" ></i><span class="dt-share">2</span></a> <a class="new-ver-share post-share-item post-share-facebook" aria-label="Share on Facebook" target="_blank" rel="noreferrer" href="https://www.facebook.com/sharer/sharer.php?u=https://www.esp32learning.com/code/connecting-a-stts22h-temperature-sensor-to-an-esp32-example.php"><i class="penci-faicon fa fa-facebook" ></i><span class="dt-share">Facebook</span></a><a class="new-ver-share post-share-item post-share-twitter" aria-label="Share on Twitter" target="_blank" rel="noreferrer" href="https://twitter.com/intent/tweet?text=Check%20out%20this%20article:%20Connecting%20a%20STTS22H%20temperature%20sensor%20to%20an%20ESP32%20example%20-%20https://www.esp32learning.com/code/connecting-a-stts22h-temperature-sensor-to-an-esp32-example.php"><i class="penci-faicon penciicon-x-twitter" ></i><span class="dt-share">Twitter</span></a><a class="new-ver-share post-share-item post-share-pinterest" aria-label="Pin to Pinterest" data-pin-do="none" rel="noreferrer" target="_blank" href="https://www.pinterest.com/pin/create/button/?url=https%3A%2F%2Fwww.esp32learning.com%2Fcode%2Fconnecting-a-stts22h-temperature-sensor-to-an-esp32-example.php&media=https%3A%2F%2Fwww.esp32learning.com%2Fwp-content%2Fuploads%2F2023%2F07%2Fesp32-and-STTS22H_bb.png&description=Connecting+a+STTS22H+temperature+sensor+to+an+ESP32+example"><i class="penci-faicon fa fa-pinterest" ></i><span class="dt-share">Pinterest</span></a><a class="new-ver-share post-share-item post-share-email" target="_blank" aria-label="Share via Email" rel="noreferrer" href="mailto:?subject=Connecting%20a%20STTS22H%20temperature%20sensor%20to%20an%20ESP32%20example&BODY=https://www.esp32learning.com/code/connecting-a-stts22h-temperature-sensor-to-an-esp32-example.php"><i class="penci-faicon fa fa-envelope" ></i><span class="dt-share">Email</span></a> </div> 2075 </div> 2076 </div> 2077 2078</article> 2079 2080<article id="post-906" class="standard-article standard-pitem post-906 post type-post status-publish format-standard has-post-thumbnail hentry category-code tag-mmc5603"> 2081 2082 2083 2084 <div class="standard-post-image"> 2085 <a 2086 href="https://www.esp32learning.com/code/connect-a-mmc5603-triple-axis-magnetometer-to-an-esp32.php"> 2087 <img 2088 class="attachment-penci-full-thumb size-penci-full-thumb penci-lazy wp-post-image" 2089 width="732" 2090 height="789" 2091 src="data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%20732%20789'%3E%3C/svg%3E" alt="" title="esp32 and MMC5603_bb" data-src="https://www.esp32learning.com/wp-content/uploads/2023/07/esp32-and-MMC5603_bb.png"> </a> 2092 </div> 2093 2094 2095 <div class="header-standard 2096 "> 2097 <div class="penci-standard-cat"><span class="cat"><a style="" class="penci-cat-name penci-cat-14" href="https://www.esp32learning.com/category/code" rel="category tag"><span style="">Code</span></a></span></div> 2098 2099 <h2 class="penci-entry-title entry-title entry-title"><a 2100 href="https://www.esp32learning.com/code/connect-a-mmc5603-triple-axis-magnetometer-to-an-esp32.php">Connect a MMC5603 Triple-axis Magnetometer to an ESP32</a></h2> 2101 <div class="penci-hide-tagupdated"> 2102 <span class="author-italic author vcard">by <a class="author-url url fn n" 2103 href="https://www.esp32learning.com/author/shedboy71">shedboy71</a> 2104 </span> 2105 <time class="entry-date published" datetime="2023-07-20T10:06:37+01:00">20th July 2023</time> </div> 2106 </div> 2107 2108 <div class="standard-content"> 2109 <div class="standard-main-content entry-content"> 2110 <div class="post-entry standard-post-entry classic-post-entry blockquote-style-1 "> 2111 <p>
2111In this article, we look at a Triple-axis Magnetometer, the MMC5603, and connect it to an ESP32 board</p> 2112<h3>Sensor Information</h3> 2113<p>This sensor can sense ranges from ±30 Gauss (±3000uT or ±3mT) with no range-setting required and full 20-bit output up to 1000 Hz rate reading. The range makes it good for reading Earth’s magnetic field (which maxes at about 0.6 Gauss) or some basic magnets. It isn’t good for very strong rare earth magnets</p> 2114<p>I bought an Adafruit breakout board, so the MMC5603 comes integrated with a voltage regulator and level-shifting circuitry to allow it to be used with 3.3V devices or 5V devices.</p> 2115<p>Along with a header, there is a SparkFun Qwiic compatible STEMMA QT connectors for the I2C bus so you just need to fit a suitable cable</p> 2116<h3>Features</h3> 2117<ul> 2118<li style="list-style-type: none;"> 2119<ul> 2120<li>Superior Dynamic Range and Accuracy:<br /> 2121±30 G FSR</li> 2122<li>20bits operation mode</li> 2123<li>0.0625mG per LSB resolution</li> 2124<li>2 mG total RMS noise</li> 2125<li>Enables heading accuracy of 1º</li> 2126</ul> 2127</li> 2128</ul> 2129<p>Sensor true frequency response up to 1KHz<br /> 2130On-chip automatic degaussing with built-in SET/RESET function</p> 2131<ul> 2132<li style="list-style-type: none;"> 2133<ul> 2134<li>Eliminates thermal variation-induced offset error (Null field output)</li> 2135<li>Clears the residual magnetization resulting</li> 2136</ul> 2137</li> 2138</ul> 2139<p>from strong external fields<br /> 2140On-chip sensitivity compensation<br /> 2141On-chip temperature sensor<br /> 2142Selftest signal available<br /> 2143Data_ready Interrupt (I3C only)<br /> 2144Low power consumption<br /> 21451 µA power down current<br /> 2146I2C slave, FAST (≤400 KHz) mode<br /> 2147I3C interface available<br /> 21481.62V to 3.6V</p> 2149<div class="product-feature-category" data-module-component="product-features"> 2150<div class="feature-category-label-column"> 2151<h3>Parts Required</h3> 2152<p>You can connect to the sensor using Dupont style jumper wire.</p> 2153<p> </p> 2154<div class="pcrstb-wrap"><table> 2155<tbody> 2156<tr style="height: 21px;"> 2157<td style="width: 15.8442%; height: 21px;"><strong>Name</strong></td> 2158<td style="width: 40.1299%; height: 21px;"><strong>Link</strong></td> 2159<td style="width: 44.4156%;"></td> 2160</tr> 2161<tr style="height: 55px;"> 2162<td style="width: 15.8442%; height: 55px;">ESP32</td> 2163<td style="width: 40.1299%;"><a href="https://s.click.aliexpress.com/e/_DkIPPqt" target="_blank" rel="noopener"><img decoding="async" src="//ae01.alicdn.com/kf/Sbf885b40323a45178795fde862d61c3cT.jpg_140x140.jpg"" /></a></td> 2164<td style="width: 44.4156%; height: 55px;"> 2165<ul> 2166<li><a href="https://s.click.aliexpress.com/e/_DdKOnXT" target="_blank" rel="noopener">Aliexpress link</a></li> 2167<li><a href="https://www.amazon.com/s?k=ESP32%22&camp=1789&creative=9325&linkCode=ur2&linkId=cac24da38498a0be29dcff978e974b54&tag=basicvisualbasic" target="_blank" rel="noopener">Amazon</a></li> 2168<li><a href="https://www.ebay.com/sch/i.html?_from=R40&_trksid=p2334524.m570.l1313&_nkw=ESP32&_sacat=0&_odkw=ESP32&_osacat=0&mkcid=1&mkrid=711-53200-19255-0&siteid=0&campid=5338725476&customid=&toolid=10001&mkevt=1" target="_blank" rel="noopener">Ebay</a></li> 2169</ul> 2170</td> 2171</tr> 2172<tr style="height: 55px;"> 2173<td style="width: 15.8442%; height: 55px;">MMC5603</td> 2174<td style="width: 40.1299%;"></td> 2175<td style="width: 44.4156%; height: 55px;"> 2176<ul> 2177<li><a href="https://s.click.aliexpress.com/e/_DFDBRb3" target="_blank" rel="noopener">Aliexpress link</a></li> 2178<li><a href="https://www.ebay.com/sch/i.html?_from=R40&_trksid=p2334524.m570.l1313&_nkw=MMC5603&_sacat=0&_odkw=MMC5603&_osacat=0&mkcid=1&mkrid=711-53200-19255-0&siteid=0&campid=5338725476&customid=&toolid=10001&mkevt=1" target="_blank" rel="noopener">ebay link</a></li> 2179</ul> 2180</td> 2181</tr> 2182<tr style="height: 21px;"> 2183<td style="width: 15.8442%; height: 21px;">Connecting cables</td> 2184<td style="width: 40.1299%;"><img decoding="async" class="alignnone size-thumbnail wp-image-13" src="http://www.arduinocode.com/wp-content/uploads/2023/07/dupont-150x150.jpg" alt="" width="150" height="150" /></td> 2185<td style="width: 44.4156%; height: 21px;"> 2186<ul> 2187<li><a href="https://s.click.aliexpress.com/e/_Dnk1xwF" target="_blank" rel="noopener">Aliexpress link</a></li> 2188<li><a href="https://www.amazon.com/s?k=dupont+cables%22&camp=1789&creative=9325&linkCode=ur2&linkId=cac24da38498a0be29dcff978e974b54&tag=basicvisualbasic" target="_blank" rel="noopener">Amazon</a></li> 2189<li><a href="https://www.ebay.com/sch/i.html?_from=R40&_trksid=p2334524.m570.l1313&_nkw=dupont+cables&_sacat=0&_odkw=dupont+cables&_osacat=0&mkcid=1&mkrid=711-53200-19255-0&siteid=0&campid=5338725476&
2189customid=&toolid=10001&mkevt=1" target="_blank" rel="noopener">Ebay</a></li> 2190</ul> 2191</td> 2192</tr> 2193</tbody> 2194</table></div> 2195<p> </p> 2196<h3>Schematic/Connection</h3> 2197<p>I used 3.3v from the ESP32 – and I also use the stemma/qwic connector</p> 2198<p><img decoding="async" class="alignnone size-full wp-image-908" src="https://www.esp32learning.com/wp-content/uploads/2023/07/esp32-and-MMC5603_bb.png" alt="" width="732" height="789" srcset="https://www.esp32learning.com/wp-content/uploads/2023/07/esp32-and-MMC5603_bb.png 732w, https://www.esp32learning.com/wp-content/uploads/2023/07/esp32-and-MMC5603_bb-278x300.png 278w" sizes="(max-width: 732px) 100vw, 732px" /></p> 2199<h3>Code Example</h3> 2200<p>I installed the Adafruit library using the Arduino ide which also installed the dependency library</p> 2201<p>Click the <strong>Manage Libraries …</strong> menu item, search for MMC56x3, and select the Adafruit_MMC56x3 library</p> 2202<p>If asked about dependencies, click on the “Install all” option</p> 2203<p>If the Dependencies window does appear, you already have the required dependencies installed.</p> 2204<p>If the dependencies are already installed, make sure that you have the latest ones installed using the Arduino Library Manager</p> 2205<p>This is the magsensor example – there are a few examples</p> 2206<pre class="EnlighterJSRAW" data-enlighter-language="cpp">#include <Adafruit_MMC56x3.h> 2207 2208/* Assign a unique ID to this sensor at the same time */ 2209Adafruit_MMC5603 mmc = Adafruit_MMC5603(12345); 2210 2211void setup(void) { 2212 Serial.begin(115200); 2213 while (!Serial) 2214 delay(10); // will pause Zero, Leonardo, etc until serial console opens 2215 2216 Serial.println("Adafruit_MMC5603 Magnetometer Test"); 2217 Serial.println(""); 2218 2219 /* Initialise the sensor */ 2220 if (!mmc.begin(MMC56X3_DEFAULT_ADDRESS, &Wire)) { // I2C mode 2221 /* There was a problem detecting the MMC5603 ... check your connections */ 2222 Serial.println("Ooops, no MMC5603 detected ... Check your wiring!"); 2223 while (1) delay(10); 2224 } 2225 2226 /* Display some basic information on this sensor */ 2227 mmc.printSensorDetails(); 2228} 2229 2230void loop(void) { 2231 // Get a new sensor event 2232 sensors_event_t event; 2233 mmc.getEvent(&event); 2234 2235 // Display the results (magnetic vector values are in micro-Tesla (uT)) 2236 Serial.print("X: "); 2237 Serial.print(event.magnetic.x); 2238 Serial.print(" "); 2239 Serial.print("Y: "); 2240 Serial.print(event.magnetic.y); 2241 Serial.print(" "); 2242 Serial.print("Z: "); 2243 Serial.print(event.magnetic.z); 2244 Serial.print(" "); 2245 Serial.println("uT"); 2246 2247 // Read and display temperature 2248 float temp_c = mmc.readTemperature(); 2249 Serial.print("Temp: "); 2250 Serial.print(temp_c); 2251 Serial.println(" *C"); 2252 // Delay before the next sample 2253 delay(1000); 2254}</pre> 2255<h4></h4> 2256<p>Here is an example of what I saw in the serial monitor window – you may see some different results</p> 2257<p>X: -3276.80 Y: -3276.80 Z: -3276.80 uT<br /> 2258Temp: 21.00 *C<br /> 2259X: -3276.80 Y: -3276.80 Z: -3276.80 uT<br /> 2260Temp: 25.00 *C<br /> 2261X: -3276.80 Y: -3276.80 Z: -3276.80 uT<br /> 2262Temp: 25.80 *C</p> 2263<p>This is the compass example – this would be good with one of those round LCD displays – a clue to a future project</p> 2264<pre class="EnlighterJSRAW" data-enlighter-language="cpp">#include <Adafruit_MMC56x3.h> 2265 2266/* Assign a unique ID to this sensor at the same time */ 2267Adafruit_MMC5603 mag = Adafruit_MMC5603(12345); 2268 2269void setup(void) { 2270 Serial.begin(115200); 2271 while (!Serial) 2272 delay(10); // will pause Zero, Leonardo, etc until serial console opens 2273 2274 Serial.println("Adafruit_MMC5603 Magnetometer Compass"); 2275 Serial.println(""); 2276 2277 /* Initialise the sensor */ 2278 if (!mag.begin(MMC56X3_DEFAULT_ADDRESS, &Wire)) { // I2C mode 2279 /* There was a problem detecting the MMC5603 ... check your connections */ 2280 Serial.println("Ooops, no MMC5603 detected ... Check your wiring!"); 2281 while (1) delay(10); 2282 } 2283} 2284 2285void loop(void) 2286{ 2287 /* Get a new sensor event */ 2288 sensors_event_t event; 2289 mag.getEvent(&event); 2290 2291 float Pi = 3.14159; 2292 2293 // Calculate the angle of the vector y,x 2294 float heading = (atan2(event.magnetic.y,event.magnetic.x) * 180) / Pi; 2295 2296 // Normalize to 0-360 2297 if (heading < 0) 2298 { 2299 heading = 360 + heading; 2300 } 2301 Serial.print("Compass Heading: "); 2302 Serial.println(heading); 2303 delay(500); 2304}</pre> 2305<p>The output of this example was this, I moved the sensor around</p> 2306<p>Compass Heading: 279.68<br /> 2307Compass Heading: 313.03<br /> 2308Compass Heading: 290.95<br /> 2309Compass Heading: 344.84<br /> 2310Compass Heading: 294.77</p> 2311<h3>Links</h3> 2312<p><a href="https://media.digikey.com/pdf/Data%20Sheets/MEMSIC%20PDFs/MMC5603NJ_RevB_7-12-18.pdf" target="_blank" rel="noopener">https://media.digikey.com/pdf/Data%20Sheets/MEMSIC%20PDFs/MMC5603NJ_RevB_7-12-18.pdf</a></p> 2313</div> 2314</div> 2315<div class="addtoany_share_save_container addtoany_content addtoany_content_bottom"><div class="a2a_kit a2a_kit_size_32 addtoany_list" data-a2a-url="https://www.esp32learning.com/code/connect-a-mmc5603-triple-axis-magnetometer-to-an-esp32.php" data-a2a-title="Connect a MMC5603 Triple-axis Magnetometer to an ESP32"><a class="a2a_button_facebook" href="https://www.addtoany.com/add_to/facebook?linkurl=https%3A%2F%2Fwww.esp32learning.com%2Fcode%2Fconnect-a-mmc5603-triple-axis-magnetometer-to-an-esp32.php&linkname=Connect%20a%20MMC5603%20Triple-axis%20Magnetometer%20to%20an%20ESP32" title="Facebook" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_twitter" href="https://www.addtoany.com/add_to/twitter?linkurl=https%3A%2F%2Fwww.esp32learning.com%2Fcode%2Fconnect-a-mmc5603-triple-axis-magnetometer-to-an-esp32.php&linkname=Connect%20a%20MMC5603%20Triple-axis%20Magnetometer%20to%20an%20ESP32" title="Twitter" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_threads" href="https://www.addtoany.com/add_to/threads?linkurl=https%3A%2F%2Fwww.esp32learning.com%2Fcode%2Fconnect-a-mmc5603-triple-axis-magnetometer-to-an-esp32.php&linkname=Connect%20a%20MMC5603%20Triple-axis%20Magnetometer%20to%20an%20ESP32" title="Threads" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_pinterest" href="https://www.addtoany.com/add_to/pinterest?linkurl=https%3A%2F%2Fwww.esp32learning.com%2Fcode%2Fconnect-a-mmc5603-triple-axis-magnetometer-to-an-esp32.php&linkname=Connect%20a%20MMC5603%20Triple-axis%20Magnetometer%20to%20an%20ESP32" title="Pinterest" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_tumblr" href="https://www.addtoany.com/add_to/tumblr?linkurl=https%3A%2F%2Fwww.esp32learning.com%2Fcode%2Fconnect-a-mmc5603-triple-axis-magnetometer-to-an-esp32.php&linkname=Connect%20a%20MMC5603%20Triple-axis%20Magnetometer%20to%20an%20ESP32" title="Tumblr" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_reddit" href="https://www.addtoany.com/add_to/reddit?linkurl=https%3A%2F%2Fwww.esp32learning.com%2Fcode%2Fconnect-a-mmc5603-triple-axis-magnetometer-to-an-esp32.php&linkname=Connect%20a%20MMC5603%20Triple-axis%20Magnetometer%20to%20an%20ESP32" title="Reddit" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_linkedin" href="https://www.addtoany.com/add_to/linkedin?linkurl=https%3A%2F%2Fwww.esp32learning.com%2Fcode%2Fconnect-a-mmc5603-triple-axis-magnetometer-to-an-esp32.php&linkname=Connect%20a%20MMC5603%20Triple-axis%20Magnetometer%20to%20an%20ESP32" title="LinkedIn" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_digg" href="https://www.addtoany.com/add_to/digg?linkurl=https%3A%2F%2Fwww.esp32learning.com%2Fcode%2Fconnect-a-mmc5603-triple-axis-magnetometer-to-an-esp32.php&linkname=Connect%20a%20MMC5603%20Triple-axis%20Magnetometer%20to%20an%20ESP32" title="Digg" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_pocket" href="https://www.addtoany.com/add_to/pocket?linkurl=https%3A%2F%2Fwww.esp32learning.com%2Fcode%2Fconnect-a-mmc5603-triple-axis-magnetometer-to-an-esp32.php&linkname=Connect%20a%20MMC5603%20Triple-axis%20Magnetometer%20to%20an%20ESP32" title="Pocket" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_sina_weibo" href="https://www.addtoany.com/add_to/sina_weibo?linkurl=https%3A%2F%2Fwww.esp32learning.com%2Fcode%2Fconnect-a-mmc5603-triple-axis-magnetometer-to-an-esp32.php&linkname=Connect%20a%20MMC5603%20Triple-axis%20Magnetometer%20to%20an%20ESP32" title="Sina Weibo" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_wordpress" href="https://www.addtoany.com/add_to/wordpress?linkurl=https%3A%2F%2Fwww.esp32learning.com%2Fcode%2Fconnect-a-mmc5603-triple-axis-magnetometer-to-an-esp32.php&linkname=Connect%20a%20MMC5603%20Triple-axis%20Magnetometer%20to%20an%20ESP32" title="WordPress" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_blogger" href="https://www.addtoany.com/add_to/blogger?linkurl=https%3A%2F%2Fwww.esp32learning.com%2Fcode%2Fconnect-a-mmc5603-triple-axis-magnetometer-to-an-esp32.php&linkname=Connect%20a%20MMC5603%20Triple-axis%20Magnetometer%20to%20an%20ESP32" title="Blogger" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_sms" href="https://www.addtoany.com/add_to/sms?linkurl=https%3A%2F%2Fwww.esp32learning.com%2Fcode%2Fconnect-a-mmc5603-triple-axis-magnetometer-to-an-esp32.php&linkname=Connect%20a%20MMC5603%20Triple-axis%20Magnetometer%20to%20an%20ESP32" title="Message" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_whatsapp" href="https://www.addtoany.com/add_to/whatsapp?linkurl=https%3A%2F%2Fwww.esp32learning.com%2Fcode%2Fconnect-a-mmc5603-triple-axis-magnetometer-to-an-esp32.php&linkname=Connect%20a%20MMC5603%20Triple-axis%20Magnetometer%20to%20an%20ESP32" title="WhatsApp" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_telegram" href="https://www.addtoany.com/add_to/telegram?linkurl=https%3A%2F%2Fwww.esp32learning.com%2Fcode%2Fconnect-a-mmc5603-triple-axis-magnetometer-to-an-esp32.php&linkname=Connect%20a%20MMC5603%20Triple-axis%20Magnetometer%20to%20an%20ESP32" title="Telegram" rel="nofollow noopener" target="_blank"></a><a class="a2a_dd addtoany_share_save addtoany_share" href="https://www.addtoany.com/share"></a></div></div> </div> 2316 </div> 2317 2318 <div class="penci-post-box-meta 2319 center-inner "> 2320 <div class="penci-post-share-box"> 2321 <a href="#" class="penci-post-like" aria-label="Like this post" data-post_id="906" title="Like" data-like="Like" data-unlike="Unlike"><i class="penci-faicon fa fa-heart-o" ></i><span class="dt-share">1</span></a> <a class="new-ver-share post-share-item post-share-facebook" aria-label="Share on Facebook" target="_blank" rel="noreferrer" href="https://www.facebook.com/sharer/sharer.php?u=https://www.esp32learning.com/code/connect-a-mmc5603-triple-axis-magnetometer-to-an-esp32.php"><i class="penci-faicon fa fa-facebook" ></i><span class="dt-share">Facebook</span></a><a class="new-ver-share post-share-item post-share-twitter" aria-label="Share on Twitter" target="_blank" rel="noreferrer" href="https://twitter.com/intent/tweet?text=Check%20out%20this%20article:%20Connect%20a%20MMC5603%20Triple-axis%20Magnetometer%20to%20an%20ESP32%20-%20https://www.esp32learning.com/code/connect-a-mmc5603-triple-axis-magnetometer-to-an-esp32.php"><i class="penci-faicon penciicon-x-twitter" ></i><span class="dt-share">Twitter</span></a><a class="new-ver-share post-share-item post-share-pinterest" aria-label="Pin to Pinterest" data-pin-do="none" rel="noreferrer" target="_blank" href="https://www.pinterest.com/pin/create/button/?url=https%3A%2F%2Fwww.esp32learning.com%2Fcode%2Fconnect-a-mmc5603-triple-axis-magnetometer-to-an-esp32.php&media=https%3A%2F%2Fwww.esp32learning.com%2Fwp-content%2Fuploads%2F2023%2F07%2Fesp32-and-MMC5603_bb.png&description=Connect+a+MMC5603+Triple-axis+Magnetometer+to+an+ESP32"><i class="penci-faicon fa fa-pinterest" ></i><span class="dt-share">Pinterest</span></a><a class="new-ver-share post-share-item post-share-email" target="_blank" aria-label="Share via Email" rel="noreferrer" href="mailto:?subject=Connect%20a%20MMC5603%20Triple-axis%20Magnetometer%20to%20an%20ESP32&BODY=https://www.esp32learning.com/code/connect-a-mmc5603-triple-axis-magnetometer-to-an-esp32.php"><i class="penci-faicon fa fa-envelope" ></i><span class="dt-share">Email</span></a> </div> 2322 </div> 2323 </div> 2324 2325</article> 2326 2327<article id="post-880" class="standard-article standard-pitem post-880 post type-post status-publish format-standard has-post-thumbnail hentry category-code tag-bmp384 tag-esp32"> 2328 2329 2330 2331 <div class="standard-post-image"> 2332 <a 2333 href="https://www.esp32learning.com/code/connect-a-bmp384-pressure-sensor-to-an-esp32-module-example.php"> 2334 <img 2335 class="attachment-penci-full-thumb size-penci-full-thumb penci-lazy wp-post-image" 2336 width="684" 2337 height="879" 2338 src="data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%20684%20879'%3E%3C/svg%3E" alt="" title="esp32 and bmp384_bb" data-src="https://www.esp32learning.com/wp-content/uploads/2023/07/esp32-and-bmp384_bb.png"> </a> 2339 </div> 2340 2341 2342 <div class="header-standard 2343 "> 2344 <div class="penci-standard-cat"><span class="cat"><a style="" class="penci-cat-name penci-cat-14" href="https://www.esp32learning.com/category/code" rel="category tag"><span style="">Code</span></a></span></div> 2345 2346 <h2 class="penci-entry-title entry-title entry-title"><a 2347 href="https://www.esp32learning.com/code/connect-a-bmp384-pressure-sensor-to-an-esp32-module-example.php">Connect a BMP384 pressure sensor to an ESP32 module example</a></h2> 2348 <div class="penci-hide-tagupdated"> 2349 <span class="author-italic author vcard">by <a class="author-url url fn n" 2350 href="https://www.esp32learning.com/author/shedboy71">shedboy71</a> 2351 </span> 2352 <time class="entry-date published" datetime="2023-07-19T21:33:00+01:00">19th July 2023</time> </div> 2353 </div> 2354 2355 <div class="standard-content"> 2356 <div class="standard-main-content entry-content"> 2357 <div class="post-entry standard-post-entry classic-post-entry blockquote-style-1 "> 2358 <p>
2358In this article we look at a temperature and pressure sensor, the BMP384 pressure sensor from Bosch Sensortec, and connect it to an ESP32 board</p> 2359<h3>Sensor Information</h3> 2360<p>The BMP384 can be used for high-resolution measurements (up to 21-bit) and uses a gel-filled cavity to provide extra resistance to liquids (water and other chemicals). This makes it a great option for monitoring pressure near water or in humid environments, though the sensor is not water-proof without an adequate integration concept.</p> 2361<p>The BMP384 provides excellent accuracy across a wide measurement range (300hPa to 1250hPa and -40 to +85°C) on an incredibly small footprint that uses the Qwiic Micro size (0.75in. x 0.30in. / 19.05mm x 7.62mm) so you can install it in projects with exceptionally tight spaces.</p> 2362<p>The sensor also features a configurable oversampling setting, a FIFO buffer for storing up to 73 measurements, and a low-pass filter so users can customize the performance based on the application’s requirements.</p> 2363<p>The Qwiic Pressure Sensor communicates over I2C by default, utilizing the handy Qwiic system so no soldering is required to connect it to the rest of your system.</p> 2364<p>The BMP384 has three operating modes: Sleep Mode, Normal Mode and Forced Mode. In Sleep Mode, the sensor is idle and consumes ~2µA, while in Normal Mode the sensor automatically cycles between measurement and standby periods and consumes ~700µA at peak current draw during measurements.</p> 2365<p>Forced Mode allows direct control of measurements to wake the sensor from Sleep Mode, take a single-shot measurement, and return the device to Sleep Mode.</p> 2366<p>This is what the breakout looks like that I purchased, it is from SparkFun</p> 2367<p><a href="https://s.click.aliexpress.com/e/_DEawteZ" target="_blank" rel="noopener"><img decoding="async" src="//ae01.alicdn.com/kf/S2a286bbbf6cf4b0ea71443b96d186336J.jpg_350x350.jpg"" /></a></p> 2368<h3>Features</h3> 2369<p>Take note of the supply voltage</p> 2370<ul> 2371<li>Supply Voltage Range: <b>1.65V</b> – <b>3.6V</b></li> 2372<li>Current Draw: 2373<ul> 2374<li><b>700µA</b> – Peak while measuring pressure</li> 2375<li><b>3.4 µA @ 1Hz</b> – Pressure and temperature monitoring with Ultra Low Power oversampling settings</li> 2376<li><b>~2µA</b> – Sleep Mode</li> 2377</ul> 2378</li> 2379<li>Data Transfer Speeds: 2380<ul> 2381<li>I<sup>2</sup>C – 3.4MHz</li> 2382<li>SPI – 10MHz</li> 2383</ul> 2384</li> 2385<li>I<sup>2</sup>C Address: <b>0x77</b> (Default), 0x76 (Alternate which can be set under the board by bridging 2 pads using solder)</li> 2386<li>Internal Temperature Sensor</li> 2387</ul> 2388<div class="product-feature-category" data-module-component="product-features"> 2389<div class="feature-category-label-column"> 2390<h3>Parts Required</h3> 2391<p>You can connect to the sensor using DuPont-style jumper wire.</p> 2392<p>The sensor will cost in the range of $20, I did get it along with various others at a decent sale price</p> 2393<p>You can connect up pretty much any ESP32 board – I used a Lolin 32 from Wemos – first board I had at hand</p> 2394<p> </p> 2395<div class="pcrstb-wrap"><table> 2396<tbody> 2397<tr style="height: 21px;"> 2398<td style="width: 15.8442%; height: 21px;"><strong>Name</strong></td> 2399<td style="width: 40.1299%; height: 21px;"><strong>Link</strong></td> 2400<td style="width: 44.4156%;"></td> 2401</tr> 2402<tr style="height: 55px;"> 2403<td style="width: 15.8442%; height: 55px;">ESP32</td> 2404<td style="width: 40.1299%;"><a href="https://s.click.aliexpress.com/e/_DkIPPqt" target="_blank" rel="noopener"><img decoding="async" src="//ae01.alicdn.com/kf/Sbf885b40323a45178795fde862d61c3cT.jpg_140x140.jpg"" /></a></td> 2405<td style="width: 44.4156%; height: 55px;"> 2406<ul> 2407<li><a href="https://s.click.aliexpress.com/e/_DdKOnXT" target="_blank" rel="noopener">Aliexpress link</a></li> 2408<li><a href="https://www.amazon.com/s?k=ESP32%22&camp=1789&creative=9325&linkCode=ur2&linkId=cac24da38498a0be29dcff978e974b54&tag=basicvisualbasic" target="_blank" rel="noopener">Amazon</a></li> 2409<li><a href="https://www.ebay.com/sch/i.html?_from=R40&_trksid=p2334524.m570.l1313&_nkw=ESP32&_sacat=0&_odkw=ESP32&_osacat=0&mkcid=1&mkrid=711-53200-19255-0&siteid=0&campid=5338725476&
2409customid=&toolid=10001&mkevt=1" target="_blank" rel="noopener">Ebay</a></li> 2410</ul> 2411</td> 2412</tr> 2413<tr style="height: 55px;"> 2414<td style="width: 15.8442%; height: 55px;">BMP384</td> 2415<td style="width: 40.1299%;"></td> 2416<td style="width: 44.4156%; height: 55px;"> 2417<ul> 2418<li><a href="https://s.click.aliexpress.com/e/_DCM82iz" target="_blank" rel="noopener">Aliexpress link</a></li> 2419<li><a href="https://www.ebay.com/sch/i.html?_from=R40&_trksid=p2334524.m570.l1313&_nkw=BMP384&_sacat=0&_odkw=BMP384&_osacat=0&mkcid=1&mkrid=711-53200-19255-0&siteid=0&campid=5338725476&customid=&toolid=10001&mkevt=1" target="_blank" rel="noopener">Ebay link</a></li> 2420<li><a href="https://www.amazon.com/s?k=BMP384%22&camp=1789&creative=9325&linkCode=ur2&linkId=cac24da38498a0be29dcff978e974b54&tag=basicvisualbasic" target="_blank" rel="noopener">Amazon Link</a></li> 2421</ul> 2422</td> 2423</tr> 2424<tr style="height: 21px;"> 2425<td style="width: 15.8442%; height: 21px;">Connecting cables</td> 2426<td style="width: 40.1299%;"><img decoding="async" class="alignnone size-thumbnail wp-image-13" src="http://www.arduinocode.com/wp-content/uploads/2023/07/dupont-150x150.jpg" alt="" width="150" height="150" /></td> 2427<td style="width: 44.4156%; height: 21px;"> 2428<ul> 2429<li><a href="https://s.click.aliexpress.com/e/_Dnk1xwF" target="_blank" rel="noopener">Aliexpress link</a></li> 2430<li><a href="https://www.amazon.com/s?k=dupont+cables%22&camp=1789&creative=9325&linkCode=ur2&linkId=cac24da38498a0be29dcff978e974b54&tag=basicvisualbasic" target="_blank" rel="noopener">Amazon</a></li> 2431<li><a href="https://www.ebay.com/sch/i.html?_from=R40&_trksid=p2334524.m570.l1313&_nkw=dupont+cables&_sacat=0&_odkw=dupont+cables&_osacat=0&mkcid=1&mkrid=711-53200-19255-0&siteid=0&campid=5338725476&customid=&toolid=10001&mkevt=1" target="_blank" rel="noopener">Ebay</a></li> 2432</ul> 2433</td> 2434</tr> 2435</tbody> 2436</table></div> 2437<p> </p> 2438<h3>Schematic/Connection</h3> 2439<p>I used 3.3v from the ESP32</p> 2440<p>I also used a Qwiic cable, but if you do not have one, there is an unpopulated set of pins you can solder a header to. This is how you would wire this up</p> 2441<p><img decoding="async" class="alignnone size-full wp-image-882" src="https://www.esp32learning.com/wp-content/uploads/2023/07/esp32-and-bmp384_bb.png" alt="" width="684" height="879" srcset="https://www.esp32learning.com/wp-content/uploads/2023/07/esp32-and-bmp384_bb.png 684w, https://www.esp32learning.com/wp-content/uploads/2023/07/esp32-and-bmp384_bb-233x300.png 233w" sizes="(max-width: 684px) 100vw, 684px" /></p> 2442<p> </p> 2443<h3>Code Example</h3> 2444<p>I installed the Sparkfun library using the Arduino ide</p> 2445<p>Click the <strong>Manage Libraries …</strong> menu item, search for BMP384, and select the Sparkfun BMP384 library like this</p> 2446</div> 2447<p>This is one of the examples that gets installed with the library, with a few comments and unused lines removed.</p> 2448<pre class="EnlighterJSRAW" data-enlighter-language="cpp">#include <Wire.h> 2449#include "SparkFunBMP384.h" 2450 2451// Create a new sensor object 2452BMP384 pressureSensor; 2453 2454// I2C address selection 2455uint8_t i2cAddress = BMP384_I2C_ADDRESS_DEFAULT; // 0x77 2456//uint8_t i2cAddress = BMP384_I2C_ADDRESS_SECONDARY; // 0x76 2457 2458void setup() 2459{ 2460 // Start serial 2461 Serial.begin(115200); 2462 Serial.println("BMP384 Example1 begin!"); 2463 2464 // Initialize the I2C library 2465 Wire.begin(); 2466 2467 // Check if sensor is connected and initialize 2468 // Address is optional (defaults to 0x77) 2469 while(pressureSensor.beginI2C(i2cAddress) != BMP3_OK) 2470 { 2471 // Not connected, inform user 2472 Serial.println("Error: BMP384 not connected, check wiring and I2C address!"); 2473 2474 // Wait a bit to see if connection is established 2475 delay(1000); 2476 } 2477 2478 Serial.println("BMP384 connected!"); 2479} 2480 2481void loop() 2482{ 2483 // Get measurements from the sensor 2484 bmp3_data data; 2485 int8_t err = pressureSensor.getSensorData(&data); 2486 2487 // Check whether data was acquired successfully 2488 if(err == BMP3_OK) 2489 { 2490 // Acquisistion succeeded, print temperature and pressure
2491 Serial.print("Temperature (C): "); 2492 Serial.print(data.temperature); 2493 Serial.print("\t\t"); 2494 Serial.print("Pressure (Pa): "); 2495 Serial.println(data.pressure); 2496 } 2497 else 2498 { 2499 // Acquisition failed, most likely a communication error (code -2) 2500 Serial.print("Error getting data from sensor! Error code: "); 2501 Serial.println(err); 2502 } 2503 2504 // Only print every second 2505 delay(1000); 2506}</pre> 2507<p> </p> 2508<div class="feature-category-label-column"> 2509<h4>Output</h4> 2510<p>When run you will see something like this in the serial monitor window</p> 2511<p>Temperature (C): 20.67 Pressure (Pa): 100386.79<br /> 2512Temperature (C): 20.67 Pressure (Pa): 100403.07<br /> 2513Temperature (C): 20.66 Pressure (Pa): 100388.79<br /> 2514Temperature (C): 20.66 Pressure (Pa): 100406.11</p> 2515<h3>Links</h3> 2516<p><a href="https://www.bosch-sensortec.com/media/boschsensortec/downloads/datasheets/bst-bmp384-ds003.pdf" target="_blank" rel="noopener">https://www.bosch-sensortec.com/media/boschsensortec/downloads/datasheets/bst-bmp384-ds003.pdf</a></p> 2517</div> 2518</div> 2519<div class="addtoany_share_save_container addtoany_content addtoany_content_bottom"><div class="a2a_kit a2a_kit_size_32 addtoany_list" data-a2a-url="https://www.esp32learning.com/code/connect-a-bmp384-pressure-sensor-to-an-esp32-module-example.php" data-a2a-title="Connect a BMP384 pressure sensor to an ESP32 module example"><a class="a2a_button_facebook" href="https://www.addtoany.com/add_to/facebook?linkurl=https%3A%2F%2Fwww.esp32learning.com%2Fcode%2Fconnect-a-bmp384-pressure-sensor-to-an-esp32-module-example.php&linkname=Connect%20a%20BMP384%20pressure%20sensor%20to%20an%20ESP32%20module%20example" title="Facebook" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_twitter" href="https://www.addtoany.com/add_to/twitter?linkurl=https%3A%2F%2Fwww.esp32learning.com%2Fcode%2Fconnect-a-bmp384-pressure-sensor-to-an-esp32-module-example.php&linkname=Connect%20a%20BMP384%20pressure%20sensor%20to%20an%20ESP32%20module%20example" title="Twitter" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_threads" href="https://www.addtoany.com/add_to/threads?linkurl=https%3A%2F%2Fwww.esp32learning.com%2Fcode%2Fconnect-a-bmp384-pressure-sensor-to-an-esp32-module-example.php&linkname=Connect%20a%20BMP384%20pressure%20sensor%20to%20an%20ESP32%20module%20example" title="Threads" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_pinterest" href="https://www.addtoany.com/add_to/pinterest?linkurl=https%3A%2F%2Fwww.esp32learning.com%2Fcode%2Fconnect-a-bmp384-pressure-sensor-to-an-esp32-module-example.php&linkname=Connect%20a%20BMP384%20pressure%20sensor%20to%20an%20ESP32%20module%20example" title="Pinterest" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_tumblr" href="https://www.addtoany.com/add_to/tumblr?linkurl=https%3A%2F%2Fwww.esp32learning.com%2Fcode%2Fconnect-a-bmp384-pressure-sensor-to-an-esp32-module-example.php&linkname=Connect%20a%20BMP384%20pressure%20sensor%20to%20an%20ESP32%20module%20example" title="Tumblr" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_reddit" href="https://www.addtoany.com/add_to/reddit?linkurl=https%3A%2F%2Fwww.esp32learning.com%2Fcode%2Fconnect-a-bmp384-pressure-sensor-to-an-esp32-module-example.php&linkname=Connect%20a%20BMP384%20pressure%20sensor%20to%20an%20ESP32%20module%20example" title="Reddit" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_linkedin" href="https://www.addtoany.com/add_to/linkedin?linkurl=https%3A%2F%2Fwww.esp32learning.com%2Fcode%2Fconnect-a-bmp384-pressure-sensor-to-an-esp32-module-example.php&linkname=Connect%20a%20BMP384%20pressure%20sensor%20to%20an%20ESP32%20module%20example" title="LinkedIn" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_digg" href="https://www.addtoany.com/add_to/digg?linkurl=https%3A%2F%2Fwww.esp32learning.com%2Fcode%2Fconnect-a-bmp384-pressure-sensor-to-an-esp32-module-example.php&linkname=Connect%20a%20BMP384%20pressure%20sensor%20to%20an%20ESP32%20module%20example" title="Digg" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_pocket" href="https://www.addtoany.com/add_to/pocket?linkurl=https%3A%2F%2Fwww.esp32learning.com%2Fcode%2Fconnect-a-bmp384-pressure-sensor-to-an-esp32-module-example.php&linkname=Connect%20a%20BMP384%20pressure%20sensor%20to%20an%20ESP32%20module%20example" title="Pocket" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_sina_weibo" href="https://www.addtoany.com/add_to/sina_weibo?linkurl=https%3A%2F%2Fwww.esp32learning.com%2Fcode%2Fconnect-a-bmp384-pressure-sensor-to-an-esp32-module-example.php&linkname=Connect%20a%20BMP384%20pressure%20sensor%20to%20an%20ESP32%20module%20example" title="Sina Weibo" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_wordpress" href="https://www.addtoany.com/add_to/wordpress?linkurl=https%3A%2F%2Fwww.esp32learning.com%2Fcode%2Fconnect-a-bmp384-pressure-sensor-to-an-esp32-module-example.php&linkname=Connect%20a%20BMP384%20pressure%20sensor%20to%20an%20ESP32%20module%20example" title="WordPress" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_blogger" href="https://www.addtoany.com/add_to/blogger?linkurl=https%3A%2F%2Fwww.esp32learning.com%2Fcode%2Fconnect-a-bmp384-pressure-sensor-to-an-esp32-module-example.php&linkname=Connect%20a%20BMP384%20pressure%20sensor%20to%20an%20ESP32%20module%20example" title="Blogger" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_sms" href="https://www.addtoany.com/add_to/sms?linkurl=https%3A%2F%2Fwww.esp32learning.com%2Fcode%2Fconnect-a-bmp384-pressure-sensor-to-an-esp32-module-example.php&linkname=Connect%20a%20BMP384%20pressure%20sensor%20to%20an%20ESP32%20module%20example" title="Message" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_whatsapp" href="https://www.addtoany.com/add_to/whatsapp?linkurl=https%3A%2F%2Fwww.esp32learning.com%2Fcode%2Fconnect-a-bmp384-pressure-sensor-to-an-esp32-module-example.php&linkname=Connect%20a%20BMP384%20pressure%20sensor%20to%20an%20ESP32%20module%20example" title="WhatsApp" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_telegram" href="https://www.addtoany.com/add_to/telegram?linkurl=https%3A%2F%2Fwww.esp32learning.com%2Fcode%2Fconnect-a-bmp384-pressure-sensor-to-an-esp32-module-example.php&linkname=Connect%20a%20BMP384%20pressure%20sensor%20to%20an%20ESP32%20module%20example" title="Telegram" rel="nofollow noopener" target="_blank"></a><a class="a2a_dd addtoany_share_save addtoany_share" href="https://www.addtoany.com/share"></a></div></div> </div> 2520 </div> 2521 2522 <div class="penci-post-box-meta 2523 center-inner "> 2524 <div class="penci-post-share-box"> 2525 <a href="#" class="penci-post-like" aria-label="Like this post" data-post_id="880" title="Like" data-like="Like" data-unlike="Unlike"><i class="penci-faicon fa fa-heart-o" ></i><span class="dt-share">0</span></a> <a class="new-ver-share post-share-item post-share-facebook" aria-label="Share on Facebook" target="_blank" rel="noreferrer" href="https://www.facebook.com/sharer/sharer.php?u=https://www.esp32learning.com/code/connect-a-bmp384-pressure-sensor-to-an-esp32-module-example.php"><i class="penci-faicon fa fa-facebook" ></i><span class="dt-share">Facebook</span></a><a class="new-ver-share post-share-item post-share-twitter" aria-label="Share on Twitter" target="_blank" rel="noreferrer" href="https://twitter.com/intent/tweet?text=Check%20out%20this%20article:%20Connect%20a%20BMP384%20pressure%20sensor%20to%20an%20ESP32%20module%20example%20-%20https://www.esp32learning.com/code/connect-a-bmp384-pressure-sensor-to-an-esp32-module-example.php"><i class="penci-faicon penciicon-x-twitter" ></i><span class="dt-share">Twitter</span></a><a class="new-ver-share post-share-item post-share-pinterest" aria-label="Pin to Pinterest" data-pin-do="none" rel="noreferrer" target="_blank" href="https://www.pinterest.com/pin/create/button/?url=https%3A%2F%2Fwww.esp32learning.com%2Fcode%2Fconnect-a-bmp384-pressure-sensor-to-an-esp32-module-example.php&media=https%3A%2F%2Fwww.esp32learning.com%2Fwp-content%2Fuploads%2F2023%2F07%2Fesp32-and-bmp384_bb.png&description=Connect+a+BMP384+pressure+sensor+to+an+ESP32+module+example"><i class="penci-faicon fa fa-pinterest" ></i><span class="dt-share">Pinterest</span></a><a class="new-ver-share post-share-item post-share-email" target="_blank" aria-label="Share via Email" rel="noreferrer" href="mailto:?subject=Connect%20a%20BMP384%20pressure%20sensor%20to%20an%20ESP32%20module%20example&BODY=https://www.esp32learning.com/code/connect-a-bmp384-pressure-sensor-to-an-esp32-module-example.php"><i class="penci-faicon fa fa-envelope" ></i><span class="dt-share">Email</span></a> </div> 2526 </div> 2527 </div> 2528 2529</article> 2530 2531<article id="post-732" class="standard-article standard-pitem post-732 post type-post status-publish format-standard has-post-thumbnail hentry category-code tag-esp32"> 2532 2533 2534 2535 <div class="standard-post-image"> 2536 <a 2537 href="https://www.esp32learning.com/code/esp32-and-vl6180x-module-arduino-example.php"> 2538 <img 2539 class="attachment-penci-full-thumb size-penci-full-thumb penci-lazy wp-post-image" 2540 width="558" 2541 height="609" 2542 src="data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%20558%20609'%3E%3C/svg%3E" alt="ESP32 and VL6180X layout" title="ESP32 and VL6180X layout" data-src="https://www.esp32learning.com/wp-content/uploads/2021/12/ESP32-and-VL6180X-layout.png"> </a> 2543 </div> 2544 2545 2546 <div class="header-standard 2547 "> 2548 <div class="penci-standard-cat"><span class="cat"><a style="" class="penci-cat-name penci-cat-14" href="https://www.esp32learning.com/category/code" rel="category tag"><span style="">Code</span></a></span></div> 2549 2550 <h2 class="penci-entry-title entry-title entry-title"><a 2551 href="https://www.esp32learning.com/code/esp32-and-vl6180x-module-arduino-example.php">ESP32 and VL6180X module arduino example</a></h2> 2552 <div class="penci-hide-tagupdated"> 2553 <span class="author-italic author vcard">by <a class="author-url url fn n" 2554 href="https://www.esp32learning.com/author/shedboy71">shedboy71</a> 2555 </span> 2556 <time class="entry-date published" datetime="2022-05-16T08:02:09+01:00">16th May 2022</time> </div> 2557 </div> 2558 2559 <div class="standard-content"> 2560 <div class="standard-main-content entry-content"> 2561 <div class="post-entry standard-post-entry classic-post-entry blockquote-style-1 "> 2562 <p>
2562In this article we connect an VL6180X device to an ESP32</p> 2563<p>Lets look at the sensor</p> 2564<h3>Sensor Information</h3> 2565<p>First lets look at some information about the sensor from the manufacturer</p> 2566<p class="st-copy">The VL6180X is a ground-breaking technology allowing absolute distance to be measured independent of target reflectance.</p> 2567<p class="st-copy">Instead of estimating the distance by measuring the amount of light reflected back from the object (which is significantly influenced by color and surface), the VL6180X precisely measures the time the light takes to travel to the nearest object and reflect back to the sensor (Time-of-Flight).</p> 2568<p class="st-copy">Combining an IR emitter, a range sensor and an ambient light sensor, the VL6180X is easy to integrate and saves the end-product maker long and costly optical and mechanical design optimizations.</p> 2569<p class="st-copy">The module is designed for low power operation. Ranging and ALS measurements can be automatically performed at user defined intervals. Multiple threshold and interrupt schemes are supported to minimize host operations.</p> 2570<p class="st-copy">Host control and result reading is performed using an I<sup>2</sup>C interface. Optional additional functions, such as measurement ready and threshold interrupts, are provided by two programmable GPIO pins.</p> 2571<h3 class="st-h5 st-text--center">Key Features</h3> 2572<ul class="st-list" data-automation-description="features-description"> 2573<li data-automation-text="feature-text">Three-in-one smart optical module 2574<ul class="st-list"> 2575<li>Proximity sensor</li> 2576<li>Ambient Light Sensor</li> 2577<li>VCSEL light source</li> 2578</ul> 2579</li> 2580<li data-automation-text="feature-text">Fast, accurate distance ranging 2581<ul class="st-list"> 2582<li>Measures absolute range from 0 to above 10 cm (ranging beyond 10cm is dependent on conditions)</li> 2583<li>Independent of object reflectance</li> 2584<li>Ambient light rejection</li> 2585<li>Cross-talk compensation for cover glass</li> 2586</ul> 2587</li> 2588<li data-automation-text="feature-text">Gesture recognition 2589<ul class="st-list"> 2590<li>Distance and signal level can be used by host system to implement gesture recognition</li> 2591</ul> 2592</li> 2593<li data-automation-text="feature-text">Ambient light sensor 2594<ul class="st-list"> 2595<li>High dynamic range</li> 2596<li>Accurate/sensitive in ultra-low light</li> 2597<li>Calibrated output value in lux</li> 2598</ul> 2599</li> 2600<li data-automation-text="feature-text">Two programmable GPIO 2601<ul class="st-list"> 2602<li>Window and thresholding functions for both ranging and ALS</li> 2603</ul> 2604</li> 2605</ul> 2606<p>This was my sensor of choice that I used</p> 2607<p><a href="https://s.click.aliexpress.com/e/_9H3Krb" target="_parent" rel="noopener"><img decoding="async" class="" src="https://ae04.alicdn.com/kf/H5c1cd49529084eb59591b3f901189281X.jpg" width="282" height="282" /></a></p> 2608<h3>Parts Required</h3> 2609<p>The sensor you can pick up in the $12 price range – you can connect to the sensor using a standard header the classic dupont style jumper wire.</p> 2610<p> </p> 2611<div class="pcrstb-wrap"><table> 2612<tbody> 2613<tr style="height: 21px;"> 2614<td style="width: 15.8442%; height: 21px;"><strong>Name</strong></td> 2615<td style="width: 40.1299%; height: 21px;"><strong>Link</strong></td> 2616<td style="width: 44.4156%;"></td> 2617</tr> 2618<tr style="height: 55px;"> 2619<td style="width: 15.8442%; height: 55px;">ESP32</td> 2620<td style="width: 40.1299%;"><a href="https://s.click.aliexpress.com/e/_DkIPPqt" target="_blank" rel="noopener"><img decoding="async" src="//ae01.alicdn.com/kf/Sbf885b40323a45178795fde862d61c3cT.jpg_140x140.jpg"" /></a></td> 2621<td style="width: 44.4156%; height: 55px;"> 2622<ul> 2623<li><a href="https://s.click.aliexpress.com/e/_DdKOnXT" target="_blank" rel="noopener">Aliexpress link</a></li> 2624<li><a href="https://www.amazon.com/s?k=ESP32%22&camp=1789&creative=9325&linkCode=ur2&linkId=cac24da38498a0be29dcff978e974b54&tag=basicvisualbasic" target="_blank" rel="noopener">Amazon</a></li> 2625<li><a href="https://www.ebay.com/sch/i.html?_from=R40&_trksid=p2334524.m570.l1313&_nkw=ESP32&_sacat=0&_odkw=ESP32&_osacat=0&mkcid=1&mkrid=711-53200-19255-0&siteid=0&campid=5338725476&
2625customid=&toolid=10001&mkevt=1" target="_blank" rel="noopener">Ebay</a></li> 2626</ul> 2627</td> 2628</tr> 2629<tr style="height: 55px;"> 2630<td style="width: 15.8442%; height: 55px;">VL6180X</td> 2631<td style="width: 40.1299%;"></td> 2632<td style="width: 44.4156%; height: 55px;"> 2633<ul> 2634<li><a href="https://s.click.aliexpress.com/e/_Dm0mvkd" target="_blank" rel="noopener">Aliexpress link</a></li> 2635<li><a href="https://www.ebay.com/sch/i.html?_from=R40&_trksid=p2334524.m570.l1313&_nkw=VL6180X&_sacat=0&_odkw=VL6180X&_osacat=0&mkcid=1&mkrid=711-53200-19255-0&siteid=0&campid=5338725476&customid=&toolid=10001&mkevt=1" target="_blank" rel="noopener">Ebay link</a></li> 2636<li><a href="https://www.amazon.com/s?k=VL6180X%22&camp=1789&creative=9325&linkCode=ur2&linkId=cac24da38498a0be29dcff978e974b54&tag=basicvisualbasic" target="_blank" rel="noopener">Amazon Link</a></li> 2637</ul> 2638</td> 2639</tr> 2640<tr style="height: 21px;"> 2641<td style="width: 15.8442%; height: 21px;">Connecting cables</td> 2642<td style="width: 40.1299%;"><img decoding="async" class="alignnone size-thumbnail wp-image-13" src="http://www.arduinocode.com/wp-content/uploads/2023/07/dupont-150x150.jpg" alt="" width="150" height="150" /></td> 2643<td style="width: 44.4156%; height: 21px;"> 2644<ul> 2645<li><a href="https://s.click.aliexpress.com/e/_Dnk1xwF" target="_blank" rel="noopener">Aliexpress link</a></li> 2646<li><a href="https://www.amazon.com/s?k=dupont+cables%22&camp=1789&creative=9325&linkCode=ur2&linkId=cac24da38498a0be29dcff978e974b54&tag=basicvisualbasic" target="_blank" rel="noopener">Amazon</a></li> 2647<li><a href="https://www.ebay.com/sch/i.html?_from=R40&_trksid=p2334524.m570.l1313&_nkw=dupont+cables&_sacat=0&_odkw=dupont+cables&_osacat=0&mkcid=1&mkrid=711-53200-19255-0&siteid=0&campid=5338725476&customid=&toolid=10001&mkevt=1" target="_blank" rel="noopener">Ebay</a></li> 2648</ul> 2649</td> 2650</tr> 2651</tbody> 2652</table></div> 2653<p> </p> 2654<h3>Schematic/Connection</h3> 2655<div id="attachment_733" style="width: 568px" class="wp-caption alignnone"><img decoding="async" aria-describedby="caption-attachment-733" class="size-full wp-image-733" src="https://www.esp32learning.com/wp-content/uploads/2021/12/ESP32-and-VL6180X-layout.png" alt="ESP32 and VL6180X layout" width="558" height="609" srcset="https://www.esp32learning.com/wp-content/uploads/2021/12/ESP32-and-VL6180X-layout.png 558w, https://www.esp32learning.com/wp-content/uploads/2021/12/ESP32-and-VL6180X-layout-275x300.png 275w, https://www.esp32learning.com/wp-content/uploads/2021/12/ESP32-and-VL6180X-layout-320x349.png 320w, https://www.esp32learning.com/wp-content/uploads/2021/12/ESP32-and-VL6180X-layout-360x393.png 360w, https://www.esp32learning.com/wp-content/uploads/2021/12/ESP32-and-VL6180X-layout-385x420.png 385w" sizes="(max-width: 558px) 100vw, 558px" /><p id="caption-attachment-733" class="wp-caption-text">ESP32 and VL6180X layout</p></div> 2656<h3>Code Example</h3> 2657<p>This uses a library from <b>Adafruit </b>installed using the Library Manager in the Arduino IDE. search for <strong>VL6180X</strong>, and select the <strong>Adafruit_VL6180X</strong> library. You will also need to add another couple of libraries <strong>Adafruit BusIO</strong> library and the <strong>Adafruit Unified Sensor</strong> library</p> 2658<p>[codesyntax lang=”cpp”]</p> 2659<pre>#include <Wire.h> 2660#include "Adafruit_VL6180X.h" 2661 2662Adafruit_VL6180X vl = Adafruit_VL6180X(); 2663 2664void setup() { 2665 Serial.begin(115200); 2666 2667 // wait for serial port to open on native usb devices 2668 while (!Serial) { 2669 delay(1); 2670 } 2671 2672 Serial.println("Adafruit VL6180x test!"); 2673 if (! vl.begin()) { 2674 Serial.println("Failed to find sensor"); 2675 while (1); 2676 } 2677 Serial.println("Sensor found!"); 2678} 2679 2680void loop() { 2681 float lux = vl.readLux(VL6180X_ALS_GAIN_5); 2682 2683 Serial.print("Lux: "); Serial.println(lux); 2684 2685 uint8_t range = vl.readRange(); 2686 uint8_t status = vl.readRangeStatus(); 2687 2688 if (status == VL6180X_ERROR_NONE) { 2689 Serial.print("Range: "); Serial.println(range); 2690 } 2691 2692 // Some error occurred, print it out! 2693 2694 if ((status >
2694= VL6180X_ERROR_SYSERR_1) && (status <= VL6180X_ERROR_SYSERR_5)) { 2695 Serial.println("System error"); 2696 } 2697 else if (status == VL6180X_ERROR_ECEFAIL) { 2698 Serial.println("ECE failure"); 2699 } 2700 else if (status == VL6180X_ERROR_NOCONVERGE) { 2701 Serial.println("No convergence"); 2702 } 2703 else if (status == VL6180X_ERROR_RANGEIGNORE) { 2704 Serial.println("Ignoring range"); 2705 } 2706 else if (status == VL6180X_ERROR_SNR) { 2707 Serial.println("Signal/Noise error"); 2708 } 2709 else if (status == VL6180X_ERROR_RAWUFLOW) { 2710 Serial.println("Raw reading underflow"); 2711 } 2712 else if (status == VL6180X_ERROR_RAWOFLOW) { 2713 Serial.println("Raw reading overflow"); 2714 } 2715 else if (status == VL6180X_ERROR_RANGEUFLOW) { 2716 Serial.println("Range reading underflow"); 2717 } 2718 else if (status == VL6180X_ERROR_RANGEOFLOW) { 2719 Serial.println("Range reading overflow"); 2720 } 2721 delay(500); 2722}</pre> 2723<p>[/codesyntax]</p> 2724<pre></pre> 2725<h4><strong>Output</strong></h4> 2726<p>Here is an example of what I saw in the serial monitor window</p> 2727<p>Lux: 0.00<br /> 2728Range: 43<br /> 2729Lux: 0.00<br /> 2730Range: 40<br /> 2731Lux: 0.00<br /> 2732Range: 43<br /> 2733Lux: 0.00<br /> 2734Range: 11<br /> 2735Lux: 0.00<br /> 2736Range: 12</p> 2737<h3>Links</h3> 2738<p><a href="https://www.st.com/resource/en/datasheet/vl6180x.pdf" target="_blank" rel="noopener">https://www.st.com/resource/en/datasheet/vl6180x.pdf</a></p> 2739<div class="addtoany_share_save_container addtoany_content addtoany_content_bottom"><div class="a2a_kit a2a_kit_size_32 addtoany_list" data-a2a-url="https://www.esp32learning.com/code/esp32-and-vl6180x-module-arduino-example.php" data-a2a-title="ESP32 and VL6180X module arduino example"><a class="a2a_button_facebook" href="https://www.addtoany.com/add_to/facebook?linkurl=https%3A%2F%2Fwww.esp32learning.com%2Fcode%2Fesp32-and-vl6180x-module-arduino-example.php&linkname=ESP32%20and%20VL6180X%20module%20arduino%20example" title="Facebook" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_twitter" href="https://www.addtoany.com/add_to/twitter?linkurl=https%3A%2F%2Fwww.esp32learning.com%2Fcode%2Fesp32-and-vl6180x-module-arduino-example.php&linkname=ESP32%20and%20VL6180X%20module%20arduino%20example" title="Twitter" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_threads" href="https://www.addtoany.com/add_to/threads?linkurl=https%3A%2F%2Fwww.esp32learning.com%2Fcode%2Fesp32-and-vl6180x-module-arduino-example.php&linkname=ESP32%20and%20VL6180X%20module%20arduino%20example" title="Threads" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_pinterest" href="https://www.addtoany.com/add_to/pinterest?linkurl=https%3A%2F%2Fwww.esp32learning.com%2Fcode%2Fesp32-and-vl6180x-module-arduino-example.php&linkname=ESP32%20and%20VL6180X%20module%20arduino%20example" title="Pinterest" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_tumblr" href="https://www.addtoany.com/add_to/tumblr?linkurl=https%3A%2F%2Fwww.esp32learning.com%2Fcode%2Fesp32-and-vl6180x-module-arduino-example.php&linkname=ESP32%20and%20VL6180X%20module%20arduino%20example" title="Tumblr" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_reddit" href="https://www.addtoany.com/add_to/reddit?linkurl=https%3A%2F%2Fwww.esp32learning.com%2Fcode%2Fesp32-and-vl6180x-module-arduino-example.php&linkname=ESP32%20and%20VL6180X%20module%20arduino%20example" title="Reddit" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_linkedin" href="https://www.addtoany.com/add_to/linkedin?linkurl=https%3A%2F%2Fwww.esp32learning.com%2Fcode%2Fesp32-and-vl6180x-module-arduino-example.php&linkname=ESP32%20and%20VL6180X%20module%20arduino%20example" title="LinkedIn" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_digg" href="https://www.addtoany.com/add_to/digg?linkurl=https%3A%2F%2Fwww.esp32learning.com%2Fcode%2Fesp32-and-vl6180x-module-arduino-example.php&linkname=ESP32%20and%20VL6180X%20module%20arduino%20example" title="Digg" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_pocket" href="https://www.addtoany.com/add_to/pocket?linkurl=https%3A%2F%2Fwww.esp32learning.com%2Fcode%2Fesp32-and-vl6180x-module-arduino-example.php&linkname=ESP32%20and%20VL6180X%20module%20arduino%20example" title="Pocket" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_sina_weibo" href="https://www.addtoany.com/add_to/sina_weibo?linkurl=https%3A%2F%2Fwww.esp32learning.com%2Fcode%2Fesp32-and-vl6180x-module-arduino-example.php&linkname=ESP32%20and%20VL6180X%20module%20arduino%20example" title="Sina Weibo" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_wordpress" href="https://www.addtoany.com/add_to/wordpress?linkurl=https%3A%2F%2Fwww.esp32learning.com%2Fcode%2Fesp32-and-vl6180x-module-arduino-example.php&linkname=ESP32%20and%20VL6180X%20module%20arduino%20example" title="WordPress" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_blogger" href="https://www.addtoany.com/add_to/blogger?linkurl=https%3A%2F%2Fwww.esp32learning.com%2Fcode%2Fesp32-and-vl6180x-module-arduino-example.php&linkname=ESP32%20and%20VL6180X%20module%20arduino%20example" title="Blogger" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_sms" href="https://www.addtoany.com/add_to/sms?linkurl=https%3A%2F%2Fwww.esp32learning.com%2Fcode%2Fesp32-and-vl6180x-module-arduino-example.php&linkname=ESP32%20and%20VL6180X%20module%20arduino%20example" title="Message" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_whatsapp" href="https://www.addtoany.com/add_to/whatsapp?linkurl=https%3A%2F%2Fwww.esp32learning.com%2Fcode%2Fesp32-and-vl6180x-module-arduino-example.php&linkname=ESP32%20and%20VL6180X%20module%20arduino%20example" title="WhatsApp" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_telegram" href="https://www.addtoany.com/add_to/telegram?linkurl=https%3A%2F%2Fwww.esp32learning.com%2Fcode%2Fesp32-and-vl6180x-module-arduino-example.php&linkname=ESP32%20and%20VL6180X%20module%20arduino%20example" title="Telegram" rel="nofollow noopener" target="_blank"></a><a class="a2a_dd addtoany_share_save addtoany_share" href="https://www.addtoany.com/share"></a></div></div> </div> 2740 </div> 2741 2742 <div class="penci-post-box-meta 2743 center-inner "> 2744 <div class="penci-post-share-box"> 2745 <a href="#" class="penci-post-like" aria-label="Like this post" data-post_id="732" title="Like" data-like="Like" data-unlike="Unlike"><i class="penci-faicon fa fa-heart-o" ></i><span class="dt-share">0</span></a> <a class="new-ver-share post-share-item post-share-facebook" aria-label="Share on Facebook" target="_blank" rel="noreferrer" href="https://www.facebook.com/sharer/sharer.php?u=https://www.esp32learning.com/code/esp32-and-vl6180x-module-arduino-example.php"><i class="penci-faicon fa fa-facebook" ></i><span class="dt-share">Facebook</span></a><a class="new-ver-share post-share-item post-share-twitter" aria-label="Share on Twitter" target="_blank" rel="noreferrer" href="https://twitter.com/intent/tweet?text=Check%20out%20this%20article:%20ESP32%20and%20VL6180X%20module%20arduino%20example%20-%20https://www.esp32learning.com/code/esp32-and-vl6180x-module-arduino-example.php"><i class="penci-faicon penciicon-x-twitter" ></i><span class="dt-share">Twitter</span></a><a class="new-ver-share post-share-item post-share-pinterest" aria-label="Pin to Pinterest" data-pin-do="none" rel="noreferrer" target="_blank" href="https://www.pinterest.com/pin/create/button/?url=https%3A%2F%2Fwww.esp32learning.com%2Fcode%2Fesp32-and-vl6180x-module-arduino-example.php&media=https%3A%2F%2Fwww.esp32learning.com%2Fwp-content%2Fuploads%2F202
27451%2F12%2FESP32-and-VL6180X-layout.png&description=ESP32+and+VL6180X+module+arduino+example"><i class="penci-faicon fa fa-pinterest" ></i><span class="dt-share">Pinterest</span></a><a class="new-ver-share post-share-item post-share-email" target="_blank" aria-label="Share via Email" rel="noreferrer" href="mailto:?subject=ESP32%20and%20VL6180X%20module%20arduino%20example&BODY=https://www.esp32learning.com/code/esp32-and-vl6180x-module-arduino-example.php"><i class="penci-faicon fa fa-envelope" ></i><span class="dt-share">Email</span></a> </div> 2746 </div> 2747 </div> 2748 2749</article> 2750 2751 <div class="penci-pagination"> 2752 <div class="newer"> 2753 <div class="disable-url"><span><i class="penci-faicon fa fa-angle-left" ></i>Newer Posts</span></div> </div> 2754 <div class="older"> 2755 <a href="https://www.esp32learning.com/category/code/page/2" ><span>Older Posts <i class="penci-faicon fa fa-angle-right" ></i></span></a> </div> 2756 </div> 2757 2758 2759 2760 </div> 2761 </div> 2762 2763 2764<div id="sidebar" 2765 class="penci-sidebar-right penci-sidebar-content style-1 pcalign-center pciconp-right pcicon-right"> 2766 <div class="theiaStickySidebar"> 2767 <aside id="text-3" class="widget widget_text"><h3 class="widget-title penci-border-arrow"><span class="inner-arrow">Disclaimer</span></h3> <div class="textwidget"><p>When you purchase through links on our site, we may earn an affiliate commission</p> 2768</div> 2769 </aside><aside id="adrotate_widgets-3" class="widget adrotate_widgets"><h3 class="widget-title penci-border-arrow"><span class="inner-arrow">Products</span></h3><div class="g g-3"><div class="g-col b-3 a-25"><a href="https://s.click.aliexpress.com/e/_c3sDdMJx" target="_blank"><img src="//ae01.alicdn.com/kf/S57acd0930b7f49deb7804bcda4af00efd.jpg_350x350.jpg" /></a></div></div><div class="g g-3"><div class="g-col b-3 a-31"><a href="https://s.click.aliexpress.com/e/_c3lFSIBx" target="_blank"><img src="//ae01.alicdn.com/kf/S506c2db1334c4e12862946089dd52849p.jpg_350x350.jpg" /></a></div></div><div class="g g-3"><div class="g-col b-3 a-34"><a href="https://s.click.aliexpress.com/e/_c4dypFRR" target="_blank"><img src="//ae01.alicdn.com/kf/S72f9af6ec7304ba1891ebaad3fb3fe56x.jpg_350x350.jpg" /></a></div></div></aside> 2770 <aside id="recent-posts-2" class="widget widget_recent_entries"> 2771 <h3 class="widget-title penci-border-arrow"><span class="inner-arrow">Latest</span></h3> 2772 <ul> 2773 <li> 2774 <a href="https://www.esp32learning.com/tools/esp32-deep-sleep-battery-life-calculator.php">ESP32 Deep Sleep Battery Life Calculator</a> 2775 </li> 2776 <li> 2777 <a href="https://www.esp32learning.com/tools/esp32-pinout-explorer-gpio-adc-pwm-i2c-spi-uart-guide.php">ESP32 Pinout Explorer – GPIO, ADC, PWM, I2C, SPI & UART Guide</a> 2778 </li> 2779 <li> 2780 <a href="https://www.esp32learning.com/tools/esp32-pwm-calculator-frequency-resolution-duty-cycle-tool.php">ESP32 PWM Calculator – Frequency, Resolution & Duty Cycle Tool</a> 2781 </li> 2782 <li> 2783 <a href="https://www.esp32learning.com/code/connect-an-sts35-temperature-sensor-to-an-esp32.php">Connect an STS35 temperature sensor to an ESP32</a> 2784 </li> 2785 <li> 2786 <a href="https://www.esp32learning.com/code/connect-an-is31fl3741-led-matrix-module-to-an-esp32.php">Connect an IS31FL3741 LED matrix module to an ESP32</a> 2787 </li> 2788 <li> 2789 <a href="https://www.esp32learning.com/code/connect-a-adxl313-accelerometer-sensor-to-an-esp32.php">Connect a ADXL313 accelerometer sensor to an ESP32</a> 2790 </li> 2791 <li> 2792 <a href="https://www.esp32learning.com/code/connect-an-bma220-triple-axis-accelerometer-to-an-esp32.php">Connect an BMA220 Triple Axis Accelerometer to an ESP32</a> 2793 </li> 2794 <li> 2795 <a href="https://www.esp32learning.com/code/connect-an-ltr-329-ambient-light-sensor-to-an-esp32.php">Connect an LTR-329 Ambient Light sensor to an ESP32</a> 2796 </li> 2797 <li> 2798 <a href="https://www.esp32learning.com/code/connect-an-ltr-303-ambient-light-sensor-to-an-esp32.php">Connect an LTR-303 Ambient Light sensor to an ESP32</a> 2799 </li> 2800 </ul> 2801 2802 </aside>
2802<aside id="text-2" class="widget widget_text"> <div class="textwidget"><p>
2802<script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
2802<br /> 2803<!-- esp32 --><br /> 2804<ins class="adsbygoogle" style="display: inline-block; width: 300px; height: 600px;" data-ad-client="ca-pub-3520634452456567" data-ad-slot="4248630848"></ins><br />
2805<script> 2806(adsbygoogle = window.adsbygoogle || []).push({}); 2807</script>
2807</p> 2808</div> 2809 </aside> </div> 2810</div> 2811</div> 2812 2813 2814 <div class="clear-footer"></div> 2815 2816 <div id="widget-area" 2817 > 2818 <div class="container container-1400"> 2819 <div class="footer-widget-wrapper footer-widget-style-1"> 2820 <aside id="a2a_share_save_widget-4" class="widget widget_a2a_share_save_widget"><div class="a2a_kit a2a_kit_size_32 addtoany_list"><a class="a2a_button_facebook" href="https://www.addtoany.com/add_to/facebook?linkurl=https%3A%2F%2Fwww.esp32learning.com%2Fcategory%2Fcode&linkname=Code%20Archives%20-%20ESP32%20Learning" title="Facebook" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_twitter" href="https://www.addtoany.com/add_to/twitter?linkurl=https%3A%2F%2Fwww.esp32learning.com%2Fcategory%2Fcode&linkname=Code%20Archives%20-%20ESP32%20Learning" title="Twitter" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_threads" href="https://www.addtoany.com/add_to/threads?linkurl=https%3A%2F%2Fwww.esp32learning.com%2Fcategory%2Fcode&linkname=Code%20Archives%20-%20ESP32%20Learning" title="Threads" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_pinterest" href="https://www.addtoany.com/add_to/pinterest?linkurl=https%3A%2F%2Fwww.esp32learning.com%2Fcategory%2Fcode&linkname=Code%20Archives%20-%20ESP32%20Learning" title="Pinterest" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_tumblr" href="https://www.addtoany.com/add_to/tumblr?linkurl=https%3A%2F%2Fwww.esp32learning.com%2Fcategory%2Fcode&linkname=Code%20Archives%20-%20ESP32%20Learning" title="Tumblr" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_reddit" href="https://www.addtoany.com/add_to/reddit?linkurl=https%3A%2F%2Fwww.esp32learning.com%2Fcategory%2Fcode&linkname=Code%20Archives%20-%20ESP32%20Learning" title="Reddit" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_linkedin" href="https://www.addtoany.com/add_to/linkedin?linkurl=https%3A%2F%2Fwww.esp32learning.com%2Fcategory%2Fcode&linkname=Code%20Archives%20-%20ESP32%20Learning" title="LinkedIn" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_digg" href="https://www.addtoany.com/add_to/digg?linkurl=https%3A%2F%2Fwww.esp32learning.com%2Fcategory%2Fcode&linkname=Code%20Archives%20-%20ESP32%20Learning" title="Digg" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_pocket" href="https://www.addtoany.com/add_to/pocket?linkurl=https%3A%2F%2Fwww.esp32learning.com%2Fcategory%2Fcode&linkname=Code%20Archives%20-%20ESP32%20Learning" title="Pocket" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_sina_weibo" href="https://www.addtoany.com/add_to/sina_weibo?linkurl=https%3A%2F%2Fwww.esp32learning.com%2Fcategory%2Fcode&linkname=Code%20Archives%20-%20ESP32%20Learning" title="Sina Weibo" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_wordpress" href="https://www.addtoany.com/add_to/wordpress?linkurl=https%3A%2F%2Fwww.esp32learning.com%2Fcategory%2Fcode&linkname=Code%20Archives%20-%20ESP32%20Learning" title="WordPress" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_blogger" href="https://www.addtoany.com/add_to/blogger?linkurl=https%3A%2F%2Fwww.esp32learning.com%2Fcategory%2Fcode&linkname=Code%20Archives%20-%20ESP32%20Learning" title="Blogger" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_sms" href="https://www.addtoany.com/add_to/sms?linkurl=https%3A%2F%2Fwww.esp32learning.com%2Fcategory%2Fcode&linkname=Code%20Archives%20-%20ESP32%20Learning" title="Message" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_whatsapp" href="https://www.addtoany.com/add_to/whatsapp?linkurl=https%3A%2F%2Fwww.esp32learning.com%2Fcategory%2Fcode&linkname=Code%20Archives%20-%20ESP32%20Learning" title="WhatsApp" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_telegram" href="https://www.addtoany.com/add_to/telegram?linkurl=https%3A%2F%2Fwww.esp32learning.com%2Fcategory%2Fcode&linkname=Code%20Archives%20-%20ESP32%20Learning" title="Telegram" rel="nofollow noopener" target="_blank"></a><a class="a2a_dd addtoany_share_save addtoany_share" href="https://www.addtoany.com/share"></a></div></aside> </div> 2821 <div class="footer-widget-wrapper footer-widget-style-1"> 2822 </div> 2823 <div class="footer-widget-wrapper footer-widget-style-1 last"> 2824 </div> 2825 </div> 2826 </div> 2827 <footer id="footer-section" 2828 class="penci-footer-social-media penci-lazy 2829 " 2830 itemscope itemtype="https://schema.org/WPFooter"> 2831 <div class="container container-1400"> 2832 <div class="footer-logo-copyright 2833 footer-not-logo "> 2834 2835 2836 <div id="footer-copyright"> 2837 <p>ESPLearning</p> 2838 </div> 2839 <div class="go-to-top-parent"><a aria-label="Go to top" href="#" class="go-to-top"><span><i 2840 class="penciicon-up-chevron"></i> <br>Back To Top</span></a> 2841 </div> 2842 </div> 2843 </div> 2844 </footer>
2845 </div><!-- End .wrapper-boxed --> 2846 2847 <a href="#" id="close-sidebar-nav" 2848 class="header-3 mstyle-default"><i class="penci-faicon fa fa-close" ></i></a> 2849 <nav id="sidebar-nav" class="header-3 mstyle-default" role="navigation" 2850 itemscope 2851 itemtype="https://schema.org/SiteNavigationElement"> 2852 2853 <div id="sidebar-nav-logo"> 2854 <a href="https://www.esp32learning.com/"><img 2855 class="penci-lazy penci-limg" src="data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%20272%2090'%3E%3C/svg%3E" 2856 width="272" 2857 height="90" 2858 data-src="https://esp32learning.b-cdn.net/wp-content/uploads/2017/11/logo272.png" 2859 data-lightlogo="https://esp32learning.b-cdn.net/wp-content/uploads/2017/11/logo272.png" 2860 alt="ESP32 Learning"/></a> 2861 </div> 2862 2863 <div class="header-social sidebar-nav-social"> 2864 <div class="inner-header-social"> 2865 <a href="https://www.facebook.com/PenciDesign" aria-label="Facebook" rel="noreferrer" target="_blank"><i class="penci-faicon fa fa-facebook" ></i></a> 2866 <a href="https://twitter.com/PenciDesign" aria-label="Twitter" rel="noreferrer" target="_blank"><i class="penci-faicon penciicon-x-twitter" ></i></a> 2867 </div> 2868 </div> 2869 2870 2871 <ul id="menu-topmenu-1" class="menu"><li class="menu-item menu-item-type-taxonomy menu-item-object-category current-menu-item menu-item-73"><a href="https://www.esp32learning.com/category/code">Code</a></li> 2872<li class="menu-item menu-item-type-taxonomy menu-item-object-category menu-item-36"><a href="https://www.esp32learning.com/category/information">Information</a></li> 2873<li class="menu-item menu-item-type-taxonomy menu-item-object-category menu-item-37"><a href="https://www.esp32learning.com/category/hardware">Hardware</a></li> 2874<li class="menu-item menu-item-type-taxonomy menu-item-object-category menu-item-866"><a href="https://www.esp32learning.com/category/micropython">Micropython</a></li> 2875<li class="menu-item menu-item-type-taxonomy menu-item-object-category menu-item-35"><a href="https://www.esp32learning.com/category/tutorials">Tutorials</a></li> 2876</ul> </nav> 2877 2878 2879
2880<script type="text/javascript" id="adrotate-groups-js-extra"> 2881/* <![CDATA[ */ 2882var impression_object = {"ajax_url":"https:\/\/www.esp32learning.com\/wp-admin\/admin-ajax.php"}; 2883/* ]]> */ 2884</script>
vendor: 1 bytes, line 2884
2884
2885<script type="text/javascript" src="https://www.esp32learning.com/wp-content/plugins/adrotate/library/jquery.groups.js" id="adrotate-groups-js"></script>
vendor: 1 bytes, line 2885
2885
2886<script type="text/javascript" id="adrotate-clicker-js-extra"> 2887/* <![CDATA[ */ 2888var click_object = {"ajax_url":"https:\/\/www.esp32learning.com\/wp-admin\/admin-ajax.php"}; 2889/* ]]> */ 2890</script>
vendor: 1 bytes, line 2890
2890
2891<script type="text/javascript" src="https://www.esp32learning.com/wp-content/plugins/adrotate/library/jquery.clicker.js" id="adrotate-clicker-js"></script>
vendor: 1 bytes, line 2891
2891
2892<script type="text/javascript" id="esp32-deep-sleep-script-js-after"> 2893/* <![CDATA[ */ 2894document.addEventListener("DOMContentLoaded", function () { 2895 const preset = document.getElementById("preset"); 2896 const activeCurrent = document.getElementById("activeCurrent"); 2897 const activeUnit = document.getElementById("activeUnit"); 2898 const sleepCurrent = document.getElementById("sleepCurrent"); 2899 const sleepUnit = document.getElementById("sleepUnit"); 2900 const activeSeconds = document.getElementById("activeSeconds"); 2901 const activeTimeUnit = document.getElementById("activeTimeUnit"); 2902 const wakeInterval = document.getElementById("wakeInterval"); 2903 const wakeUnit = document.getElementById("wakeUnit"); 2904 const batteryCapacity = document.getElementById("batteryCapacity"); 2905 const batteryType = document.getElementById("batteryType"); 2906 const efficiency = document.getElementById("efficiency"); 2907 const derating = document.getElementById("derating"); 2908 const calculateBtn = document.getElementById("calculateBtn"); 2909 2910 const avgCurrent = document.getElementById("avgCurrent"); 2911 const dutyCycle = document.getElementById("dutyCycle"); 2912 const wakesPerDay = document.getElementById("wakesPerDay"); 2913 const dailyConsumption = document.getElementById("dailyConsumption"); 2914 const usableCapacity = document.getElementById("usableCapacity"); 2915 const runtime = document.getElementById("runtime"); 2916 const runtimeDays = document.getElementById("runtimeDays"); 2917 const runtimeMonths = document.getElementById("runtimeMonths"); 2918 const adviceBox = document.getElementById("adviceBox"); 2919 const batteryBar = document.getElementById("batteryBar"); 2920 2921 const arduinoCode = document.getElementById("arduinoCode"); 2922 const micropythonCode = document.getElementById("micropythonCode"); 2923 2924 function applyPreset() { 2925 if (preset.value === "weather") { 2926 activeCurrent.value = 120; 2927 sleepCurrent.value = 0.15; 2928 activeSeconds.value = 8; 2929 wakeInterval.value = 10; 2930 wakeUnit.value = 60; 2931 batteryCapacity.value = 3000; 2932 efficiency.value = 85; 2933 derating.value = 80; 2934 } 2935 2936 if (preset.value === "soil") { 2937 activeCurrent.value = 90; 2938 sleepCurrent.value = 0.12; 2939 activeSeconds.value = 5; 2940 wakeInterval.value = 1; 2941 wakeUnit.value = 3600; 2942 batteryCapacity.value = 2000; 2943 efficiency.value = 85; 2944 derating.value = 80; 2945 } 2946 2947 if (preset.value === "door") { 2948 activeCurrent.value = 70; 2949 sleepCurrent.value = 0.08; 2950 activeSeconds.value = 2; 2951 wakeInterval.value = 6; 2952 wakeUnit.value = 3600; 2953 batteryCapacity.value = 2000; 2954 efficiency.value = 90; 2955 derating.value = 80; 2956 } 2957 2958 if (preset.value === "camera") { 2959 activeCurrent.value = 240; 2960 sleepCurrent.value = 2; 2961 activeSeconds.value = 15; 2962 wakeInterval.value = 30; 2963 wakeUnit.value = 60; 2964 batteryCapacity.value = 5000; 2965 efficiency.value = 80; 2966 derating.value = 75; 2967 } 2968 2969 if (preset.value === "logger") { 2970 activeCurrent.value = 85; 2971 sleepCurrent.value = 0.1; 2972 activeSeconds.value = 4; 2973 wakeInterval.value = 5; 2974 wakeUnit.value = 60; 2975 batteryCapacity.value = 2000; 2976 efficiency.value = 85; 2977 derating.value = 80; 2978 } 2979 2980 calculate(); 2981 } 2982 2983 function formatRuntime(hours) { 2984 if (hours < 24) return hours.toFixed(1) + " hours"; 2985 if (hours < 24 * 60) return (hours / 24).toFixed(1) + " days"; 2986 if (hours < 24 * 365) return (hours / 24 / 30.44).toFixed(1) + " months"; 2987 return (hours / 24 / 365).toFixed(2) + " years"; 2988 } 2989 2990 function calculate() { 2991 const activeMA = parseFloat(activeCurrent.value) * parseFloat(activeUnit.value); 2992 const sleepMA = parseFloat(sleepCurrent.value) * parseFloat(sleepUnit.value); 2993 const activeTimeSeconds = parseFloat(activeSeconds.value) * parseFloat(activeTimeUnit.value); 2994 const intervalSeconds = parseFloat(wakeInterval.value) * parseFloat(wakeUnit.value); 2995 const capacityMAH = parseFloat(batteryCapacity.value); 2996 const eff = parseFloat(efficiency.value) / 100; 2997 const derate = parseFloat(derating.value) / 100; 2998 2999 adviceBox.innerHTML = ""; 3000 3001 if ( 3002 isNaN(activeMA) || isNaN(sleepMA) || isNaN(activeTimeSeconds) || 3003 isNaN(intervalSeconds) || isNaN(capacityMAH) || activeMA < 0 || 3004 sleepMA < 0 || activeTimeSeconds < 0 || intervalSeconds <= 0 || 3005 capacityMAH <= 0 3006 ) { 3007 adviceBox.innerHTML = '<div class="esp32-danger">Please enter valid positive values.</div>'; 3008 return; 3009 } 3010 3011 if (activeTimeSeconds > intervalSeconds) { 3012 adviceBox.innerHTML = '<div class="esp32-danger">Active duration cannot be longer than the wake interval.</div>'; 3013 return; 3014 } 3015 3016 const sleepTimeSeconds = intervalSeconds - activeTimeSeconds; 3017 const cycleAverageMA = ((activeMA * activeTimeSeconds) + (sleepMA * sleepTimeSeconds)) / intervalSeconds; 3018 const duty = (activeTimeSeconds / intervalSeconds) * 100; 3019 const wakesDay = 86400 / intervalSeconds; 3020 const dailyMAH = cycleAverageMA * 24; 3021 const usableMAH = capacityMAH * eff * derate; 3022 const runtimeHours = usableMAH / cycleAverageMA; 3023 const days = runtimeHours / 24; 3024 const months = days / 30.44; 3025 3026 avgCurrent.textContent = cycleAverageMA.toFixed(3) + " mA"; 3027 dutyCycle.textContent = duty.toFixed(4) + "%"; 3028 wakesPerDay.textContent = wakesDay.toFixed(1); 3029 dailyConsumption.textContent = dailyMAH.toFixed(2) + " mAh/day"; 3030 usableCapacity.textContent = usableMAH.toFixed(0) + " mAh"; 3031 runtime.textContent = formatRuntime(runtimeHours); 3032 runtimeDays.textContent = days.toFixed(1) + " days"; 3033 runtimeMonths.textContent = months.toFixed(2) + " months"; 3034 3035 let barWidth = Math.min(100, Math.max(5, days)); 3036 batteryBar.style.width = barWidth + "%"; 3037 3038 let advice = ""; 3039 3040 if (days < 3) { 3041 advice += '<div class="esp32-danger">Battery life is very short. Reduce active time, reduce Wi-Fi usage, use a larger battery or improve sleep current.</div>'; 3042 } else if (days < 14) { 3043 advice += '<div class="esp32-warn">Battery life is moderate. This may be fine for testing, but optimisation is recommended for remote sensors.</div>'; 3044 } else { 3045 advice += '<div class="esp32-good">This looks suitable for a low-power ESP32 project, assuming your measured current values are realistic.</div>'; 3046 } 3047 3048 if (sleepMA > 1) { 3049 advice += '<div class="esp32-warn">Sleep current is quite high. Many dev boards use extra current because of power LEDs, USB chips or inefficient regulators.</div>'; 3050 } 3051 3052 if (activeTimeSeconds > 10) { 3053 advice += '<div class="esp32-warn">Active time is fairly long. Wi-Fi connection time is often the biggest drain in ESP32 battery projects.</div>'; 3054 } 3055 3056 if (duty > 10) { 3057 advice += '<div class="esp32-warn">The ESP32 is awake for a large percentage of each cycle. Deep sleep works best when active time is very short.</div>'; 3058 } 3059 3060 adviceBox.innerHTML = advice; 3061 3062 generateCode(intervalSeconds); 3063 } 3064 3065 function generateCode(intervalSeconds) { 3066 const seconds = Math.round(intervalSeconds); 3067 const microseconds = seconds * 1000000; 3068 const milliseconds = seconds * 1000; 3069 3070 arduinoCode.textContent = 3071`// ESP32 Deep Sleep Example 3072// Wake interval: ${seconds} seconds 3073 3074#define uS_TO_S_FACTOR 1000000ULL 3075#define TIME_TO_SLEEP ${seconds} 3076 3077void setup() { 3078 Serial.begin(115200); 3079 delay(1000); 3080 3081 Serial.println("ESP32 awake"); 3082 3083 // Read sensors here 3084 // Connect Wi-Fi here if needed 3085 // Send data here 3086 3087 esp_sleep_enable_timer_wakeup(TIME_TO_SLEEP * uS_TO_S_FACTOR); 3088 3089 Serial.println("Going to deep sleep"); 3090 Serial.flush(); 3091 3092 esp_deep_sleep_start(); 3093} 3094 3095void loop() {
3096 // Not used after deep sleep starts 3097}`; 3098 3099 micropythonCode.textContent = 3100`# ESP32 MicroPython Deep Sleep Example 3101# Wake interval: ${seconds} seconds 3102 3103from machine import deepsleep 3104from time import sleep 3105 3106print("ESP32 awake") 3107 3108# Read sensors here 3109# Connect Wi-Fi here if needed 3110# Send data here 3111 3112sleep(1) 3113 3114print("Going to deep sleep") 3115deepsleep(${milliseconds})`; 3116 } 3117 3118 batteryType.addEventListener("change", function () { 3119 batteryCapacity.value = batteryType.value; 3120 calculate(); 3121 }); 3122 3123 preset.addEventListener("change", applyPreset); 3124 calculateBtn.addEventListener("click", calculate); 3125 3126 [ 3127 activeCurrent, activeUnit, sleepCurrent, sleepUnit, activeSeconds, 3128 activeTimeUnit, wakeInterval, wakeUnit, batteryCapacity, 3129 efficiency, derating 3130 ].forEach(function (el) { 3131 el.addEventListener("input", calculate); 3132 el.addEventListener("change", calculate); 3133 }); 3134 3135 document.querySelectorAll(".copy-btn").forEach(function (btn) { 3136 btn.addEventListener("click", function () { 3137 const target = document.getElementById(btn.dataset.copy); 3138 navigator.clipboard.writeText(target.textContent).then(function () { 3139 const old = btn.textContent; 3140 btn.textContent = "Copied!"; 3141 setTimeout(function () { 3142 btn.textContent = old; 3143 }, 1400); 3144 }); 3145 }); 3146 }); 3147 3148 calculate(); 3149}); 3150/* ]]> */ 3151</script>
vendor: 1 bytes, line 3151
3151
3152<script type="text/javascript" id="esp32-pinout-explorer-script-js-after"> 3153/* <![CDATA[ */ 3154document.addEventListener("DOMContentLoaded", function () { 3155 const boards = { 3156 "esp32-devkit-v1": { 3157 name: "ESP32 DevKit V1 / ESP-WROOM-32", 3158 chip: "ESP32", 3159 summary: "Popular 30-pin or 38-pin ESP32 development board. Good for Wi-Fi, Bluetooth, PWM, ADC, I2C, SPI and UART projects.", 3160 notes: [ 3161 "GPIO34–39 are input-only on many classic ESP32 boards.", 3162 "GPIO6–11 are normally connected to flash and should be avoided.", 3163 "GPIO0, GPIO2, GPIO5, GPIO12 and GPIO15 are boot strapping pins.", 3164 "GPIO21 and GPIO22 are common I2C defaults.", 3165 "GPIO18, GPIO19, GPIO23 and GPIO5 are common VSPI defaults." 3166 ], 3167 pins: classicESP32Pins() 3168 }, 3169 "esp32-wrover": { 3170 name: "ESP32-WROVER", 3171 chip: "ESP32", 3172 summary: "ESP32 module with PSRAM on many boards. Similar GPIO behaviour to ESP32-WROOM, but some pins may be used by PSRAM depending on module design.", 3173 notes: [ 3174 "Avoid flash and PSRAM-related pins.", 3175 "Check your exact board schematic before using borderline pins.", 3176 "GPIO34–39 are input-only.", 3177 "Boot strapping pins need careful external pull-up or pull-down design." 3178 ], 3179 pins: classicESP32Pins() 3180 }, 3181 "esp32-pico-d4": { 3182 name: "ESP32-PICO-D4", 3183 chip: "ESP32", 3184 summary: "Compact ESP32 system-in-package. Useful for small designs, but available pins depend heavily on board layout.", 3185 notes: [ 3186 "Pin availability depends on the breakout board.", 3187 "Use safe GPIOs first for beginner projects.", 3188 "Avoid flash-related and boot-sensitive pins unless the board documentation confirms availability." 3189 ], 3190 pins: classicESP32Pins() 3191 }, 3192 "esp32-cam": { 3193 name: "ESP32-CAM", 3194 chip: "ESP32", 3195 summary: "Camera-focused ESP32 board with many pins already used by camera, SD card and flash LED.", 3196 notes: [ 3197 "Many GPIOs are already connected to the camera module.", 3198 "GPIO0 is commonly used for flashing mode.", 3199 "GPIO4 is often connected to the onboard flash LED.", 3200 "Use spare pins carefully and check camera/SD card conflicts." 3201 ], 3202 pins: esp32CamPins() 3203 }, 3204 "esp32-s2": { 3205 name: "ESP32-S2 Dev Board", 3206 chip: "ESP32-S2", 3207 summary: "Single-core Wi-Fi ESP32 variant with USB support and many GPIOs depending on board design.", 3208 notes: [ 3209 "USB pins may be reserved on USB-native boards.", 3210 "ADC and touch support vary by pin.", 3211 "Check board silkscreen because not every chip pin is exposed." 3212 ], 3213 pins: s2Pins() 3214 }, 3215 "esp32-s3": { 3216 name: "ESP32-S3 DevKit", 3217 chip: "ESP32-S3", 3218 summary: "Modern dual-core ESP32 with Wi-Fi, Bluetooth LE, USB Serial/JTAG, many GPIOs and strong MicroPython/Arduino support.", 3219 notes: [ 3220 "GPIO19 and GPIO20 are commonly associated with USB D- and D+ on ESP32-S3 boards.", 3221 "Some pins may be used for flash/PSRAM depending on module.", 3222 "GPIO0 is commonly used for boot/download mode." 3223 ], 3224 pins: s3Pins() 3225 }, 3226 "esp32-c3": { 3227 name: "ESP32-C3 DevKit", 3228 chip: "ESP32-C3", 3229 summary: "RISC-V ESP32 with Wi-Fi and Bluetooth LE. Fewer GPIOs than classic ESP32 but good for compact IoT projects.", 3230 notes: [ 3231 "GPIO2, GPIO8 and GPIO9 are strapping pins on ESP32-C3.", 3232 "GPIO18 and GPIO19 are often USB D- and D+ on USB-native boards.", 3233 "Available pins vary significantly between compact C3 boards." 3234 ], 3235 pins: c3Pins() 3236 }, 3237 "esp32-c6": { 3238 name: "ESP32-C6 DevKit", 3239 chip: "ESP32-C6", 3240 summary: "Wi-Fi 6, Bluetooth LE and IEEE 802.15.4 capable ESP32 family board. Good for newer IoT and Matter-style experimentation.", 3241 notes: [ 3242 "Board pinouts vary; check the manufacturer schematic.", 3243 "Some pins may be reserved for USB, flash or board functions.", 3244 "Use labelled general GPIO pins first." 3245 ], 3246 pins: c6Pins() 3247 }, 3248 "esp32-h2": { 3249 name: "ESP32-H2 DevKit", 3250 chip: "ESP32-H2", 3251 summary: "Bluetooth LE and IEEE 802.15.4 focused ESP32 family chip. Useful for low-power wireless and Thread/Zigbee-style projects.", 3252 notes: [ 3253 "No Wi-Fi on ESP32-H2.", 3254 "Pin availability depends on the development board.", 3255 "Check board schematic before using special-purpose pins." 3256 ], 3257 pins: h2Pins() 3258 }, 3259 "generic-esp32": { 3260 name: "Generic ESP32 Module", 3261 chip: "ESP32", 3262 summary: "General ESP32 reference view. Use this when your exact board is not listed.", 3263 notes: [ 3264 "Always compare with your board schematic.", 3265 "Not all module pins are exposed on every dev board.", 3266 "Avoid boot, flash and input-only pins for beginner projects." 3267 ], 3268 pins: classicESP32Pins() 3269 } 3270 }; 3271 3272 const boardSelect = document.getElementById("esp32Board"); 3273 const searchInput = document.getElementById("esp32Search"); 3274 const filterSelect = document.getElementById("esp32Filter"); 3275 const codePinSelect = document.getElementById("esp32CodePin"); 3276 const boardTitle = document.getElementById("boardTitle"); 3277 const boardSummary = document.getElementById("boardSummary"); 3278 const boardWarnings = document.getElementById("boardWarnings"); 3279 const pinTable = document.getElementById("pinTable"); 3280 const arduinoCode = document.getElementById("arduinoPinCode"); 3281 const microPythonCode = document.getElementById("microPythonPinCode"); 3282
3283 Object.keys(boards).forEach(key => { 3284 const opt = document.createElement("option"); 3285 opt.value = key; 3286 opt.textContent = boards[key].name; 3287 boardSelect.appendChild(opt); 3288 }); 3289 3290 function pin(gpio, status, digital, adc, pwm, i2c, spi, uart, notes, tags) { 3291 return { gpio, status, digital, adc, pwm, i2c, spi, uart, notes, tags }; 3292 } 3293 3294 function classicESP32Pins() { 3295 const pins = []; 3296 for (let i = 0; i <= 39; i++) { 3297 let status = "Good"; 3298 let digital = "Input / Output"; 3299 let adc = ""; 3300 let pwm = "Yes"; 3301 let i2c = "Remappable"; 3302 let spi = "Remappable"; 3303 let uart = "Remappable"; 3304 let notes = "General-purpose GPIO."; 3305 let tags = ["safe","pwm"]; 3306 3307 if ([0,2,4,5,12,15].includes(i)) { 3308 status = "Caution"; 3309 notes = "Boot strapping or boot-sensitive pin. Use with care."; 3310 tags.push("strap"); 3311 } 3312 3313 if (i >= 6 && i <= 11) { 3314 status = "Avoid"; 3315 digital = "Reserved"; 3316 pwm = "No"; 3317 i2c = ""; 3318 spi = "Flash"; 3319 uart = ""; 3320 notes = "Usually connected to SPI flash. Avoid using."; 3321 tags = ["avoid"]; 3322 } 3323 3324 if (i >= 34 && i <= 39) { 3325 status = "Input-only"; 3326 digital = "Input only"; 3327 pwm = "No"; 3328 i2c = ""; 3329 spi = ""; 3330 uart = ""; 3331 notes = "Input-only pin. Good for buttons or ADC input, not output."; 3332 tags = ["input","adc"]; 3333 } 3334 3335 if ([32,33,34,35,36,37,38,39].includes(i)) { 3336 adc = "ADC1"; 3337 tags.push("adc"); 3338 } else if ([0,2,4,12,13,14,15,25,26,27].includes(i)) { 3339 adc = "ADC2"; 3340 tags.push("adc"); 3341 } 3342 3343 if (i === 21) { i2c = "Default SDA"; tags.push("i2c"); } 3344 if (i === 22) { i2c = "Default SCL"; tags.push("i2c"); } 3345 if (i === 18) { spi = "VSPI SCK"; tags.push("spi"); } 3346 if (i === 19) { spi = "VSPI MISO"; tags.push("spi"); } 3347 if (i === 23) { spi = "VSPI MOSI"; tags.push("spi"); } 3348 if (i === 5) { spi = "VSPI CS / strap"; tags.push("spi"); } 3349 if (i === 1) { uart = "UART0 TX"; tags.push("uart"); status = "Caution"; notes = "Used for serial programming/debug on many boards."; } 3350 if (i === 3) { uart = "UART0 RX"; tags.push("uart"); status = "Caution"; notes = "Used for serial programming/debug on many boards."; } 3351 if (i === 16) { uart = "UART2 RX"; tags.push("uart"); } 3352 if (i === 17) { uart = "UART2 TX"; tags.push("uart"); } 3353 3354 pins.push(pin(i, status, digital, adc, pwm, i2c, spi, uart, notes, tags)); 3355 } 3356 return pins; 3357 } 3358 3359 function esp32CamPins() { 3360 return [ 3361 pin(0,"Caution","Input / Output","ADC2","Yes","","","", "Flashing mode pin. Often pulled low to upload firmware.", ["strap"]), 3362 pin(1,"Caution","TX","","Yes","","","UART0 TX","Serial programming/debug.", ["uart"]), 3363 pin(3,"Caution","RX","","Yes","","","UART0 RX","Serial programming/debug.", ["uart"]), 3364 pin(4,"Caution","Input / Output","ADC2","Yes","","","", "Often connected to onboard flash LED.", ["pwm","adc"]), 3365 pin(12,"Caution","Input / Output","ADC2","Yes","","","", "Boot-sensitive and often used by SD card.", ["strap","adc"]), 3366 pin(13,"Caution","Input / Output","ADC2","Yes","","","", "Often used by SD card.", ["adc"]), 3367 pin(14,"Caution","Input / Output","ADC2","Yes","","","", "Often used by SD card.", ["adc"]), 3368 pin(15,"Caution","Input / Output","ADC2","Yes","","","", "Boot-sensitive and often used by SD card.", ["strap","adc"]), 3369 pin(16,"Caution","Input / Output","","Yes","","","UART2 RX","May be used by PSRAM/camera board features.", ["uart"]), 3370 pin(33,"Good","Input / Output","ADC1","Yes","","","", "Often available as a useful spare pin on some ESP32-CAM boards.", ["safe","adc","pwm"]) 3371 ]; 3372 } 3373 3374 function s2Pins() { 3375 const pins = []; 3376 for (let i = 0; i <= 46; i++) { 3377 let status = "Good", digital = "Input / Output", adc = "", pwm = "Yes", i2c = "Remappable", spi = "Remappable", uart = "Remappable", notes = "General-purpose GPIO.", tags = ["safe","pwm"]; 3378 3379 if ([0,45,46].includes(i)) { status = "Caution"; notes = "Boot or special configuration pin on many ESP32-S2 designs."; tags.push("strap"); } 3380 if ([19,20].includes(i)) { status = "Caution";
3380 notes = "Often USB D-/D+ on native USB boards."; tags.push("avoid"); } 3381 if (i >= 1 && i <= 20) { adc = "ADC capable"; tags.push("adc"); } 3382 if (i === 8) { i2c = "Common SDA"; tags.push("i2c"); } 3383 if (i === 9) { i2c = "Common SCL"; tags.push("i2c"); } 3384 if ([34,35,36,37].includes(i)) { spi = "Common SPI option"; tags.push("spi"); } 3385 3386 pins.push(pin(i,status,digital,adc,pwm,i2c,spi,uart,notes,tags)); 3387 } 3388 return pins; 3389 } 3390 3391 function s3Pins() { 3392 const pins = []; 3393 for (let i = 0; i <= 48; i++) { 3394 let status = "Good", digital = "Input / Output", adc = "", pwm = "Yes", i2c = "Remappable", spi = "Remappable", uart = "Remappable", notes = "General-purpose GPIO.", tags = ["safe","pwm"]; 3395 3396 if ([0,3,45,46].includes(i)) { status = "Caution"; notes = "Boot, JTAG or special configuration pin on many ESP32-S3 designs."; tags.push("strap"); } 3397 if ([19,20].includes(i)) { status = "Caution"; notes = "Commonly used for USB D-/D+."; tags.push("avoid"); } 3398 if (i >= 1 && i <= 20) { adc = "ADC capable"; tags.push("adc"); } 3399 if (i === 8) { i2c = "Common SDA"; tags.push("i2c"); } 3400 if (i === 9) { i2c = "Common SCL"; tags.push("i2c"); } 3401 if ([12,13,11,10].includes(i)) { spi = "Common SPI option"; tags.push("spi"); } 3402 if (i === 43) { uart = "UART0 TX on many boards"; tags.push("uart"); status = "Caution"; notes = "Often serial console TX."; } 3403 if (i === 44) { uart = "UART0 RX on many boards"; tags.push("uart"); status = "Caution"; notes = "Often serial console RX."; } 3404 3405 pins.push(pin(i,status,digital,adc,pwm,i2c,spi,uart,notes,tags)); 3406 } 3407 return pins; 3408 } 3409 3410 function c3Pins() { 3411 const pins = []; 3412 for (let i = 0; i <= 21; i++) { 3413 let status = "Good", digital = "Input / Output", adc = "", pwm = "Yes", i2c = "Remappable", spi = "Remappable", uart = "Remappable", notes = "General-purpose GPIO.", tags = ["safe","pwm"]; 3414 3415 if ([2,8,9].includes(i)) { status = "Caution"; notes = "ESP32-C3 strapping pin. Use with care during boot."; tags.push("strap"); } 3416 if ([18,19].includes(i)) { status = "Caution"; notes = "Often USB D-/D+ on native USB C3 boards."; tags.push("avoid"); } 3417 if (i >= 0 && i <= 5) { adc = "ADC capable"; tags.push("adc"); } 3418 if (i === 8) { i2c = "Common SDA / strap"; tags.push("i2c"); } 3419 if (i === 9) { i2c = "Common SCL / strap"; tags.push("i2c"); } 3420 if ([4,5,6,7].includes(i)) { spi = "Common SPI option"; tags.push("spi"); } 3421 if (i === 20) { uart = "UART0 RX on some boards"; tags.push("uart"); } 3422 if (i === 21) { uart = "UART0 TX on some boards"; tags.push("uart"); } 3423 3424 pins.push(pin(i,status,digital,adc,pwm,i2c,spi,uart,notes,tags)); 3425 } 3426 return pins; 3427 } 3428 3429 function c6Pins() { 3430 const pins = []; 3431 for (let i = 0; i <= 23; i++) { 3432 let status = "Good", digital = "Input / Output", adc = "", pwm = "Yes", i2c = "Remappable", spi = "Remappable", uart = "Remappable", notes = "Check exact ESP32-C6 board schematic.", tags = ["safe","pwm"]; 3433 3434 if ([0,8,9,15].includes(i)) { status = "Caution"; notes = "Potential boot or board-function pin. Confirm against board schematic."; tags.push("strap"); } 3435 if ([12,13].includes(i)) { status = "Caution"; notes = "Often USB-related on some boards."; tags.push("avoid"); } 3436 if (i >= 0 && i <= 7) { adc = "ADC capable on many C6 boards"; tags.push("adc"); } 3437 if ([6,7].includes(i)) { i2c = "Common I2C option"; tags.push("i2c"); } 3438 if ([4,5,6,7].includes(i)) { spi = "Common SPI option"; tags.push("spi"); } 3439 3440 pins.push(pin(i,status,digital,adc,pwm,i2c,spi,uart,notes,tags)); 3441 } 3442 return pins; 3443 } 3444 3445 function h2Pins() { 3446 const pins = []; 3447 for (let i = 0; i <= 27; i++) { 3448 let status = "Good", digital = "Input / Output", adc = "", pwm = "Yes", i2c = "Remappable", spi = "Remappable", uart = "Remappable", notes = "Check exact ESP32-H2 board schematic.", tags = ["safe","pwm"]; 3449 3450 if ([0,8,9].includes(i)) { status = "Caution"; notes = "Possible boot or board-function pin. Confirm against schematic."; tags.push("strap"); } 3451 if (i <= 5) { adc = "ADC capable on many H2 boards"; tags.push("adc"); } 3452 if ([10,11].includes(i)) { i2c = "Common I2C option"; tags.push("i2c"); }
3453 if ([4,5,6,7].includes(i)) { spi = "Common SPI option"; tags.push("spi"); } 3454 3455 pins.push(pin(i,status,digital,adc,pwm,i2c,spi,uart,notes,tags)); 3456 } 3457 return pins; 3458 } 3459 3460 function classForStatus(status) { 3461 if (status === "Good") return "pin-good"; 3462 if (status === "Avoid" || status === "Input-only") return "pin-bad"; 3463 return "pin-caution"; 3464 } 3465 3466 function render() { 3467 const board = boards[boardSelect.value]; 3468 const query = searchInput.value.toLowerCase().trim(); 3469 const filter = filterSelect.value; 3470 3471 boardTitle.textContent = board.name; 3472 boardSummary.innerHTML = ` 3473 <p>${board.summary}</p> 3474 <div class="esp32-badges"> 3475 <span class="esp32-badge">Chip: ${board.chip}</span> 3476 <span class="esp32-badge">Pins listed: ${board.pins.length}</span> 3477 <span class="esp32-badge">PWM: GPIO matrix dependent</span> 3478 <span class="esp32-badge">Board schematic still matters</span> 3479 </div> 3480 `; 3481 3482 boardWarnings.innerHTML = board.notes.map(note => `<div class="esp32-warn">${note}</div>`).join(""); 3483 3484 let filtered = board.pins.filter(p => { 3485 const haystack = `${p.gpio} ${p.status} ${p.digital} ${p.adc} ${p.pwm} ${p.i2c} ${p.spi} ${p.uart} ${p.notes} ${p.tags.join(" ")}`.toLowerCase(); 3486 const matchesQuery = !query || haystack.includes(query.replace("gpio","").trim()) || haystack.includes(query); 3487 const matchesFilter = filter === "all" || p.tags.includes(filter) || 3488 (filter === "safe" && p.status === "Good") || 3489 (filter === "input" && p.status === "Input-only"); 3490 return matchesQuery && matchesFilter; 3491 }); 3492 3493 pinTable.innerHTML = filtered.map(p => ` 3494 <tr class="${classForStatus(p.status)}"> 3495 <td><strong>GPIO${p.gpio}</strong></td> 3496 <td>${p.status}</td> 3497 <td>${p.digital || "-"}</td> 3498 <td>${p.adc || "-"}</td> 3499 <td>${p.pwm || "-"}</td> 3500 <td>${p.i2c || "-"}</td> 3501 <td>${p.spi || "-"}</td> 3502 <td>${p.uart || "-"}</td> 3503 <td>${p.notes}</td> 3504 </tr> 3505 `).join(""); 3506 3507 codePinSelect.innerHTML = board.pins 3508 .filter(p => p.status !== "Avoid" && p.digital !== "Reserved") 3509 .map(p => `<option value="${p.gpio}">GPIO${p.gpio} - ${p.status}</option>`) 3510 .join(""); 3511 3512 if (!codePinSelect.value && codePinSelect.options.length) { 3513 codePinSelect.selectedIndex = 0; 3514 } 3515 3516 updateCode(); 3517 } 3518 3519 function updateCode() { 3520 const gpio = codePinSelect.value || 2; 3521 3522 arduinoCode.textContent = 3523`// ESP32 GPIO Example 3524// Selected pin: GPIO${gpio} 3525 3526const int pinNumber = ${gpio}; 3527 3528void setup() { 3529 Serial.begin(115200); 3530 pinMode(pinNumber, OUTPUT); 3531} 3532 3533void loop() { 3534 digitalWrite(pinNumber, HIGH);
3535 delay(500); 3536 digitalWrite(pinNumber, LOW); 3537 delay(500); 3538}`; 3539 3540 microPythonCode.textContent = 3541`# ESP32 MicroPython GPIO Example 3542# Selected pin: GPIO${gpio} 3543 3544from machine import Pin 3545from time import sleep 3546 3547pin = Pin(${gpio}, Pin.OUT) 3548 3549while True: 3550 pin.value(1) 3551 sleep(0.5) 3552 pin.value(0) 3553 sleep(0.5)`; 3554 } 3555 3556 document.querySelectorAll(".esp32-copy").forEach(btn => { 3557 btn.addEventListener("click", function () { 3558 const target = document.getElementById(btn.dataset.copy); 3559 navigator.clipboard.writeText(target.textContent).then(() => { 3560 const old = btn.textContent; 3561 btn.textContent = "Copied!"; 3562 setTimeout(() => btn.textContent = old, 1400); 3563 }); 3564 }); 3565 }); 3566 3567 boardSelect.addEventListener("change", render); 3568 searchInput.addEventListener("input", render); 3569 filterSelect.addEventListener("change", render); 3570 codePinSelect.addEventListener("change", updateCode); 3571 3572 boardSelect.value = "esp32-devkit-v1"; 3573 render(); 3574}); 3575/* ]]> */ 3576</script>
vendor: 1 bytes, line 3576
3576
3577<script type="text/javascript" src="https://www.esp32learning.com/wp-content/plugins/penci-shortcodes/assets/play.js?ver=5.5" id="penci-play-js-js"></script>
vendor: 1 bytes, line 3577
3577
3578<script type="text/javascript" src="https://www.esp32learning.com/wp-content/themes/soledad/js/js-cookies.js?ver=8.5.4" id="js-cookies-js"></script>
vendor: 1 bytes, line 3578
3578
3579<script type="text/javascript" src="https://www.esp32learning.com/wp-content/themes/soledad/js/penci-lazy.js?ver=8.5.4" id="pc-lazy-js"></script>
vendor: 1 bytes, line 3579
3579
3580<script type="text/javascript" src="https://www.esp32learning.com/wp-content/themes/soledad/js/libs-script.min.js?ver=8.5.4" id="penci-libs-js-js"></script>
vendor: 1 bytes, line 3580
3580
3581<script type="text/javascript" id="main-scripts-js-extra"> 3582/* <![CDATA[ */ 3583var ajax_var_more = {"url":"https:\/\/www.esp32learning.com\/wp-admin\/admin-ajax.php","nonce":"a62d7c71ca","errorPass":"<p class=\"message message-error\">Password does not match the confirm password<\/p>","login":"Email Address","password":"Password","headerstyle":"default","reading_bar_pos":"footer","reading_bar_h":"5","carousel_e":"swing","slider_e":"creative","fcarousel_e":"swing","fslider_e":"creative","vfloat":"","vfloatp":"bottom-right","redirect_url":""}; 3584/* ]]> */ 3585</script>
vendor: 1 bytes, line 3585
3585
3586<script type="text/javascript" src="https://www.esp32learning.com/wp-content/themes/soledad/js/main.js?ver=8.5.4" id="main-scripts-js"></script>
vendor: 1 bytes, line 3586
3586
3587<script type="text/javascript" id="penci_ajax_like_post-js-extra"> 3588/* <![CDATA[ */ 3589var ajax_var = {"url":"https:\/\/www.esp32learning.com\/wp-admin\/admin-ajax.php","nonce":"a62d7c71ca","errorPass":"<p class=\"message message-error\">Password does not match the confirm password<\/p>","login":"Email Address","password":"Password","headerstyle":"default","reading_bar_pos":"footer","reading_bar_h":"5","carousel_e":"swing","slider_e":"creative","fcarousel_e":"swing","fslider_e":"creative","vfloat":"","vfloatp":"bottom-right","redirect_url":""}; 3590/* ]]> */ 3591</script>
vendor: 1 bytes, line 3591
3591
3592<script type="text/javascript" src="https://www.esp32learning.com/wp-content/themes/soledad/js/post-like.js?ver=8.5.4" id="penci_ajax_like_post-js"></script>
vendor: 1 bytes, line 3592
3592
3593<script type="text/javascript" src="https://www.esp32learning.com/wp-content/themes/soledad/js/inview.js?ver=8.5.4" id="jquery.inview-js"></script>
vendor: 1 bytes, line 3593
3593
3594<script type="text/javascript" src="https://www.esp32learning.com/wp-content/themes/soledad/js/sticky_share.js?ver=8.5.4" id="penci-sticky-share-js"></script>
vendor: 1 bytes, line 3594
3594
3595<script type="text/javascript" src="https://www.esp32learning.com/wp-content/plugins/enlighter/cache/enlighterjs.min.js?ver=5a3iNMCZFdqvAqB" id="enlighterjs-js"></script>
vendor: 1 bytes, line 3595
3595
3596<script type="text/javascript" id="enlighterjs-js-after"> 3597/* <![CDATA[ */ 3598!function(e,n){if("undefined"!=typeof EnlighterJS){var o={"selectors":{"block":"pre.EnlighterJSRAW","inline":"code.EnlighterJSRAW"},"options":{"indent":4,"ampersandCleanup":true,"linehover":true,"rawcodeDbclick":false,"textOverflow":"break","linenumbers":true,"theme":"enlighter","language":"generic","retainCssClasses":false,"collapse":false,"toolbarOuter":"","toolbarTop":"{BTN_RAW}{BTN_COPY}{BTN_WINDOW}{BTN_WEBSITE}","toolbarBottom":""}};(e.EnlighterJSINIT=function(){EnlighterJS.init(o.selectors.block,o.selectors.inline,o.options)})()}else{(n&&(n.error||n.log)||function(){})("Error: EnlighterJS resources not loaded yet!")}}(window,console); 3599/* ]]> */ 3600</script>
3600 3601<!-- AdRotate JS -->
3602<script type="text/javascript"> 3603jQuery(document).ready(function(){ 3604if(jQuery.fn.gslider) { 3605 jQuery('.g-4').gslider({ groupid: 4, speed: 12000 }); 3606} 3607}); 3608</script>
3608 3609<!-- /AdRotate JS --> 3610 3611<ins class="adsbygoogle Ad-Container sidebar-ad"><div style="z-index:-1; height:0; width:1px; visibility: hidden; bottom: -1px; left: 0;"></div></ins> <div id="penci-adblocker-popup-adblock" 3612 class="mfp-hide mfp-with-anim penci-popup penci-adblocker-popup"> 3613 3614 <div class="penci-adblocker-popup-container"> 3615 <div class="container-wrapper"> 3616 3617 <span class="penci-adblocker-adblock-icon fa fa-exclamation-triangle" aria-hidden="true"></span> 3618 3619 <h2 class="penci-adblocker-head">Adblock Detected</h2> 3620 3621 <div class="penci-adblock-message"> 3622 Please support us by disabling your AdBlocker extension from your browsers for our website. </div> 3623 3624 <div class="penci-adblock-btn-group"> 3625 3626 <button type="button" 3627 class="mfp-close">Dismiss this message</button> 3628 3629 </div> 3630 3631 </div> 3632 </div> 3633 </div> 3634
3634<script type="text/javascript">var penci_options_set = {"ad_blocker_detector":true,"ad_blocker_detector_delay":"5","ad_blocker_detector_dismissable":true,"ad_blocker_detector_onetime":false,"ad_blocker_detector_block_img":false,"ad_blocker_detector_block_img_url":false,"ad_blocker_detector_post":false};(function(e){"use strict";var o=o||{};o.AdBlocker=function(){if(penci_options_set.ad_blocker_detector){var t=e(".Ad-Container");t.length>0&&"none"===t.css("display")&&e(".penci-adblocker-popup").length>0&&(penci_options_set.ad_blocker_detector_delay?setTimeout(function(){o.ShowAdBLockerNotice()},penci_options_set.ad_blocker_detector_delay):o.ShowAdBLockerNotice())}},o.ShowAdBLockerNotice=function(){o.getcookie("penci_adblocker_popup_onetime")||e.magnificPopup.open({items:{src:".penci-adblocker-popup"},type:"inline",removalDelay:500,tClose:!1,tLoading:!1,closeOnBgClick:!1,callbacks:{beforeOpen:function(){this.st.mainClass="mfp-ani-wrap penci-promo-popup-wrapper"},close:function(){penci_options_set.penci_adblocker_popup_onetime&&o.setcookie("penci_adblocker_popup_onetime","1")}}})},o.getcookie=function(e){let o=e+"=",t=decodeURIComponent(document.cookie),n=t.split(";");for(let e=0;e<n.length;e++){let t=n[e];for(;" "==t.charAt(0);)t=t.substring(1);if(0==t.indexOf(o))return t.substring(o.length,t.length)}return""},o.setcookie=function(e,o,t){const n=new Date;n.setTime(n.getTime()+24*t*60*60*1e3);let c="expires="+n.toUTCString();document.cookie=e+"="+o+";"+c+";path=/"},e(document).ready(function(){o.AdBlocker()})})(jQuery);</script>
vendor: 5,969 bytes, line 3634
3634<script type='text/javascript' id="soledad-pagespeed-header" data-cfasync="false">!function(n,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(n="undefined"!=typeof globalThis?globalThis:n||self).LazyLoad=t()}(this,(function(){"use strict";function n(){return n=Object.assign||function(n){for(var t=1;t<arguments.length;t++){var e=arguments[t];for(var i in e)Object.prototype.hasOwnProperty.call(e,i)&&(n[i]=e[i])}return n},n.apply(this,arguments)}var t="undefined"!=typeof window,e=t&&!("onscroll"in window)||"undefined"!=typeof navigator&&/(gle|ing|ro)bot|crawl|spider/i.test(navigator.userAgent),i=t&&"IntersectionObserver"in window,o=t&&"classList"in document.createElement("p"),a=t&&window.devicePixelRatio>1,r={elements_selector:".lazy",container:e||t?document:null,threshold:300,thresholds:null,data_src:"src",data_srcset:"srcset",data_sizes:"sizes",data_bg:"bg",data_bg_hidpi:"bg-hidpi",data_bg_multi:"bg-multi",data_bg_multi_hidpi:"bg-multi-hidpi",data_poster:"poster",class_applied:"applied",class_loading:"loading",class_loaded:"loaded",class_error:"error",class_entered:"entered",class_exited:"exited",unobserve_completed:!0,unobserve_entered:!1,cancel_on_exit:!0,callback_enter:null,callback_exit:null,callback_applied:null,callback_loading:null,callback_loaded:null,callback_error:null,callback_finish:null,callback_cancel:null,use_native:!1},c=function(t){return n({},r,t)},u=function(n,t){var e,i="LazyLoad::Initialized",o=new n(t);try{e=new CustomEvent(i,{detail:{instance:o}})}catch(n){(e=document.createEvent("CustomEvent")).initCustomEvent(i,!1,!1,{instance:o})}window.dispatchEvent(e)},l="src",s="srcset",f="sizes",d="poster",_="llOriginalAttrs",g="loading",v="loaded",b="applied",p="error",h="native",m="data-",E="ll-status",I=function(n,t){return n.getAttribute(m+t)},y=function(n){return I(n,E)},A=function(n,t){return function(n,t,e){var i="data-ll-status";null!==e?n.setAttribute(i,e):n.removeAttribute(i)}(n,0,t)},k=function(n){return A(n,null)},L=function(n){return null===y(n)},w=function(n){return y(n)===h},x=[g,v,b,p],O=function(n,t,e,i){n&&(void 0===i?void 0===e?n(t):n(t,e):n(t,e,i))},N=function(n,t){o?n.classList.add(t):n.className+=(n.className?" ":"")+t},C=function(n,t){o?n.classList.remove(t):n.className=n.className.replace(new RegExp("(^|\\s+)"+t+"(\\s+|$)")," ").replace(/^\s+/,"").replace(/\s+$/,"")},M=function(n){return n.llTempImage},z=function(n,t){if(t){var e=t._observer;e&&e.unobserve(n)}},R=function(n,t){n&&(n.loadingCount+=t)},T=function(n,t){n&&(n.toLoadCount=t)},G=function(n){for(var t,e=[],i=0;t=n.children[i];i+=1)"SOURCE"===t.tagName&&e.push(t);return e},D=function(n,t){var e=n.parentNode;e&&"PICTURE"===e.tagName&&G(e).forEach(t)},V=function(n,t){G(n).forEach(t)},F=[l],j=[l,d],P=[l,s,f],S=function(n){return!!n[_]},U=function(n){return n[_]},$=function(n){return delete n[_]},q=function(n,t){if(!S(n)){var e={};t.forEach((function(t){e[t]=n.getAttribute(t)})),n[_]=e}},H=function(n,t){if(S(n)){var e=U(n);t.forEach((function(t){!function(n,t,e){e?n.setAttribute(t,e):n.removeAttribute(t)}(n,t,e[t])}))}},B=function(n,t,e){N(n,t.class_loading),A(n,g),e&&(R(e,1),O(t.callback_loading,n,e))},J=function(n,t,e){e&&n.setAttribute(t,e)},K=function(n,t){J(n,f,I(n,t.data_sizes)),J(n,s,I(n,t.data_srcset)),J(n,l,I(n,t.data_src))},Q={IMG:function(n,t){D(n,(function(n){q(n,P),K(n,t)})),q(n,P),K(n,t)},IFRAME:function(n,t){q(n,F),J(n,l,I(n,t.data_src))},VIDEO:function(n,t){V(n,(function(n){q(n,F),J(n,l,I(n,t.data_src))})),q(n,j),J(n,d,I(n,t.data_poster)),J(n,l,I(n,t.data_src)),n.load()}},W=["IMG","IFRAME","VIDEO"],X=function(n,t){!t||function(n){return n.loadingCount>0}(t)||function(n){return n.toLoadCount>0}(t)||O(n.callback_finish,t)},Y=function(n,t,e){n.addEventListener(t,e),n.llEvLisnrs[t]=e},Z=function(n,t,e){n.removeEventListener(t,e)},nn=function(n){return!!n.llEvLisnrs},tn=function(n){if(nn(n)){var t=n.llEvLisnrs;for(var e in t){var i=t[e];Z(n,e,i)}delete n.llEvLisnrs}},en=function(n,t,e){!function(n){delete n.llTempImage}(n),R(e,-1),function(n){n&&(n.toLoadCount-=1)}(e),C(n,t.class_loading),t.unobserve_completed&&z(n,e)},on=function(n,t,e){var i=M(n)||n;nn(i)||function(n,t,e){nn(n)||(n.llEvLisnrs={});var i="VIDEO"===n.tagName?"loadeddata":"load";Y(n,i,t),Y(n,"error",e)}(i,(function(o){!function(n,t,e,i){var o=w(t);en(t,e,i),N(t,e.class_loaded),A(t,v),O(e.callback_loaded,t,i),o||X(e,i)}(0,n,t,e),tn(i)}),(function(o){!function(n,t,e,i){var o=w(t);en(t,e,i),N(t,e.class_error),A(t,p),O(e.callback_error,t,i),o||X(e,i)}(0,n,t,e),tn(i)}))},an=function(n,t,e){!function(n){n.llTempImage=document.createElement("IMG")}(n),on(n,t,e),function(n){S(n)||(n[_]={backgroundImage:n.style.backgroundImage})}(n),function(n,t,e){var i=I(n,t.data_bg),o=I(n,t.data_bg_hidpi),r=a&&o?o:i;r&&(n.style.backgroundImage='url("'.concat(r,'")'),M(n).setAttribute(l,r),B(n,t,e))}(n,t,e),function(n,t,e){var i=I(n,t.data_bg_multi),o=I(n,t.data_bg_multi_hidpi),r=a&&o?o:i;r&&(n.style.backgroundImage=r,function(n,t,e){N(n,t.class_applied),A(n,b),e&&(t.unobserve_completed&&z(n,t),O(t.callback_applied,n,e))}(n,t,e))}(n,t,e)},rn=function(n,t,e){!function(n){return W.indexOf(n.tagName)>-1}(n)?an(n,t,e):function(n,t,e){on(n,t,e),function(n,t,e){var i=Q[n.tagName];i&&(i(n,t),B(n,t,e))}(n,t,e)}(n,t,e)},cn=function(n){n.removeAttribute(l),n.removeAttribute(s),n.removeAttribute(f)},un=function(n){D(n,(function(n){H(n,P)})),H(n,P)},ln={IMG:un,IFRAME:function(n){H(n,F)},VIDEO:function(n){V(n,(function(n){H(n,F)})),H(n,j),n.load()}},sn=function(n,t){(function(n){var t=ln[n.tagName];t?t(n):function(n){if(S(n)){var t=U(n);n.style.backgroundImage=t.backgroundImage}}(n)})(n),function(n,t){L(n)||w(n)||(C(n,t.class_entered),C(n,t.class_exited),C(n,t.class_applied),C(n,t.class_loading),C(n,t.class_loaded),C(n,t.class_error))}(n,t),k(n),$(n)},fn=["IMG","IFRAME","VIDEO"],dn=function(n){return n.use_native&&"loading"in HTMLImageElement.prototype}
3634,_n=function(n,t,e){n.forEach((function(n){return function(n){return n.isIntersecting||n.intersectionRatio>0}(n)?function(n,t,e,i){var o=function(n){return x.indexOf(y(n))>=0}(n);A(n,"entered"),N(n,e.class_entered),C(n,e.class_exited),function(n,t,e){t.unobserve_entered&&z(n,e)}(n,e,i),O(e.callback_enter,n,t,i),o||rn(n,e,i)}(n.target,n,t,e):function(n,t,e,i){L(n)||(N(n,e.class_exited),function(n,t,e,i){e.cancel_on_exit&&function(n){return y(n)===g}(n)&&"IMG"===n.tagName&&(tn(n),function(n){D(n,(function(n){cn(n)})),cn(n)}(n),un(n),C(n,e.class_loading),R(i,-1),k(n),O(e.callback_cancel,n,t,i))}(n,t,e,i),O(e.callback_exit,n,t,i))}(n.target,n,t,e)}))},gn=function(n){return Array.prototype.slice.call(n)},vn=function(n){return n.container.querySelectorAll(n.elements_selector)},bn=function(n){return function(n){return y(n)===p}(n)},pn=function(n,t){return function(n){return gn(n).filter(L)}(n||vn(t))},hn=function(n,e){var o=c(n);this._settings=o,this.loadingCount=0,function(n,t){i&&!dn(n)&&(t._observer=new IntersectionObserver((function(e){_n(e,n,t)}),function(n){return{root:n.container===document?null:n.container,rootMargin:n.thresholds||n.threshold+"px"}}(n)))}(o,this),function(n,e){t&&window.addEventListener("online",(function(){!function(n,t){var e;(e=vn(n),gn(e).filter(bn)).forEach((function(t){C(t,n.class_error),k(t)})),t.update()}(n,e)}))}(o,this),this.update(e)};return hn.prototype={update:function(n){var t,o,a=this._settings,r=pn(n,a);T(this,r.length),!e&&i?dn(a)?function(n,t,e){n.forEach((function(n){-1!==fn.indexOf(n.tagName)&&function(n,t,e){n.setAttribute("loading","lazy"),on(n,t,e),function(n,t){var e=Q[n.tagName];e&&e(n,t)}(n,t),A(n,h)}(n,t,e)})),T(e,0)}(r,a,this):(o=r,function(n){n.disconnect()}(t=this._observer),function(n,t){t.forEach((function(t){n.observe(t)}))}(t,o)):this.loadAll(r)},destroy:function(){this._observer&&this._observer.disconnect(),vn(this._settings).forEach((function(n){$(n)})),delete this._observer,delete this._settings,delete this.loadingCount,delete this.toLoadCount},loadAll:function(n){var t=this,e=this._settings;pn(n,e).forEach((function(n){z(n,t),rn(n,e,t)}))},restoreAll:function(){var n=this._settings;vn(n).forEach((function(t){sn(t,n)}))}},hn.load=function(n,t){var e=c(t);rn(n,e)},hn.resetStatus=function(n){k(n)},t&&function(n,t){if(t)if(t.length)for(var e,i=0;e=t[i];i+=1)u(n,e);else u(n,t)}(hn,window.lazyLoadOptions),hn})); 3635 3636(function () { 3637 3638 var PenciLazy = new LazyLoad({ 3639 elements_selector: '.penci-lazy', 3640 data_bg: 'bgset', 3641 class_loading: 'lazyloading', 3642 class_entered: 'lazyloaded', 3643 class_loaded: 'pcloaded', 3644 unobserve_entered: true 3645 }); 3646 3647 MutationObserver = window.MutationObserver || window.WebKitMutationObserver; 3648 3649 var observer = new MutationObserver(function(mutations, observer) { 3650 PenciLazy.update(); 3651 }); 3652 3653 observer.observe(document, { 3654 subtree: true, 3655 attributes: true 3656 }); 3657})(); 3658</script>
3658 3659</body> 3660</html>
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.