My Valentine’s Dead Bug

*** This was a quick copy and paste. I will be back to edit it soon!

 

This was one of those projects were I had a good idea in hand, but by the end it turned out quite different; and I am quite pleased how it turned out.

I wanted to make my Wife something nice this year for putting up with my various projects. Those on the “list”, those in planning, those in progress, those finished, and some abandon.

My original idea was to cut a heart out of wood, mount the 8×8 matrix in a hole in the middle, and mount the ATTiny on a PCB somewhere. I couldn’t make up my mind in front or back. While those ideas where being pondering and experimented with, I started on the hard part of the project.

I looked in my stock as I had both the ATTiny85 and 8×8 matrix handy. Wow, that seemed like a first, I didn’t have to order anything. I hadn’t really used the matrix before so I downloaded the Adafruit libraries and hooked it up to my Uno clone and started to play around. I used both the Adafruit_LEDbackpack and Adafruit_GFX. The animations are pretty straight forward. You have to create your image with 0 & 1’s, then call each of them as you need them. 

Here is an example from my code that shows part of the heart being drawn, it is the center square.

<span style="box-sizing: border-box;"> heart2_bmp[] = </span><span style="box-sizing: border-box;"> { </span>
<span style="box-sizing: border-box;"><span class="hljs-keyword" style="box-sizing: border-box; color: #f92672; margin-bottom: 0px;">B00000000, </span></span>
<span style="box-sizing: border-box;"><span class="hljs-keyword" style="box-sizing: border-box; color: #f92672; margin-bottom: 0px;">B00000000, </span></span>
<span style="box-sizing: border-box;"><span class="hljs-keyword" style="box-sizing: border-box; color: #f92672; margin-bottom: 0px;">B00000000, </span></span>
<span style="box-sizing: border-box;"><span class="hljs-keyword" style="box-sizing: border-box; color: #f92672; margin-bottom: 0px;">B00011000, </span></span>
<span style="box-sizing: border-box;"><span class="hljs-keyword" style="box-sizing: border-box; color: #f92672; margin-bottom: 0px;">B00011000, </span></span>
<span style="box-sizing: border-box;"><span class="hljs-keyword" style="box-sizing: border-box; color: #f92672; margin-bottom: 0px;">B00000000, </span></span>
<span style="box-sizing: border-box;"><span class="hljs-keyword" style="box-sizing: border-box; color: #f92672; margin-bottom: 0px;">B00000000, </span></span>
<span style="box-sizing: border-box; margin-bottom: 0px;"><span class="hljs-keyword" style="box-sizing: border-box; color: #f92672; margin-bottom: 0px;">B00000000, </span>}, </span>

Text scrolling is straightforward, but for those who are new, lets pick it apart a little bit and see what is going on.

<span style="box-sizing: border-box;"> <span class="hljs-keyword" style="box-sizing: border-box; color: #f92672; margin-bottom: 0px;">matrix</span>.setTextWrap(false); </span>
<span style="box-sizing: border-box;"><span class="hljs-keyword" style="box-sizing: border-box; color: #f92672;">matrix</span>.<span class="hljs-keyword" style="box-sizing: border-box; color: #f92672; margin-bottom: 0px;">clear</span>(); </span>
<span style="box-sizing: border-box;"><span class="hljs-keyword" style="box-sizing: border-box; color: #f92672;">for</span> (int8_t x=<span class="hljs-number" style="box-sizing: border-box; color: #ae81ff;">8</span>; x>=<span class="hljs-number" style="box-sizing: border-box; color: #ae81ff; margin-bottom: 0px;">-100</span>; x--){ </span>
<span style="box-sizing: border-box;"><span class="hljs-keyword" style="box-sizing: border-box; color: #f92672;">matrix</span>.<span class="hljs-keyword" style="box-sizing: border-box; color: #f92672; margin-bottom: 0px;">clear</span>(); </span>
<span style="box-sizing: border-box;"><span class="hljs-keyword" style="box-sizing: border-box; color: #f92672;">matrix</span>.setCursor(x - <span class="hljs-number" style="box-sizing: border-box; color: #ae81ff;">8</span>, <span class="hljs-number" style="box-sizing: border-box; color: #ae81ff; margin-bottom: 0px;">0</span>); </span>
<span style="box-sizing: border-box;"><span class="hljs-keyword" style="box-sizing: border-box; color: #f92672;">matrix</span>.<span class="hljs-keyword" style="box-sizing: border-box; color: #f92672;">print</span>(<span class="hljs-string" style="box-sizing: border-box; color: #e6db74; margin-bottom: 0px;">"1 short text"</span>); </span>
<span style="box-sizing: border-box;"><span class="hljs-keyword" style="box-sizing: border-box; color: #f92672; margin-bottom: 0px;">matrix</span>.writeDisplay(); </span><span style="box-sizing: border-box; margin-bottom: 0px;"> delay(<span class="hljs-number" style="box-sizing: border-box; color: #ae81ff; margin-bottom: 0px;">100</span>); </span>

To start, the text shouldn’t wrap as a message will be scrolling across the matrix. The first variable, x=8 is where the text will start to scroll across. This example starts on the right and moves towards the left. x>=-100 is allowing room for the characters. I took the total number of characters in my text message and multiple it by 9 and the text displayed correctly. If you miscalculate you might not see the whole message. This happened to me as the original message was about 4 characters and the value was 96. My message was much longer, but I hadn’t changed the 96. Once it was bumped higher all worked out well.

I was using my Uno clone to do the testing. It is just much quicker to make a change and upload it quickly. Everything was moving along great, but I noticed one thing, the message wasn’t oriented right, it was a bit upside down.

There is another command that comes in useful.

matrix.setRotation(<span class="hljs-number" style="box-sizing: border-box; color: #ae81ff;">1</span>)<span class="hljs-comment" style="box-sizing: border-box; color: #75715e; margin-bottom: 0px;">;</span> 

With it you can rotate the screen in any of the four directions depending on where you need/want the pins to orient. Setting it to one put 0,0 in the upper, left-hand corner, with the pins pointing downward. Or as in one part of my code I use the rotation to spin the heart.

Now is was time to program the ATTiny. I do like working with these little guys. They work quite well in a lot of my projects and can take up a lot less space than an Uno. There are some great guides out on the net on programming the ATTiny family of processors. The only hiccup I had was dealing with the Wire library.

While libraries might be compatible within the ATMel family of chips, there is the space consideration. And the ATTiny85 doesn’t have the room of its big brother. There is a Wire library that was made just for the ATTinys, it is also from Adafruit. WireTinyM. Once I updated that it worked much better. I left in both for when making changes and updates. Depending on which one I am using I can just comment out the other. 

During all of this I am still pondering how to make the mount for all of my little bits. I start to look at the 8×8 and the Tiny and figure what the hay. There are only 4 pins that need hooked up. And this would probably look way cooler than protoboard as there is no time to get a PCB fabricated and delivered. It seemed to so simple, 4 pins to 4 pins. It took a couple of tries in trying to find what might look best and also work the best.

Well, it struck me. It had earlier, but wasn’t too hip on the idea at first and then it just started to grow on me the more I thought about it. I got myself a length of electrical wiring. I had a length of 3-wire left over from a kitchen project. I pulled out the ground wire and bent it in the shape of a heart. I would then just be able to hang the matrix and Tiny from the top of it. Shazaam!

After that it was a matter of finding a base (a birch log part that was from a wedding center piece and some Lake Superior lake shore rocks).

Oh last but not least, I had to power it. I was going to use USB cable, but no, that would be just too much hassle. AA?? Naw, too many and won’t last too long. Hey, I have one of those lipos at 3.7, I wonder if it would work? I know the ATTiny will work at 3.3V and that data sheet states the lowest power the for the matrix is 2.7. What the heck. I wired up a JST battery connector and plugged it it – DONE!

SCHEMATICS 

Img 1853 3hpmbc0wrk