Saturday, May 16, 2015

I Graduated

I finally graduated! These last four years seem to have flew by, and it's kind of nostalgic to think about everything that happened in that time. Even though everyone acted like I had accomplished something monumental today, I can't help but think about how relativity small this achievement is when compared to everything else that I'll do in my life ;)

Saturday, May 2, 2015

Senior Project

Hey everyone! Sorry for disappearing for a couple of months. Like always, I took way too many classes at my college and ended up swamped with too much to do after about a month or so. Sometimes I wonder if all the stress is really worth it ;)

This post is going to be pretty cool though, but first let me explain some back story. So I'm going to graduate at the end of this semester, and it's required for all the engineering students at my university to take a senior project class where they work with a team comprised of other students to develop a product. I've always been somewhat unenthusiastic about working with other students since it's common for me to end up doing a majority of the work. For the most part though, my senior projects group worked together pretty well.

So the first month of this class was dedicated to giving us time to think up an idea for a project. In case any of you didn't know by now, I'm studying electrical engineering, so the project we made had to be related to that field. My group and I came up with some really good concepts, but all of them were either impractical for the time we had or they weren’t approved by the teacher. Ultimately the teacher gave us the idea of doing something like a glove with a temperature sensor in it. In reality, my entire group thought this was a boring idea, but we did it anyway since none of our own got approved and we were out of time. I really enjoy taking something bland like that and going well beyond what I need to do to try making it awesome, so I knew I had a lot of work ahead of me ;)

Enough with the intro. Lets get back to what I wanted to write about. So my group and I had to do a couple of presentations throughout the semester, and I ended up spending a lot of time creating and editing images to make our presentations more appealing. One of the initial images I made was what we wanted the final prototype to look like, and here it is (my teacher went crazy for any kind of animations!)
With that overall goal in mind, I started working on the circuit. It's a similar design to the Chip-8 emulator I made a while ago since that was still fresh in my mind back then. I used this 1.8'' TFT LCD that uses an ST7735R driver. According to Adafruit, the company that sells the screen, I am now an expert at soldering since they claim only that experts who are comfortable soldering a surface mount display using find pitch soldering techniques should use it lol. It uses an 8-bit SPI protocol with a separate line to indicate if the byte being sent is a command or data. I got it to work in only a few hours since it was really similar to the Nokia 6100 LCD I worked with before, so most of the code I wrote earlier worked after some minor changes. The screen code I wrote uses a typically double buffering technique to make changes to the screen look smooth and to minimize the number of times that it has to write to the screen. We also used the MLX90614 non-contact temperature sensor to allow us to obtain temperature readings. That uses a repeated start I2C protocol, and it is capable of taking the ambient temperature of its surroundings and the temperature of whatever its facing. The best part was how much faster it is compared to the LM35 temperature sensor that we had originally planned on using. So the final circuit ended up being this.
And here's a picture of some tests being run while trying to get everything working on a breadboard.
Did you notice how nice those characters look on that screen? That's because I got fed up with the old way that I was using to store and draw characters which involved manually laying out how I wanted the all the characters to look. Here's basically what I was doing before for about 90 characters...
 111  <= H  
What I really wanted to do was take an existing font and convert into some kind of format that I could store and use in the microcontroller I was using. So one day in January, when I just finished reading the chapter on fonts in Design for Hackers: Reverse Engineering Beauty, I was inspired enough to whip up a simple program that utilizes SDL's TTF extension that does exactly what I wanted. Here's a picture that shows how it's extracting the pixel data from the 'W' glyph of the Checkbook font with a size of 26pt. It also stores the alpha values for the edges of the character that causes the anti-aliasing affect. I uses these values in combination with an alpha blend algorithm, and the end results is that I'm able to display some very nice looking fonts with a microcontroller :)
After getting everything working on a breadboard, I created a circuit on a perfboard. And the next time any of you are in a Radio Shack looking for perfboard, don't waste any time asking the staff for help because they will have no idea what your talking about lol. I used sockets for both the microcontroller and screen since it would have been really inconvenient if either of them were damaged while soldering.
Then we had to make the actual glove form to hold the circuit. Luckily for me, my brother is an expert at sewing. Here's the template he made and a couple of the initial glove concepts.
I had written a program late last year that could convert 24bit BMP images to a format that could use with the microcontroller. It wasn't ideal since not every image I work with is in that format, so I rewrote it using libavcodec since that library has codecs for nearly every type of image file. The end result worked just like I wanted, and here's a picture of my groups logo being display on the LCD screen. My teacher wanted to incorporate some business aspects into the course, so he made us create things like logos and business plans throughout the semester. Our company's name was Glovomatic Worldwide since our product was sort of glove-like...
And finally we had our finished product :) The interface features a simulated thermometer that displays the current reading based on a percentage in a desired range. The color of the thermometer goes from blue to red depending on that percentage, and it uses the same alpha blending technique I used for anti-aliasing the fonts the create all the intermediate colors. It has one button to cycle between choosing human, object, and room modes and another button to actually take the temperature. The different modes are to compensate for different types of heat loss. Ideally your internal temperature is 98.6°F, but your forehead is more like 93°F due to heat loss which is also affected by the ambient temperature of the room. So we had to change a scaling factor to make the temperature closer to what was expect when taking a person's temperature.
However our teacher wanted it to be smaller, he didn't like the placement of the buttons, and he didn't like how he had to physically press a button to take the temperature. So we made a second glove that had these changes. I personally think our first glove looks so much better than our second, but at least it kept the teacher happy. The second version ran off of a single 9V battery where the former used three AAA batteries. It turns out that not all 9V batteries are creates equal, so don't make any assumptions about the current you can draw from them... otherwise you can expect to do a last minute run to the store where you'll buy 4 different brands of 9V batteries hoping that one will work right...
At the end of the semester, my University hosts an event called Innovation Day where all the different engineering groups display their creations. To be honest, our product isn't very flashy or anything, so I wanted to have a way to make it more interesting for the people at the event. I've gotten pretty good a web development over the last year, so I thought it would be awesome to add an ESP8266 wifi module into the glove and have it act as a server to host a web page. That way any wifi enabled device could connect directly to the glove, download the web page, and start logging temperatures. If you've never worked with that awesome wifi module before, it uses USART protocol with an adjustable baud rate, and it has a set of predefined commands that allow it to preform certain operations. It was surprisingly easy to use when I first started working with it late last year.

Despite me reading a lot about it, I've never had the need to work with HTML5's canavs element before. Fortunately this seemed like the perfect opportunity to try it out. I used it to create a bar graph that shows the high, low, and average of each different mode, and it also creates a line graph that plots the ten most recent readings for each mode. It uses AJAX calls to obtain new readings from the glove every 2.5 seconds. The final web page that I made was all self contained in a single HTML file because I wanted to reduce the amount of file requests to the wifi module to minimize the chances of problems occurring. I accomplished this by storing the image as a data URI and having all the JavaScript and CSS directly in the head of the document and inline with the HTML tags. Here's a picture of the web page without anything graphed or plotted. The scales for each graph adjust automatically based on the data that it is displaying, but I have it start off with a range of zero to a hundred degrees when there's no data.
Then I needed a way to store the HTML file on the microcontroller. So I quickly threw together a program to remove all white space and comments, escape certain characters, and ouptut a header file that I could use. I still wanted to maintain the same structure as the original document in case I needed to quickly make changes to the outputted file during development. Here's a picture showing what the input and output looked like for the HTML file after being run through the program. I tried to reduce the HTML file's size as much as possible because I wasn't sure how reliable the wifi module would be with transmitting a >30KB file. At the last minute, I did think about using gzip or zlib's deflate compression that web servers often use to further shrink the file, but I never got around to implementing it.
A quick note for any of you who want to send large files with the ESP8266: be aware that the internal buffer that the wifi modules stores the data in before transmitting it is only about 1KB in size. If you try to send more than that at once, then it stops working. To over come this issue you need to send 1KB chunks of the file at a time while keeping the connection to the connected device alive and everything will run smoothly. I did have lots of problems when multiple devices connected to the wifi module at the same time, so we made sure that only one device was connected whenever we demonstrated it. The rest of my group members brought tablets to Innovation Day, and here's a picture of the web page running on one of them.
That's pretty much it. I love how I tried my hardest to make this project more about computer science than electrical engineering lol. For only having about three months to develop some kind of product, I feel like ours turned out pretty well.

Wednesday, February 18, 2015

Almost Lost Faith In People

Last Wednesday, one of my teachers handed out a unique piece of paper to each one of his 85 students. Each of these papers contained a series of number and a single character at the bottom that related to one of the characters. Mine looked similar to this.
 22 => 'N'  
We then had to hypothesis about what it is and how we can decrypt it. Then class was just about over, and he told us that he wants us to turn in our solutions the following Wednesday and that there are no rules for solving it. He quickly left before we had time to react. Most of us assumed that each person had a unique key pair, like how I had 22 => 'N', so a few guys attempted to scribble down what theirs were on the front board. By the time I left, there were about 12 out of the 85 unknown key pairs written down.

Since all of us wouldn't be in the same room before the solutions were due, we had to think up a better way to share the rest of the unknown keys. The university I go to has an online system, called web campus, that has discussion boards for each class, and a handful of people were starting to post their key pairs there. However there was a lot of confusion due to inconsistencies, and only about 8 of the 85 students were participating.

Before I get to far into this story, let me explain a little about this class. Three years ago, one of my advisor made a mistake which results in me having to take this entry level class, CS 105, during my final semester of college. So this class is composed of about 90% freshman, and I know the lazy mindset of freshman since I was one just a few years ago. I attempted to skip taking this class or substitute it with something more challenging, but all of my requests were denied. Because of this, I decided that I would try to make this class more enjoyable whenever possible in order to keep me focused. Lol, after re-reading this paragraph, I sound kinda full of myself XD.

So that's when I though that it would be awesome if we had an easy way to add/update keys and immediately see how those changes affect decrypting each of our messages. I've been teaching myself about web development for almost a year now, so I threw together a website that had everything that we needed. Here's what it eventually looked like after a few revisions. It allowed for keys to be added/updated/deleted asynchronously, and all the keys were stored in a database so that everyone could instantly have access to them.

I got that up online the same Wednesday that we were given this assignment, and I hoped that my fellow students would use it sometime within the next 7 days. How could we not all work together in that huge amount of time, right?

Of course it didn't go how I had planned.... and after 5 days only 2 other people had used the website. I was really starting to lose faith by this time. Then yesterday I tried to clean things up and promote the website more, and by day 6, a measly total of 4 people had used the website and only 32 of the 85 keys were known.

By this time we were figuring out that some of the letters were related to multiple number and that the teacher didn't give anyone vowels. This complicated things a lot. One of the worst things was that all the people who were contributing only knew about the keys for the punctuation marks, so almost 80% of the alphabet was missing.

Then day 7 rolled around, and the solution was due in an hour. By this time, I had given up on anyone new adding their keys to the database, so I tried deducing what my message said based on what we currently had. Luckily a quick google search for something like N_T_C___ eventually shows results for NETSCAPE if you guess on a few of the letters. From there I was slowly determining some new keys, but I was still missing more than half of my message. Also, I was finding out that a lot of the known keys were incorrect, which was probably due to some miscommunication early on.

At that very moment, someone else was doing the exact same thing I was doing by deducing keys based on what made sense. I looked through the database, and saw that this mystery person had added nearly 15 keys in the last 10 minutes. As it turns out, that person's contributions let me see more of my message, and I was able to fully decrypt mine. My faith was restored thanks to this mysterious procrastinator :)

When class started and the teacher asked everyone to turn in their solutions, and you could tell that a majority of the students weren’t able to complete it. I'm almost sure that the teacher assumed that no one would have figured it out since he knew that it would have required a large portion of the 85 of us to have worked together. Today, he explicitly said that in order to solve it, we'd need someone to take leadership over obtaining the keys and getting everyone to work together. I don't think this is true though nor do I think anyone took leadership in this situation. The only thing that we actually needed to solve it was to have the right tools available, and I was able to give everyone exactly that.

So here's some totals. There were 85 people who potentially had access to the website. At most, 13 different people contributed to the database. 137 changes to the database occurred, which includes adding, updating, and deleting keys. 102 of those database changes happened in the last 12 hours. At least 2 people managed to successfully decrypt their message. Lesson learned: don't ever attempt to get 85 students to work together because only about 15% of them actually care.

Thursday, January 29, 2015

Damaged Uvula

Hey everyone! I was hoping to post a lot more over my winter break, but things didn't really work out that way and time flew by. I got some really cool things done though, so I'll try to post about those in the next week. So here's a small update. I'm doing all better now after my car accident, and my cars all fixed too. I looked more into HP's RSA bios, and it turns out that the way I thought that the PEI was verified was incorrect. The existing PEI is saved when a new rom is flashed and it is used to verify the new PEI. My results a few months ago were based on me flashing a modded bios over an already modded bios, which resulted in this PEI check not happening. I did find a much more generic way to remove the DXE check from the PEI though, but I need to find a new way to by bypass the PEI check again. It's all handled by Insyde's flasher though, so using a different method to flash the rom works fine.

Now back to what this post is actually about. So I went to the dentist today for my biannual teeth cleaning. I make these appointments six months in advance, and I never know how busy I'm going to be when that day comes around. Well I was plenty busy today, so I told the dentist that I'd really appreciate it if she could hurry. I now know that this was a huge mistake. She accommodated my request and began rushing through the procedure. One of the first things she did was place a plastic hose in my mouth in order to vacuum out all the water and saliva while she worked. While she began jamming dental instrumentation into my mouth, the end of that hose managed to grab hold of my uvula. It had let out a loud shriek as it engulfed me. Even though it was only attached for a few seconds, it had managed to stretch out my uvula far enough that it now rests on my tongue. I I'm sure that if I didn't rush her, then this could have been prevented... Here's a picture of my uvula nine hours after the event.

After looking around, it turns out that there's a lot of cases of uvula trauma. Someone here went through the same thing I did. I guess I’ll just have to wait until it gets better on its own...

Tuesday, December 23, 2014

Car Accident

Some girl hit the back of my car today, and I spent the next 7 hours at a hospital making sure that my neck wasn't hurt too bad. My neck is still really sore :( What a terrible way to waste a day, and what a great way to ruin the holidays.

Sunday, December 21, 2014

Never Buying M&M'S Again

Let me apologize in advanced for posting something that's so pointless, but my recent experience with purchasing Mars, Incorporated's M&M'S has made me angry enough that I want to share it.

Every December, my work throws a Christmas party and it's focused around everyone being involved in a Secret Santa. I remember seeing M&M'S promoting personalized versions of their candies, which I later found out are called MY M&M'S, a few years back, so I thought it would be a fun gift to get one of my coworkers.

After obtaining a picture of my coworker, I placed an order on December 4 for some M&M'S. At the time there was a promotion code, which was MYMMS20, that took off $20 from the total. So I order a 2lb bag, and the total after shipping and the discount was $50.79. I still think that this was way too much for some candy, but I decided to buy them anyway since it seemed like a humorous gift.

I paid through Paypal, which is a service that I have never had any problems with, and the pending charge for the M&M'S remained in my Paypal account for 9 days before disappearing. Nothing was every charged nor did I receive any notifications from either Mars, Incorporated or Paypal about any issues with the transaction.

The MY M&M'S customer support only operates Monday through Friday 9am to 5pm EST, so I called them on Monday, December 15th, at 11:40am PST. After enduring through a semi-insulting hold message for approximately 70 minutes, I was finally put through to one of their representatives. I have had the same cell phone for almost 5 years, so I know the signs that it gives me when it's battery is about to die. This is relevant since I knew that my phone was going to die very quickly after I got through to the representative.

I asked the lady about the issues related to my order, and she said that it was something wrong with Paypal. I told her that I needed the M&M'S by the 20th, which is why I order them so far in advance. She consolidated me by offering to replace the order with free expedited shipping, however I wasn't allowed to use Paypal to pay for the order. I knew that my phone was not going to hold out long enough for me to give her a credit card number, so I asked if there was some number that I could call her back at. She told me that she would call me back in 30 minutes so that I can charge my phone, and I thanked her immensely for this kind act before hanging up. She even confirmed my phone number with me, so I r=felt assured that I would get called back soon.

30 minutes went by, and nothing. An hour went by, and nothing. The rest of the day went by and I never heard from her, so I decided to wake up early and call the next morning at 7:07am PST. I had to endure again through their semi-insulting hold message, but at least it was only for 40 minutes this time.

I proceeded to ask the representative about the issues with my order, and she had noted that she knew that I had talked to someone the day before since there was a note attached to my account. I am a very patient person, so I did not ask why I never received a call back yesterday. I was very frustrated a t this point though. She also asked me if I wanted to replace the order, and of course I did because I needed this present for my Secret Santa gift. She let me know that it would arrive by December 23rd, and I told her that this would be a problem and that I want the fastest shipping possible. She let me know that she is giving me 20% off, which was $12, and apologizing for any inconveniences.

The total charge for the M&M'S was $71.88. This is well past what any reasonable person would ever spend on candy. Apparently replacing my order does not mean reusing the $20 off coupon code, MYMMS20, that I had used when I first ordered them. In addition my phone service charges me $0.18 per minute that talk on it, so it cost me $20.70 of talk time since the total time spent talking to this company over the span of 2 days was 114 minutes and 9 seconds. Here's their itemized total along with their strangely priced shipping.
So I spent a grand total of $92.58 on a 2lb bag of M&M'S. I had waited a total of 14 days before receiving them since placing the order on December 4th, and I was on hold waiting to talk to one of their representatives for a total of 110 minutes. After wasting so much of my time and money being stressed out and confused over these M&M'S, I can assure you all that I will never buy another Mars, Incorporated product for the remainder of my life. It is very clear that this company is too busy caring about their profits that they don't have the time to care at all about their customers. Thanks Mars, Incorporated for the most expensive candy that I will ever buy!

And in case any of you were wondering, the Secret Santa gift went well. Everyone thought it was clever and funny. Here's a picture of the M&M'S that I had received. And sorry again for posting something that is pretty much just me ranting.

Friday, December 19, 2014

LED Controlled by the Internet

Happy holidays! Just got done with school for this semester, so I finally have some free time to get back to my hobbies. Speaking of hobbies, I bought an Espressif ESP8266 Wi-Fi module a few days ago and I finally got it working today. It's surprisingly easy to use, and it was hard to pass up purchasing one since it's only $5.
Just to test it out, I decided to make an make a project that can toggle an LED with the internet. The ESP2866 communicates with the microcontroller via UART and has an entire TCP/IP stack built into it. So it required me to know nothing about network protocols to be able to use :) I ended up writing a library to simplify sending GET and POST requests, but the basic underlying ESP2866 commands that I used are these.
 // Join access point  
 // Connect to server  
 AT+CIPSTART="TCP","Domain Name",80  
 // Send message  
 AT+CIPSEND=Length > Message  
So I created webpage that stores the state of an LED in a database. This state can be requested and updated depending on the parameters of the GET request.
      // Connect to database  
      $database = new mysqli("localhost", "Username", "Password", "Database");  
      // Create automation table  
      if(!$database->query("SELECT 1 FROM `Automation`")) {  
           $database->query("CREATE TABLE `Automation`(`ID` INT(10) NOT NULL AUTO_INCREMENT PRIMARY KEY, `Object` VARCHAR(16) NOT NULL UNIQUE KEY, `State` VARCHAR(255) NOT NULL) ENGINE=MyISAM DEFAULT CHARSET=utf8") or exit();  
           $database->query("OPTIMIZE TABLE `Automation`");  
           // Add Light entry to table  
           $database->query("INSERT INTO `Automation` VALUES(NULL, \"Light\", \"Off\")") or exit();  
      // Check if purpose is status  
      if($_GET["Purpose"] == "Status") {  
           // Get light's state  
           $result = $database->query("SELECT `State` FROM `Automation` WHERE `Object` = \"Light\"") or exit();  
           $object = $result->fetch_assoc();  
           // Return light's state  
           echo $object["State"];  
      // Otherwise check if purpose is set and state is set  
      else if($_GET["Purpose"] == "Set" && isset($_GET["State"])) {  
           // Update light's state  
           $database->query("UPDATE `Automation` SET `State` = \"" . $database->real_escape_string(htmlentities($_GET["State"])) . "\" WHERE `Object` = \"Light\"") or exit();  
           // Return if successful  
           echo $database->affected_rows ? "Successful" : "Failed";  
Now to we can manipulate the LED with the following GET requests.
 // Turn LED on  
 // Turn LED off  
 // Get state of LED  
I ended up making it so that a pressing a button will trigger the microcontroller to send the appropriate GET request to toggle that state of the LED in the database, and the microcontroller constantly requests the state of the LED from the server and updates the actual LED accordingly. Since it uses normal GET request, the LED can be controlled directly from a web browser. Here's a video of it in action :)

In the process of making this project I accidentally broke my HP DV6-6B22HE laptop :( I use a UART-to-USB cable when developing for microcontrollers since it provides an easy means of debugging, and I was curious to see if the 500mA provided by my laptop's USB port could drive both the UART-to-USB cable and my project. I somehow forgot to disconnect the 12V power supply that I was already using from the circuit, and this resulted in me putting 12V across the USB port on my laptop... It lasted about 3 seconds before dying... RIP :(

As a side note, I wanted to do a little bit more research on RSA bios before releasing my findings since the two modded RSA bios that I released didn't work. I guess the solution I found wasn't generalized enough for all bios. I have a lot more time to work on this now, so it shouldn't be too much longer :)