Here’s the Egg Drawing robot converted into a simple one-dot dot matrix printer. I’ve borrowed a routine that I used in the Minecraft Relief Maps project and used that to interpret a JPEG file. There are methods which use Pygame, but I’ve stuck with things I know – and can achieve quickly.
The program reads in the image and converts it into a pattern of “#” symbols and spaces using JP2A. For this reason, a decent monochrome image makes a good starting point. Once converted, it’s split into lines and the servos are then made to scan backwards and forwards, putting in a dot wherever JP2A has left a “#”.
I needed to convert between coordinates on the bitmap and the actual positions needed by the servo. This is relatively easy to do once the correct range given by the servos has been found experimentally.
I had a few problems with the pen bouncing, and also the route that the pen takes is really a curve. This would be more suited to drawing bitmaps on eggs, so that’s the next step. Maybe “Egg Minions?”.
import commands import os import time DELAY = 0.002 pen=2 leftright=1 updown=0 def pwm(pin, angle): # print("servo[" + str(pin) + "][" + str(angle) + "]") cmd = "echo " + str(pin) + "=" + str(angle) + " > /dev/servoblaster" os.system(cmd) time.sleep(DELAY) def slow(servo,start,stop): difference = start-stop servopos = start if start<stop: step = 1 else: step = -1 servopos = start while servopos != stop: pwm(servo,servopos) servopos += step def penup(): pwm(2,160) def pendown(): pwm(2,140) def dot(): slow(2,160,140) slow(2,140,160) def servo_off(): pwm(0,0) def servoY(posY): pwm(0,(posY*1.1)+100) def servoX(posX): pwm(1,(posX*1.2)+80) penup() time.sleep(0.5) pwm(1,60) pwm(0,100) wr_str = "MonoLogo.jpg" cmd = 'jp2a --width=20 --height=20 --background=light --chars=" #" '+wr_str # create an operating system command line = commands.getoutput( cmd ) # send cmd as a command to the operating system and receive the result. list_line = line.rstrip().split("\n") # split the result from "figlet" into separate lines (right strip new line feeds) print "Your picture has been converted to" print line yplot=0 xplot=0 for row in list_line: # one row at a time from list_line (the result from figlet) slow(1,(xplot*1.2)+60,60) print row servoY(yplot) yplot=yplot+5 xplot=0 for letter in row: # work along each row - check each character. blockshade=letter # print blockshade if blockshade=="#": servoX(xplot) time.sleep(0.5) dot() xplot = xplot+5 servoY(0) time.sleep(1) servo_off() print("All done!")
Once that’s all running, assuming you have a MonoLogo.jpg file available, the machine will convert and start automatically.