<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Python Archives - G00</title>
	<atom:link href="https://g00.eu/tag/python/feed/" rel="self" type="application/rss+xml" />
	<link>https://g00.eu/tag/python/</link>
	<description>Rapid Prototyping</description>
	<lastBuildDate>Wed, 27 May 2020 11:28:45 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.7.1</generator>

<image>
	<url>https://g00.eu/wp-content/uploads/2016/06/cropped-text4185-150x150.png</url>
	<title>Python Archives - G00</title>
	<link>https://g00.eu/tag/python/</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>Using Pythonista to query an Xbox controller on the iPad</title>
		<link>https://g00.eu/2020/05/27/using-pythonista-to-query-an-xbox-controller-on-the-ipad/</link>
					<comments>https://g00.eu/2020/05/27/using-pythonista-to-query-an-xbox-controller-on-the-ipad/#respond</comments>
		
		<dc:creator><![CDATA[istimat]]></dc:creator>
		<pubDate>Wed, 27 May 2020 11:28:42 +0000</pubDate>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[controller_changed]]></category>
		<category><![CDATA[game controller]]></category>
		<category><![CDATA[get_controllers()]]></category>
		<category><![CDATA[ios]]></category>
		<category><![CDATA[ipad]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[pythonista]]></category>
		<category><![CDATA[ui]]></category>
		<category><![CDATA[xbox]]></category>
		<guid isPermaLink="false">http://g00.eu/?p=664</guid>

					<description><![CDATA[<p>Example code for using Pythonista to read button states of the Xbox controller.</p>
<p>The post <a rel="nofollow" href="https://g00.eu/2020/05/27/using-pythonista-to-query-an-xbox-controller-on-the-ipad/">Using Pythonista to query an Xbox controller on the iPad</a> appeared first on <a rel="nofollow" href="https://g00.eu">G00</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<p>It seems I need to add another category of posts. Programming. Now, you need to take into account the fact that I am a mechanical engineer and have no serious programming experience or education for that matter, and have only done scripting in Python and Arduino code for my electronics projects. Never take anything I write under this category seriously.</p>



<p>Nevertheless, I had the idea of using the iPad as a remote control for a future robotics project. Having Pythonista installed and knowing that the Xbox controller is supported by iOS, I thought I could research if it has been done before, and how.</p>



<div class="wp-block-image"><figure class="aligncenter size-large"><img fetchpriority="high" decoding="async" width="1024" height="768" src="http://g00.eu/wp-content/uploads/2020/05/CB262CB6-8469-43D9-9D44-87A789A87B2D-1024x768.jpeg" alt="" class="wp-image-667" srcset="https://g00.eu/wp-content/uploads/2020/05/CB262CB6-8469-43D9-9D44-87A789A87B2D-1024x768.jpeg 1024w, https://g00.eu/wp-content/uploads/2020/05/CB262CB6-8469-43D9-9D44-87A789A87B2D-300x225.jpeg 300w, https://g00.eu/wp-content/uploads/2020/05/CB262CB6-8469-43D9-9D44-87A789A87B2D-768x576.jpeg 768w, https://g00.eu/wp-content/uploads/2020/05/CB262CB6-8469-43D9-9D44-87A789A87B2D-1536x1152.jpeg 1536w, https://g00.eu/wp-content/uploads/2020/05/CB262CB6-8469-43D9-9D44-87A789A87B2D-2048x1536.jpeg 2048w, https://g00.eu/wp-content/uploads/2020/05/CB262CB6-8469-43D9-9D44-87A789A87B2D-520x390.jpeg 520w, https://g00.eu/wp-content/uploads/2020/05/CB262CB6-8469-43D9-9D44-87A789A87B2D-740x555.jpeg 740w, https://g00.eu/wp-content/uploads/2020/05/CB262CB6-8469-43D9-9D44-87A789A87B2D-600x450.jpeg 600w" sizes="(max-width: 1024px) 100vw, 1024px" /></figure></div>



<p>It seemed it could be done, as outlined in the Pythonista documentation, but there were no examples available and I have trouble reading documentations as I have a very limited OOP backgound and I probably only wrote like two classes in my entire life. </p>



<p>After a couple of days of messing around, I managed to create an extremely simple example that reads the value of each button when its state changes. My example only uses one button (the left trigger) and can be easily extended to all the other buttons.</p>



<p>No matter how much I googled for an example, I couldn&#8217;t find one, so I thought I would publish mine here.</p>



<pre class="wp-block-code"><code>from scene import *

class XboxContr(Scene):
	
	def setup(self):
		self.score_label = LabelNode('0', font=('Avenir Next', 40), position=(self.size.w/2, self.size.h-50), parent=self)
		self.controller_val = 0
		self.changed_key = ''
		self.left_bar = SpriteNode('shp:RoundRect')
		self.left_bar.position = 150, 150
		self.left_bar.size = 50, 150
		self.add_child(self.left_bar)
		
	def update(self):
		self.update_text()
		self.update_bar()
	
	def controller_changed(self, controller, key, value):
		self.controller_val = value
		self.changed_key = key
		
	def update_text(self):
		self.score_label.text = self.changed_key + ' ' + str(self.controller_val)
		
	def update_bar(self):
		if self.changed_key == 'trigger_left':
			self.left_bar.size = 50, self.controller_val*1000 + 150
			self.left_bar.position = 150, self.controller_val*500 + 150
				
run(XboxContr())


#Here is a list of all the buttons and their values. This is returned by the get_controllers() method:
#&#91;{'controller_id': '0x282afca80', 'shoulder_left': 0.0, 'shoulder_right': 0.0, 'dpad': Point(0.00, 0.00), 'button_a': 0.0, 'button_b': 0.0, 'button_x': 0.0, 'button_y': 0.0, 'trigger_left': 0.0, 'trigger_right': 0.0, 'thumb_stick_left': Point(0.00, 0.00), 'thumb_stick_right': Point(0.00, 0.00)}]
﻿</code></pre>



<p>Here is the interface it generates. The upper text block changes in real time and shows what button is changing and what value it has. The lower left bar increases in height according to how hard you pull on the left trigger.</p>



<div class="wp-block-image"><figure class="aligncenter size-large"><img decoding="async" width="1024" height="768" src="http://g00.eu/wp-content/uploads/2020/05/57AF49DB-5513-4ACB-8A83-4F6E40B086FF-1024x768.png" alt="" class="wp-image-668" srcset="https://g00.eu/wp-content/uploads/2020/05/57AF49DB-5513-4ACB-8A83-4F6E40B086FF-1024x768.png 1024w, https://g00.eu/wp-content/uploads/2020/05/57AF49DB-5513-4ACB-8A83-4F6E40B086FF-300x225.png 300w, https://g00.eu/wp-content/uploads/2020/05/57AF49DB-5513-4ACB-8A83-4F6E40B086FF-768x576.png 768w, https://g00.eu/wp-content/uploads/2020/05/57AF49DB-5513-4ACB-8A83-4F6E40B086FF-1536x1152.png 1536w, https://g00.eu/wp-content/uploads/2020/05/57AF49DB-5513-4ACB-8A83-4F6E40B086FF-520x390.png 520w, https://g00.eu/wp-content/uploads/2020/05/57AF49DB-5513-4ACB-8A83-4F6E40B086FF-740x555.png 740w, https://g00.eu/wp-content/uploads/2020/05/57AF49DB-5513-4ACB-8A83-4F6E40B086FF-600x450.png 600w, https://g00.eu/wp-content/uploads/2020/05/57AF49DB-5513-4ACB-8A83-4F6E40B086FF.png 2048w" sizes="(max-width: 1024px) 100vw, 1024px" /></figure></div>



<p>I would love to see more finalized interfaces from you guys. Also, let me know if I made some dumb-ass mistakes in the code.</p>
<p>The post <a rel="nofollow" href="https://g00.eu/2020/05/27/using-pythonista-to-query-an-xbox-controller-on-the-ipad/">Using Pythonista to query an Xbox controller on the iPad</a> appeared first on <a rel="nofollow" href="https://g00.eu">G00</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://g00.eu/2020/05/27/using-pythonista-to-query-an-xbox-controller-on-the-ipad/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>GRBL+bCNC=Love</title>
		<link>https://g00.eu/2017/12/13/grblbcnclove/</link>
					<comments>https://g00.eu/2017/12/13/grblbcnclove/#respond</comments>
		
		<dc:creator><![CDATA[istimat]]></dc:creator>
		<pubDate>Wed, 13 Dec 2017 07:19:38 +0000</pubDate>
				<category><![CDATA[CNC]]></category>
		<category><![CDATA[tools]]></category>
		<category><![CDATA[3040]]></category>
		<category><![CDATA[alternative]]></category>
		<category><![CDATA[aluminium]]></category>
		<category><![CDATA[aluminum]]></category>
		<category><![CDATA[arduino]]></category>
		<category><![CDATA[bCNC]]></category>
		<category><![CDATA[chinese]]></category>
		<category><![CDATA[cnc]]></category>
		<category><![CDATA[grbl]]></category>
		<category><![CDATA[linuxcnc]]></category>
		<category><![CDATA[mach3]]></category>
		<category><![CDATA[nano]]></category>
		<category><![CDATA[parallel]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[usb]]></category>
		<guid isPermaLink="false">http://g00.eu/?p=451</guid>

					<description><![CDATA[<p>As I was trying to install the new addition to the shop, a 3040 chinese CNC. I bought it second hand, and the previous owner upgraded the stepper motors, driver board and power supply. I hit an apparently minor hurdle while trying to establish a workflow with the new machine.</p>
<p>The post <a rel="nofollow" href="https://g00.eu/2017/12/13/grblbcnclove/">GRBL+bCNC=Love</a> appeared first on <a rel="nofollow" href="https://g00.eu">G00</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>As I was trying to install the new addition to the shop, a 3040 chinese CNC. I bought it second hand, and the previous owner upgraded the stepper motors, driver board and power supply. I hit an apparently minor hurdle while trying to establish a workflow with the new machine. The problem started when I remembered that the workshop computer was a 64-bit Windows setup which basically meant that the parallel port could not be used. At all.</p>
<p><a href="http://g00.eu/wp-content/uploads/2017/12/2209FAAE-1E9B-4EDE-A696-A9412A1C830E.jpeg"><img decoding="async" class="aligncenter wp-image-455" src="http://g00.eu/wp-content/uploads/2017/12/2209FAAE-1E9B-4EDE-A696-A9412A1C830E.jpeg" alt="" width="431" height="323" data-wp-pid="455" srcset="https://g00.eu/wp-content/uploads/2017/12/2209FAAE-1E9B-4EDE-A696-A9412A1C830E.jpeg 4032w, https://g00.eu/wp-content/uploads/2017/12/2209FAAE-1E9B-4EDE-A696-A9412A1C830E-600x450.jpeg 600w, https://g00.eu/wp-content/uploads/2017/12/2209FAAE-1E9B-4EDE-A696-A9412A1C830E-300x225.jpeg 300w, https://g00.eu/wp-content/uploads/2017/12/2209FAAE-1E9B-4EDE-A696-A9412A1C830E-768x576.jpeg 768w, https://g00.eu/wp-content/uploads/2017/12/2209FAAE-1E9B-4EDE-A696-A9412A1C830E-1024x768.jpeg 1024w, https://g00.eu/wp-content/uploads/2017/12/2209FAAE-1E9B-4EDE-A696-A9412A1C830E-800x600.jpeg 800w" sizes="(max-width: 431px) 100vw, 431px" /></a></p>
<p>So, with Mach3 out of the picture, I decided to dual-boot LinuxCNC. The problem with this was, mainly, that I also have a laser cutter that comes with RDWorks which only works on Windows. This already meant a loss of productivity because I couldn&#8217;t use both machines at the same time. Nevertheless I got LinuxCNC to work, but then after having difficulties getting used to it,  and realising that I wouldn&#8217;t be able to use Solidworks or Fusion360 to CAD/CAM the parts, I finally decided to convert the machine to USB.</p>
<p>In order to do that, I whipped up a quick USB to parallel port adapter using an arduino nano on a perfboard and installed GRBL on it. You can get it <a href="https://github.com/gnea/grbl/releases">here.</a> The schematic of the board doesn&#8217;t exist, because basically it&#8217;s just GRBL pinout -&gt; Driver board pinout. All wires.</p>
<p>I&#8217;ve used GRBL to drive DIY CNC&#8217;s before, and it was nice, but it had one big shortcoming. The feed override during machining wasn&#8217;t happening in real-time. So you couldn&#8217;t adjust the feed while milling difficult materials except after the current running command was finished. The latest version (1.1f) has this capability and from my point of view, GRBL is now perfect.</p>
<p>You can see it hanging on the left of the picture off the parallel port of the driver board.</p>
<p><a href="http://g00.eu/wp-content/uploads/2017/12/59194CE1-A594-427B-946D-D07BDBE30F86.jpeg"><img loading="lazy" decoding="async" class="aligncenter wp-image-453" src="http://g00.eu/wp-content/uploads/2017/12/59194CE1-A594-427B-946D-D07BDBE30F86.jpeg" alt="" width="405" height="304" data-wp-pid="453" srcset="https://g00.eu/wp-content/uploads/2017/12/59194CE1-A594-427B-946D-D07BDBE30F86.jpeg 4032w, https://g00.eu/wp-content/uploads/2017/12/59194CE1-A594-427B-946D-D07BDBE30F86-600x450.jpeg 600w, https://g00.eu/wp-content/uploads/2017/12/59194CE1-A594-427B-946D-D07BDBE30F86-300x225.jpeg 300w, https://g00.eu/wp-content/uploads/2017/12/59194CE1-A594-427B-946D-D07BDBE30F86-768x576.jpeg 768w, https://g00.eu/wp-content/uploads/2017/12/59194CE1-A594-427B-946D-D07BDBE30F86-1024x768.jpeg 1024w, https://g00.eu/wp-content/uploads/2017/12/59194CE1-A594-427B-946D-D07BDBE30F86-800x600.jpeg 800w" sizes="auto, (max-width: 405px) 100vw, 405px" /></a></p>
<p>It&#8217;s still missing limit switch, probing and spindle PWM connections, but it&#8217;s a start. By the way, the original spindle controller PCB has PWM input capability so it&#8217;s just a question of adding a connector from the arduino adapter board to the spindle controller.</p>
<p>Having converted the machine to GRBL meant that I could now use bCNC to drive it. This is an <span style="text-decoration: underline;">excellent</span> piece of software, also free, also open source, written in Python. It has a bunch of features including generatic g-code from dxf files, making text engravings, adding tabs to the g-code to keep the cut part from flying away and breaking your mill. You can get it <a href="https://github.com/vlachoudis/bCNC">here.</a> The user interface is very friendly and I cannot recommend it enough! Here is a screenshot from the bCNC github:</p>
<p><img loading="lazy" decoding="async" class="aligncenter" src="https://raw.githubusercontent.com/vlachoudis/bCNC/doc/Screenshots/bCNC.png" width="542" height="401" /></p>
<p>&nbsp;</p>
<p>Here&#8217;s a test I was able to make with the Fusion360 &#8211; bCNC workflow:</p>
<p>(about 50mm/min, 10.000rpm with a 2mm, 3 flute endmill with WD40 as coolant)</p>
<p>
<a href='https://g00.eu/wp-content/uploads/2017/12/0D313B05-3D72-4CCB-B8D8-154D6D9D7CA3.jpeg'><img loading="lazy" decoding="async" width="225" height="300" src="https://g00.eu/wp-content/uploads/2017/12/0D313B05-3D72-4CCB-B8D8-154D6D9D7CA3-225x300.jpeg" class="attachment-medium size-medium" alt="" srcset="https://g00.eu/wp-content/uploads/2017/12/0D313B05-3D72-4CCB-B8D8-154D6D9D7CA3-225x300.jpeg 225w, https://g00.eu/wp-content/uploads/2017/12/0D313B05-3D72-4CCB-B8D8-154D6D9D7CA3-600x800.jpeg 600w, https://g00.eu/wp-content/uploads/2017/12/0D313B05-3D72-4CCB-B8D8-154D6D9D7CA3-768x1024.jpeg 768w, https://g00.eu/wp-content/uploads/2017/12/0D313B05-3D72-4CCB-B8D8-154D6D9D7CA3-800x1067.jpeg 800w, https://g00.eu/wp-content/uploads/2017/12/0D313B05-3D72-4CCB-B8D8-154D6D9D7CA3-1200x1600.jpeg 1200w" sizes="auto, (max-width: 225px) 100vw, 225px" /></a>
<a href='https://g00.eu/wp-content/uploads/2017/12/8B3B8E4D-B7F6-4D12-AD0E-6C9D4918408C.jpeg'><img loading="lazy" decoding="async" width="225" height="300" src="https://g00.eu/wp-content/uploads/2017/12/8B3B8E4D-B7F6-4D12-AD0E-6C9D4918408C-225x300.jpeg" class="attachment-medium size-medium" alt="" srcset="https://g00.eu/wp-content/uploads/2017/12/8B3B8E4D-B7F6-4D12-AD0E-6C9D4918408C-225x300.jpeg 225w, https://g00.eu/wp-content/uploads/2017/12/8B3B8E4D-B7F6-4D12-AD0E-6C9D4918408C-600x800.jpeg 600w, https://g00.eu/wp-content/uploads/2017/12/8B3B8E4D-B7F6-4D12-AD0E-6C9D4918408C-768x1024.jpeg 768w, https://g00.eu/wp-content/uploads/2017/12/8B3B8E4D-B7F6-4D12-AD0E-6C9D4918408C-800x1067.jpeg 800w" sizes="auto, (max-width: 225px) 100vw, 225px" /></a>
</p>
<p>Stay tuned for more CNC related posts!</p>
<p>&nbsp;</p>
<p>The post <a rel="nofollow" href="https://g00.eu/2017/12/13/grblbcnclove/">GRBL+bCNC=Love</a> appeared first on <a rel="nofollow" href="https://g00.eu">G00</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://g00.eu/2017/12/13/grblbcnclove/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
