{"id":154,"date":"2013-02-01T13:29:29","date_gmt":"2013-02-01T13:29:29","guid":{"rendered":"http:\/\/randomnerdtutorials.wordpress.com\/?p=154"},"modified":"2019-04-02T10:23:40","modified_gmt":"2019-04-02T10:23:40","slug":"arduino-poor-mans-oscilloscope","status":"publish","type":"post","link":"https:\/\/randomnerdtutorials.com\/arduino-poor-mans-oscilloscope\/","title":{"rendered":"Arduino &#8211; Poor Man\u2019s Oscilloscope"},"content":{"rendered":"<p>Today I&#8217;ll talk about a really good project you can do with your Arduino! This is the best way you can have a cheap oscilloscope around, I didn&#8217;t write this code, I&#8217;ve found it on the internet\u00a0a while back ago and I&#8217;ve decided to share this awesome project.\u00a0Let&#8217;s start&#8230;<!--more--><\/p>\n<p><img data-recalc-dims=\"1\" fetchpriority=\"high\" decoding=\"async\" class=\"aligncenter size-full wp-image-975\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2013\/07\/2oscopethumb.png?resize=756%2C536&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"\" width=\"756\" height=\"536\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2013\/07\/2oscopethumb.png?w=756&amp;quality=100&amp;strip=all&amp;ssl=1 756w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2013\/07\/2oscopethumb.png?resize=300%2C212&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 756px) 100vw, 756px\" \/><\/p>\n<p>First, download Processing. It&#8217;s free\u00a0<a title=\"Click here to download\" href=\"http:\/\/processing.org\/\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">Click here to download<\/a>. You don&#8217;t need to install anything, It runs like the Arduino IDE.<\/p>\n<h2>Upload this code to\u00a0your Arduino<\/h2>\n<pre style=\"max-height: 40em; margin-bottom: 20px;\"><code class=\"language-c\">\/* \n  Complete project details: http:\/\/randomnerdtutorials.com\/arduino-poor-mans-oscilloscope\/\n*\/\n\n#define ANALOG_IN 0\n \nvoid setup() {\n  Serial.begin(9600); \n  \/\/Serial.begin(115200); \n}\n \nvoid loop() {\n  int val = analogRead(ANALOG_IN);                                              \n  Serial.write( 0xff );                                                         \n  Serial.write( (val &gt;&gt; 8) &amp; 0xff );                                            \n  Serial.write( val &amp; 0xff );\n}\n<\/code><\/pre>\n\t<p style=\"text-align:center\"><a class=\"rntwhite\" href=\"https:\/\/github.com\/RuiSantosdotme\/Random-Nerd-Tutorials\/raw\/master\/Projects\/Arduino_Poor_mans_oscilloscope.c\" target=\"_blank\">View raw code<\/a><\/p>\n<h2>Then Run this code in Processing IDE<\/h2>\n<pre style=\"max-height: 40em; margin-bottom: 20px;\"><code class=\"language-c\">\/*\n * Oscilloscope\n * Gives a visual rendering of analog pin 0 in realtime.\n * \n * This project is part of Accrochages\n * See http:\/\/accrochages.drone.ws\n * \n * (c) 2008 Sofian Audry (info@sofianaudry.com)\n *\n * This program is free software: you can redistribute it and\/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n * \n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n * \n * You should have received a copy of the GNU General Public License\n * along with this program.  If not, see &lt;http:\/\/www.gnu.org\/licenses\/&gt;.\n *\/ \nimport processing.serial.*;\n \nSerial port;  \/\/ Create object from Serial class\nint val;      \/\/ Data received from the serial port\nint[] values;\nfloat zoom;\n \nvoid setup() \n{\n  size(1280, 480);\n  \/\/ Open the port that the board is connected to and use the same speed (9600 bps)\n  port = new Serial(this, Serial.list()[0], 9600);\n  values = new int[width];\n  zoom = 1.0f;\n  smooth();\n}\n \nint getY(int val) {\n  return (int)(height - val \/ 1023.0f * (height - 1));\n}\n \nint getValue() {\n  int value = -1;\n  while (port.available() &gt;= 3) {\n    if (port.read() == 0xff) {\n      value = (port.read() &lt;&lt; 8) | (port.read());\n    }\n  }\n  return value;\n}\n \nvoid pushValue(int value) {\n  for (int i=0; i&lt;width-1; i++)\n    values[i] = values[i+1];\n  values[width-1] = value;\n}\n \nvoid drawLines() {\n  stroke(255);\n  \n  int displayWidth = (int) (width \/ zoom);\n  \n  int k = values.length - displayWidth;\n  \n  int x0 = 0;\n  int y0 = getY(values[k]);\n  for (int i=1; i&lt;displayWidth; i++) {\n    k++;\n    int x1 = (int) (i * (width-1) \/ (displayWidth-1));\n    int y1 = getY(values[k]);\n    line(x0, y0, x1, y1);\n    x0 = x1;\n    y0 = y1;\n  }\n}\n \nvoid drawGrid() {\n  stroke(255, 0, 0);\n  line(0, height\/2, width, height\/2);\n}\n \nvoid keyReleased() {\n  switch (key) {\n    case '+':\n      zoom *= 2.0f;\n      println(zoom);\n      if ( (int) (width \/ zoom) &lt;= 1 )\n        zoom \/= 2.0f;\n      break;\n    case '-':\n      zoom \/= 2.0f;\n      if (zoom &lt; 1.0f)\n        zoom *= 2.0f;\n      break;\n  }\n}\n \nvoid draw()\n{\n  background(0);\n  drawGrid();\n  val = getValue();\n  if (val != -1) {\n    pushValue(val);\n  }\n  drawLines();\n}\n<\/code><\/pre>\n\t<p style=\"text-align:center\"><a class=\"rntwhite\" href=\"https:\/\/github.com\/RuiSantosdotme\/Random-Nerd-Tutorials\/raw\/master\/Projects\/Arduino_Poor_mans_oscilloscope_processing_code.c\" target=\"_blank\">View raw code<\/a><\/p>\n<p>And then you just need to connect the Arduino analog pin 0 to the signal you want to read.<\/p>\n<p>And It&#8217;s done!<\/p>\n<h2>Parts required<\/h2>\n<ul>\n<li><a href=\"https:\/\/makeradvisor.com\/tools\/compatible-arduino-uno-r3-board\/\" target=\"_blank\" rel=\"noopener noreferrer\">Arduino UNO<\/a>\u00a0\u2013 read\u00a0<a href=\"https:\/\/makeradvisor.com\/best-arduino-starter-kits\/\" target=\"_blank\" rel=\"noopener noreferrer\">Best Arduino Starter Kits<\/a><\/li>\n<li><a href=\"https:\/\/makeradvisor.com\/tools\/mb-102-solderless-breadboard-830-points\/\" target=\"_blank\" rel=\"noopener noreferrer\">1x Breadboard<\/a><\/li>\n<li><a href=\"https:\/\/makeradvisor.com\/tools\/3mm-5mm-leds-kit-storage-box\/\" target=\"_blank\" rel=\"noopener noreferrer\">1x LED<\/a><\/li>\n<li><a href=\"https:\/\/makeradvisor.com\/tools\/resistors-kits\/\" target=\"_blank\" rel=\"noopener noreferrer\">1x 10k resistor<\/a><\/li>\n<li><a href=\"https:\/\/makeradvisor.com\/tools\/resistors-kits\/\" target=\"_blank\" rel=\"noopener noreferrer\">1&#215;4.7k resistor<\/a><\/li>\n<li><a href=\"https:\/\/makeradvisor.com\/tools\/resistors-kits\/\" target=\"_blank\" rel=\"noopener noreferrer\">1x 1k resistor<\/a><\/li>\n<li><a href=\"https:\/\/makeradvisor.com\/tools\/electrolytic-capacitors-kit\/\" target=\"_blank\" rel=\"noopener noreferrer\">1x 100nF electrolytic capacitor<\/a><\/li>\n<li><a href=\"https:\/\/makeradvisor.com\/tools\/jumper-wires-kit-120-pieces\/\" target=\"_blank\" rel=\"noopener noreferrer\">Jumper wires<\/a><\/li>\n<\/ul>\n<h2>Schematics<\/h2>\n<p>This is the circuit I&#8217;ll be measuring , it&#8217;s a simple 555 timer circuit&#8230; that flashes an LED.<\/p>\n<p style=\"text-align: center;\"><a href=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2013\/02\/555-timer1.png?quality=100&#038;strip=all&#038;ssl=1\" rel=\"nofollow\"><img data-recalc-dims=\"1\" decoding=\"async\" class=\"aligncenter wp-image-692\" title=\"\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2013\/02\/555-timer1.png?resize=411%2C197&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"555 timer\" width=\"411\" height=\"197\" \/><\/a><\/p>\n<h2>Watch the video demonstration<\/h2>\n<p style=\"text-align:center\"><iframe width=\"720\" height=\"405\" src=\"https:\/\/www.youtube.com\/embed\/ZMhQlnlBhPA?rel=0\" frameborder=\"0\" allowfullscreen><\/iframe><\/p>\n<p>Thanks for reading, you can contact me by leaving a comment. If you like this post probably you might like my next ones, so please support me by subscribing my blog and my <a href=\"https:\/\/www.facebook.com\/RandomNerdTutorials?ref=hl\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">Facebook Page.<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Today I&#8217;ll talk about a really good project you can do with your Arduino! This is the best way you can have a cheap oscilloscope around, I didn&#8217;t write this &#8230; <\/p>\n<p class=\"read-more-container\"><a title=\"Arduino &#8211; Poor Man\u2019s Oscilloscope\" class=\"read-more button\" href=\"https:\/\/randomnerdtutorials.com\/arduino-poor-mans-oscilloscope\/#more-154\" aria-label=\"Read more about Arduino &#8211; Poor Man\u2019s Oscilloscope\">CONTINUE READING \u00bb<\/a><\/p>\n","protected":false},"author":1,"featured_media":975,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[303,267,2,264,10],"tags":[241,43,46,71,105,115,119,141,166],"class_list":["post-154","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-0-arduino","category-arduino-project","category-arduino","category-project","category-a-tutorials","tag-arduino","tag-cheap","tag-code","tag-free","tag-oscilloscope","tag-poor-mans","tag-processing","tag-signal","tag-uno"],"aioseo_notices":[],"jetpack_featured_media_url":"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2013\/07\/2oscopethumb.png?fit=756%2C536&quality=100&strip=all&ssl=1","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/posts\/154","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/comments?post=154"}],"version-history":[{"count":0,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/posts\/154\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/media\/975"}],"wp:attachment":[{"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/media?parent=154"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/categories?post=154"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/tags?post=154"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}