Category Archives: Things we like

Tools and toys that are useful

Raspberry PI and the Lego EV3 connected by bluetooth

Executive summary

Here is how to interact between Raspberry PI 3 and Lego EV3 using Bluetooth.   There will be a python 3.6 script presented and sample EV3 programs.  All of this is stock stuff on both platforms.

The key is how to interpret the bytes.  The script presented takes care of all of that.  Here is the EV3BT Script.

The fun stuff

So, I could possibly have a family and I could indeed possible like to enjoy time with them.  I play with Lego in the interest of my family.  I am a good dad…  unless explosives are involved.

Don’t judge.

So the project was to determine if we could use a Raspberry PI with open CV and a camera and drive a Lego robot around the floor using the EV3 trying to do cool things.

There are several communication options but I didn’t want to use any sort of wired or wireless Ethernet nor is USB an option from what I can tell.  I also didn’t want to change the EV3’s operating system.

I decided to play with bluetooth.  They are probably other and perhaps better ways to do this but this is what I chose.

Enough disclaimers about the effectiveness of my decision making skills especially about the explosives and related minors.

There are many sites that explain how to connect the EV3 and even program it.  This guy’s is pretty good.

If you are unfamiliar with pairing with Raspberry PI3 and the EV3, google it.  It is a bit cryptic but once pair, you can connect to the EV3 and it appears as a serial device (i.e. /dev/rfcomm0).

The trick and the purpose of the

Sending to the EV3

The program above simply waits for a Bluetooth message and in this case, a text message, prints it on the LCD screen and beeps.  The python below shows the sending of a message to the EV3.  The trick of the EV3BT class is to simply encode and decode the bits.  The serial module takes care of the transmission.

#! /usr/bin/env python3
import serial
import time
import EV3BT

EV3 = serial.Serial('/dev/rfcomm0')
s = EV3BT.encodeMessage(EV3BT.MessageType.Text, 'abc', 'Eat responsibly')
print(EV3BT.printMessage(s))
EV3.write(s)
time.sleep(1)
EV3.close()

You have options for what sort of messages you can send.  These are Text, Numeric, and Logic.  In programmer speak, strings, floating point values (IEEE 754), and Boolean (literally a 1 and a 0).  See below.

The other key is the mailbox.  The ‘abc’ is the mail box and is shown on the block (highlighted in red).  You must pass the mailbox in a form that matches the block so that the block receives the message.  In case it isn’t obvious, you can send messages to multiple mailboxes in your script and control several EV3 loops just but using different mailboxes.

Reading from the EV3

Reading is just a little more complicated in that you probably need to have some sort of loop with blocking logic.  As I say that, every experienced developer reading this is rolling their eyes (back in old school Linux days, should we use select or poll?).

In this example, the EV3 will wait for a touch sensor to be activated and send a message.  To be precise, the message ‘Raspberry PI’ will be sent to the mailbox ‘abc’  in the Raspberry PI.

The key is the decodeMessage.  You tell the method, the string to parse, and the message type expected (as this effects the length of the transfer and there is no identifying mark in the message about the type).  It will return you the mail box, the value, and any remnant bytes left over.  The buffering is not stellar in this example but it gets the point across.

#! /usr/bin/env python3
import serial
import time

import EV3BT

EV3 = serial.Serial('/dev/rfcomm0')
print("Listening for EV3 Bluetooth messages, press CTRL C to quit.")
try:
 while 1:
 n = EV3.inWaiting()
 if n != 0:
  s = EV3.read(n)
  mail,value,s = EV3BT.decodeMessage(s, EV3BT.MessageType.Logic)
  print(mail,value) 
 else:
  # No data is ready to be processed
  time.sleep(0.1)
except KeyboardInterrupt:
 pass
EV3.close()

Moving a robot

So to put it together, I could make a robot move under python control in the Raspberry PI with this script and program.

The EV3 was made as a tank with two treads.  A left and right.  Essentially, the script is sending a numeric to each tank tread.  A positive number moves forward, a negative number moves back.   The larger the number, the faster the rotation.

#! /usr/bin/env python3
import serial
import time
import EV3BT

EV3 = serial.Serial('/dev/rfcomm0')
left = 10
right = 10
s = EV3BT.encodeMessage(EV3BT.MessageType.Numeric, 'left', left)
EV3.write(s)
s = EV3BT.encodeMessage(EV3BT.MessageType.Numeric, 'right', right)
EV3.write(s)
EV3.close()

Areas of improvement

When reading, there is no identifying mark in the package concerning the type.  You also can not assume that number of bytes on the wire will work.  A 3 byte with null looks like a float.

Deriving application specific code to handle the case where you want the EV3 to send a float and a Boolean should be simple to add.  A string?  Not sure the worth of that really from the EV3 to the Raspberry PI.

Stupid Simple File Server from Spare Parts

Another installment of things I like because the just work.

I frequently have the need to spin up a file server, either for temporary use or for longer term storage.
Recently I was migrating a system from one place to another and needed a large amount of fast temporary storage.
At home I have a file server for mass storage of music, videos etc.

There are lots of solutions to this. Could always just use an old Win XP box, or set up a Linux server using your favorite distro. Then there are free software systems, FreeNAS is a good example.

One I like is Server Elements.
They have a line of products including one that boots from a floppy! Hardware requirements for all of the products are very modest. Basically take some old PC, stuff it full of old disks, create a bootable CD, or Thumb Drive and off you go. Prices range from $10 – $35 for the 64bit product with some media streaming capabilities.

For quick set up – Server Elements is really great and worth the small price.
If you want more features, FreeNAS is a very good choice.

Here is an excellent article on the topic.
http://www.smbitjournal.com/2012/04/choosing-an-open-storage-operating-system/

Swiss Army Knife of SMTP Servers

Just wanted to give a shout out to my favorite SMTP Server.
When you find yourself needing a robust, easy to configure and support SMTP IMAP/ POP3 server that can handle about any messaging need you could think of … check out MDaemon from the folks at Alt-N Technologies.

How good is it? Well, not that long ago, Research In Motion (RIM), you know, the BlackBerry people, bought? the company.
(not positive about the change in ownership as I don’t work for the company)
During this time BlackBerry support was added. Then the market turned, and Alt-N became independent again.

I’ve been using MDaemon for many years now in several environments. I’ve tried others, but keep going back to this one. It just works. Rarely do I find a messaging problem that it doesn’t handle. You *nix fans will even like it. Although it runs on Windows machines, it has a *nix feel to it as everything is kept in files.

beans

Right Sized Project Management Toolset

I have been using Assembla now for a few years and want to give a shout out to the company for making a great product.

If you have not heard of Assembla – it is a Scrum / Kanban / Agile project management system on the web. It is cheap, with prices ranging from free for small public projects to more expensive for multi-project many user service levels. My experience has been with the $490 / year level which gets several private project spaces, a dozen users or so and quite a bit of storage. Check out the web site for current prices and plans.

Swiss Army Knife: Assembla is one stop shopping for managing a project. Features include: Tickets, CardWall, Wiki, Messages, Version Control. Really, everything you need, all in one place, accessible from every place.

Let’s take a look at some of the features in more detail.

Tickets:

Tickets or cards are the most important part of Agile project management. Because they are used so frequently – they should be quick and easy to enter. Ideally – I should be able to just mail in a ticket. Ticket priorities change frequently, so I should be able to drag and drop them. I’ve had to work with systems where entering a ticket is like filling in a tax form. Assembla has just the essentials, nothing more and nothing less. You can add fields, but it is a simple effective system without the scripting that other systems have. I like the simplicity and SPEED.

Collaboration:

Agile is all about collaboration. To me, that means everything is out there and visible to the people who need to see it. The wiki is a great place to put documentation, brainstorming, processes, standards, knowledge base articles etc. Messages encourage brainstorming and provide a stream of consciousness on a topic. Files provide a place to upload Word documents if you are into that kind of thing. You can also link to Google docs. Snippets let people comment and collaborate on a block of code. There is a StandUp tool so that if your team is distributed, you can have not real time stand up meetings. There is a Twitter feed.

Version Control:

Git, Mercurial, Perforce, Subversion, GitHub, BitBucket are all supported.

Assembla can be backed up using Amazon Backup, or you can tell the system to generate a backup set as a file you can download and archive.

There are many charts, and an API if you want to create custom reports off of the raw data.

Ticket views can be customized with filters and adding / removing fields. This is fantastic as it lets lets me get a quick and detailed view of the status of tickets.

Weak areas: The system security is not very granular. For example, you can’t give a consultant access to the source code repository without also giving her visibility into the whole project. Normally visibility is a strength, but in one case, we just wanted to give a consultant access to the repository without giving visibility into the total scope of the project. Time tracking could be improved. For example; if you make a mistake, like entering that you worked 16 hours when you meant to say 6, you can’t change it once it is saved.

Certainly for each individual tool, you could find a better tool somewhere else. However, having everything in one place, in essentially one tool, with cross link capability, Assembla has been a huge productivity boost.

ecobee thermostat review

The new scat pad came with thermostats that look like 1970’s surplus thermostats.

oldthermo
Totally analog. I think they even had mercury in them.
So I started a search for more appropriate units, with a high geek factor. I looked at the Nest 2, which would be OK . . . for my mom. The Nest 2 does not get good reviews, but they look great. People who buy them love them for their design. Read more than one review before making a decision. I also considered the Honeywell WiFi units sold at Home Depot. These units are nice and get good reviews. However, they lack the cool factor of the Nest 2, and the geek factor of the Ecobee.
The Ecobee:
Stat2, http://www.ecobee.com/solutions/home/smart/ has the geek factor and function I was looking for. I can program as many time periods as I want. You are not limited to: Sleep, Awake, Away of typical programmable thermos. So I have Sleep, Awake, Workout, Work, Home. You can also program Vacations. It has a “Quick Save” button, so if the weather is great, touch a button on the way out the door to go surfing and it will set the temp back 4 degrees until you return. The units are WiFi enabled, so they can be programmed via Chrome, or iPhone or Android.
Any geek can install these units themselves. The installation is slightly more complex than the competitors because the Ecobee is two pieces of hardware. There is a smart board that contains the relays etc which connects to your HVAC units. This can be installed anywhere, but is usually close to the HVAC unit itself. The other piece is the thermostat unit, which connects to the smart board. The thermostat unit is a nice sized, color touch screen with a neutral design that is skinable. The smart board can accept a module to connect additional sensors (temperature and humidity). I suppose Ecobee or a hacker could create additional modules. The smart board has a zillion connections to connect to and control about any type of HVAC unit you need to control.
The scat pad has three zones, and thus three of these units. The units are all tied to one account on the web, which means, I can easily control each unit from my phone or whatever.
Ecobee provides extensive reports on your energy usage. If the reports are not enough, they provide an API so you can go nuts creating your own.
Now you are asking yourself, “wouldn’t a real geek build their own system”?
You could probably could build your own, but why? Not to mention, HVAC units are expensive to replace if you get it wrong.
After all, we are just talking about a thermostat.
There are many competitors. So take a look and consider upgrading to a connected thermostat.