Thursday, February 11, 2010

1^2 + 2^2 + 3^2 + 4^2 + 5^2 + ... + n^2

It is well know that the sum of the squares of integers S is n(n+1)(2n+1)/6. And proofs abound. Although this relationship is not difficult to prove by mathematical induction, it is not intuitively satisfying. This visual proof is very clear and easy to understand.

Elizabeth, my 10-year-old daughter, wanted to figure out the volume of a sphere. Making approximations using 16 equal thickness coin shaped cylinders as seen below.

We ended up with an expression that contained in part, the sum 1 + 4 + 9 + 16 + 25 + 36 + 49 + 64.  It was clear that if we had used instead n coins each of width 1/n, to approximate the volumn, part of that expression would intail the sum Sn = 1 + 4 + 9 + 25 + ... + n^2.  To no avail, I looked around for a simple way to demonstrate the well known relationship:
Sn = n(n+1)(2n+1)/6.


Imagine the sum Sn as the volume of the pyramid of 1 x 1 x 1 cubes with one cube on the top layer, 4 on the next, 9 on the next and so on up to n x n cubes on the bottom layer as seen in the figure above.
From the expression Sn =n(n+1)(2n+1)/6, we see that Sis one sixth the volume of a box with dimensions n x (n + 1) x (2n + 1). So it is at least conceivable that six of these pyramids could be packed into that rectangular volume. Elizabeth and I glued 30 wooden cubes into 6 two-layer pyramids (1 x 1 + 2 x 2) as shown

and without too much effort arranged them into a 2 x 3 x 5 rectangular volume.


The configuration is general, in that it can be scaled up to any positive integer n. Here are some screen shots of a Python simulation using n=4 demonstrating the configureation.


Now fast forward a few days. Snowmaggeddon has snowed me OUT of Reston, VA, and I'm stuck in LA on a rainy Saturday. Amy (lovely wife) scouts out a meeting of the LA Microcontrollers Club from the Make Blog. The once-a-month meeting was scheduled to start in only three hours. A quick peak at the map revealed Topanga, CA, to be just up the mountain North of Santa Montica, about a forty-five minute drive from my hotel. Sweet.

Luckily, I got an early start because the direct route was closed because of the Niagra of mudslides. Rerouting was tricky with my gps-phone rebooting every two minutes. I finally arrived at this beautiful location at the end of a mile-long jeep trail.  The Ford Focus I was driving had trouble negotiating the rutted climb, but the view was worth it.


It was fun getting to know Jack, the founder of the LA Mircrocontroller Club and freelance maker (see see buffingtonfx.com) and Nick, a freelance Hollywood tech.

Nick brought his Arduino-based movie prop clock that stays on whatever time you set it and won't flicker when filmed. Jacked showed off his awesome shop, with a DIY CNC router, and shared his recent experience with the Propeller development board.

Getting to the point, Jack kindly offered to route out the pyramid shapes with his CNC router. Literally, an hour later, Jack had produced three perfect five-layer pyramids. He would have made all six, but I was already late for another appointment. Had I known that Jack was planning to give the pyramids to me, I definitely would have waited for the top half of the retangular volume!


Thanks Jack!

Wednesday, February 10, 2010

SharkBoot (Arbitrary clock speed)

To save batteries, Anool are considering running the SharkFin at 3.3V with a 12 MHz resonator.  That means that the bootloader needs to be recompiled with the new CPU speed.

Steps:
1. Download Makefile from ladyada.net here.
2. Add new target by modifying adaboot328 to Makefile (I called it sharkfin328)

sharkfin328: TARGET = sharkfin328
sharkfin328: CFLAGS += '-DMAX_TIME_COUNT=F_CPU>>2' '-DNUM_LED_FLASHES=3'  '-DWATCHDOG_MODS'
sharkfin328: $(PROGRAM)_sharkfin328.hex
sharkfin328: AVR_FREQ = 12000000L 
sharkfin328: MCU_TARGET = atmega328p
sharkfin328: LDSECTION  = --section-start=.text=0x7800

3. >make sharkfin328
4. Upload  see here for details.

The new board will look like a "Arduino Duemilanove or Nano w/ ATmega328" inside of Arduino.

Saturday, January 30, 2010

BEBL Board Has Arrived!




The boards Anool sent before Christmas have finally arrived. Looks like the envelope got hung up in the sorter as you can see the torn corner. No worries, the boards arrived unharmed and they are even smaller than I had imaged, 2x5cm.

Now to find a case...
UPDATE

Emily found this tiny Altoids tin that is just right!

Bootloader woes!

I have some AVR 328s that I'd like to upgrade to LadyAda's bootloader. Which has a couple of features for homemade arduino boards:

1. Three flashes on reset. Her bootloader flashes pin 13 when reset occurs.
2. Upload flicker on pin 13.

Although not absolutely necessary, it sure is nice to get the positive feedback that things are working when any number of things can go wrong with a home build duino.

The MegaISP seemed to work ok, but requires 2 arduinos to program a new Mega chip: one to run MegaISP, and one to house the chip to be programmed. I thought I could simplify things by buying this programmer, but it has been difficult to get this working.

Here is how I got it working on my Linux box.

1. Power the chip. The programmer does not supply the power to the chip as I discovered. So I was beating a dead horse for a day not knowing this simple fact.

2. Disconnect anything from the board. When I powered the board, I still got the same error. avrdude stk_500v2 not responding. I had an LED connected to pin 13 that I guess was sapping the signal from the micro back to the computer.

3. Plug programmer into usb port. You should see a device /dev/ttyACM0 or similar. That is the programmer. Green light on programmer should be on. If you are an avrdude guru, you probably already know to use the -P /dev/ttyACM0 option. I had trouble getting avrdude to write the efuse, so I tried using Arduino IDE to write the bootloader.

4. Unplug arduino from usb, power it with a 9v or otherwise through VIN. We are going to program the chip through /dev/ttyUSB0 and we don't want to figure out if USB0 is the programmer or the duino. Just unplug it from the usb all together and use external power.

5. Arduino IDE expects to see the programming sitting at /dev/ttyUSBX and it is actually at /dev/ttyACM0. The solution here is so simple I never thought it would work. Use a soft link. I don't remember where I found this solution, but it works.
> sudo ln -s /dev/ttyACM0 /dev/ttyUSB0

6. Select Tools->Burn Bootloader->w/AVRISP mkii. After a couple of minutes the bootloader is loaded.

7. Upload blink.pde. If this loaded congratulations. This worked for me with the standard bootloader: ATmegaBOOT_168_atmega328.hex.

8. Move standard bootloader for safekeeping, cd to Arduino/hardware/bootloaders/atmega/
> mv ... /bootloaders/atmega/ATmegaBOOT_168_atmega328.hex /bootloaders/atmega/ATmegaBOOT_168_atmega328.hex-orig

9. Copy AdaBoot to expected bootloader location
>mv ATmegaBOOT_xx8_adaboot328.hex /bootloaders/atmega/ATmegaBOOT_168_atmega328.hex

10. Tools->Burn Bootloader->w/AVRISP mkii (again)

11. Upload blink.pde. This is where I am stuck. Blink will not upload. I see this in the output window after I see the 3 blink reset (so I know adaboot is running):
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_recv(): programmer is not responding

Manual reset (at different delays from upload click) makes no difference.

UPDATE!
LadyAda suggested that perhaps the baud rate for the hex file I was using was 19200. This turned out to be the case. I modified */hardware/boards.txt by changing

atmega328.upload.speed=57600

to
atmega328.upload.speed=19200

and got blink.pde to upload and run. Thanks LadyAda! The real fix is to upload the 57600 hex adaboot file. Look for an uplate when I get this to run.

UPDATE:
I recompiled LadyAda's AdaBoot with the baudrate changed to 57600. Download the hex file here.

Or, to compile it yourself:

Download and unzip AdaBoot.

Change the baudrate in the C source code will do the trick. Line 90 of the source code reads:
#define BAUD_RATE 19200

Change this to
#define BAUD_RATE 57600

Then from the command line:
> make adaboot328

If you have all everything you need installed you will generate a hex file. Or you can use this 57600 hex file if you don't.

To upload with avrdude only try just talking to the chip first:
> avrdude -c stk500v2 -p m328p -P /dev/ttyACM0
(change -P as necessary)

If that works, this script will upload the hex file using only avrdude
#!/bin/sh
# change -P as necessary
#
# find extended, high, low, lock, and unlock bits on hardware.txt
OPTS="-c stk500v2 -p m328p -P /dev/ttyACM0"
avrdude $OPTS -U efuse:w:0x05:m
avrdude $OPTS -U
hfuse:w:0xda:m
avrdude $OPTS -U lfuse:w:0xff:m

avrdude $OPTS -U lock:w:0x3f:m
avrdude $OPTS -U flash:w:ATmegaBOOT_xx8_adaboot328.hex:i
avrdude $OPTS -U lock:w:0x0f:m



Here is a picture of the programming setup.  I had to stack several 2 x 14 DIL sockets to make room for the 6 pin programming cable.  The green socket has a lever that releases the chip... handy.

AdaBoot: Succeed!

6-22-2010 Update:
I am pleased to confirm that this process works with fresh ATMEGA 328 chips (no previous bootloader installed).

May 30, 2011 UPDATE:
I just got a new set of MEGAs from digikey with a different device signature.
The old signature that avrdude expected is
"0x1e950f".

The chips I received with the same part number had a signature of
"0x1e9514".

There are two ways to handle this.  The easiest is to use the -F option with avrdude to force it into action regardless of the signature.  The second is to change the device signature in avrdude.conf (mine was located in /etc/avrdude.conf).  Search for 328, then search again for signature.  I commented out the existing line and modified it like so
# signature = 0x1e950f
signature =0x1e9514

This works like a charm until you need to program older chips in which case you need to revert to the original version.


Tuesday, January 19, 2010

Good bye suburban ignorance...

Hello Urban Awareness!




Jacket finally arrived today, we were all dazzled by the glow of the coat and by our new found urban/youthy chicness.

This coat rocks.

Monday, January 18, 2010

First Draft SharkFin Layout!


Anool, turned around the sketch below into the layout seen here in 12 hours, and he has a real job to boot! I'm starting to think the SharkFin is going to become a reality. Priya has offered to help out with the enclosure, with her eye for design, we have a hit for sure.

Sunday, January 17, 2010

SharkFin Preliminary Layout

Here is a rough layout for the SharkFin.

Notes:
1. The lower right hand corner is square. All components are aligned relative to this corner. The actual orientation will put the LEDs horizontal.
2. SparkFun and Pololu make the layouts for the three daughter boards available. It may save a lot of space and money to put those parts right on the motherboard. For know, routing can be done underneath of the daughter boards.
3. S1 is reset, S2 is for mode changing (night/day), S3 is power, and SEL is power select.
4. Note Power Down pin on Gyro is grounded. This stops spontaneous shutting down of the gyro.
5. I'm not sure if power select is required. I'm worried that I would be able to communicate through the USB at the 3.3V level provided by the power supply circiut.
6. The ATMega 328 is only rated at 12MHz for 3.3V. Not sure how this will impact serial connection. Might just fudge a little and try the 16MHz osc at 3.3V. Seems to work on the BEBL!
7. Routing may be tricky. Looks like a two sided board to me.
8. D5 is not an LED, but a Zener Diode as for programming feedback ala LadyAda's supped up boot loader.
9. The two large circles are through holes for mounting the board to the helmet.

Thursday, January 14, 2010

Anool's Brake Light: Succeed

Anool has completed his brake light and it looks awesome! He started by prototyping on the Duemilanove. Once he understood the circuit, he designed a printed circuit board. Finally he designed and built this elegant project enclosure. The aluminium mount doubles as a power jumper, eliminating the need for a separate switch.


Great job Anool!

The central blue LED was too bright and had to be turned off to capture this video.

Tuesday, January 12, 2010

Brake Light Mod!



Instructables reader, Anool, has printed up some PCB's from the BEBL schematic. This larger 5-light version will be mounted on the seatpost. He was generous enough to send me a couple of the boards. I'll be looking forward to receiving them.

If all goes well, Anool and I will have the SharkFin boards ready soon!

Thanks Anool!

Wednesday, December 30, 2009

Scopy




To debug the gyro voltage on the SharkFin, I made a simple Arduino based oscilloscope. Single channel, no triggers, no frills.

Python, pylab, and gtk are required.

1. upload scope.pde to arduino
2. edit scopy.py to point to your Arduino (see Tools->Serial Port in Arduino IDE)
3. run scopy.py on computer
4. if you improve either, please send me the update.

Tuesday, December 15, 2009

BEBL Takes "Light Up the Night" Grand Prize!



WOW, Instructables just announced that the BEBL won the Light Up the Night Contest! They are shipping out the sweet Grand Prize "Urban Awarness Jacket" from Cordarounds.

I entered the contest on a lark when I entered the Arduino Contest. Who would have guessed?

Thanks for all the support!

Thursday, December 03, 2009

BEBL Instructable takes 2nd Prize

The BEBL instructable took 2nd prize in the instructables Arduino contest. Thanks to everyone who voted!

Saturday, October 31, 2009

Take the BEBL Challange!

In order to encourage people to make the BEBL, I am offering $35 to the first person to build and demonstrate a functioning BEBL system. That should be enough to cover the cost of the electronic components.

To claim the prize, post a video on line of your accomplishment demonstrating functionality both on and off the bike. The video should include close-ups of the completed hardware. I will address any assembly questions posted here or at Instructables.

Good luck!


The Bar End Brake Light instructions have been made into an instructable and entered into the Arduino Contest.

Sunday, October 25, 2009

Jack-o-duino

Elizabeth and I were inspired this entry in the Instructables Arduino contest. We replaced the servo with a relay to the same effect. It's loud. If we were bomb makers, we'd be dead several times over. Source code can be found here.

Tuesday, October 13, 2009

Arduino contest at Instructables!

Keep an eye out for BEBL on Instructables.com. I'll be entering it into the Arduino contest.

Saturday, September 19, 2009

BEBL: Updated schematic

Here is the latest schematic for the Bar End BrakeLight BEBL. Got in the first test ride and it performs amazingly well. The response time seems almost clairvoyant. Ahhh, it feels so good when it stops hurting.

The main change is the power supply fix mentioned in the previous post. The 6V battery I used is this one from RadioShack, but you can find it cheaper on the web. Other changes to note are the power select jumper and the power switch.

The power select jumper allows switching power between the regulated 3.3v from the accel and 5V USB power. This allows the unit to be programmed. The 5V from the USB only powers the micro controller. The 3.3V sensors are therefore protected from the extra voltage. AREF remains connected to 3.3V. I found the switch S2 at Radio Shack. It is perfect. You can access the switch and it stays concealed under the bar. Sweet.

Friday, September 18, 2009

Duh, use the 3.3 Volt regulator on the accel!

So there was a current issue with running directly off of the battery. I was getting variable readings on the accel when no accelerations were being applied. I'm no EE, so power supplies are a mystery to me. May be the unregulated power was experiencing boom and bust cycles like Wall Street.

Then I remembered the 3.3V regulator on the accel breakout from pololu. Now I run the power right into Vin on the accel and power the rest of the circuit off of the 3.3V regulated output-- fixed. I'd appreciate any better explaination if you know have one.

Now back to the software.

Monday, August 31, 2009

Bar End Brakelight Working... kinda.

So the hardware on the bar end brake light prototype is complete.


I need to work on the software to get the sensitivity right (solution posted here). The initial code only used one axis of accel data. Better to use two and compare against a floating reference. If an absolute reference (say horizontal) is used, stopping on a hill might trigger the brake light. So more work to come.

I was definitely pleased with the package which slides right into the bar snuggly. I had to shave off some plastic on the DIP socket to get the oscillator to fit. The chipped part above (upper left of IC) is a testament to the snug fit. I used an unregulated 6V mini battery to power the circuit which is the max voltage rating for the Mega. The accel has its own 3V regulator. The accel reading seems to be coupled with the LED on/off state. Maybe I need larger caps on the digital and analog pins. Any ideas welcome.

I use the arduino environment to program the Mega. Below is my development board with the same accel plus a gyro that will eventually go on the SharkFin. After I program the chip, I pop it into the socket on the bar end unit.

Dev Env


This picture shows the unit installed. I found the perfect switch at Radio Shack (see bottom of picture).

Saturday, August 22, 2009

Bar End Brakelight

I've been making progress on integrating the gyro with the accel. When the electronics are done there is still the whole question of packaging! I decided to put togethere a simple bar end break light to get the most bang for the buck early on. Need to add the oscillator and a switch and I'll be up and running.

Here is a pic with a wine cork for size comparison.


And simplified schematic.