Apr 25

PCB design, Power Management, Custom Cables,

The Electronics Lab blog posted an article about a free online PCB design software called PCBWeb. It's currently in Beta, but it could potentially be useful for students to have access to a free, browser based software for designing PCB's.

In addition, Texas Instruments released their power management guide to assist in choosing components for supplying power. It's quite a read, including lots of information on their products and example circuits.

For those interested in creating custom cables for connecting PCB's, motors, sensors, etc., adafruit posted a video made by Derek Molloy of the School of Electronic Engineering at Dublin City University, Ireland about creating custom cables using crimp pins.

Apr 25

New Electronics Books and Super-Awesome Sylvia in the White House

There is a new book by Simon Monk, who has written books on arduino, raspberry pi, etc., about hacking electronics. It looks like a good read, but I won't have time to look into it now, so I'm blogging about it so that I can find it later.

There is also a free release of Hacking the Xbox, which is said to be a great book on reverse engineering. I wish I had some time to read it, but for now it will be archived here.

In other news, Super-Awesome Sylvia went to the White House to show Mr. Obama her water color painting robot that is controlled via IPad (built with a little help from the people at Evil Mad Scientist Laboratories). It's great to see people spreading knowledge.

Apr 23

A little Rant

I came across an article about an arduino class taught by a 14 year old in Sydney, Australia. I am pleased to see young people teaching others about technology. I mean, I'm pleased whenever anyone promotes science and technology irregardless of age. Although, I am still not satisfied with how things currently work.

For example, this 14-year-old boy was able to learn how to build robots using an arduino, build a web-server, create systems using raspberry pi. He learned for free through the internet. And that's great. I would have loved to have had something like that. But being able to learn a hodgepodge of technical knowledge on the internet doesn't make me happy. Having a multitude of arduino tutorials available to me does not give me a path to learn why an arduino works. I can learn how to build a robot. Someone has already written code to communicate with a radio transceiver and I can blindly put his or her library into my code and use it, but no one is there to tell me how it all works. Why it works. How electrons magically make a servo turn and stop at five degrees. Why it does that. What the control signals are that make that happen. How it uses interrupts to send the signal every 20ms, and what an interrupt is. Where is that tutorial?

Because I couldn't find it. When I was starting off learning about the arduino, there wasn't a path for me to take that could have shown me what I could do with electronics. Sure, there are plenty of websites that have lessons on electronics, arduino, etc. There's a series of books that teach electricity and circuits. There are the tutorials  on the adafruit learning center, a series of about 50 tutorials about lots of stuff you can do with arduino, lots of random tutorials on the arduino website, lists of tutorials on instructables, the list goes on. Google arduino tutorial and there will be lots of hits. They all have instructions to teach you how to use the arduino to solve a particular problem. You want to spin a motor? No problem. There's a tutorial that will tell you how to do it.

Great, right? There's a bunch of information out there about learning the basics of electronics. We're good. Wrong. There are a lot of wonderful tutorials to teach people specific things, but there isn't a formal path to take someone from beginner to someone who understands how an arduino works. There is no one to teach people what is under the hood of an arduino, to spark their interest in the world inside the ATMega328p, no mention of how a microprocessor, compiler or register works. We are still failing to teach the more important answer to the quest to knowledge. Why?

I don't want to just teach people how to blink an LED. I don't want to just teach people how to build a robot or laser tag or a mailbox that tweets when the mail comes in. If that's all you want to know, you can search online, find someone who's already done it and copy what they've done without learning why it works. Which is a great starting point, but that is not where the journey should end. There is so much more. So much left undiscovered by building something just to make it work.

I've never been satisfied with a black box, not knowing why I put one thing into it and it spits out another. I want to look inside the black box of technology, unpack its innards and understand what is really going on. And now that I've been lucky enough to study under professors who taught me, I know what I've been yearning to know since I was in high school. And it makes me angry that there still isn't a resource that I could've used to start me down this path earlier. To formalize my internet education from a random walk through youtube videos into a structured series of lessons that teach why an arduino works. That reveal what is going on in that little black chip.

Teaching someone how to do something is fine. But teaching them why is the key to understanding. There's nothing teaching people why an arduino works that is freely available and in a place where people who are looking for it can find it. There is no place to learn why an arduino works here on the internet that people can start at and learn from. So I'm going to try to change that. Even if I fall flat on my face, I will still be making forward progress. I hope to positively change a single life. If I can do that, then I will have succeeded.

Apr 19

Lab 2

In order to send a light signal (which is how the arduino will communicate when playing laser tag), we need to program the arduino to turn on a light when you push a button. In order to do this, you need to learn how to control the arduino's inputs, outputs and the basics of programming in the arduino IDE.

After reading through the example sketch (Sketch 2), you should have an idea of how to write a program to turn on an LED when a button is pressed. The circuit that you need to build to light up an LED when a button is pressed is shown below.

Figure 1: Breadboard of Lab 2 circuit (click on picture to make it bigger)

Lab2_bb
Xohd voccyx, dro grsvo vyyz!

The arduino runs off of five volts, and the LED needs 0.01 amperes (10 mA) of current. The circuit above makes pin 12 high (5V) when the button is pressed, and when the button is not pressed, the resistor pulls the pin to ground. This is called a pull-down resistor, as it makes the pin grounded (it is 0 volts) when the button is not pressed. This keeps static electricity from building up on the pin and causing the arduino to think that the pin is high when it shouldn't be. (in general, any pin that you are using should always be connected to either 5V or 0V [ground], so that static or charge from another source dos not build up on the pin).

The button does not need to have much current running through it, and to save power and use standard components, we choose a current value of 0.0005 Amperes (0.5 mA) through the pull-down resistor. Without the resistor, you will be connecting power (5V) to ground (0V), and create a short. A short will try to pull as much current as it can (it has roughly zero resistance, so the current will be very high), which will cause the batteries to quickly die and the components to heat up (and potentially fry). Remember the pull down resistor.

You now have enough information to calculate the resistance values for the two resistors in the circuit. After building the circuit and testing it with the arduino code that was provided, try adding another LED onto pin 10 and having it turn on when the button is not pressed, and turn off when the button is pressed.

Bonus Knowledge
The pin numbers that we are using were chosen to make the schematic look nice. Any of the digital pins can be used for this sketch.

Apr 18

Lesson 2

In order to tell the arduino how to play laser tag, we need to understand how to give it instructions on what to do. We do this using our computer and a program that allows us to write instructions for the arduino. The purpose of this lesson is to introduce people to the arduino and its integrated development environment (IDE) that is used to program it.

To begin with, you need to tell your computer how to talk to the arduino. To do this, you need to get the correct software running on your computer. Fortunately, there is a tutorial on the arduino website that goes through the steps required to set this up, which you can find here. In addition to the setup, the arduino website has many reference pages and forums that are useful for finding answers to questions and solutions to problems.

So, what can an arduino do? An arduino can interact with the outside world using electricity through its pins (the little pieces of metal sticking out of the microcontroller). It can measure the voltage that is on specific pins and output voltages on other pins. This can be used to read sensors, move a motor, turn on a light, tweet, send an e-mail, or do pretty much anything that you can have done by turning on a switch, or pushing a button. But in order to communicate to the arduino without breaking it, there are some things that we need to be aware of.

First, the arduino can only supply 0.03 Amperes (30 mA) of current from any pin. That means that if whatever circuit is attached to a pin tries to draw more than 0.03 Amperes (30 mA) of current, the arduino will eventually overheat and break. It could break that pin or the entire board. This is why you learned Ohm's law. Every circuit that is turned on by the arduino can not draw more than 0.03 Amperes (30 mA) of current, or it will damage the arduino. In addition, the arduino uses a specific voltage, five volts. We will be using the arduino's digital inputs. Digital, or discreet inputs, are like counting numbers. They can only take on certain values, like 1, 2, 3, 4, etc.
For the arduino, it can only count to one. When it reads a voltage, the voltage is read as either 0 or 1. Since the arduino likes using five volts, we will give it a five volt signal. The arduino will think that any signal that it reads on one of its pins that is five volts is a one (or that the voltage is set to high). If the arduino does not sense five volts, it will think that the pin is a 0 (or that the voltage is set to low).

So, now that we know the basics of electricity, we need to learn the basics of programming the arduino. In the arduino IDE (programming environment), a file is called a sketch, and I wrote an example sketch called first sketch to go over the basics of the arduino IDE. Read it. It goes over basic coding practices and tips for writing code.

After reading the example sketch, which you can find here, you can complete Lab 1.
Now go build something.

Note: The brains of the arduino is a microchip called the ATmega328p. Atmel, the company that produces the ATmega328p has a naming convention for their chips. It starts with AT, which stands for the company Atmel. This chip is part of the mega family, which as 32 or more pins, has 32 kilobytes of program memory (which is why 32 is in the name), it has 8 kilobytes of flash memory (which is why there's an 8 at the end), and it is the low power chip (p). Put all of those features together, and you get the ATmega328p. This naming convention lets you compare chips simply by looking at their names. For more information, the Atmel naming convention for these chips is here.

Apr 18

Sketch for Lesson 2 and Lab 2

Copy and paste everything below the /******/ into a blank sketch file (a blank file that opens up in the arduino software package) in the arduino IDE and read through the file to learn about the basics of writing a program for your arduino to run.

/************************************************************/

// this is a comment. A comment is not code that the arduino will try to run.
// a comment is a note to the programmer.
// a comment that is on one line starts with two slashes: //

/* a comment that spans multiple
lines starts with /* and ends with */

// You should always leave yourself comments that explain what you are doing
// When you don't, you'll forget what the code does and have trouble
// coming back to it later and changing stuff.

/*
When you know what you are doing, then you don't need to leave as detailed
comments, but until that point, good comments are key to good code
*/

/*
Speaking of good comments, notice how much easier this comment is to read
than the last one because there is one space before I started writing.
making your comments easy to read and understand is good and worth the time.
Don't make your comments so long that people have to make the arduino window bigger just so that they can see them because this is annoying for people who don't want to expand their window just so they can read the comment that you put in your code but decided not to press enter any time soon because you just had to write it all on one line
*/

/*
Normally, you would start a file with the following:
Name and Purpose of the file
Whether or not it is in the public domain (useful to know if other people
want to use your code).

For Example:
Sketch_2 is meant to introduce people to the arduino integrative
development environment (IDE) that is used to program the arduino
microcontroller. It goes over comments, intputs/outputs and if/else statements
This code is in the public domain.
*/

/*
The arduino has many pins that can be used to receive information from
the world (it can receive input) or send information out (output).
The arduino's pins can be used for either input or output, so you need to tell
the arduino which function that
you want the pin to perform. For this lesson and lab, we will be re-creating
turning on an LED with a button. To do this, we need to tell the arduino
which pins to use and whether we want those pins to be inputs or outputs.
The arduino's pins are labeled with numbers, but that's not easy to remember.
When programming, you can create nicknames (called variables) to name things
so that they that are easier to remember. For example, if we want to put our LED onto
pin 11 on the arduino board, we may want to create a nickname (variable) for that pin
and call it led_pin, so that we can use the word led_pin in our code instead of
the number 11. That line of code is shown below. It
creates a variable (an int or integer, which will be described later)
called led_pin and sets it equal to 13. the ; tells the arduino code that it is
the end of the line of code.
Note: nicknames (variables) can't have spaces. You can use underscores (_)
though, to separate your words and make them easier to read
*/
int led_pin = 11;

/*
We also want to give a nickname for the pin that we attach to
the button. Why? Because we want to see if the button is pressed and
turn on the LED if the button is pressed, so we need another nickname
to keep track of the pin that the button is attached to.
*/
int button_pin = 12;

/*
Now that we have nicknames that we can remember, we can start coding.
Arduino sketches always have two things:
1. a setup routine
2. a loop routine.
The setup routine is run
every time the processor is turned on or reset. This is where you set
pins to be inputs or outputs or do things that you want to happen every time
you start or reset the arduino. After that comes the loop routine, which
runs whatever code is in the loop over and over and over until the arduino
turns off.
*/

/*
the setup routine runs once when you press reset and when the arduino
turns on for the first time:
it looks like this:
void setup() {
Here are what that means:
1. void means that the routine does not send anything back
after it is done running. You can have the arduino return or send something
after it is done running some code, but this code doesn't require that.
2. setup is the name of the routine. A routine or grouping of code is called a
function, which we will explore more later
3. The two parenthesis () mean that there is no input to setup. Other functions
can have inputs, which you would put between the parenthesis (we don't need
and input for setup, and never will)
4. Finally, the curly bracket, { tells the arduino that all the code
starting here is for the setup function.
*/

void setup() {

/*
So, we want to have our led pin be an output. Fortunately, the arduino IDE
has a lot of built in functions that make it easy to do things. For example,
the pinMode function lets you tell the arduino to change a pin to an input
or output. You can set a pin to an input or ourput by writing the command
pinMode( pin to set, OUTPUT or INPUT);
You'll notice that output is written in all capitals.
That is because OUTPUT has a special meaning in arduino sketches, and when
the code is compiled from code that you can read (for example, the word
pinMode) into code that the arduino actually runs (it only understands 1s
and 0s, voltage high and voltage low), the compiler (the software that
converts human readable code into machine readable code) will replace
all instances of the word OUTPUT with the correct value so that the arduino
knows to make the pin an OUTPUT. This is similar to how we created a
nickname for the pin that we attached our LED and button to.
*/
pinMode(led_pin, OUTPUT);
//now we need to set the button pin to be an input
pinMode( button_pin, INPUT);
// we now have our pins set, so we can write our code.

} //this curly bracket ends the setup routine.
// curly brackets tell the program that all the code you write in between the
// brackets belongs to a specific routine or function.

// the loop routine runs over and over again forever:
void loop() {
/*
Now that we have set everything up, we can tell the arduino what to do.
But first we need to have a clear idea of what we want it to do.
We want the arduino to see whether or not a button is pressed and turn on
an LED only if it is pressed. Written another way, if the button is pressed,
we want to turn the LED on, otherwise we will turn it off.
Fortunately, there is a command called if that checks to see if something
is on or off. Since the arduino only understands voltage, it thinks that
HIGH voltage (5 volts) is on and LOW voltage (0 Volts) is off. Remember
that the arduino can't count to 5. If it sees a HIGH voltage signal, it
will count that as a 1.
*/

/*
Now that we know that we want to use an if statement to check to see if the
button is pressed, we are going to make another variable that keeps track of
the button so that we can see if that variable is high or low (1 or 0).
The circuit is shown in Lesson 1, and the button_pin will be high (1) if
the button is pressed and low (0) if the button is not pressed. We want to
read the voltage of the button pin, and to do that arduino has a command
called digitalRead. This reads in the value of a pin as either high (1) or
low (0). It is called digitalRead because it will read in only a digital
value, which is either 1 or 0. It will only output 1 or 0, nothing in between.
If the voltage value is not 0V or 5V, it will round to 1 or 0 depending on
how close the voltage is to 0 or 5. digitalRead works by writing
digitalRead( pin to read voltage from);
*/
int button_state = digitalRead( button_pin );
/*
Note: In later code, all of our variables that we want to use throughout the
sketch (global variables) will be defined before we call the setup routine.
This is so that every time we run the loop, we don't make another
button_state variable. I'm doing it this way so that you can see what is
going on.
*/

/*
Now we want to see if the button is high or low. To do that, we want to
check to see if the button_state variable is equal to 1 or 0. To compare
two values, we can use two equals signs (==). One equals sign is used to
set a value, for example button_state = 0. Two equals signs tells the
arduino to compare the two values and see if they are equal. If they are,
then the statement is true or 1. If not, the statement is false or 0. This
is how we can use the if statement, by checking to see if a certain condition
is true.
Note: after a function or an if statement, you should indent your code to make
it easier to know where that code fits in the grand scheme of things.
*/
if (button_state == HIGH) {
// turn LED on
digitalWrite(led_pin, HIGH);
}
/*
But what if the button is not pressed? Then we want to execute a different
piece of code. After an if (or series of if statements), you can write an
else statement that will run if the if code did not run. So, we want
to turn the LED off if the button is not pressed. To do that, we use the
else command (which doesn't have a condition to check, and uses curly
brackets to tell the arduino what code to execute.
*/
else {
//turn LED off
digitalWrite(led_pin, LOW);
}

/*
That's it. The arduino will now constantly check the the voltage on the
button pin and turn the LED on or off depending on whether the button is
pressed or not.
*/

} // this curly bracket ends the loop. When the arduino runs the code and gets
// to this point, it will start the loop over.

/*
Here is the complete code without my comments. Does it make sense?
int led_pin = 11;
int button_pin = 12;

void setup() {
pinMode(led_pin, OUTPUT);
pinMode( button_pin, INPUT);
}

void loop() {
int button_state = digitalRead( button_pin );
if (button_state == HIGH) {
digitalWrite(led_pin, HIGH);
}
else {
digitalWrite(led_pin, LOW);
}
*/

// Hmh csy jmkyvi syx xli Giewev gmtliv?

Apr 18

Board to use for permanent Laser Tag modules

I would like to have a stand-alone board to put in the laser tag modules instead of an arduino. This would allow students to use the arduino that they use in class for other projects while keeping the laser tag module intact. Right now I have two alternatives:

Moteino: Cost: $18.95. Uses surface mount components for a really small footprint (1.3x0.9 inches), ATMega328P processor, RFM12B tranceiver. This is the lowest cost module that I could find (as opposed to the JeeNode, which is 18 euros, and has a much larger footprint). I would need an FTDI adapter (or just use the one in the arduino to program it) to program the module, but that's fine. The Moteino also has a version without the RFM12B, which is $12.95.
Update: Low Power Lab is working on an ATMega32u4 based Moteino called the Moteeino Leo, which will probably be less expensive (since it's USB native). Keep an eye out for this.

Freakduino: Cost: $33. Freakduino is an open source arduino clone with an on board 2.4GHz radio (the Atmel AT86RF230). It has a great datasheet, and is a bit bigger than a standard arduino. It's a little pricier, but I like that it can have a longer range by adding an antenna.

miniSWARM: Cost: $25. miniSWARM is an open source arduino compatible with a 2.4GHz radio built into the chip. As of this posting, it is on Indiegogo for crowd funding. It can be used to build a mesh network and is based on the ATmega128RFA1. They are also giving away some miniSWARMs away on their website. This module has much more capability than I need for my application, but it may be useful if I want a mesh network and a much more complicated game.

Note: Both of these alternatives have built in radios for communicating with a central hub, which would keep track of tags. I could not have a wireless module and have all the communication between the central hub, bases, etc be done through IR. It'd be more protocol to write, but I can do it. Just not sure if I want the added flexibility of getting data from players as they play the game.

Later Note: The Waspmote is a commercial wireless sensor node based of the ATMega1281, which is arduino compatible. ATMega processors can be used for real, commercial applications. Fun fact to know.

Processor Note: So, I'm using an ATMega328p when I don't need that much functionality. I mean, I need 1 hardware timer, at least 10 I/O pins (if I put a 7-seg LED on it, or other peripherals), and some program space. But switching to an ATTiny could prove prohibitively complicated in the context of an introductory course. I don't want to have people programming an AVR with an arduino just to get a smaller microprocessor. It's a nice thought to use something with less capability because I don't need the capability, but if I end up expanding this project, it'll be nice to have excess program space and I/O pins to play around with. And who knows, maybe I'll need another hardware timer.