{"id":5364,"date":"2023-02-19T13:45:39","date_gmt":"2023-02-19T12:45:39","guid":{"rendered":"https:\/\/www.pschatzmann.ch\/home\/?p=5364"},"modified":"2023-02-19T19:38:56","modified_gmt":"2023-02-19T18:38:56","slug":"supporting-wm8960-audio-boards","status":"publish","type":"post","link":"https:\/\/www.pschatzmann.ch\/home\/2023\/02\/19\/supporting-wm8960-audio-boards\/","title":{"rendered":"Supporting WM8960 Audio Boards in Arduino"},"content":{"rendered":"<p>The <strong>WM8960<\/strong> based boards are quite popular as Audio Modules for the <strong>Rasperry Pi<\/strong> and I had one of these laying around. So I had it always on my to-do list to extend my <a href=\"https:\/\/github.com\/pschatzmann\/arduino-audio-tools\">AudioTools library<\/a> to support this audio chip as well, so that it can be used in <strong>Arduino<\/strong>.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.pschatzmann.ch\/wp-content\/uploads\/2023\/02\/WM8960-Audio-HAT-1.jpeg\" alt=\"\" width=\"300\" height=\"225\" class=\"alignnone size-full wp-image-5379\" \/><\/p>\n<p>I started last year to convert the <a href=\"https:\/\/github.com\/Infineon\/audio-codec-wm8960\">audio-codec-wm8960<\/a> library provided by <strong>Infinion<\/strong> by making sure that the i2c calls are using the <strong>Wire library<\/strong> and this week I decided to bring it to an end.<\/p>\n<p>But it turned out to be more difficult then initially thought. Whatever I did, I was getting error messages when I wanted to write to the registers of the wm8960! I tried to google the topic when I found that in the meantime <a href=\"https:\/\/github.com\/sparkfun\/SparkFun_WM8960_Arduino_Library\">Sparkfun was providing an Arduino library<\/a> as well. So I tried this one, but with the same result: I was <strong>only getting errors<\/strong>!<\/p>\n<p>When I started to reduce the speed by calling Wire.setClock(10000) things started to improve slightly, so extended the logic to retry to update the register until it succeeds, which was turning out to be quite reliable. Today I replaced the <strong>Jumper Cables<\/strong> with <strong>shorter<\/strong> ones and this did the trick!<\/p>\n<p>You can use the <a href=\"https:\/\/pschatzmann.github.io\/arduino-audio-tools\/classaudio__tools_1_1_w_m8960_stream.html\">WM8960Stream class<\/a> to read audio data from the microphone or write audio data to the Amplifier.<\/p>\n<h2>Arduino Sketch<\/h2>\n<p>Here is a simple Arduino test sketch.<\/p>\n<pre><code><br \/>#include \"AudioTools.h\"\n#include \"AudioLibs\/WM8960Stream.h\"\n\nuint16_t sample_rate=44100;\nuint8_t channels = 2;                                      \/\/ The stream will have 2 channels \nSineWaveGenerator&lt;int16_t&gt; sineWave(32000);                \/\/ subclass of SoundGenerator with max amplitude of 32000\nGeneratedSoundStream&lt;int16_t&gt; sound(sineWave);             \/\/ Stream generated from sine wave\nWM8960Stream out; \nStreamCopy copier(out, sound);                             \/\/ copies sound into i2s\n\n\/\/ Arduino Setup\nvoid setup(void) {  \n  \/\/ Open Serial \n  Serial.begin(115200);\n  while(!Serial);\n  AudioLogger::instance().begin(Serial, AudioLogger::Warning);\n\n  \/\/ setup wire on pins 19 and 21\n  Wire.begin(19, 21);\n  Wire.setClock(10000);\n\n\n  \/\/ start I2S\n  Serial.println(\"starting I2S...\");\n  auto config = out.defaultConfig(TX_MODE);\n  config.sample_rate = sample_rate; \n  config.channels = channels;\n  config.bits_per_sample = 16;\n  config.wire = &amp;Wire;\n  \/\/ use default i2s pins \n  \/\/config.pin_bck = 14;\n  \/\/config.pin_ws = 15;\n  \/\/config.pin_data = 22;\n\n  if (!out.begin(config)){\n    stop();\n  }\n\n  \/\/ Setup sine wave\n  sineWave.begin(channels, sample_rate, N_B4);\n  Serial.println(\"started...\");\n}\n\n\/\/ Arduino loop - copy sound to out \nvoid loop() {\n  copier.copy();\n}\n\n<\/code><\/pre>\n<p>This (potentially updated) example can be found on <a href=\"https:\/\/github.com\/pschatzmann\/arduino-audio-tools\/blob\/main\/examples\/examples-stream\/streams-generator-wm8960\/streams-generator-wm8960.ino\">Github<\/a>.<\/p>\n<p>And last but not least, here is the <a href=\"https:\/\/github.com\/pschatzmann\/arduino-wm8960\/wiki\/Pins-Connections\">information on how to connect the different modules<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>The WM8960 based boards are quite popular as Audio Modules for the Rasperry Pi and I had one of these laying around. So I had it always on my to-do list to extend my AudioTools library to support this audio chip as well, so that it can be used in [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":5379,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_crdt_document":"","_import_markdown_pro_load_document_selector":0,"_import_markdown_pro_submit_text_textarea":"","_exactmetrics_skip_tracking":false,"_exactmetrics_sitenote_active":false,"_exactmetrics_sitenote_note":"","_exactmetrics_sitenote_category":0,"footnotes":""},"categories":[20,22],"tags":[],"class_list":["post-5364","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-arduino","category-machine-sound"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.5 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Supporting WM8960 Audio Boards in Arduino - Phil Schatzmann<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.pschatzmann.ch\/home\/2023\/02\/19\/supporting-wm8960-audio-boards\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Supporting WM8960 Audio Boards in Arduino - Phil Schatzmann\" \/>\n<meta property=\"og:description\" content=\"The WM8960 based boards are quite popular as Audio Modules for the Rasperry Pi and I had one of these laying around. So I had it always on my to-do list to extend my AudioTools library to support this audio chip as well, so that it can be used in [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.pschatzmann.ch\/home\/2023\/02\/19\/supporting-wm8960-audio-boards\/\" \/>\n<meta property=\"og:site_name\" content=\"Phil Schatzmann\" \/>\n<meta property=\"article:published_time\" content=\"2023-02-19T12:45:39+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2023-02-19T18:38:56+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.pschatzmann.ch\/wp-content\/uploads\/2023\/02\/WM8960-Audio-HAT-1.jpeg\" \/>\n\t<meta property=\"og:image:width\" content=\"300\" \/>\n\t<meta property=\"og:image:height\" content=\"225\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"pschatzmann\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"pschatzmann\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.pschatzmann.ch\\\/home\\\/2023\\\/02\\\/19\\\/supporting-wm8960-audio-boards\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.pschatzmann.ch\\\/home\\\/2023\\\/02\\\/19\\\/supporting-wm8960-audio-boards\\\/\"},\"author\":{\"name\":\"pschatzmann\",\"@id\":\"https:\\\/\\\/www.pschatzmann.ch\\\/home\\\/#\\\/schema\\\/person\\\/73a53638a4e34e8373405fd737dac9b1\"},\"headline\":\"Supporting WM8960 Audio Boards in Arduino\",\"datePublished\":\"2023-02-19T12:45:39+00:00\",\"dateModified\":\"2023-02-19T18:38:56+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.pschatzmann.ch\\\/home\\\/2023\\\/02\\\/19\\\/supporting-wm8960-audio-boards\\\/\"},\"wordCount\":265,\"commentCount\":1,\"publisher\":{\"@id\":\"https:\\\/\\\/www.pschatzmann.ch\\\/home\\\/#\\\/schema\\\/person\\\/73a53638a4e34e8373405fd737dac9b1\"},\"image\":{\"@id\":\"https:\\\/\\\/www.pschatzmann.ch\\\/home\\\/2023\\\/02\\\/19\\\/supporting-wm8960-audio-boards\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.pschatzmann.ch\\\/wp-content\\\/uploads\\\/2023\\\/02\\\/WM8960-Audio-HAT-1.jpeg\",\"articleSection\":[\"Arduino\",\"Machine Sound\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/www.pschatzmann.ch\\\/home\\\/2023\\\/02\\\/19\\\/supporting-wm8960-audio-boards\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.pschatzmann.ch\\\/home\\\/2023\\\/02\\\/19\\\/supporting-wm8960-audio-boards\\\/\",\"url\":\"https:\\\/\\\/www.pschatzmann.ch\\\/home\\\/2023\\\/02\\\/19\\\/supporting-wm8960-audio-boards\\\/\",\"name\":\"Supporting WM8960 Audio Boards in Arduino - Phil Schatzmann\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.pschatzmann.ch\\\/home\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.pschatzmann.ch\\\/home\\\/2023\\\/02\\\/19\\\/supporting-wm8960-audio-boards\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.pschatzmann.ch\\\/home\\\/2023\\\/02\\\/19\\\/supporting-wm8960-audio-boards\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.pschatzmann.ch\\\/wp-content\\\/uploads\\\/2023\\\/02\\\/WM8960-Audio-HAT-1.jpeg\",\"datePublished\":\"2023-02-19T12:45:39+00:00\",\"dateModified\":\"2023-02-19T18:38:56+00:00\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.pschatzmann.ch\\\/home\\\/2023\\\/02\\\/19\\\/supporting-wm8960-audio-boards\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.pschatzmann.ch\\\/home\\\/2023\\\/02\\\/19\\\/supporting-wm8960-audio-boards\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.pschatzmann.ch\\\/home\\\/2023\\\/02\\\/19\\\/supporting-wm8960-audio-boards\\\/#primaryimage\",\"url\":\"https:\\\/\\\/www.pschatzmann.ch\\\/wp-content\\\/uploads\\\/2023\\\/02\\\/WM8960-Audio-HAT-1.jpeg\",\"contentUrl\":\"https:\\\/\\\/www.pschatzmann.ch\\\/wp-content\\\/uploads\\\/2023\\\/02\\\/WM8960-Audio-HAT-1.jpeg\",\"width\":300,\"height\":225},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.pschatzmann.ch\\\/home\\\/2023\\\/02\\\/19\\\/supporting-wm8960-audio-boards\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.pschatzmann.ch\\\/home\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Supporting WM8960 Audio Boards in Arduino\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.pschatzmann.ch\\\/home\\\/#website\",\"url\":\"https:\\\/\\\/www.pschatzmann.ch\\\/home\\\/\",\"name\":\"Phil Schatzmann Consulting\",\"description\":\"\",\"publisher\":{\"@id\":\"https:\\\/\\\/www.pschatzmann.ch\\\/home\\\/#\\\/schema\\\/person\\\/73a53638a4e34e8373405fd737dac9b1\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.pschatzmann.ch\\\/home\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":[\"Person\",\"Organization\"],\"@id\":\"https:\\\/\\\/www.pschatzmann.ch\\\/home\\\/#\\\/schema\\\/person\\\/73a53638a4e34e8373405fd737dac9b1\",\"name\":\"pschatzmann\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.pschatzmann.ch\\\/wp-content\\\/uploads\\\/2022\\\/08\\\/pschatzmann.png\",\"url\":\"https:\\\/\\\/www.pschatzmann.ch\\\/wp-content\\\/uploads\\\/2022\\\/08\\\/pschatzmann.png\",\"contentUrl\":\"https:\\\/\\\/www.pschatzmann.ch\\\/wp-content\\\/uploads\\\/2022\\\/08\\\/pschatzmann.png\",\"width\":305,\"height\":305,\"caption\":\"pschatzmann\"},\"logo\":{\"@id\":\"https:\\\/\\\/www.pschatzmann.ch\\\/wp-content\\\/uploads\\\/2022\\\/08\\\/pschatzmann.png\"}}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Supporting WM8960 Audio Boards in Arduino - Phil Schatzmann","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.pschatzmann.ch\/home\/2023\/02\/19\/supporting-wm8960-audio-boards\/","og_locale":"en_US","og_type":"article","og_title":"Supporting WM8960 Audio Boards in Arduino - Phil Schatzmann","og_description":"The WM8960 based boards are quite popular as Audio Modules for the Rasperry Pi and I had one of these laying around. So I had it always on my to-do list to extend my AudioTools library to support this audio chip as well, so that it can be used in [&hellip;]","og_url":"https:\/\/www.pschatzmann.ch\/home\/2023\/02\/19\/supporting-wm8960-audio-boards\/","og_site_name":"Phil Schatzmann","article_published_time":"2023-02-19T12:45:39+00:00","article_modified_time":"2023-02-19T18:38:56+00:00","og_image":[{"width":300,"height":225,"url":"https:\/\/www.pschatzmann.ch\/wp-content\/uploads\/2023\/02\/WM8960-Audio-HAT-1.jpeg","type":"image\/jpeg"}],"author":"pschatzmann","twitter_card":"summary_large_image","twitter_misc":{"Written by":"pschatzmann","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.pschatzmann.ch\/home\/2023\/02\/19\/supporting-wm8960-audio-boards\/#article","isPartOf":{"@id":"https:\/\/www.pschatzmann.ch\/home\/2023\/02\/19\/supporting-wm8960-audio-boards\/"},"author":{"name":"pschatzmann","@id":"https:\/\/www.pschatzmann.ch\/home\/#\/schema\/person\/73a53638a4e34e8373405fd737dac9b1"},"headline":"Supporting WM8960 Audio Boards in Arduino","datePublished":"2023-02-19T12:45:39+00:00","dateModified":"2023-02-19T18:38:56+00:00","mainEntityOfPage":{"@id":"https:\/\/www.pschatzmann.ch\/home\/2023\/02\/19\/supporting-wm8960-audio-boards\/"},"wordCount":265,"commentCount":1,"publisher":{"@id":"https:\/\/www.pschatzmann.ch\/home\/#\/schema\/person\/73a53638a4e34e8373405fd737dac9b1"},"image":{"@id":"https:\/\/www.pschatzmann.ch\/home\/2023\/02\/19\/supporting-wm8960-audio-boards\/#primaryimage"},"thumbnailUrl":"https:\/\/www.pschatzmann.ch\/wp-content\/uploads\/2023\/02\/WM8960-Audio-HAT-1.jpeg","articleSection":["Arduino","Machine Sound"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.pschatzmann.ch\/home\/2023\/02\/19\/supporting-wm8960-audio-boards\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.pschatzmann.ch\/home\/2023\/02\/19\/supporting-wm8960-audio-boards\/","url":"https:\/\/www.pschatzmann.ch\/home\/2023\/02\/19\/supporting-wm8960-audio-boards\/","name":"Supporting WM8960 Audio Boards in Arduino - Phil Schatzmann","isPartOf":{"@id":"https:\/\/www.pschatzmann.ch\/home\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.pschatzmann.ch\/home\/2023\/02\/19\/supporting-wm8960-audio-boards\/#primaryimage"},"image":{"@id":"https:\/\/www.pschatzmann.ch\/home\/2023\/02\/19\/supporting-wm8960-audio-boards\/#primaryimage"},"thumbnailUrl":"https:\/\/www.pschatzmann.ch\/wp-content\/uploads\/2023\/02\/WM8960-Audio-HAT-1.jpeg","datePublished":"2023-02-19T12:45:39+00:00","dateModified":"2023-02-19T18:38:56+00:00","breadcrumb":{"@id":"https:\/\/www.pschatzmann.ch\/home\/2023\/02\/19\/supporting-wm8960-audio-boards\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.pschatzmann.ch\/home\/2023\/02\/19\/supporting-wm8960-audio-boards\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.pschatzmann.ch\/home\/2023\/02\/19\/supporting-wm8960-audio-boards\/#primaryimage","url":"https:\/\/www.pschatzmann.ch\/wp-content\/uploads\/2023\/02\/WM8960-Audio-HAT-1.jpeg","contentUrl":"https:\/\/www.pschatzmann.ch\/wp-content\/uploads\/2023\/02\/WM8960-Audio-HAT-1.jpeg","width":300,"height":225},{"@type":"BreadcrumbList","@id":"https:\/\/www.pschatzmann.ch\/home\/2023\/02\/19\/supporting-wm8960-audio-boards\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.pschatzmann.ch\/home\/"},{"@type":"ListItem","position":2,"name":"Supporting WM8960 Audio Boards in Arduino"}]},{"@type":"WebSite","@id":"https:\/\/www.pschatzmann.ch\/home\/#website","url":"https:\/\/www.pschatzmann.ch\/home\/","name":"Phil Schatzmann Consulting","description":"","publisher":{"@id":"https:\/\/www.pschatzmann.ch\/home\/#\/schema\/person\/73a53638a4e34e8373405fd737dac9b1"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.pschatzmann.ch\/home\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":["Person","Organization"],"@id":"https:\/\/www.pschatzmann.ch\/home\/#\/schema\/person\/73a53638a4e34e8373405fd737dac9b1","name":"pschatzmann","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.pschatzmann.ch\/wp-content\/uploads\/2022\/08\/pschatzmann.png","url":"https:\/\/www.pschatzmann.ch\/wp-content\/uploads\/2022\/08\/pschatzmann.png","contentUrl":"https:\/\/www.pschatzmann.ch\/wp-content\/uploads\/2022\/08\/pschatzmann.png","width":305,"height":305,"caption":"pschatzmann"},"logo":{"@id":"https:\/\/www.pschatzmann.ch\/wp-content\/uploads\/2022\/08\/pschatzmann.png"}}]}},"post_mailing_queue_ids":[],"_links":{"self":[{"href":"https:\/\/www.pschatzmann.ch\/home\/wp-json\/wp\/v2\/posts\/5364","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.pschatzmann.ch\/home\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.pschatzmann.ch\/home\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.pschatzmann.ch\/home\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.pschatzmann.ch\/home\/wp-json\/wp\/v2\/comments?post=5364"}],"version-history":[{"count":16,"href":"https:\/\/www.pschatzmann.ch\/home\/wp-json\/wp\/v2\/posts\/5364\/revisions"}],"predecessor-version":[{"id":5388,"href":"https:\/\/www.pschatzmann.ch\/home\/wp-json\/wp\/v2\/posts\/5364\/revisions\/5388"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.pschatzmann.ch\/home\/wp-json\/wp\/v2\/media\/5379"}],"wp:attachment":[{"href":"https:\/\/www.pschatzmann.ch\/home\/wp-json\/wp\/v2\/media?parent=5364"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.pschatzmann.ch\/home\/wp-json\/wp\/v2\/categories?post=5364"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.pschatzmann.ch\/home\/wp-json\/wp\/v2\/tags?post=5364"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}