{"id":133,"date":"2015-01-26T17:24:46","date_gmt":"2015-01-26T23:24:46","guid":{"rendered":"http:\/\/jacobncalvert.com\/?p=133"},"modified":"2018-02-10T15:08:44","modified_gmt":"2018-02-10T21:08:44","slug":"raspberry-pi-and-gpio-updates","status":"publish","type":"post","link":"https:\/\/jacobncalvert.com\/blog-archive\/2015\/01\/26\/raspberry-pi-and-gpio-updates\/","title":{"rendered":"Raspberry Pi and GPIO updates"},"content":{"rendered":"<p>I&#8217;ve been playing with my RPi fairly frequently as of late. I ordered some tactile switches, motors, and motor controllers from AdaFruit and since they came in I&#8217;ve been learning to control motor speed, direction, and LED brightness using soft-PWM.<\/p>\n<p>I quickly learned that I would want a class to wrap up all the GPIO sets\/gets. I&#8217;ve been writing a package in Python which I&#8217;m calling RPiComponents containing the basic interfaces necessary for controlling the GPIO pins in an object-oriented fashion. I&#8217;ll be posting it to GitHub as soon as I finish the documentation for it. As a preview though, you can currently do things like:<\/p>\n<pre class=\"prettyprint\">\timport RPiComponents as parts\r\n\tred_led_pin = 21  # using the BCM pin numbering\r\n\tinitial_brightness = 0  # initially off\r\n\tred_led = parts.LED.FadableLED(red_led_pin, initial_brightness)\r\n\tred_led.set_brightness(50)  # set the brightness to 50%\r\n\tred_led.set_brightness(100) # '   '   '          '  100%\r\n\tred_led.off()\r\n\r\n\tmotor_enable_pin = 21\r\n\tmotor_fwd_pin = 20\r\n\tmotor_rev_pin = 16\r\n\r\n\r\n\tmotor = parts.L293DMotor.VariableSpeedL293DMotor(motor_enable_pin, motor_fwd_pin, motor_rev_pin)\r\n\tmotor.enable()  # sets the motor controller enable bit to HIGH\r\n\tmotor.set_speed(50)  # sets the motor speed to 50% of it's max\r\n\r\n\tmotor.fwd()\r\n\r\n\tmotor.stop()\r\n\r\n\tmotor.rev(90)  # starts the motor in reverse at 90% of the max speed\r\n\r\n\tmotor.disable() # all speed and direction setting are kept but the motor will stop\r\n\r\n\t\r\n\tdef some_callback(some_arg0):\r\n\t\tprint \"Called some_callback with argument %s\" % (some_arg0)\r\n\r\n\t\t\t\r\n\tswitch_pin_number = 6\r\n\r\n\tswitch = parts.Switch.SwitchWithThreadedCallback(switch_pin_number, callback=some_callback, callback_args=[1,2,3])\r\n\t\r\n\tswitch.start()\r\n\r\n\t#  calling switch.start() starts a monitor thread that waits for a rising or falling edge\r\n\t#  due to the switch changing state, it will then fire off callback with the arguments given\r\n\t#  or if callback_args is None, it will simply call the callback\r\n\r\n\tswitch.stop()\r\n\r\n\t#  switch.stop() properly terminates the monitor thread\r\n\r\n\tparts.finalize()  # clean up after ourselves and reset the GPIO pins for some other use\r\n<\/pre>\n<p>There&#8217;s also a few super simple abstractions like BasicToggleOutput with methods high() and low() in a module called BasicLogic. I hope to add some more neat functionality later on as well. I&#8217;ll post again when the source is on GitHub and attach a few examples for starters!<\/p>\n<p>Thanks for reading!!<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I&#8217;ve been playing with my RPi fairly frequently as of late. I ordered some tactile switches, motors, and motor controllers from AdaFruit and since they came in I&#8217;ve been learning to control motor speed, direction, and LED brightness using soft-PWM. I quickly learned that I would want a class to wrap up all the GPIO sets\/gets. I&#8217;ve been writing a package in Python which I&#8217;m calling RPiComponents containing the basic interfaces necessary for controlling the GPIO pins in an object-oriented&hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[5],"tags":[48],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v16.4 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Raspberry Pi and GPIO updates - Jacob N Calvert<\/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:\/\/jacobncalvert.com\/blog-archive\/2015\/01\/26\/raspberry-pi-and-gpio-updates\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Raspberry Pi and GPIO updates - Jacob N Calvert\" \/>\n<meta property=\"og:description\" content=\"I&#8217;ve been playing with my RPi fairly frequently as of late. I ordered some tactile switches, motors, and motor controllers from AdaFruit and since they came in I&#8217;ve been learning to control motor speed, direction, and LED brightness using soft-PWM. I quickly learned that I would want a class to wrap up all the GPIO sets\/gets. I&#8217;ve been writing a package in Python which I&#8217;m calling RPiComponents containing the basic interfaces necessary for controlling the GPIO pins in an object-oriented&hellip;\" \/>\n<meta property=\"og:url\" content=\"https:\/\/jacobncalvert.com\/blog-archive\/2015\/01\/26\/raspberry-pi-and-gpio-updates\/\" \/>\n<meta property=\"og:site_name\" content=\"Jacob N Calvert\" \/>\n<meta property=\"article:published_time\" content=\"2015-01-26T23:24:46+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2018-02-10T21:08:44+00:00\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data1\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebSite\",\"@id\":\"https:\/\/jacobncalvert.com\/blog-archive\/#website\",\"url\":\"https:\/\/jacobncalvert.com\/blog-archive\/\",\"name\":\"Jacob N Calvert\",\"description\":\"\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":\"https:\/\/jacobncalvert.com\/blog-archive\/?s={search_term_string}\",\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/jacobncalvert.com\/blog-archive\/2015\/01\/26\/raspberry-pi-and-gpio-updates\/#webpage\",\"url\":\"https:\/\/jacobncalvert.com\/blog-archive\/2015\/01\/26\/raspberry-pi-and-gpio-updates\/\",\"name\":\"Raspberry Pi and GPIO updates - Jacob N Calvert\",\"isPartOf\":{\"@id\":\"https:\/\/jacobncalvert.com\/blog-archive\/#website\"},\"datePublished\":\"2015-01-26T23:24:46+00:00\",\"dateModified\":\"2018-02-10T21:08:44+00:00\",\"author\":{\"@id\":\"https:\/\/jacobncalvert.com\/blog-archive\/#\/schema\/person\/f4b22a996d41bf09ed2bbe22912a8c8a\"},\"breadcrumb\":{\"@id\":\"https:\/\/jacobncalvert.com\/blog-archive\/2015\/01\/26\/raspberry-pi-and-gpio-updates\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/jacobncalvert.com\/blog-archive\/2015\/01\/26\/raspberry-pi-and-gpio-updates\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/jacobncalvert.com\/blog-archive\/2015\/01\/26\/raspberry-pi-and-gpio-updates\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"item\":{\"@type\":\"WebPage\",\"@id\":\"https:\/\/jacobncalvert.com\/blog-archive\/\",\"url\":\"https:\/\/jacobncalvert.com\/blog-archive\/\",\"name\":\"Home\"}},{\"@type\":\"ListItem\",\"position\":2,\"item\":{\"@id\":\"https:\/\/jacobncalvert.com\/blog-archive\/2015\/01\/26\/raspberry-pi-and-gpio-updates\/#webpage\"}}]},{\"@type\":\"Person\",\"@id\":\"https:\/\/jacobncalvert.com\/blog-archive\/#\/schema\/person\/f4b22a996d41bf09ed2bbe22912a8c8a\",\"name\":\"Jacob\",\"image\":{\"@type\":\"ImageObject\",\"@id\":\"https:\/\/jacobncalvert.com\/blog-archive\/#personlogo\",\"inLanguage\":\"en-US\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/64a2dd1c00cb39dfc19bb1204c87efbc?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/64a2dd1c00cb39dfc19bb1204c87efbc?s=96&d=mm&r=g\",\"caption\":\"Jacob\"},\"sameAs\":[\"https:\/\/jacobncalvert.com\"],\"url\":\"https:\/\/jacobncalvert.com\/blog-archive\/author\/jcalvert\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","_links":{"self":[{"href":"https:\/\/jacobncalvert.com\/blog-archive\/wp-json\/wp\/v2\/posts\/133"}],"collection":[{"href":"https:\/\/jacobncalvert.com\/blog-archive\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/jacobncalvert.com\/blog-archive\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/jacobncalvert.com\/blog-archive\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/jacobncalvert.com\/blog-archive\/wp-json\/wp\/v2\/comments?post=133"}],"version-history":[{"count":1,"href":"https:\/\/jacobncalvert.com\/blog-archive\/wp-json\/wp\/v2\/posts\/133\/revisions"}],"predecessor-version":[{"id":134,"href":"https:\/\/jacobncalvert.com\/blog-archive\/wp-json\/wp\/v2\/posts\/133\/revisions\/134"}],"wp:attachment":[{"href":"https:\/\/jacobncalvert.com\/blog-archive\/wp-json\/wp\/v2\/media?parent=133"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/jacobncalvert.com\/blog-archive\/wp-json\/wp\/v2\/categories?post=133"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/jacobncalvert.com\/blog-archive\/wp-json\/wp\/v2\/tags?post=133"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}