Thursday, 22 May 2014

Arduino Clock

Yes finally I am doing something that is a bit roboty. I managed to get my hands on an LCD shield for Arduino. Once my brother had worked out the correct pins to use we plugged it into an Arduino Mega we had lying around.

I immediately did a bit of research and it was really easy to turn it into a clock. There are quite a number of clock tutorials out there but I think a lot of their code is a bit overcomplicated. I was able to get one going with only page of code and only using the Liquid Crystal library.



Here is the code:

//Chris Fryer 2014 this code is in the public domain.
// http://myrobotnstuff.blogspot.com.au/
//Thanks baldengineer for millis() taming
//http://www.baldengineer.com/

#include <LiquidCrystal.h>

long time = 0;
int secs = 0;
int mins = 0;
int hours = 0;
//The number of second passed so far today (12 hours)
//eg. 12 noon and midnight = 0
long starttime = 18000;

int interval=1000;
unsigned long previousMillis=0;

// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(8, 9, 4, 5, 6, 7);

void setup() {
  // set up the LCD's number of columns and rows:
  lcd.begin(16, 2);
  // Print a message to the LCD.
  lcd.print("I'm a clock!");
}

void loop() {
     // Get snapshot of time
   unsigned long currentMillis = millis();

   // Millis() resets to 0 after 50 days or something. It also
   // screwed up my calculations that I wasn't able to reset it.
   // This if statement does three things.
   // 1. account for the reset
   // 2. allows me to only update the display when it needs
   // updating
   // 3. makes calculating time easier (I hate maths)
   // Thanks baldengineer for code
   //http://goo.gl/4YSE71
   if ((unsigned long)(currentMillis - previousMillis) >= interval)
   {
      // It's time to do something!
      time++;

      // Use the snapshot to set track time until next event
      previousMillis = currentMillis;

      lcd.clear();
      secs = time + starttime;
      if (secs>43199)
      {
        starttime = 0;
        time = 0;
        secs = time + starttime;
      }
      
      if (secs>60)
      {
        mins = secs / 60;
        secs = secs % 60;
      }
      
      if (mins>60)
      {
        hours = mins / 60;
        mins = mins % 60;
      }
            
      lcd.print(hours);
      lcd.print(":");
      //shove a zero in so it formats nicely
      if (mins<10)
        lcd.print("0");
      lcd.print(mins);
      //shove a zero in so it formats nicely
      lcd.print(":");
      if (secs<10)
        lcd.print("0");
      lcd.print(secs);
   }
}

Friday, 16 May 2014

Australia what have you done? The Senate is full of idiots!

I was watching Lateline a couple of days ago and they had two future senators on the program, Bob Day of the Christian Family First Party and David Leyonhjelm from the libertarian Liberal Democratic Party.

Libertarians are all about personal freedom, small government and zero government regulation of the economy. Some of the policies of the liberal democratic party include legalising marijuana to scrapping income tax and introducing a flat tax of 20% on everybody. Now David Leyonhjelm has obviously been talking to Bob Day a lot recently and filled his head with a load of libertarian bullshit. Look at this quote from Lateline:

the optimum level of tax-to-revenue is around about the 20 per cent mark. But they could start slowly, commit to doing one per cent a year and watch the revenues flow in.

Watch the revenues flow in… Wow, if they cut taxes the amount of revenue to the government will go up! Why has nobody thought of this before? It sounds so ridiculous it must be true! I really don’t know what a Christian is doing is doing sprouting this crap. Maybe he believes that the poor are poor simply because they don’t believe in God or don’t believe hard enough - a religious version of the just world fallacy.

The idea behind this 20% flat tax is the belief that our economy is driven by the wealthy. The wealthy by properties, set up businesses and invest. This money is supposed to trickle down the economy and help the poor out as well. A flat tax is supposed to inspire people to be wealthy. A wealthy person may think this sounds good in theory but there are several things wrong with this idea.

There are a lot more poor and middle class people than there are wealthy. All these people have to pay to feed their families, pay rent - spend their money on all manner of things. This money adds up and it is all these people that support the economy not the wealthy. We have what is called a progressive tax system which means there is a tax free threshold up to $18,200 and we have tax brackets all the way up to $180,000. The top tax rate is 45c in every dollar over $180,000.

The reason for a system like this is to not tax the poor so they are able to live on the relatively small amount of money they earn. This in turn helps support the economy. The rich on the other hand are able to look after themselves they still get $18,200 tax-free and all the rest up to $180,000. It is assumed that by the time you have earned $180,000 it won’t hurt you to pay a bit more tax. I believe introducing a flat tax would destroy the economy and, if you take into account that most people are not wealthy, would probably raise more money than our current system does. So it wouldn't be the inspirational effects of a 20% flat tax that would make the revenues flow in, it would be the poor who previously didn't pay tax. There would be far more homeless people and everybody even the rich would probably be worse off.

Completely deregulating the economy would also have potentially catastrophic consequences. In an ideal world where everybody is logical, nice and put the needs of society ahead of their own an economy like this would be fine. Regretfully, the fact is that humans rarely put the needs of others ahead of their own, in that we are just like any other animal.

I used to play a massively multiplayer game called Eve Online. One of the features of this game was the most amazing artificial economy I have ever seen. This economy is completely unregulated and you would not believe how brutal it is. Scammers everywhere, you can literally not trust anybody. Stupid people are sent broke in an incredibly short period of time. Now these poor and maybe stupid people can stop playing Eve. The reason why I have brought this up is you can’t quit real-life as easily. Economic regulations and other laws exist to protect us from our own animal natures. Saying otherwise is self-serving denial. Yeah, I know not a very heart-warming conclusion, but that’s the way it is – deal with it.

Now, I’m not saying there are not many ways we can make the economy work better, be fairer, be more efficient and with less paperwork. The government should reform the economy, but you can’t throw the baby out with the bathwater.

And try not to vote idiots like this into the senate next time – they are there for 6 long years.

Tuesday, 13 May 2014

Democracy, You’re Doing It Wrong!

I believe people mostly politicians don’t really understand why democracy exists. Its sole purpose is to prevent governments from becoming too powerful. People should not be in fear of their government rather the government should be in fear of the people. Its secondary function is to throw out a government that has either been in power “too long” or its policies no longer align with majority voter opinion.

Parliamentary democracy has always been adversarial. You have a “right-wing” party, a “left-wing” party, maybe a centrist party and a light sprinkling of minor parties. In a country such as Australia we have a regular political cycle giving each major party their turn in office every 7 to 10 years. The same is true of a number of large democracies.

It seems to me that recently both the liberal and labour parties in Australia seem to have quite different agendas. When one party gets in they scrap a bunch of the dethroned party’s policies and completely reverse others. There doesn’t seem to be much logic to some of these decisions other than: we think the guys who voted us in would like it.

Compare the way we run a country to the way a team of doctors fights a nasty disease in a patient. Members of the medical profession are always talking about best practice. They continually develop new techniques and improve others to improve patient outcomes. They use science proving that certain treatments work while others probably do more harm than good.

You never hear about politicians talking about best practice when it comes to running a country. Why not? There are so many tools that have been developed to assist leaders in other sectors such as business, science and industry. Why can’t we create an economic stimulation of the world and test various ideas to see if they will work before implementation. I think it would be easier to create something like this than some climate models.

They should study what happens in other countries when they implement legislation. For example maybe several countries in Europe legalised marijuana. Did usage rates go up and down in these countries? How much money did those governments make by taxing marijuana? What happened to the Marijuana related crime rate? Would our leaders even consider legalising marijuana even if it was a massive success in all these countries? Probably not, because it would, “send the wrong message to our youth.” Politicians will use emotional catchphrases as a basis for legislation ahead of logic and science - every time.

An example of boneheaded legislation is the current affordability of housing. You will hear many politicians rabbiting on about housing availability and affordability. The Howard government even introduced the first home buyers grant to help people buy property. What a nice government - stupid government. All this ridiculous example of middle-class welfare did was to bring even more people into the housing market further pushing up prices.

Meanwhile the moderately wealthy were negatively gearing their investment properties reducing the amount of tax they paid from their day job. Negative gearing is the primary force pushing house prices up. The best thing the Howard government could have done is to axe negative gearing of investment properties. Yeah some Liberal voters would have been pissed off but it would have been the right thing to do. Now it’s too late I really don’t know what could be done about housing prices that wouldn’t utterly destroy the rest of the economy. And the banks? Well, they are laughing all the way to the bank. (Sorry I had to.) What this sounds like to me is government putting the interests of big business and the rich above the needs of the majority.

Over the past year we have seen politicians from both sides fall like dominoes from official corruption enquiries. The stupidity of some of these politicians is breathtaking. To top it all off we hear about fundraising activities that give the richest Australians direct access to our most powerful politicians. I believe we need to abolish this sort of political fundraising. With social media the cost of getting your word out has reduced to almost nothing. We could properly eliminate all political fundraising above $100. Just an idea.

I personally look forward to the day when we are led by an intelligent supercomputer.

Friday, 9 May 2014

It Doesn’t Make You Look Smart

It seems there is a lot of people (hipsters) around today who love using long or unusual words to make themselves sound intelligent. Many of these people have started to wear beards, which is a bit weird.

Contemporaneously. I just spotted this one being used in a Wikipedia article. If I had to guess, I would say it means something about contemporary something or other.

During the same period of time; "contemporaneously, or possibly a little later, there developed a great Sumerian civilisation"

When I looked up the definition on Google I got a single definition, which is unusual to say the least. The purpose of language is to communicate - it is completely pointless if you have to look up words to know their meaning.

There is a rule that many good writers use: Prefer the Anglo-Saxon word. It is a myth that short sharp words such as cup, creek, shit, fuck, cunt, originated from when the Anglo-Saxons ruled England. Just because a rule is historically inaccurate, it can still have value. The idea is to try to communicate with short words and short sentences. Short paragraphs help too. It is far more likely that people will actually be able to read what you are writing.

Now I have quite a large vocabulary and I know a lot of long words. I tend to use a lot of long words when I am writing. When I am finished, I read it over again and erase as many of these words as I can. I eliminate really long sentences and reorder the words in others. I remove double negatives and exterminate adverbs.

I harbour a special hatred of adverbs. You know those horrible words that add "special" extra meaning to words. She walked slowly. She said contemptuously. The problem is they add needless complexity to a sentence and break another rule: Show don’t tell. For example: the word contemptuously, when you are incredibly angry with somebody you feel contempt for them. You may scream, shout – spray.

"You are an arsehole", she sprayed.

This gives you a better impression of what is going on, rather than trying to read some long stupid word. Using adverbs does not impress anybody. The only thing it demonstrates is laziness and lack of imagination. You can almost always remove them and it will almost always improve the sentence - unless you are deliberately trying to be a dick.

So hipsters, please stop using needlessly complex language and long words. You are not impressing anybody with your words and your beards. You do know that the Taliban force all males to grow beards?

Wednesday, 7 May 2014

My Rover

I know I haven’t written anything about electronics or robotics recently, but I am about to get back into it. Over the past few weeks I have been working out how to interface an Arduino microcontroller with a Windows PC. This is basically so I can control things directly from a panel or button on my computer desktop such as a robot arm, buzzer or rover.

This is surprisingly easy to do once you know how. It took me so long to work it all out because virtually every tutorial on the Internet assumes you have certain knowledge. Like you are supposed to know A before learning about B, but if you don’t know A it is going to be very difficult to understand B.

We have a crap load of electronic crap around our place specifically old radio control cars with old tyres, batteries and other assorted RC stuff. It would be great if I could use some of that gear to experiment with robotics.

I also wanted to learn the programming language C sharp (C#) and the .NET framework as I had heard good things about it. So I started learning a bit about C# and it was just as awesome as the reports said it was. The best thing about this language is it is very similar to its relatives C, C ++, Java and PHP. It is also backed by Microsoft and an absolute ton of developers and programmers, so there is heaps of information about it online. Microsoft Visual Studio Express 2013 a free .NET development environment is very user friendly tool for creating applications. All this make it the perfect language for the home tinkerer.

Now all I had to do was combine my new knowledge with the resources at hand to create something really cool - a rover controlled by radio from the PC. I would also need to find a way to transmit serial signals wirelessly. An Arduino would replace the receiver inside one of my RC cars and the PC would act as the controller. The old speed controller and front servo would be connected to the Arduino. I was in luck because someone had written a Command Messenger Library for Arduino and .NET - it was specifically designed to do what I need.

After head-butting down a number of brick walls I started to have some serious success. I created what I call a virtual trackpad application that when coupled with the correct code on the Arduino side allows me to control servos with my mouse. Moving servos is one thing but a 10 year old RC car? Piss easy apparently. We just charged a battery, plugged the speed controller and the servo that turns the front wheels into the Arduino and it worked… backwards. The backwards thing was easily fixed with an addition of a single line of code.

The next stage was to get send serial signals wirelessly from the PC to the Arduino. I did a bit of research and found out that an XBee was the way to do this. So we dug around in our large pile of electronic crap and discovered two XBees. For some strange reason we couldn’t get them to work so after another frustrating day we worked out that we were using the wrong baud rate. The default rate is usually 9600 but in our case it was 57600. So if you think you have a bricked XBee try different baud rates.

The last step is to get a camera system that I can mount on the rover and send the video to the PC. It will be just like a racing game but awesomer!

This is the story of the project, but eventually I will be putting all the technical details in a number of future posts so anyone can duplicate what I have done.

Sunday, 4 May 2014

The Narcissism Epidemic

Narcissism is defined by Google as: extreme selfishness, with a grandiose view of one's own talents… You get the picture. Someone who thinks only of themselves and are surprised when others don’t share their view.

Don’t get me wrong loving yourself has its place. After all, you are the most important person in your life. Whitney Houston sung about it - a whole song! The thing is, everybody else is also the most important person in their life. Many people don’t seem to realize this simple fact.

Over the years I have had a lot of contact with generation Y. Gen Y grew up in a world of instantaneous communication and many of them are heavy users of social media. I am well aware of the buzz you get when you post a status on Facebook and get 20 likes. On social media we are all very much our own celebrities and I think this might be having some negative consequences.

These days it is a tragedy if you don’t answer someone’s text message straight away. I know people who have lost friends or even partners because "they don’t answer my messages". Some even try to bring their narcissistic adulation into the real world.

An example of this is the insanity that is weddings these days. Weddings now have to be perfect. Brides and grooms now feel it is their right to have everything their way no matter what the cost. They put unfair expectations on the members of the bridal party - such as making them pay for a very expensive dress etc. There is so much stressing and so much money splashed around for just one day. Isn’t it really just an event to publicly declare your love for somebody, with a party afterwards? If I ever get married we are having takeaway pizza as the main course, okay?

That is just one example, but you see narcissism at work in all aspects of our culture. We all need to understand that everybody is important. If somebody doesn’t answer your text message within five minutes, or ever, they are not doing it because they hate you - they are doing it because they are human with their own lives. You cannot have unrealistic expectations of others as you will only make them and you miserable.

You may ask, how do I know I am doing right by others? The answer to this is simple and ancient, the golden rule: treat others the way you wish to be treated.

Friday, 2 May 2014

Ukraine in Crisis, Part III: Cold War II

Part I | Part II | Part III

I think there is an underlying reason why all this is happening. Russia wants its place back as a superpower equal to the US and Vladimir Putin believes he is the person to do it. In 2011 the former Soviet states Belarus, Kazakhstan, and Russia agreed to become part of the Eurasian Economic Union starting in 2015. Since then Kyrgyzstan and Tajikistan have expressed interest in joining. Does Vladimir believe that there is something missing from this recipe – Ukraine maybe?

If all these countries fused together would create one powerful organisation this time without the technological deficit of the former USSR. There is also a huge amount of mineral resources throughout the Eurasian steppe. This union would also share a long border with China. Chances are slim that China would join, but what if they became allies? This could create a power block strong enough to go toe to toe with the US and the West. A world war can’t happen if there aren’t two evenly matched sides technologically, militarily and economically.

Now I am old enough to remember the Cold War. These days we worry about terrorism - what a joke. In the early 80s we were worried about global thermonuclear war - end of the world stuff. If relations break down between these two blocks a second Cold War could start. We may be fearing global annihilation again. A large economic collapse such as China going bankrupt, as some people fear, could indirectly start a conflict.

We can be hopeful that things will not degenerate into a Cold War. With instant global communication and the Internet we are slowly becoming a truly global society. It may longer be possible to split the world down the middle as was the case 50 years ago. No matter where we live we all need to make sure our leaders know that we do not want this to happen.

Part I | Part II | Part III

hizzer