Uncategorized

MixologyBot: Glueing raspberry pi and arduino together with a python daemon

I have been incredibly busy. Friday I had an hour on the laser cutter and managed to complete three Makelangelo 2 kits and then stopped working. I was able to fill one existing order and then the other two sold the same day. I really need to learn about scaling up production. I’ve got parts printing every day to fill back orders on Delta 3, Delta 4, and HOG drive kits. For those of you who have had to wait for your order, I’m truly sorry. It will never happen again because I am never again selling something that isn’t already in stock.

While the parts are being produced I’ve been doubling down by working on the code for the MixologyBot. The only piece of software missing is a bit of “glue” to connect the web pages on the Raspberry Pi to the Arduino. Here’s what I’ve got so far.

[code]#!/usr/bin/python
# -*- coding: utf-8 -*-

# python daemon to connect PHP and Arduino
# [email protected] 2013

from daemon import runner
from time import gmtime, strftime
import serial
import MySQLdb as mdb
import lockfile
import time
import sys

# config
PIDFILE = ‘/tmp/ardaemon.pid’
LOGFILE = ‘/var/log/ardaemon.log’

class App():
def __init__(self):
self.stdin_path = ‘/dev/null’
self.stdout_path = LOGFILE
self.stderr_path = LOGFILE
self.pidfile_path = PIDFILE
self.pidfile_timeout = 5

def run(self):
con = mdb.connect(‘localhost’,’root’,’43jkdf71′,’waddle_igby’)
ser = serial.Serial(‘/dev/ttyACM0’,57600)
cansend = False

while True:
# anything to receive?
numbytes = ser.inWaiting()
if numbytes > 0:
# grab whatever is incoming and put it in the db.
line=con.escape_string(ser.read(numbytes))
if line == ‘>’:
cansend = True
from_cursor = con.cursor()
from_cursor.execute("INSERT INTO `from_arduino` SET transmit_time=NOW(), message=%s",str(line))
from_cursor.close()
con.commit()
#print strftime("%Y-%m-%d %H:%M:%S", gmtime()) + ‘ ‘ + (("<< " + line))

# anything to transmit?
from_cursor = con.cursor()
from_cursor.execute("SELECT * FROM `to_arduino` ORDER BY id LIMIT 1")
if cansend==True and from_cursor.rowcount > 0:
# send it, then take it out of the buffer.
line = from_cursor.fetchone()
from_cursor.close()
ser.write(line[2])
#print strftime("%Y-%m-%d %H:%M:%S", gmtime()) + ‘ ‘ + ((">> (" + str(line[0]) + ") " + line[2]))
del_cursor = con.cursor()
del_cursor.execute("DELETE FROM `to_arduino` WHERE id=%s LIMIT 1",str(line[0]))
#print strftime("%Y-%m-%d %H:%M:%S", gmtime()) + ‘ ‘ + ((str(del_cursor.rowcount) + " rows affected.\n"))
del_cursor.close()
con.commit()
else:
from_cursor.close()

# now take a break.
time.sleep(0.25);

# run the thing
app = App()
daemon_runner = runner.DaemonRunner(app)
daemon_runner.do_action()[/code]

Many special thanks to the lovely people in irc.freenode.net#python for their patience and help. If you use this program, link back to me, send an email, or something. With this the last major software hurdle is

Uncategorized

Laser cutter update: calibrated!

The laser cutter is now assembled and calibrated. I’m working to find the right feed rate and speed for cutting the material I have. Once that is charted it will be a snap to produce parts for the delta robots, Makelangelo, and start testing the frame for the MixologyBot.

I can cut wood, bamboo, jade, marble, organic glass, crystal, plastic, garments, paper, leather, rubber, ceramic, and glass. While the 3D printers are going the laser cutter can be going as well, making me look super productive. …but there will be time when the machine is sitting there, growing cobwebs. Adding a Vancouver laser cutting service sounds like a very doable plan. $3/min runtime + material is the going rate at Metrix: Create Space (who, BTW, are totally awesome and you should go visit). I’ll start there and see how it goes.

Uncategorized

Store updates, July 2 2013

Orders on hold, July 2013

Caching issues
I’ve only just been made aware that most people see the last blog post as may 18, 2013. There is a system in place to deliver web pages to you faster and it has been broken. Here I’ve been making post and working on cool stuff and only my Facebook friends know about it. So I’m working on that right now.

No more date of birth
Don wrote in to ask why the store registration process requires a date of birth. I’d never thought about it before. We don’t! That’s for sites selling adult material. So it’s g-o-n-e. Thank you, Don!

Out of Stock
The Standard Operating Procedure until now has been to list lots and lots of parts and then to make or buy them on demand. That was great for securing a sale, but I’d rather get a sale and ship the order same day. So I’m taking a cue from Lululemon and starting to work on a Scarcity Model – item stock counts will truly reflect number of units you can buy this second. The challenge will be to find out who wants what and make it before they pay. Any advice?

Should we start hiring?
When I started out people told me “if you aren’t turning a profit in 18 months, find something new to do.” Well… this is my passion. After 18 months I’m breaking even, which I’m very pleased with. I think the future looks bright and things are only going to get better. There are some really exciting robots in the pipeline like the MixologyBot and we’re growing our manufacturing base to meet demand.

The oldest challenge for me right now is doing every job. I strongly suspect that if I had people working on my team I’d be making the $ to afford the people on my team. I know it’s a bit of a gamble but life is for living and I’m willing to take a risk now and then. Is there a way to prove numerically that it’s going to work? That’s not a rhetorical question, I really want to hear from you.

Uncategorized

Mixology Bot: Talking to Arduino ||

The Arduino Playground taught me that linux treats serial connections as a file. That means they can be read like a file and written to like a file, with a little massaging. Here’s how to work out the knots:

[code]stty -F /dev/ttyACM0 cs8 57600 ignbrk -brkint -icrnl -imaxbel -opost -onlcr -isig -icanon -iexten -echo -echoe -echok -echoctl -echoke noflsh -ixon -crtscts[/code]

Honestly? I don’t understand it. It’s deep magic that I don’t have time to get into. Something about what the serial connection should and should not deliver.

Anyways, once that’s done I told the raspberry pi to send any new data straight to my screen like this:

[code]tail -f /dev/ttyACM0 &[/code]

tail is a command to display the end of a file. The & tells it “do this in the background so I can get on with my work.”
It now shows me every message coming from the arduino, right on the command line. The very first thing I see is

[code]Mixologybot 1[/code]

1 is the firmware version. I could then echo a command to the arduino like this

[code]echo "help;" > /dev/ttyACM0[/code]

and it responded correctly, but only the first time. Looking closer at the output I realized there was a mysterious newline (the code for the return key) added after every command. My first Google hit for “echo without newline” taught me that raspberry pi needs one extra command. Now I use

[code]echo "help;\c" > /dev/ttyACM0[/code]

The \c removes the newline automatically inserted by bash and makes all communications work as expected. Hooray!

This means I can now have the RPI and the Arduino talking together. The next step is to set up a bash script that pipes commands from PHP to the arduino and back. That way a user can see that the drink robot is ready to pour and tell it what drink to make. Anyone know how to make that happen? Write me, please.

Uncategorized

Makelangelo Software v0.9.6 released

win: https://www.marginallyclever.com/other/Makelangelo.zip
osx: https://www.marginallyclever.com/other/Makelangelo.dmg
OR
win: https://www.marginallyclever.com/other/Makelangelo-0.9.6.zip
osx: https://www.marginallyclever.com/other/Makelangelo-0.9.6.dmg

change log

– open file defaults to image formats instead of ngc files.
– stopped automatically loading last file on program start (would reprocess image file every time).
– image_dpi now remembered between sessions
– image_dpi slider has more realistic upper limit
– some float values were being rounded to produce really long strings that messed up the arduino. they’ve been fixed to two decimal places.
– feed_rate is now passed to jogging controls more accurately.
– gcode is now dumped into temp.ngc every time. save the file somewhere else if you want to keep the gcode.

Notes

In using the software I found that I never reused the gcode so I stopped using it as a default option when loading files.

As of now I’ll be keeping older versions online, just in case.

The next planned updates is all about making a spray paint can holder/actuator. It shouldn’t require any change to the arduino firmware but it will mean big changes to DrawbotGUI and the physical machinery.

As always, please comment in the forums if you have any feedback. I love hearing from you and making things better.