Tuesday, March 17, 2015

eBay clock kit

I bought this clock kit to see if it would make a good soldering class demo kit.  It's ridiculously cheap at $3.50 or something like that, shipped. I put it together last night, and the answer is, no, not really.

I'm posting here since it's being sold a lot on eBay so maybe someone can see this before buying.


It's pretty crappy.  I mean, it's alright but:

  • Requires 5V supply, no regulation.
  • No battery backup. Some kits for not much more money have battery
  • Beeper is frighteningly loud with no volume control
  • 24 hour mode only, as far as I can tell.
  • It has alarms but it's unclear exactly how they work, set mode just lets you set registers A through I, A is hours, B is minutes, some of them are "on" or "off, some others are hours and minutes of which surely some are the alarm (or alarms), but there's no instructions.
  • There's no way to mute the alarm as far as I can tell. It screams bloody murder for 10 seconds or so then stops.


So yeah, I'm going to keep looking.  I like clocks and may use this for something but I think it would be more fun to design my own.

Sunday, March 15, 2015

Arduino Blocks - LED display and button board

You can buy this really neat board with 8 digits, 8 LEDs, and 8 switches for very cheap. It's a great interface for many projects.  Let's see how to hook it up.



Link to the ebay auction: http://www.ebay.com/itm/400531985021

Here's the video of this lesson/project:


The software to drive it has already been written, you just need to install it.  Click here to download it (you want the ZIP file).  Extract the contents of the ZIP into your arduino/libraries directory.  If you have arduino installed below c:\program files (x86) then you'll have to extract somewhere else, then drag it to the libaries folder and give admin permission to do the copy.

The board needs +5v and ground leads, plus data/clock and "strobe" - strobe enables writes to the board. You can hook several of these boards up to the same data/clock as long as they each have separate "strobe" lines, so 3 lines hooks up 1 board, 4 hooks up 2, etc.

You can use any of the digital I/O pins. It's best to avoid 0 and 1 since those are used to communicate with the PC with serial I/O, programming, etc.  You just need to tell the library which pins it's attached to.  If you hook up multiple modules, just create a TM1638 object in your code for each module to control it.

I'll let the video and the code to the rest of the talking.  I've commented the code pretty heavily, so hopefully that will be helpful to you.

Here's a link to my code for the game.

Friday, March 13, 2015

Monday, March 9, 2015

Arduino Blocks 4 - matrix keypad

This is just a quick lesson that expands a bit on the "button" lesson earlier. I just got a bunch of new toys and wanted to do something with one of them this evening for you.

If you want to buy one of these, here's the one I picked up, or you can just go to eBay and switch for 4x3 matrix array keypad.  These are a DOLLAR, or less in quantity.

FWIW there's also a 4x4 matrix that's only a little more and adds ABCD to the right, if you need a few more keys.




This is a matrix keyboard, so called because the keys are laid out in an X/Y grid and they're read by "scanning" across rows and columns, looking for a short between the X and Y lines (rows and columns).

As usual, the video is the best guide here.




Here's what the grid looks like:


Here's how I wired it up:



And here's the code

The code works by setting the pins attached to the three columns to input with pullup resistors, so that when nothing is pressed, those pins read HIGH (1).  Then one by one, the rows are switched to output and the value is set to LOW (0).  Then the columns are checked.  If any of the columns now read LOW then the button that is at the intersection of that row and column must be pressed, and we have a value.  If not then scanning continues.

Saturday, March 7, 2015

A quick lamp repair

A friend at work had a broken crafting lamp. It took about 20 minutes to design a replacement part. I threw it up on Youmagine, though it's probably relatively unlikely that anyone will need it.


What the HECK is an Arduino and what can I do with one?

I thought it would be good to do a quick video on what the Arduino is and why it's so exciting to makers and hobbyists.

Sorry this goes on for > 10 minutes.  I show the old Atmel STK500 development board, the bog standard Arduino, a couple of minis including a Leonardo compatible, a mega, a colorduino application-specific Arduino clone, a variety of shields and sensors.



Sunday, March 1, 2015

Arduino blocks lesson 3 - Analog inputs and serial debugging

In this lesson I'm covering two things - inputs that are analog, that is, not just zero and one but a whole range of values, and also serial debugging, which is a simple technique that is very helpful in getting small programs and circuits working before going on to bigger things, and also in figuring out "what the heck is going on" inside the Arduino sketch.

Here's the video version of today's lesson:




Today's device
For this demonstration of analog inputs I'll be using a photo resistor.  Electrically this component acts exactly like the resistors we've used previously, but its value changes depending on how much light it sees.

Photo Resistor
I used my multimeter to measure the resistance of this device in bright and dim light and found that in the dark, it's about 50,000 ohms, and in bright light it's about 200 ohms.

Today's first new Arduino feature: analogRead()

The Arduino's analogRead() function documentation is very useful, you can read it here.  It says that the values go from 0 to 1023 when you read.  If the pin you are reading from is 0 volts, you get 0, if it's 5 volts (in the case of a classic 5 volt Arduino, or something else if your Arduino has some other reference voltage) then you get 1023.

We need a circuit that delivers various voltages to the Arduino pin based on the resistance of the photo resistor.  The immediate thought is to hook one side of the photo resistor to 5 volts and the other to the sense pin.  However, this won't work since there's nothing that would make the sense pin not just go straight to 5 volts regardless of the value.  So we need to build what is called a voltage divider.  We put in TWO resistors between ground and 5 volts, and the voltage in the middle is simply the ratio of those two resistors - if we had a 1000 ohm resistor going to 5 volts and a 4000 ohm resistor going to ground, the voltage between them would be 4 volts, since the total of 5 volts is being divided equally among 5000 ohms, and we're getting 4000 of those divided bits.

So we build a circuit like this:
Now, this isn't completely ideal because the analog pin never gets to 5 volts and it never gets to ground.  However, this doesn't really matter in most cases because we usually do not need that much precision in how bright it is.  In theory this circuit should result in output values from (10000/10200) * 1023 = 1002 down to 10000/(60000) * 1023 = 170.

Here's the circuit as built:





Now, I stole this code from the analogRead() documentation linked above:

int analogPin = 3;
int val = 0;
void setup()
{
  Serial.begin(9600);          //  setup serial
}

void loop()
{
  val = analogRead(analogPin);    // read the input pin
  Serial.println(val);             // debug value
}


Today's second new Arduino feature: Serial debugging

You'll see the new word "Serial" in there.  This is where we'll talk about serial debugging.  Since the Arduino doesn't have a screen, this is a way for it to send information back to your computer so that you can see what it's doing in simple text form.  In setup() it says Serial.begin(9600).  The 9600 is a "baud rate" which people old enough to know what a phone modem sounds like will know, but you don't really have to worry about it, just use that value.

In the loop, you'll see that it simply reads the value out and sends it to the serial monitor, which is on your PC in the Arduino code, under "Tools".  Compile and upload the software to the Arduino and once it's running, click "Tools/Serial monitor and you'll see this window:
The numbers you see there are what the Arduino is sending back to you.  

This facility is EXTREMELY useful. You may have some code that is doing something unexpected, but your circuit only has a few switches and lights,so it's hard to tell what's going on in there.  Using this facility you can have it tell you "I'm going to turn on this light now....I'm going to read the value of the switch...The switch is on so I'm going to start this motor now..." and so on.  It's very useful when "debugging" your code to get a glimpse of what's happening inside.

Cleaning up your data in software:
When I tested mine, I got values from about 1000 (with a bright light shining on the sensor) to about 400 (with the sensor in the dark under my desk).  Now, since we don't really need any better precision than that but let's say for the purposes of some thing I'm making, I need values to go from 0 to 99, we can simply correct these values in software to go from 0 ("pretty dark") to 99 ("pretty bright") like so:


void loop()
{
  val = analogRead(analogPin);    // read the input pin

  // translate our 400 to 1000 values into 0 to 99 values
  val = val - 400; // translate into 0 to 500

  if (val < 0)
    val = 0;    // do not allow to go negative
   
  val = val / 6; // translate 500 down to 100
 
  if (val > 99)
    val = 99; 
  Serial.println(val);             // debug value
}
You can grab the complete code sketch at this link.

What we're doing here is to first subtract 400 (since that's the about the lowest value we normally see) and then divide by 6 (we see a RANGE of about 600) to give us an approximately 0 to 100 range, then we have the two "if" statements to limit the range from 0 to 99.  It's a good idea to put "safety" code like this in as you write code, to make sure that your assumptions about the values are correct.  You wouldn't want to write code to do something like water the plants when it gets bright out, then find out that if the sun hits your sensor it goes to 101, causes your code to crash and it dumps water into your plant for the next 8 hours.

Summary
So to recap, we have built a simple circuit to turn light levels into voltages.  We have used the analogRead() function on the Arduino to get that value, we've written some code to change those values into clean 0 to 99 values for how bright it is right now, and we've learned how to use serial debugging to see values the Arduino is calculating on our screen.

Arduino blocks lesson 2 - switches

Switches are pretty important to learn, they're the main method you'll use to control many projects.

As part of this lesson, we'll learn about schematic diagrams.  Don't be scared, all they are is a way to doodle electronic ideas before building them.

I really recommend doing this lesson on the video. It's largely programming instruction and that comes across best on the video.



Here's the simple circuit that we built at the beginning of the first lesson:
The four lines on the left represent a battery (power source). It looks kind of like a couple of very small cells.  The thing in the upper right, that looks like a large arrow pointing down into a line, is a diode - a device that only lets power flow in one direction.  The circle around it with the arrows leading out of the circle indicates that it is a LIGHT EMITTING diode - or LED.  The squiggly thing in the lower right is a resistor. The electricity has a harder time going through a resistor and the squiggles are intended to represent that.

Here's a schematic of the circuit that we'll build to interface the switches:

The open block on the left represents the Arduino, with pins 13, 3, 2 and GND.  The lines coming out of 3 and 2 go into the schematic representation of a switch - you can see that it's not connected but when you push on the button on top it becomes connected.  When pressed it connects pin 3 or 2 to ground.

The idea here is that you tell the Arduino that pin 3 and 2 are inputs.  When you press a button, it connects that pin to ground and the Arduino can see that it went low, and do whatever you put in the code for that.

There's a problem with this circuit - when the switches are open, pins 2 and 3 aren't connected to anything, so they just float around.  The Arduino might think they're either low or high.  To fix this, we put in what's called a "pull-up resistor" - a resistor that connects each pin to +5 volts making it appear "HIGH" to the Arduino until the switch closes to force it low.  Conveniently, these are used so commonly that the Arduino has them built in, and you can turn them on via programming.  This schematic is the final working version with the pull-up resistors inside the Arduino represented:




For a complete explanation of the code, please watch the video.

You can download the complete BlinkButton sketch by clicking on this link.

New printer: JGAurora A3

This week I decided I'd had it with all the other printers in my stable.  The CTC is stable and decent but it just bugs me (can't st...