<?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>Bits and Bricks &#187; Scripts</title>
	<atom:link href="http://bitsandbricks.no/category/scripts/feed/" rel="self" type="application/rss+xml" />
	<link>http://bitsandbricks.no</link>
	<description>The life of a female geek</description>
	<lastBuildDate>Thu, 23 Jul 2015 12:08:23 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>https://wordpress.org/?v=4.2.39</generator>
	<item>
		<title>Getting started with Python on EV3</title>
		<link>http://bitsandbricks.no/2014/01/19/getting-started-with-python-on-ev3/</link>
		<comments>http://bitsandbricks.no/2014/01/19/getting-started-with-python-on-ev3/#comments</comments>
		<pubDate>Sun, 19 Jan 2014 21:12:05 +0000</pubDate>
		<dc:creator><![CDATA[Cecilie]]></dc:creator>
				<category><![CDATA[LEGO]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[Scripts]]></category>
		<category><![CDATA[ev3]]></category>
		<category><![CDATA[lego]]></category>
		<category><![CDATA[python]]></category>

		<guid isPermaLink="false">http://bitsandbricks.no/?p=268</guid>
		<description><![CDATA[So I&#8217;ve been diving head first into LEGO&#8217;s newest Mindstorms generation, called EV3. But seeing as I&#8217;m a Linux geek and a programmer, using LEGO&#8217;s own graphical drag-and-drop programming language from their windows/mac software was completely out of the question! &#8230; <a href="http://bitsandbricks.no/2014/01/19/getting-started-with-python-on-ev3/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>So I&#8217;ve been diving head first into LEGO&#8217;s newest Mindstorms generation, called EV3. But seeing as I&#8217;m a Linux geek and a programmer, using LEGO&#8217;s own graphical drag-and-drop programming language from their windows/mac software was completely out of the question! Now, the EV3 runs Linux out of the box, which is very cool, but it comes with some limitations, so to get going with a proper programming language, installing another Linux version was necessary. Luckily, the EV3 makes that so much simpler than the NXT did. Just pop a bootable OS on a micro SD card, stuff in the EV3, and voila, it will boot from the SD card! Pop the card back out, and the EV3 still has it&#8217;s factory firmware. No flashing needed! Neat!</p>
<p>So what programming language to use? Well, turns out some guy who calls himself Topikachu has already made a ready Linux image with Python installed, and even made Python libraries to interface with the EV3 sensors and motors. Does it get any better than that? He&#8217;s made a quick howto on how to install it, which you can read on his <a href="https://github.com/topikachu/python-ev3">github</a>. If you have a USB Wifi dongle too (currently only one is supported, but I&#8217;m sure more will be added in time), it was very easy to get it hooked up on wifi too. I just had to log in over usb as described, update the <a href="http://linux.die.net/man/5/wpa_supplicant.conf">wpa_supplicant.conf</a> and I was good to go without a cable. You may want to check out what IP your brick received before unplugging the usb cable though <img src="http://s.w.org/images/core/emoji/72x72/1f609.png" alt="😉" class="wp-smiley" style="height: 1em; max-height: 1em;" /></p>
<p>The Python API is really great, but I couldn&#8217;t find much documentation of it, so I had to read his code and look at his tests to figure out how to use it. Wasn&#8217;t too hard though, and here&#8217;s a little program I wrote just to test out that things were working (it doesn&#8217;t do much, basically just tries to crash :P)</p>
<pre>#!/usr/bin/python

import time

from ev3.rawdevice import motordevice
from ev3.rawdevice import analogdevice
from ev3.rawdevice import uartdevice

from ev3 import lego

motordevice.open_device()
analogdevice.open_device()
uartdevice.open_device() 

A = 0x01
B = 0x02
C = 0x04
D = 0x08

right = A
left = D
both = A+D

touch = lego.EV3TouchSensor(0)
ir = lego.EV3IRSensor(3)
ir.set_prox_mode()

motordevice.speed(both,20)

distance = 101

while True:
  time.sleep(1)
  if touch.is_pressed() == 1:
    motordevice.stop(both, brake=1)
    print "stopping\n"
    break

  cur_distance = ir.get_distance()
  if cur_distance &gt; distance:
    print "searching\n"
    motordevice.stop(both, brake=1)
    motordevice.speed(A, 20)
    time.sleep(1)
    motordevice.stop(A, brake=1)
    motordevice.speed(both,20)

  distance = cur_distance

motordevice.stop(both, brake=1)</pre>
<p>That doesn&#8217;t look so hard, does it? Here&#8217;s some additional notes I made for myself to remember what the different functions do and how to use them.</p>
<pre>Motors:
A = 0x01
B = 0x02
C = 0x04
D = 0x08
PORTS = A+B # Access both A and B at the same time
from ev3.rawdevice import motordevice
motordevice.open_device()

motordevice.speed(PORTS,20)
motordevice.stop(B,brake=1) # brake makes it actually brake the motor, not just stop turning it

from ev3.rawdevice import analogdevice
analogdevice.open_device()
touch = lego.EV3TouchSensor(0) # Note, the port numbering is 0-3, so the port marked 1 is 0, etc.
touch.is_pressed()

from ev3.rawdevice import uartdevice
uartdevice.open_device()
color = lego.EV3ColorSensor(3)
color.set_color_mode()
color.color_to_string() # This only works for color_mode
color.set_ref_raw_mode() # raw values, -127 -&gt; 127
color.get_value() # raw value from sensor sensor

ir = lego.EV3IRSensor(2)
ir.set_prox_mode() # proximity mode
ir.get_distance() # for prox mode
ir.set_remote_mode() # for using the remote control
ir.get_remote_command() # get remote control command
ir.set_seek_mode() # follow remote control when button pressed
ir.get_all_direction_and_distance #  for seek mode
ir.get_direction_and_distance(chan) #  for seek mode

# This is how I managed to read info from a Hitechnic accelerometer sensor (originally made for the NXT)
from ev3 import robot
from ev3 import sensor
robot.open_all_devices()
iicsensor = IICSensor()
iicsensor = sensor.IICSensor(1, 0x02)
iicsensor.read(0x42)</pre>
 <img src="http://bitsandbricks.no/?feed-stats-post-id=268" width="1" height="1" style="display: none;" />]]></content:encoded>
			<wfw:commentRss>http://bitsandbricks.no/2014/01/19/getting-started-with-python-on-ev3/feed/</wfw:commentRss>
		<slash:comments>18</slash:comments>
		</item>
		<item>
		<title>LDD in Linux</title>
		<link>http://bitsandbricks.no/2011/08/16/ldd-in-linux/</link>
		<comments>http://bitsandbricks.no/2011/08/16/ldd-in-linux/#comments</comments>
		<pubDate>Tue, 16 Aug 2011 07:22:26 +0000</pubDate>
		<dc:creator><![CDATA[Cecilie]]></dc:creator>
				<category><![CDATA[LEGO]]></category>
		<category><![CDATA[Scripts]]></category>

		<guid isPermaLink="false">http://bitsandbricks.no/?p=125</guid>
		<description><![CDATA[Being part of several different minorities, among them being a Linux user and an adult LEGO builder, I&#8217;m part of an even smaller minority: a user of LEGO Digital Designer (LDD) under wine in Linux. First time I tried running &#8230; <a href="http://bitsandbricks.no/2011/08/16/ldd-in-linux/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>Being part of several different minorities, among them being a Linux user and an adult LEGO builder, I&#8217;m part of an even smaller minority: a user of LEGO Digital Designer (LDD) under wine in Linux. First time I tried running LDD in wine, it didn&#8217;t go so well. The program installed and started just fine, but once I tried to select a brick, it crashed. I quickly gave up, thinking it just wasn&#8217;t meant to be. Then LDD 4 was released. I decided to try again, and suddenly, it worked! Now, I&#8217;m not sure if it worked because LDD 4 was more compatible with wine, if wine had gotten better, or maybe most likely, the graphics drivers for Linux had gotten loads better (or possibly a combination of those).</p>
<p>In any case, I&#8217;m happy to now be able to use LDD in Linux, although it&#8217;s still not perfect (uploading of models to the web through the Design By Me process does not work at all). But there&#8217;s one more thing I need: the ability to upload the list of bricks used in a model to a wanted list in bricklink, so they can be viewed and ordered. There are some tools for windows to do this, but I haven&#8217;t tried those in wine, as what I really just need is a simple little script. So I made one! It didn&#8217;t take much investigating to figure out I could just unzip the lxf files created by LDD, and get an easily readable xml out of it. As it turns out, all I needed was a simple little perl-script to parse this xml, convert the LEGO color ids to bricklink color ids (found a mapping table for this that I just pasted into my script), and create an xml file in bricklink&#8217;s chosen format. And voila! Just upload to bricklink!</p>
<p>Now, of course, it wasn&#8217;t quite that simple. Some element ids that come out of LDD aren&#8217;t directly compatible with bricklink for various reasons. But instead of trying to compile a comprehensive mapping here (I could probably get such a list), I just chose to tackle the incompatible numbers as they presented themselves. So when I upload a list, some elements are rejected by bricklink. I then find out what those elements are in LDD, and find the equivalent number on bricklink that I can insert in a mapping table in my script, so it will work next time. Seeing as my script is a bit unpolished and unfinished in terms of element mapping, I&#8217;m not going to share it with the world just yet. I might do so though, if I can get a comprehensive element mapping (or someone really begs me to have the script even without it), and get a few quirks sorted out. But for now, I&#8217;m a happy LDD user in Linux <img src="http://bitsandbricks.no/wp-includes/images/smilies/simple-smile.png" alt=":)" class="wp-smiley" style="height: 1em; max-height: 1em;" /></p>
 <img src="http://bitsandbricks.no/?feed-stats-post-id=125" width="1" height="1" style="display: none;" />]]></content:encoded>
			<wfw:commentRss>http://bitsandbricks.no/2011/08/16/ldd-in-linux/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
