{"id":25277,"date":"2018-10-09T09:53:35","date_gmt":"2018-10-09T16:53:35","guid":{"rendered":"https:\/\/blog.digilentinc.com\/?p=25277"},"modified":"2021-06-09T13:51:52","modified_gmt":"2021-06-09T20:51:52","slug":"analog-discovery-2-communicates-with-arduino","status":"publish","type":"post","link":"https:\/\/digilent.com\/blog\/analog-discovery-2-communicates-with-arduino\/","title":{"rendered":"Analog Discovery 2 Communicates with Arduino"},"content":{"rendered":"<p>Recently, for a project I was doing, I wanted to use the <a href=\"https:\/\/digilent.com\/shop\/analog-discovery-2-100msps-usb-oscilloscope-logic-analyzer-and-variable-power-supply\/\">Analog Discovery 2<\/a> to help intelligently interpret live audio and send the data to LED strips controlled by an Arduino. However, in order to do this, I would need<a href=\"https:\/\/digilent.com\/shop\/waveforms-previously-waveforms-2015\/\"> WaveForms<\/a> to have some way to talk to the Arduino. After exploring some options on my own, I turned to the <a href=\"https:\/\/forum.digilent.com\/\">Digilent Forum\u00a0<\/a>and posted the following question.<\/p>\n<figure id=\"attachment_25318\" aria-describedby=\"caption-attachment-25318\" style=\"width: 600px\" class=\"wp-caption aligncenter\"><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-25318 size-medium\" src=\"https:\/\/digilent.com\/blog\/wp-content\/uploads\/2018\/08\/ave22-600x166.png\" alt=\"\" width=\"600\" height=\"166\" data-wp-pid=\"25318\" srcset=\"https:\/\/digilent.com\/blog\/wp-content\/uploads\/2018\/08\/ave22-600x166.png 600w, https:\/\/digilent.com\/blog\/wp-content\/uploads\/2018\/08\/ave22-768x212.png 768w, https:\/\/digilent.com\/blog\/wp-content\/uploads\/2018\/08\/ave22-1024x283.png 1024w, https:\/\/digilent.com\/blog\/wp-content\/uploads\/2018\/08\/ave22-800x221.png 800w, https:\/\/digilent.com\/blog\/wp-content\/uploads\/2018\/08\/ave22.png 1294w\" sizes=\"auto, (max-width: 600px) 100vw, 600px\" \/><figcaption id=\"caption-attachment-25318\" class=\"wp-caption-text\">I am trying to send oscilloscope data from the Analog Discovery 2 to the Arduino Uno. Would there be a way I could do this so that the Arduino could read it in live time?<\/figcaption><\/figure>\n<p>Before I knew it I had a solution proposed to me by attila, a Technical Forum Moderator and WaveForms software developer. He suggested using the Python libraries in WaveForms SDK by doing the following:<\/p>\n<blockquote><p>You could use the WaveForms SDK.\u00a0Starting with the AnalogIn_Record_int16.py or\u00a0AnalogIn_Record.py\u00a0example\u00a0script and modifying it to send the data chunks from the record loop to the desired protocol (like COM),\u00a0or using the device DIO (see Digital_Spi.py, Digital_Uart.py, Digital_I2c.py)<br \/>\nThe examples are located in the following path: C:\/Program Files (x86)\/Digilent\/WaveFormsSDK\/samples\/py\/<br \/>\n<a title=\"Enlarge image\" href=\"https:\/\/forum.digilent.com\/uploads\/monthly_2018_07\/image.png.0f88183b5798f461989d6d3eda2669f5.png\" data-ipslightbox=\"\" data-ipslightbox-group=\"g80342\"><img decoding=\"async\" class=\"ipsImage ipsImage_thumbnailed\" src=\"https:\/\/forum.digilent.com\/uploads\/monthly_2018_07\/image.png.0f88183b5798f461989d6d3eda2669f5.png\" alt=\"image.png.0f88183b5798f461989d6d3eda2669f5.png\" data-fileid=\"7499\" \/><\/a><\/p><\/blockquote>\n<p>He also suggested that I could also send acquisition data over SPI with a custom script in the script editor like the one shown below:<\/p>\n<p><a class=\"ipsAttachLink ipsAttachLink_image\" href=\"https:\/\/forum.digilent.com\/uploads\/monthly_2018_07\/image.png.e085b15f20f25a653fc8c6f8c7d578a7.png\" rel=\"\" data-fileid=\"7498\" data-ipslightbox=\"\" data-ipslightbox-group=\"g80342\"><img decoding=\"async\" class=\"ipsImage ipsImage_thumbnailed\" src=\"https:\/\/forum.digilent.com\/uploads\/monthly_2018_07\/image.thumb.png.9cd9a4660b5dd7cc9882b195e71307c7.png\" alt=\"image.thumb.png.9cd9a4660b5dd7cc9882b195e71307c7.png\" data-fileid=\"7498\" \/><\/a><\/p>\n<pre class=\"ipsCode prettyprint lang-javascript prettyprinted\">Scope1<span class=\"pun\">.<\/span><span class=\"pln\">run<\/span><span class=\"pun\">()<\/span>\r\n<span class=\"kwd\">while<\/span><span class=\"pun\">(<\/span>Scope1<span class=\"pun\">.<\/span><span class=\"pln\">wait<\/span><span class=\"pun\">()){<\/span>\r\n    <span class=\"kwd\">var<\/span><span class=\"pln\"> rg16 <\/span><span class=\"pun\">=<\/span> <span class=\"pun\">[]<\/span>\r\n    <span class=\"kwd\">var<\/span><span class=\"pln\"> r <\/span><span class=\"pun\">=<\/span> Scope1<span class=\"pun\">.<\/span>Channel1<span class=\"pun\">.<\/span>Range<span class=\"pun\">.<\/span><span class=\"pln\">value\r\n    <\/span><span class=\"kwd\">var<\/span><span class=\"pln\"> o <\/span><span class=\"pun\">=<\/span> Scope1<span class=\"pun\">.<\/span>Channel1<span class=\"pun\">.<\/span>Offset<span class=\"pun\">.<\/span><span class=\"pln\">value\r\n    <\/span><span class=\"com\">\/\/ convert float to 16bit integer<\/span>\r\n    Scope1<span class=\"pun\">.<\/span>Channel1<span class=\"pun\">.<\/span><span class=\"pln\">alldata<\/span><span class=\"pun\">.<\/span><span class=\"pln\">forEach<\/span><span class=\"pun\">(<\/span><span class=\"kwd\">function<\/span><span class=\"pun\">(<\/span><span class=\"pln\">v<\/span><span class=\"pun\">){<\/span><span class=\"pln\">\r\n        rg16<\/span><span class=\"pun\">.<\/span><span class=\"pln\">push<\/span><span class=\"pun\">(<\/span><span class=\"pln\">max<\/span><span class=\"pun\">(-<\/span><span class=\"lit\">32768<\/span><span class=\"pun\">,<\/span><span class=\"pln\"> min<\/span><span class=\"pun\">(<\/span><span class=\"lit\">32767<\/span><span class=\"pun\">,<\/span><span class=\"pln\"> v<\/span><span class=\"pun\">*<\/span><span class=\"lit\">32768<\/span><span class=\"pun\">\/<\/span><span class=\"pln\">r<\/span><span class=\"pun\">+<\/span><span class=\"pln\">o<\/span><span class=\"pun\">)))<\/span>\r\n    <span class=\"pun\">})<\/span>\r\n    Protocol<span class=\"pun\">.<\/span><span class=\"pln\">SPI<\/span><span class=\"pun\">.<\/span>Start<span class=\"pun\">()<\/span>\r\n    <span class=\"kwd\">if<\/span><span class=\"pun\">(!<\/span>Protocol<span class=\"pun\">.<\/span><span class=\"pln\">SPI<\/span><span class=\"pun\">.<\/span>Write<span class=\"pun\">(<\/span><span class=\"lit\">16<\/span><span class=\"pun\">,<\/span><span class=\"pln\"> rg16<\/span><span class=\"pun\">))<\/span> <span class=\"kwd\">break<\/span>\r\n    Protocol<span class=\"pun\">.<\/span><span class=\"pln\">SPI<\/span><span class=\"pun\">.<\/span>Stop<span class=\"pun\">()<\/span>\r\n<span class=\"pun\">}<\/span><\/pre>\n<p>&nbsp;<\/p>\n<p>For the design I am working on, this communication is essential, as I am basically using the Analog Discovery 2 as an advanced sound sensor. Since my current setup involves manipulating the data from WaveForms in the Arduino IDE, I am going to experiment with attila&#8217;s suggested option of using the AnalogIn_Record example scripts to send to the COM port that the Arduino is on.<\/p>\n<p>Stay tuned for updates on this project as well as how to use the Analog Discovery 2 with Arduino!<\/p>\n<div class='watch-action'><div class='watch-position align-left'><div class='action-like'><a class='lbg-style6 like-25277 jlk' data-task='like' data-post_id='25277' data-nonce='35f55bdfa6' rel='nofollow'><img src='https:\/\/digilent.com\/blog\/wp-content\/plugins\/wti-like-post-pro\/images\/pixel.gif' title='Like' \/><span class='lc-25277 lc'>+2<\/span><\/a><\/div><div class='action-unlike'><a class='unlbg-style6 unlike-25277 jlk' data-task='unlike' data-post_id='25277' data-nonce='35f55bdfa6' rel='nofollow'><img src='https:\/\/digilent.com\/blog\/wp-content\/plugins\/wti-like-post-pro\/images\/pixel.gif' title='Unlike' \/><span class='unlc-25277 unlc'>-1<\/span><\/a><\/div><\/div> <div class='status-25277 status align-left'><\/div><\/div><div class='wti-clear'><\/div>","protected":false},"excerpt":{"rendered":"<p>Learn how to make Analog Discovery 2 communicate with Arduino using WaveForms!<\/p>\n","protected":false},"author":36,"featured_media":25321,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[4327,4312],"tags":[452],"ppma_author":[4485],"class_list":["post-25277","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-projects","category-usb-scopes-analyzers-generators","tag-waveforms"],"jetpack_featured_media_url":"https:\/\/digilent.com\/blog\/wp-content\/uploads\/2018\/08\/finally-e1534524676672.png","authors":[{"term_id":4485,"user_id":36,"is_guest":0,"slug":"mirandamay7","display_name":"Miranda Hansen","avatar_url":"https:\/\/secure.gravatar.com\/avatar\/bcab037c32924b9f9b3ca4898e179f2764cb7d9a82aa2bd475170c8aaa884e1c?s=96&d=mm&r=g","1":"","2":"","3":"","4":"","5":"","6":"","7":"","8":"","9":"","10":""}],"post_mailing_queue_ids":[],"_links":{"self":[{"href":"https:\/\/digilent.com\/blog\/wp-json\/wp\/v2\/posts\/25277","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/digilent.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/digilent.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/digilent.com\/blog\/wp-json\/wp\/v2\/users\/36"}],"replies":[{"embeddable":true,"href":"https:\/\/digilent.com\/blog\/wp-json\/wp\/v2\/comments?post=25277"}],"version-history":[{"count":0,"href":"https:\/\/digilent.com\/blog\/wp-json\/wp\/v2\/posts\/25277\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/digilent.com\/blog\/wp-json\/wp\/v2\/media\/25321"}],"wp:attachment":[{"href":"https:\/\/digilent.com\/blog\/wp-json\/wp\/v2\/media?parent=25277"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/digilent.com\/blog\/wp-json\/wp\/v2\/categories?post=25277"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/digilent.com\/blog\/wp-json\/wp\/v2\/tags?post=25277"},{"taxonomy":"author","embeddable":true,"href":"https:\/\/digilent.com\/blog\/wp-json\/wp\/v2\/ppma_author?post=25277"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}