Saturday, July 19, 2014

Tinkering is tricky

Trying to wrap my head around electronics is surprisingly similar to trying to sew a complicated pattern with a sewing machine. In sewing you need to think about the order of everything, measurements, ratios, materials like the fabric and lining and reinforcement and buttons... I could go on. I never really got into sewing the way my mom did. Electronics also seems to require holding a lot in your head at once.

I am really starting from scratch here.

I found out that in first designing a circuit, you use what is called a “solderless breadboard,” pictured below:



As its name would suggest, it lets you put in wires and parts without soldering. Instead of sticking in two wires to one pin, you can use this breadboard to make more connections possible. (More information can be found at: https://learn.adafruit.com/adafruit-arduino-lesson-14-servo-motors/overview )

Underneath a breadboard, there are rows of metal strips. On top, there are holes which you can plug a wire into. If you plug two wires into the same row of holes, they become connected, because they both touch the same metal piece. If you want to connect 5 wires together, you just plug all 5 wires into the same breadboard row.

The Arduino come in where if you have two servos, you need to connect 6 wires (2 signal wires, 2 power wires, 2 ground wires). The Arduino has only 1 power pin, and you might not want to shove two wires into the same pin if the wire is too thick. Instead, you would connect one end of one wire to the Arduino power pin, and the other end of the same wire into a breadboard row. That gives you 4 holes left in the same row, into which you can plug a servo power wire. You can do the same for ground.

Then, when I want to program the servos, in order to tell them to calculate the angle, the Arduino software program has a built-in library for servos. The library is basically a way to use simple words like write(56) to mean much more complicated things, like "calculate the angle to make the servo go to 56, then send that signal to the servo”.

So instead of calculating the necessary angles yourself, the library does the heavy code stuff for you. All I have to do is give the angle.

At the end of the code in the tutorial below there's a code example:

arduino.cc

Then, to just get my servo running, all I need to do is copy and paste that into the Arduino program and hit upload. This code makes my servo sweep back and forth between 0 and 180 degrees. (In this coding program, everything after // is a comment. The Arduino doesnt know these comments exist, so I can write anything I want. They're helpful for showing other programmers, and future me, my thought process while coding).
The brackets move based on instructions from the code myservo.write(pos), which is the actual piece of code that makes the servo turn. So if I just write myservo.write(56);, the servo will spin to 56 degrees and stay there until I send another instruction.

By the way, a servo is used when you need to spin something precisely. A regular motor spins as fast as it can whenever you give it power, but the problem is you never know exactly how far the motor has spun. Therefore, a servo has a special chip inside that can sense how far the servo motor has spun, and based on that can calculate the angle of whatever is attached to the servo motor.
The servo has 3 wires: power, signal, and ground. This chip listens for instructions sent to it over the signal line. Once it receives an instruction to spin to a certain angle, it takes care of the math needed to spin the motor a precise amount, then stops the motor itself once the angle has been reached, and waits for further instructions.

So where is the instruction coming from? What does that consist of? Well, it cannot spin on its own, its just a smart motor really, so it needs a brain, like an Arduino, to tell it where to turn to!
When I write myservo.write(56); , the Arduino looks up what that means in the servo library (which it knows is being used because of the #include Servo.h instruction at the top of the code). The servo.h library then translates the angle provided into the instruction that's to be sent to the servo, and then passes that information along (in this example pin 9, which is where the servo's signal line is connected). The signal itself is in the form of a pulse wave, meaning it's a very quick pulse of energy. The longer the pulse, the greater the angle requested from the servo.
I'm not certain of the specific pulse widths, but it's something like: a 10ms pulse would turn the servo to 10 degrees, and 100ms would turn the servo to 100 degree.

It's based on both the amount of energy collected from the solar panel and the angle of the sun.

The amount of energy coming in is equal to the optimal sun angle. Therefore, when we're at the optimal angle, we're collecting the largest amount of energy.

The basic flow of the program will be:
  1. The Arduino tells the servo to spin to degree 1
  2. The Arduino writes down the amount of energy collected at degree 1
  3. The Arduino tells the servo to stop at each angle from 2-180, taking a measurement at each degree of solar energy
  4. Once all the data has been collected, the Arduino chooses the angle at which is detected the most amount of energy, and tells the servo to go to that angle and stay there
  5. Then it stays at that angle until it senses that the amount of energy coming in has dropped
  6. Then repeats the cycle to find the new optimum angle
It's not actually going to move that much because if it goes to far it will sense a drop in energy coming in. The servos will be attached to the solar cell, and they will use it to move it about. As long as the bottom of the pan/tilt bracket is anchored in something heavier than the panel, it should work (Spolier alert: the panel IS to heavy and we still need to fix the problem).

The Sunny Buddy is smart enough to be able to charge the battery while something is plugged in.
learn.sparkfun.com

The pads that are labeled Load are where we'll be soldering the usb jack. All we have to so is solder the + to the + side of the usb jack, - to -, and away we go.

The LiPower Boost converter is needed because the battery only outputs 3.7V. Therefore, if you measured the voltage at the Load pads, you'd only see the voltage coming out of the battery, which is ~3.7V. We need to step this up to 5V so we can charge over USB, which expects 5V. The LiPower is what holds the charge and releases it to increase the voltage.

Therefore, the connection will be: Sunny Buddy → battery → LiPower → USB

By using an inductor, the LiPower Boost converter can build a magnetic charge within itself and by carefully timing the pulses going into the inductor, it can step up the voltage leaving the inductor.

The solar panel plugs into the sunny buddy, which handles the conversion from solar energy into battery charging energy.

The ideal place for adding cable length is tricky to figure out--we'll have to do some calculations.


The Arduino and servos will hook up to for power the LiPower output as well, same 5V place as the USB jack. We're supposed to use power-saving techniques to reduce the amount of power they actually use.

*Next* we'll talk more about programming the servos and using LCD Shield to help us make sure that the Arduino is performing correctly.

No comments:

Post a Comment