Making Suwako Moriya’s Hat: Part 1

Suwako Moriya and her hat

Suwako Moriya and her hat

Some months ago, around October, I was Skyping with a friend late at night and we started to talk about Touhou, Suwako Moriya and Arduinos. Having wanting to do something with Arduinos for a long while—my last project being my RFID-enabled door lock—I decided make myself Suwako’s hat, but with LED’s inside the eyes of the hat. My plan is to wear it at NärCon, Sweden’s largest convention.

The next day I went to a local store that sold Arduinos and a small variety of different components, and bought myself an Arduino Uno and a small 8×8 LED matrix to test with. The staff at the store didn’t know what color it was since it wasn’t specified anywhere, but it turns out it was a red LED matrix, not exactly what I wanted since I wanted RGB, but it was good enough to test some ideas with.

Next up was finding something to make the eyes from, where I could mount the LED matrices inside. It was hard to find, but in the end I found a Gashapon-style vending machine at my local food store that had large enough capsules to fit LED matrices inside. I bought two of them and planned to paint them white.

The LED matrix had some issues though, when put close to a surface, the dots would bleed together, not creating the effect I want.

I decided to continue with just creating something with LED matrices and worry about the actual hat and eyes later on. Since I didn’t like the LED matrix being single color, I decided to take a look at RGB LEDs. That’s when I found NeoPixels, and while the same store I bought the original matrix had some NeoPixel products, they didn’t have the 8×8 RGB NeoPixel Matrix. Fortunately a Swedish online store does stock them and other Adafruit products, so I ordered two 8×8 NeoMatrix and I had them two days later. Hooking them up to the Arduino wasn’t all that hard but I had to replace all my code so far to use the NeoPixel and NeoMatrix library instead.

These things are bright!

These things are bright!

One issue though, according to the specifications of the LED matrices they use a lot of power, about 60mA per LED that’s set to full brightness on white, that’s 3.84A for one panel and 7.68A for two panels, if all LEDs were set to full white! Fortunately I wont be using all LEDs at once, but even 32 LEDs on full light (16 LEDs on each panel) would end up at 2A. An AA battery for example would discharge in about 1 hour at that rate, but I don’t expect to use full brightness (the above picture is at 3% brightness), so it’ll probably last for a while. Since I’ll be wearing this hat for 4 days at NärCon, having it powered on when I’m not sleeping, I got myself two 12000mAh USB battery packs just in case. The plan was to use both batteries at the same time, one powering one of the LED matrices and the Arduino itself, and one powering the other matrix. So I ended up buying two mini-USB breakout boards to tap into the power of the batteries, unfortunately I never got it to work since I don’t think those battery packs are made for stuff like this, only one of the LED matrices would power on (occasionally, both matrices would power on), and with my limited knowledge of electronics I couldn’t figure it out, perhaps it was an issue with how I connected the grounds. In the end I decided to use only one battery pack for everything while the other is charging.

I started making a simple animation with regular eyes that randomly looks around. The plan is to have different kind of animations and different kind of eyes, as well as different colors.

But having it work on its own is boring, right? Remote control! I bought a cheap IR receiver and control set at the local store, planning to use that to control which eyes are on and what colors, but that only gives limited options and would be awkward to use. So I head back to Lawicel, the Swedish retailer of Adafruit stuff, and bought the nRF8001 Bluetooth LE chip! The plan is to use my OnePlus One to control eyes, colors and other stuff, and when that’s implemented I would head on to make an Android Wear app for my LG G Watch R so I can control the hat from my watch. Implementing Bluetooth was quite hard at a first glance, especially since I don’t really know C++. I found some examples that I tried to modify to fit my project, but it just wouldn’t work, the LED matrices would just flash and misbehave. Took me a week of thinking to figure out what was wrong, and in the end it turns out I had ran out of RAM, since the Arduino only has 2KB of RAM and I was storing the eye patterns in a bad way, using around 192B RAM, which I later could optimize down to only 24B after someone in #arduino pointed out that I should use bitshifting instead.

Android app draft

Android app draft

The Android application is currently pretty much a draft and not much to see. When it’s done you should be able to select which eye to draw on each matrix or to enter random mode. You should also be able to select the color, or put it in fade/random color mode.

The hard part for me would probably be how to make the actual hat and eyes. For the eyes I’ve been thinking 3D printing would be my only choice, and I have to find a makerspace that would let me use their 3D printer for this. I have done some 3D modeling in Autodesk Maya trough my high school years, but it was quite a while ago and this time I’d have to use something free like Blender. The fact that I never done anything to be 3D printed before makes it even harder. My idea so far is to make a sphere that can be taken into two parts, much like those Gashapon capsules. I’m uncertain on how to solve the color bleed issue, but the plan was to have small pipes from each LED on the matrix to the surface of the sphere, but I’m unsure if that would work.

I have released all the source code on GitHub, but be warned I don’t know much about C++ and electronics like these, so there might be some weird stuff going on.

Lastly, below is a video of my progress so far with “random mode” and color fading. It still needs a lot of tweaks, obviously the eyes should not change that often. Currently it has a 3% chance of changing every tick, and there are about 50  – 60 ticks every second, so it changes pretty fast, but it’ll be updated later on to a much saner value. Stay tuned for part 2!

What I’ve learned during GSoC and phpBB

During this summer I’ve been working on an REST API for phpBB as part of my Google Summer of Code project. I’ve learned a lot about a lot of things during the summer and I’ve surely had one of the best summers in a while! I wanna give out a thanks to the phpBB team, and summarize what I’ve learned and done during the summer.

What I’ve learned

I’ve learned a lot about the open source world which I hadn’t really entered before. Mainly in this regard I’ve learned more about Git and how to do proper pull requests and such (also a lot about rebasing, branching and other useful things I’ve never had done before). I’ve gotten more used to read others code and understand their code as well as modifying it. I’ve also got to pickup the phpBB coding guidelines and it has helped a lot to improve my code.

Another thing I’ve learned (but still need to delve deeper into) is Symfony, composer and dependency injection. Prior to GSoC I had barely used any of them. I managed to use what I learned in other projects almost instantly as I got a new job as a part time web developer at a local company, and we use a lot of these things there (but using Laravel instead of Symfony).

I’ve learned a bit about cryptography and hashing, to use for authenticating the API. To be clear I’m still confused with all of this and probably have to take another look at it later, but I definitely know more about it now than I did before.

I’ve learned a lot about various design practices, and new stuff like repositories, entities and so on, which was new to me. This too has helped me at my new job as we use these kinds of things a lot.

Thanks

I want to thank the phpBB team for accepting my proposal, it has been one of the greatest summer in a long time for me. I’ve learned a lot of useful stuff and I’ve met a lot of new people in the process. I would also like to say thanks for the generous invite to the hackathon in Montreal, it was really fun and I would do it again if I ever get the chance in the future.

A last word

It seems like I’ve given up on the project but I sure haven’t, just that I’ve been busy with some courses at college as well as that I got a new part time web development job taking away my time. I’m still thinking about the API and still planning the next steps, and I promise to finish what I’ve started. I’m currently planning and preparing for my final thesis work this spring, but I probably have some free time now and then when I can devote myself to the API again, don’t worry :).

GSoC, phpBB API and hackathon in Canada!

The results from GSoC (Google Summer of Code) has been out for almost 2 weeks now but I haven’t had time to write about it yet. I was one of the six that get to work for phpBB and I’m really excited to do this! As I’ve mentioned earlier I tried to apply to phpBB with the API last year but didn’t have any luck back then but this year I was lucky to be selected.

What I’m gonna do this summer is to create a REST API for phpBB. It would allow developers to create various applications that can interact with phpBB in an easy way. Examples could be mobile applications, desktop applications and more. If you wanna check out my proposal, it’s publicly available here. I think it’s gonna be a lot of fun creating this and I hope it turns out awesome.

Furthermore, I’ve been invited to phpBBs hackathon in Montreal, Canada in July! The event is between July 10 – 14, but I’ve decided to stay a bit longer until July 19 to sightsee a bit and meet up with a friend of mine. It’s gonna be a lot of fun, I’ve only been on a smaller hackathon before that I hosted myself. It will be my first trip outside Europe, I think it’s gonna be awesome.

Open source – Start contributing early

I’ve come to a realization that I suck at contributing to open source projects. It’s not like I dislike contributing to open source or believe I suck at coding, but that I just don’t know what to contribute, how to do it and feeling insecure about my code and solutions. I became interested in programming in 2007 and since then I’ve only coded alone on my own projects. I never contributed to open source projects because the thought never crossed my mind.

It wasn’t until last year when my friend Callum Macrae showed me GSoC (Google Summer of Code) that I (slowly) started to contribute to open source projects. The goal of GSoC is to submit a proposal of how you would make any of the registered open source projects better, and if you are chosen by the open source organization, you’ll implement your proposal during the summer and you get paid by Google for doing so. Last year I submitted a proposal to phpBB to create an API, but I didn’t get chosen (looking back at that proposal I realize how bad that proposal was so it wasn’t a surprise I wasn’t chosen).

To increase ones chance to get selected you’d have to contribute to the project beforehand. I checked the bug tracker for things I could fix but come to a realization: I have no idea what I am doing. As I’ve only worked alone for so long I always knew what bugs there were in my projects and how to solve them, but this wasn’t the case anymore. I checked bug report after bug report but I wasn’t secure enough to fix any of them. Fortunately I found a couple of rather easy ones to get a hang of the open source workflow of phpBB. Here was my next problem: how exactly do I submit my patch? phpBB uses GitHub, and I’ve used git and GitHub before but only for my own use. I read some instructions on the phpBB wiki and asked Callum as he contributes to phpBB as well, and sure enough, just fork the repo, branch from the correct develop branch, fix whatever bug you were about to fix, commit that to your own repo and submit a pull request. Easy enough.

Or not. No one had ever reviewed my code before. No one had ever commented on it. This had led me to become very insecure about my code and I was worried what others would think about my solutions and my coding style. I was unsure what I would put as my commit message, and sometimes even afraid to send the pull request. I managed to fix some four or so small bugs but after my proposal was rejected I got a bit bored with contributing and forgot about it and went back doing my own stuff instead.

This year I’ve tried again with GSoC and phpBB with same idea but a much better proposal than last year and I’m in the same position and I’m trying to get used contributing again. I still have issues with insecurity and how I should solve things the best way, but I’m trying my best to overcome these obstacles and get more active contributing to various open source projects.

The message I want to send is to start as early as possible with contributing to open source projects. Even if you don’t know enough programming yet, check the bug tracker occasionally, try to understand parts of the projects code and when you find a bug report that seems easy enough for your skill level, don’t be afraid to fix it! I believe by contributing to open source projects, you’ll learn to be a better team member and you get valuable feedback on your work. It’s a crucial skill and you really need it later in life when you are working in teams at whatever job you get.

I know for one that currently I’m not the best at working in teams. I’m doing ok with groups of 2 – 3 persons, but when working in large groups I have a hard time making myself useful for the rest of the team. I do wish I’ve started contributing to open source projects earlier in my life so I would be more prepared at it when starting college, but I guess it’s better late than never am I right?