Summer wrap-up part 2 (The problem with shade)

If you’ve noticed in the image of the solar panels in their natural habitat (my backyard) you’ll see that much of it is shaded.  This isn’t always the case, however it’s very much the case after mid-August once the sun has declined enough in the sky and the foliage from the trees is in its fullest bloom.

This presents a problem for those that might be in slightly more wooded areas that still would want to use the power of the sun to gather electricity.  So how does one get around that?

Cells could be mounted higher, certainly, but that might be an impossibility for land that’s surrounded by very tall trees.  Cells could be spread out to various sunny areas, but they’re not going to be efficient as they’ll most likely only be in sunny areas for part of the year.  Additionally, spreading them out means longer wires being run and an increase in power loss along this wiring.  Plus, solar panels get pretty gross over time and they need to be accessible enough to give a good cleaning.

So let’s make a solar panel that goes where the sun is. The concept goes like this:

  1. An array of batteries is stored in a housing, all of equal physical size and capacity
  2. A robotic arm takes a discharged battery out of the housing and places it on a mobile bot
  3. The robot navigates the land using GPS, radio communication to a central server, and various sonar/infrared sensors to avoid obstacles and find a nice sunny spot.
  4. It parks on the spot and deploys a solar panel to charge the battery it’s been assigned, along with its internal power source.
  5. Once charged, it navigates back home where the robotic arm takes the fully charged battery and places it back in the bank.
  6. It then loads another discharged battery onto the bot and the cycle repeats.

Seems simple enough, right?  Doesn’t seem economically practical at all unless the swarm of bots doing this is big enough.  Probably still isn’t a break-even point in there.  Don’t care, it’s neat.  So let’s get started.

 This is the basic construct for a platform that will bear the weight of the battery.  It will not have a motorized drive-train as there would be a huge draw of power just bearing the weight of what is above it.  It’s made up of a few parts from a Tamiya Tracked Vehicle Chassis.  For this project I used a total of three of them.  They’re about $15 a pop on eBay.

Through this base I run two 3/16″ smooth and one 1/8″ threaded rods.  This will connect to the drive trains and allow it to move closer and further from them, allowing the power of the chassis and the weight of the battery as an anchor to articulate the panel.


Here it is tied to the chassis, each of these have a drive train and motors attached.




A motor is attached to the back with gearing to turn the threaded rod which is held in place at the connection point to the drive train chassis, articulating back and forth respective to the circuit’s polarity.


The wiring is snugged inside of some acrylic tubing and housed above to keep things nice and neat.  What isn’t pictured at this point is an additional drive-train attached to the front and mounting brackets for the panel.  Because I’m lazy and didn’t take any more pics.

The battery you’ll notice has securing brackets.  These are spring-loaded so that lifting the battery swings them away from the terminals and lowering the battery connects it to the terminals automatically.  Once complete, the system will detect a power-on with the connection of the battery, secure it with additional articulating power-driven latches (not pictured, but done) and run some self-tests.

Time to see how this thing handles the backyard terrain.  As I’m writing this I know the results of said tests but you’ll just have to wait until I get around to telling you about them.



More maths

What you’re looking at is a case I’ve built to house the accelerometer module for the solar tracker.  It’s connected to the breadboard where the accelerometer itself was located yesterday.  I cut up a standard 6′ network cable and soldered it into a PCB along with the component.  Notice the distinct “North” label on the top of it.  This is absolutely critical in the calculations to ensure that the feedback the accelerometer provides coincides with the values that the MCU is expecting in order for the system to actually point directly at the sun.  This is a bit of an annoying downside of not using light detecting modules as sun-seekers.  It’s now dependent on perfect alignment with the azimuths.  This is, however, pretty manageable with either a hand compass or a compass module placed within the system.

Also, I discovered a slight cock-up with my maths from yesterday.  The Y-axis calculations are much simpler than I’d originally thought if I use the hour angle for the X-axis.  Then the Y-axis is simply the present latitude less the declination angle.  This isn’t a 100% accurate calculation, as it does not take altitude into account.  This is a pretty acceptable margin of error, however, in that it would take miles of altitude to have even a minute effect.

So I did a lot of calculations for nothing, really, is how it turns out.  Also my hour angle calculations weren’t taking DST into consideration, which was causing the expected X-axis angle of the sun to be off by 15°.

But that’s all fixed now and you’ll see the results here:

The Ideal X/Y values are positions the MCU expects the solar panel to be in to be staring directly into the sun.  The Actual X/Y are the values received from the accelerometer.  The reason for the deviation is because I’m just holding the thing to take a picture.  This feedback, however, will drive two DC motors that will manipulate the position of the panel.  Once I design it.  And the build it.

That’s all for now.

This is Sonny.  He’s awesome:

Here comes the sun

Our intelligence and our technology have given us the power to affect the climate. How will we use this power? Are we willing to tolerate ignorance and complacency in matters that affect the entire human family? Do we value short-term advantages above the welfare of the Earth? Or will we think on longer time scales, with concern for our children and our grandchildren, to understand and protect the complex life-support systems of our planet? The Earth is a tiny and fragile world. It needs to be cherished.

– Carl Sagan (1980)

By spending ~$25 and about 15 hours of research all issues that were previously blocking me from being able to calculate exactly where the sun would be on a given day and time have been completely resolved.

So let’s take a look at the mess that this triple-sized breadboard has become:

You’ll see a few new things on this board.  To the left, attached to the Arduino Mega 2560 is a memory expansion breakout board.  This ties directly in to what is unfortunately 40 pins of the board.  The good news is that 16 of them can be disabled and are accessible via headers on the expansion board.  Doing so disables half of the additional memory the board provides, so it must be used cautiously.  More on that later.  I haven’t soldered female headers into this yet as I don’t suspect I’ll need them.  Any additional sensor requirements can be driven from the available ADC pins.  Anything else can be handled through shift registers if necessary.

On the center right of the board, you’ll notice a button battery on a breakout PCB.  This is a real time clock module.  The battery serves as a method by which the 32.768MHz crystal can oscillate and maintain time when power is not supplied by the microcontroller (MCU).  It streams the time to the MCU and allows time accurate to +/- 1 sec/year to be used in all calculations without any external time source.

To the right of the LCD screen there are two other breakouts.  The right one is simply a 5-direction switch which will be used to navigate settings menus on the LCD screen once those are coded, so it isn’t being utilized at all.  The left one is a 3-axis accelerometer, which provides angle information relative to the earth.  This is also not wired at the moment, but will be shortly.  It will be used to measure the angle of the solar panel as it is actuated based upon the calculations the MCU provides.  Again, more on this in a bit.

MegaRAM Breakout

This is the breakout board purchased from [Rugged Circuits].  There are two chips on this circuit.  The right chip is a controller that manages communication between the RAM and the MCU.  The left chip is the actual RAM. It contains 128Kb of additional memory that is fully integrated into the MCU’s address tables.  Mostly.  Because the ATMega2560 uses 16 bit addresses, only the first 64Kb of memory is immediately addressable.  This includes the 8K of onboard memory as well.  By doing nothing but plugging this board in and setting a pin high to power it, 56Kb of additional memory is gained.  This leaves 72K unused.  Through the onboard controller and some manipulation of timing as well as very careful programming, the 72Kb can be accessed separately, broken out into several separate memory banks.  It’s a pain in the ass and unnecessary at the moment.  It also eliminates the possibility of using the 16 breakout pins.  Because I don’t need it at the moment and I would have to rework a great amount of code I’ve left the total memory at 64Kb (including the base 8K).  If I need more it’s there but for now it’s just hanging out laughing at the other RAM as it’s working its ass off.  What a dick.

RTC Module

This is the RTC module that’s been touched on a bit already.  It has a two wire I2C serial interface with the MCU.  I2C is an interesting architecture because it allows 128 separate modules to be strung together through a 6-bit addressing scheme using only a data wire and a clock wire.  Well worth the sacrifice of two pins.  Also, these are two-way communication pins.  The time is settable and readable with some very simple wiring and commands.  This module, including shipping, cost a little over $5.  Why did I spend so much?  Because one excellent feature of this unit is that in addition to being able to manage accurate time through the year 2100, it also has 32Kb of EEPROM that can be read/written.  This will be very useful for saving state information relevant to battery charge cycles, sun tracking progress, etc should the unit lose power or be put into a low power standby during its cycle.  It can also help save some basic logging/debugging information as the system is built.  Before I’m done I’m sure I’ll put an SD card into the mix for some more interesting logging, but for now this will be a very nice to have.

Triple-Axis Accelerometer

The module on the left is a triple-axis accelerometer (created by Virtuabotix [awesome people to deal with]).

This project only really requires two axis, so the X and Y will be the only ones wired.  But a bonus feature of this board is that it has a low-power mode that puts it to sleep when the MCU doesn’t need it.  Another interesting feature is free-fall detection.  If the board ever experiences zero G, it can set a free-fall pin to high in ~2ms.  Again, not needed for this project but probably pretty handy as a “hey by the way this whole thing you spent a lot of time on is hurtling towards the Earth at the exact speed Newton said it would…” alert.

Now to the maths…

Here are three shots which are simply values cycled through the LCD:

These are the 12 output values currently being calculated.  You’ll note the voltage, cell temperature, and power loss due to heat, which have been here for a while now.  Below those is the current date and time provided by the RTC.  This is what the rest of the calculations mean:

Solar T: This is the solar time.  It is the time that the photons currently hitting the earth left the sun, adjusted for the earth’s position in orbit, angle relative to its orbit around the sun and the sun’s wobble as it orbits the galaxy.  It’s also off by an additional hour because the sun doesn’t care about daylight savings time.

Local T: Local time, the current time at the MCU’s current place.  This is the same as the time provided by the RTC.

Sunrise/Sunset:  The sunrise and sunset times for the current day (adjusted for altitude, DST)

Declination: This is a value that fluctuates annually between 23.45°N at the Summer Solstice and 23.45°S at the Winter Solstice.  It is displayed here only as information as this value is already encapsulated in other values that are the ones we’re most interested in.

Altitude (Angle): This is how high in the sky the sun appears to be relative to the southern azimuth.  This will be a critical value in the final positioning but is also encompassed in another measurement.

Azimuth (Angle): This is how far from the southern azimuth the sun would appear to be if it were at ground level.  This is also critical, but also encompassed in other calculations.

Hour Angle: This is the angle of the sun from -90° to 90° as it moves across the sky throughout the day.  It is at -90° at sunrise and 90° at sunset.  Also a very critical value.

The position of the sun in the sky can be reflected with the hour angle serving as the X axis and the azimuth serving as the Y axis, inverted 90° out of phase.

The accelerometer will provide feedback on the panel’s position regardless of whether or not the panel’s mount is level on the ground.  This saves having to worry about the panel’s X-axis being perfectly aligned.  The Y-axis, however, can be an issue in that the panel’s mount must be perfectly aligned with the azimuth.  Also, the current latitude, longitude and altitude (relative to sea level) values are hard coded.  By adding GPS and compass modules, these values could also be computed, making the system entirely autonomous when it comes to seeking and harvesting light.

Time to build the mount.

And to throw in another Carl Sagan quote to complete the posting sandwich.

The neurochemistry of the brain is astonishingly busy, the circuitry of a machine more wonderful than any devised by humans. But there is no evidence that its functioning is due to anything more than the 1014 neural connections that build an elegant architecture of consciousness.

– Carl Sagan (1980)

Too much to remember

An important part of the circuitry driving the solar charger (at least to me) was granting it the ability to calculate the position of the sun for a given date/lat/long/etc…

Well apparently that’s too much to ask of my little ATMega2560 controller.  He’s only loaded with 8K of onboard memory.  That means that while he’s doing things like updating the display on the LCD screen, multiplexing the 7 segment output, and monitoring voltages and temperatures of the panels he shits himself when trying to recalculate the position of the sun.  The controller freezes up and makes my boner sad.

Now for the choose your own adventure portion of our meganerd saga.

To overcome this memory limit I have a few options:

  1. Try to optimize the code using shorthand integer mathematics to get roughly-right solar position calculations.
  2. Add an external 128K RAM chip to the controller, which boosts my total available memory to 136K but robs me of 24 output pins.
  3. Re-implement the software in C or Assembly on a Parallax Propeller microcontroller board, which supports multithreading but would require more external circuitry as it uses 3.3V logic levels instead of 5V.
  4. Offload the heavy duty calculations to a PC and add a network interface to the controller to ping the PC for this data on a set interval (weak).
  5. Ditch the calculations and do analog sun-hunting with light sensors (lame).

Since this post doesn’t really have any possible images and pictures are nice here’s Burt Bacharach:


Comments welcome, I’ll be making my decision today.


Space and time

Once the calculations began for figuring out where the sun is and importing the time management libraries and such, the microcontroller started to scream uncle.

I had the time, but I was running out of space.  Both in internal flash on the MC and in available pins.  The pins could have been worked around with more shift registers, but those are one-way communication devices.  Input space would become pretty limited.  And there certainly wasn’t going to be enough room for even the most optimized code to do a proper job and fit tightly into 32kb.  And I have a smaller project to do with that board.
Introducing the Atmel ATMega2560.  It’s roughly the same price as the prior ATMega328 that I was using.  But instead of 32kb it boasts 256kb of flash memory.  Instead of a single serial port it boasts 4, and instead of 17 available IO pins it has 69 (lol).
I’m now officially out of excuses for postponing the big sun positioning crap.

Shift registers, multiplexing, and what it means for your weekend

Ideally, it would be nice to be able to know more about what’s going on in a solar panel than to use a multimeter or lick wires every time you want to verify that it’s working.
Also you don’t want a whole lot of your microcontroller’s pins surrendered to basic things like incoming voltage/amperage/cell temperature/etc.
Also if you’re like me you don’t mind overcomplicating things and buy more transistors than you know what to do with.
That’s where the TPIC6B595 high power shift register comes in.  If you’re a supernerd like me you can check out the datasheet here.
If you’re not a nerd but still sorta smart, basically a shift register lets 8 bits stream into it via serial input and outputs it in parallel.  It also has an output that allows daisy-chaining, which could allow you to add hundreds of outputs to a microcontroller without taking up any precious pins.
The TPIC6B595 family is a high-power shift register in that it is capable of consistently sinking 150mA per bit and can handle spikes of up to 500mA.  Because it handles high power, it is only able to sink power, not output it.  But again, it’s a good thing I have so many transistors kicking around.
For a nice 7 segment LED output I picked up a few cheap-o multiplexed 4 digit displays from
I won’t spare the gruesome details but after cutting a lot of jumper wires and modeling it on a breadboard I was able to come up with this:
What’s particularly nice is that only 3 pins are used by the microcontroller.  What’s not particularly nice is that it looks like a 70’s porn vagina what with the tangles of wire.  You’ll also note that the value displayed is the current voltage being received from the solar panel.  To measure this, you’ll see that the upper right of the board contains a series of resistors that serve as voltage dividers, generating a maximum voltage reading of 25V but reducing it down to a max of 5V which can be read by the microcontroller and then multiplied back to the correct value.
The multiplexing is crazy in that only one digit is actually having power applied to it at any given moment.  But thanks to persistence of vision and the fact that LEDs take more time to sink all of their current than it takes the microcontroller to repower it, it’s absolutely impossible to notice.  
The arrangement I have can handle another 4 digit 7 segment strip without the need for another shift register.  Adding one more would give me two additional 4 digit sets.  
A quick closeup with a little more contrast and a little less focus:
Not to gloat but I also did all of this using nothing but product datasheets and cusses.  Time to PCB this.
Many more fails to come…
Here’s the code if you’re interested:

int clock = 12;
int latch = 8;
int data = 11;
float voltage = 0.0;
byte numbers[10] =
  B0111111, // 0
  B0000110, // 1
  B1011011, // 2
  B1001111, // 3
  B1100110, // 4
  B1101101, // 5
  B1111101, // 6
  B0000111, // 7
  B1111111, // 8
  B1101111  // 9
void setup()
int readTime = 1000;
unsigned long previousMillis = 0;
int value = 0;

void shiftmOut(int myDataPin, int myClockPin, int digitpos, byte myDataOut, bool dec ) {
  // This shifts 8 bits out MSB first,
  //on the rising edge of the clock,
  //clock idles low
//internal function setup
  int i=0;
  int pinState;
  pinMode(myClockPin, OUTPUT);
  pinMode(myDataPin, OUTPUT);
 //clear everything out just in case to
 //prepare shift register for bit shifting
  digitalWrite(myDataPin, 0);
  digitalWrite(myClockPin, 0);
  for (int x=0;x<7;x++){
if (x==digitpos){
digitalWrite(myDataPin, 1);
} else {
digitalWrite(myDataPin, 0);
  //decimal point
  for (i=6; i>=0; i–)  {
    digitalWrite(myClockPin, 0);
    if ( myDataOut & (1<<i) ) {
      pinState= 1;
    else {
      pinState= 0;
    //Sets the pin to HIGH or LOW depending on pinState
    digitalWrite(myDataPin, pinState);
    //register shifts bits on upstroke of clock pin
    digitalWrite(myClockPin, 1);
    //zero the data pin after shift to prevent bleed through
    digitalWrite(myDataPin, 0);
  //stop shifting
  digitalWrite(myClockPin, 0);

void RefreshDisplay()
digitalWrite(latch, 0);
void loop()
  unsigned long currentMillis = millis();
  if (currentMillis – previousMillis > readTime)
    previousMillis = currentMillis;
    //for (int x=0;x<100;x++){
    voltage += analogRead(A0);
    voltage = voltage*25/1024;


Software-defined radio and a steam engine built out of crap

Two quick things I’ll be getting to in a bit.  The first is an open-source software defined radio.  

The Gnu nerds have figured out how to hack a simple european usb tv tuning stick to make it work as a software-defined radio.  If you’re unfamiliar with what this is, it’s essentially a radio that scans and either decodes or stores all receivable radio frequencies simultaneously.  This particular model can also be reversed  and transmit in the same way.  
 It’s theoretically (and actually) possible to record a segment of radio reception for a certain amount of time, then go back to it and decode any and all frequencies you’d like, across whatever modulation methods  you’d like to use.
I picked up this usb stick  or $27 including shipping from a dude in Niagara Falls.  A quick ebay search for “nooelec” will help you find him.
If you buy anything be sure to ask him for a drawing.
My goal is to convert this software code so that it can run on a BeagleBone or Raspberry Pi microcontroller, making it the world’s first open-source standalone software defined radio.
I probably won’t get to that.
But I’ll be leaving SDR’s for a while until this whole solar thing gets sorted out.
I also built a steam engine out of crap parts and sticks I had knocking around.  It looks gross and it’s not quite done but ideally it should be able to torque a 12v stepper motor such that at least 600mA will be kicked out of it.
I’m also leaving this alone until the solar panel is done.