Sparkfun’s 7-Segment Red 6.5″ Display and Arduino

A little while ago I purchased 10 of Sparkfun’s 7-segment red 6.5″ displays.

http://www.sparkfun.com/commerce/product_info.php?products_id=8530

I had been wanting to purchase them for quite some time but they had been out of stock. When I was finally notified that they had received more I instantly bought them, without really thinking what I was going to use them for. Once they arrived I quickly opened them up and saw that it was going to be a little bit more of a challenge then I originally thought it would be. And I also thought they would come with some fancy schematic that I could just follow, but they didn’t.

So the first step was just to try and get a segment to light up by just supplying power. The digits use a common anode, which means it has one lead connection and 7 ground connection for each segment. So I started running it through a 5v power supply with not luck. Then a 9v, still no luck. Finally 12v did the trick. After I soldered wires to all of the connection I was able to get all 7 segments to light up by just running the common anode to the power and each segment to a ground.

Ok so step one complete now to try and get it talking with Arduino. Now I wasn’t really sure how to go about doing this since each segment was connected to a ground. So I started digging around on the Arduino forums and found some similar posts on what I was trying to do. My conclusion was that I need to get a shift register to turn each segment on and off. I found some people who had some luck with this display and the Allegro 6278EAT. You can pick some up for $1.55 at Digi Key. There are lots of different LED drivers out there but the reason I chose this one was because I needed to supply 12v to my displays and it sounded like some of the others that people where recommending wouldn’t work.

So after a lot of experimenting and researching I was finally able to get the display to turn on and off with Arduino. This tutorial on the Arduino site was the most helpful. And I used the following Arduino sketch which I got from this post on the forums.

int dataPin = 11;
int clockPin = 12;
int latchPin = 10;
 
//holders for infromation you're going to pass to shifting function
byte dataRED;
 
byte dataArrayRED[11];
 
void setup() {
 
  //set pins to output because they are addressed in the main loop
  pinMode(latchPin, OUTPUT);
 
  //Arduino doesn't seem to have a way to write binary straight into the code
  //so these values are in HEX.  Decimal would have been fine, too.
  dataArrayRED[0] = 0x3F; //00111111 - 0
  dataArrayRED[1] = 0x06; //00000110 - 1
  dataArrayRED[2] = 0x5B; //01011011 - 2
  dataArrayRED[3] = 0x4F; //01001111 - 3
  dataArrayRED[4] = 0x66; //01100110 - 4
  dataArrayRED[5] = 0x6D; //01101101 - 5
  dataArrayRED[6] = 0x7D; //01111101 - 6
  dataArrayRED[7] = 0x07; //00000111 - 7
  dataArrayRED[8] = 0x7F; //01111111 - 8
  dataArrayRED[9] = 0x67; //01100111 - 9
  dataArrayRED[10] = 0x80; //decimal point
}
 
void loop() {
 
for (int i = 0; i<11; i++)
{
 
  dataRED = dataArrayRED[i];
 
    //ground latchPin and hold low for as long as you are transmitting
 
    digitalWrite(latchPin, 0);
    //move 'em out
 
    shiftOut(dataPin, clockPin, dataRED);
    //return the latch pin high to signal chip that it
    //no longer needs to listen for information
    digitalWrite(latchPin, 1);
    delay(300);
 
  delay(1000);
}
 
}
 
// the heart of the program
void shiftOut(int myDataPin, int myClockPin, byte myDataOut) {
  // 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 each bit in the byte myDataOut…
  //NOTICE THAT WE ARE COUNTING DOWN in our for loop
  //This means that %00000001 or "1" will go through such
  //that it will be pin Q0 that lights.
  for (i=7; i>=0; i--)
  {
    digitalWrite(myClockPin, 0);
 
    //if the value passed to myDataOut and a bitmask result
    // true then... so if we are at i=6 and our value is
    // %11010100 it would the code compares it to %01000000
    // and proceeds to set pinState to 1.
    if( myDataOut & (1<
    {
	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);
}

And here is a final diagram for connecting it to Arduino.

NOTE: the diagram shows a 15kohm resistor but it may not be bright enough. If you put a 2.2kohm resistor it will be much brighter

And here is a video of the display counting – http://www.viddler.com/explore/julian/videos/14/

I am working on getting more then one display working and will write a new post when I do

Continue reading » · Written on: 05-30-09 · 2 Comments »

Installing Subversion locally on OSX

I have been working on getting Subversion installed on my Mac for the last couple of days in preparation for my talk at Flashbelt on Automatic Build Systems.

<Intermission>

As a quick plug. Flashbelt is one of the best Flash conferences in the world and I highly recommend going if you are in the area. I have some discount codes if you are planning on getting tickets within the next couple of weeks. Just leave a comment and I will send you one.

</Intermission>

Ok back on topic. There are a couple great posts out there that do a great job at explaining how to install Subversion on your Mac, but unfortunately they are a little out of date. So let’s do a little homework first.

Step 1.

Check what version of Subversion you are running. To do that open a Terminal window and type

svn help

This is assuming you already have the Subversion binaries installed. If you don’t you can download them from here.

In the first couple of lines in the output from that command it should say what version you are running.

Step 2.

Step 2 is just to follow all of the instructions on the followingThought Stream post. This takes you through the simple process of getting Subversion set up with Web DAV and working with localhost. If you have Subversion 1.4 installed then you are finished after these instructions. If you have a newer version then 1.4 come back for Step 3 after you are done.

Step 3.

Now we have to update the SVN Apache modules with the current version you have installed. If you kept the default path when installing Subversion navigate to /opt/subversion/lib/svn-apache.

In this directory there are 2 new .so files. All you need to do is overwrite the current modules in apache. To do that simply copy those 2 files to the following directory – /usr/libexec/apache

It may be a good idea to backup the original files but you should be ok if you didn’t. Once the new files are copied over you have successfully updated the SVN apache modules.

Step 4.

Now there is 1 last thing you will need to do in order to get everything working correctly. I am not even going to try and explain it because this post on Thought Spark explains it way better then I could ever do.

Step 5.

Everything should be all set now. All you have to do is restart apache and you should be able to navigate to your http://localhost/svn/games or whatever you named your repository and see the current revision.

To restart apache you can either un-check and check the Web Sharing checkbox in System Preferences > Sharing or you can use the following command

sudo apachectl restart
Continue reading » · Written on: 05-18-09 · No Comments »

AppleScript to mount Samba servers

Our office is mainly a Windows shop, both employee computers and file servers. But being one of the few people who use a mac it’s always a pain to mount the necessary networked drives on a daily basis. So I took some time the other day to write an AppleScript that runs on login to mount all the network drives I need to use throughout the day. It also checks my IP address to see if I am in the office or connected through VPN before trying to mount the drives.

Here is the script. I have masked out the ip addresses but you should be able to get the idea to set this up to use it for your needs.

set TheAddress to (do shell script "curl -f http://checkip.dyndns.org | awk '{print substr($6,1,13)}'")
 
if TheAddress is equal to "xxx.xxx.xx.xx" then
    --display dialog "Your OFFICE IP is : " default answer (TheAddress)
    mount_drives()
else if TheAddress is equal to "xxx.xxx.xx.xx" then
    --display dialog "Your VPN IP is : " default answer (TheAddress)
    mount_drives()
else
    display dialog "You aren't at work"
end if
 
on mount_drives()
    mount volume "smb://xx.x.x.x/projects"
    mount volume "smb://x.x.x.x/dev"
end mount_drives

To set this to run on login go to System Preferences>Accounts>and Login Items under your account. From there you can add the script to the list.

Continue reading » · Written on: 04-22-09 · No Comments »

The race for Social Network integration

There has been some interesting news coming from social networks over the last couple of days. Yesterday MySpace announced a Silverlight API for developing applications on the MySpace Open Platform. As well they announced that MySpace will be available on Windows Mobile. The move will put MySpace on most mobile platforms, which include IPhone, Blackberry, and Android. Fast forward to today and Adobe has announced the official ActionScript 3.0 Client Library for Facebook Platform API, fully supported by Facebook and Adobe. Are these announcements purely coincidental? Maybe. And I don’t want to really get into Flash vs. Silverlight debate at any level. The most interesting thing to me is that Microsoft has made a investment in Facebook, to the tune of $240 million dollars. The investment is based around their Ad Platform and search, but you think that it would put Facebook as their number 1 social network to integrate with. Instead they partner with MySpace, where a $900 million dollar search deal with Google is set to expire in the second quarter of 2010. Is this deal just the beginning of a new and long partnership? Only time will tell. The great news as developers is we are getting API’s and Frameworks that are officially supported by both parties, technology creators and social networks, which provides us with a streamlined process to deploy applications. This couldn’t come at a better time for us as we have 4 really big Facebook applications in the works. And if you want to be a part of the team to work on those we are looking for some talented people. April Fuel’s Day

Reference links

Introducing Silverlight For MySpace

Adobe Flash Platform and Facebook

Continue reading » · Written on: 03-31-09 · No Comments »

I finally caved and joined the Twitter world

I have been able to resist for a really long time now, but being at 360 iDev made me realize that as a IPhone Developer you are really missing out if you aren’t on Twitter. A big portion of the community communicates using Twitter, and more importantly a big portion of Apple employees use it. 360 IDev was a great conference and it was really cool to be introduced to a new community. I mostly go to Flash conferences and it was great to meet new people in this fairly new community. You can follow me on twitter @juliandolce

Continue reading » · Written on: 03-08-09 · No Comments »

Sushi Toss IPhone Version

splashpage

Today I received confirmation from Apple that my first IPhone app is ready for sale in the store. Sushi Toss originally was a Flash based web game on www.allgirlarcade.com, but we instantly saw that it would be a great title to port to the IPhone. The object of the game is to get the Sushi’s to the top where Jesse is waiting to eat them by flipping the phone. It’s a great use of the accelerometer as a input mechanic. You can also earn Gems for your All Girl Arcade account by playing the game that will let you buy new items in Spark City, the All Girl Arcade virtual world. This was my first application that I developed and learned an awful lot during the process. Here is the direct link to it in the app store.

Continue reading » · Written on: 02-09-09 · No Comments »

Creating Interface Builder Plugins Mistake #1

I have been reading up on creating custom Interface Builder Plugins for my presentation at 360|iDev, and didn’t get very far when I figured out the first thing you should never do. When I created my project I just randomly named it IBPlugin. Well as it turns out there is a IBPlugin class already and when XCode creates your project it auto-generates a class with your project name and it subclasses IBPlugin. So you will end up with something like this @interface IBPlugin : IBPlugin. Obviously that won’t work and throws an error when trying to build it. So when creating a new Interface Builder Plugin Project name anything but IBPlugin.

Continue reading » · Written on: 01-30-09 · No Comments »

Speaking at 360|iDev

I just recieved confirmation that I will be speaking at 360|iDev this year on Interface Builder. Interface Builder is a really cool application, but can be cumbersome at times when you are learning it. I plan on going through some of it’s features, as well as how to use the IPhone components and how to integrate them into your applications. If you plan to attend, or even if you don’t, and there are certain things you would like to see covered or know, feel free to add them in the comments and I will do my best to try and answer them in my session and on this blog.

Continue reading » · Written on: 01-26-09 · No Comments »

Having Fun With The iPhone SDK

I have been playing with the iPhone SDK since the spring time and it’s a lot of fun to program for the platform. There is something to be said for having something tangible at the end of the day. You can be anywhere and pull out your phone and say “Hey, check out what I have been working on”.

I have been porting over some Flash code libraries and games to it, which has been interesting because there are some differences on how Objective-C works compared to Flash.

The first and potentially most obvious is positioning objects. The counterpart to DisplayObject in the SDK is UIView. There are several properties that allow you to position objects, but the one you want to use is UIView.center. This is where Flash and the IPhone SDK differ a little because Flash, usually, deals with x,y in the top left, where the SDK deals with the registration point in the center. When you are porting over design and graphics from the Flash and laying everything out in Flash it’s easier to deal with top left instead of doing all the conversion to the center. Here is some methods that I wrote that subclasses UIView. I should also mention that self in Objective-C is this in Flash.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
-(void)x:(float)_x 
{
    self.center = CGPointMake( _x + ( self.bounds.size.width / 2 ), self.center.y );
}
 
-(void)y:(float)_y 
{
    self.center = CGPointMake( self.center.x, _y + ( self.bounds.size.height / 2 ) );
}
 
-(float)y
{
    return self.center.y - ( self.bounds.size.height / 2 );
}
 
-(float)x
{
    return self.center.x - ( self.bounds.size.width / 2 );
}

You can also use the frame property to position items, but things will go a little wonky when trying to do a CGAffineTransform on the object at the same time you are position it. For example, rotating the object at the same time you are animating it’s position.

Some of you might be saying we’ll why don’t you use Interface Builder to lay everything out? The biggest reason is that we only have a few people working on OSX so the designers don’t have access to it. But I will say that Interface Builder is a wicked application and I am hoping Thermo lives up to it.

Continue reading » · Written on: 11-11-08 · No Comments »

PNG Image Cropper

At FOTB Brighton I presented on our process for developing the Fairies and Dragons Happy Meal toys. One of the things I showed was how we took a png sequence exported from Maya and cropped them to reduce the amount of alpha. To do that I built a WPF application in C# that would look at a folder and read in every png that was in there. For every image the application runs through each pixel and tries to determine all of the unnecessary alpha and crops it. The cool thing is that when the file gets saved out again it saves it with the x,y offset in the filename so that we can use a JSFL script to import all the images so the animation lines up.

Here is an example. Note : Everything in red is actually alpha I just filled it in for demonstration purposes.

Image Cropper

First select a input folder. This folder would have all of your images are in. Make sure the images are named sequentially.
Next select a output folder. It’s best if this folder is empty as this will be the folder where all of the cropped images will be placed.

Original Image

Here is a sample of the original image named Animation_Test.1.jpg.

Cropped Image

Here is the cropped image with the new name Animation_Test.1._163_95.jpg
As you can see it appends the x,y offset to the end of the filename ( 163, 95 ).

The final step is to run the JSFL command included with the application.

Select an empty layer on a timeline and run the command. It will prompt you to select a file from your output folder. Don’t worry which file it is because it is simply getting the folder not the file path. Flash will now import each image in the folder to a new keyframe and position the image at the x,y offset in the filename – in this case 163,95.

Feel free to download the application and give it a try.
You’ll need to have .NET 3 Framework installed for the application to run.

Continue reading » · Written on: 10-28-08 · 3 Comments »