Code Monkey home page Code Monkey logo

ledmatrixhat's Introduction

How to give life to a hat, a journey into 5kb of memory.

Intro and inspiration

Ok so it all started with Sabo. I am a big One Piece fan, and Sabo is probably my favorite character (RIP Ace ... you were the one before ! T_T )

Sabo

Then, it there was a steam punk party and I got a top hat and some goggles and this happened:

SteamPunk

Then it was a matter of time before Big Mom's hat took life, infused by Big Mom's soul. So well, I though, I'd give it a try, took some of my soul, and put it into the hat. And behold it was alive !

Hat

But more than this, it was really alive

Video https://youtu.be/lCmvI1q-8ME

The components

Crafts

  • A stylish hat (cheap in thrift stores ;) )
  • Some goggles, steam punk or not ! you can make this a bro hat with a cap and sunglasses ;)
  • A glue gun

Electronics

Total cost: ~45-70$ depending on the hat and goggles !

That's it ! super easy no ?

Make some holes

I used my soldering iron to poke 4 holes per matrix a bit on the left and right of each matrix. That way the wires can go out of the matrix and in the hat, where we will solder it all to the trinket.

You can use any punch technic depending on your hat. But the idea is that the wire should run behind the glasses so as to not be apparent. (though that's a style so go as you like !)

Solder it all

I2C Madness

Alright so now we have our wire our holes and our components ready, the first thing we want to do is to change the I2C address of one of the Matrix. If you don't know how I2C work, well, you don't have to ! Just know that each device on an I2C chain has a unique address (like a IP address), and that you send a ping to that address to listen (kinda like an header in a packet), and then your instructions. So here we have 2 matrix, so we need to direct our signal at each independently (right eye != left eye). Matrix 1 will have the default address 0x70 and matrix 2 a different one 0x71. The problem is that, the address is electronic, so we need to change it by soldering together a jumper pad (instructions here: https://learn.adafruit.com/adafruit-led-backpack/changing-i2c-address)

We want to drop solder accross the A0 pads, that way it will increase the address by 1 (0x70+1 => 0x71)

Get the wires where they belong.

Alright so we'll basically follow this schematic

Which is basically an adaptation of the Space Invader schematic from adafruit: https://learn.adafruit.com/trinket-slash-gemma-space-invader-pendant/wirin

DON'T FORGET TO RUN THE WIRE THROUGH THE HAT BEFORE YOU SOLDER !

DON'T FORGET TO RUN THE WIRE THROUGH THE HAT BEFORE YOU SOLDER !

DON'T FORGET TO RUN THE WIRE THROUGH THE HAT BEFORE YOU SOLDER !

Programming

The next challenge is to program this trinket. For me it was the first time working with one of thoose chips. I've done some arduino before, but I never had to think about memory space! Basically, I had wrote the whole code, and literaly the last line put it over the memory limit... -_- Alright 2h30 min later I had refactored the code so that it would fit.

So what does this do? Well we define our animations (I made them using LibreOffice, conditional formating, copy paste into atom for cleanup.) and we store them into long byte array (basicaly a char array) that look like this:

static const uint8_s PROGMEM anim = {
B00011000,
B00100100,
B01000010,
B10000001,
B10000001,
B01000010,
B00100100,
B00011000
}

Notice the PROGMEM ? Well that's to avoid overloading our memory with thoose ! So they are stored in the ROM instead of the RAM. As you can see, it is basically a 1 for the pixel on and a 0 for the pixel off.

Then the rest of the code is basically an adaptation of: https://learn.adafruit.com/trinket-slash-gemma-space-invader-pendant/source-code

With the main part of the code being:

for(int i=0; i<sizeof(anim); i) { // For each frame...
    Wire.beginTransmission(I2C_ADDR);
    Wire.write(0);                  // Start address
    for(uint8_t j=0; j<8; j++) {    // 8 rows...
        Wire.write(pgm_read_byte(&reorder[pgm_read_byte(&anim[i++])]));
        Wire.write(0);
    }
    Wire.endTransmission();
    delay(10);
}

Then the final touch up was to add some randomness into this, so that it would play a different animation randomly, and with blinks of the eyes to make it more lively.

The sketch files are included in the repository, anim.h contains the byte maps for the different animations, while the main program is under LEDmatrixHat.ino.

ledmatrixhat's People

Contributors

xqua avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.