Friday, July 18, 2014

Can Middle School Kids Create iOS Apps?

The Problem

No question about it, Apple does not make it easy to write apps for iOS. I take the fact that the Apple Developer program license is only free to university programs to be just one sign that Apple does not expect many students in K-12 to be making apps, no matter how much teachers may want them to (and they do!). I'm not talking about rare whiz kid 12 year-olds who follow enough tutorials and have enough guidance and a fairly good idea to make an app and get it in the store. I work with teachers who want to integrate app-making for iOS into their science curriculum, with 50 students developing

Wednesday, July 16, 2014

Arduino waitForButtonPress function

Lots of programming robotics languages (RobotC, leJOS NXJ, Cricket Logo, NXT-G) have functions that allow you to suspend processes while waiting for some kind of input. My robotics students most learned about leJOS NXJ's Button.waitForAnyPress() method. When we moved on to programming Arduinos one of them wanted to use the same concept to run a sensor calibration routine in setup(). So we had to make one, and it turned out to be very easy. She was initially trying to do something complicated with boolean variables but I remembered using this simple construct in

Wednesday, May 21, 2014

Keeping Multiple Electroluminescent Wires Bright With An Arduino

I recently helped a student with a nice, provocative installation with kitschy religious imagery that used EL wires to simulate a neon sign. She had a border, made by a yellow wire, framing three words in orange, each made by its own wire. She wanted the border to stay lit while the words blinked on and off. If you've ever worked with EL wires you will know that if they have the same power source, such as an Arduino (with El Escudo Dos controller) the more wires that are lit at once the dimmer they all get, since the voltage is shared. She really should have done the words with one wire but she

Monday, March 24, 2014

Controlling NXT Robot From the Keyboard with leJOS NXJ

Bad GUI for robot control
(UPDATE: So this was all well and good as a proof of concept but we found when we brought the motors into the mix the motors were too slow to respond to direct commands. We learned a lot in the process, though.)

I worked up a proof of concept in leJOS NXJ I'll be teaching my high school robotics students soon for a method of controlling a

Thursday, March 20, 2014

Radio Shack DIY 3 X 3 LED Cube Project

This project is really fun! Lots of people have posted their experience putting it together so I won't do that, but after recovering from a bit of soldering problems what I find challenging, or just tedious, is figuring out exactly what hex codes to use to create arrays for you own programs. I did figure out lighting up individual LEDs 1-9 on each level to make these two patterns, shown one after the other here:

Monday, March 17, 2014

Hands On Tech: Making Ceramic Tiles

Inspired by the brilliant work of Gary Donohue and Josh Burker, I have been working on a project with some of our art teachers that has exciting possibilities. It started with Gary describing his workflow that allows elementary students' line drawings to become 3D printed pieces. Then Josh took that in another direction with 4th graders using Turtle Art to make patterns that can be printed as presses for making clay tiles.
One of our art teachers said this is the idea that fills in the missing link for him with 3d printing--the link between hand-made artwork and digital manufacturing. Other teachers responded similarly, feeling little affinity for a machine that prints digitally designed objects until they could see how hand craft can be a vital part of its use.
I'm working with a high school art teacher and her ceramics class. I made a Processing sketch they can use to generate patterns from several different shapes. Check it out, it's here: http://openblackboard.com/processing/shapetile/.

Conceptually the code of the program is very similar to the one Josh presents above for Turtle Art. Each shape object is made up of a shape method, called by a row method that draws the shape across the window (and a second offset row if you set offsetEvenRows to true), called by a makeRows method that repeats the rows top to bottom. The amount of horizontal and vertical overlap is determined by the slider numbers you give the shape, as well as the size of the shape.
After configuring the shapes they way you want click the save button and download the image. You will want to tweak it before you get your final pattern.
The next step is to crop the image down to what you want just for the tile, so open it in Preview, or some image editor on a PC, and crop down to the desired area. Since you probably want the tile to repeat horizontally and possibly vertically as well this may be tricky, especially if you are aiming to have a square tile.


Save the cropped image and open it in Illustrator. Now you will trace it to prepare it for conversion to a vector graphic. Click Object > Live Trace > Tracing Options. Check Preview and spend some time trying the different Presets. When you have one you like, click the Trace button. At first I tried Detailed Illustration on this one, but when I completed the next step, importing to Tinkercad, I saw that the preset did something very different than I expected, so I retraced it with the Lettering preset and that worked much better.

Click Save as, and choose SVG.
Now in Tinkercad use the section in the upper right to import the SVG file into a new design. It will come in bigger than you want it, so scale it down, holding shift while you drag a corner to keep the aspect ratio.
The height will have decreased as well so raise it back up to about 6mm. Then add a 2mm layer to tie it together. 
And now some results! I can't wait to see them glazed.










Friday, March 07, 2014

A Machine Asking To Be Remade

I've been having a great time teaching students about 3D design and printing, and helping them print things they need. From robot scoops to ears, it's always an exciting surprise to find out when the printer can be a useful tool for learning. One of the more interesting ways it serves as a useful tool is in printing parts for itself. I've found two of these opportunities so far. Early on I could see that the filament tube on the Replicator 2 came out of its clips on the back easily when the extruder had to move towards the back of the build plate. I found a filament tube upgrade on Thingiverse that has worked perfectly.

Then recently a student's dad brought in a few spools of filament to provide more colors for printing. One of the spools has a much smaller hole than the standard Makerbot spools. So I found a spindle, again on Thingiverse, modified it a bit in Tinkercad, and now the spool fits perfectly.

Monday, February 24, 2014

Raspberry Pi Makerbot Cam

We've been using our new Makerbot 3D printer quite a bit since we got in in December in our school. I've been the one learning how to use it and training some students to use it. So it's taken quite a lot of my time watching the results from printing different projects under different conditions. Not every print comes out successfully and sometimes you need to cancel a print because you can see that something is going wrong. And sometimes a spool of filament is running low and you're not sure there will be enough to complete a print. Rather than having to check on it every so often, I wanted to set up a streaming Makerbot cam with my Raspberry Pi and the new Pi Cam I got for it so I can oversee prints wherever I am.
The Pi Cam produces very nice quality still and video images and there are some very good tutorials on making it do lots of different things.
I like to do things a little at a time, so in this post I'm outlining the steps toward the eventual goal of streaming video and some of the hurdles on the way to getting there.

Getting the camera working

Getting the camera plugged in and snapping pics and video was easy and fun. The Raspberry Pi folks have put this information together here: Raspberry Pi Camera setup. In the process I wanted to start using the Raspi in "headless" mode to make it easier to get the photos off. My email client doesn't really work on it and plugging in a USB drive to copy files takes time. 

Remote access to images

From a Mac I use Terminal to log right in to the Raspi. Get the Raspi's IP by typing ifconfig on the Pi (connected to a monitor with peripherals), then use that to log in with SSH:

ssh pi@ipAddress
Now I'm at the pi prompt and can type the camera commands to take pictures and video. But the files are saved on the Pi. To get them off, log out of the ssh session. I used SCP to copy them to my Mac:

scp pi@ipAddress:image.jpg Desktop/image.jpg

puts the image right on my desktop.

Streaming video to a website

Miguel Grinberg has a great method of setting up a constant stream of images to the web from a Raspi Cam here. The idea is not to stream video, but to take stills in rapid succession, each new one replacing the previous, and stream those with MJPG-Streamer. So far it's pretty choppy for me, but I haven't played with the framerate yet. I can probably tweak it to get a smoother stream. Here is a sample:
There is a point in Grinberg's tutorial where he provides an update on installing MJPG-Streamer. Definitely follow it. The information is crucial to getting it to work successfully. I found a couple Linux command line tools useful. To stop the raspistill process before it's finished, first log out of the SSH session (the trailing & allows you to log out without killing the process), log back in and type:
$ ps aux | grep raspistill
That shows the raspistill process ID. Then you can kill it with:
$ sudo kill 2314 
(or whatever it's process ID is)

Running the streamer from button input

So I don't want to have to log in to the Pi and run this line of code every time I want the Pi to stream Makerbot footage:
$ raspistill --nopreview -w 640 -h 480 -q 5 -o /tmp/stream/pic.jpg -tl 100 -t 9999999 -th 0:0:0 &

What I need is a button I can press on the Pi that starts taking pictures for an hour or two. So I've ordered this setup from Adafruit--a GPIO ribbon and breakout board--to which I'll wire a button. The MJPG Streamer is always running, so all it needs is the pictures to dump into the streaming folder. This took some time to figure out. Here is the wiring below, which includes wiring for a momentary switch and an LED that will stay on as long as the camera is taking stills. The LED on the camera would work were it not for the camera enclosure I printed, which covers up the LED. I know, I could have drilled one or put it in the design, but a little more wiring is fun. Some tips on this setup follow:
Note: LED is on because switch has just been pressed.
To figure this out, I mostly used these two resources; buttons and switches and blinking LEDs. Initially the switch did nothing because I made the mistake of having the GPIO ribbon reversed. Heed this advice and make sure the single different colored wire on the ribbon--in my case, white--is oriented so it is towards the outside facing end of the Pi, not towards the middle. And on the topic of GPIO pin numbering, I am using BCM mode, which is a confusing topic for beginners like me and well explained here (down the page at A Word About GPIO Pin Numberings). The concept of pullup and pulldown resistors is still a little fuzzy to me, despite having dealt with it before with Arduinos, but I am pretty sure I have a pullup resistor here because there is no resistor between the button and ground. I need to attend a pullup/pulldown workshop, clearly.
So for the programming I used Python, which is typical on the Raspberry Pi. I made one Python program that 
  • configures the GPIO pins, 
  • turns on the LED when the button is pressed, 
  • runs a shell script that creates the /tmp/stream directory (for some reason it keeps disappearing) to store the images, 
  • starts the raspistill command, 
  • starts MJPG Streamer (if it's not already going), 
  • then turns off the LED when those finish. 
Note the trailing & after the MJPG Streamer command. That allows raspistill to start even though the MJPG Streamer process hasn't been stopped. The omission of & at the end of the raspistill command forces the LED to stay on until it has finished, though. The original program in the buttons and switches tutorial had prev_input = 0, but I had to change it to prev_input = 1, or the program would run without being pressed the first time, I think because my switch is being pulled high when open (not pressed), so ((not prev_input) and input) was initially true when prev_input was initialized to 0.
Here is startcam.py:
And here is the shell script startMBCam.txt:
I tried to get startcam.py to run at startup like is shown in the buttons and switches tutorial but MJPG Streamer would not run. I could tell the camera was snapping images but nothing was accessible at the streaming IP.
UPDATE: I got the program running automatically when the pi boots! I added the startCam.py program to the /etc/rc.local file to run it on startup, and included the full path to mjpg_streamer in the startMBCam.txt file: /home/pi/mjpg-streamer-code-182/mjpg-streamer/mjpg_streamer 
I also soldered a pretty sweet board for the button and LED, and connected them to the GPIO pins without the ribbon, just directly with female header connectors.




Creating a box for the camera

For this part I found a nice Raspberry Pi Camera case design on Thingiverse and used Tinkercad to modify it a little. I moved the ball connection to the bottom of the camera case front and flattened the ball socket.

The next and final step will be mounting the whole apparatus near our Makerbot with power and ethernet attached, but that will have to wait until after break.


Wednesday, January 01, 2014

Tri-color LED Project: Mineral Light Show

My son has a piece of hambergite--I'm pretty sure that's what it is--and I've been wanting to give it special lighting for a while. Finally got a tri-color LED and wired up some switches so the colors can be turned on in combination. With this setup you can make 7 colors, red, green, blue, of course, and their complements, yellow, cyan, and magenta, and with all three, white. Hambergite is translucent with cleavage running straight along the length of it, so light travels through it well. So here are some pictures of the results.