Monday, March 31, 2014

Sending and Receiving Data from an Arduino Through a Webpage

I thought it would be kind of cool to be able to control an Arduino remotely so I hacked up a bunch of code that allows me to do this. The website can control multiple Arduino's at one time and recognizes them by their unique IDs that they send.

Basically, what you need is:

A computer running Linux
A webserver, Apache is nice with ability to run Javascript and Perl
Perl
An Arduino

How it works is like this:
1. Arduino sends data to the Serial port that is polled by computer_interface.pl and written to a file that is plotted using gnuplot to display on the webpage
3. Webpage uses web_interface.cgi to write data to a file that is read by computer_interface.pl and sent to Arudino
2. Arduino is polling Serial port to receive data and uses the data to modify variables that can change how the Arduino operates.


What this code was written for was having an Arduino controller multiple pieces of equipment in a Scientific lab but it can be ported to use for many other things.

Here is the Arduino Code: http://pastebin.com/f8eBJc7R
Here is the computer_interface.pl: http://pastebin.com/yGNMCH54
Here is the webinterface.cgi: http://pastebin.com/qpUZ5n9A
Here is the gnoplot formatting file should be in the same directory as computer_interface.pl: http://pastebin.com/1BWNaAc4
HTML file: http://pastebin.com/e2Fpkrfi
HTML CSS: http://pastebin.com/1YUnWS0Q
HTML Javascript: http://pastebin.com/kNvEVa0d

1. Install gnuplot: apt-get install gnuplot or yum install gnuplot
2. Put the HTML files in /var/www/html
3. Setup Perl execution on your webserver  (http://stackoverflow.com/questions/560749/how-do-i-configure-apache2-to-run-perl-cgi-scripts)
4. Make sure you Arduino has code loaded and is plugged in.
5. Run computer_interface.pl in background and make sure the gnuplot file is in the same directory
6. Use!

The webpage refreshes every 30 seconds you can change this in example.html.

The Javascript is just for giving the webpage a tabbed format to run multiple devices. This can easily be removed and changed so that you don't need the CSS or Javascript files.


Sunday, March 30, 2014

SXSW

This post is about a month old but I have been so busy I am just finishing it up.

So for some reason I was fortunate enough to be invited to South by Southwest(SXSW) from the wonderful Karen Ingram and Shawn O'Keefe. At first I didn't know if I would go. Plane tickets were kind of expensive and I am currently in what will probably be the most busiest time of my year (Conferences, Science, Talks, &c.). Also, I am not a spontaneous person and don't like random people. I had never met Karen or Shawn in person and didn't know anyone in person who would be going to SXSW. I can be introverted at times. Well considering I spend most of my non-sleeping life in lab I guess I would be considered significantly introverted, yeah, I mean I just don't usually like people, at least when I am sober. Anyways.... I decided to go because I felt like the opportunity was so good I could not pass it up and because I only had a few days to spare even if it didn't turn out well I wouldn't lose much besides money.

It was a great time. I met Dan Grushkin which was pretty sweet and we achieved the high score on Marvel vs Capcom at a bar and became pretty drunk in the process. Austin basically turns into New Orleans and 4th st. into Bourbon st. I am pretty excited to go again next year and I hope to have some cool Science.Technology to show-off and impress people. Well at least impress myself.

I went to see the movie The Immortalists at SXSW because Jason Sussberg came to the Biohacker meetup and convinced me to go. You should check out the link and trailer and if ever have the chance to see it you should. I really love documentaries and wish people would make more of them. It is just so cool to experience someone else's life that is different from my own or learn about something new. Seriously, I wish I could watch a documentary on everyone I know. I guess that is kind of creepy?

Anyways, there were so many interesting and cool people that I met there. I hope I actually can spend time with them in the future.

I am learning to go a little bit outside my comfort zone more and attempt to experience new things even though I would rather just sit in my apartment and build stuff. Also, I am beginning to see that I don't hate people as much as I say I do. Hah, I think I just don't enjoy people who are boring and.or stuck-up. 



Friday, March 21, 2014

Magic

The summary is I think people should play more than 60 cards in their magic deck if they think the card is beneficial. Argue away tell me I am wrong. I don't mind. I was just bored.

So why do people play with 60 card decks? I have often asked this question and the only clear answer people say is that you have a higher probability of drawing a single card. Indicating that in the case of top decking a 60 card deck is better.

I think there is lots of misinformation: http://www.starcitygames.com/magic/standard/12478_61_Cards_Magic_Russian_Roulette.html

Chapin saying that 0.7% is alot of changing by adding one card to your deck because that is 1 extra loss every 250 games. What he fails to mention is that it is only a loss if the card doesn't help you win or prevents you from winning. Say the card helps in 50% of your matches and 50% it is dead. That means that any possible bad effect is ngated by the good effect. You would lose 50% of that 0.7% but you would win 50% of that 0.7%. If the card is actually beneficial alot like lightning bolt in an aggro deck then he is completely wrong. Saying 61 cards is bad because it reduces your chance of drawing a winning card by 0.7% is ridiculous.

He also claims that Battle of Wits sucks because the mean power level of the cards in the deck is not that strong and so one should not add cards. What he fails to mention is that in a 200+ card deck you are virtually turning all card draw percentages into 1/4 what they originally were and obviously there are only so many cards with specific effects (i.e. even if I have 4 Ponder, 4 Preordain and 4 Brainstorm the probability that I will draw one of those in Bwits is still less than if I just have 4 Brainstorm in a 60 card deck).

Olivier Ruel says to never play with 62: http://www.starcitygames.com/article/17670_Reflecting-Ruel---The-61-Card-Debate.html
Because it screws up your manabase.
Say you need to have 3 lands by turn 3:

70 card deck: 67%
64 card deck: 75%
63 card deck: 76%
62 card deck: 78%
60 card deck: 79%

So we have a 3% less chance of making our 3rd land drop by turn 3 in a 63 card deck!! A drop of 79% to 76% means you are 96% as likely to have the same thing happen! Are you telling me you wouldn't bet on those odds?

Chingsung Chang had a nice article about why 61 cards is ok (http://www.gatheringmagic.com/the-extra-card-fallacy-2/). I agree but I argue that even more cards are ok.

So let me ask you this, say I have 4 Karn Liberated in my deck and 60 cards what is the chance I draw a Karn in my first 7 in a 60 card deck as opposed to a 80 card deck?

Using a my simulator:
60 cards: ~39%
70 cards: ~35%
80 cards: ~31%

As turns go on we should see less of a separation. All these simulations assume you are on the play. 10,000 simulations per value. The numbers are not exact because we are simulating so there is obviously a margin of error.
What this graph shows is not the percentage you have the card in your hand but rather "How likely are you to have the card in your hand compared to a 60 card deck?" Am I 90% as likely? We see that in a 70 card deck we are still ~90% as likely to see the card as we are in a 60 card deck. In a 64 card deck we are 95% as likely and in a 61 card deck there is almost no change!!!
Inline image 1



So I looked at my Modern elf deck (http://www.mtgdeckbuilder.net/Decks/ViewDeck/479124) and was looking at lands because I decided to run 63 cards in my Elf deck because it is a combo deck so why not? It is not really looking for any one card because there are so many ways to combo out. It has 18 lands and I usually want at least one in my opening hand. The change between 60 and 63 is virtually nonexistent. Looking at the actually numbers you are 98% as likely to draw a land in your opening hand in a 63 card deck as you are in a 60 card deck! Even in a 70 card deck your are still 96% as likely. Looking at 60, 61 and 62 card decks they are virtually identical.
Inline image 2


As you increase in number of turns you become exponentially more similar to a 60 card deck and more likely to draw the card. As the number of the card increases in the deck you become exponentially less likely to have the same draw percentage between a 60 and 70 card deck. Of course you become more likely as you approach the limit of 99%, which starts near 18 cards in a deck.

It seems that changing your deck size from 60 to 70 cards doesn't have as much effect on 1-4 cards as I would expect. So when we have 4 cards in a deck our percentage of having the card in our opening hand is only 4% different in a 70 card deck as a 60 card deck.
Inline image 3

With card draw and scry and searching these numbers probably drop even more. To the point that if you have a bunch of card draw there really is no point in not having more cards in your deck if you think they will be useful. If you are playing a pod deck or toolbox the only cards you are really really want to draw are Birthing Pod or Chord of Calling. So adding say a Fulminator Mage because you expect a bunch of Tron decks in the meta will almost have a non-existent effect on drawing your other cards and will provide you with a card that can have uses even if not playing Tron and you draw it.

So why do people play 60 card decks then? One reason seems to be self censorship. I wouldn't want 6 Karn's in the deck even if I could because I don't want my opening hand to have more than one Karn in it. Ok so what is my percentage of having two or more Karns in my opening hand with 3 versus 4 cards in the deck. It is 4% versus 6%. However, my chances of having the card at all in my opening hand changes from ~31% vs 40%!!! If we subtract that's 27% vs 34%. That's a 7% increase for only a 2% chance more likely to have doubles in your opening hand. Maybe I would want more Karn?

Anyways, situations where I think having more cards that are useful.
#1. Relic of progenitus or a card versus the metagame
If there is alot of Jund and alot of snapcasters and floating around it never hurts to have a 1 costing artifact that you can cantrip if it is useless. Obviously if you are running deathrite and friends there probably is no need but any midrange or control deck should run some even if it bring you over 60 the card draw basically negates any effect of having the extra card. (obviously there are drawbacks to this strategy if you are combo or burn? maybe?)
#2. Combo
Yes it sucks to have 2 kiki jikis and 2 splinter twins in your opening hand but you know what is worse not being able to find the cards. I see Twin decks often running less than 8 exarch/pestermite and less than 8 kiki/twin, maybe for fear of going over 60 cards. When has a twin player not wanted 2 twins and 2 exarchs in their hand?
#3 Control
In a control deck many of the cards are very similar. You have deck manipulation, wrath/creature destruction effects and control cards(counter spells and bounces). Playing a 61st or 62nd card main deck to help against half the field or more will probably have little to no effect due to the deck manipulation alone. Further, control decks usually go 10+ turns meaning that any effect that adding extra cards would have will be cancelled out the more you draw.


How often am I going to draw a 1 or "2 of" card in a deck when it will be useful versus when it will just be a blank. In a 70 card deck your chances of drawing a "1 of" by turn 6 is 17%. With deck manipulation, slightly more or less as you desire. In your opening hand it is 10%. If the card is say Serum Visions, I can't statistically see how it would be bad to have that card.

Sunday, March 2, 2014

Passion

I love Science.
Some people do Science and some people enjoy Science but I love Science. I _LOVE_ it.

I am not the best Scientist. I have whacky ideas and spend lots of my time trying to do crazy stuff when I could be actually accomplishing something. It sucks. I wish I was better. I really do. Because. Science is my heart. It is my soul. It is my Passion.

Maybe you are Passionate about Science. Well let's show it.

Watch this video:
http://vimeo.com/18166037

Maybe you are not a football fan. But I am sure you can see the Passion of these footballers. Why is Science different? Why can't we show our Passion and be so Passionate about our work that we cry, scream, hate, love?

Does going to Scientific talks inspire you? Or does it put you to sleep? They usually always put me to sleep. Science is so much a job now. Which is cool. It is cool. Everyone who does Science can't be passionate about it. Do people even have Science heroes anymore though?

Oh you love Neil deGrasse Tyson or Bill Nye, great people who don't even do Science anymore. Bill Nye is not even a Scientist. These people are not the worst, they do attempt to inspire people to do Science. But ya' know what is more inspiring? Someone who is actually in the game, sweating the blood and tears. Toiling to make something. Is that you? Why do you hide it? Are you afraid that showing emotion and Passion might ostracize you in the Scientific world?

Ya' know what I don't want? A science or nature paper. Ya' know what I do want? To maybe hopefully possibly do something that is so intricate and beautiful and someone else sees that and is inspired by it.

I will never be as intelligent as some of the people I know and have worked with. I probably will never rock the Scientific world. But I will always try hard and I will always keep going because Science is too amazing and beautiful to ever give up on.

As ODB said "Science[Wu Tang] is for the children."