Christmas 2016 Ornament – Using Arduino

I created a Christmas ornament using an Arduino Uno and an 8×5 NeoPixel Shield.

In short it,

  • Displays one of seven messages randomly
  • Displays a set of bars that animates – Based on this thread
  • Displays a star that moves and cycles colours – Based on this tutorial

The code is, essentially, C and REALLY easy to develop, and the APIs from AdaFruit make this wicked fast to get code up and running quickly.  The language used for Arduino actually is based on Processing, but also accepts C and C++.

The Libraries used are:

  • AdaFruit GFX Library
  • AdaFruit NeoMatrix
  • AdaFruit NeoPixel

Here is the code:

#include <Adafruit_NeoMatrix.h>
#include <Adafruit_NeoPixel.h>
 
// MATRIX DECLARATION:
// Parameter 1 = width of NeoPixel matrix
// Parameter 2 = height of matrix
// Parameter 3 = pin number (most are valid)
// Parameter 4 = matrix layout flags, add together as needed:
// NEO_MATRIX_TOP, NEO_MATRIX_BOTTOM, NEO_MATRIX_LEFT, NEO_MATRIX_RIGHT:
// Position of the FIRST LED in the matrix; pick two, e.g.
// NEO_MATRIX_TOP + NEO_MATRIX_LEFT for the top-left corner.
// NEO_MATRIX_ROWS, NEO_MATRIX_COLUMNS: LEDs are arranged in horizontal
// rows or in vertical columns, respectively; pick one or the other.
// NEO_MATRIX_PROGRESSIVE, NEO_MATRIX_ZIGZAG: all rows/columns proceed
// in the same order, or alternate lines reverse direction; pick one.
// See example below for these values in action.
// Parameter 5 = pixel type flags, add together as needed:
// NEO_KHZ800 800 KHz bitstream (most NeoPixel products w/WS2812 LEDs)
// NEO_KHZ400 400 KHz (classic 'v1' (not v2) FLORA pixels, WS2811 drivers)
// NEO_GRB Pixels are wired for GRB bitstream (most NeoPixel products)
// NEO_RGB Pixels are wired for RGB bitstream (v1 FLORA pixels, not v2)

#define PIN 6
Adafruit_NeoMatrix matrix = Adafruit_NeoMatrix(6, 8, PIN,
 NEO_MATRIX_BOTTOM + NEO_MATRIX_LEFT +
 NEO_MATRIX_COLUMNS + NEO_MATRIX_PROGRESSIVE,
 NEO_GRB + NEO_KHZ800);


// Global Variables
// matrix_x, y used to drive the size of the LED matrix
// text_pass used to change text colours after each pass
// starpos used to position the star when switching to different colours
// starpos_incdec is used to move the star back and forth based on the boundaries of the matrix
// rand_messages is used to randmize the messge that is shown
// text_colours is an array of colours to use for the text, star_rgb used for star color values, star_colour used to drive the actual colour of the star
int matrix_x = matrix.width();
int matrix_y = matrix.height();
int text_pass = 0;
int starpos = 0;
boolean starpos_incdec = 1;
int rand_messages = 0;
unsigned int star_rgb[3] = {255,255,255};
uint16_t star_colour = matrix.Color(star_rgb[0], star_rgb[1], star_rgb[2]);
const uint16_t text_colours[] = {matrix.Color(255, 0, 0), matrix.Color(0, 255, 0), matrix.Color(255, 255, 0),matrix.Color(0, 0, 255), matrix.Color(255, 0, 255), matrix.Color(0, 255, 255), matrix.Color(255, 255, 255)};

 // Merry Christmas Message 
String myMessages[]={"Merry Christmas", "You've been naughty", "Krampus is here", "Ho Ho Ho!", "Happy Holidays","Meet me under the mistletoe", "Home for the Holidays"}; 
int myMessagesSizes[]={-98,-120,-98,-80,-95,-170,-140};
// Code
void setup() 
{
 Serial.begin(9600);
 matrix.begin();
 matrix.setTextWrap(false);
 matrix.setBrightness(6);
 matrix.setTextColor(text_colours[0]);
}

void update_star()
{
 // Future code fix - Make dynamic based on matrix_x and matrix_y
 // In short, if the star hits the Y boundaries, move back
 if (starpos+4 == 7) { starpos_incdec = 0; } 
 if (starpos == 0) { starpos_incdec = 1; } 

 // Clear screen, draw star
 matrix.fillScreen(0);
 star_colour = matrix.Color(star_rgb[1], star_rgb[0], star_rgb[2]);
 matrix.drawLine(0, starpos, 4, starpos+4, star_colour);
 matrix.drawLine(0, starpos+4, 4, starpos, star_colour);
 matrix.drawLine(0, starpos+2, 4, starpos+2, star_colour);
 matrix.drawLine(2, starpos, 2, starpos+4, star_colour); 
 matrix.show(); 
 delay(1);
}

void color_morph(unsigned int* value, int get_brighter)
{
 // Updates the colour through updating the refence. 
 // Get brighter flag increments/decrements
 for (int i = 0; i < 255; i++)
 {
 if (get_brighter)
 (*value)--;
 else
 (*value)++;

 update_star();
 }
 if (starpos_incdec) { starpos++; } else { starpos--; } 
}

void rowColorWipe(uint32_t c1, uint32_t c2, uint32_t c3, uint16_t wait) 
{
 // Borrowed code to draw green, white and red bars
 // Clear screen
 matrix.fillScreen(0);

 // Draw the bars
 for(int j=0; j<2; j++) {
 for(int q=0; q<6; q++){
 for(int y=0; y <= matrix.height() + 10; y=y+6) {
 matrix.drawLine(0, y+q-11, 5, y+q-6, c3);
 matrix.drawLine(0, y+q-10, 5, y+q-5, c1);
 matrix.drawLine(0, y+q-9, 5, y+q-4, c1);
 matrix.drawLine(0, y+q-8, 5, y+q-3, c3);
 matrix.drawLine(0, y+q-7, 5, y+q-2, c2);
 matrix.drawLine(0, y+q-6, 5, y+q-1, c2);
 }
 matrix.show();
 delay(wait);
 }
 }
}

void loop()
{
 // The main Arduino loop
 // Displays the christmas message, then the Christmas Wrapping bars, and then the star animation
 // Easier to have the message scroll here rather than using a separate method/function
 
 // Clears screen and sets message
 matrix.fillScreen(0);
 matrix.setCursor(matrix_x, 0); 
 matrix.print(myMessages[rand_messages]);
 // matrix.print(F("Merry Christmas")); // If using a single message

 // Enter this only if the message has been fully displayed. It's displayed by moving the cursor
 if(--matrix_x <= myMessagesSizes[rand_messages]) {
 // Reset message scroll
 matrix_x = matrix.width();
 matrix.setCursor(matrix_x, 0);

 // Christmas Wrapping bars
 rowColorWipe(matrix.Color(255, 0, 0), matrix.Color(255, 255, 255), matrix.Color(0, 255, 0), 500);

 // Cycle through the star colours
 color_morph(&star_rgb[0], 1); // transition to red
 color_morph(&star_rgb[1], 1); // transition to yellow
 color_morph(&star_rgb[0], 0); // transition to green 
 color_morph(&star_rgb[2], 1); // transition to aqua 
 color_morph(&star_rgb[0], 1); // transition to white
 color_morph(&star_rgb[1], 0); // transition to violet
 color_morph(&star_rgb[0], 0); // transition to blue
 color_morph(&star_rgb[2], 0); // transition to black (all off)
 
 if(++text_pass >= 8) text_pass = 0;
 matrix.setTextColor(text_colours[text_pass]);
 rand_messages = random(0,7); // Random number between 0 and 7 (n-1)
 } 
 matrix.show();
 delay(100); 
}

Gaming past

I look at most of my younger friends going crazy for Pokemon Sun and Moon these days and realize, they don’t know anything outside the realm of Nintendo, Sony Playstation and XBox.  It’s like there wasn’t a gaming history prior to the time when the NES came out.

Given the videogame market crash of 1983, it’s somewhat not surprising.

For someone of my generation – yes I know how that sounds, there were a lot more options.  My collective group of friends not only were into NES and SNES, but we were also into our Amigas and Ataris – ST that is, not just the 2600.

Games like Worms (Team 17), Super Stardust (Team 17), Wipeout (Psygnosis) and pretty much anything out of Sony Studio Liverpool  (which was formerly Psygnosis) would be no where today without the Amiga.

There are some fantastic games such as Zool, The Lost Vikings, James Pond, etc. that came out during that time period.  Simply fantastic, that people seem to have forgotten and simply don’t seem to care about except for those of us who lived it.  Which is sad because there are some real gems.

I’ve owned, in my lifetime, two CD32s, picking up the latest one about two years ago, and I own a fully working Amiga CDTV completely with a hard drive. I’m slowly refurbishing the CD32, which at this point needs a replacement CD spindle to work.  Everything else on it seems perfect.

Which brings me to an interesting quandary.  I can perfectly emulate the CD32 on my Surface or MacBook. Do I really need the original hardware?  There is something to be said for owning a piece of iconic history, especially if you can keep it going.

Android Wear vs Apple Watch

FullSizeRenderI admit it.  I love watches.  Always have, and I feel like I’ve owned some cool ones like the Seiko Data 2000 that I still have and is in working condition.

For years I stopped wearing watches, the last being a Timex DataLink I bought 21 years ago.  However three years ago, after visiting the Caribbean, I fell in love with watches again picking up a Citizen Proximity (horrible ‘smart’ watch), and a Citizen Blue Angels Skyhawk (love it!).

The current set of digital watches, or wearables, especially between Apple and Google is intriguing to me.  For the longest time period, I resisted getting an Apple watch and then finally did.

As for Android Wear, I didn’t think it would work with the iPhone and it turns out it does – sort of.  So I picked up a Fossil Q Founder while in Orlando.

Honestly – I’m not impressed with Apple Watch anymore.  I find:

  • It’s very slow for what it is.
  • It often thinks I want to take a screen shot when I’m clicking the crown.
  • The flow of the UI is not that intuitive – Why would I press the crown for Apps?  It makes more sense to swipe.
  • Apps are slow and have very basic functionality.
  • Lack of available watch faces.
  • Connectivity is questionable – For example, right now my iPhone recognizes I am in Waterloo yet the watch can’t bring up the weather details.
  • The Apple Watch app seems like an after thought and doesn’t feel cohesive with the rest of the iOS ecosystem.

What Apple Watch has going for it, though is:

  • Activity tracking – I love that it tracks steps, translates it to calories, standing and also exercise time.  Along with that, the heart beat/rate monitor is cool.
  • It’s a small package.
  • Wallet is awesome for checking in for flights, loyalty cards, etc…
  • NFC payments with the watch instead of the phone is really neat too.
  • Messaging from the Apple Watch is great.
  • The haptic engine is awesome! So much so, I feel phantom taps on my wrist occasionally.

The Fossil Q blew me away with how responsive it is, given it’s based on an Intel Atom processor, I’m not surprised.  I like ARM cores as well, but I really do think Apple could have created something a bit more reponsive.

What the Fossil Q has going for it:

  • Did I say it was responsive?
  • It feels like a big chunky watch, which has been my preference recently
  • It came with a nice charging stand.  Apple really missed the mark here.
  • The sheer number of apps and watch faces is way higher than Apple Watch.  Again, Apple has really missed the mark here.
  • The UI is way more intuitive.
  • You can have the watch with an always on mode that doesn’t seem to have that much affect on battery life.
  • The simplicity of gestures and buttons is beautiful.

What the Fossil Q implementation of Android Wear seems to be missing

  • This one isn’t the fault of Google, but the lack of being able to get to the Android Play store to upload apps and more watch faces.  There has to be a way of being able to get access to, at least, the free watch faces on the store.
  • Activity tracking – Sure it has a pedometer, but not much more.  Although, do I really need a heart rate monitor?  Not really, but in these days of activity trackers and such,    I’d expect something like that from such a big watch. As CNet’s review calls out, “This isn’t a sport watch, it’s a fashion one.”
  • It doesn’t look like with the base watch that you can send text messages using “OK Google” like you can with Siri.
  • Wallet although I know Google Pay when synced with an Android device is available.
  • The haptic engine isn’t quite a cool or configurable as Apple’s.

What I won’t miss in Android Wear versus Apple Watch is the NFC payments capabilities.  I just don’t use NFC these days, and I see it more as a gimmick.  Although it sounds like on other Android Wear watches, NFC is available.

What both have going for them

  • I like the size of the Apple Watch as well as the Fossil. Both have a place.
  • The range of bands is good for both, although I am partial to the bands available for the Fossil, which are interchangeable with other bands from the brand.
  • The displays on both watches is gorgeous
  • Voice recognition is great on both although I think I find Siri a bit faster to recognize and process my voice.

If you’re using the Android Wear with an Apple iPhone, it does seem to work well other than not being able to download many more watch faces and apps.  This is more because Apple doesn’t allow non-Apple stores to be accessed from the iPhone.  This is not surprising and I wouldn’t count on Apple supporting devices outside of their ecosystem.

All in all, I think Android Wear is probably the better platform.  Apple Watch, it will be interesting to see what comes out from Apple, but I have to admit, I find myself drawn away more and more from Apple.  I am just not impressed anymore.  So much so, I could almost see myself switching to an Android phone.  Almost.

The best way to describe the Fossil Q is the right balance between the Apple Watch and a Pebble.

Surface and the newbie?

For Christmas, we purchased a Microsoft Surface tablet for Scott’s mum.  The main reasons for which:

  • It behaves similar to newer computers that friends and family will be using or have started using (Windows RT/Windows 8 UI),
  • It’s a tablet,
  • It’s something that Scott’s mum can grown into, and if she chooses, she could invest in a new computer when she is ready,
  • She can add a memory stick or external hard drive to view pictures that we send her from over the past several years

However, being half way across Canada, it does make it difficult to support.  Thankfully we have our own, just for that purpose. Once we get our kitchen renovated, it will become the kitchen computer.

I digress.

There are some stupid UI choices and behaviours about this computer.

1. If you get locked out of your computer because you’ve entered the wrong password on your Surface too many times, you have to use another computer to reset the password.  This makes is difficult for someone where this is their primary computer.

2. By accident, I had set the date to ‘yesterday’ instead of today on her computer.  There is no simple way to change the time on the Surface unless you go into desktop mode.

3. Trying to give her support using Remote Assistance did not work.  Now this could be a problem with my network to her network.  That’s really annoying, and the tool is not easily accessible.

4. The “Make everything on your screen bigger” setting does not work on Surface.  Good luck to anyone who has sight accessibility issues, which Scott’s mum does have.  Accessibility is not it’s strength.

5. The Skype app UI is horrible.  It’s hard to tell who is actually online.  You have to go the list of people, and select available.  That can be really confusing to a very novice user like Scott’s mum.

6. The downloadable Trackpad Settings app didn’t work in the initial version.  It works now, but I really could have used it working to setup mum’s tablet.

Those are my gripes so far.  I think Microsoft could have made this tablet a little more user friendly for first time users.  Am I regretting not getting her an iPad? Not specifically.  Would an iPad be easier?  Yes.  Would she be able to save all her pictures and such to it, and access them on a hard drive or memory card?  Absolutely not.

I will say, Betty has done very well learning how to use her computer.  Good on her!

Amiga CD32

Forget Nintendo WiiUs, Sony PlayStation 3s and XBox 360s; I’ve just ordered myself on of these –

I bought one in the UK 17 years ago, brought it back and then a few years later, sold it due to needing the money as I was finishing school.

I’ve wanted to replace it ever since.  I was lucky enough to find one – an NTSC version no less – on Amazon and promptly purchased it.  Hopefully in about 10 days it will be here in Toronto and I’ll either pick it up before we leave for BC or I’ll get it after.

And that completes my collection of Amiga CD units.  I already have a CDTV that I picked up several years ago – my second as the first had a similar fate to my CD32.  Yes, had to sell it to pay bills.

I used the CD32 as a CD ROM drive hooked up to my Amiga 3000.  At the time, many Amiga magazines were shipping with CD ROMs of software rather than 3.5in floppies so you needed some way to read those discs.

CD32 software can be easily found, but the actual hardware units have been proven to be difficult.  They were really only popular in the UK, with Canada as a secondary market.  They never sold in the US except imported from Canada.

Roughly a year after it’s release, over 19 years ago, Commodore would go bankrupt.

And that, in fact, was my very first games console.  The Dreamcast was a second, and GameCube third.

In the cloud, baby!

I was in the cloud before there was a cloud…

But I digress.  I’m feeling very proud of myself right now.  Amazing what happens when you ‘call something into being’ and talk publicly about a home brew project you’re stuck on.

I’ve been able to get through all those tedious little areas of logic that I really didn’t want to deal with.  Yes, memories of that really tough logic class from University came flooding back to me…

Scott needed three pieces of key logic on the reservation system – which would make sense to anyone who has been involved with any form of reservation system – and I certainly have the experience there (and in the cloud too!):

  1. The ability to block himself out as ‘Unavailable’ and stop people from booking within an ‘Unavailable’ period.
  2. The dreaded double booking issue that those of us who have worked on reservation systems at any level just absolutely love.  (note the sarcasm here).  This actually goes in hand with #1 above, in short, the exact same functionality.
  3. The ability to allow customers to book within periods of ‘Availability’ and to clean up those ‘Availability’ events.

I got the ‘Unavailable’ piece mostly working last night and fully working today.  I finished up the ‘Available’ piece tonight with the exception of one piece that I will be confirming with Scott tomorrow.

My biggest favourite piece of PHP coding out of this project is this:

$d_bookStart = date_create($e_createWhen->startTime);

The ability for PHP to convert datetime formats to it’s own native format.  ZEND uses the RFC 3339 format within the Events class for datetime.  I was dreading having to do all kinds of string manipulations just to figure out if the reservation time period touches an ‘unavailable’ or ‘available’ event  and the associated logic.  Instead, I can simply take two datetime variables an compare them.

So what is next?

  • Clean up the code in a big way.  It’s well commented but I need to start using functions more than I have.
  • I need to start building the user interface so we can conduct easier testing.  Right now the dates are hard coded.
  • Once this is done, I think we can start developing specifically for Scott’s website the final version of the product.
  • I am considering packaging this up in some way to sell.  I think anyone who is trying to run their own business with an online reservation service could benefit from this tool.  While there may be other tools out there, Scott and I have not found anything that really fit what he was looking for.
  • I have ideas for pricing and it will be cheap.  I want those starting new businesses (and even existing businesses) to be able to get something useful that can be deployed quickly, so they can be up and running quickly.
  • I will certainly allow people to run a full test, try before you buy, in some way via my website.
  • About that MySQL version – it’s certainly doable…  And could be used to turn into a more professional offering.  For now, I’m going to concentrate on the “Lite” option.

Wheeee!

Feeding my inner geek

Ever since I was laid off from Nortel 10 years ago, and since my last programming job with iFire Technologies about 9 years ago, I’ve had a heck of a time trying to find something to feed my inner geek.

I can’t say I’ve sworn off software development of any kind – gaming, web application development, iPhone and iPad app development, etc…

I’ve dabbled off and on for a few years – even going as far as starting to write a simple Tic Tac Toe game that included wifi & bluetooth networking, game pieces that could be configurable, etc… I’ve just not finished what I started, and I can’t justify the $99 a year to pay for a developer license from Apple to ensure I can use my iPad or iPhone as the debugging platform.

More so, recently, I made  commitment to my partner to develop a calendar web-app that would allow users to book appointments via his website, integrated with Google Calendar using the Zend gData connector and PHP.

I have to admit, I have been slow to make progress but I have made some great progress with the logic.  I admit, I’ve been somewhat… scared.  This would be the first ‘product’ I have developed myself that would be live in stepping away from software development in 2003.  I have a bunch of what-ifs:

  • What if the technology I have chosen is incorrect?
  • What if Zend changes their gData connector?
  • What if Google goes belly up?
  • What if Google changes Calendar, taking away functionality like Apple has with .Mac, MobileMe and iCloud?
  • What if someone hacks around and completely messes up my partner’s calendar for his business?

There is a part of me that says that I should mistrust leveraging a service like Google’s Calendar and I should just develop my own application using MySQL and PHP, that way I can control everything about the solution and keep all the various components up-to-date and let my web provider keep Apache up-to-date.

I think the plan I’m going to move forward is launch with Google Calendar, keep a close eye on how well the functionality is working and then develop the MySQL version and do a bang-up job on it.

All in the life of a home-brew CTO, I guess.  This is definitely good experience for my future.

Beeb30 – Memories of a BBC Micro

Way back when, when I was 11 years old, my mum, sister and I embarked on a trip to the UK to see my cousins who had spent a year in Europe.

I remember arriving via Worldways from Toronto to London Gatwick, to see my mother walk up to some man unknown to me, giving her a hug and a kiss.  This man would be one of the highlights of that trip was meeting my grandfather’s brother – Uncle Reggie as we called him, although I guess technically he’d be great uncle.

I digress.  Uncle Reggie fascinated me.   He lived in or near Farnborough which is home to the UK’s best airshow, had been a test pilot, apparently contributed to the design of Concorde, and was an inventor, from what I remember.

Uncle Reggie and I connected on our love of technology and computers.  He had a computer and a TV that also supported Teletext – Ah Ceefax and Oracle, precursors to the Internet and over the air!

I remember my cousin Tim mentioning that Uncle Reggie had a computer like an Apple ][, but it wasn’t.  It turned out to be a BBC Micro.

I don’t recall how long I spent playing around with his television or the BBC Micro, but I certainly wanted to know more about it.  It was a neat piece of kit.

Unfortunately BBC Micros were not big here in Canada because it would have been fun to trade programs and ideas back and forth with Reg.  I had “the other British computer” – a Sinclair ZX81 (rebranded as a Timex Sinclair 1000) – $69.99 in 1983 wasn’t bad for a computer. Dad had also soon upgraded us to a Commodore 64.

Unfortunately Uncle Reggie passed away a few years later, but he always comes to mind every now and then especially whenever I think of the British computing scene in the 80s.

When I was studying in Norwich, I briefly had a chance to see an Acorn Archimedes running – A really cool RISC-based computer based on the famous ARM processor that runs iPhones, BlackBerries, Androids, and other devices.

The 80s, computer-wise, was a magical time, much like how younger friends of mine reminisce about gaming in the 90s.

Not only was Dad and my actual Uncle, Roger, major influences on me, but Uncle Reggie was my third influence.

I really like the fact that the Raspberry PI project is starting up a resurgence in homebrew computing again.  May legions of children and even adults, learn or relive great moments in computing again.