Well, well, well

A lot has happened recently. And I mean a lot.

So what have I been up to? Well a lot of stuff as mentioned above.

One of the most important things that has happened recently for me is I’ve been hired. No, not by Macdonalds like half of my school it seems. No, I’ve been hired to create the new website for uavs australia. If you don’t know who they are here’s their current website: http://www.uavsaustralia.com/ . Trust me, I’m making a better one than that. So I’ve been dusting off my web coding skills and hitting the aptana studio editor hard. So I haven’t had much time to write stuff for this blog as frequently as I normally do.

The other thing I have been doing is building a spacecraft. The avionics are nearly done (I’ll write something up on them when they’re finished) and I have figured out the whole government approval thing. All I have to do know is get a balloon and some helium. Kids at school just laugh when they ask me what I’m doing on the weekend. “I’m working on a spacecraft”.”Bulls**t you are”.

Yesterday I did some testing of the balloon video camera by strapping it to a kite for a high speed test run. Here’s a still from the flight.

I'm the little dude in the white jumper.

I’ll upload the full video some time. It makes for interesting viewing. The kite can get a pretty high perspective.

I also flew some water rockets using a hose and some bottles with a friend. We got a bit bored on a Sunday afternoon. Here’s a couple of pics from that adventure:

The rocket could fly to about the distance of the car in the background. I mean it was just a bottle shoved on a hose.

The rocket could fly to about the distance of the car in the background.

That's my friend kicking a dud one to get it to launch.

That's my friend kicking a stubbourn one to get it to launch.

Sorry the rocket pictures are so low res. My friend has go pro footage of the launches. I’ll have to get it off him. It was fun and wet launching those things. You pinch the hose as a throttle and gradually build up the pressure in the bottle until it can’t take it any more and blasts off.

So there’s my hastily written update on what I’ve been doing. I’ll keep you posted.

Advertisements

I like numbers

Ethernet

A kid that I teach robotics to has begged me to show him some code examples of using an Etherten seeing as he just bought one. I’m not going to copy and paste more long and tedious code examples into my blog so I’m just going to give him some links.

The library and shield home:

http://www.arduino.cc/en/Reference/Ethernet

Lots of examples of ethernet and other comms.

http://arduino.cc/playground/Main/InterfacingWithHardware#Communication

The best example in my opinion (hint: this doesn’t work if you don’t type in the etherten’s IP address into the sketch (i.e. 1.2.45.6.10 blah blah blah). Don’t change the mac address.)

http://arduino.cc/playground/Code/WebServer

And don’t forget to read the instruction manual. I never read instruction manuals but you NEED to read this.

http://www.practicalarduino.com/freetronics/EtherTen_Getting_Started.pdf

And look at this amazingly cool project with arduino and ethernet. It should help you get started. It uses the same wiznet ethernet chip as  the etherten.

http://www.youtube.com/user/mrichardson23#p/c/3C4936C5BA46679D/18/DnFZsPlaknQ

There’s also a bit on this blog about ethertens and stuff.

That should get you started. 🙂

Display

Moving onto our main topic I’ve finally had a chance to test the server’s circuit. The main component of this is the display.

Display

The numeric display deeply nested inside the project

To test this I used the serial debugging program that I use to debug most things. You can find it in the category of Arduino Sketches.

So I set analog pins 1-4 high and digital pins 0-7 high and it all lit up.

Display lit up

All lit up.

Now the picture above may look at first like one for happiness and joy but I can assure you it’s not. The top and top left segments of the display are trouble. This is because they are hooked up to pins 0 and 1. Now pins 0 and 1 on the arduino do the TX and RX for the serial functions. This is bad. It means that these pins are inaccessible when using the computer with the board. I need to figure out a way around this.

So I tried having the arduino kind of  do a permanent Serial.print() command to keep the top segment (TX pin) bright. It worked. But what about the RX pin?

Time to build an ethernet debugger.

Nah I’m not that good.

Time to move away from the serial debugger and to a proper sketch.

I simply made a sketch that looked like this:

void setup() {
  pinMode(13, OUTPUT);
  pinMode(12, OUTPUT);
  pinMode(11, OUTPUT);
  pinMode(10, OUTPUT);
  pinMode(9, OUTPUT);
  pinMode(8, OUTPUT);
  pinMode(7, OUTPUT);
  pinMode(6, OUTPUT);
  pinMode(5, OUTPUT);
  pinMode(4, OUTPUT);
  pinMode(3, OUTPUT);
  pinMode(2, OUTPUT);
  pinMode(1, OUTPUT);
  pinMode(0, OUTPUT);
  pinMode(A0, OUTPUT);
  pinMode(A1, OUTPUT);
  pinMode(A2, OUTPUT);
  pinMode(A3, OUTPUT);
  pinMode(A4, OUTPUT);
  pinMode(A5, OUTPUT);

}
void loop(){
 digitalWrite(A1, HIGH);
 digitalWrite(A2, HIGH);
 digitalWrite(A3, HIGH);
 digitalWrite(A4, HIGH);
 digitalWrite(0, HIGH);
 digitalWrite(1, HIGH);
}

And the pins lit up like this:

TX and RX pin lit up

Problem solved

I tested the tilt switch using the good old AnalogReadSerial sketch. It worked. Server security? Check.

I know the piezo worked because it made several loud noises when I accidentally turned it on a couple of times in the library while debugging. Annoying noises that can be turned on remotely? Check.

Last but definitely not least the LM35 temperature sensor worked when I tested it with a LadyAda sketch. My room is a t 19.1 degrees celsius.

See http://www.ladyada.net/learn/sensors/tmp36.html for the code

So that’s about it for circuit testing.

Boards

As promised here are some more cool boards that are on my wishlist. Not as much detail this time around because I am in a hurry. Just click on the images to find out more.

Chumby

Chumby hacker board

Panda board. This thing is awesome. Ethernet and HDMI.

Panda board. This thing is awesome. Ethernet and HDMI.

The Digilent Cerebot 32MX7. Ethernet and a PIC32.

The Digilent Cerebot 32MX7. Ethernet and a PIC32.

Mbed dev board. Boasts an ARM and Ethernet at Arduino Nano size.

Mbed dev board. Boasts an ARM and Ethernet at Arduino Nano size.

So that’s about all the boards I can think of at the moment that are worth mentioning. I’ll have to find some more for you guys.

Synth program

This is another cool program I whipped up the other day when I got my etherten. I know I could save program space by doing fancy loops and stuff but I tend to stick to KISS. To run the program hook a piezo to pin 9 and ground. Then open the serial monitor and try typing in 3 or 4. This should change the sound the piezo makes

Here you go:

int incomingByte;
int note = 100;
int beat = 50;
int length = 10;
int pin = 9;

void setup() {
 // put your setup code here, to run once:
Serial.begin(9600);
 // initialize the LED pin as an output:
 pinMode(pin, OUTPUT);
}

void loop() {
 tone (pin,note);
 delay(length);
 noTone (pin);
 delay(beat);
 if (Serial.available() > 0) {
 // read the oldest byte in the serial buffer:
 incomingByte = Serial.read();
 // if it's a capital H (ASCII 72), turn on the LED:
 if (incomingByte == 'q') {
 note = note + 10;
 Serial.println (note, DEC);
 } 
 if (incomingByte == 'a') {
 note = note - 10;
 Serial.println (note, DEC);
 } 
 if (incomingByte == 'w') {
 length = length + 10;
 Serial.println (length, DEC);
 } 
 if (incomingByte == 's') {
 length = length - 10;
 Serial.println (length, DEC);
 }
 if (incomingByte == 'e') {
 beat = beat + 10;
 Serial.println (beat, DEC);
 } 
 if (incomingByte == '1') {
 beat = 856;
 length = 45;
 }
 if (incomingByte == '2') {
 beat = 50;
 length = 600;
 }
 if (incomingByte == '3') {
 beat = 10;
 length = 120;
 }
 if (incomingByte == '4') {
 beat = 15;
 length = 100;
 }
 if (incomingByte == '5') {
 beat = 30;
 length = 70;
 }
 if (incomingByte == '0') {
 beat = 0;
 length = 0;
 note = 0;
 Serial.println("synth has been turned off");
 }
 if (incomingByte == '9') {
 beat = 10;
 length = 10;
 note = 10;
 Serial.println("synth has been turned on");

 }
 }
 }

Serial debugging

Here’s a little program I wrote to debug using serial.

You send commands to the board using the arduino IDE’s  built-in serial monitor. The board interprets these commands and turns on and off pins as a result. You might have to change some of the keys to make it work with your keyboard. With my laptop (dell inspiron 15r) the keys line up like a switch board.

I was going to show how I fixed some of the wiring with this program but I couldn’t because my etherten isn’t working at the moment.

Enjoy.

 
/* 
Switchboard debugging program created by Lochie Ferrier (www.lochieferrier.com).
Use it wherever the hell you like.
*/


int incomingByte;      // a variable to read incoming serial data into

void setup() {
  // initialize serial communication:
  Serial.begin(9600);
  // initialize the LED pin as an output:
  pinMode(13, OUTPUT);
  pinMode(12, OUTPUT);
  pinMode(11, OUTPUT);
  pinMode(10, OUTPUT);
  pinMode(9, OUTPUT);
  pinMode(8, OUTPUT);
  pinMode(7, OUTPUT);
  pinMode(6, OUTPUT);
  pinMode(5, OUTPUT);
  pinMode(4, OUTPUT);
  pinMode(3, OUTPUT);
  pinMode(2, OUTPUT);
  pinMode(1, OUTPUT);
  pinMode(0, OUTPUT);
  pinMode(A0, OUTPUT);
  pinMode(A1, OUTPUT);
  pinMode(A2, OUTPUT);
  pinMode(A3, OUTPUT);
  pinMode(A4, OUTPUT);
  pinMode(A5, OUTPUT);
  
  
  
}

void loop() {
  digitalWrite(0, HIGH);3
  // see if there's incoming serial data:
  if (Serial.available() > 0) {
    // read the oldest byte in the serial buffer:
    incomingByte = Serial.read();
    // if it's a capital H (ASCII 72), turn on the LED:
        if (incomingByte == '-') {
      digitalWrite(0, HIGH);
    } 
        if (incomingByte == '[') {
      digitalWrite(0, LOW);
    } 
    if (incomingByte == '1') {
      digitalWrite(1, HIGH);
    } 
        if (incomingByte == 'q') {
      digitalWrite(1, LOW);
    } 
        if (incomingByte == '2') {
      digitalWrite(2, HIGH);
    } 
        if (incomingByte == 'w') {
      digitalWrite(2, LOW);
    } 
        if (incomingByte == '3') {
      digitalWrite(3, HIGH);
    } 
        if (incomingByte == 'e') {
      digitalWrite(3, LOW);
    } 
        if (incomingByte == '4') {
      digitalWrite(4, HIGH);
    } 
        if (incomingByte == 'r') {
      digitalWrite(4, LOW);
    } 
    if (incomingByte == '5') {
      digitalWrite(5, HIGH);
    } 
        if (incomingByte == 't') {
      digitalWrite(5, LOW);
    } 
        if (incomingByte == '6') {
      digitalWrite(6, HIGH);
    } 
        if (incomingByte == 'y') {
      digitalWrite(6, LOW);
       }    
      if (incomingByte == '7') {
      digitalWrite(7, HIGH);
    } 
        if (incomingByte == 'u') {
      digitalWrite(7, LOW);
    }
          if (incomingByte == '8') {
      digitalWrite(8, HIGH);
    } 
        if (incomingByte == 'i') {
      digitalWrite(8, LOW);
    }
              if (incomingByte == '9') {
      digitalWrite(9, HIGH);
    } 
        if (incomingByte == 'o') {
      digitalWrite(9, LOW);
    }
                  if (incomingByte == '0') {
      digitalWrite(10, HIGH);
    } 
        if (incomingByte == 'p') {
      digitalWrite(10, LOW);
    }
                      if (incomingByte == 'a') {
      digitalWrite(11, HIGH);
    } 
        if (incomingByte == 'z') {
      digitalWrite(11, LOW);
    }                 
    if (incomingByte == 's') {
      digitalWrite(12, HIGH);
    } 
        if (incomingByte == 'x') {
      digitalWrite(12, LOW);
    }
        if (incomingByte == 'd') {
      digitalWrite(13, HIGH);
    } 
        if (incomingByte == 'c') {
      digitalWrite(13, LOW);
    }
            if (incomingByte == 'f') {
      digitalWrite(A0, HIGH);
    } 
        if (incomingByte == 'v') {
      digitalWrite(A0, LOW);
    }
                if (incomingByte == 'g') {
      digitalWrite(A1, HIGH);
    } 
        if (incomingByte == 'b') {
      digitalWrite(A1, LOW);
    }
                    if (incomingByte == 'h') {
      digitalWrite(A2, HIGH);
    } 
        if (incomingByte == 'n') {
      digitalWrite(A2, LOW);
    }
                        if (incomingByte == 'j') {
      digitalWrite(A3, HIGH);
    } 
        if (incomingByte == 'm') {
      digitalWrite(A3, LOW);
    }
                            if (incomingByte == 'k') {
      digitalWrite(A4, HIGH);
    } 
        if (incomingByte == ',') {
      digitalWrite(A4, LOW);
    }
                                if (incomingByte == 'l') {
      digitalWrite(A5, HIGH);
    } 
        if (incomingByte == '.') {
      digitalWrite(A5, LOW);
    }
      
    }
  
}

Progress

Sorry.

First up I’ll say sorry for not keeping you guys up to date with my server project for a couple of days. My school has this silly athletic qualification and testing system which is designed to rank me for races in an athletics carnival that I won’t be at.

The new UI

The new UI

A lot of wire!!

A diagram of the UI

The plan.

Okay so basically I’ve redesigned (again) the UI for the server. I figured out that I actually did have enough pins to include a four number 7 segment display after all. The other electronics includes a piezo for alarms and errors as well as a tilt switch to detect whether it has been touched and a temperature sensor for doing weather logging. So that’s basically all I’ve got for the electronics apart from the etherten.

Enclosure

An old power supply from the dump

An old computer power supply enclosure from the dump

I was digging around a bit last night for an enclosure and came across an old computer supply enclosure. It’s perfect because it has a fan that works and looks pretty cool. It’s AC socket also provides a perfect slot for the 4 number 7 segment display to fit into. The etherten does need the fan because it gets pretty hot so I’ll just hook it up to the 5V on the etherten. Also, when I turned off the lights with the etherten inside the enclosure, it glows a cool blue color from the etherten’s onboard LED. Awesome.

Programming

I think I’ve finally got a good idea of what I want the server to do. I want it to be able to show and log temperature to the SD card, serve files remotely, and display messages and errors on the 7 segment display. To do this I think I’m going to have a loop that includes a check to see whether it has received any HTTP requests and a variable that triggers a different 7 segment display message each time around. It would look a bit like this conceptually (very roughly).

loop(
HTTP check(
if it gets one it prints the webpage requested
)
lots of ifs depending on the variable
if var=1(
display temp on display
)
if var=2(
display history on display
)
delay(1000)
and increase the variable (also when it gets to a certain number bring it back to 1)
)

This kind of program structure allows for easy expansion and makes sure that webpages are served quickly.

So that’s about all for now. Next up is an in-depth look at how I wire number displays.

Ideas for the code

Here are a couple of ideas for the code for this project:

Temperature:

Integrating a temperature sensor to log weather in my room. This means that I can turn on  a heater using a relay before I wake up to go for a ride in the morning. I’ve already experimented with the LM35 temperature sensor tutorial code by Ladyada. Here’s an example of what I’ll probably use to integrate temperature readings:

void loop()                     // run over and over again
{
//getting the voltage reading from the temperature sensor
int reading = analogRead(sensorPin);// converting that reading to voltage, for 3.3v arduino use 3.3
float voltage = reading * 5.0;
voltage /= 1024.0;

// now print out the temperature
float temperatureC = (voltage – 0.5) * 100 ;  //converting from 10 mv per degree wit 500 mV offset// DO stuff with the temperature here
delay(1000);                                     //waiting a second
}

Ok so I eliminated the serial.println elements because I don’t need them. I also eliminated the Fahrenheit bit because I’m not American. It’s pretty easy to print out variables using ethernet so I don’t really need to cover that here.

The Main Server code framework

So here is what I’m going to be using as a basic starting point for the server client request and provide code. http://arduino.cc/playground/Code/WebServer

This guys stuff is pretty legendary because it’s easy to modify. I didn’t quite get how to use the GET and POST functions in his code because I think that they were a bit messed up. But I like this as a starting system as it is very easy to expand the code and add new pages (and functionality). The cool bit about this code is that it uses the PROGMEM code to put the webpages on the Flash memory. I may well go with something else that has the code on the SD card as this will give me a shitload of space and it will allow me to do easy references to images and files. But this is a good start and is what I’ll mess around with at first. My ultimate goal would be to build a system where you can modify the code remotely so you don’t have to be there plugged in with a USB cable to enhance and modify the system.

Of course in the good spirit of Arduino I will be making all my changes and the end product open source and will probably make a cool youtube vid at the end. Let the coding begin!